WIP world pausing
This commit is contained in:
@@ -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
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "EventBroker.h"
|
||||
#include "System.h"
|
||||
#include "World.h"
|
||||
#include "EPause.h"
|
||||
|
||||
class SystemPipeline
|
||||
{
|
||||
@@ -12,7 +13,10 @@ public:
|
||||
SystemPipeline(World* world, EventBroker* eventBroker)
|
||||
: m_World(world)
|
||||
, m_EventBroker(eventBroker)
|
||||
{ }
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &SystemPipeline::OnPause);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EResume, &SystemPipeline::OnResume);
|
||||
}
|
||||
|
||||
~SystemPipeline()
|
||||
{
|
||||
@@ -51,6 +55,10 @@ public:
|
||||
|
||||
void Update(double dt)
|
||||
{
|
||||
if (m_Paused) {
|
||||
dt = 0.0;
|
||||
}
|
||||
|
||||
for (UnorderedSystems& group : m_OrderedSystemGroups) {
|
||||
// Process events
|
||||
for (auto& pair : group.Systems) {
|
||||
@@ -80,6 +88,7 @@ public:
|
||||
private:
|
||||
World* m_World;
|
||||
EventBroker* m_EventBroker;
|
||||
bool m_Paused = false;
|
||||
|
||||
struct UnorderedSystems
|
||||
{
|
||||
@@ -88,6 +97,21 @@ private:
|
||||
std::vector<ImpureSystem*> ImpureSystems;
|
||||
};
|
||||
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
|
||||
@@ -14,14 +14,15 @@
|
||||
#include "../Core/World.h"
|
||||
#include "../Core/EntityWrapper.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "../Core/EPause.h"
|
||||
#include "../Rendering/Texture.h"
|
||||
|
||||
class EditorGUI
|
||||
{
|
||||
public:
|
||||
EditorGUI(EventBroker* eventBroker);
|
||||
EditorGUI(World* world, EventBroker* eventBroker);
|
||||
|
||||
void Draw(World* world);
|
||||
void Draw();
|
||||
|
||||
void SelectEntity(EntityWrapper entity);
|
||||
|
||||
@@ -57,6 +58,7 @@ public:
|
||||
void SetComponentDeleteCallback(OnComponentDelete_t f) { m_OnComponentDelete = f; }
|
||||
|
||||
private:
|
||||
World* m_World;
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
// Config variables
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
#include "Editor/EditorGUI.h"
|
||||
|
||||
EditorGUI::EditorGUI(EventBroker* eventBroker)
|
||||
: m_EventBroker(eventBroker)
|
||||
EditorGUI::EditorGUI(World* world, EventBroker* eventBroker)
|
||||
: m_World(world)
|
||||
, m_EventBroker(eventBroker)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditorGUI::Draw(World* world)
|
||||
void EditorGUI::Draw()
|
||||
{
|
||||
ImGui::ShowTestWindow();
|
||||
drawMenu();
|
||||
drawTools();
|
||||
drawEntities(world);
|
||||
drawEntities(m_World);
|
||||
drawComponents(m_CurrentSelection);
|
||||
}
|
||||
|
||||
@@ -65,10 +66,20 @@ void EditorGUI::drawTools()
|
||||
pauseIcon = ResourceManager::Load<Texture>("Textures/Icons/Pause.png")->m_Texture;
|
||||
} catch (const std::exception&) { }
|
||||
|
||||
|
||||
ImGui::ImageButton((void*)playIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), ImVec4(0, 1, 0, 1));
|
||||
static bool paused = false;
|
||||
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::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();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re
|
||||
m_EditorWorld->AttachComponent(m_Camera.ID, "Camera");
|
||||
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->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));
|
||||
@@ -49,7 +49,7 @@ void EditorSystem::Update(double dt)
|
||||
{
|
||||
m_EditorWorldSystemPipeline->Update(dt);
|
||||
|
||||
m_EditorGUI->Draw(m_World);
|
||||
m_EditorGUI->Draw();
|
||||
m_EditorStats->Draw(dt);
|
||||
|
||||
m_DebugCameraInputController->Update(dt);
|
||||
|
||||
+1
-1
@@ -27,7 +27,6 @@ Game::Game(int argc, char* argv[])
|
||||
// Create the core event broker
|
||||
m_EventBroker = new EventBroker();
|
||||
|
||||
|
||||
// Create the renderer
|
||||
m_Renderer = new Renderer(m_EventBroker, m_World);
|
||||
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
||||
@@ -143,6 +142,7 @@ void Game::Tick()
|
||||
m_ClientOrServer->Update();
|
||||
}
|
||||
// Iterate through systems and update world!
|
||||
m_EventBroker->Process<SystemPipeline>();
|
||||
m_SystemPipeline->Update(dt);
|
||||
debugTick(dt);
|
||||
m_Renderer->Update(dt);
|
||||
|
||||
Reference in New Issue
Block a user