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

This commit is contained in:
Pontus Fransson 2014-02-26 10:24:42 +01:00
commit dbbc7a9769
14 changed files with 152 additions and 28 deletions

View File

@ -762,6 +762,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
case GameLogic::PlayerAction::PlayerAction_Idle:
player->playAnimation(L"idle", true);
break;
case GameLogic::WeaponAction::WeaponAction_PrimaryShoot:
break;
case GameLogic::WeaponAction::WeaponAction_SecondaryShoot:
break;
case GameLogic::WeaponAction::WeaponAction_Reload:
break;
default:
break;
}
@ -769,6 +778,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
}
}
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;
}
}

View File

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

View File

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

View File

@ -182,12 +182,16 @@ void Game::SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer)
}
void Game::SetActionSubscription(GameEvent::AnimationEventFunction functionPointer)
{
this->onPlayerActionEventFnc = functionPointer;
this->onActionEventFnc = functionPointer;
}
void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer)
{
this->onPickupEventFnc = functionPointer;
}
void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer)
{
this->onCollisionEventFnc = functionPointer;
}
bool Game::Initiate()
{
API::Instance().Init();

View File

@ -87,6 +87,7 @@ namespace GameLogic
void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override;
void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override;
void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override;
void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override;
bool Initiate() override;
float GetFrameTime() const;
@ -106,8 +107,9 @@ namespace GameLogic
GameEvent::ObjectHpFunction onDamageTakenFnc;
GameEvent::ObjectRespawnedFunction onRespawnFnc;
GameEvent::ObjectDeadFunction onDeadFnc;
GameEvent::AnimationEventFunction onPlayerActionEventFnc;
GameEvent::AnimationEventFunction onActionEventFnc;
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(*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(*CollisionEventFunction)(IObjectData*object, int collisionID);
//etc...
};
@ -188,7 +189,7 @@ namespace GameLogic
virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0;
virtual void SetActionSubscription(GameEvent::AnimationEventFunction 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)
{
srand (time(NULL));
objID = 100;
}
Level::~Level(void)
@ -409,6 +410,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID)
}
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);
}
void Level::RemovePlayerFromGame(Player *player)
@ -417,7 +427,7 @@ void Level::RemovePlayerFromGame(Player *player)
{
if ((Player*)this->playerObjects[i] == player)
{
//this->playerObjects[i].
this->playerObjects[i] = nullptr;
}
}
}
@ -430,7 +440,8 @@ void Level::RespawnPlayer(Player *player)
{
//this->teamManager.RespawnPlayerRandom(player);
Float3 spawnPoint = spawnPoints[0];
int i = rand() % spawnPoints.Size();
Float3 spawnPoint = spawnPoints[i];
player->Respawn(spawnPoint);
}
void Level::Update(float deltaTime)
@ -438,19 +449,22 @@ void Level::Update(float deltaTime)
// update lvl-things
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]->deathTimerTick(deltaTime))
RespawnPlayer(this->playerObjects[i]);
}
else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED)
{
this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
// 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]->getAffectingPlayer(), DEATH_TIMER); // add killer ID
if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
{
// true when timer reaches 0
if(this->playerObjects[i]->deathTimerTick(deltaTime))
RespawnPlayer(this->playerObjects[i]);
}
else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED)
{
this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
// 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]->getAffectingPlayer(), DEATH_TIMER); // add killer ID
}
}
}

View File

@ -142,7 +142,7 @@ void Player::BeginFrame()
if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING)
{
if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE)
this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle);
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle);
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
}
}
@ -178,7 +178,7 @@ void Player::BeginFrame()
if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING)
{
if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING)
this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Walk);
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Walk);
this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
}
}
@ -200,7 +200,7 @@ void Player::BeginFrame()
this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20);
if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING)
this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Jump);
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Jump);
this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING;
}
}
@ -208,7 +208,7 @@ void Player::BeginFrame()
{
if(this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING)
{
this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle);
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle);
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
}
}

View File

@ -969,7 +969,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
}
//#define protocol_Gameplay_ObjectAction 369
//#define protocol_Gameplay_ObjectAction 369
struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject
{
short objectID;
@ -1010,4 +1010,46 @@ namespace GameLogic
private:
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

View File

@ -72,6 +72,7 @@
#define protocol_Gameplay_ObjectDie 367
#define protocol_Gameplay_ObjectDisconnectPlayer 368
#define protocol_Gameplay_ObjectAction 369
#define protocol_Gameplay_ObjectCollision 370
#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 PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID );
static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID );
static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID );
//Private member variables
private:
Utility::DynamicMemory::DynamicArray<gClient> gClients;

View File

@ -176,6 +176,11 @@ using namespace DanBias;
// send action protocol
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 *****************//
//******************************************************************************************************************//

View File

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

View File

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