Merge remote-tracking branch 'origin/GameLogic' into Camera

This commit is contained in:
Dander7BD 2014-02-11 09:34:17 +01:00
commit 5ddafc7fc2
13 changed files with 680 additions and 108 deletions

View File

@ -17,6 +17,9 @@
#include "vld.h" #include "vld.h"
#include "GameClientRecieverFunc.h" #include "GameClientRecieverFunc.h"
#include "../Misc/EventHandler/EventHandler.h"
using namespace Oyster::Event;
namespace DanBias namespace DanBias
{ {
@ -138,8 +141,6 @@ namespace DanBias
HRESULT DanBiasGame::Update(float deltaTime) HRESULT DanBiasGame::Update(float deltaTime)
{ {
m_data->inputObj->Update(); m_data->inputObj->Update();
if(m_data->serverOwner) if(m_data->serverOwner)

View File

@ -301,8 +301,8 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Flo
modelData.visible = true; modelData.visible = true;
//modelData.world = world; //modelData.world = world;
modelData.position = Oyster::Math::Float3(world[12], world[13], world[14]); modelData.position = Oyster::Math::Float3(world[12], world[13], world[14]);
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(0,0,0), 1);
modelData.scale = Oyster::Math::Float3(2,2,2); modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = modelName; modelData.modelPath = modelName;
modelData.id = myId; modelData.id = myId;
@ -593,7 +593,9 @@ void GameState::Protocol( ObjPos* pos )
{ {
if(dynamicObjects[i]->GetId() == pos->object_ID) 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 if(dynamicObjects[i]->GetId() == myId) // playerobj
{ {

View File

@ -51,6 +51,8 @@ void Level::InitiateLevel(std::string levelPath)
objects = ll.LoadLevel(levelPath); objects = ll.LoadLevel(levelPath);
int objCount = objects.size(); int objCount = objects.size();
int modelCount = 0; int modelCount = 0;
int staticObjCount = 0;
int dynamicObjCount = 0;
for (int i = 0; i < objCount; i++) for (int i = 0; i < objCount; i++)
{ {
ObjectTypeHeader* obj = objects.at(i); ObjectTypeHeader* obj = objects.at(i);
@ -72,120 +74,32 @@ void Level::InitiateLevel(std::string levelPath)
staticObjData->ModelFile; staticObjData->ModelFile;
ICustomBody* rigidBody_Static; ICustomBody* rigidBody_Static;
//if( staticObjPhysicData->geometryType = CollisionGeometryType_Box)
//{
// //API::SimpleBodyDescription sbDesc_Static;
// //sbDesc_Static.centerPosition = staticObjData->position; // collision shape
// //sbDesc_Static.ignoreGravity = false; // because it is static // radius, rotation in world, position in world, mass, restitution, static and dynamic friction
// //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 = 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); this->staticObjects[staticObjCount]->objectID = modelCount++;
// //sbDesc_Static.mass = staticObjPhysicData->mass; rigidBody->SetCustomTag(this->staticObjects[staticObjCount]);
// //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);*/
// }
//}
} }
break; break;
case ObjectType::ObjectType_Dynamic: case ObjectType::ObjectType_Dynamic:
{ {
ObjectHeader* staticObjData = ((ObjectHeader*)obj); ObjectHeader* staticObjData = ((ObjectHeader*)obj);
//LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj);
staticObjData->ModelFile; staticObjData->ModelFile;
ICustomBody* rigidBody_Dynamic; ICustomBody* rigidBody_Dynamic;
//if( staticObjPhysicData->geometryType = CollisionGeometryType_Box)
//{
// //API::Instance().AddCollisionBox()
// //API::SimpleBodyDescription sbDesc_Dynamic;
// //sbDesc_Dynamic.centerPosition = staticObjData->position; 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_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);
this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
// ////sbDesc_Static.inertiaTensor.Cuboid(staticObjPhysicData->mass); this->dynamicObjects[dynamicObjCount]->objectID = modelCount++;
// //sbDesc_Dynamic.mass = staticObjPhysicData->mass; rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]);
// //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]);
// //}
//}
} }
break; break;
case ObjectType::ObjectType_Light: case ObjectType::ObjectType_Light:

View File

@ -0,0 +1,261 @@
///////////////////////
// Sam Svensson 2013 //
///////////////////////
#ifndef MISC_EVENT_BUTTON_H
#define MISC_EVENT_BUTTON_H
#include "IEventButton.h"
namespace Oyster
{
namespace Event
{
template <typename Owner>
struct ButtonEvent
{
ButtonState state;
IEventButton* sender;
Owner owner;
void* userData;
};
template <typename Owner>
class EventButton : public IEventButton
{
protected:
//typedef for callback function pointer
typedef void (*EventFunc)(Oyster::Event::ButtonEvent<Owner>& e);
struct PrivData
{
PrivData() : ID(currID++){}
static unsigned int currID;
const unsigned int ID;
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(EventFunc func);
EventButton(EventFunc func, Owner owner);
EventButton(EventFunc func, Owner owner, void* userData);
~EventButton();
void Update(InputClass *input);
//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<Owner>& obj);
};
template <typename Owner>
unsigned int EventButton<Owner>::PrivData::currID = 0;
template <typename Owner>
EventButton<Owner>::EventButton()
{
this->privData.eventCallback = NULL;
this->privData.userData = NULL;
this->privData.previousState = ButtonState_None;
this->privData.enabled = true;
}
template <typename Owner>
EventButton<Owner>::EventButton(Owner owner)
{
this->privData.owner = owner;
this->privData.eventCallback = NULL;
this->privData.userData = NULL;
this->privData.previousState = ButtonState_None;
this->privData.enabled = true;
}
template <typename Owner>
EventButton<Owner>::EventButton(EventFunc func)
{
this->privData.eventCallback = func;
this->privData.userData = NULL;
this->privData.previousState = ButtonState_None;
this->privData.enabled = true;
}
template <typename Owner>
EventButton<Owner>::EventButton(EventFunc func, Owner owner)
{
this->privData.owner = owner;
this->privData.eventCallback = func;
this->privData.userData = NULL;
this->privData.previousState = ButtonState_None;
this->privData.enabled = true;
}
template <typename Owner>
EventButton<Owner>::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 <typename Owner>
EventButton<Owner>::~EventButton()
{}
//Checks for collision and
template <typename Owner>
void EventButton<Owner>::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 <typename Owner>
void EventButton<Owner>::SendEvent(ButtonState state)
{
if(privData.eventCallback != NULL)
{
Oyster::Event::ButtonEvent<Owner> event;
event.state = state;
event.sender = this;
event.owner = privData.owner;
event.userData = privData.userData;
privData.eventCallback(event);
}
}
template <typename Owner>
void EventButton<Owner>::SetUserData(void* data)
{
this->privData.userData = data;
}
template <typename Owner>
void EventButton<Owner>::SetEventFunc(EventFunc func)
{
this->privData.EventFunc = EventFunc;
}
template <typename Owner>
void EventButton<Owner>::SetOwner(Owner owner)
{
this->privData.owner = owner;
}
template <typename Owner>
bool EventButton<Owner>::Enabled()
{
return this->privData.enabled;
}
template <typename Owner>
unsigned int EventButton<Owner>::GetID()
{
return this->privData.ID;
}
/* Something is wrong, can't return EventFunc
template <typename Owner>
EventFunc EventButton<Owner>::GetFunctionPointer()
{
return this->privData.eventCallback;
}*/
template <typename Owner>
Owner EventButton<Owner>::GetOwner()
{
return this->privData.owner;
}
template <typename Owner>
bool EventButton<Owner>::operator ==(const EventButton<Owner>& obj)
{
return (this->privData.ID == obj.privData.ID);
}
}
}
#endif

View File

@ -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 <typename Owner>
class EventButtonCircle : public EventButton<Owner>
{
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<Owner>& e), float xPos, float yPos, float radius)
: EventButton(EventFunc), xPos(xPos), yPos(yPos), radius(radius)
{}
EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent<Owner>& e), Owner owner, float xPos, float yPos, float radius)
: EventButton(EventFunc, owner), xPos(xPos), yPos(yPos), radius(radius)
{}
EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent<Owner>& 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

View File

@ -0,0 +1,51 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#include "EventButtonCollection.h"
#include "../../Input/L_inputClass.h"
using namespace Oyster::Event;
EventButtonCollection::EventButtonCollection()
: collectionState(EventCollectionState_Enabled)
{
}
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 < (int)buttons.size(); i++)
{
buttons[i]->Update(inputObject);
}
}
}
EventCollectionState EventButtonCollection::GetState() const
{
return collectionState;
}
void EventButtonCollection::SetState(const EventCollectionState state)
{
collectionState = state;
}
void EventButtonCollection::Clear()
{
buttons.clear();
collectionState = EventCollectionState_Enabled;
}

View File

@ -0,0 +1,58 @@
//////////////////////////////////////
// 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"
#include <vector>
namespace Oyster
{
namespace Event
{
enum EventCollectionState
{
EventCollectionState_Disabled,
EventCollectionState_Enabled,
EventCollectionState_Count,
EventCollectionState_Unknown = -1,
};
class EventButtonCollection
{
public:
EventButtonCollection();
~EventButtonCollection();
void Update(InputClass* inputObject);
template <typename Owner>
void AddButton(EventButton<Owner>* button)
{
buttons.push_back(button);
}
EventCollectionState GetState() const;
void SetState(const EventCollectionState state);
//Clear all buttons and reset the state.
void Clear();
private:
std::vector<IEventButton*> buttons;
EventCollectionState collectionState;
};
}
}
#endif

View File

@ -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 <typename Owner>
class EventButtonRectangle : public EventButton<Owner>
{
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<Owner>& 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<Owner>& 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<Owner>& 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

View File

@ -0,0 +1,47 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#include "EventHandler.h"
using namespace Oyster::Event;
Oyster::Event::EventHandler EvtHandler;
EventHandler& EventHandler::Instance()
{
return EvtHandler;
}
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 < (int)collections.size(); i++)
{
collections.at(i)->Update(inputObject);
}
}
void EventHandler::AddCollection(EventButtonCollection& collection)
{
collections.push_back(&collection);
}
EventButtonCollection& EventHandler::CreateCollection()
{
EventButtonCollection* temp = new EventButtonCollection;
collections.push_back(temp);
return *temp;
}

View File

@ -0,0 +1,41 @@
//////////////////////////////////////
// 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 <vector>
namespace Oyster
{
namespace Event
{
class EventHandler
{
public:
EventHandler();
~EventHandler();
static EventHandler& Instance();
void Update(InputClass* inputObject);
void AddCollection(EventButtonCollection& collection);
EventButtonCollection& CreateCollection();
private:
std::vector<EventButtonCollection*> collections;
};
}
}
#endif

View File

@ -0,0 +1,41 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef MISC_IEVENT_BUTTON
#define MISC_IEVENT_BUTTON
class InputClass;
namespace Oyster
{
namespace Event
{
enum ButtonState
{
ButtonState_None,
ButtonState_Hover,
ButtonState_Pressed,
ButtonState_Down,
ButtonState_Released,
};
class IEventButton
{
public:
virtual ~IEventButton(){}
virtual void Update(InputClass *input){}
virtual void SendEvent(ButtonState state){}
struct ButtonEvent;
virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )){}
virtual unsigned int GetID(){ return -1; }
};
}
}
#endif

