Added collision and weapon events and send them to client

This commit is contained in:
Linda Andersson 2014-02-26 10:05:07 +01:00
parent 8438b7dfbb
commit 13d6a062fc
13 changed files with 143 additions and 24 deletions

View File

@ -750,6 +750,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
case GameLogic::PlayerAction::PlayerAction_Idle: case GameLogic::PlayerAction::PlayerAction_Idle:
player->playAnimation(L"idle", true); player->playAnimation(L"idle", true);
break; break;
case GameLogic::WeaponAction::WeaponAction_PrimaryShoot:
break;
case GameLogic::WeaponAction::WeaponAction_SecondaryShoot:
break;
case GameLogic::WeaponAction::WeaponAction_Reload:
break;
default: default:
break; break;
} }
@ -757,6 +766,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
} }
} }
return GameClientState::event_processed; return GameClientState::event_processed;
case protocol_Gameplay_ObjectCollision:
{
Protocol_ObjectCollision decoded(data);
C_Object *object;
object = (this->privData->players)[decoded.objectID];
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
}
if( object )
{
switch (decoded.collisionID)
{
case GameLogic::CollisionEvent::CollisionEvent_BasicCollision:
break;
default:
break;
}
}
}
return GameClientState::event_processed;
default: break; default: break;
} }
} }

View File

@ -1,7 +1,7 @@
#include "AttatchmentMassDriver.h" #include "AttatchmentMassDriver.h"
#include "PhysicsAPI.h" #include "PhysicsAPI.h"
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "Game.h"
using namespace GameLogic; using namespace GameLogic;
@ -48,6 +48,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
{ {
currentEnergy -= 90.0f; currentEnergy -= 90.0f;
ForcePush(usage,dt); ForcePush(usage,dt);
// add CD
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot);
} }
break; break;
@ -56,6 +58,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
{ {
currentEnergy -= 1.0f; currentEnergy -= 1.0f;
ForcePull(usage,dt); ForcePull(usage,dt);
// add CD
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot);
} }
break; break;
@ -64,6 +68,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
{ {
currentEnergy -= 90.0f; currentEnergy -= 90.0f;
ForceZip(usage,dt); ForceZip(usage,dt);
// add CD
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate);
} }
break; break;
} }

View File

@ -69,7 +69,8 @@ using namespace GameLogic;
//player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
break; break;
} }
// send collision event message
((Game*)&Game::Instance())->onCollisionEventFnc(player, CollisionEvent::CollisionEvent_BasicCollision);
//return Physics::ICustomBody::SubscriptMessage_none; //return Physics::ICustomBody::SubscriptMessage_none;
} }

View File

@ -188,6 +188,10 @@ void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer)
{ {
this->onPickupEventFnc = functionPointer; this->onPickupEventFnc = functionPointer;
} }
void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer)
{
this->onCollisionEventFnc = functionPointer;
}
bool Game::Initiate() bool Game::Initiate()
{ {
API::Instance().Init(); API::Instance().Init();

View File

@ -87,6 +87,7 @@ namespace GameLogic
void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override;
void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override;
void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override;
void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override;
bool Initiate() override; bool Initiate() override;
float GetFrameTime() const; float GetFrameTime() const;
@ -108,6 +109,7 @@ namespace GameLogic
GameEvent::ObjectDeadFunction onDeadFnc; GameEvent::ObjectDeadFunction onDeadFnc;
GameEvent::AnimationEventFunction onActionEventFnc; GameEvent::AnimationEventFunction onActionEventFnc;
GameEvent::PickupEventFunction onPickupEventFnc; GameEvent::PickupEventFunction onPickupEventFnc;
GameEvent::CollisionEventFunction onCollisionEventFnc;
}; };
} }

View File

@ -33,6 +33,7 @@ namespace GameLogic
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(*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 typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer
typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID);
//etc... //etc...
}; };
@ -188,7 +189,7 @@ namespace GameLogic
virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0;
virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0;
virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0;
virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0;
}; };
} }

View File

