From 8ee83741696d9909af25aa5fb3ede7bacc3c2a5e Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 31 Jan 2014 11:28:01 +0100 Subject: [PATCH 01/12] Misc - EventHandler --- Code/Game/DanBiasGame/GameClientRecieverFunc.h | 4 ++-- Code/Misc/EventHandler/EventButton.cpp | 0 Code/Misc/EventHandler/EventButton.h | 0 Code/Misc/EventHandler/EventButtonCollection.cpp | 0 Code/Misc/EventHandler/EventButtonCollection.h | 0 Code/Misc/EventHandler/EventHandler.cpp | 0 Code/Misc/EventHandler/EventHandler.h | 0 Code/Misc/Misc.vcxproj | 2 ++ Code/Misc/Misc.vcxproj.filters | 6 ++++++ 9 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 Code/Misc/EventHandler/EventButton.cpp create mode 100644 Code/Misc/EventHandler/EventButton.h create mode 100644 Code/Misc/EventHandler/EventButtonCollection.cpp create mode 100644 Code/Misc/EventHandler/EventButtonCollection.h create mode 100644 Code/Misc/EventHandler/EventHandler.cpp create mode 100644 Code/Misc/EventHandler/EventHandler.h diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h index b355027a..de8f63a6 100644 --- a/Code/Game/DanBiasGame/GameClientRecieverFunc.h +++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h @@ -130,8 +130,8 @@ namespace DanBias break; case protocol_Lobby_GameData: //this->LobbyGameData (Protocol_LobbyGameData (p), c); { - GameLogic::Protocol_LobbyGameData temp(p); - printf("%s, %i.%i\n", temp.mapName.c_str(), temp.majorVersion, temp.minorVersion); + //GameLogic::Protocol_LobbyGameData temp(p); + //printf("%s, %i.%i\n", temp.mapName.c_str(), temp.majorVersion, temp.minorVersion); } break; case protocol_Lobby_ClientData: //this->LobbyMainData (Protocol_LobbyClientData (p), c); diff --git a/Code/Misc/EventHandler/EventButton.cpp b/Code/Misc/EventHandler/EventButton.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h new file mode 100644 index 00000000..e69de29b diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h new file mode 100644 index 00000000..e69de29b diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h new file mode 100644 index 00000000..e69de29b diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 6c3db1ec..46b85f01 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -146,6 +146,7 @@ + @@ -164,6 +165,7 @@ + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index 8413642a..92a559df 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -51,6 +51,9 @@ Source Files + + Source Files + @@ -116,5 +119,8 @@ Header Files + + Header Files + \ No newline at end of file From d6769ac62f145283088d0d2d56b2a884ecf5baf2 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 31 Jan 2014 13:06:11 +0100 Subject: [PATCH 02/12] Misc - EventHandler, EventCollection --- .../EventHandler/EventButtonCollection.cpp | 25 +++++++++++++ .../Misc/EventHandler/EventButtonCollection.h | 31 ++++++++++++++++ Code/Misc/EventHandler/EventHandler.cpp | 37 +++++++++++++++++++ Code/Misc/EventHandler/EventHandler.h | 35 ++++++++++++++++++ Code/Misc/Misc.vcxproj | 8 +++- Code/Misc/Misc.vcxproj.filters | 16 +++++++- 6 files changed, 148 insertions(+), 4 deletions(-) diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index e69de29b..b3d37bfe 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -0,0 +1,25 @@ +#include "EventButtonCollection.h" + +using namespace Oyster::Event; + +EventButtonCollection::EventButtonCollection() +{ + +} + +EventButtonCollection::~EventButtonCollection() +{ +} + +void EventButtonCollection::Update(InputClass* inputObject) +{ + for(int i = 0; i < buttons.size(); i++) + { + buttons.at(i)->Update(inputObject); + } +} + +EventButton* EventButtonCollection::AddButton(EventButton* button) +{ + +} \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index e69de29b..31201f9c 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -0,0 +1,31 @@ +#ifndef EVENT_BUTTON_COLLECTION_H +#define EVENT_BUTTON_COLLECTION_H + +#include "../../Input/L_inputClass.h" + +#include "EventButton.h" + +#include + +namespace Oyster +{ + namespace Event + { + class EventButtonCollection + { + public: + EventButtonCollection(); + ~EventButtonCollection(); + + void Update(InputClass* inputObject); + + EventButton* AddButton(EventButton* button); + + private: + std::vector buttons; + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index e69de29b..8f6705df 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -0,0 +1,37 @@ +#include "EventHandler.h" + +using namespace Oyster::Event; + +EventHandler EvtHandler; + +EventHandler& EventHandler::Instance() +{ + return EvtHandler; +} + +EventHandler::EventHandler() +{ + +} + +EventHandler::~EventHandler() +{ +} + +void EventHandler::Update(InputClass* inputObject) +{ + for(int i = 0; i < collections.size(); i++) + { + collections.at(i)->Update(inputObject); + } +} + +EventButtonCollection* EventHandler::CreateCollection() +{ + +} + +EventButtonCollection* EventHandler::GetCollection(/*ID*/); +{ + +} \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index e69de29b..c3ecc0a2 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -0,0 +1,35 @@ +#ifndef EVENT_HANDLER_H +#define EVENT_HANDLER_H + +#include "../../Input/L_inputClass.h" + +#include "EventButtonCollection.h" +#include "EventButton.h" + +#include + +namespace Oyster +{ + namespace Event + { + class EventHandler + { + EventHandler(); + ~EventHandler(); + + EventHandler& Instance(); + + void Update(InputClass* inputObject); + + EventButtonCollection* CreateCollection(); + EventButtonCollection* GetCollection(/*ID*/); + + + private: + std::vector collections; + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 46b85f01..52b7c96c 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -146,7 +146,9 @@ - + + + @@ -163,9 +165,11 @@ + + - + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index 92a559df..d4874b4c 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -51,7 +51,13 @@ Source Files - + + Source Files + + + Source Files + + Source Files @@ -119,7 +125,13 @@ Header Files - + + Header Files + + + Header Files + + Header Files From a864ad81e71e0f65379b4c67b66ba8bffaec67ba Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 31 Jan 2014 14:16:58 +0100 Subject: [PATCH 03/12] Misc - EventHandler, EventCollection updated. --- .../EventHandler/EventButtonCollection.cpp | 36 ++++++++++++++++--- .../Misc/EventHandler/EventButtonCollection.h | 19 +++++++++- Code/Misc/EventHandler/EventHandler.cpp | 7 ++-- Code/Misc/EventHandler/EventHandler.h | 5 ++- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index b3d37bfe..268712c5 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -2,9 +2,9 @@ using namespace Oyster::Event; -EventButtonCollection::EventButtonCollection() +EventButtonCollection::EventButtonCollection() + : collectionState(EventCollectionState_Enabled) { - } EventButtonCollection::~EventButtonCollection() @@ -13,13 +13,39 @@ EventButtonCollection::~EventButtonCollection() void EventButtonCollection::Update(InputClass* inputObject) { - for(int i = 0; i < buttons.size(); i++) + if(this->collectionState == EventCollectionState_Enabled) { - buttons.at(i)->Update(inputObject); + for(int i = 0; i < buttons.size(); i++) + { + buttons.at(i)->CheckCollision(inputObject); + } } } -EventButton* EventButtonCollection::AddButton(EventButton* button) +void EventButtonCollection::AddButton(EventButton& button) { + buttons.push_back(button); +} +EventButton& EventButtonCollection::CreateButton() +{ + EventButton temp; + buttons.push_back(&temp); + return temp; +} + +EventCollectionState EventButtonCollection::GetState() const +{ + return collectionState; +} + +void EventButtonCollection::SetState(const EventCollectionState state) +{ + collectionState = state; +} + +void EventButtonCollection::Clear() +{ + buttons.clear(); + collectionState = EventCollectionState_Enabled; } \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 31201f9c..4368e195 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -11,6 +11,15 @@ namespace Oyster { namespace Event { + enum EventCollectionState + { + EventCollectionState_Disabled, + EventCollectionState_Enabled, + + EventCollectionState_Count, + EventCollectionState_Unknown = -1, + }; + class EventButtonCollection { public: @@ -19,10 +28,18 @@ namespace Oyster void Update(InputClass* inputObject); - EventButton* AddButton(EventButton* button); + void AddButton(EventButton& button); + EventButton& CreateButton(); + + EventCollectionState GetState() const; + void SetState(const EventCollectionState state); + + //Clear all buttons and reset the state. + void Clear(); private: std::vector buttons; + EventCollectionState collectionState; }; } diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 8f6705df..e064ad41 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -11,7 +11,6 @@ EventHandler& EventHandler::Instance() EventHandler::EventHandler() { - } EventHandler::~EventHandler() @@ -26,12 +25,12 @@ void EventHandler::Update(InputClass* inputObject) } } -EventButtonCollection* EventHandler::CreateCollection() +void EventHandler::AddCollection(EventButtonCollection& collection) { - + collections.push_back(&collection); } -EventButtonCollection* EventHandler::GetCollection(/*ID*/); +EventButtonCollection& EventHandler::CreateCollection() { } \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index c3ecc0a2..1a438e8c 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -21,9 +21,8 @@ namespace Oyster void Update(InputClass* inputObject); - EventButtonCollection* CreateCollection(); - EventButtonCollection* GetCollection(/*ID*/); - + void AddCollection(EventButtonCollection& collection); + EventButtonCollection& CreateCollection(); private: std::vector collections; From 8f83dcd41345d41082588077da157d1b31308d20 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Fri, 31 Jan 2014 14:29:29 +0100 Subject: [PATCH 04/12] GL- Eventbutton implemented --- Code/Misc/EventHandler/EventButton.cpp | 0 Code/Misc/EventHandler/EventButton.h | 126 +++++++++++++++++++++++++ 2 files changed, 126 insertions(+) delete mode 100644 Code/Misc/EventHandler/EventButton.cpp diff --git a/Code/Misc/EventHandler/EventButton.cpp b/Code/Misc/EventHandler/EventButton.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index e69de29b..189102cc 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -0,0 +1,126 @@ +/////////////////////// +// Sam Svensson 2013 // +/////////////////////// + +#include "../../Input/L_inputClass.h" +#include + +namespace Oyster +{ + namespace Event + { + + template + class EventButton + { + private: + enum ButtonState + { + Button_Clicked, + Button_Hover, + Button_Hold, + Button_Smashed, + }; + struct ButtonEvent + { + ButtonState state; + EventButton &sender; + T owner; + }; + + struct PrivData + { + static unsigned int currID; + unsigned int ID; + + T owner; + void (*EventFunc)( ButtonEvent e ); + }; + + PrivData privData; + + public: + EventButton(); + EventButton(T owner); + EventButton(void (*EventFunc)( ButtonEvent e)); + EventButton(void (*EventFunc)( ButtonEvent e), T owner); + + ~EventButton(); + + void checkCollision(InputClass *input); + + void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //? + + unsigned int GetID(); + T& GetOwner(); + + }; + + + template + EventButton::EventButton() + { + this->privData.ID = privData.currID; + this->privData.currID += 1; + this->privData.owner = NULL; + this->privData.EventFunc = NULL; + } + + template + EventButton::EventButton(T owner) + { + this->privData.ID = privData.currID; + this->privData.currID += 1; + this->privData.owner = owner; + this->privData.EventFunc = NULL; + } + + template + EventButton::EventButton(void (*EventFunc)( ButtonEvent e)) + { + this->privData.ID = privData.currID; + this->privData.currID += 1; + this->privData.owner = NULL; + this->privData.EventFunc = EventFunc; + } + + template + EventButton::EventButton(void (*EventFunc)( ButtonEvent e), T owner) + { + this->privData.ID = privData.currID; + this->privData.currID += 1; + this->privData.owner = owner; + this->privData.EventFunc = EventFunc; + } + + template + EventButton~EventButton() + { + + } + + template + void EventButton::checkCollision(InputClass *input) + { + //??????????????? TODO: everything + } + + template + void EventButton::SetEventFunc(void (*EventFunc)( ButtonEvent e )) + { + this->privData.EventFunc = EventFunc; + } + + template + unsigned int EventButton::GetID() + { + return this->privData.ID; + } + + template + T& EventButton::GetOwner() + { + return this->privData.owner; + } + } +} \ No newline at end of file From d5f285c089e4768509c4cf09fd8a0fcbc915ed2a Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 31 Jan 2014 14:31:27 +0100 Subject: [PATCH 05/12] Misc - Test --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 5 +++++ Code/Misc/EventHandler/EventHandler.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 4a54297f..24c14a0c 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -17,6 +17,9 @@ #include "vld.h" #include "GameClientRecieverFunc.h" +#include "../Misc/EventHandler/EventHandler.h" +using namespace Oyster::Event; + namespace DanBias { @@ -130,6 +133,8 @@ namespace DanBias HRESULT DanBiasGame::Update(float deltaTime) { + EventHandler::Instance(); + if(m_data->recieverObj->IsConnected()) m_data->recieverObj->Update(); diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index 1a438e8c..e19a8149 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -17,7 +17,7 @@ namespace Oyster EventHandler(); ~EventHandler(); - EventHandler& Instance(); + static EventHandler& Instance(); void Update(InputClass* inputObject); From e76dfc73f2a646354c4c8e167a9e9112c15178a8 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Fri, 31 Jan 2014 15:06:25 +0100 Subject: [PATCH 06/12] Misc - EventButton changed to inheritance --- Code/Misc/EventHandler/EventButton.h | 65 +++++++++++---------------- Code/Misc/EventHandler/IEventButton.h | 41 +++++++++++++++++ Code/Misc/Misc.vcxproj | 1 + Code/Misc/Misc.vcxproj.filters | 3 ++ 4 files changed, 71 insertions(+), 39 deletions(-) create mode 100644 Code/Misc/EventHandler/IEventButton.h diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 189102cc..e4ba0a4d 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -4,36 +4,23 @@ #include "../../Input/L_inputClass.h" #include +#include "IEventButton.h" namespace Oyster { namespace Event { - - template - class EventButton + template + class EventButton : public IEventButton { private: - enum ButtonState - { - Button_Clicked, - Button_Hover, - Button_Hold, - Button_Smashed, - }; - struct ButtonEvent - { - ButtonState state; - EventButton &sender; - T owner; - }; - + struct PrivData { static unsigned int currID; unsigned int ID; - T owner; + owner owner; void (*EventFunc)( ButtonEvent e ); }; @@ -41,9 +28,9 @@ namespace Oyster public: EventButton(); - EventButton(T owner); + EventButton(owner owner); EventButton(void (*EventFunc)( ButtonEvent e)); - EventButton(void (*EventFunc)( ButtonEvent e), T owner); + EventButton(void (*EventFunc)( ButtonEvent e), owner owner); ~EventButton(); @@ -52,13 +39,13 @@ namespace Oyster void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //? unsigned int GetID(); - T& GetOwner(); + owner& GetOwner(); }; - template - EventButton::EventButton() + template + EventButton::EventButton() { this->privData.ID = privData.currID; this->privData.currID += 1; @@ -66,8 +53,8 @@ namespace Oyster this->privData.EventFunc = NULL; } - template - EventButton::EventButton(T owner) + template + EventButton::EventButton(owner owner) { this->privData.ID = privData.currID; this->privData.currID += 1; @@ -75,8 +62,8 @@ namespace Oyster this->privData.EventFunc = NULL; } - template - EventButton::EventButton(void (*EventFunc)( ButtonEvent e)) + template + EventButton::EventButton(void (*EventFunc)( ButtonEvent e)) { this->privData.ID = privData.currID; this->privData.currID += 1; @@ -84,8 +71,8 @@ namespace Oyster this->privData.EventFunc = EventFunc; } - template - EventButton::EventButton(void (*EventFunc)( ButtonEvent e), T owner) + template + EventButton::EventButton(void (*EventFunc)( ButtonEvent e), owner owner) { this->privData.ID = privData.currID; this->privData.currID += 1; @@ -93,32 +80,32 @@ namespace Oyster this->privData.EventFunc = EventFunc; } - template - EventButton~EventButton() + template + EventButton~EventButton() { } - template - void EventButton::checkCollision(InputClass *input) + template + void EventButton::checkCollision(InputClass *input) { //??????????????? TODO: everything } - template - void EventButton::SetEventFunc(void (*EventFunc)( ButtonEvent e )) + template + void EventButton::SetEventFunc(void (*EventFunc)( ButtonEvent e )) { this->privData.EventFunc = EventFunc; } - template - unsigned int EventButton::GetID() + template + unsigned int EventButton::GetID() { return this->privData.ID; } - template - T& EventButton::GetOwner() + template + owner& EventButton::GetOwner() { return this->privData.owner; } diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h new file mode 100644 index 00000000..35a8827c --- /dev/null +++ b/Code/Misc/EventHandler/IEventButton.h @@ -0,0 +1,41 @@ +#include "../../Input/L_inputClass.h" + +namespace Oyster +{ + namespace Event + { + class IEventButton + { + + private: + + enum ButtonState + { + Button_Clicked, + Button_Hover, + Button_Hold, + Button_Smashed, + }; + + struct ButtonEvent + { + ButtonState state; + IEventButton &sender; + + template + owner owner; + }; + + public: + virtual void checkCollision(InputClass *input) = 0; + + virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )) = 0; + + virtual unsigned int GetID() = 0; + + template + virtual owner& GetOwner() = 0; + + }; + } +} \ No newline at end of file diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 52b7c96c..2d2d35f4 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -167,6 +167,7 @@ + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index d4874b4c..7bc3ffc9 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -134,5 +134,8 @@ Header Files + + Header Files + \ No newline at end of file From dbe8b4706b2e856eb47c46611433e01feb6dc8b2 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 31 Jan 2014 15:06:30 +0100 Subject: [PATCH 07/12] Misc - Changed to no template/template --- Code/Misc/EventHandler/EventButton.h | 11 +++++++---- Code/Misc/EventHandler/EventButtonCollection.cpp | 6 ++++-- Code/Misc/EventHandler/EventButtonCollection.h | 10 +++++++--- Code/Misc/Misc.vcxproj | 1 - Code/Misc/Misc.vcxproj.filters | 3 --- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 189102cc..99eb9279 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -9,11 +9,8 @@ namespace Oyster { namespace Event { - - template - class EventButton + struct IButton { - private: enum ButtonState { Button_Clicked, @@ -21,6 +18,12 @@ namespace Oyster Button_Hold, Button_Smashed, }; + }; + template + class EventButton :public IButton + { + private: + struct ButtonEvent { ButtonState state; diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 268712c5..859abc4d 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -22,12 +22,14 @@ void EventButtonCollection::Update(InputClass* inputObject) } } -void EventButtonCollection::AddButton(EventButton& button) +template +void EventButtonCollection::AddButton(EventButton& button) { buttons.push_back(button); } -EventButton& EventButtonCollection::CreateButton() +template +EventButton& EventButtonCollection::CreateButton() { EventButton temp; buttons.push_back(&temp); diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 4368e195..9065ffc5 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -3,6 +3,7 @@ #include "../../Input/L_inputClass.h" +#include "IEventButton.h" #include "EventButton.h" #include @@ -28,8 +29,11 @@ namespace Oyster void Update(InputClass* inputObject); - void AddButton(EventButton& button); - EventButton& CreateButton(); + template + void AddButton(EventButton& button); + + template + EventButton& CreateButton(); EventCollectionState GetState() const; void SetState(const EventCollectionState state); @@ -38,7 +42,7 @@ namespace Oyster void Clear(); private: - std::vector buttons; + std::vector buttons; EventCollectionState collectionState; }; diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 52b7c96c..76191ba0 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -146,7 +146,6 @@ - diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index d4874b4c..649b0e5b 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -54,9 +54,6 @@ Source Files - - Source Files - Source Files From 6f264f5e7b8909ce8bb531b83a43039ef442b932 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 31 Jan 2014 15:38:12 +0100 Subject: [PATCH 08/12] Misc - EventHandler fixed all errors. --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 1 - Code/Misc/EventHandler/EventButton.h | 44 +++++++++++++--------- Code/Misc/EventHandler/EventHandler.cpp | 6 ++- Code/Misc/EventHandler/EventHandler.h | 1 + Code/Misc/EventHandler/IEventButton.h | 26 +++++-------- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 24c14a0c..ea3a3fc9 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -133,7 +133,6 @@ namespace DanBias HRESULT DanBiasGame::Update(float deltaTime) { - EventHandler::Instance(); if(m_data->recieverObj->IsConnected()) m_data->recieverObj->Update(); diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 01da474c..547cdb47 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -2,19 +2,25 @@ // Sam Svensson 2013 // /////////////////////// +#ifndef MISC_EVENT_BUTTON_H +#define MISC_EVENT_BUTTON_H #include "../../Input/L_inputClass.h" -#include -#include "IEventButton.h" namespace Oyster { namespace Event { - - template - class EventButton : public IEventButton + template + class EventButton { private: + struct ButtonEvent + { + IEventButton::ButtonState state; + EventButton &sender; + owner owner; + }; + struct PrivData { static unsigned int currID; @@ -34,7 +40,7 @@ namespace Oyster ~EventButton(); - void checkCollision(InputClass *input); + void CheckCollision(InputClass *input); void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //? @@ -44,7 +50,7 @@ namespace Oyster }; - template + template EventButton::EventButton() { this->privData.ID = privData.currID; @@ -53,7 +59,7 @@ namespace Oyster this->privData.EventFunc = NULL; } - template + template EventButton::EventButton(owner owner) { this->privData.ID = privData.currID; @@ -62,7 +68,7 @@ namespace Oyster this->privData.EventFunc = NULL; } - template + template EventButton::EventButton(void (*EventFunc)( ButtonEvent e)) { this->privData.ID = privData.currID; @@ -71,7 +77,7 @@ namespace Oyster this->privData.EventFunc = EventFunc; } - template + template EventButton::EventButton(void (*EventFunc)( ButtonEvent e), owner owner) { this->privData.ID = privData.currID; @@ -80,34 +86,36 @@ namespace Oyster this->privData.EventFunc = EventFunc; } - template - EventButton~EventButton() + template + EventButton::~EventButton() { } - template - void EventButton::checkCollision(InputClass *input) + template + void EventButton::CheckCollision(InputClass *input) { //??????????????? TODO: everything } - template + template void EventButton::SetEventFunc(void (*EventFunc)( ButtonEvent e )) { this->privData.EventFunc = EventFunc; } - template + template unsigned int EventButton::GetID() { return this->privData.ID; } - template + template owner& EventButton::GetOwner() { return this->privData.owner; } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index e064ad41..0d270997 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -2,7 +2,7 @@ using namespace Oyster::Event; -EventHandler EvtHandler; +Oyster::Event::EventHandler EvtHandler; EventHandler& EventHandler::Instance() { @@ -32,5 +32,7 @@ void EventHandler::AddCollection(EventButtonCollection& collection) EventButtonCollection& EventHandler::CreateCollection() { - + EventButtonCollection temp; + collections.push_back(&temp); + return temp; } \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index e19a8149..7fb86b13 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -14,6 +14,7 @@ namespace Oyster { class EventHandler { + public: EventHandler(); ~EventHandler(); diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 35a8827c..4b2467c6 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -1,3 +1,5 @@ +#ifndef MISC_IEVENT_BUTTON +#define MISC_IEVENT_BUTTON #include "../../Input/L_inputClass.h" namespace Oyster @@ -6,8 +8,8 @@ namespace Oyster { class IEventButton { - - private: + + public: enum ButtonState { @@ -17,25 +19,15 @@ namespace Oyster Button_Smashed, }; - struct ButtonEvent - { - ButtonState state; - IEventButton &sender; - - template - owner owner; - }; - - public: - virtual void checkCollision(InputClass *input) = 0; + virtual void CheckCollision(InputClass *input) = 0; + struct ButtonEvent; virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )) = 0; virtual unsigned int GetID() = 0; - - template - virtual owner& GetOwner() = 0; }; } -} \ No newline at end of file +} + +#endif \ No newline at end of file From 9671eb8ee9ce1945c508974874bdd44dded432bf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 3 Feb 2014 10:41:54 +0100 Subject: [PATCH 09/12] Misc - Having problems with template with events. --- Code/Misc/EventHandler/EventButton.h | 29 ++++++++++++------- .../EventHandler/EventButtonCollection.cpp | 6 ++-- .../Misc/EventHandler/EventButtonCollection.h | 2 +- Code/Misc/EventHandler/IEventButton.h | 2 ++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 547cdb47..6a0a2cfb 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -13,7 +13,7 @@ namespace Oyster template class EventButton { - private: + public: struct ButtonEvent { IEventButton::ButtonState state; @@ -42,13 +42,16 @@ namespace Oyster void CheckCollision(InputClass *input); + void SendEvent(IEventButton::ButtonState state); + void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //? unsigned int GetID(); - owner& GetOwner(); }; - + + template + unsigned int EventButton::PrivData::currID = 0; template EventButton::EventButton() @@ -73,7 +76,7 @@ namespace Oyster { this->privData.ID = privData.currID; this->privData.currID += 1; - this->privData.owner = NULL; + //this->privData.owner = NULL; this->privData.EventFunc = EventFunc; } @@ -96,6 +99,17 @@ namespace Oyster void EventButton::CheckCollision(InputClass *input) { //??????????????? TODO: everything + SendEvent(Button_Smashed); + } + + template + void EventButton::SendEvent(IEventButton::ButtonState state) + { + ButtonEvent event; + event.state = state; + event.sender = this; + event.owner = privData.owner; + privData.EventFunc(event); } template @@ -109,13 +123,8 @@ namespace Oyster { return this->privData.ID; } - - template - owner& EventButton::GetOwner() - { - return this->privData.owner; - } } } + #endif \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 859abc4d..a6e4ed40 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -23,16 +23,16 @@ void EventButtonCollection::Update(InputClass* inputObject) } template -void EventButtonCollection::AddButton(EventButton& button) +void EventButtonCollection::AddButton(Owner a) { - buttons.push_back(button); + //buttons.push_back(button); } template EventButton& EventButtonCollection::CreateButton() { EventButton temp; - buttons.push_back(&temp); + buttons.push_back((IEventButton)&temp); return temp; } diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 9065ffc5..2a3faf35 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -30,7 +30,7 @@ namespace Oyster void Update(InputClass* inputObject); template - void AddButton(EventButton& button); + void AddButton(Owner a); template EventButton& CreateButton(); diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 4b2467c6..236ab73c 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -21,6 +21,8 @@ namespace Oyster virtual void CheckCollision(InputClass *input) = 0; + virtual void SendEvent(IEventButton::ButtonState state) = 0; + struct ButtonEvent; virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )) = 0; From 50d28a5784163fe6186bfc6147f9386700a67281 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 4 Feb 2014 08:46:20 +0100 Subject: [PATCH 10/12] Misc - Still having problems with template with eventhandler. --- Code/Misc/EventHandler/EventButton.h | 2 +- .../EventHandler/EventButtonCollection.cpp | 14 -------------- .../Misc/EventHandler/EventButtonCollection.h | 19 +++++++++++++++---- Code/Misc/EventHandler/IEventButton.h | 2 -- Code/Misc/Misc.vcxproj | 2 +- Code/Misc/Misc.vcxproj.filters | 10 +++++----- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 6a0a2cfb..e8fbc690 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -58,7 +58,7 @@ namespace Oyster { this->privData.ID = privData.currID; this->privData.currID += 1; - this->privData.owner = NULL; + //this->privData.owner = NULL; this->privData.EventFunc = NULL; } diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index a6e4ed40..7908816e 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -22,20 +22,6 @@ void EventButtonCollection::Update(InputClass* inputObject) } } -template -void EventButtonCollection::AddButton(Owner a) -{ - //buttons.push_back(button); -} - -template -EventButton& EventButtonCollection::CreateButton() -{ - EventButton temp; - buttons.push_back((IEventButton)&temp); - return temp; -} - EventCollectionState EventButtonCollection::GetState() const { return collectionState; diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 2a3faf35..130d59fa 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -29,11 +29,22 @@ namespace Oyster void Update(InputClass* inputObject); - template - void AddButton(Owner a); + template + void AddButton(EventButton& button) + { + EventButton* b = new EventButton(); + buttons.size(); + buttons.push_back((IEventButton*)b); + //buttons.push_back((IEventButton*)&button); + } - template - EventButton& CreateButton(); + template + EventButton& CreateButton() + { + EventButton temp; + buttons.push_back(&temp); + return temp; + } EventCollectionState GetState() const; void SetState(const EventCollectionState state); diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 236ab73c..92c58c10 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -8,9 +8,7 @@ namespace Oyster { class IEventButton { - public: - enum ButtonState { Button_Clicked, diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 51b905d2..f3e58e56 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -166,10 +166,10 @@ + - diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index f8309aed..edcf0e99 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -51,10 +51,10 @@ Source Files - + Source Files - + Source Files @@ -122,15 +122,15 @@ Header Files - - Header Files - Header Files Header Files + + Header Files + Header Files From 9a82b7002055cc769e30e934daa363eadcf050d9 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 11 Feb 2014 09:16:01 +0100 Subject: [PATCH 11/12] Misc - Button system working. (Logic) --- Code/Misc/EventHandler/EventButton.h | 273 +++++++++++++----- Code/Misc/EventHandler/EventButtonCircle.h | 64 ++++ .../EventHandler/EventButtonCollection.cpp | 16 +- .../Misc/EventHandler/EventButtonCollection.h | 25 +- Code/Misc/EventHandler/EventButtonRectangle.h | 60 ++++ Code/Misc/EventHandler/EventHandler.cpp | 17 +- Code/Misc/EventHandler/EventHandler.h | 10 +- Code/Misc/EventHandler/IEventButton.h | 32 +- Code/Misc/Misc.vcxproj | 2 + Code/Misc/Misc.vcxproj.filters | 6 + 10 files changed, 399 insertions(+), 106 deletions(-) create mode 100644 Code/Misc/EventHandler/EventButtonCircle.h create mode 100644 Code/Misc/EventHandler/EventButtonRectangle.h diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index e8fbc690..64215da2 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -4,125 +4,256 @@ #ifndef MISC_EVENT_BUTTON_H #define MISC_EVENT_BUTTON_H -#include "../../Input/L_inputClass.h" + +#include "IEventButton.h" namespace Oyster { namespace Event { - template - class EventButton + template + struct ButtonEvent { - public: - struct ButtonEvent - { - IEventButton::ButtonState state; - EventButton &sender; - owner owner; - }; + ButtonState state; + IEventButton* sender; + Owner owner; + void* userData; + }; + + template + class EventButton : public IEventButton + { + protected: + //typedef for callback function pointer + typedef void (*EventFunc)(Oyster::Event::ButtonEvent& e); struct PrivData { + PrivData() : ID(currID++){} + static unsigned int currID; - unsigned int ID; + const unsigned int ID; - owner owner; - void (*EventFunc)( ButtonEvent e ); + ButtonState previousState; + Owner owner; + EventFunc eventCallback; + void* userData; + bool enabled; }; - + + PrivData privData; + private: + //Implement this in the inherited classes for collision against that shape. + virtual bool Collision(InputClass *input) = 0; + public: EventButton(); - EventButton(owner owner); - EventButton(void (*EventFunc)( ButtonEvent e)); - EventButton(void (*EventFunc)( ButtonEvent e), owner owner); - + EventButton(Owner owner); + EventButton(EventFunc func); + EventButton(EventFunc func, Owner owner); + EventButton(EventFunc func, Owner owner, void* userData); ~EventButton(); - - void CheckCollision(InputClass *input); - void SendEvent(IEventButton::ButtonState state); + void Update(InputClass *input); - void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //? + //Send event to callback function + void SendEvent(ButtonState state); + //Set + void SetUserData(void* data); + void SetEventFunc(EventFunc func); + void SetOwner(Owner owner); + + //Get + bool Enabled(); unsigned int GetID(); - + //EventFunc GetFunctionPointer(); + Owner GetOwner(); + + bool operator ==(const EventButton& obj); + }; - template - unsigned int EventButton::PrivData::currID = 0; + template + unsigned int EventButton::PrivData::currID = 0; - template - EventButton::EventButton() + template + EventButton::EventButton() { - this->privData.ID = privData.currID; - this->privData.currID += 1; - //this->privData.owner = NULL; - this->privData.EventFunc = NULL; + this->privData.eventCallback = NULL; + this->privData.userData = NULL; + this->privData.previousState = ButtonState_None; + this->privData.enabled = true; } - template - EventButton::EventButton(owner owner) + template + EventButton::EventButton(Owner owner) { - this->privData.ID = privData.currID; - this->privData.currID += 1; this->privData.owner = owner; - this->privData.EventFunc = NULL; + this->privData.eventCallback = NULL; + this->privData.userData = NULL; + this->privData.previousState = ButtonState_None; + this->privData.enabled = true; } - template - EventButton::EventButton(void (*EventFunc)( ButtonEvent e)) + template + EventButton::EventButton(EventFunc func) { - this->privData.ID = privData.currID; - this->privData.currID += 1; - //this->privData.owner = NULL; - this->privData.EventFunc = EventFunc; + this->privData.eventCallback = func; + this->privData.userData = NULL; + this->privData.previousState = ButtonState_None; + this->privData.enabled = true; } - template - EventButton::EventButton(void (*EventFunc)( ButtonEvent e), owner owner) + template + EventButton::EventButton(EventFunc func, Owner owner) { - this->privData.ID = privData.currID; - this->privData.currID += 1; this->privData.owner = owner; + this->privData.eventCallback = func; + this->privData.userData = NULL; + this->privData.previousState = ButtonState_None; + this->privData.enabled = true; + } + + template + EventButton::EventButton(EventFunc func, Owner owner, void* userData) + { + this->privData.owner = owner; + this->privData.eventCallback = func; + this->privData.userData = userData; + this->privData.previousState = ButtonState_None; + this->privData.enabled = true; + } + + template + EventButton::~EventButton() + {} + + //Checks for collision and + template + void EventButton::Update(InputClass *input) + { + if(this->privData.enabled) + { + ButtonState currentState = ButtonState_None; + + if(Collision(input)) + { + if(input->IsMousePressed()) + { + //Change state when the mouse button is pressed + switch(this->privData.previousState) + { + case ButtonState_None: + currentState = ButtonState_Hover; + break; + + case ButtonState_Hover: + case ButtonState_Released: + currentState = ButtonState_Pressed; + break; + + case ButtonState_Pressed: + case ButtonState_Down: + currentState = ButtonState_Down; + break; + default: + break; + } + } + else + { + //Change state when the mouse button is NOT pressed + switch(this->privData.previousState) + { + case ButtonState_None: + case ButtonState_Hover: + case ButtonState_Released: + currentState = ButtonState_Hover; + break; + + case ButtonState_Pressed: + case ButtonState_Down: + currentState = ButtonState_Released; + break; + default: + break; + } + } + } + + //Only call the callback function when the state has changed. + if(this->privData.previousState != currentState) + SendEvent(currentState); + + this->privData.previousState = currentState; + } + } + + template + void EventButton::SendEvent(ButtonState state) + { + if(privData.eventCallback != NULL) + { + Oyster::Event::ButtonEvent event; + event.state = state; + event.sender = this; + event.owner = privData.owner; + event.userData = privData.userData; + privData.eventCallback(event); + } + } + + template + void EventButton::SetUserData(void* data) + { + this->privData.userData = data; + } + + template + void EventButton::SetEventFunc(EventFunc func) + { this->privData.EventFunc = EventFunc; } - template - EventButton::~EventButton() + template + void EventButton::SetOwner(Owner owner) { - + this->privData.owner = owner; } - template - void EventButton::CheckCollision(InputClass *input) + template + bool EventButton::Enabled() { - //??????????????? TODO: everything - SendEvent(Button_Smashed); - } - - template - void EventButton::SendEvent(IEventButton::ButtonState state) - { - ButtonEvent event; - event.state = state; - event.sender = this; - event.owner = privData.owner; - privData.EventFunc(event); + return this->privData.enabled; } - template - void EventButton::SetEventFunc(void (*EventFunc)( ButtonEvent e )) - { - this->privData.EventFunc = EventFunc; - } - - template - unsigned int EventButton::GetID() + template + unsigned int EventButton::GetID() { return this->privData.ID; } + + /* Something is wrong, can't return EventFunc + template + EventFunc EventButton::GetFunctionPointer() + { + return this->privData.eventCallback; + }*/ + + template + Owner EventButton::GetOwner() + { + return this->privData.owner; + } + + template + bool EventButton::operator ==(const EventButton& obj) + { + return (this->privData.ID == obj.privData.ID); + } } } diff --git a/Code/Misc/EventHandler/EventButtonCircle.h b/Code/Misc/EventHandler/EventButtonCircle.h new file mode 100644 index 00000000..3a298acb --- /dev/null +++ b/Code/Misc/EventHandler/EventButtonCircle.h @@ -0,0 +1,64 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef MISC_EVENT_BUTTON_CIRCLE_H +#define MISC_EVENT_BUTTON_CIRCLE_H + +#include "EventButton.h" +#include "../../Input/L_inputClass.h" + +namespace Oyster +{ + namespace Event + { + template + class EventButtonCircle : public EventButton + { + public: + EventButtonCircle() + : EventButton(), xPos(0), yPos(0), radius(0) + {} + EventButtonCircle(Owner owner, float xPos, float yPos, float radius) + : EventButton(owner), xPos(xPos), yPos(yPos), radius(radius) + {} + EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent& e), float xPos, float yPos, float radius) + : EventButton(EventFunc), xPos(xPos), yPos(yPos), radius(radius) + {} + EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent& e), Owner owner, float xPos, float yPos, float radius) + : EventButton(EventFunc, owner), xPos(xPos), yPos(yPos), radius(radius) + {} + EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent& e), Owner owner, void* userData, float xPos, float yPos, float radius) + : EventButton(EventFunc, owner, userData), xPos(xPos), yPos(yPos), radius(radius) + {} + ~EventButtonCircle() + {} + + //Circle vs point collision + bool Collision(InputClass* inputObject) + { + //Should come from the InputClass + float xMouse = 2, yMouse = 2; + + float xDiff = xMouse - xPos; + float yDiff = yMouse - yPos; + + float length = (xDiff * xDiff) + (yDiff * yDiff); + + if(length <= radius*radius) + { + return true; + } + + return false; + } + + private: + float xPos, yPos; + float radius; + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 7908816e..6a77c520 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -1,5 +1,11 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + #include "EventButtonCollection.h" +#include "../../Input/L_inputClass.h" + using namespace Oyster::Event; EventButtonCollection::EventButtonCollection() @@ -9,15 +15,21 @@ EventButtonCollection::EventButtonCollection() EventButtonCollection::~EventButtonCollection() { + int size = buttons.size(); + for(int i = 0; i < size; i++) + { + delete buttons[i]; + buttons[i] = NULL; + } } void EventButtonCollection::Update(InputClass* inputObject) { if(this->collectionState == EventCollectionState_Enabled) { - for(int i = 0; i < buttons.size(); i++) + for(int i = 0; i < (int)buttons.size(); i++) { - buttons.at(i)->CheckCollision(inputObject); + buttons[i]->Update(inputObject); } } } diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 130d59fa..0cc77b42 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -1,8 +1,14 @@ -#ifndef EVENT_BUTTON_COLLECTION_H -#define EVENT_BUTTON_COLLECTION_H +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef MISC_EVENT_BUTTON_COLLECTION_H +#define MISC_EVENT_BUTTON_COLLECTION_H #include "../../Input/L_inputClass.h" +#include "../DynamicArray.h" + #include "IEventButton.h" #include "EventButton.h" @@ -30,20 +36,9 @@ namespace Oyster void Update(InputClass* inputObject); template - void AddButton(EventButton& button) + void AddButton(EventButton* button) { - EventButton* b = new EventButton(); - buttons.size(); - buttons.push_back((IEventButton*)b); - //buttons.push_back((IEventButton*)&button); - } - - template - EventButton& CreateButton() - { - EventButton temp; - buttons.push_back(&temp); - return temp; + buttons.push_back(button); } EventCollectionState GetState() const; diff --git a/Code/Misc/EventHandler/EventButtonRectangle.h b/Code/Misc/EventHandler/EventButtonRectangle.h new file mode 100644 index 00000000..fc917437 --- /dev/null +++ b/Code/Misc/EventHandler/EventButtonRectangle.h @@ -0,0 +1,60 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef MISC_EVENT_BUTTON_RECTANGLE_H +#define MISC_EVENT_BUTTON_RECTANGLE_H + +#include "EventButton.h" +#include "../../Input/L_inputClass.h" + +namespace Oyster +{ + namespace Event + { + template + class EventButtonRectangle : public EventButton + { + public: + EventButtonRectangle() + : EventButton(), xPos(0), yPos(0), halfWidth(0), halfHeight(0) + {} + EventButtonRectangle(Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) + : EventButton(owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) + {} + EventButtonRectangle(void (*EventFunc)( Oyster::Event::ButtonEvent& e), float xPos, float yPos, float halfWidth, float halfHeight) + : EventButton(EventFunc), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) + {} + EventButtonRectangle(void (*EventFunc)( Oyster::Event::ButtonEvent& e), Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) + : EventButton(EventFunc, owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) + {} + EventButtonRectangle(void (*EventFunc)( Oyster::Event::ButtonEvent& e), Owner owner, void* userData, float xPos, float yPos, float halfWidth, float halfHeight) + : EventButton(EventFunc, owner, userData), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) + {} + ~EventButtonRectangle() + {} + + //Circle vs point collision + bool Collision(InputClass* inputObject) + { + //Should come from the InputClass + float xMouse = 1, yMouse = 0; + + if(xMouse >= xPos - halfWidth && xMouse <= xPos + halfWidth + && yMouse >= yPos - halfHeight && yMouse <= yPos + halfHeight) + { + return true; + } + + return false; + } + + private: + float xPos, yPos; + float halfWidth, halfHeight; + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 0d270997..a7347075 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -1,3 +1,7 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + #include "EventHandler.h" using namespace Oyster::Event; @@ -15,11 +19,16 @@ EventHandler::EventHandler() EventHandler::~EventHandler() { + int size = collections.size(); + for(int i = 0; i < size; i++) + { + delete collections[i]; + } } void EventHandler::Update(InputClass* inputObject) { - for(int i = 0; i < collections.size(); i++) + for(int i = 0; i < (int)collections.size(); i++) { collections.at(i)->Update(inputObject); } @@ -32,7 +41,7 @@ void EventHandler::AddCollection(EventButtonCollection& collection) EventButtonCollection& EventHandler::CreateCollection() { - EventButtonCollection temp; - collections.push_back(&temp); - return temp; + EventButtonCollection* temp = new EventButtonCollection; + collections.push_back(temp); + return *temp; } \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index 7fb86b13..4ca1a9ab 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -1,10 +1,16 @@ -#ifndef EVENT_HANDLER_H -#define EVENT_HANDLER_H +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef MISC_EVENT_HANDLER_H +#define MISC_EVENT_HANDLER_H #include "../../Input/L_inputClass.h" #include "EventButtonCollection.h" #include "EventButton.h" +#include "EventButtonCircle.h" +#include "EventButtonRectangle.h" #include diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 92c58c10..901a8265 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -1,30 +1,38 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + #ifndef MISC_IEVENT_BUTTON #define MISC_IEVENT_BUTTON -#include "../../Input/L_inputClass.h" + +class InputClass; namespace Oyster { namespace Event { + enum ButtonState + { + ButtonState_None, + ButtonState_Hover, + ButtonState_Pressed, + ButtonState_Down, + ButtonState_Released, + }; + class IEventButton { public: - enum ButtonState - { - Button_Clicked, - Button_Hover, - Button_Hold, - Button_Smashed, - }; + virtual ~IEventButton(){} - virtual void CheckCollision(InputClass *input) = 0; + virtual void Update(InputClass *input){} - virtual void SendEvent(IEventButton::ButtonState state) = 0; + virtual void SendEvent(ButtonState state){} struct ButtonEvent; - virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )) = 0; + virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )){} - virtual unsigned int GetID() = 0; + virtual unsigned int GetID(){ return -1; } }; } diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index f3e58e56..e329e9cd 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -165,7 +165,9 @@ + + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index edcf0e99..c50f2804 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -134,5 +134,11 @@ Header Files + + Header Files + + + Header Files + \ No newline at end of file From 489115840d3169745052102e5bbd62e9ed023e67 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 11 Feb 2014 09:17:16 +0100 Subject: [PATCH 12/12] GL - base for lvl loading --- .../DanBiasGame/GameClientState/GameState.cpp | 8 +- Code/Game/GameLogic/Level.cpp | 120 +++--------------- 2 files changed, 22 insertions(+), 106 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 9e52e218..8fecd86f 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -285,8 +285,8 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Flo modelData.visible = true; //modelData.world = world; modelData.position = Oyster::Math::Float3(world[12], world[13], world[14]); - modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); - modelData.scale = Oyster::Math::Float3(2,2,2); + modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(0,0,0), 1); + modelData.scale = Oyster::Math::Float3(1,1,1); modelData.modelPath = modelName; modelData.id = myId; @@ -565,7 +565,9 @@ void GameState::Protocol( ObjPos* pos ) { if(dynamicObjects[i]->GetId() == pos->object_ID) { - dynamicObjects[i]->setWorld(world); + + dynamicObjects[i]->setPos(Float3(world[12], world[13], world[14])); + if(dynamicObjects[i]->GetId() == myId) // playerobj { diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index ec571b9f..06d461fa 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -51,6 +51,8 @@ void Level::InitiateLevel(std::string levelPath) objects = ll.LoadLevel(levelPath); int objCount = objects.size(); int modelCount = 0; + int staticObjCount = 0; + int dynamicObjCount = 0; for (int i = 0; i < objCount; i++) { ObjectTypeHeader* obj = objects.at(i); @@ -71,121 +73,33 @@ void Level::InitiateLevel(std::string levelPath) //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj); staticObjData->ModelFile; - ICustomBody* rigidBody_Static; - //if( staticObjPhysicData->geometryType = CollisionGeometryType_Box) - //{ - // //API::SimpleBodyDescription sbDesc_Static; - - // //sbDesc_Static.centerPosition = staticObjData->position; - // //sbDesc_Static.ignoreGravity = false; // because it is static - // //sbDesc_Static.rotation = Oyster::Math::Float3(staticObjData->rotation[0], staticObjData->rotation[1],staticObjData->rotation[2]);//Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); + ICustomBody* rigidBody_Static; + // collision shape + // radius, rotation in world, position in world, mass, restitution, static and dynamic friction + ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); + + // add rigidbody to the logical obj + // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this + // set object_type to objID + this->staticObjects.Push(new StaticObject(rigidBody,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); - // ////sbDesc_Static.inertiaTensor.Cuboid(staticObjPhysicData->mass); - // //sbDesc_Static.mass = staticObjPhysicData->mass; - // //sbDesc_Static.frictionCoeff_Static = staticObjPhysicData->frictionCoeffStatic; - // //sbDesc_Static.frictionCoeff_Dynamic = staticObjPhysicData->frictionCoeffDynamic; - // ////sbDesc_Static.restitutionCoeff = - // //sbDesc_Static.size = Oyster::Math::Float3(40,40,40); - // //rigidBody_Static = API::Instance().CreateRigidBody(sbDesc_Static).Release(); - // //if(rigidBody_Static) - // //{ - // // this->staticObjects.Push(new StaticObject(rigidBody_Static,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); - // // int id = this->staticObjects.Size()-1; - // // rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]); - // //} - //} - //if( staticObjPhysicData->geometryType = CollisionGeometryType_Sphere) - //{ - // //API::SphericalBodyDescription sbDesc_Static; - - // //sbDesc_Static.centerPosition = staticObjData->position; - // //sbDesc_Static.ignoreGravity = true; // because it is static - // //sbDesc_Static.rotation = Oyster::Math::Float3(staticObjData->rotation[0], staticObjData->rotation[1],staticObjData->rotation[2]);//Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); - - // ////sbDesc_Static.inertiaTensor.Sphere(staticObjPhysicData->mass); - - // //sbDesc_Static.mass = staticObjPhysicData->mass; - // //sbDesc_Static.frictionCoeff_Static = staticObjPhysicData->frictionCoeffStatic; - // //sbDesc_Static.frictionCoeff_Dynamic = staticObjPhysicData->frictionCoeffDynamic; - // ////sbDesc_Static.restitutionCoeff = - // ////sbDesc_Static.radius = - // //rigidBody_Static = API::Instance().CreateRigidBody(sbDesc_Static).Release(); - // if(rigidBody_Static) - // { - // this->staticObjects.Push(new StaticObject(rigidBody_Static,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); - // int id = this->staticObjects.Size()-1; - // rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]); - // } - - // if (OBJECT_TYPE::OBJECT_TYPE_WORLD) - // { - // /*API::Gravity gravityWell; - // gravityWell.gravityType = API::Gravity::GravityType_Well; - // gravityWell.well.mass = 1e17f; - // gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); - // API::Instance().AddGravity(gravityWell);*/ - // } - //} + this->staticObjects[staticObjCount]->objectID = modelCount++; + rigidBody->SetCustomTag(this->staticObjects[staticObjCount]); } break; case ObjectType::ObjectType_Dynamic: { ObjectHeader* staticObjData = ((ObjectHeader*)obj); - //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj); staticObjData->ModelFile; ICustomBody* rigidBody_Dynamic; - //if( staticObjPhysicData->geometryType = CollisionGeometryType_Box) - //{ - // //API::Instance().AddCollisionBox() - // //API::SimpleBodyDescription sbDesc_Dynamic; - // //sbDesc_Dynamic.centerPosition = staticObjData->position; - // //sbDesc_Dynamic.ignoreGravity = false; // because it is static - // //sbDesc_Dynamic.rotation = Oyster::Math::Float3(staticObjData->rotation[0], staticObjData->rotation[1],staticObjData->rotation[2]);//Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); + rigidBody_Dynamic = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); - - // ////sbDesc_Static.inertiaTensor.Cuboid(staticObjPhysicData->mass); - // //sbDesc_Dynamic.mass = staticObjPhysicData->mass; - // //sbDesc_Dynamic.frictionCoeff_Static = staticObjPhysicData->frictionCoeffStatic; - // //sbDesc_Dynamic.frictionCoeff_Dynamic = staticObjPhysicData->frictionCoeffDynamic; - // ////sbDesc_Static.restitutionCoeff = - // //sbDesc_Dynamic.size = Oyster::Math::Float3(40,40,40); - // //rigidBody_Dynamic = API::Instance().CreateRigidBody(sbDesc_Dynamic).Release(); - // //if(rigidBody_Dynamic) - // //{ - // // rigidBody_Dynamic->SetSubscription(Level::PhysicsOnMoveLevel); - // // this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); - // // int id = this->dynamicObjects.Size()-1; - // // rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]); - // //} - //} - //if( staticObjPhysicData->geometryType = CollisionGeometryType_Sphere) - //{ - // //API::Instance().AddCollisionBox() - // //API::SphericalBodyDescription sbDesc_Dynamic; - - // //sbDesc_Dynamic.centerPosition = staticObjData->position; - // //sbDesc_Dynamic.ignoreGravity = false; // use gravity on dynamic obj - // //sbDesc_Dynamic.rotation = Oyster::Math::Float3(staticObjData->rotation[0], staticObjData->rotation[1],staticObjData->rotation[2]);//Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); - - // ////sbDesc_Static.inertiaTensor.Sphere(staticObjPhysicData->mass); - - // //sbDesc_Dynamic.mass = staticObjPhysicData->mass; - // //sbDesc_Dynamic.frictionCoeff_Static = staticObjPhysicData->frictionCoeffStatic; - // //sbDesc_Dynamic.frictionCoeff_Dynamic = staticObjPhysicData->frictionCoeffDynamic; - // ////sbDesc_Static.restitutionCoeff = - // ////sbDesc_Static.radius = - // //rigidBody_Dynamic = API::Instance().CreateRigidBody(sbDesc_Dynamic).Release(); - // //if(rigidBody_Dynamic) - // //{ - // // rigidBody_Dynamic->SetSubscription(Level::PhysicsOnMoveLevel); - // // this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); - // // int id = this->dynamicObjects.Size()-1; - // // rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]); - // //} - //} + this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects[dynamicObjCount]->objectID = modelCount++; + rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]); } break; case ObjectType::ObjectType_Light: