Merge branch 'GameLogic' of https://github.com/dean11/Danbias into GameLogic

This commit is contained in:
lindaandersson 2014-02-12 09:32:22 +01:00
commit 8c1f1e6608
14 changed files with 271 additions and 107 deletions

View File

@ -215,7 +215,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="GameClientRecieverFunc.h" /> <ClInclude Include="GameClientRecieverFunc.h" />
<ClInclude Include="GameClientState\Buttons\ButtonCircle.h" /> <ClInclude Include="GameClientState\Buttons\ButtonEllipse.h" />
<ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" /> <ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" />
<ClInclude Include="GameClientState\Buttons\ButtonRectangle.h" /> <ClInclude Include="GameClientState\Buttons\ButtonRectangle.h" />
<ClInclude Include="GameClientState\Camera.h" /> <ClInclude Include="GameClientState\Camera.h" />

View File

@ -59,8 +59,8 @@ namespace DanBias
{ {
WindowShell::CreateConsoleWindow(); WindowShell::CreateConsoleWindow();
//if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1024, 768), cPOINT())))
if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC())) //if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC()))
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
if( FAILED( InitDirect3D() ) ) if( FAILED( InitDirect3D() ) )
@ -132,7 +132,7 @@ namespace DanBias
HRESULT DanBiasGame::InitInput() HRESULT DanBiasGame::InitInput()
{ {
m_data->inputObj = new InputClass; m_data->inputObj = new InputClass;
if(!m_data->inputObj->Initialize(m_data->window->GetHINSTANCE(), m_data->window->GetHWND(), m_data->window->GetHeight(), m_data->window->GetWidth())) if(!m_data->inputObj->Initialize(m_data->window->GetHINSTANCE(), m_data->window->GetHWND(), m_data->window->GetWidth(), m_data->window->GetHeight()))
{ {
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK); MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
return E_FAIL; return E_FAIL;
@ -207,6 +207,8 @@ namespace DanBias
delete m_data->inputObj; delete m_data->inputObj;
delete m_data; delete m_data;
EventHandler::Instance().Clean();
Oyster::Graphics::API::Clean(); Oyster::Graphics::API::Clean();
GameServerAPI::ServerStop(); GameServerAPI::ServerStop();

View File

@ -1,62 +0,0 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef DANBIAS_CLIENT_BUTTON_CIRCLE_H
#define DANBIAS_CLIENT_BUTTON_CIRCLE_H
#include "EventButtonGUI.h"
namespace DanBias
{
namespace Client
{
template <typename Owner>
class ButtonCircle : public EventButtonGUI<Owner>
{
public:
ButtonCircle()
: EventButtonGUI(), radius(0)
{}
ButtonCircle(std::wstring textureName, Owner owner, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight)
: EventButtonGUI(textureName, owner, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius)
{}
ButtonCircle(std::wstring textureName, EventFunc func, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight)
: EventButtonGUI(textureName, func, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius)
{}
ButtonCircle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight)
: EventButtonGUI(textureName, func, owner, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius)
{}
ButtonCircle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight)
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius)
{}
~ButtonCircle()
{}
//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;
}
protected:
float radius;
};
}
}
#endif

View File

@ -0,0 +1,63 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef DANBIAS_CLIENT_BUTTON_CIRCLE_H
#define DANBIAS_CLIENT_BUTTON_CIRCLE_H
#include "EventButtonGUI.h"
//Only for testing because we don't have any other input
#include "../WindowManager/WindowShell.h"
namespace DanBias
{
namespace Client
{
template <typename Owner>
class ButtonEllipse : public EventButtonGUI<Owner>
{
public:
ButtonEllipse()
: EventButtonGUI(), radius(0)
{}
ButtonEllipse(std::wstring textureName, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight)
: EventButtonGUI(textureName, owner, xPos, yPos, textureWidth, textureHeight)
{}
ButtonEllipse(std::wstring textureName, EventFunc func, float xPos, float yPos, float textureWidth, float textureHeight)
: EventButtonGUI(textureName, func, xPos, yPos, textureWidth, textureHeight)
{}
ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight)
: EventButtonGUI(textureName, func, owner, xPos, yPos, textureWidth, textureHeight)
{}
ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float textureWidth, float textureHeight)
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureWidth, textureHeight)
{}
virtual ~ButtonEllipse()
{}
//Circle vs point collision
bool Collision(InputClass* inputObject)
{
POINT p;
GetCursorPos(&p);
ScreenToClient(WindowShell::GetHWND(), &p);
RECT r;
GetClientRect(WindowShell::GetHWND(), &r);
//Should come from the InputClass
float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom;
double normx = (xMouse - xPos) / width;
double normy = (yMouse - yPos) / height;
return (normx * normx + normy * normy) < 0.25;
}
protected:
};
}
}
#endif