@ -16,6 +16,7 @@ using namespace Oyster::Math;
Level::Level(void) Level::Level(void)
{ {
srand (time(NULL));
objID = 100; objID = 100;
} }
Level::~Level(void) Level::~Level(void)
@ -405,6 +406,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID)
} }
void Level::AddPlayerToGame(Player *player) void Level::AddPlayerToGame(Player *player)
{ {
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
{
if (!this->playerObjects[i])
{
this->playerObjects[i] = player;
return;
}
}
// if no free space, allocate a new spot
this->playerObjects.Push(player); this->playerObjects.Push(player);
} }
void Level::RemovePlayerFromGame(Player *player) void Level::RemovePlayerFromGame(Player *player)
@ -413,7 +423,7 @@ void Level::RemovePlayerFromGame(Player *player)
{ {
if ((Player*)this->playerObjects[i] == player) if ((Player*)this->playerObjects[i] == player)
{ {
//this->playerObjects[i]. this->playerObjects[i] = nullptr;
} }
} }
} }
@ -426,7 +436,8 @@ void Level::RespawnPlayer(Player *player)
{ {
//this->teamManager.RespawnPlayerRandom(player); //this->teamManager.RespawnPlayerRandom(player);
Float3 spawnPoint = spawnPoints[0]; int i = rand() % spawnPoints.Size();
Float3 spawnPoint = spawnPoints[i];
player->Respawn(spawnPoint); player->Respawn(spawnPoint);
} }
void Level::Update(float deltaTime) void Level::Update(float deltaTime)
@ -434,19 +445,22 @@ void Level::Update(float deltaTime)
// update lvl-things // update lvl-things
for(int i = 0; i < (int)this->playerObjects.Size(); i++) for(int i = 0; i < (int)this->playerObjects.Size(); i++)
{ {
if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) if(this->playerObjects[i])
{ {
// true when timer reaches 0 if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
if(this->playerObjects[i]->deathTimerTick(deltaTime)) {
RespawnPlayer(this->playerObjects[i]); // true when timer reaches 0
} if(this->playerObjects[i]->deathTimerTick(deltaTime))
else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) RespawnPlayer(this->playerObjects[i]);
{ }
this->playerObjects[i]->setDeathTimer(DEATH_TIMER); else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED)
// HACK to avoid crasch. affected by tag is NULL {
Player* killer = this->playerObjects[i]->getAffectingPlayer(); this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID // HACK to avoid crasch. affected by tag is NULL
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID 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]->getAffectingPlayer(), DEATH_TIMER); // add killer ID
}
} }
} }

View File

@ -969,7 +969,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
} }
//#define protocol_Gameplay_ObjectAction 369 //#define protocol_Gameplay_ObjectAction 369
struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject
{ {
short objectID; short objectID;
@ -1010,4 +1010,46 @@ namespace GameLogic
private: private:
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
//#define protocol_Gameplay_ObjectCollision 370
struct Protocol_ObjectCollision :public Oyster::Network::CustomProtocolObject
{
short objectID;
int collisionID;
// TODO: maybe position, impact, and velocity
Protocol_ObjectCollision()
{
this->protocol[0].value = protocol_Gameplay_ObjectCollision;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
this->objectID = -1;
this->collisionID = -1;
}
Protocol_ObjectCollision(Oyster::Network::CustomNetProtocol& p)
{
this->objectID = p[1].value.netShort;
this->collisionID = p[2].value.netInt;
}
Protocol_ObjectCollision( int id, int collisionID)
{
this->protocol[0].value = protocol_Gameplay_ObjectCollision;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
this->objectID = id;
this->collisionID = collisionID;
}
Oyster::Network::CustomNetProtocol GetProtocol() override
{
this->protocol[1].value = objectID;
this->protocol[2].value = collisionID;
return protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H

View File

@ -72,6 +72,7 @@
#define protocol_Gameplay_ObjectDie 367 #define protocol_Gameplay_ObjectDie 367
#define protocol_Gameplay_ObjectDisconnectPlayer 368 #define protocol_Gameplay_ObjectDisconnectPlayer 368
#define protocol_Gameplay_ObjectAction 369 #define protocol_Gameplay_ObjectAction 369
#define protocol_Gameplay_ObjectCollision 370
#define protocol_GameplayMAX 399 #define protocol_GameplayMAX 399

View File

@ -105,6 +105,7 @@ namespace DanBias
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 PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID );
static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID );
static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID );
//Private member variables //Private member variables
private: private:
Utility::DynamicMemory::DynamicArray<gClient> gClients; Utility::DynamicMemory::DynamicArray<gClient> gClients;

View File

@ -176,6 +176,11 @@ using namespace DanBias;
// send action protocol // send action protocol
GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol());
} }
void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID )
{
// send action protocol
GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol());
}
//*****************************************************// //*****************************************************//
//****************** Protocol methods *****************// //****************** Protocol methods *****************//
//******************************************************************************************************************// //******************************************************************************************************************//

View File

@ -114,6 +114,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart)
this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); this->gameInstance.SetDeadSubscription(GameSession::ObjectDead);
this->gameInstance.SetActionSubscription(GameSession::ActionEvent); this->gameInstance.SetActionSubscription(GameSession::ActionEvent);
this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); this->gameInstance.SetPickupSubscription(GameSession::PickupEvent);
this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent);
this->gameInstance.SetFPS(60); this->gameInstance.SetFPS(60);
this->description.clients.Clear(); this->description.clients.Clear();

View File

@ -95,16 +95,26 @@ namespace GameLogic
enum PlayerAction enum PlayerAction
{ {
PlayerAction_Jump, PlayerAction_Jump = 0,
PlayerAction_Walk, PlayerAction_Walk = 1,
PlayerAction_Idle, PlayerAction_Idle = 2,
}; };
// continue ID counting from playerAction
enum WeaponAction enum WeaponAction
{ {
WeaponAtcion_PrimaryShoot, WeaponAction_PrimaryShoot = 3,
WeaponAction_SecondaryShoot WeaponAction_SecondaryShoot = 4,
WeaponAction_UtilityActivate = 5,
WeaponAction_Reload = 6,
WeaponAction_EnergyDepleted = 7,
}; };
// TODO: add more collision Events
enum CollisionEvent
{
CollisionEvent_BasicCollision,
};
enum PickupType enum PickupType
{ {
PickupType_Health, PickupType_Health,