Fixed exit crash(es)

This commit is contained in:
2016-01-06 11:20:16 +01:00
parent c133223bac
commit 34cbbb3eb1
5 changed files with 21 additions and 49 deletions
+5
View File
@@ -7,10 +7,13 @@
class System class System
{ {
friend class SystemPipeline;
protected: protected:
System(EventBroker* eventBroker) System(EventBroker* eventBroker)
: m_EventBroker(eventBroker) : m_EventBroker(eventBroker)
{ } { }
virtual ~System() = default;
EventBroker* m_EventBroker; EventBroker* m_EventBroker;
}; };
@@ -24,6 +27,7 @@ protected:
: System(eventBroker) : System(eventBroker)
, m_ComponentType(componentType) , m_ComponentType(componentType)
{ } { }
virtual ~PureSystem() = default;
const std::string m_ComponentType; const std::string m_ComponentType;
@@ -38,6 +42,7 @@ protected:
ImpureSystem(EventBroker* eventBroker) ImpureSystem(EventBroker* eventBroker)
: System(eventBroker) : System(eventBroker)
{ } { }
virtual ~ImpureSystem() = default;
virtual void Update(World* world, double dt) = 0; virtual void Update(World* world, double dt) = 0;
}; };
+2 -4
View File
@@ -14,10 +14,8 @@ public:
{ } { }
~SystemPipeline() ~SystemPipeline()
{ {
for (auto& pair : m_PureSystems) { for (auto& pair : m_Systems) {
for (auto& system : pair.second) { delete pair.second;
delete system;
}
} }
} }
+3
View File
@@ -12,6 +12,7 @@
#include "../Core/World.h" #include "../Core/World.h"
#include "PickingPass.h" #include "PickingPass.h"
#include "DrawScenePass.h" #include "DrawScenePass.h"
#include "DebugCameraInputController.h"
#define TILE_SIZE 16 #define TILE_SIZE 16
@@ -45,6 +46,8 @@ private:
//----------------------Variables----------------------// //----------------------Variables----------------------//
EventBroker* m_EventBroker; EventBroker* m_EventBroker;
std::shared_ptr<DebugCameraInputController<Renderer>> m_DebugCameraInputController;
Texture* m_ErrorTexture; Texture* m_ErrorTexture;
Texture* m_WhiteTexture; Texture* m_WhiteTexture;
float m_CameraMoveSpeed; float m_CameraMoveSpeed;
+4 -6
View File
@@ -1,5 +1,4 @@
#include "Rendering/Renderer.h" #include "Rendering/Renderer.h"
#include "Rendering/DebugCameraInputController.h"
void Renderer::Initialize() void Renderer::Initialize()
{ {
@@ -10,6 +9,7 @@ void Renderer::Initialize()
if (m_Camera == nullptr) { if (m_Camera == nullptr) {
m_Camera = m_DefaultCamera; m_Camera = m_DefaultCamera;
} }
m_DebugCameraInputController = std::make_shared<DebugCameraInputController<Renderer>>(m_EventBroker, -1);
TEMPCreateLights(); TEMPCreateLights();
InitializeRenderPasses(); InitializeRenderPasses();
@@ -89,8 +89,6 @@ void Renderer::InitializeShaders()
void Renderer::InputUpdate(double dt) void Renderer::InputUpdate(double dt)
{ {
static DebugCameraInputController<Renderer> firstPersonInputController(m_EventBroker, -1);
glm::vec3 m_Position = m_Camera->Position(); glm::vec3 m_Position = m_Camera->Position();
if (glfwGetKey(m_Window, GLFW_KEY_O) == GLFW_PRESS) if (glfwGetKey(m_Window, GLFW_KEY_O) == GLFW_PRESS)
{ {
@@ -120,9 +118,9 @@ void Renderer::InputUpdate(double dt)
m_CameraMoveSpeed = 0.5f; m_CameraMoveSpeed = 0.5f;
} }
firstPersonInputController.Update(dt); m_DebugCameraInputController->Update(dt);
m_Camera->SetOrientation(firstPersonInputController.Orientation()); m_Camera->SetOrientation(m_DebugCameraInputController->Orientation());
m_Camera->SetPosition(firstPersonInputController.Position()); m_Camera->SetPosition(m_DebugCameraInputController->Position());
} }
void Renderer::Update(double dt) void Renderer::Update(double dt)
+7 -39
View File
@@ -27,7 +27,7 @@ Game::Game(int argc, char* argv[])
0, 0,
m_Config->Get<int>("Video.Width", 1280), m_Config->Get<int>("Video.Width", 1280),
m_Config->Get<int>("Video.Height", 720) m_Config->Get<int>("Video.Height", 720)
)); ));
m_Renderer->Initialize(); m_Renderer->Initialize();
m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f))); m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
@@ -64,17 +64,17 @@ Game::Game(int argc, char* argv[])
networkFunction(); networkFunction();
} }
m_LastTime = glfwGetTime(); m_LastTime = glfwGetTime();
debugInitialize();
} }
Game::~Game() Game::~Game()
{ {
// Call before to ensure that thread closes correctly. delete m_SystemPipeline;
//if (m_IsClientOrServer) delete m_World;
// m_ClientOrServer.Close();
delete m_FrameStack; delete m_FrameStack;
delete m_InputProxy;
delete m_InputManager;
delete m_Renderer;
delete m_RenderQueueFactory;
delete m_EventBroker; delete m_EventBroker;
} }
@@ -103,7 +103,6 @@ void Game::Tick()
// Iterate through systems and update world! // Iterate through systems and update world!
m_SystemPipeline->Update(m_World, dt); m_SystemPipeline->Update(m_World, dt);
debugTick(dt);
m_Renderer->Update(dt); m_Renderer->Update(dt);
m_EventBroker->Process<Client>(); m_EventBroker->Process<Client>();
@@ -115,37 +114,6 @@ void Game::Tick()
m_EventBroker->Clear(); m_EventBroker->Clear();
} }
bool Game::debugOnInputCommand(const Events::InputCommand& e)
{
if (e.Command == "DebugReload" && e.Value == 1) {
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
if (!mapToLoad.empty()) {
delete m_World;
m_World = new World();
ResourceManager::Release("EntityXMLFile", mapToLoad);
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
}
}
if (e.Command == "SwitchToServer" && e.Value > 0) {
m_ClientOrServer = new Server();
LOG_INFO("Switching to server");
m_ClientOrServer->Start(m_World, m_EventBroker);
}
if (e.Command == "SwitchToClient" && e.Value > 0) {
m_ClientOrServer = new Client(m_Config);
m_ClientOrServer->Start(m_World, m_EventBroker);
LOG_INFO("Switching to client");
}
return false;
}
void Game::debugInitialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Game::debugOnInputCommand);
}
void Game::debugTick(double dt) void Game::debugTick(double dt)
{ {
m_EventBroker->Process<Game>(); m_EventBroker->Process<Game>();