|
|
|
@ -45,13 +45,22 @@ namespace lunarium
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mScriptState.Initialize().LogIfFailed(LogCategory::GAME_SYSTEM, "Failed to initialize the world script state");
|
|
|
|
mScriptState.Initialize().LogIfFailed(LogCategory::GAME_SYSTEM, "Failed to initialize the world script state");
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Load the world interface script
|
|
|
|
// Load the world interface script
|
|
|
|
mWorldInterface.SetModuleName("WorldInterface");
|
|
|
|
mWorldInterface.SetModuleName("WorldInterface");
|
|
|
|
std::string code = File::ReadTextFile("world_interface.wren"); // This will eventually move to internal data
|
|
|
|
std::string code = File::ReadTextFile("world_interface.wren"); // This will eventually move to internal data
|
|
|
|
mWorldInterface.SetScriptCode(code);
|
|
|
|
mWorldInterface.SetScriptCode(code);
|
|
|
|
|
|
|
|
|
|
|
|
mScriptState.RunScript(&mWorldInterface);
|
|
|
|
mScriptState.RunScript(&mWorldInterface);
|
|
|
|
mScriptState.RunSnippet("WorldInterface", "WorldInterface.Init()");
|
|
|
|
|
|
|
|
|
|
|
|
// Get class and method handles
|
|
|
|
|
|
|
|
mWIHandle = mScriptState.GetWrenClassHandle("WorldInterface", "WorldInterface");
|
|
|
|
|
|
|
|
mWIInitMethod = mScriptState.GetWrenMethodHandle("Init()");
|
|
|
|
|
|
|
|
mWIDoOnLoadMethod = mScriptState.GetWrenMethodHandle("DoOnLoad()");
|
|
|
|
|
|
|
|
mWIDoOnUnloadMethod = mScriptState.GetWrenMethodHandle("DoOnUnload()");
|
|
|
|
|
|
|
|
mWIUpdateMethod = mScriptState.GetWrenMethodHandle("Update(_)");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init the interface
|
|
|
|
|
|
|
|
mScriptState.CallWrenMethod(mWIInitMethod, mWIHandle, {}, "WorldInterface.Init()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void World::OnLoad()
|
|
|
|
void World::OnLoad()
|
|
|
|
@ -76,13 +85,15 @@ namespace lunarium
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Call OnLoad for each registered EntityBehavior class object
|
|
|
|
// Call OnLoad for each registered EntityBehavior class object
|
|
|
|
mScriptState.RunSnippet("WorldInterface", "WorldInterface.DoOnLoad()");
|
|
|
|
//mScriptState.RunSnippet("WorldInterface", "WorldInterface.DoOnLoad()");
|
|
|
|
|
|
|
|
mScriptState.CallWrenMethod(mWIDoOnLoadMethod, mWIHandle, {}, "WorldInterface.DoOnLoad()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void World::OnUnload()
|
|
|
|
void World::OnUnload()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO: Call OnUnLoad for each registered EntityBehavior class object
|
|
|
|
// TODO: Call OnUnLoad for each registered EntityBehavior class object
|
|
|
|
mScriptState.RunSnippet("WorldInterface", "WorldInterface.DoOnUnload()");
|
|
|
|
//mScriptState.RunSnippet("WorldInterface", "WorldInterface.DoOnUnload()");
|
|
|
|
|
|
|
|
mScriptState.CallWrenMethod(mWIDoOnUnloadMethod, mWIHandle, {}, "WorldInterface.DoOnUnload()");
|
|
|
|
mScriptState.Shutdown();
|
|
|
|
mScriptState.Shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -100,10 +111,11 @@ namespace lunarium
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Update all scripts
|
|
|
|
// Update all scripts
|
|
|
|
// Call OnUpdate for each registered EntityBehavior class object
|
|
|
|
// Call OnUpdate for each registered EntityBehavior class object
|
|
|
|
std::string code = "WorldInterface.Update(";
|
|
|
|
// std::string code = "WorldInterface.Update(";
|
|
|
|
code.append(std::to_string(dt));
|
|
|
|
// code.append(std::to_string(dt));
|
|
|
|
code.append(")");
|
|
|
|
// code.append(")");
|
|
|
|
mScriptState.RunSnippet("WorldInterface", code);
|
|
|
|
// mScriptState.RunSnippet("WorldInterface", code);
|
|
|
|
|
|
|
|
mScriptState.CallWrenMethod(mWIUpdateMethod, mWIHandle, { {WrenParamType::WPT_DOUBLE, (double)dt} }, "WorldInterface.Update(dt)");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|