# HG changeset patch
# User koryspansel
# Date 1316713625 25200
# Node ID d27c06bd8ce13a983b25f960dde42323e16e6210
# Parent 91e927584f92dc02e8970127466287f5aa14a1ee
Simplify input manager and remove event system
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/LightClone.vcproj
--- a/LightClone/LightClone.vcproj Thu Sep 22 10:38:54 2011 -0700
+++ b/LightClone/LightClone.vcproj Thu Sep 22 10:47:05 2011 -0700
@@ -276,22 +276,6 @@
>
-
-
-
-
-
-
-
-
@@ -434,22 +418,6 @@
>
-
-
-
-
-
-
-
-
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/Event.cpp
--- a/LightClone/Source/Event.cpp Thu Sep 22 10:38:54 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-/*
- * Event
- */
-
-#include "Event.h"
-
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/Event.h
--- a/LightClone/Source/Event.h Thu Sep 22 10:38:54 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Event
- */
-
-#ifndef __EVENT_H__
-#define __EVENT_H__
-
-#include "Core.h"
-
-/*
- * EventResult
- */
-enum
-{
- EventResult_Stop,
- EventResult_Continue,
- EventResult_Error,
-};
-
-/*
- * Event
- */
-struct Event
-{
- /*
- * nType
- */
- uint32 nType;
-};
-
-#endif //__EVENT_H__
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/EventSink.cpp
--- a/LightClone/Source/EventSink.cpp Thu Sep 22 10:38:54 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-/*
- * EventSink
- */
-
-#include "EventSink.h"
-
-/*
- * ~EventSink
- */
-EventSink::~EventSink()
-{
-}
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/EventSink.h
--- a/LightClone/Source/EventSink.h Thu Sep 22 10:38:54 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * EventSink
- */
-
-#ifndef __EVENTSINK_H__
-#define __EVENTSINK_H__
-
-#include "Core.h"
-#include "ArrayList.h"
-#include "Event.h"
-
-/*
- * EventSink
- */
-class EventSink
-{
-public:
-
- /*
- * ~EventSink
- */
- virtual ~EventSink();
-
- /*
- * ProcessEvent
- */
- virtual int32 ProcessEvent(const Event& kEvent) = 0;
-};
-
-/*
- * EventSinkList
- */
-typedef ArrayList EventSinkList;
-
-#endif //__EVENTSINK_H__
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/EventSource.cpp
--- a/LightClone/Source/EventSource.cpp Thu Sep 22 10:38:54 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-/*
- * EventSource
- */
-
-#include "EventSource.h"
-
-/*
- * ~EventSource
- */
-EventSource::~EventSource()
-{
-}
\ No newline at end of file
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/EventSource.h
--- a/LightClone/Source/EventSource.h Thu Sep 22 10:38:54 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- * EventSource
- */
-
-#ifndef __EVENTSOURCE_H__
-#define __EVENTSOURCE_H__
-
-#include "Core.h"
-#include "ArrayList.h"
-
-/*
- * EventSystem
- */
-class EventSystem;
-
-/*
- * EventSource
- * An event source, as its name implies, is an object that generates events
- */
-class EventSource
-{
-public:
-
- /*
- * ~EventSource
- */
- virtual ~EventSource();
-
- /*
- * Update
- * Give the event source a chance to post events to the system
- */
- virtual void Update(EventSystem* pSystem, float fElapsed) = 0;
-};
-
-/*
- * EventSourceList
- */
-typedef ArrayList EventSourceList;
-
-#endif //__EVENTSOURCE_H__
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/EventSystem.cpp
--- a/LightClone/Source/EventSystem.cpp Thu Sep 22 10:38:54 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * EventSystem
- */
-
-#include "EventSystem.h"
-
-/*
- * EventSystem
- */
-EventSystem::EventSystem()
-{
-}
-
-/*
- * AddSource
- */
-ErrorCode EventSystem::AddSource(EventSource* pSource)
-{
- return kSources.Add(pSource);
-}
-
-/*
- * AddSink
- */
-ErrorCode EventSystem::AddSink(EventSink* pSink)
-{
- return kSinks.Add(pSink);
-}
-
-/*
- * RemoveSink
- */
-ErrorCode EventSystem::RemoveSink(EventSink* pSink)
-{
- ErrorCode eCode = Error_Fail;
-
- int32 nIndex = kSinks.Find(pSink);
- if(nIndex >= 0)
- {
- eCode = kSinks.Remove(nIndex);
- }
-
- return eCode;
-}
-
-/*
- * Post
- */
-void EventSystem::Post(const Event& kEvent)
-{
- for(uint32 i = 0; i < kSinks.Size(); ++i)
- {
- if(kSinks[i]->ProcessEvent(kEvent) == EventResult_Stop)
- {
- break;
- }
- }
-}
-
-/*
- * Update
- */
-void EventSystem::Update(float fElapsed)
-{
- for(uint32 i = 0; i < kSources.Size(); ++i)
- {
- kSources[i]->Update(this, fElapsed);
- }
-}
\ No newline at end of file
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/EventSystem.h
--- a/LightClone/Source/EventSystem.h Thu Sep 22 10:38:54 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/*
- * EventSystem
- */
-
-#ifndef __EVENTSYSTEM_H__
-#define __EVENTSYSTEM_H__
-
-#include "Core.h"
-#include "EventSource.h"
-#include "EventSink.h"
-#include "Event.h"
-
-/*
- * EventSystem
- * The system ties together event sources and event sinks, and provides an
- * interface to the system for registering these objects.
- */
-class EventSystem
-{
- /*
- * kSources
- */
- EventSourceList kSources;
-
- /*
- * kSinks
- */
- EventSinkList kSinks;
-
-public:
-
- /*
- * EventSystem
- */
- EventSystem();
-
- /*
- * AddSource
- */
- ErrorCode AddSource(EventSource* pSource);
-
- /*
- * AddSink
- * TODO: This should support specifying a specific event
- */
- ErrorCode AddSink(EventSink* pSink);
-
- /*
- * RemoveSink
- */
- ErrorCode RemoveSink(EventSink* pSink);
-
- /*
- * Post
- */
- void Post(const Event& kEvent);
-
- /*
- * Update
- */
- virtual void Update(float fElapsed);
-};
-
-#endif //__EVENTSYSTEM_H__
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/InputManager.cpp
--- a/LightClone/Source/InputManager.cpp Thu Sep 22 10:38:54 2011 -0700
+++ b/LightClone/Source/InputManager.cpp Thu Sep 22 10:47:05 2011 -0700
@@ -3,7 +3,6 @@
*/
#include "InputManager.h"
-#include "EventSystem.h"
/*
* fMouseSensitivity
@@ -114,7 +113,7 @@
/*
* Update
*/
-void InputManager::Update(EventSystem* pEventSystem, float fElapsed)
+void InputManager::Update(float fElapsed)
{
if(pKeyboard)
{
@@ -129,35 +128,6 @@
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);
- }
- }
- }
}
if(pMouse)
@@ -176,44 +146,6 @@
fMouseX = Clamp(fMouseX + fMouseSensitivity * kCurrentMouseState.lX, kMouseBounds.X, kMouseBounds.X + kMouseBounds.Width - 1.0f);
fMouseY = Clamp(fMouseY + fMouseSensitivity * kCurrentMouseState.lY, kMouseBounds.Y, kMouseBounds.Y + kMouseBounds.Height - 1.0f);
-
- for(uint32 i = 0; i < sizeof(kCurrentMouseState.rgbButtons) / sizeof(kCurrentMouseState.rgbButtons[0]); ++i)
- {
- if(kPreviousMouseState.rgbButtons[i] & 0x80)
- {
- if(!(kCurrentMouseState.rgbButtons[i] & 0x80))
- {
- InputEvent kEvent;
- kEvent.nType = InputEventType_MouseUp;
- kEvent.nButton = i;
- kEvent.nDuration = 0;
-
- pEventSystem->Post(kEvent);
- }
- }
- else
- {
- if(kCurrentMouseState.rgbButtons[i] & 0x80)
- {
- InputEvent kEvent;
- kEvent.nType = InputEventType_MouseDown;
- kEvent.nButton = i;
- kEvent.nDuration = 0;
-
- pEventSystem->Post(kEvent);
- }
- }
- }
-
- if(kCurrentMouseState.lX != 0 || kCurrentMouseState.lY != 0)
- {
- InputEvent kEvent;
- kEvent.nType = InputEventType_MouseMove;
- kEvent.fX = fMouseX;
- kEvent.fY = fMouseY;
-
- pEventSystem->Post(kEvent);
- }
}
}
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/InputManager.h
--- a/LightClone/Source/InputManager.h Thu Sep 22 10:38:54 2011 -0700
+++ b/LightClone/Source/InputManager.h Thu Sep 22 10:47:05 2011 -0700
@@ -8,24 +8,6 @@
#define DIRECTINPUT_VERSION 0x0800
#include
#include "Core.h"
-#include "Event.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,
-};
/*
* MouseButton
@@ -39,57 +21,9 @@
};
/*
- * InputEvent
- */
-struct InputEvent : public Event
-{
- 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 : public EventSource
+class InputManager
{
/*
* pDirectInput
@@ -161,7 +95,7 @@
/*
* Update
*/
- virtual void Update(EventSystem* pEventSystem, float fElapsed);
+ void Update(float fElapsed);
/*
* SetBounds
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/Mediator.cpp
--- a/LightClone/Source/Mediator.cpp Thu Sep 22 10:38:54 2011 -0700
+++ b/LightClone/Source/Mediator.cpp Thu Sep 22 10:47:05 2011 -0700
@@ -112,14 +112,7 @@
return Error_Fail;
}
- eCode = kEventSystem.AddSource(&kInputManager);
- if(eCode != Error_Success)
- {
- Terminate();
- return Error_Fail;
- }
-
- eCode = kWorld.Initialize(&kEventSystem, &kResourceManager, &kInputManager);
+ eCode = kWorld.Initialize(&kResourceManager, &kInputManager);
if(eCode != Error_Success)
{
Terminate();
@@ -148,8 +141,6 @@
*/
void Mediator::Update(float fElapsed)
{
- kEventSystem.Update(fElapsed);
-
kWorld.Update(fElapsed);
}
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/Mediator.h
--- a/LightClone/Source/Mediator.h Thu Sep 22 10:38:54 2011 -0700
+++ b/LightClone/Source/Mediator.h Thu Sep 22 10:47:05 2011 -0700
@@ -20,11 +20,6 @@
class Mediator : public WindowCallback
{
/*
- * kEventSystem
- */
- EventSystem kEventSystem;
-
- /*
* kWindow
*/
Window kWindow;
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/World.cpp
--- a/LightClone/Source/World.cpp Thu Sep 22 10:38:54 2011 -0700
+++ b/LightClone/Source/World.cpp Thu Sep 22 10:47:05 2011 -0700
@@ -22,13 +22,12 @@
/*
* Initialize
*/
-ErrorCode World::Initialize(EventSystem* pSystem, ResourceManager* pResourceManager, InputManager* pInput)
+ErrorCode World::Initialize(ResourceManager* pResourceManager, InputManager* pInput)
{
ErrorCode eCode = Error_Fail;
if(pResourceManager && pInput)
{
- pEventSystem = pSystem;
pInputManager = pInput;
eCode = kEnvironment.Initialize(pResourceManager);
@@ -381,6 +380,8 @@
*/
void World::ProcessInput(float fElapsed)
{
+ pInputManager->Update(fElapsed);
+
#if defined(_DEBUG)
if(pInputManager->IsKeyDown(DIK_LEFT))
{
diff -r 91e927584f92 -r d27c06bd8ce1 LightClone/Source/World.h
--- a/LightClone/Source/World.h Thu Sep 22 10:38:54 2011 -0700
+++ b/LightClone/Source/World.h Thu Sep 22 10:47:05 2011 -0700
@@ -7,7 +7,6 @@
#include "Core.h"
#include "ResourceManager.h"
-#include "EventSystem.h"
#include "RenderContext.h"
#include "Environment.h"
#include "Bot.h"
@@ -27,11 +26,6 @@
class World
{
/*
- * pEventSystem
- */
- EventSystem* pEventSystem;
-
- /*
* pInputManager
*/
InputManager* pInputManager;
@@ -151,7 +145,7 @@
/*
* Initialize
*/
- ErrorCode Initialize(EventSystem* pSystem, ResourceManager* pResource, InputManager* pInput);
+ ErrorCode Initialize(ResourceManager* pResource, InputManager* pInput);
/*
* Terminate