# HG changeset patch # User koryspansel # Date 1315980105 25200 # Node ID 7081e8e6008ca18059734d80eb79ca97d4f38d84 # Parent 28cf0baf2772c40214e33bbe5c21b20505628f84 Working on integrating the EventSystem diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/EventSource.cpp --- a/LightClone/Source/EventSource.cpp Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/EventSource.cpp Tue Sep 13 23:01:45 2011 -0700 @@ -4,3 +4,9 @@ #include "EventSource.h" +/* + * ~EventSource + */ +EventSource::~EventSource() +{ +} \ No newline at end of file diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/EventSource.h --- a/LightClone/Source/EventSource.h Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/EventSource.h Tue Sep 13 23:01:45 2011 -0700 @@ -27,10 +27,10 @@ virtual ~EventSource(); /* - * Generate + * Update * Give the event source a chance to post events to the system */ - virtual void Generate(EventSystem* pSystem); + virtual void Update(EventSystem* pSystem, float fElapsed) = 0; }; /* diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/EventSystem.cpp --- a/LightClone/Source/EventSystem.cpp Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/EventSystem.cpp Tue Sep 13 23:01:45 2011 -0700 @@ -26,12 +26,12 @@ } /* - * Process + * Update */ -void EventSystem::Process() +void EventSystem::Update(float fElapsed) { for(uint32 i = 0; i < kSources.GetSize(); ++i) { - kSources[i]->Generate(this); + kSources[i]->Update(this, fElapsed); } } \ No newline at end of file diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/EventSystem.h --- a/LightClone/Source/EventSystem.h Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/EventSystem.h Tue Sep 13 23:01:45 2011 -0700 @@ -8,6 +8,7 @@ #include "Core.h" #include "EventSource.h" #include "EventSink.h" +#include "Event.h" //TODO: Support registering sinks for specific events @@ -36,14 +37,19 @@ EventSystem(); /* + * AddSource + */ + ErrorCode AddSource(EventSource* pSource); + + /* * Post */ void Post(const Event& kEvent); /* - * Process + * Update */ - void Process(); + virtual void Update(float fElapsed); }; #endif //__EVENTSYSTEM_H__ diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/InputManager.cpp --- a/LightClone/Source/InputManager.cpp Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/InputManager.cpp Tue Sep 13 23:01:45 2011 -0700 @@ -113,7 +113,7 @@ /* * Update */ -void InputManager::Update(float fElapsed) +void InputManager::Update(EventSystem* pEventSystem, float fElapsed) { if(pKeyboard) { @@ -126,6 +126,35 @@ if(SUCCEEDED(hResult)) { hResult = pKeyboard->GetDeviceState(sizeof(kCurrentKeyboardState), kCurrentKeyboardState); + + for(uint32 i = 0; i < sizeof(kCurrentKeyboardState) / sizeof(kCurrentKeyboardState[0]); ++i) + { + // check for key up events + if(kPreviousKeyboardState[i] & 0x80) + { + if(!(kCurrentKeyboardState[i] & 0x80)) + { + InputEvent kEvent; + kEvent.nType = InputEventType_KeyUp; + kEvent.nKey = i; + kEvent.nDuration = 0; + + pEventSystem->Post(kEvent); + } + } + else + { + if(kCurrentKeyboardState[i] & 0x80) + { + InputEvent kEvent; + kEvent.nType = InputEventType_KeyDown; + kEvent.nKey = i; + kEvent.nDuration = 0; + + pEventSystem->Post(kEvent); + } + } + } } } } diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/InputManager.h --- a/LightClone/Source/InputManager.h Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/InputManager.h Tue Sep 13 23:01:45 2011 -0700 @@ -8,14 +8,81 @@ #define DIRECTINPUT_VERSION 0x0800 #include #include "Core.h" +#include "EventSource.h" //TODO: Remove the need to pass InputManager to world objects during // initialization by sending input events instead /* + * InputEventType + */ +enum +{ + InputEventType_KeyDown, + InputEventType_KeyUp, + + InputEventType_MouseDown, + InputEventType_MouseUp, + InputEventType_MouseMove, +}; + +/* + * InputEvent + */ +struct InputEvent +{ + /* + * nType + */ + uint32 nType; + + union + { + struct + { + /* + * nKey + */ + uint32 nKey; + + /* + * nDuration + */ + uint32 nDuration; + }; + + struct + { + /* + * nButton + */ + uint32 nButton; + + /* + * nDuration + */ + uint32 nDuration; + }; + + struct + { + /* + * fX + */ + float fX; + + /* + * fY + */ + float fY; + }; + }; +}; + +/* * InputManager */ -class InputManager +class InputManager : public EventSource { /* * pDirectInput @@ -87,7 +154,7 @@ /* * Update */ - void Update(float fElapsed); + virtual void Update(EventSystem* pEventSystem, float fElapsed); /* * SetBounds diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/Mediator.cpp --- a/LightClone/Source/Mediator.cpp Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/Mediator.cpp Tue Sep 13 23:01:45 2011 -0700 @@ -112,7 +112,14 @@ return Error_Fail; } - eCode = kWorld.Initialize(&kResourceManager, &kInputManager); + eCode = kEventSystem.AddSource(&kInputManager); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + + eCode = kWorld.Initialize(&kEventSystem, &kResourceManager, &kInputManager); if(eCode != Error_Success) { Terminate(); diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/Mediator.h --- a/LightClone/Source/Mediator.h Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/Mediator.h Tue Sep 13 23:01:45 2011 -0700 @@ -25,6 +25,11 @@ class Mediator : public WindowCallback { /* + * kEventSystem + */ + EventSystem kEventSystem; + + /* * kWindow */ Window kWindow; diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/World.cpp --- a/LightClone/Source/World.cpp Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/World.cpp Tue Sep 13 23:01:45 2011 -0700 @@ -67,12 +67,13 @@ /* * Initialize */ -ErrorCode World::Initialize(ResourceManager* pResourceManager, InputManager* pInput) +ErrorCode World::Initialize(EventSystem* pSystem, ResourceManager* pResourceManager, InputManager* pInput) { ErrorCode eCode = Error_Fail; if(pResourceManager && pInput) { + pEventSystem = pSystem; pInputManager = pInput; eCode = kEnvironment.Initialize(pResourceManager); @@ -392,7 +393,7 @@ */ void World::ProcessInput(float fElapsed) { - pInputManager->Update(fElapsed); + //pInputManager->Update(fElapsed); #if defined(_DEBUG) if(pInputManager->IsKeyDown(DIK_LEFT)) diff -r 28cf0baf2772 -r 7081e8e6008c LightClone/Source/World.h --- a/LightClone/Source/World.h Tue Sep 13 19:44:23 2011 -0700 +++ b/LightClone/Source/World.h Tue Sep 13 23:01:45 2011 -0700 @@ -6,6 +6,8 @@ #define __WORLD_H__ #include "Core.h" +#include "ResourceManager.h" +#include "EventSystem.h" #include "RenderContext.h" #include "Environment.h" #include "Bot.h" @@ -13,7 +15,6 @@ #include "Loader.h" #include "CameraController.h" #include "DragController.h" -#include "ResourceManager.h" #include "InputManager.h" #include "ButtonPane.h" #include "Dialog.h" @@ -25,6 +26,11 @@ class World { /* + * pEventSystem + */ + EventSystem* pEventSystem; + + /* * pInputManager */ InputManager* pInputManager; @@ -135,7 +141,7 @@ /* * Initialize */ - ErrorCode Initialize(ResourceManager* pResource, InputManager* pInput); + ErrorCode Initialize(EventSystem* pSystem, ResourceManager* pResource, InputManager* pInput); /* * Terminate