|
|
|
|
@ -42,34 +42,8 @@ namespace lunarium
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::InitScriptState()
|
|
|
|
|
{
|
|
|
|
|
// mScriptState.Initialize().LogIfFailed(LogCategory::GAME_SYSTEM, "Failed to initialize the world script state");
|
|
|
|
|
|
|
|
|
|
// // Register foreign methods
|
|
|
|
|
// mScriptState.RegisterForeignMethod({"WorldInterface", "WorldInterface", true, "GetComponent(_,_)", (WrenForeignMethodFn)&World::GetVelocityComponent});
|
|
|
|
|
|
|
|
|
|
// // Load the world interface script
|
|
|
|
|
// mWorldInterface.SetModuleName("WorldInterface");
|
|
|
|
|
// std::string code = File::ReadTextFile("world_interface.wren"); // This will eventually move to internal data
|
|
|
|
|
// mWorldInterface.SetScriptCode(code);
|
|
|
|
|
|
|
|
|
|
// mScriptState.RunScript(&mWorldInterface);
|
|
|
|
|
|
|
|
|
|
// // 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()
|
|
|
|
|
{
|
|
|
|
|
// InitScriptState();
|
|
|
|
|
|
|
|
|
|
WorldAPI::Initialize(this).LogIfFailed(LogCategory::GAME_SYSTEM, "Failed to initialized the world scripting api");
|
|
|
|
|
|
|
|
|
|
@ -90,17 +64,13 @@ namespace lunarium
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call OnLoad for each registered EntityBehavior class object
|
|
|
|
|
//mScriptState.CallWrenMethod(mWIDoOnLoadMethod, mWIHandle, {}, "WorldInterface.DoOnLoad()");
|
|
|
|
|
WorldAPI::InvokeEvent(WorldAPI::Event::ON_LOAD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void World::OnUnload()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Call OnUnLoad for each registered EntityBehavior class object
|
|
|
|
|
//mScriptState.CallWrenMethod(mWIDoOnUnloadMethod, mWIHandle, {}, "WorldInterface.DoOnUnload()");
|
|
|
|
|
// Call OnUnLoad for each registered EntityBehavior class object
|
|
|
|
|
WorldAPI::InvokeEvent(WorldAPI::Event::ON_UNLOAD);
|
|
|
|
|
|
|
|
|
|
//mScriptState.Shutdown();
|
|
|
|
|
WorldAPI::Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -118,7 +88,6 @@ namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
// Update all scripts
|
|
|
|
|
// Call Update for each registered EntityBehavior class object
|
|
|
|
|
//mScriptState.CallWrenMethod(mWIUpdateMethod, mWIHandle, { {WrenParamType::WPT_DOUBLE, (double)dt} }, "WorldInterface.Update(dt)");
|
|
|
|
|
WorldAPI::InvokeEvent(WorldAPI::Event::ON_UPDATE, dt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -176,6 +145,10 @@ namespace lunarium
|
|
|
|
|
mpActiveCamera = pCam;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
// ENTITY API
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
entt::registry* World::GetEntityRegistry()
|
|
|
|
|
{
|
|
|
|
|
return &mECSRegistry;
|
|
|
|
|
@ -245,37 +218,37 @@ namespace lunarium
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::DrawHeirarchy(lunarium::Renderer2D* g, entt::entity& entity, TransformComponent& my_trans, BlockOutComponent& bo_comp, glm::mat4 current_transform)
|
|
|
|
|
{
|
|
|
|
|
// Draw current entity
|
|
|
|
|
Rectangle rect(my_trans.Position.x, my_trans.Position.y, bo_comp.Size.x, bo_comp.Size.y);
|
|
|
|
|
Color color(bo_comp.Color.x, bo_comp.Color.y, bo_comp.Color.z, bo_comp.Color.w);
|
|
|
|
|
g->DrawQuad(rect, color, nullptr, -my_trans.Rotation.z, Rectangle(-1, -1, -1, -1), current_transform);
|
|
|
|
|
|
|
|
|
|
// Apply transform to children's transforms
|
|
|
|
|
current_transform *= my_trans.GetTransform();
|
|
|
|
|
|
|
|
|
|
// Iterate and draw children
|
|
|
|
|
if (mECSRegistry.all_of<ChildrenComponent>(entity))
|
|
|
|
|
{
|
|
|
|
|
ChildrenComponent& children_comp = mECSRegistry.get<ChildrenComponent>(entity);
|
|
|
|
|
for (int i = 0; i < children_comp.Children.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
Entity* pEnt = GetEntity(children_comp.Children[i]);
|
|
|
|
|
entt::entity handle = pEnt->GetEnttHandle();
|
|
|
|
|
|
|
|
|
|
if (pEnt->HasComponent<TransformComponent>() && pEnt->HasComponent<BlockOutComponent>())
|
|
|
|
|
{
|
|
|
|
|
TransformComponent& trans_comp = pEnt->GetComponent<TransformComponent>();
|
|
|
|
|
BlockOutComponent& bo_comp = pEnt->GetComponent<BlockOutComponent>();
|
|
|
|
|
|
|
|
|
|
DrawHeirarchy(g, handle, trans_comp, bo_comp, current_transform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// void World::DrawHeirarchy(lunarium::Renderer2D* g, entt::entity& entity, TransformComponent& my_trans, BlockOutComponent& bo_comp, glm::mat4 current_transform)
|
|
|
|
|
// {
|
|
|
|
|
// // Draw current entity
|
|
|
|
|
// Rectangle rect(my_trans.Position.x, my_trans.Position.y, bo_comp.Size.x, bo_comp.Size.y);
|
|
|
|
|
// Color color(bo_comp.Color.x, bo_comp.Color.y, bo_comp.Color.z, bo_comp.Color.w);
|
|
|
|
|
// g->DrawQuad(rect, color, nullptr, -my_trans.Rotation.z, Rectangle(-1, -1, -1, -1), current_transform);
|
|
|
|
|
|
|
|
|
|
// // Apply transform to children's transforms
|
|
|
|
|
// current_transform *= my_trans.GetTransform();
|
|
|
|
|
|
|
|
|
|
// // Iterate and draw children
|
|
|
|
|
// if (mECSRegistry.all_of<ChildrenComponent>(entity))
|
|
|
|
|
// {
|
|
|
|
|
// ChildrenComponent& children_comp = mECSRegistry.get<ChildrenComponent>(entity);
|
|
|
|
|
// for (int i = 0; i < children_comp.Children.size(); i++)
|
|
|
|
|
// {
|
|
|
|
|
// Entity* pEnt = GetEntity(children_comp.Children[i]);
|
|
|
|
|
// entt::entity handle = pEnt->GetEnttHandle();
|
|
|
|
|
|
|
|
|
|
// if (pEnt->HasComponent<TransformComponent>() && pEnt->HasComponent<BlockOutComponent>())
|
|
|
|
|
// {
|
|
|
|
|
// TransformComponent& trans_comp = pEnt->GetComponent<TransformComponent>();
|
|
|
|
|
// BlockOutComponent& bo_comp = pEnt->GetComponent<BlockOutComponent>();
|
|
|
|
|
|
|
|
|
|
// DrawHeirarchy(g, handle, trans_comp, bo_comp, current_transform);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
glm::mat4 World::GetParentTransform(LUUID parent)
|
|
|
|
|
{
|
|
|
|
|
|