|
|
|
|
@ -17,6 +17,13 @@
|
|
|
|
|
#include <renderer/frame_buffer.h>
|
|
|
|
|
#include <renderer/orthographic_camera.h>
|
|
|
|
|
#include "entity.h"
|
|
|
|
|
#include <scripting/wren_script.h>
|
|
|
|
|
|
|
|
|
|
#define LOAD_ASSETS_FROM_EDITOR true
|
|
|
|
|
#if LOAD_ASSETS_FROM_EDITOR
|
|
|
|
|
#include <editor/contents/content_manager.h>
|
|
|
|
|
#include <editor/contents/script.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
@ -27,15 +34,16 @@ namespace lunarium
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
World::World(std::string name)
|
|
|
|
|
: mUUID(UUID::GetNewID()), mName(name), mpActiveCamera(nullptr), mFrameBuffer(nullptr)
|
|
|
|
|
: mUUID(UUID::GetNewID()), mName(name), mpActiveCamera(nullptr), mFrameBuffer(nullptr),
|
|
|
|
|
mGetAssetsFromEditor(LOAD_ASSETS_FROM_EDITOR)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
InitScriptState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::InitScriptState()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
mScriptState.Initialize().LogIfFailed(LogCategory::GAME_SYSTEM, "Failed to initialize the world script state");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void World::OnLoad()
|
|
|
|
|
@ -60,9 +68,25 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
void World::Update(float dt)
|
|
|
|
|
{
|
|
|
|
|
auto group = mECSRegistry.group<>(entt::get<VelocityComponent, TransformComponent>);
|
|
|
|
|
// Update all scripts
|
|
|
|
|
auto group_scripts = mECSRegistry.view<ScriptComponent>();
|
|
|
|
|
for(auto entity: group_scripts)
|
|
|
|
|
{
|
|
|
|
|
auto& script_comp = group_scripts.get<ScriptComponent>(entity);
|
|
|
|
|
|
|
|
|
|
// Render the group
|
|
|
|
|
#if LOAD_ASSETS_FROM_EDITOR
|
|
|
|
|
|
|
|
|
|
editor::Script* pScript = (editor::Script*) editor::ContentManager::GetInstance().GetAsset(script_comp.ScriptID);
|
|
|
|
|
|
|
|
|
|
WrenScript script(pScript->GetScriptFile().filename().string().c_str(), pScript->GetScript());
|
|
|
|
|
|
|
|
|
|
mScriptState.RunScript(&script);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update Transforms for any enity with a velocity
|
|
|
|
|
auto group = mECSRegistry.group<>(entt::get<VelocityComponent, TransformComponent>);
|
|
|
|
|
for(auto entity: group)
|
|
|
|
|
{
|
|
|
|
|
auto &transform = group.get<TransformComponent>(entity);
|
|
|
|
|
|