View File

@ -6,6 +6,9 @@
#define DANBIAS_CLIENT_BUTTON_RECTANGLE_H #define DANBIAS_CLIENT_BUTTON_RECTANGLE_H
#include "EventButtonGUI.h" #include "EventButtonGUI.h"
#include <iostream>
//Only for testing because we don't have any other input
#include "../WindowManager/WindowShell.h"
namespace DanBias namespace DanBias
{ {
@ -16,31 +19,43 @@ namespace DanBias
{ {
public: public:
ButtonRectangle() ButtonRectangle()
: EventButtonGUI(), halfWidth(0), halfHeight(0) : EventButtonGUI(), width(0), height(0)
{} {}
ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height)
: EventButtonGUI(textureName, owner, xPos, yPos, halfWidth, halfHeight) : EventButtonGUI(textureName, owner, xPos, yPos, width, height)
{} {}
ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float halfWidth, float halfHeight) ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height)
: EventButtonGUI(textureName, func, xPos, yPos, halfWidth, halfHeight) : EventButtonGUI(textureName, func, xPos, yPos, width, height)
{} {}
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height)
: EventButtonGUI(textureName, func, owner, xPos, yPos, halfWidth, halfHeight) : EventButtonGUI(textureName, func, owner, xPos, yPos, width, height)
{} {}
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float halfWidth, float halfHeight) ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height)
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, halfWidth, halfHeight) : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, width, height)
{} {}
~ButtonRectangle() virtual ~ButtonRectangle()
{} {}
//Circle vs point collision //Circle vs point collision
bool Collision(InputClass* inputObject) bool Collision(InputClass* inputObject)
{ {
//Should come from the InputClass POINT p;
float xMouse = 1, yMouse = 0; RECT r;
GetCursorPos(&p);
ScreenToClient(WindowShell::GetHWND(), &p);
GetClientRect(WindowShell::GetHWND(), &r);
if(xMouse >= xPos - halfWidth && xMouse <= xPos + halfWidth //Should come from the InputClass
&& yMouse >= yPos - halfHeight && yMouse <= yPos + halfHeight) float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom;
float widthTemp = xPos - width * 0.5f;
float widthTemp2 = xPos + width * 0.5f;
float heightTemp = yPos - height * 0.5f;
float heightTemp2 = yPos + height * 0.5f;
//std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl;
if(xMouse >= widthTemp && xMouse <= widthTemp2 &&
yMouse >= heightTemp && yMouse <= heightTemp2)
{ {
return true; return true;
} }

View File

@ -6,6 +6,7 @@
#define DANBIAS_CLIENT_EVENT_BUTTON_GUI_H #define DANBIAS_CLIENT_EVENT_BUTTON_GUI_H
#include "../Misc/EventHandler/EventButton.h" #include "../Misc/EventHandler/EventButton.h"
#include "../OysterGraphics/DllInterfaces/GFXAPI.h"
namespace DanBias namespace DanBias
{ {
@ -16,49 +17,79 @@ namespace DanBias
{ {
public: public:
EventButtonGUI() EventButtonGUI()
: EventButton(), xPos(0), yPos(0), halfWidth(0), halfHeight(0), texture(NULL) : EventButton(), xPos(0), yPos(0), width(0), height(0), texture(NULL)
{} {}
EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height)
: EventButton(owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) : EventButton(owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
{ {
CreateTexture(textureName); CreateTexture(textureName);
} }
EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float halfWidth, float halfHeight) EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height)
: EventButton(func), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) : EventButton(func), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
{ {
CreateTexture(textureName); CreateTexture(textureName);
} }
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height)
: EventButton(func, owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) : EventButton(func, owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
{ {
CreateTexture(textureName); CreateTexture(textureName);
} }
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float halfWidth, float halfHeight) EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height)
: EventButton(func, owner, userData), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) : EventButton(func, owner, userData), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
{ {
CreateTexture(textureName); CreateTexture(textureName);
} }
~EventButtonGUI() virtual ~EventButtonGUI()
{} {
Oyster::Graphics::API::DeleteTexture(texture);
Oyster::Graphics::API::DeleteTexture(texture2);
Oyster::Graphics::API::DeleteTexture(texture3);
texture = NULL;
texture2 = NULL;
texture3 = NULL;
}
void CreateTexture(std::wstring textureName) void CreateTexture(std::wstring textureName)
{ {
std::wstring file = L".png";
//Create texture //Create texture
texture = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"none") + file);
texture2 = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"highlight") + file);
texture3 = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"down") + file);
} }
virtual void Render() virtual void Render()
{ {
if(EventButton<Owner>::Enabled()) if(EventButton<Owner>::Enabled())
{ {
//Render att xPos and yPos //Render att xPos and yPos
//With halfWidth and halfHeight //With width and height
if(EventButton<Owner>::GetState() == ButtonState_None)
{
Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height));
}
else if(EventButton<Owner>::GetState() == ButtonState_Hover)
{
Oyster::Graphics::API::RenderGuiElement(texture2, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height));
}
else
{
Oyster::Graphics::API::RenderGuiElement(texture3, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height));
}
} }
} }
protected: protected:
float xPos, yPos; float xPos, yPos;
float halfWidth, halfHeight; float width, height;
void* texture; Oyster::Graphics::API::Texture texture;
Oyster::Graphics::API::Texture texture2;
Oyster::Graphics::API::Texture texture3;
}; };
} }

