Added eventfunctions for PlayerAction and PickupEvent

This commit is contained in:
Linda Andersson 2014-02-25 14:35:27 +01:00
parent f56323ee01
commit b8395e9af7
8 changed files with 77 additions and 23 deletions

View File

@ -156,14 +156,18 @@ void Game::SetFrameTimeLength( float seconds )
this->frameTime = seconds; this->frameTime = seconds;
} }
void Game::SetSubscription(GameEvent::ObjectMovedFunction functionPointer) void Game::SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer)
{ {
this->onMoveFnc = functionPointer; this->onMoveFnc = functionPointer;
} }
void Game::SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) void Game::SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer)
{ {
this->onDisableFnc = functionPointer; this->onDisableFnc = functionPointer;
} }
void Game::SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer)
{
this->onEnableFnc = functionPointer;
}
void Game::SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) void Game::SetHpSubscription(GameEvent::ObjectHpFunction functionPointer)
{ {
this->onDamageTakenFnc = functionPointer; this->onDamageTakenFnc = functionPointer;
@ -176,7 +180,14 @@ void Game::SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer)
{ {
this->onDeadFnc = functionPointer; this->onDeadFnc = functionPointer;
} }
void Game::SetActionSubscription(GameEvent::AnimationEventFunction functionPointer)
{
this->onPlayerActionEventFnc = functionPointer;
}
void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer)
{
this->onPickupEventFnc = functionPointer;
}
bool Game::Initiate() bool Game::Initiate()
{ {
API::Instance().Init(); API::Instance().Init();
@ -204,5 +215,5 @@ void Game::PhysicsOnMove(const ICustomBody *object)
} }
void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer<ICustomBody> proto) void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer<ICustomBody> proto)
{ {
if(gameInstance.onDisableFnc) gameInstance.onDisableFnc(0, 0); if(gameInstance.onDisableFnc) gameInstance.onDisableFnc(0);
} }

View File

@ -79,11 +79,14 @@ namespace GameLogic
bool NewFrame() override; bool NewFrame() override;
void SetFPS( int FPS ) override; void SetFPS( int FPS ) override;
void SetFrameTimeLength( float seconds ) override; void SetFrameTimeLength( float seconds ) override;
void SetSubscription(GameEvent::ObjectMovedFunction functionPointer) override; void SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer) override;
void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) override; void SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer) override;
void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) override; void SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer) override;
void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) override; void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) override;
void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) override;
void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override;
void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override;
void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override;
bool Initiate() override; bool Initiate() override;
float GetFrameTime() const; float GetFrameTime() const;
@ -96,11 +99,15 @@ namespace GameLogic
LevelData* level; LevelData* level;
float frameTime; float frameTime;
bool initiated; bool initiated;
GameEvent::ObjectDisabledFunction onDisableFnc;
GameEvent::ObjectMovedFunction onMoveFnc; GameEvent::ObjectMovedFunction onMoveFnc;
GameEvent::ObjectDisabledFunction onDisableFnc;
GameEvent::ObjectEnabledFunction onEnableFnc;
GameEvent::ObjectHpFunction onDamageTakenFnc; GameEvent::ObjectHpFunction onDamageTakenFnc;
GameEvent::ObjectRespawnedFunction onRespawnFnc; GameEvent::ObjectRespawnedFunction onRespawnFnc;
GameEvent::ObjectDeadFunction onDeadFnc; GameEvent::ObjectDeadFunction onDeadFnc;
GameEvent::AnimationEventFunction onPlayerActionEventFnc;
GameEvent::PickupEventFunction onPickupEventFnc;
}; };
} }

View File

@ -26,10 +26,13 @@ namespace GameLogic
namespace GameEvent namespace GameEvent
{ {
typedef void(*ObjectMovedFunction)(IObjectData* object); // Callback method that recieves and object typedef void(*ObjectMovedFunction)(IObjectData* object); // Callback method that recieves and object
typedef void(*ObjectDisabledFunction)(IObjectData* object, float seconds); // Callback method that recieves and object typedef void(*ObjectDisabledFunction)(IObjectData* object); // Callback method that recieves and object
typedef void(*ObjectEnabledFunction)(IObjectData* object); // Callback method that recieves and object
typedef void(*ObjectHpFunction)(IObjectData* object, float hp); // Callback method that sends obj HP typedef void(*ObjectHpFunction)(IObjectData* object, float hp); // Callback method that sends obj HP
typedef void(*ObjectRespawnedFunction)(IObjectData* object, Oyster::Math::Float3 spawnPos ); // Callback method that sends spawnPos typedef void(*ObjectRespawnedFunction)(IObjectData* object, Oyster::Math::Float3 spawnPos ); // Callback method that sends spawnPos
typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer
typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer
typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer
//etc... //etc...
}; };
@ -177,15 +180,14 @@ namespace GameLogic
/** Set a specific object event subscription callback /** Set a specific object event subscription callback
* @param * @param
*/ */
virtual void SetSubscription(GameEvent::ObjectMovedFunction functionPointer) = 0; virtual void SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer) = 0;
virtual void SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer) = 0;
/** Set a specific object event subscription callback virtual void SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer) = 0;
* @param
*/
virtual void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) = 0;
virtual void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) = 0; virtual void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) = 0;
virtual void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) = 0; virtual void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) = 0;
virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0;
virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0;
virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0;
}; };
} }

