Mercurial > LightClone
changeset 12:c046b9e8ae32
Work on event system
author | koryspansel |
---|---|
date | Tue, 13 Sep 2011 18:26:29 -0700 |
parents | d80d06d5ff53 |
children | 28cf0baf2772 |
files | LightClone/LightClone.vcproj LightClone/Source/ArrayList.h LightClone/Source/Core.h 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/GuiButton.cpp LightClone/Source/Types.h |
diffstat | 13 files changed, 481 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ > </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> @@ -295,6 +311,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > <File + RelativePath=".\Source\ArrayList.h" + > + </File> + <File RelativePath=".\Source\Bot.h" > </File> @@ -335,6 +355,22 @@ > </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\GraphicsDevice.h" > </File> @@ -383,6 +419,10 @@ > </File> <File + RelativePath=".\Source\Types.h" + > + </File> + <File RelativePath=".\Source\Util.h" > </File>
--- /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<typename Type> +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__
--- 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 <d3d9.h> #include <d3dx9.h> @@ -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
--- /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" +
--- /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__
--- /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() +{ +}
--- /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<EventSink*> EventSinkList; + +#endif //__EVENTSINK_H__
--- /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" +
--- /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<EventSource*> EventSourceList; + +#endif //__EVENTSOURCE_H__
--- /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
--- /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__
--- 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);
--- /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__