@@ -25,6 +25,14 @@ namespace fmt {
25
25
return formatter<std::string>::format (path.string (), ctx);
26
26
}
27
27
};
28
+
29
+ template <>
30
+ struct formatter <StarEngine::UUID> : formatter<std::string> {
31
+ template <typename FormatContext>
32
+ auto format (const StarEngine::UUID& uuid, FormatContext& ctx) const {
33
+ return formatter<std::string>::format (std::to_string (uuid), ctx);
34
+ }
35
+ };
28
36
} // namespace fmt
29
37
30
38
namespace StarEngine {
@@ -177,46 +185,25 @@ namespace StarEngine {
177
185
InitMono ();
178
186
ScriptGlue::RegisterFunctions ();
179
187
180
- LoadAssembly (" Resources/Scripts/StarEngine-ScriptCore.dll" );
181
- LoadAppAssembly (" SandboxProject/Assets/Scripts/Binaries/Sandbox.dll" );
188
+ bool status = LoadAssembly (" Resources/Scripts/StarEngine-ScriptCore.dll" );
189
+ if (!status)
190
+ {
191
+ SE_CORE_ERROR (" [ScriptEngine] Could not load StarEngine-ScriptCore assembly." );
192
+ return ;
193
+ }
194
+ status = LoadAppAssembly (" SandboxProject/Assets/Scripts/Binaries/Sandbox.dll" );
195
+ if (!status)
196
+ {
197
+ SE_CORE_ERROR (" [ScriptEngine] Could not load app assembly." );
198
+ return ;
199
+ }
200
+
182
201
LoadAssemblyClasses ();
183
202
184
203
ScriptGlue::RegisterComponents ();
185
204
186
205
// Retrieve and instantiate class
187
206
s_Data->EntityClass = ScriptClass (" StarEngine" , " Entity" , true );
188
- #if 0
189
-
190
- MonoObject* instance = s_Data->EntityClass.Instantiate();
191
-
192
- // Call method
193
- MonoMethod* printMessageFunc = s_Data->EntityClass.GetMethod("PrintMessage", 0);
194
- s_Data->EntityClass.InvokeMethod(instance, printMessageFunc);
195
-
196
- // Call method with param
197
- MonoMethod* printIntFunc = s_Data->EntityClass.GetMethod("PrintInt", 1);
198
-
199
- int value = 5;
200
- void* param = &value;
201
-
202
- s_Data->EntityClass.InvokeMethod(instance, printIntFunc, ¶m);
203
-
204
- MonoMethod* printIntsFunc = s_Data->EntityClass.GetMethod("PrintInts", 2);
205
- int value2 = 508;
206
- void* params[2] =
207
- {
208
- &value,
209
- &value2
210
- };
211
- s_Data->EntityClass.InvokeMethod(instance, printIntsFunc, params);
212
-
213
- MonoString* monoString = mono_string_new(s_Data->AppDomain, "Hello World from C++!");
214
- MonoMethod* printCustomMessageFunc = s_Data->EntityClass.GetMethod("PrintCustomMessage", 1);
215
- void* stringParam = monoString;
216
- s_Data->EntityClass.InvokeMethod(instance, printCustomMessageFunc, &stringParam);
217
-
218
- SE_CORE_ASSERT(false);
219
- #endif
220
207
}
221
208
222
209
void ScriptEngine::Shutdown ()
@@ -265,32 +252,34 @@ namespace StarEngine {
265
252
s_Data->RootDomain = nullptr ;
266
253
}
267
254
268
- void ScriptEngine::LoadAssembly (const std::filesystem::path& filepath)
255
+ bool ScriptEngine::LoadAssembly (const std::filesystem::path& filepath)
269
256
{
270
257
// Create an App Domain
271
258
s_Data->AppDomain = mono_domain_create_appdomain (" StarEngineScriptRuntime" , nullptr );
272
259
mono_domain_set (s_Data->AppDomain , true );
273
260
274
- // Move this maybe
275
261
s_Data->CoreAssemblyFilepath = filepath;
276
262
s_Data->CoreAssembly = Utils::LoadMonoAssembly (filepath, s_Data->EnableDebugging );
263
+ if (s_Data->CoreAssembly == nullptr )
264
+ return false ;
265
+
277
266
s_Data->CoreAssemblyImage = mono_assembly_get_image (s_Data->CoreAssembly );
278
- // Utils::PrintAssemblyTypes(s_Data->CoreAssembly) ;
267
+ return true ;
279
268
}
280
269
281
270
282
- void ScriptEngine::LoadAppAssembly (const std::filesystem::path& filepath)
271
+ bool ScriptEngine::LoadAppAssembly (const std::filesystem::path& filepath)
283
272
{
284
- // Move this maybe
285
273
s_Data->AppAssemblyFilepath = filepath;
286
274
s_Data->AppAssembly = Utils::LoadMonoAssembly (filepath, s_Data->EnableDebugging );
287
- auto assemb = s_Data->AppAssembly ;
275
+ if (s_Data->AppAssembly == nullptr )
276
+ return false ;
288
277
s_Data->AppAssemblyImage = mono_assembly_get_image (s_Data->AppAssembly );
289
- auto assembi = s_Data->AppAssemblyImage ;
290
- // Utils::PrintAssemblyTypes(s_Data->AppAssembly);
291
278
292
279
s_Data->AppAssemblyFileWatcher = CreateScope<filewatch::FileWatch<std::string>>(filepath.string (), OnAppAssemblyFileSystemEvent);
293
280
s_Data->AssemblyReloadPending = false ;
281
+
282
+ return true ;
294
283
}
295
284
296
285
void ScriptEngine::ReloadAssembly ()
@@ -343,10 +332,15 @@ namespace StarEngine {
343
332
void ScriptEngine::OnUpdateEntity (Entity entity, Timestep ts)
344
333
{
345
334
UUID entityUUID = entity.GetUUID ();
346
- SE_CORE_ASSERT (s_Data->EntityInstances .find (entityUUID) != s_Data->EntityInstances .end ());
347
-
348
- Ref<ScriptInstance> instance = s_Data->EntityInstances [entityUUID];
349
- instance->InvokeOnUpdate ((float )ts);
335
+ if (s_Data->EntityInstances .find (entityUUID) != s_Data->EntityInstances .end ())
336
+ {
337
+ Ref<ScriptInstance> instance = s_Data->EntityInstances [entityUUID];
338
+ instance->InvokeOnUpdate ((float )ts);
339
+ }
340
+ else
341
+ {
342
+ SE_CORE_ERROR (" Could not find ScriptInstance for entity {0}" , entityUUID);
343
+ }
350
344
}
351
345
352
346
Scene* ScriptEngine::GetSceneContext ()
0 commit comments