# HG changeset patch # User koryspansel # Date 1315963589 25200 # Node ID c046b9e8ae326caaabc75943c3e0af63fb29b557 # Parent d80d06d5ff53f129624233c9ec64d36669a58946 Work on event system diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/LightClone.vcproj --- a/LightClone/LightClone.vcproj Tue Sep 13 09:34:11 2011 -0700 +++ b/LightClone/LightClone.vcproj Tue Sep 13 18:26:29 2011 -0700 @@ -217,6 +217,22 @@ > + + + + + + + + @@ -295,6 +311,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + @@ -335,6 +355,22 @@ > + + + + + + + + @@ -383,6 +419,10 @@ > + + diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/ArrayList.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/ArrayList.h Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,163 @@ +/* + * ArrayList + */ + +#ifndef __ARRAYLIST_H__ +#define __ARRAYLIST_H__ + +#include "Core.h" + +/* + * ArrayList + */ +template +class ArrayList +{ + /* + * pList + */ + Type* pList; + + /* + * nCapacity + */ + uint32 nCapacity; + + /* + * nSize + */ + uint32 nSize; + +public: + + /* + * ArrayList + */ + ArrayList() : pList(0), nCapacity(0), nSize(0) + { + } + + /* + * ~ArrayList + */ + ~ArrayList() + { + delete[] pList; + } + + /* + * Add + */ + ErrorCode Add(Type& kValue) + { + ErrorCode eCode = Resize(nSize + 1); + if(eCode == Error_Success) + { + pList[nSize++] = kValue; + } + + return eCode; + } + + /* + * Remove + */ + ErrorCode Remove(uint32 nIndex) + { + ErrorCode eCode = Error_Fail; + + if(nIndex < nSize) + { + --nCount; + + for(uint32 i = nIndex; i < nCount; ++i) + { + pList[i] = pList[i + 1]; + } + + eCode = Error_Success + } + + return eCode; + } + + /* + * Clear + */ + void Clear() + { + nSize = 0; + } + + /* + * GetSize + */ + uint32 GetSize() const + { + return nSize; + } + + /* + * Find + */ + int32 Find(Type& kValue) const + { + for(uint32 i = 0; i < nSize; ++i) + { + if(pList[i] == kValue) + { + return (int32)i; + } + } + + return -1; + } + + /* + * operator [] + */ + Type& operator[](int nIndex) + { + //ASSERT(nIndex < nSize); + return pList[nIndex]; + } + + /* + * operator [] + */ + const Type& operator[](int nIndex) const + { + //ASSERT(nIndex < nSize); + return pList[nIndex]; + } + +private: + + /* + * Resize + */ + ErrorCode Resize(uint32 nAmount) + { + if(nAmount > nCapacity) + { + Type* pArray = new Type[2 * nAmount]; + + if(pList) + { + for(uint32 i = 0; i < nSize; ++i) + { + pArray[i] = pList[i]; + } + + delete[] pList; + } + + pList = pArray; + nCapacity = 2 * nAmount; + } + + return Error_Success; + } +}; + +#endif //__ARRAYLIST_H__ diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/Core.h --- a/LightClone/Source/Core.h Tue Sep 13 09:34:11 2011 -0700 +++ b/LightClone/Source/Core.h Tue Sep 13 18:26:29 2011 -0700 @@ -5,6 +5,7 @@ #ifndef __CORE_H__ #define __CORE_H__ +#include "Types.h" #include #include @@ -16,50 +17,6 @@ #endif /* - * int8 - */ -typedef signed char int8; - -/* - * int16 - */ -typedef signed short int16; - -/* - * int32 - */ -typedef signed int int32; - -/* - * uint8 - */ -typedef unsigned char uint8; - -/* - * uint16 - */ -typedef unsigned short uint16; - -/* - * uint32 - */ -typedef unsigned int uint32; - -/* - * ErrorCode - */ -typedef int32 ErrorCode; - -/* - * Error - */ -enum -{ - Error_Success = 0, - Error_Fail = -1, -}; - -/* * GameState */ enum diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/Event.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/Event.cpp Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,6 @@ +/* + * Event + */ + +#include "Event.h" + diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/Event.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/Event.h Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,27 @@ +/* + * Event + */ + +#ifndef __EVENT_H__ +#define __EVENT_H__ + +#include "Core.h" + +/* + * EventResult + */ +enum +{ + EventResult_Stop, + EventResult_Continue, + EventResult_Error, +}; + +/* + * Event + */ +struct Event +{ +}; + +#endif //__EVENT_H__ diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/EventSink.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/EventSink.cpp Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,12 @@ +/* + * EventSink + */ + +#include "EventSink.h" + +/* + * ~EventSink + */ +EventSink::~EventSink() +{ +} diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/EventSink.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/EventSink.h Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,34 @@ +/* + * EventSink + */ + +#ifndef __EVENTSINK_H__ +#define __EVENTSINK_H__ + +#include "Core.h" +#include "ArrayList.h" + +/* + * EventSink + */ +class EventSink +{ +public: + + /* + * ~EventSink + */ + virtual ~EventSink(); + + /* + * ProcessEvent + */ + virtual int32 ProcessEvent() = 0; +}; + +/* + * EventSinkList + */ +typedef ArrayList EventSinkList; + +#endif //__EVENTSINK_H__ diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/EventSource.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/EventSource.cpp Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,6 @@ +/* + * EventSource + */ + +#include "EventSource.h" + diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/EventSource.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/EventSource.h Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,37 @@ +/* + * EventSource + */ + +#ifndef __EVENTSOURCE_H__ +#define __EVENTSOURCE_H__ + +#include "Core.h" +#include "ArrayList.h" + +/* + * + +/* + * EventSource + */ +class EventSource +{ +public: + + /* + * ~EventSource + */ + virtual ~EventSource(); + + /* + * Generate + */ + virtual void Generate(EventSystem* pSystem); +}; + +/* + * EventSourceList + */ +typedef ArrayList EventSourceList; + +#endif //__EVENTSOURCE_H__ diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/EventSystem.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/EventSystem.cpp Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,37 @@ +/* + * EventSystem + */ + +#include "EventSystem.h" + +/* + * EventSystem + */ +EventSystem::EventSystem() +{ +} + +/* + * Post + */ +void EventSystem::Post(const Event& kEvent) +{ + for(uint32 i = 0; i < kSinks.GetSize(); ++i) + { + if(kSinks[i]->ProcessEvent() == EventResult_Stop) + { + break; + } + } +} + +/* + * Process + */ +void EventSystem::Process() +{ + for(uint32 i = 0; i < kSources.GetSize(); ++i) + { + kSources[i]->Generate(this); + } +} \ No newline at end of file diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/EventSystem.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/EventSystem.h Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,64 @@ +/* + * EventSystem + */ + +#ifndef __EVENTSYSTEM_H__ +#define __EVENTSYSTEM_H__ + +#include "Core.h" +#include "EventSource.h" +#include "EventSink.h" + +//TODO: Support registering sinks for specific events + +/* + * EventResult + */ +enum +{ + EventResult_Stop, + EventResult_Continue, + EventResult_Error, +}; + +/* + * Event + */ +struct Event +{ +}; + +/* + * EventSystem + */ +class EventSystem +{ + /* + * kSources + */ + EventSourceList kSources; + + /* + * kSinks + */ + EventSinkList kSinks; + +public: + + /* + * EventSystem + */ + EventSystem(); + + /* + * Post + */ + void Post(const Event& kEvent); + + /* + * Process + */ + void Process(); +}; + +#endif //__EVENTSYSTEM_H__ diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/GuiButton.cpp --- a/LightClone/Source/GuiButton.cpp Tue Sep 13 09:34:11 2011 -0700 +++ b/LightClone/Source/GuiButton.cpp Tue Sep 13 18:26:29 2011 -0700 @@ -84,14 +84,14 @@ D3DXMATRIX kTranslate; //D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + fX + 0.5f, 0.5f * ScreenSizeY - fY + 0.5f, 0.0f); - D3DXMatrixTranslation( + //D3DXMatrixTranslation( D3DXMATRIX kWorldMatrix; D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pBackgroundTexture); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture[nState]); pEffect->CommitChanges(); kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); diff -r d80d06d5ff53 -r c046b9e8ae32 LightClone/Source/Types.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/Types.h Tue Sep 13 18:26:29 2011 -0700 @@ -0,0 +1,52 @@ +/* + * Types + */ + +#ifndef __TYPES_H__ +#define __TYPES_H__ + +/* + * int8 + */ +typedef signed char int8; + +/* + * int16 + */ +typedef signed short int16; + +/* + * int32 + */ +typedef signed int int32; + +/* + * uint8 + */ +typedef unsigned char uint8; + +/* + * uint16 + */ +typedef unsigned short uint16; + +/* + * uint32 + */ +typedef unsigned int uint32; + +/* + * ErrorCode + */ +typedef int32 ErrorCode; + +/* + * Error + */ +enum +{ + Error_Success = 0, + Error_Fail = -1, +}; + +#endif //__TYPES_H__