20 #define SCRIPT_TYPE_NAME "raScriptClass" 21 #define SCRIPT_UPDATE_TEST "UpdatePosition" 23 #ifdef GetTempFileName 24 #undef GetTempFileName 29 public ref class raScriptEngine
sealed 42 m_pScriptAssembly =
nullptr;
43 m_pScriptType =
nullptr;
44 m_hasNotSecurityException =
false;
46 if((m_pSavedFile !=
nullptr ) && (m_pSavedFile->Length > 0))
50 File::Delete(m_pSavedFile);
55 m_pSavedFile =
nullptr;
62 if(pScriptName ==
nullptr || pScriptName->Length == 0)
65 StreamReader^ pReader =
nullptr;
68 pReader =
gcnew StreamReader(pScriptName);
69 System::String^ pScriptText = pReader->ReadToEnd();
71 if(pScriptText ==
nullptr || pScriptText->Length == 0)
74 CSharpCodeProvider^ pProvider =
gcnew CSharpCodeProvider();
75 CompilerParameters^ pParams =
gcnew CompilerParameters();
76 pParams->GenerateExecutable =
false;
77 pParams->GenerateInMemory =
false;
78 m_pSavedFile = System::String::Concat(Path::GetTempFileName(),
".dll");
79 pParams->OutputAssembly = m_pSavedFile;
81 CompilerResults^ pResult = pProvider->CompileAssemblyFromSource(pParams,
82 gcnew array<System::String^>{ pScriptText });
84 if(pResult->Errors->Count > 0)
86 System::Diagnostics::Debugger::Log(0,
nullptr,
87 pResult->Errors[0]->ErrorText);
92 m_pScriptAssembly = System::Reflection::Assembly::LoadFrom(pResult->PathToAssembly);
94 if(m_pScriptType =
nullptr)
96 m_pScriptAssembly =
nullptr;
104 System::Diagnostics::Debugger::Log(0,
nullptr,
116 if(pX == NULL || pY == NULL || pZ == NULL)
118 if(m_pScriptAssembly ==
nullptr || m_pScriptType ==
nullptr)
121 if(!m_canUpdatePosition)
126 array<System::Object^>^pParams = { fRunTime, *pX, *pY, *pZ };
128 BindingFlags::InvokeMethod |
129 BindingFlags::DeclaredOnly |
130 BindingFlags::Public |
131 BindingFlags::NonPublic |
132 BindingFlags::Static),
133 nullptr,
nullptr, pParams);
135 *pX =
static_cast<float>(pParams[1]);
136 *pY =
static_cast<float>(pParams[2]);
137 *pZ =
static_cast<float>(pParams[3]);
139 catch(TargetInvocationException^ e)
141 System::Diagnostics::Debugger::Log(0,
nullptr,
143 m_canUpdatePosition =
false;
149 static Assembly^ m_pScriptAssembly =
nullptr;
150 static Type^ m_pScriptType =
nullptr;
151 static String^ m_pSavedFile =
nullptr;
152 static bool m_hasNotSecurityException =
false;
153 static bool m_canUpdatePosition =
true;
#define SCRIPT_UPDATE_TEST
static bool LoadScriptData(System::String^ pScriptName)
static bool UpdatePosition(float fRunTime, float *pX, float *pY, float *pZ)
static void ResetObjects()