diff --git a/include/Core/Engine.h b/include/Core/Engine.h index dbd1d24..3b74562 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -53,6 +53,9 @@ #include "Physics/ESetImpulse.h" #include "Physics/CWaterVolume.h" +#include "Game/EGameStart.h" +#include "Sound/EPlaySound.h" + #include "GUI/Frame.h" #include "GUI/Button.h" #include "Game/MainMenu.h" @@ -82,8 +85,6 @@ public: m_World = std::make_shared(m_EventBroker); - - //TODO: Move this out of engine.h m_World->ComponentFactory.Register(); m_World->SystemFactory.Register( @@ -131,7 +132,7 @@ public: //OctoBall - { + { auto ent = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(ent); transform->Position = glm::vec3(-0.f, 0.26f, -9.f); @@ -142,14 +143,14 @@ public: std::shared_ptr circleShape = m_World->AddComponent(ent); std::shared_ptr ball = m_World->AddComponent(ent); ball->Speed = 5.f; - std::shared_ptr physics = m_World->AddComponent(ent); - physics->Static = false; + std::shared_ptr physics = m_World->AddComponent(ent); + physics->Static = false; auto plight = m_World->AddComponent(ent); plight->Radius = 2.f; m_World->CommitEntity(ent); - } + } //PointLightTest { @@ -310,6 +311,11 @@ public: m_World->CommitEntity(ent); } + + //EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart); + m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1)); + m_EventBroker->Subscribe(m_EGameStart); + m_LastTime = glfwGetTime(); } @@ -327,22 +333,27 @@ public: //m_EventBroker->Swap(); ResourceManager::Update(); - - m_World->Update(dt); - m_EventBroker->Process(); - m_FrameStack->UpdateLayered(dt); + if (m_GameIsRunning) { + m_World->Update(dt); + } + if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_ENTER)) { + Events::GameStart e; + m_EventBroker->Publish(e); + } if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) { ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl"); } //TODO Fill up the renderQueue with models (Temp fix) - TEMPAddToRenderQueue(); - m_FrameStack->DrawLayered(m_RendererQueue); + if (m_GameIsRunning) { + TEMPAddToRenderQueue(); + } // Render scene //TODO send renderqueue to draw. m_Renderer->Draw(m_RendererQueue); + m_EventBroker->Process(); // Swap event queues m_EventBroker->Swap(); @@ -440,7 +451,6 @@ public: } } - m_RendererQueue.Sort(); } //TODO: Get this out of engine.h @@ -511,7 +521,27 @@ private: std::shared_ptr m_InputManager; std::shared_ptr m_World; - + //TODO: Redo + bool m_GameIsRunning = false; + dd::EventRelay m_EGameStart; + bool OnGameStart(const dd::Events::GameStart &event) + { + m_GameIsRunning = true; + //Todo: Move this + { + dd::Events::PlaySound e; + e.path = "Sounds/BGM/under-the-sea-instrumental.wav"; + e.isAmbient = true; + m_EventBroker->Publish(e); + } + { + dd::Events::PlaySound e; + e.path = "Sounds/BGM/water-flowing.wav"; + e.volume = 0.3f; + e.isAmbient = true; + m_EventBroker->Publish(e); + } + }; double m_LastTime; }; diff --git a/include/Game/EGameStart.h b/include/Game/EGameStart.h new file mode 100644 index 0000000..bfee0fd --- /dev/null +++ b/include/Game/EGameStart.h @@ -0,0 +1,25 @@ +// +// Created by Adam on 2015-09-25. +// + +#ifndef EVENTS_EGAMESTART_H__ +#define EVENTS_EGAMESTART_H__ + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct GameStart : public Event +{ + +}; + +} + +} + +#endif diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index 8594d92..90939a1 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -36,26 +36,7 @@ void dd::Systems::SoundSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume); - //Todo: Move this - { - dd::Events::PlaySound e; - e.path = "Sounds/BGM/under-the-sea-instrumental.wav"; - e.isAmbient = true; - EventBroker->Publish(e); - } - { - dd::Events::PlaySound e; - e.path = "Sounds/BGM/water-flowing.wav"; - e.volume = 0.3f; - e.isAmbient = true; - EventBroker->Publish(e); - } - { - dd::Events::MasterVolume e; - e.isAmbient = true; - e.gain = 1.f; - EventBroker->Publish(e); - } + } void dd::Systems::SoundSystem::Update(double dt) @@ -182,12 +163,6 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) } } - { - dd::Events::StopSound e; - e.path = "Sounds/BGM/water-flowing.wav"; - EventBroker->Publish(e); - } - //Send play-sound event dd::Events::PlaySound e; e.path = collisionSound->filePath;