14 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
15 |
#include "tree.h" |
#include "tree.h" |
16 |
#include "CoreVMFunctions.h" |
#include "CoreVMFunctions.h" |
17 |
|
#include "CoreVMDynVars.h" |
18 |
#include "editor/NkspScanner.h" |
#include "editor/NkspScanner.h" |
19 |
|
|
20 |
#define DEBUG_SCRIPTVM_CORE 0 |
#define DEBUG_SCRIPTVM_CORE 0 |
99 |
m_fnAbs = new CoreVMFunction_abs; |
m_fnAbs = new CoreVMFunction_abs; |
100 |
m_fnRandom = new CoreVMFunction_random; |
m_fnRandom = new CoreVMFunction_random; |
101 |
m_fnNumElements = new CoreVMFunction_num_elements; |
m_fnNumElements = new CoreVMFunction_num_elements; |
102 |
|
m_fnInc = new CoreVMFunction_inc; |
103 |
|
m_fnDec = new CoreVMFunction_dec; |
104 |
|
m_varRealTimer = new CoreVMDynVar_NKSP_REAL_TIMER; |
105 |
|
m_varPerfTimer = new CoreVMDynVar_NKSP_PERF_TIMER; |
106 |
|
m_fnShLeft = new CoreVMFunction_sh_left; |
107 |
|
m_fnShRight = new CoreVMFunction_sh_right; |
108 |
} |
} |
109 |
|
|
110 |
ScriptVM::~ScriptVM() { |
ScriptVM::~ScriptVM() { |
114 |
delete m_fnAbs; |
delete m_fnAbs; |
115 |
delete m_fnRandom; |
delete m_fnRandom; |
116 |
delete m_fnNumElements; |
delete m_fnNumElements; |
117 |
|
delete m_fnInc; |
118 |
|
delete m_fnDec; |
119 |
|
delete m_fnShLeft; |
120 |
|
delete m_fnShRight; |
121 |
|
delete m_varRealTimer; |
122 |
|
delete m_varPerfTimer; |
123 |
} |
} |
124 |
|
|
125 |
VMParserContext* ScriptVM::loadScript(const String& s) { |
VMParserContext* ScriptVM::loadScript(const String& s) { |
134 |
context->registerBuiltInConstIntVariables( builtInConstIntVariables() ); |
context->registerBuiltInConstIntVariables( builtInConstIntVariables() ); |
135 |
context->registerBuiltInIntVariables( builtInIntVariables() ); |
context->registerBuiltInIntVariables( builtInIntVariables() ); |
136 |
context->registerBuiltInIntArrayVariables( builtInIntArrayVariables() ); |
context->registerBuiltInIntArrayVariables( builtInIntArrayVariables() ); |
137 |
|
context->registerBuiltInDynVariables( builtInDynamicVariables() ); |
138 |
|
|
139 |
context->createScanner(is); |
context->createScanner(is); |
140 |
|
|
217 |
else if (name == "abs") return m_fnAbs; |
else if (name == "abs") return m_fnAbs; |
218 |
else if (name == "random") return m_fnRandom; |
else if (name == "random") return m_fnRandom; |
219 |
else if (name == "num_elements") return m_fnNumElements; |
else if (name == "num_elements") return m_fnNumElements; |
220 |
|
else if (name == "inc") return m_fnInc; |
221 |
|
else if (name == "dec") return m_fnDec; |
222 |
|
else if (name == "sh_left") return m_fnShLeft; |
223 |
|
else if (name == "sh_right") return m_fnShRight; |
224 |
return NULL; |
return NULL; |
225 |
} |
} |
226 |
|
|
232 |
return std::map<String,VMInt8Array*>(); |
return std::map<String,VMInt8Array*>(); |
233 |
} |
} |
234 |
|
|
235 |
|
std::map<String,VMDynVar*> ScriptVM::builtInDynamicVariables() { |
236 |
|
std::map<String,VMDynVar*> m; |
237 |
|
|
238 |
|
m["$NKSP_PERF_TIMER"] = m_varPerfTimer; |
239 |
|
m["$NKSP_REAL_TIMER"] = m_varRealTimer; |
240 |
|
m["$KSP_TIMER"] = m_varRealTimer; |
241 |
|
|
242 |
|
return m; |
243 |
|
} |
244 |
|
|
245 |
std::map<String,int> ScriptVM::builtInConstIntVariables() { |
std::map<String,int> ScriptVM::builtInConstIntVariables() { |
246 |
return std::map<String,int>(); |
std::map<String,int> m; |
247 |
|
|
248 |
|
m["$NI_CB_TYPE_INIT"] = VM_EVENT_HANDLER_INIT; |
249 |
|
m["$NI_CB_TYPE_NOTE"] = VM_EVENT_HANDLER_NOTE; |
250 |
|
m["$NI_CB_TYPE_RELEASE"] = VM_EVENT_HANDLER_RELEASE; |
251 |
|
m["$NI_CB_TYPE_CONTROLLER"] = VM_EVENT_HANDLER_CONTROLLER; |
252 |
|
|
253 |
|
return m; |
254 |
} |
} |
255 |
|
|
256 |
VMEventHandler* ScriptVM::currentVMEventHandler() { |
VMEventHandler* ScriptVM::currentVMEventHandler() { |