diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 3b1a4382..1a693bc4 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -22,6 +22,8 @@ namespace Nuake bool PhysicsSystem::Init() { + Logger::Log("Initializing the physic system"); + // We need to initialize shapes first, then bodies... InitializeShapes(); @@ -42,7 +44,7 @@ namespace Nuake // PhysicsManager::Get()->RegisterGhostBody(ghostBody); //} - + Logger::Log("Physic system initialized successfully"); return true; } diff --git a/Nuake/src/Scene/Systems/ScriptingSystem.cpp b/Nuake/src/Scene/Systems/ScriptingSystem.cpp index 7c9ff076..5c9cfe2a 100644 --- a/Nuake/src/Scene/Systems/ScriptingSystem.cpp +++ b/Nuake/src/Scene/Systems/ScriptingSystem.cpp @@ -13,6 +13,8 @@ namespace Nuake { { ScriptingEngine::Init(); + Logger::Log("Initializing ScriptingSystem"); + auto& entities = m_Scene->m_Registry.view(); for (auto& e : entities) { @@ -24,7 +26,10 @@ namespace Nuake { wren.mWrenScript->Build(wren.mModule, true); if (!wren.mWrenScript->HasCompiledSuccesfully()) + { + Logger::Log("ScriptingSystem failed"); return false; + } wren.mWrenScript->SetScriptableEntityID((int)e); wren.mWrenScript->CallInit(); @@ -69,8 +74,15 @@ namespace Nuake { { WrenScriptComponent& wren = entities.get(e); - if (wren.mWrenScript != nullptr) - wren.mWrenScript->CallExit(); + try + { + if (wren.mWrenScript != nullptr) + wren.mWrenScript->CallExit(); + } + catch (std::exception* e) + { + } + } ScriptingEngine::Close(); diff --git a/Nuake/src/Scripting/ScriptingEngine.cpp b/Nuake/src/Scripting/ScriptingEngine.cpp index ebe508f6..4755d6a8 100644 --- a/Nuake/src/Scripting/ScriptingEngine.cpp +++ b/Nuake/src/Scripting/ScriptingEngine.cpp @@ -19,6 +19,7 @@ namespace Nuake { const char* module, const int line, const char* msg) { + Logger::Log("YO"); switch (errorType) { case WREN_ERROR_COMPILE: @@ -37,6 +38,12 @@ namespace Nuake { std::string t = "Script Runtime Error: " + std::string(msg); Logger::Log(t, WARNING); } break; + default: + { + std::string t = "Script Runtime Error: " + std::string(msg); + Logger::Log(t, CRITICAL); + } + break; } } @@ -143,6 +150,7 @@ namespace Nuake { void ScriptingEngine::Init() { + Logger::Log("Initializing Scripting Engine"); m_Scripts = std::map>(); m_LoadedScripts.clear(); @@ -156,6 +164,7 @@ namespace Nuake { m_WrenVM = wrenNewVM(&config); + Logger::Log("Registing Scripting Modules"); Ref engineModule = CreateRef(); RegisterModule(engineModule); Ref sceneModule = CreateRef(); @@ -166,6 +175,8 @@ namespace Nuake { RegisterModule(inputModule); Ref physicsModule = CreateRef(); RegisterModule(physicsModule); + Logger::Log("Scripting Modules Registered"); + Logger::Log("Scripting Engine initialized successfully"); } void ScriptingEngine::Close() diff --git a/Nuake/src/Scripting/WrenScript.cpp b/Nuake/src/Scripting/WrenScript.cpp index 687f8937..fc544ee6 100644 --- a/Nuake/src/Scripting/WrenScript.cpp +++ b/Nuake/src/Scripting/WrenScript.cpp @@ -1,4 +1,6 @@ #include "WrenScript.h" + +#include "src/Core/Logger.h" #include "src/Core/String.h" #include @@ -48,19 +50,27 @@ namespace Nuake { WrenVM* vm = ScriptingEngine::GetWrenVM(); std::string relativePath = mFile->GetRelativePath(); + // Can't import twice the same script, otherwise gives a compile error. if (!ScriptingEngine::IsScriptImported(relativePath)) { std::string source = "import \"" + relativePath + "\" for " + GetModules()[moduleId]; WrenInterpretResult result = wrenInterpret(vm, "main", source.c_str()); - if (result != WREN_RESULT_SUCCESS) + + Logger::Log("Wren result: " + std::to_string(result)); + if (result == WREN_RESULT_SUCCESS) + { + Logger::Log("Wren result success: " + std::to_string(result)); + CompiledSuccesfully = true; + ScriptingEngine::ImportScript(relativePath); + } + else + { + Logger::Log("Wren result failed: " + std::to_string(result)); CompiledSuccesfully = false; - - if (!CompiledSuccesfully) return; - - ScriptingEngine::ImportScript(relativePath); + } } // Get handle to class diff --git a/Nuake/src/Scripting/WrenScript.h b/Nuake/src/Scripting/WrenScript.h index 7364c128..e4abe168 100644 --- a/Nuake/src/Scripting/WrenScript.h +++ b/Nuake/src/Scripting/WrenScript.h @@ -19,7 +19,7 @@ namespace Nuake { Ref mFile; std::map methods; - WrenHandle* m_Instance; + WrenHandle* m_Instance = nullptr; WrenHandle* m_OnInitHandle; WrenHandle* m_OnUpdateHandle; WrenHandle* m_OnFixedUpdateHandle;