Sending energy update to client.

This commit is contained in:
Linda Andersson 2014-02-27 14:56:18 +01:00
parent 97ea35e91e
commit b4409d2147
10 changed files with 47 additions and 8 deletions

View File

@ -707,7 +707,16 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponEnergy:
{
Protocol_ObjectWeaponEnergy decoded(data);
if( this->privData->myId == decoded.objectID )
{
// show my energy
float energy = decoded.energy;
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectRespawn:
{
Protocol_ObjectRespawn decoded(data);

View File

@ -13,6 +13,7 @@ AttatchmentMassDriver::AttatchmentMassDriver(void)
this->hasObject = false;
this->currentEnergy = StandardMaxEnergy;
this->maxEnergy = StandardMaxEnergy;
this->energyChange = 0;
this->rechargeRate = StandardrechargeRate;
this->force = Standardforce;
}
@ -22,6 +23,7 @@ AttatchmentMassDriver::AttatchmentMassDriver(Player &owner)
this->currentEnergy = StandardMaxEnergy;
this->maxEnergy = StandardMaxEnergy;
this->rechargeRate = StandardrechargeRate;
this->energyChange = 0;
this->force = Standardforce;
this->owner = &owner;
@ -120,6 +122,7 @@ void AttatchmentMassDriver::Update(float dt)
if(currentEnergy < maxEnergy)
{
currentEnergy += rechargeRate * 0.5f; //rechargeRate is halfed if you are holding an object
energyChange += rechargeRate * 0.5f;
}
}
@ -128,12 +131,17 @@ void AttatchmentMassDriver::Update(float dt)
if(currentEnergy < maxEnergy)
{
currentEnergy += rechargeRate;
energyChange += rechargeRate * 0.5f;
}
}
if(currentEnergy > maxEnergy) currentEnergy = maxEnergy;
if(energyChange > 10)
{
((Game*)&Game::Instance())->onEnergyUpdateFnc( this->owner, currentEnergy);
energyChange = 0;
}
}
/********************************************************

View File

@ -63,7 +63,7 @@ namespace GameLogic
Oyster::Math::Float maxEnergy;
Oyster::Math::Float currentEnergy;
Oyster::Math::Float energyChange; // variable used to limit energy update messages
Oyster::Math::Float rechargeRate;
struct Aim

View File

@ -192,6 +192,10 @@ void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPo
{
this->onCollisionEventFnc = functionPointer;
}
void Game::SetWeaponEnergySubscription(GameEvent::WeaponEnergyFunction functionPointer)
{
this->onEnergyUpdateFnc = functionPointer;
}
bool Game::Initiate()
{
API::Instance().Init();

View File

@ -90,6 +90,7 @@ namespace GameLogic
void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override;
void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override;
void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override;
void SetWeaponEnergySubscription(GameEvent::WeaponEnergyFunction functionPointer) override;
bool Initiate() override;
float GetFrameTime() const;
@ -112,6 +113,7 @@ namespace GameLogic
GameEvent::AnimationEventFunction onActionEventFnc;
GameEvent::PickupEventFunction onPickupEventFnc;
GameEvent::CollisionEventFunction onCollisionEventFnc;
GameEvent::WeaponEnergyFunction onEnergyUpdateFnc;
};
}

View File

@ -34,6 +34,7 @@ namespace GameLogic
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);
typedef void(*WeaponEnergyFunction)(IObjectData*object, float energy);
//etc...
};
@ -192,6 +193,7 @@ namespace GameLogic
virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0;
virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0;
virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0;
virtual void SetWeaponEnergySubscription(GameEvent::WeaponEnergyFunction functionPointer) = 0;
};
}

View File

@ -810,28 +810,35 @@ namespace GameLogic
//#define protocol_Gameplay_ObjectWeaponEnergy 365
struct Protocol_ObjectWeaponEnergy :public Oyster::Network::CustomProtocolObject
{
int objectID;
float energy;
Protocol_ObjectWeaponEnergy()
{
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[0].value.netShort = protocol_Gameplay_ObjectWeaponEnergy;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
this->objectID = -1;
this->energy = 0.0f;
}
Protocol_ObjectWeaponEnergy(float energy)
Protocol_ObjectWeaponEnergy(int objectID, float energy)
{
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[0].value.netShort = protocol_Gameplay_ObjectWeaponEnergy;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
this->objectID = objectID;
this->energy = energy;
}
Protocol_ObjectWeaponEnergy(Oyster::Network::CustomNetProtocol& p)
{
this->energy = p[1].value.netFloat;
this->objectID = p[1].value.netInt;
this->energy = p[2].value.netFloat;
}
Oyster::Network::CustomNetProtocol GetProtocol() override
{
this->protocol[1].value = this->energy;
this->protocol[1].value = this->objectID;
this->protocol[2].value = this->energy;
return protocol;
}

View File

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

View File

@ -185,6 +185,11 @@ using namespace DanBias;
// send action protocol
GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol());
}
void GameSession::EnergyUpdate( GameLogic::IObjectData* movedObject , float energy )
{
// send action protocol
GameSession::gameSession->Send(Protocol_ObjectWeaponEnergy(movedObject->GetID(), energy).GetProtocol());
}
//*****************************************************//
//****************** Protocol methods *****************//
//******************************************************************************************************************//

View File

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