-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPluginAPIManager.cpp
185 lines (147 loc) · 4.55 KB
/
PluginAPIManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "[Common]\CLIWrapper.h"
#include "PluginAPIManager.h"
#include "Render Window\RenderWindowManager.h"
namespace cse
{
static const CSEInterface kCSEInterface =
{
PluginAPIManager::InitializeInterface,
PluginAPIManager::GetVersion,
};
static const CSEConsoleInterface kCSEConsoleInterface =
{
PluginAPIManager::PrintToConsole,
PluginAPIManager::RegisterConsoleCallback
};
static const CSEIntelliSenseInterface kCSEIntelliSenseInterface =
{
PluginAPIManager::RegisterCommandURL
};
static const CSERendererInterface kCSERendererInterface =
{
PluginAPIManager::PrintToRenderWindow
};
static const CSEScriptInterface kCSEScriptInterface =
{
PluginAPIManager::RegisterScriptCommand,
};
PluginAPIManager PluginAPIManager::Instance;
const UInt8 PluginAPIManager::kInterfaceVersion = 4;
PluginAPIManager::PluginAPIManager() :
ConsolePrintCallbacks(),
ObScriptCommandURLs(),
CodaScriptPluginCommandRegistrar("Plugin Functions"),
Initialized(false)
{
;//
}
PluginAPIManager::~PluginAPIManager()
{
Deinitailize();
}
const CSEInterface* PluginAPIManager::GetInterface()
{
SME_ASSERT(Initialized);
return &kCSEInterface;
}
UInt32 PluginAPIManager::ConsumeIntelliSenseInterface(componentDLLInterface::CommandTableData* OutCommandData)
{
SME_ASSERT(Initialized);
OutCommandData->DeveloperURLDataListCount = ObScriptCommandURLs.size();
if (!ObScriptCommandURLs.empty())
{
OutCommandData->DeveloperURLDataListHead = new componentDLLInterface::CommandTableData::DeveloperURLData[OutCommandData->DeveloperURLDataListCount];
int i = 0;
for (const auto& Itr : ObScriptCommandURLs)
{
OutCommandData->DeveloperURLDataListHead[i].CommandName = Itr.first.c_str();
OutCommandData->DeveloperURLDataListHead[i].URL = Itr.second.c_str();
++i;
}
}
return ObScriptCommandURLs.size();
}
void PluginAPIManager::ConsumeConsoleInterface()
{
SME_ASSERT(Initialized);
BGSEECONSOLE->RegisterPrintCallback(ConsolePrintCallbackPrototype);
}
void PluginAPIManager::ConsumeScriptInterface( bgsee::script::CodaScriptCommandRegistrar::ListT& OutRegistrars )
{
SME_ASSERT(Initialized);
OutRegistrars.push_back(&CodaScriptPluginCommandRegistrar);
}
void PluginAPIManager::Initialize( void )
{
Initialized = true; // just for the sake of completeness
}
void PluginAPIManager::Deinitailize( void )
{
ConsolePrintCallbacks.clear();
ObScriptCommandURLs.clear();
Initialized = false;
}
void PluginAPIManager::ConsolePrintCallbackPrototype(const char* Prefix, const char* Message)
{
if (Instance.Initialized == false)
return;
for (ConsolePrintCallbackListT::const_iterator Itr = Instance.ConsolePrintCallbacks.begin(); Itr != Instance.ConsolePrintCallbacks.end(); Itr++)
(*Itr)(Message, Prefix);
}
UInt8 PluginAPIManager::GetVersion()
{
return kInterfaceVersion;
}
const void* PluginAPIManager::InitializeInterface(UInt8 InterfaceType)
{
SME_ASSERT(Instance.Initialized);
switch (InterfaceType)
{
case CSEInterface::kCSEInterface_Console:
return &kCSEConsoleInterface;
case CSEInterface::kCSEInterface_IntelliSense:
return &kCSEIntelliSenseInterface;
case CSEInterface::kCSEInterface_Renderer:
return &kCSERendererInterface;
case CSEInterface::kCSEInterface_Script:
return &kCSEScriptInterface;
default:
return nullptr;
}
}
void PluginAPIManager::RegisterCommandURL(const char *CommandName, const char *URL)
{
SME_ASSERT(Instance.Initialized);
Instance.ObScriptCommandURLs.insert(std::make_pair(CommandName, URL));
}
void PluginAPIManager::RegisterConsoleCallback(CSEConsoleInterface::ConsolePrintCallback Handler)
{
SME_ASSERT(Instance.Initialized);
for (ConsolePrintCallbackListT::const_iterator Itr = Instance.ConsolePrintCallbacks.begin(); Itr != Instance.ConsolePrintCallbacks.end(); Itr++)
{
if (*Itr == Handler)
return;
}
Instance.ConsolePrintCallbacks.push_back(Handler);
}
void PluginAPIManager::RegisterScriptCommand(bgsee::script::ICodaScriptCommand* Command)
{
SME_ASSERT(Instance.Initialized);
Instance.CodaScriptPluginCommandRegistrar.Add(Command);
}
void PluginAPIManager::PrintToConsole(const char* Prefix, const char* FormatString, ...)
{
if (Instance.Initialized == false)
return;
char Buffer[0x1000] = {0};
va_list Args;
va_start(Args, FormatString);
vsnprintf_s(Buffer, sizeof(Buffer), _TRUNCATE, FormatString, Args);
va_end(Args);
BGSEECONSOLE->LogMsg(Prefix, Buffer);
}
void PluginAPIManager::PrintToRenderWindow(const char* Message, float DisplayDuration)
{
;// not supported anymore
}
}