changeset 43:d27c06bd8ce1

Simplify input manager and remove event system
author koryspansel
date Thu, 22 Sep 2011 10:47:05 -0700
parents 91e927584f92
children 6790cf9e8bd8
files LightClone/LightClone.vcproj LightClone/Source/Event.cpp LightClone/Source/Event.h LightClone/Source/EventSink.cpp LightClone/Source/EventSink.h LightClone/Source/EventSource.cpp LightClone/Source/EventSource.h LightClone/Source/EventSystem.cpp LightClone/Source/EventSystem.h LightClone/Source/InputManager.cpp LightClone/Source/InputManager.h LightClone/Source/Mediator.cpp LightClone/Source/Mediator.h LightClone/Source/World.cpp LightClone/Source/World.h
diffstat 15 files changed, 8 insertions(+), 463 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 					>
 				</File>
 				<File
-					RelativePath=".\Source\Event.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\EventSink.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\EventSource.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\EventSystem.cpp"
-					>
-				</File>
-				<File
 					RelativePath=".\Source\GraphicsDevice.cpp"
 					>
 				</File>
@@ -434,22 +418,6 @@
 					>
 				</File>
 				<File
-					RelativePath=".\Source\Event.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\EventSink.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\EventSource.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\EventSystem.h"
-					>
-				</File>
-				<File
 					RelativePath=".\Source\FixedString.h"
 					>
 				</File>
--- 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"
-
--- 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__
--- 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()
-{
-}
--- 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<EventSink*> EventSinkList;
-
-#endif //__EVENTSINK_H__
--- 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
--- 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<EventSource*> EventSourceList;
-
-#endif //__EVENTSOURCE_H__
--- 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
--- 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__
--- 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);
-		}
 	}
 }
 
--- 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 <dinput.h>
 #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
--- 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);
 }
 
--- 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;
--- 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))
 	{
--- 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