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 |
} |
} |
107 |
|
|
108 |
ScriptVM::~ScriptVM() { |
ScriptVM::~ScriptVM() { |
112 |
delete m_fnAbs; |
delete m_fnAbs; |
113 |
delete m_fnRandom; |
delete m_fnRandom; |
114 |
delete m_fnNumElements; |
delete m_fnNumElements; |
115 |
|
delete m_fnInc; |
116 |
|
delete m_fnDec; |
117 |
|
delete m_varRealTimer; |
118 |
|
delete m_varPerfTimer; |
119 |
} |
} |
120 |
|
|
121 |
VMParserContext* ScriptVM::loadScript(const String& s) { |
VMParserContext* ScriptVM::loadScript(const String& s) { |
130 |
context->registerBuiltInConstIntVariables( builtInConstIntVariables() ); |
context->registerBuiltInConstIntVariables( builtInConstIntVariables() ); |
131 |
context->registerBuiltInIntVariables( builtInIntVariables() ); |
context->registerBuiltInIntVariables( builtInIntVariables() ); |
132 |
context->registerBuiltInIntArrayVariables( builtInIntArrayVariables() ); |
context->registerBuiltInIntArrayVariables( builtInIntArrayVariables() ); |
133 |
|
context->registerBuiltInDynVariables( builtInDynamicVariables() ); |
134 |
|
|
135 |
context->createScanner(is); |
context->createScanner(is); |
136 |
|
|
213 |
else if (name == "abs") return m_fnAbs; |
else if (name == "abs") return m_fnAbs; |
214 |
else if (name == "random") return m_fnRandom; |
else if (name == "random") return m_fnRandom; |
215 |
else if (name == "num_elements") return m_fnNumElements; |
else if (name == "num_elements") return m_fnNumElements; |
216 |
|
else if (name == "inc") return m_fnInc; |
217 |
|
else if (name == "dec") return m_fnDec; |
218 |
return NULL; |
return NULL; |
219 |
} |
} |
220 |
|
|
226 |
return std::map<String,VMInt8Array*>(); |
return std::map<String,VMInt8Array*>(); |
227 |
} |
} |
228 |
|
|
229 |
|
std::map<String,VMDynVar*> ScriptVM::builtInDynamicVariables() { |
230 |
|
std::map<String,VMDynVar*> m; |
231 |
|
|
232 |
|
m["$NKSP_PERF_TIMER"] = m_varPerfTimer; |
233 |
|
m["$NKSP_REAL_TIMER"] = m_varRealTimer; |
234 |
|
m["$KSP_TIMER"] = m_varRealTimer; |
235 |
|
|
236 |
|
return m; |
237 |
|
} |
238 |
|
|
239 |
std::map<String,int> ScriptVM::builtInConstIntVariables() { |
std::map<String,int> ScriptVM::builtInConstIntVariables() { |
240 |
return std::map<String,int>(); |
return std::map<String,int>(); |
241 |
} |
} |