View File

@ -146,6 +146,8 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="EventHandler\EventButtonCollection.cpp" />
<ClCompile Include="EventHandler\EventHandler.cpp" />
<ClCompile Include="Packing\Packing.cpp" /> <ClCompile Include="Packing\Packing.cpp" />
<ClCompile Include="Resource\Loaders\ByteLoader.cpp" /> <ClCompile Include="Resource\Loaders\ByteLoader.cpp" />
<ClCompile Include="Resource\Loaders\CustomLoader.cpp" /> <ClCompile Include="Resource\Loaders\CustomLoader.cpp" />
@ -164,6 +166,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="DynamicArray.h" /> <ClInclude Include="DynamicArray.h" />
<ClInclude Include="EventHandler\EventButton.h" />
<ClInclude Include="EventHandler\EventButtonCircle.h" />
<ClInclude Include="EventHandler\EventButtonCollection.h" />
<ClInclude Include="EventHandler\EventButtonRectangle.h" />
<ClInclude Include="EventHandler\EventHandler.h" />
<ClInclude Include="EventHandler\IEventButton.h" />
<ClInclude Include="GID.h" /> <ClInclude Include="GID.h" />
<ClInclude Include="IQueue.h" /> <ClInclude Include="IQueue.h" />
<ClInclude Include="OysterCallback.h" /> <ClInclude Include="OysterCallback.h" />

View File

@ -51,6 +51,12 @@
<ClCompile Include="Packing\Packing.cpp"> <ClCompile Include="Packing\Packing.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="EventHandler\EventButtonCollection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="EventHandler\EventHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Utilities.h"> <ClInclude Include="Utilities.h">
@ -116,5 +122,23 @@
<ClInclude Include="Packing\Packing.h"> <ClInclude Include="Packing\Packing.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="EventHandler\EventButton.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventHandler\EventButtonCollection.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventHandler\EventHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventHandler\IEventButton.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventHandler\EventButtonCircle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventHandler\EventButtonRectangle.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>