diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index 0e0a599d..852039fd 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -73,9 +73,10 @@ void Engine::EnterPlayMode() { // Dont trigger init if already in player mode. if (!IsPlayMode) - GetCurrentScene()->OnInit(); - - IsPlayMode = true; + if(GetCurrentScene()->OnInit()) + IsPlayMode = true; + else + GetCurrentScene()->OnExit(); } void Engine::ExitPlayMode() @@ -86,6 +87,7 @@ void Engine::ExitPlayMode() Input::ShowMouse(); } + Input::ShowMouse(); IsPlayMode = false; } diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 40ce5dec..ac63f5c2 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -76,16 +76,22 @@ Entity Scene::GetEntityByID(int id) } } -void Scene::OnInit() +bool Scene::OnInit() { for (auto& system : m_Systems) - system->Init(); + if(!system->Init()) + { + return false; + } + + return true; } void Scene::OnExit() { for (auto& system : m_Systems) system->Exit(); + } void Scene::Update(Timestep ts) diff --git a/Nuake/src/Scene/Scene.h b/Nuake/src/Scene/Scene.h index 6c1e44b9..bf457df0 100644 --- a/Nuake/src/Scene/Scene.h +++ b/Nuake/src/Scene/Scene.h @@ -44,7 +44,7 @@ public: Entity GetEntity(int handle); Entity GetEntityByID(int id); void Init(); - void OnInit(); + bool OnInit(); void OnExit(); void Update(Timestep ts); void FixedUpdate(Timestep ts); diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 3c2c9d08..5fdf8bb2 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -16,7 +16,7 @@ PhysicsSystem::PhysicsSystem(Scene* scene) m_Scene = scene; } -void PhysicsSystem::Init() +bool PhysicsSystem::Init() { // Create physic world. auto view = m_Scene->m_Registry.view(); @@ -83,6 +83,7 @@ void PhysicsSystem::Init() PhysicsManager::Get()->RegisterGhostBody(ghostBody); } + return true; } void PhysicsSystem::Update(Timestep ts) diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.h b/Nuake/src/Scene/Systems/PhysicsSystem.h index a76ca83b..4a405168 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.h +++ b/Nuake/src/Scene/Systems/PhysicsSystem.h @@ -4,7 +4,7 @@ class PhysicsSystem : public System { public: PhysicsSystem(Scene* scene); - void Init() override; + bool Init() override; void Update(Timestep ts) override; void Draw() override {} void FixedUpdate(Timestep ts) override; diff --git a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp index a696dd89..edb0eea1 100644 --- a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp +++ b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp @@ -120,6 +120,7 @@ void QuakeMapBuilder::CreateBrush(brush* brush, brush_geometry* brush_inst, Scen { face* face = &brush->faces[f]; texture_data* texture = &textures[face->texture_idx]; + if (std::string(texture->name) == "__TB_empty") { texture->height = 1; @@ -127,7 +128,7 @@ void QuakeMapBuilder::CreateBrush(brush* brush, brush_geometry* brush_inst, Scen } else { - std::string path = "resources/Textures/" + std::string(texture->name) + ".png"; + std::string path = FileSystem::Root + "textures/" + std::string(texture->name) + ".png"; auto tex = TextureManager::Get()->GetTexture(path); texture->height = tex->GetHeight(); @@ -157,7 +158,7 @@ void QuakeMapBuilder::CreateBrush(brush* brush, brush_geometry* brush_inst, Scen vertexNormal, vertexTangent, glm::vec3(0.0, 1.0, 0.0), 0.0f - }); + }); } for (int i = 0; i < (face_geo_inst->vertex_count - 2) * 3; ++i) @@ -168,7 +169,7 @@ void QuakeMapBuilder::CreateBrush(brush* brush, brush_geometry* brush_inst, Scen if (lastTextureID != face->texture_idx) { - lastTexturePath = "resources/Textures/" + std::string(texture->name) + ".png"; + lastTexturePath = FileSystem::Root + "textures/" + std::string(texture->name) + ".png"; if (std::string(texture->name) == "__TB_empty") bsp.Meshes.push_back(CreateRef(vertices, indices, DefaultMaterial)); @@ -246,7 +247,7 @@ void QuakeMapBuilder::CreateFuncBrush(brush* brush, brush_geometry* brush_inst, } else { - std::string path = "resources/Textures/" + std::string(texture->name) + ".png"; + std::string path = FileSystem::Root + std::string(texture->name) + ".png"; auto tex = TextureManager::Get()->GetTexture(path); texture->height = tex->GetHeight(); texture->width = tex->GetWidth(); @@ -291,7 +292,7 @@ void QuakeMapBuilder::CreateFuncBrush(brush* brush, brush_geometry* brush_inst, { if (lastTextureID != face->texture_idx) { - lastTexturePath = "resources/Textures/" + std::string(texture->name) + ".png"; + lastTexturePath = FileSystem::Root + "textures/" + std::string(texture->name) + ".png"; if (std::string(texture->name) == "__TB_empty") bsp.Meshes.push_back(CreateRef(vertices, indices, DefaultMaterial)); else diff --git a/Nuake/src/Scene/Systems/ScriptingSystem.cpp b/Nuake/src/Scene/Systems/ScriptingSystem.cpp index e873a2c8..6b5d6358 100644 --- a/Nuake/src/Scene/Systems/ScriptingSystem.cpp +++ b/Nuake/src/Scene/Systems/ScriptingSystem.cpp @@ -7,7 +7,7 @@ ScriptingSystem::ScriptingSystem(Scene* scene) m_Scene = scene; } -void ScriptingSystem::Init() +bool ScriptingSystem::Init() { ScriptingEngine::Init(); @@ -16,7 +16,11 @@ void ScriptingSystem::Init() { WrenScriptComponent& wren = entities.get(e); if (wren.Script != "" && wren.Class != "") + { wren.WrenScript = CreateRef(wren.Script, wren.Class, true); + if (!wren.WrenScript->CompiledSuccesfully) + return false; + } if (wren.WrenScript != nullptr) { @@ -24,6 +28,8 @@ void ScriptingSystem::Init() wren.WrenScript->CallInit(); } } + + return true; } diff --git a/Nuake/src/Scene/Systems/ScriptingSystem.h b/Nuake/src/Scene/Systems/ScriptingSystem.h index 07572319..ceba23ad 100644 --- a/Nuake/src/Scene/Systems/ScriptingSystem.h +++ b/Nuake/src/Scene/Systems/ScriptingSystem.h @@ -5,7 +5,7 @@ class Scene; class ScriptingSystem : public System { public: ScriptingSystem(Scene* scene); - void Init() override; + bool Init() override; void Update(Timestep ts) override; void Draw() override {} void FixedUpdate(Timestep ts) override; diff --git a/Nuake/src/Scene/Systems/System.h b/Nuake/src/Scene/Systems/System.h index 958fbe84..b032132b 100644 --- a/Nuake/src/Scene/Systems/System.h +++ b/Nuake/src/Scene/Systems/System.h @@ -7,7 +7,7 @@ class System { public: Scene* m_Scene; - virtual void Init() = 0; + virtual bool Init() = 0; virtual void Draw() = 0; diff --git a/Nuake/src/Scene/Systems/TrenchbroomSystem.cpp b/Nuake/src/Scene/Systems/TrenchbroomSystem.cpp index 65d51d2e..dc3f5579 100644 --- a/Nuake/src/Scene/Systems/TrenchbroomSystem.cpp +++ b/Nuake/src/Scene/Systems/TrenchbroomSystem.cpp @@ -6,9 +6,9 @@ TrenchbroomSystem::TrenchbroomSystem(Scene* scene) m_Scene = scene; } -void TrenchbroomSystem::Init() +bool TrenchbroomSystem::Init() { - + return true; } void TrenchbroomSystem::Update(Timestep ts) diff --git a/Nuake/src/Scene/Systems/TrenchbroomSystem.h b/Nuake/src/Scene/Systems/TrenchbroomSystem.h index bf1b48be..e923986d 100644 --- a/Nuake/src/Scene/Systems/TrenchbroomSystem.h +++ b/Nuake/src/Scene/Systems/TrenchbroomSystem.h @@ -4,7 +4,7 @@ class TrenchbroomSystem : public System { public: TrenchbroomSystem(Scene* scene); - void Init() override; + bool Init() override; void Update(Timestep ts) override; void Draw() override {} void FixedUpdate(Timestep ts) override; diff --git a/Nuake/src/Scripting/ScriptingEngine.cpp b/Nuake/src/Scripting/ScriptingEngine.cpp index 45d97b7c..41fdc683 100644 --- a/Nuake/src/Scripting/ScriptingEngine.cpp +++ b/Nuake/src/Scripting/ScriptingEngine.cpp @@ -23,13 +23,13 @@ void errorFn(WrenVM* vm, WrenErrorType errorType, { case WREN_ERROR_COMPILE: { - std::string t = "Script error in: " + std::string(module)+ " line:" + std::to_string(line) + " \n error: "+ msg; + std::string t = std::string(module)+ " line " + std::to_string(line) + ": "+ msg; Logger::Log(t, CRITICAL); Engine::ExitPlayMode(); } break; case WREN_ERROR_STACK_TRACE: { - std::string t = "Script Stack trace: " + std::string(module) + " line:" + std::to_string(line) + " \n stack: " + msg; + std::string t = "Stack trace: " + std::string(module) + " line " + std::to_string(line) + ": " + msg; Logger::Log(t, CRITICAL); } break; case WREN_ERROR_RUNTIME: diff --git a/Nuake/src/Scripting/WrenScript.cpp b/Nuake/src/Scripting/WrenScript.cpp index 01b369bf..a96e4c77 100644 --- a/Nuake/src/Scripting/WrenScript.cpp +++ b/Nuake/src/Scripting/WrenScript.cpp @@ -9,8 +9,15 @@ WrenScript::WrenScript(const std::string& path, const std::string& mod, bool isE // Import statement std::string source = "import \"" + path + "\" for " + mod; + CompiledSuccesfully = true; + // Import file as module - wrenInterpret(vm, "main", source.c_str()); + WrenInterpretResult result = wrenInterpret(vm, "main", source.c_str()); + if (result != WREN_RESULT_SUCCESS) + CompiledSuccesfully = false; + + if (!CompiledSuccesfully) + return; // Get handle to class wrenEnsureSlots(vm, 1); @@ -61,6 +68,9 @@ void WrenScript::CallFixedUpdate(float timestep) void WrenScript::CallExit() { + if (!CompiledSuccesfully) + return; + WrenVM* vm = ScriptingEngine::GetWrenVM(); wrenEnsureSlots(vm, 1); wrenSetSlotHandle(vm, 0, this->m_Instance); diff --git a/Nuake/src/Scripting/WrenScript.h b/Nuake/src/Scripting/WrenScript.h index 87424069..1b24769d 100644 --- a/Nuake/src/Scripting/WrenScript.h +++ b/Nuake/src/Scripting/WrenScript.h @@ -15,6 +15,8 @@ public: WrenHandle* m_OnExitHandle; WrenHandle* m_SetEntityIDHandle; + bool CompiledSuccesfully; + WrenScript(const std::string& path, const std::string& mod, bool isEntity = false); void CallInit();