WIP world pausing

This commit is contained in:
2016-01-19 00:52:17 +01:00
parent 79eaa7364c
commit 9e3dfff7b6
6 changed files with 72 additions and 13 deletions
+22
View File
@@ -0,0 +1,22 @@
#ifndef EPause_h__
#define EPause_h__
#include "EventBroker.h"
#include "World.h"
namespace Events
{
struct Pause : Event
{
::World* World;
};
struct Resume : Event
{
::World* World;
};
}
#endif
+25 -1
View File
@@ -5,6 +5,7 @@
#include "EventBroker.h" #include "EventBroker.h"
#include "System.h" #include "System.h"
#include "World.h" #include "World.h"
#include "EPause.h"
class SystemPipeline class SystemPipeline
{ {
@@ -12,7 +13,10 @@ public:
SystemPipeline(World* world, EventBroker* eventBroker) SystemPipeline(World* world, EventBroker* eventBroker)
: m_World(world) : m_World(world)
, m_EventBroker(eventBroker) , m_EventBroker(eventBroker)
{ } {
EVENT_SUBSCRIBE_MEMBER(m_EPause, &SystemPipeline::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &SystemPipeline::OnResume);
}
~SystemPipeline() ~SystemPipeline()
{ {
@@ -51,6 +55,10 @@ public:
void Update(double dt) void Update(double dt)
{ {
if (m_Paused) {
dt = 0.0;
}
for (UnorderedSystems& group : m_OrderedSystemGroups) { for (UnorderedSystems& group : m_OrderedSystemGroups) {
// Process events // Process events
for (auto& pair : group.Systems) { for (auto& pair : group.Systems) {
@@ -80,6 +88,7 @@ public:
private: private:
World* m_World; World* m_World;
EventBroker* m_EventBroker; EventBroker* m_EventBroker;
bool m_Paused = false;
struct UnorderedSystems struct UnorderedSystems
{ {
@@ -88,6 +97,21 @@ private:
std::vector<ImpureSystem*> ImpureSystems; std::vector<ImpureSystem*> ImpureSystems;
}; };
std::vector<UnorderedSystems> m_OrderedSystemGroups; std::vector<UnorderedSystems> m_OrderedSystemGroups;
EventRelay<SystemPipeline, Events::Pause> m_EPause;
bool OnPause(const Events::Pause& e) {
if (e.World == m_World) {
m_Paused = true;
}
return true;
}
EventRelay<SystemPipeline, Events::Resume> m_EResume;
bool OnResume(const Events::Resume& e) {
if (e.World == m_World) {
m_Paused = false;
}
return true;
}
}; };
#endif #endif
+4 -2
View File
@@ -14,14 +14,15 @@
#include "../Core/World.h" #include "../Core/World.h"
#include "../Core/EntityWrapper.h" #include "../Core/EntityWrapper.h"
#include "../Core/ResourceManager.h" #include "../Core/ResourceManager.h"
#include "../Core/EPause.h"
#include "../Rendering/Texture.h" #include "../Rendering/Texture.h"
class EditorGUI class EditorGUI
{ {
public: public:
EditorGUI(EventBroker* eventBroker); EditorGUI(World* world, EventBroker* eventBroker);
void Draw(World* world); void Draw();
void SelectEntity(EntityWrapper entity); void SelectEntity(EntityWrapper entity);
@@ -57,6 +58,7 @@ public:
void SetComponentDeleteCallback(OnComponentDelete_t f) { m_OnComponentDelete = f; } void SetComponentDeleteCallback(OnComponentDelete_t f) { m_OnComponentDelete = f; }
private: private:
World* m_World;
EventBroker* m_EventBroker; EventBroker* m_EventBroker;
// Config variables // Config variables
+18 -7
View File
@@ -1,17 +1,18 @@
#include "Editor/EditorGUI.h" #include "Editor/EditorGUI.h"
EditorGUI::EditorGUI(EventBroker* eventBroker) EditorGUI::EditorGUI(World* world, EventBroker* eventBroker)
: m_EventBroker(eventBroker) : m_World(world)
, m_EventBroker(eventBroker)
{ {
} }
void EditorGUI::Draw(World* world) void EditorGUI::Draw()
{ {
ImGui::ShowTestWindow(); ImGui::ShowTestWindow();
drawMenu(); drawMenu();
drawTools(); drawTools();
drawEntities(world); drawEntities(m_World);
drawComponents(m_CurrentSelection); drawComponents(m_CurrentSelection);
} }
@@ -65,10 +66,20 @@ void EditorGUI::drawTools()
pauseIcon = ResourceManager::Load<Texture>("Textures/Icons/Pause.png")->m_Texture; pauseIcon = ResourceManager::Load<Texture>("Textures/Icons/Pause.png")->m_Texture;
} catch (const std::exception&) { } } catch (const std::exception&) { }
static bool paused = false;
ImGui::ImageButton((void*)playIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), ImVec4(0, 1, 0, 1)); if (ImGui::ImageButton((void*)playIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (!paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) {
Events::Resume e;
e.World = m_World;
m_EventBroker->Publish(e);
paused = false;
}
ImGui::SameLine(); ImGui::SameLine();
ImGui::ImageButton((void*)pauseIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0)); if (ImGui::ImageButton((void*)pauseIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) {
Events::Pause e;
e.World = m_World;
m_EventBroker->Publish(e);
paused = true;
}
ImGui::End(); ImGui::End();
} }
+2 -2
View File
@@ -19,7 +19,7 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re
m_EditorWorld->AttachComponent(m_Camera.ID, "Camera"); m_EditorWorld->AttachComponent(m_Camera.ID, "Camera");
m_DebugCameraInputController = new DebugCameraInputController<EditorSystem>(m_EventBroker, -1); m_DebugCameraInputController = new DebugCameraInputController<EditorSystem>(m_EventBroker, -1);
m_EditorGUI = new EditorGUI(m_EventBroker); m_EditorGUI = new EditorGUI(m_World, m_EventBroker);
m_EditorGUI->SetEntitySelectedCallback(std::bind(&EditorSystem::OnEntitySelected, this, std::placeholders::_1)); m_EditorGUI->SetEntitySelectedCallback(std::bind(&EditorSystem::OnEntitySelected, this, std::placeholders::_1));
m_EditorGUI->SetEntityImportCallback(std::bind(&EditorSystem::importEntity, this, std::placeholders::_1, std::placeholders::_2)); m_EditorGUI->SetEntityImportCallback(std::bind(&EditorSystem::importEntity, this, std::placeholders::_1, std::placeholders::_2));
m_EditorGUI->SetEntitySaveCallback(std::bind(&EditorSystem::OnEntitySave, this, std::placeholders::_1, std::placeholders::_2)); m_EditorGUI->SetEntitySaveCallback(std::bind(&EditorSystem::OnEntitySave, this, std::placeholders::_1, std::placeholders::_2));
@@ -49,7 +49,7 @@ void EditorSystem::Update(double dt)
{ {
m_EditorWorldSystemPipeline->Update(dt); m_EditorWorldSystemPipeline->Update(dt);
m_EditorGUI->Draw(m_World); m_EditorGUI->Draw();
m_EditorStats->Draw(dt); m_EditorStats->Draw(dt);
m_DebugCameraInputController->Update(dt); m_DebugCameraInputController->Update(dt);
+1 -1
View File
@@ -27,7 +27,6 @@ Game::Game(int argc, char* argv[])
// Create the core event broker // Create the core event broker
m_EventBroker = new EventBroker(); m_EventBroker = new EventBroker();
// Create the renderer // Create the renderer
m_Renderer = new Renderer(m_EventBroker, m_World); m_Renderer = new Renderer(m_EventBroker, m_World);
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false)); m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
@@ -143,6 +142,7 @@ void Game::Tick()
m_ClientOrServer->Update(); m_ClientOrServer->Update();
} }
// Iterate through systems and update world! // Iterate through systems and update world!
m_EventBroker->Process<SystemPipeline>();
m_SystemPipeline->Update(dt); m_SystemPipeline->Update(dt);
debugTick(dt); debugTick(dt);
m_Renderer->Update(dt); m_Renderer->Update(dt);