Added error handling in wren. Game while abort lauching and print error in logger
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<TransformComponent, RigidBodyComponent>();
|
||||
@@ -83,6 +83,7 @@ void PhysicsSystem::Init()
|
||||
|
||||
PhysicsManager::Get()->RegisterGhostBody(ghostBody);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PhysicsSystem::Update(Timestep ts)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Mesh>(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<Mesh>(vertices, indices, DefaultMaterial));
|
||||
else
|
||||
|
||||
@@ -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<WrenScriptComponent>(e);
|
||||
if (wren.Script != "" && wren.Class != "")
|
||||
{
|
||||
wren.WrenScript = CreateRef<WrenScript>(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -7,7 +7,7 @@ class System {
|
||||
public:
|
||||
Scene* m_Scene;
|
||||
|
||||
virtual void Init() = 0;
|
||||
virtual bool Init() = 0;
|
||||
|
||||
virtual void Draw() = 0;
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ TrenchbroomSystem::TrenchbroomSystem(Scene* scene)
|
||||
m_Scene = scene;
|
||||
}
|
||||
|
||||
void TrenchbroomSystem::Init()
|
||||
bool TrenchbroomSystem::Init()
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TrenchbroomSystem::Update(Timestep ts)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user