View File

@ -9,7 +9,7 @@
using namespace DanBias::Client; using namespace DanBias::Client;
//Menu buttons //Menu buttons
#include "Buttons/ButtonCircle.h" #include "Buttons/ButtonEllipse.h"
#include "Buttons/ButtonRectangle.h" #include "Buttons/ButtonRectangle.h"
#include "../Misc/EventHandler/EventHandler.h" #include "../Misc/EventHandler/EventHandler.h"
using namespace Oyster::Event; using namespace Oyster::Event;
@ -27,6 +27,7 @@ struct LoginState::myData
//Menu button collection //Menu button collection
EventButtonCollection* collection; EventButtonCollection* collection;
int testNumber;
}privData; }privData;
@ -34,6 +35,8 @@ enum TestEnum
{ {
Create, Create,
Options, Options,
Incr,
Decr,
Exit, Exit,
}; };
@ -48,15 +51,46 @@ void LoginState::ButtonCallback(Oyster::Event::ButtonEvent<LoginState*>& e)
switch(type) switch(type)
{ {
case Create: case Create:
if(e.state == ButtonState_Released) /*if(e.state == ButtonState_None)
{
int a = 0;
std::cout << "None" << std::endl;
}
else if(e.state == ButtonState_Hover)
{
int a = 0;
std::cout << "Hover" << std::endl;
}
else if(e.state == ButtonState_Down)
{
int a = 0;
std::cout << "Down" << std::endl;
}
else if(e.state == ButtonState_Pressed)
{
int a = 0;
std::cout << "Pressed" << std::endl;
}
else if(e.state == ButtonState_Released)
{ {
//Change to create state or something similar //Change to create state or something similar
} int a = 0;
std::cout << "Released" << std::endl;
}*/
break; break;
case Options: case Options:
break; break;
case Exit: case Exit:
break; break;
case Incr:
if(e.state == ButtonState_Released)
e.owner->privData->testNumber++;
break;
case Decr:
if(e.state == ButtonState_Released)
e.owner->privData->testNumber--;
break;
} }
} }
@ -68,7 +102,7 @@ LoginState::~LoginState(void)
bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
{ {
privData = new myData(); privData = new myData();
this->nwClient = nwClient; this->nwClient = nwClient;
// load models // load models
//LoadModels(L"UImodels.txt"); //LoadModels(L"UImodels.txt");
InitCamera(Oyster::Math::Float3(0,0,5.4f)); InitCamera(Oyster::Math::Float3(0,0,5.4f));
@ -76,7 +110,23 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
//Create menu buttons //Create menu buttons
privData->collection = new EventButtonCollection; privData->collection = new EventButtonCollection;
EventHandler::Instance().AddCollection(privData->collection); EventHandler::Instance().AddCollection(privData->collection);
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"textureName.jpg", &LoginState::ButtonCallback, this, (void*)Options, 0.0f, 0.0f, 0.0f, 0.0f)); privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.2f, 0.1f, 0.2f));
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.3f, 0.1f, 0.2f));
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.4f, 0.1f, 0.2f));
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.5f, 0.1f, 0.2f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.15f, 0.05f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.25f, 0.05f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.35f, 0.05f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.45f, 0.05f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f));
//Incr/decr buttons
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f));
privData->testNumber = 0;
return true; return true;
} }
@ -146,6 +196,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key
// failed to connect // failed to connect
return ClientState_Same; return ClientState_Same;
} }
privData->collection->SetState(EventCollectionState_Disabled);
return ClientState_LobbyCreated; return ClientState_LobbyCreated;
} }
// join game // join game
@ -159,6 +210,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key
// failed to connect // failed to connect
return ClientState_Same; return ClientState_Same;
} }
privData->collection->SetState(EventCollectionState_Disabled);
return ClientState_Lobby; return ClientState_Lobby;
} }
return ClientState_Same; return ClientState_Same;
@ -181,8 +233,16 @@ bool LoginState::Render(float dt)
// render lights // render lights
//Render buttons //Render buttons
Oyster::Graphics::API::StartGuiRender();
EventHandler::Instance().Render(); EventHandler::Instance().Render();
std::wstring number;
wchar_t temp[10];
_itow_s(privData->testNumber, temp, 10);
number = temp;
Oyster::Graphics::API::StartTextRender();
Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7, 0.2), Oyster::Math::Float2(0.1, 0.1));
Oyster::Graphics::API::EndFrame(); Oyster::Graphics::API::EndFrame();
return true; return true;
} }
@ -196,6 +256,9 @@ bool LoginState::Release()
privData->object[i] = NULL; privData->object[i] = NULL;
} }
delete privData->collection;
//EventHandler::Instance().DeleteCollection(privData->collection);
delete privData; delete privData;
privData = NULL; privData = NULL;
return true; return true;

