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

This commit is contained in:
dean11 2014-02-20 16:54:36 +01:00
commit a1411bd9da
14 changed files with 129 additions and 30 deletions

View File

@ -2,37 +2,76 @@
#include "CollisionManager.h"
using namespace GameLogic;
using namespace Oyster::Math;
DynamicObject::DynamicObject()
:Object()
{
this->isReleased = false;
this->isActive = true;
}
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID)
:Object(rigidBody, EventOnCollision, type, objectID)
{
this->isReleased = false;
this->isActive = true;
}
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID)
:Object(rigidBody, EventOnCollision, type, objectID)
{
this->isReleased = false;
this->isActive = true;
}
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision)
:Object(rigidBody, EventOnCollision, type, objectID)
{
this->extraDamageOnCollision = extraDamageOnCollision;
this->isReleased = false;
this->isActive = true;
}
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision)
:Object(rigidBody, EventOnCollision, type, objectID)
{
this->extraDamageOnCollision = extraDamageOnCollision;
this->isReleased = false;
this->isActive = true;
}
DynamicObject::~DynamicObject(void)
{
}
void DynamicObject::ReleaseDynamicObject()
{
//TODO: Inactivate the physics object
if(this->isReleased) return;
this->isReleased = true;
this->isActive = false;
this->lookDirection = Float3::null;
this->forwardDirection = Float3::null;
this->scale = Float3::null;
this->extraDamageOnCollision = 0;
}
bool DynamicObject::IsReleased()
{
return this->isReleased;
}
bool DynamicObject::IsActive()
{
return this->isActive;
}
void DynamicObject::Inactivate()
{
this->isActive = false;
}
void DynamicObject::Activate()
{
this->isActive = true;
this->isReleased = false;
}

View File

@ -22,7 +22,15 @@ namespace GameLogic
~DynamicObject(void);
void ReleaseDynamicObject();
bool IsReleased();
bool IsActive();
void Inactivate();
void Activate();
private:
bool isActive;
bool isReleased;
};

View File

@ -67,6 +67,17 @@ void Game::GetAllPlayerPositions() const
Game::PlayerData* Game::CreatePlayer()
{
//Se if there is a free player somewhere in our list
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i] && this->players[i]->player->IsReleased())
{
//We give the body to someone else
this->players[i]->player->Activate();
return this->players[i];
}
}
// Find a free space in array or insert at end
int insert = InsertObject(this->players, (PlayerData*)0);
int freeID = 0;

View File

@ -43,8 +43,8 @@ namespace GameLogic
void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) override;
void TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) override;
ObjectSpecialType GetObjectType() const override;
void Inactivate() override;
void Release() override;
Player *player;
};

View File

@ -106,6 +106,9 @@ namespace GameLogic
* @return The current player state
********************************************************/
virtual PLAYER_STATE GetState() const = 0;
virtual void Inactivate() = 0;
virtual void Release() = 0;
};
class ILevelData :public IObjectData

View File

@ -93,4 +93,12 @@ void Game::PlayerData::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyste
void Game::PlayerData::TurnLeft(Oyster::Math3D::Float deltaLeftRadians )
{
this->player->TurnLeft(deltaLeftRadians);
}
void Game::PlayerData::Inactivate()
{
this->player->Inactivate();
}
void Game::PlayerData::Release()
{
this->player->ReleaseDynamicObject();
}

View File

