diff --git a/include/Core/Engine.h b/include/Core/Engine.h index a4e7b38..d3d164b 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -34,6 +34,7 @@ #include "CTemplate.h" #include "Core/ConfigFile.h" #include "Core/EventBroker.h" +#include "Input/InputSystem.h" #include "Rendering/CModel.h" #include "Rendering/CSprite.h" #include "Rendering/CPointLight.h" @@ -176,6 +177,9 @@ public: m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + //m_World->SystemFactory.Register( + // [this]() { return new Systems::InputSystem(m_World.get(), m_EventBroker); }); + //m_World->AddSystem(); m_World->SystemFactory.Register( [this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); }); m_World->AddSystem(); @@ -257,9 +261,10 @@ public: m_LastTime = currentTime; // Update input + m_EventBroker->Swap(); m_InputManager->Update(dt); - // Swap event queues to get fresh input data in the read queue - //m_EventBroker->Swap(); + //m_EventBroker->Process(); + m_EventBroker->Swap(); //ResourceManager::Update(); if (m_GameIsRunning) { @@ -284,6 +289,7 @@ public: m_EventBroker->Process(); // Swap event queues m_EventBroker->Swap(); + m_EventBroker->Clear(); glfwPollEvents(); } diff --git a/include/Core/EventBroker.h b/include/Core/EventBroker.h index ce2a5a4..8ef1f95 100644 --- a/include/Core/EventBroker.h +++ b/include/Core/EventBroker.h @@ -121,6 +121,7 @@ public: int Process(); int Process(std::string contextTypeName); void Swap(); + void Clear(); void Unsubscribe(BaseEventRelay &relay); private: diff --git a/include/Game/LifebuoySystem.h b/include/Game/LifebuoySystem.h index cfe123b..f293eb6 100644 --- a/include/Game/LifebuoySystem.h +++ b/include/Game/LifebuoySystem.h @@ -47,6 +47,10 @@ public: private: bool m_Pause = false; EntityID m_Template; + Events::Lifebuoy m_SavedEvent; + bool m_Lifebuoy = false; + float m_Timer; + float m_WaitingTime = 0.4; dd::EventRelay m_EContact; dd::EventRelay m_EPause; @@ -58,6 +62,7 @@ private: bool OnPause(const dd::Events::Pause &event); bool OnResume(const dd::Events::Resume &event); bool OnLifebuoy(const dd::Events::Lifebuoy &event); + bool Lifebuoy(const dd::Events::Lifebuoy &event); bool OnLifebuoyHit(const dd::Events::LifebuoyHit &event); struct LifebuoyInfo diff --git a/src/game/Core/EventBroker.cpp b/src/game/Core/EventBroker.cpp index ce91fd9..d07b95b 100644 --- a/src/game/Core/EventBroker.cpp +++ b/src/game/Core/EventBroker.cpp @@ -91,8 +91,11 @@ int dd::EventBroker::Process(std::string contextTypeName) void dd::EventBroker::Swap() { std::swap(m_EventQueueRead, m_EventQueueWrite); - m_EventQueueWrite->clear(); +} +void dd::EventBroker::Clear() +{ + m_EventQueueWrite->clear(); } void dd::EventBroker::subscribeImmediate(dd::BaseEventRelay& relay) diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index e546b71..700f1fc 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -792,7 +792,7 @@ void dd::Systems::LevelSystem::GetBrickSet(int set, int setCluster) // These are if (set == 1) { level = // The Butterfly {4, 0, 0, 1, 0, 0, 1, - 1, 6, 0, 1, 0, 6, 1, + 1, 6, 0, 1, 0, 1, 1, 1, 1, 1, 6, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, @@ -841,7 +841,7 @@ void dd::Systems::LevelSystem::GetBrickSet(int set, int setCluster) // These are 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 1, 3, 1, 1, 1, 1, 5 }; + 1, 3, 1, 1, 1, 1, 1 }; color = {m, m, m, m, m, m, m, m, m, m, m, m, m, m, diff --git a/src/game/Game/LifebuoySystem.cpp b/src/game/Game/LifebuoySystem.cpp index 13a3f1f..86ac22b 100644 --- a/src/game/Game/LifebuoySystem.cpp +++ b/src/game/Game/LifebuoySystem.cpp @@ -76,6 +76,19 @@ void dd::Systems::LifebuoySystem::Update(double dt) ++it; } } + + if (IsPaused()) { + return; + } + + if (m_Lifebuoy) { + m_Timer += dt; + if (m_Timer > m_WaitingTime) { + m_Timer = 0; + m_Lifebuoy = false; + Lifebuoy(m_SavedEvent); + } + } } void dd::Systems::LifebuoySystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -113,7 +126,14 @@ bool dd::Systems::LifebuoySystem::OnContact(const dd::Events::Contact &event) return true; } -bool dd::Systems::LifebuoySystem::OnLifebuoy(const dd::Events::Lifebuoy &event) +bool dd::Systems::LifebuoySystem::OnLifebuoy(const dd::Events::Lifebuoy &event) +{ + m_Lifebuoy = true; + m_SavedEvent = event; + return true; +} + +bool dd::Systems::LifebuoySystem::Lifebuoy(const dd::Events::Lifebuoy &event) { auto ent = m_World->CloneEntity(m_Template); m_World->SetProperty(ent, "Name", "Lifebuoy"); @@ -121,7 +141,8 @@ bool dd::Systems::LifebuoySystem::OnLifebuoy(const dd::Events::Lifebuoy &event) auto transform = m_World->GetComponent(ent); auto physics = m_World->GetComponent(ent); physics->CollisionType = CollisionType::Type::Dynamic; - transform->Position = glm::vec3(0.f, 0.f, -10.f); + //transform->Position = glm::vec3(0.f, 0.f, -10.f); + transform->Position = event.Transform->Position; transform->Velocity = glm::vec3(20.f, 3.f, 0.f); LifebuoyInfo info; info.Entity = ent; diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index 309effe..4aa2d89 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -56,6 +56,7 @@ void dd::Systems::PadSystem::Initialize() cModel->ModelFile = "Models/Ship/Ship.obj"; auto pad = m_World->AddComponent(ent); + pad->SlowdownModifier = 10.f; m_World->CommitEntity(ent); m_Edge = 3.2 - (ctransform->Scale.x / 2);