View File

@ -99,7 +99,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
Oyster::Math::Float3 look = owner->GetLookDir(); Oyster::Math::Float3 look = owner->GetLookDir();
Oyster::Math::Float3 pos = owner->GetPosition(); Oyster::Math::Float3 pos = owner->GetPosition();
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (20000 * dt); pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (200 * dt);
Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(look, up, pos); Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(look, up, pos);
Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/8,1,1,50); Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/8,1,1,50);

View File

@ -47,7 +47,7 @@ Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
{ {
this->rigidBody = rigidBody; this->rigidBody = rigidBody;
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)collisionFuncAfter);
this->type = type; this->type = type;
this->objectID = GID(); this->objectID = GID();
} }
@ -55,7 +55,7 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefor
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
{ {
this->rigidBody = rigidBody; this->rigidBody = rigidBody;
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)collisionFuncAfter);
this->type = type; this->type = type;
this->objectID = GID(); this->objectID = GID();
} }

View File

@ -54,7 +54,7 @@ namespace Oyster
EventButton(EventFunc func); EventButton(EventFunc func);
EventButton(EventFunc func, Owner owner); EventButton(EventFunc func, Owner owner);
EventButton(EventFunc func, Owner owner, void* userData); EventButton(EventFunc func, Owner owner, void* userData);
~EventButton(); virtual ~EventButton();
void Update(InputClass *input); void Update(InputClass *input);
@ -72,6 +72,7 @@ namespace Oyster
unsigned int GetID(); unsigned int GetID();
//EventFunc GetFunctionPointer(); //EventFunc GetFunctionPointer();
Owner GetOwner(); Owner GetOwner();
ButtonState GetState();
bool operator ==(const EventButton<Owner>& obj); bool operator ==(const EventButton<Owner>& obj);
@ -139,7 +140,8 @@ namespace Oyster
if(this->privData.enabled) if(this->privData.enabled)
{ {
ButtonState currentState = ButtonState_None; ButtonState currentState = ButtonState_None;
static bool outside = false;
static bool clicked = false;
if(Collision(input)) if(Collision(input))
{ {
if(input->IsMousePressed()) if(input->IsMousePressed())
@ -148,12 +150,19 @@ namespace Oyster
switch(this->privData.previousState) switch(this->privData.previousState)
{ {
case ButtonState_None: case ButtonState_None:
outside = true;
currentState = ButtonState_Hover; currentState = ButtonState_Hover;
break; break;
case ButtonState_Hover: case ButtonState_Hover:
case ButtonState_Released: case ButtonState_Released:
currentState = ButtonState_Pressed; if(outside == false)
{
clicked = true;
currentState = ButtonState_Pressed;
}
else
currentState = ButtonState_Hover;
break; break;
case ButtonState_Pressed: case ButtonState_Pressed:
@ -166,6 +175,7 @@ namespace Oyster
} }
else else
{ {
outside = false;
//Change state when the mouse button is NOT pressed //Change state when the mouse button is NOT pressed
switch(this->privData.previousState) switch(this->privData.previousState)
{ {
@ -173,6 +183,7 @@ namespace Oyster
case ButtonState_Hover: case ButtonState_Hover:
case ButtonState_Released: case ButtonState_Released:
currentState = ButtonState_Hover; currentState = ButtonState_Hover;
clicked = false;
break; break;
case ButtonState_Pressed: case ButtonState_Pressed:
@ -256,6 +267,12 @@ namespace Oyster
{ {
return this->privData.owner; return this->privData.owner;
} }
template <typename Owner>
ButtonState EventButton<Owner>::GetState()
{
return this->privData.previousState;
}
template <typename Owner> template <typename Owner>
bool EventButton<Owner>::operator ==(const EventButton<Owner>& obj) bool EventButton<Owner>::operator ==(const EventButton<Owner>& obj)

View File

@ -3,7 +3,7 @@
////////////////////////////////////// //////////////////////////////////////
#include "EventButtonCollection.h" #include "EventButtonCollection.h"
#include "EventHandler.h"
#include "../../Input/L_inputClass.h" #include "../../Input/L_inputClass.h"
using namespace Oyster::Event; using namespace Oyster::Event;
@ -15,6 +15,14 @@ EventButtonCollection::EventButtonCollection()
EventButtonCollection::~EventButtonCollection() EventButtonCollection::~EventButtonCollection()
{ {
for(int i = 0; i < EventHandler::Instance().collections.size(); i++)
{
if(EventHandler::Instance().collections.at(i) == this)
{
EventHandler::Instance().collections.erase(EventHandler::Instance().collections.begin() + i);
}
}
int size = buttons.size(); int size = buttons.size();
for(int i = 0; i < size; i++) for(int i = 0; i < size; i++)
{ {

View File

@ -26,6 +26,16 @@ EventHandler::~EventHandler()
} }
} }
void EventHandler::Clean()
{
int size = collections.size();
for(int i = 0; i < size; i++)
{
delete collections[i];
}
collections.clear();
}
void EventHandler::Update(InputClass* inputObject) void EventHandler::Update(InputClass* inputObject)
{ {
for(int i = 0; i < (int)collections.size(); i++) for(int i = 0; i < (int)collections.size(); i++)
@ -45,4 +55,17 @@ void EventHandler::Render()
void EventHandler::AddCollection(EventButtonCollection* collection) void EventHandler::AddCollection(EventButtonCollection* collection)
{ {
collections.push_back(collection); collections.push_back(collection);
}
void EventHandler::DeleteCollection(EventButtonCollection* collection)
{
for(int i = 0; i < collections.size(); i++)
{
if(collections.at(i) == collection)
{
delete collection;
collections.erase(collections.begin() + i);
break;
}
}
} }

View File

@ -24,14 +24,17 @@ namespace Oyster
static EventHandler& Instance(); static EventHandler& Instance();
void Clean();
void Update(InputClass* inputObject); void Update(InputClass* inputObject);
void Render(); void Render();
void AddCollection(EventButtonCollection* collection); void AddCollection(EventButtonCollection* collection);
void DeleteCollection(EventButtonCollection* collection);
private: private:
std::vector<EventButtonCollection*> collections; std::vector<EventButtonCollection*> collections;
friend class EventButtonCollection;
}; };
} }
} }

View File

@ -389,6 +389,7 @@ namespace Oyster
Gui::Pass.RenderStates.SampleCount = 1; Gui::Pass.RenderStates.SampleCount = 1;
Gui::Pass.RenderStates.SampleState = RenderStates::ss; Gui::Pass.RenderStates.SampleState = RenderStates::ss;
Gui::Pass.RenderStates.BlendState = RenderStates::bs;
////---------------- Blur Pass Setup ---------------------------- ////---------------- Blur Pass Setup ----------------------------
Blur::HorPass.Shaders.Compute = GetShader::Compute(L"BlurHor"); Blur::HorPass.Shaders.Compute = GetShader::Compute(L"BlurHor");