Simple HelloWorld Event for understanding.

This commit is contained in:
Stiffly
2015-09-09 18:42:08 +02:00
parent 80d98470e9
commit fbeb1fb9a6
5 changed files with 58 additions and 19 deletions
+19 -13
View File
@@ -33,6 +33,7 @@
#include "Rendering/CModel.h" #include "Rendering/CModel.h"
#include "CTemplate.h" #include "CTemplate.h"
#include "Transform/TransformSystem.h" #include "Transform/TransformSystem.h"
#include "Core/Sound.h"
namespace dd namespace dd
{ {
@@ -42,24 +43,26 @@ class Engine
public: public:
Engine(int argc, char* argv[]) Engine(int argc, char* argv[])
{ {
// m_EventBroker = std::make_shared<EventBroker>(); m_EventBroker = std::make_shared<EventBroker>();
m_Renderer = std::make_shared<BGFXRenderer>(); m_Renderer = std::make_shared<BGFXRenderer>();
m_Renderer->SetFullscreen(false); m_Renderer->SetFullscreen(false);
m_Renderer->SetResolution(Rectangle(0, 0, 1280, 720)); m_Renderer->SetResolution(Rectangle(0, 0, 1280, 720));
m_Renderer->Initialize(); m_Renderer->Initialize();
// m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker); m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
// //
// m_World = std::make_shared<World>(m_EventBroker); m_World = std::make_shared<World>(m_EventBroker);
// //
// //TODO: Move this out of engine.h //TODO: Move this out of engine.h
// m_World->ComponentFactory.Register<Components::Transform>(); m_World->ComponentFactory.Register<Components::Transform>();
// m_World->SystemFactory.Register<Systems::TransformSystem>([this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); }); m_World->SystemFactory.Register<Systems::TransformSystem>([this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
// m_World->AddSystem<Systems::TransformSystem>(); m_World->SystemFactory.Register<Systems::Sound>([this]() {return new Systems::Sound(m_World.get(), m_EventBroker); });
// m_World->ComponentFactory.Register<Components::Model>(); m_World->AddSystem<Systems::TransformSystem>();
// m_World->ComponentFactory.Register<Components::Template>(); m_World->AddSystem<Systems::Sound>();
// m_World->Initialize(); m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
m_World->Initialize();
// 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);
@@ -82,9 +85,9 @@ public:
// ResourceManager::Update(); // ResourceManager::Update();
// //
// // Update input // // Update input
// m_InputManager->Update(dt); m_InputManager->Update(dt);
// //
// m_World->Update(dt); m_World->Update(dt);
// //
// 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");
@@ -98,7 +101,7 @@ public:
m_Renderer->Draw(m_RendererQueue); m_Renderer->Draw(m_RendererQueue);
// Swap event queues // Swap event queues
// m_EventBroker->Clear(); m_EventBroker->Clear();
glfwPollEvents(); glfwPollEvents();
} }
@@ -175,6 +178,9 @@ 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: Delete this please
std::shared_ptr<dd::Systems::Sound> m_Sound;
double m_LastTime; double m_LastTime;
}; };
+20 -3
View File
@@ -5,15 +5,32 @@
#ifndef DAYDREAM_SOUND_H #ifndef DAYDREAM_SOUND_H
#define DAYDREAM_SOUND_H #define DAYDREAM_SOUND_H
#include "Core/EKeyDown.h"
#include "Core/EventBroker.h"
#include "Core/System.h"
#include "Core/World.h"
namespace dd namespace dd
{ {
class Sound namespace Systems
{ {
class Sound : public System {
public: public:
void HelloWorld(); Sound(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
private: : System(world, eventBroker) { EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Sound::OnKeyDown); }
void Init();
private:
dd::EventRelay<Sound, dd::Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const dd::Events::KeyDown &event);
void HelloWorld();
}; };
} }
}
#endif //DAYDREAM_SOUND_H #endif //DAYDREAM_SOUND_H
+1 -1
View File
@@ -36,6 +36,7 @@
#include "EventBroker.h" #include "EventBroker.h"
#include "EComponentCreated.h" #include "EComponentCreated.h"
#include "ResourceManager.h" #include "ResourceManager.h"
#include "Sound.h"
namespace dd namespace dd
{ {
@@ -248,7 +249,6 @@ protected:
EntityID GenerateEntityID(); EntityID GenerateEntityID();
void RecycleEntityID(EntityID id); void RecycleEntityID(EntityID id);
}; };
template <class T> template <class T>
+16 -2
View File
@@ -1,9 +1,23 @@
// //
// Created by Adam on 2015-09-09. // Created by Adam on 2015-09-09.
// //
#include "PrecompiledHeader.h"
#include "Core/Sound.h" #include "Core/Sound.h"
void dd::Sound::HelloWorld() void dd::Systems::Sound::Init()
{ {
std::cout << "Hej världen!" << std::endl;
}
void dd::Systems::Sound::HelloWorld()
{
LOG_INFO("Hej världen!");
}
bool dd::Systems::Sound::OnKeyDown(const dd::Events::KeyDown &event)
{
// #define GLFW_KEY_S 83
if(event.KeyCode == 83){
HelloWorld();
}
} }
+2
View File
@@ -19,6 +19,8 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "Core/World.h" #include "Core/World.h"
//TODO Delete this please
void dd::World::RecycleEntityID(EntityID id) void dd::World::RecycleEntityID(EntityID id)
{ {
m_RecycledEntityIDs.push(id); m_RecycledEntityIDs.push(id);