EStartGame up and running. Moved BGM-play from soundsystem init to EGameStart.
This commit is contained in:
@@ -1879,5 +1879,3 @@ f 166/13/239 259/24/24 401/34/255
|
|||||||
f 161/12/240 166/13/239 400/32/253
|
f 161/12/240 166/13/239 400/32/253
|
||||||
f 163/27/245 161/12/240 399/29/251
|
f 163/27/245 161/12/240 399/29/251
|
||||||
f 256/19/19 163/27/245 398/30/30
|
f 256/19/19 163/27/245 398/30/30
|
||||||
l 300 301
|
|
||||||
l 299 298
|
|
||||||
|
|||||||
+64
-31
@@ -52,6 +52,9 @@
|
|||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CBoxShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
|
|
||||||
|
#include "Game/EGameStart.h"
|
||||||
|
#include "Sound/EPlaySound.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
@@ -72,13 +75,11 @@ public:
|
|||||||
|
|
||||||
m_World = std::make_shared<World>(m_EventBroker);
|
m_World = std::make_shared<World>(m_EventBroker);
|
||||||
|
|
||||||
|
//TODO: Move this out of engine.h
|
||||||
|
m_World->ComponentFactory.Register<Components::Transform>();
|
||||||
//TODO: Move this out of engine.h
|
m_World->SystemFactory.Register<Systems::TransformSystem>(
|
||||||
m_World->ComponentFactory.Register<Components::Transform>();
|
[this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->SystemFactory.Register<Systems::TransformSystem>(
|
m_World->AddSystem<Systems::TransformSystem>();
|
||||||
[this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
|
|
||||||
m_World->AddSystem<Systems::TransformSystem>();
|
|
||||||
m_World->ComponentFactory.Register<Components::Model>();
|
m_World->ComponentFactory.Register<Components::Model>();
|
||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
|
|
||||||
@@ -86,10 +87,10 @@ public:
|
|||||||
m_World->SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
|
m_World->SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::SoundSystem>();
|
m_World->AddSystem<Systems::SoundSystem>();
|
||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::Sprite>();
|
m_World->ComponentFactory.Register<Components::Sprite>();
|
||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::RectangleShape>();
|
m_World->ComponentFactory.Register<Components::RectangleShape>();
|
||||||
m_World->ComponentFactory.Register<Components::Physics>();
|
m_World->ComponentFactory.Register<Components::Physics>();
|
||||||
m_World->ComponentFactory.Register<Components::Ball>();
|
m_World->ComponentFactory.Register<Components::Ball>();
|
||||||
m_World->ComponentFactory.Register<Components::Brick>();
|
m_World->ComponentFactory.Register<Components::Brick>();
|
||||||
m_World->ComponentFactory.Register<Components::Pad>();
|
m_World->ComponentFactory.Register<Components::Pad>();
|
||||||
@@ -98,9 +99,9 @@ public:
|
|||||||
m_World->ComponentFactory.Register<Components::PowerUp>();
|
m_World->ComponentFactory.Register<Components::PowerUp>();
|
||||||
m_World->ComponentFactory.Register<Components::PowerUpBrick>();
|
m_World->ComponentFactory.Register<Components::PowerUpBrick>();
|
||||||
|
|
||||||
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
||||||
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::PhysicsSystem>();
|
m_World->AddSystem<Systems::PhysicsSystem>();
|
||||||
|
|
||||||
m_World->SystemFactory.Register<Systems::LevelSystem>([this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
|
m_World->SystemFactory.Register<Systems::LevelSystem>([this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::LevelSystem>();
|
m_World->AddSystem<Systems::LevelSystem>();
|
||||||
@@ -109,10 +110,10 @@ public:
|
|||||||
m_World->SystemFactory.Register<Systems::BallSystem>([this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
|
m_World->SystemFactory.Register<Systems::BallSystem>([this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::BallSystem>();
|
m_World->AddSystem<Systems::BallSystem>();
|
||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::Model>();
|
m_World->ComponentFactory.Register<Components::Model>();
|
||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
m_World->ComponentFactory.Register<Components::PointLight>();
|
m_World->ComponentFactory.Register<Components::PointLight>();
|
||||||
m_World->Initialize();
|
m_World->Initialize();
|
||||||
|
|
||||||
|
|
||||||
//TODO: Remove tobias light-test code.
|
//TODO: Remove tobias light-test code.
|
||||||
@@ -120,29 +121,29 @@ public:
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
//OctoBall
|
//OctoBall
|
||||||
{
|
{
|
||||||
auto ent = m_World->CreateEntity();
|
auto ent = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Position = glm::vec3(-0.f, 0.26f, -10.f);
|
transform->Position = glm::vec3(-0.f, 0.26f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
|
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||||
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
|
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
|
||||||
|
|
||||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||||
|
|
||||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||||
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||||
ball->Speed = 5.f;
|
ball->Speed = 5.f;
|
||||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
physics->Static = false;
|
physics->Static = false;
|
||||||
|
|
||||||
auto plight = m_World->AddComponent<Components::PointLight>(ent);
|
auto plight = m_World->AddComponent<Components::PointLight>(ent);
|
||||||
plight->Radius = 2.f;
|
plight->Radius = 2.f;
|
||||||
|
|
||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//PointLightTest
|
//PointLightTest
|
||||||
{
|
{
|
||||||
@@ -227,6 +228,11 @@ public:
|
|||||||
m_World->CommitEntity(ent);
|
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();
|
m_LastTime = glfwGetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,9 +249,14 @@ public:
|
|||||||
// Update input
|
// Update input
|
||||||
m_InputManager->Update(dt);
|
m_InputManager->Update(dt);
|
||||||
|
|
||||||
m_World->Update(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)) {
|
// if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
|
||||||
// ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
|
// ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
|
||||||
@@ -263,12 +274,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO Fill up the renderQueue with models (Temp fix)
|
//TODO Fill up the renderQueue with models (Temp fix)
|
||||||
TEMPAddToRenderQueue();
|
if (m_GameIsRunning) {
|
||||||
|
TEMPAddToRenderQueue();
|
||||||
|
}
|
||||||
|
|
||||||
// Render scene
|
// Render scene
|
||||||
//TODO send renderqueue to draw.
|
//TODO send renderqueue to draw.
|
||||||
m_Renderer->Draw(m_RendererQueue);
|
m_Renderer->Draw(m_RendererQueue);
|
||||||
|
|
||||||
|
m_EventBroker->Process<Engine>();
|
||||||
// Swap event queues
|
// Swap event queues
|
||||||
m_EventBroker->Clear();
|
m_EventBroker->Clear();
|
||||||
|
|
||||||
@@ -355,7 +369,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_RendererQueue.Sort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Get this out of engine.h
|
//TODO: Get this out of engine.h
|
||||||
@@ -416,7 +429,27 @@ private:
|
|||||||
std::shared_ptr<InputManager> m_InputManager;
|
std::shared_ptr<InputManager> m_InputManager;
|
||||||
std::shared_ptr<World> m_World;
|
std::shared_ptr<World> m_World;
|
||||||
|
|
||||||
|
//TODO: Redo
|
||||||
|
bool m_GameIsRunning = false;
|
||||||
|
dd::EventRelay<Engine, dd::Events::GameStart> 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;
|
double m_LastTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -36,26 +36,7 @@ void dd::Systems::SoundSystem::Initialize()
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
|
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)
|
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
|
//Send play-sound event
|
||||||
dd::Events::PlaySound e;
|
dd::Events::PlaySound e;
|
||||||
e.path = collisionSound->filePath;
|
e.path = collisionSound->filePath;
|
||||||
|
|||||||
Reference in New Issue
Block a user