@ -293,6 +293,11 @@ bool Player::IsIdle()
return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE);
}
void Player::Inactivate()
{
//this->
}
Oyster::Math::Float3 Player::GetPosition() const
{
return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos;

View File

@ -63,6 +63,8 @@ namespace GameLogic
bool IsJumping();
bool IsIdle();
void Inactivate();
Oyster::Math::Float3 GetPosition() const;
Oyster::Math::Float3 GetLookDir() const;
Oyster::Math::Float4x4 GetOrientation() const;

View File

@ -292,6 +292,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectEnabled 356
struct Protocol_ObjectPositionRotation :public Oyster::Network::CustomProtocolObject
{
short object_ID;
@ -366,7 +367,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectEnabled 356
//#define protocol_Gameplay_ObjectEnabled 357
struct Protocol_ObjectEnable :public Oyster::Network::CustomProtocolObject
{
int objectID;
@ -399,7 +400,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectDisabled 357
//#define protocol_Gameplay_ObjectDisabled 358
struct Protocol_ObjectDisable :public Oyster::Network::CustomProtocolObject
{
int objectID;
@ -439,7 +440,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectCreate 358
//#define protocol_Gameplay_ObjectCreate 359
struct Protocol_ObjectCreate :public Oyster::Network::CustomProtocolObject
{
//ObjectType type; //ie player, box or whatever
@ -543,7 +544,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectCreatePlayer 359
//#define protocol_Gameplay_ObjectCreatePlayer 360
struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject
{
/*1*/ int object_ID;
@ -673,7 +674,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectJoinTeam 360
//#define protocol_Gameplay_ObjectJoinTeam 361
struct Protocol_ObjectJoinTeam :public Oyster::Network::CustomProtocolObject
{
int objectID;
@ -713,7 +714,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectLeaveTeam 361
//#define protocol_Gameplay_ObjectLeaveTeam 362
struct Protocol_ObjectLeaveTeam :public Oyster::Network::CustomProtocolObject
{
int objectID;
@ -745,7 +746,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectWeaponCooldown 362
//#define protocol_Gameplay_ObjectWeaponCooldown 363
struct Protocol_ObjectWeaponCooldown :public Oyster::Network::CustomProtocolObject
{
float seconds;
@ -777,7 +778,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectWeaponEnergy 363
//#define protocol_Gameplay_ObjectWeaponEnergy 364
struct Protocol_ObjectWeaponEnergy :public Oyster::Network::CustomProtocolObject
{
float energy;
@ -809,7 +810,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectRespawn 364
//#define protocol_Gameplay_ObjectRespawn 365
struct Protocol_ObjectRespawn :public Oyster::Network::CustomProtocolObject
{
float position[3];
@ -852,7 +853,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectDie 365
//#define protocol_Gameplay_ObjectDie 366
struct Protocol_ObjectDie :public Oyster::Network::CustomProtocolObject
{
int objectID;

View File

@ -69,7 +69,6 @@
#define protocol_Gameplay_ObjectWeaponEnergy 364
#define protocol_Gameplay_ObjectRespawn 365
#define protocol_Gameplay_ObjectDie 366
//Disconnect
#define protocol_Gameplay_ObjectDisconnectPlayer 367
#define protocol_GameplayMAX 399

View File

@ -55,6 +55,7 @@ namespace DanBias
GameLogic::IPlayerData* ReleasePlayer();
Oyster::Network::NetClient ReleaseClient();
bool IsInvalid();
void Invalidate();
int IncrementFailedProtocol();
void ResetFailedProtocolCount();

View File

@ -25,12 +25,15 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::Net
}
GameClient::~GameClient()
{
this->client = 0;
this->player = 0;
if(this->player)
this->player->Inactivate();
this->isReady = false;
this->character = L"crate_colonists.dan";
this->alias = L"Unknown";
this->secondsSinceLastResponse = 0.0f;
this->client = 0;
this->player = 0;
}
void GameClient::SetPlayer(GameLogic::IPlayerData* player)
@ -58,8 +61,14 @@ void GameClient::SetState(ClientState state)
this->state = state;
}
bool GameClient::IsInvalid()
{
return this->isInvalid;
}
void GameClient::Invalidate()
{
this->player->Release();
this->player = 0;
this->isInvalid = true;
this->isReady = false;
this->state = ClientState_Invalid;

View File

@ -62,24 +62,30 @@ using namespace DanBias;
{
case NetworkClient::ClientEventArgs::EventType_Disconnect:
{
//Send disconnect message to all the other players so the player can be removed from the client.
Protocol_ObjectDisconnectPlayer dp(cl->GetClient()->GetID());
for(int i = 0; i < this->gClients.Size(); i++)
{
if(this->gClients[i] && this->gClients[i] != cl)
{
this->gClients[i]->GetClient()->Send(dp);
}
}
printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str());
Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID());
for (unsigned int i = 0; i < this->gClients.Size(); i++)
{
if(i != temp && this->gClients[i]) this->gClients[i]->GetClient()->Send(prot);
}
this->gClients[temp]->Invalidate();
}
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve:
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
{
if(this->gClients[temp]->IncrementFailedProtocol() >= 5/*client->threshold*/)
{
Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID());
for (unsigned int i = 0; i < this->gClients.Size(); i++)
{
if(i != temp && this->gClients[i]) this->gClients[i]->GetClient()->Send(prot);
}
this->gClients[temp]->Invalidate();
}
}
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
this->ParseProtocol(e.args.data.protocol, cl);
@ -267,10 +273,17 @@ using namespace DanBias;
switch (p.status)
{
case GameLogic::Protocol_General_Status::States_disconected:
{
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
//TODO: Tell other clients
//Protocol_
Protocol_ObjectDisconnectPlayer prot(c->GetPlayer()->GetID());
for (unsigned int i = 0; i < this->gClients.Size(); i++)
{
if( this->gClients[i] && c->GetClient()->GetID() != this->gClients[i]->GetClient()->GetID() ) this->gClients[i]->GetClient()->Send(prot);
}
c->Invalidate();
this->Detach(c->GetClient()->GetID());
}
break;
case GameLogic::Protocol_General_Status::States_idle:

View File

@ -214,7 +214,7 @@ bool GameSession::Join(gClient gameClient)
{
for (unsigned int i = 0; i < this->gClients.Size(); i++)
{
if(this->gClients[i])
if(this->gClients[i] && !this->gClients[i]->IsInvalid())
{
IPlayerData* temp = this->gClients[i]->GetPlayer();
Protocol_ObjectCreatePlayer p1( temp->GetPosition(), temp->GetRotation(), temp->GetScale(),