View File

@ -434,10 +434,13 @@ void Level::Update(float deltaTime)
{ {
this->playerObjects[i]->setDeathTimer(DEATH_TIMER); this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
// HACK to avoid crasch. affected by tag is NULL // HACK to avoid crasch. affected by tag is NULL
Player* killer = this->playerObjects[i]->getAffectingPlayer();
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID
} }
} }
} }
int Level::getNrOfDynamicObj() int Level::getNrOfDynamicObj()
{ {

View File

@ -98,11 +98,13 @@ namespace DanBias
//Callback method receiving from game logic //Callback method receiving from game logic
static void ObjectMove ( GameLogic::IObjectData* movedObject ); static void ObjectMove ( GameLogic::IObjectData* movedObject );
static void ObjectDisabled ( GameLogic::IObjectData* movedObject, float seconds ); static void ObjectDisabled ( GameLogic::IObjectData* movedObject );
static void ObjectEnabled ( GameLogic::IObjectData* movedObject );
static void ObjectDamaged ( GameLogic::IObjectData* movedObject, float hp ); static void ObjectDamaged ( GameLogic::IObjectData* movedObject, float hp );
static void ObjectRespawned ( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos ); static void ObjectRespawned ( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos );
static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ); static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds );
static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID );
static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID );
//Private member variables //Private member variables
private: private:
Utility::DynamicMemory::DynamicArray<gClient> gClients; Utility::DynamicMemory::DynamicArray<gClient> gClients;

View File

@ -146,9 +146,13 @@ using namespace DanBias;
GameSession::gameSession->Send(p.GetProtocol()); GameSession::gameSession->Send(p.GetProtocol());
//} //}
} }
void GameSession::ObjectDisabled( GameLogic::IObjectData* movedObject, float seconds ) void GameSession::ObjectDisabled( GameLogic::IObjectData* movedObject )
{ {
GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID(), seconds).GetProtocol()); //GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol());
}
void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject )
{
//GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol());
} }
void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp )
{ {
@ -162,6 +166,16 @@ using namespace DanBias;
{ {
GameSession::gameSession->Send(Protocol_ObjectDie(victim->GetID(), killer->GetID(), seconds).GetProtocol()); GameSession::gameSession->Send(Protocol_ObjectDie(victim->GetID(), killer->GetID(), seconds).GetProtocol());
} }
void GameSession::PickupEvent( GameLogic::IObjectData* movedObject, int pickupEffectID )
{
// send pickup protocol
GameSession::gameSession->Send(Protocol_ObjectPickup(movedObject->GetID(), pickupEffectID).GetProtocol());
}
void GameSession::ActionEvent( GameLogic::IObjectData* movedObject , int actionID )
{
// send action protocol
GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol());
}
//*****************************************************// //*****************************************************//
//****************** Protocol methods *****************// //****************** Protocol methods *****************//
//******************************************************************************************************************// //******************************************************************************************************************//

View File

@ -106,11 +106,14 @@ bool GameSession::Create(GameDescription& desc, bool forceStart)
} }
/* Set some game instance data options */ /* Set some game instance data options */
this->gameInstance.SetSubscription(GameSession::ObjectMove); this->gameInstance.SetMoveSubscription(GameSession::ObjectMove);
this->gameInstance.SetSubscription(GameSession::ObjectDisabled); this->gameInstance.SetDisableSubscription(GameSession::ObjectDisabled);
this->gameInstance.SetEnableSubscription(GameSession::ObjectEnabled);
this->gameInstance.SetHpSubscription(GameSession::ObjectDamaged); this->gameInstance.SetHpSubscription(GameSession::ObjectDamaged);
this->gameInstance.SetRespawnSubscription(GameSession::ObjectRespawned); this->gameInstance.SetRespawnSubscription(GameSession::ObjectRespawned);
this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); this->gameInstance.SetDeadSubscription(GameSession::ObjectDead);
this->gameInstance.SetActionSubscription(GameSession::ActionEvent);
this->gameInstance.SetPickupSubscription(GameSession::PickupEvent);
this->gameInstance.SetFPS(60); this->gameInstance.SetFPS(60);
this->description.clients.Clear(); this->description.clients.Clear();

View File

@ -92,6 +92,18 @@ namespace GameLogic
WorldSize_Unknown = -1 WorldSize_Unknown = -1
}; };
enum PlayerAction
{
PlayerAction_Jump,
PlayerAction_Walk,
PlayerAction_Idle,
};
enum PickupType
{
PickupType_Health,
PickupType_SpeedBoost
};
/************************************ /************************************
Structs Structs