This commit is contained in:
dean11 2014-02-17 16:17:07 +01:00 committed by Robin Engman
parent b4b5998a64
commit 5137404bb6
5 changed files with 199 additions and 158 deletions

View File

@ -546,14 +546,14 @@ namespace GameLogic
//#define protocol_Gameplay_ObjectCreatePlayer 359
struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject
{
//ObjectType type; //ie player, box or whatever
int object_ID;
int teamId;
std::string name;
std::string meshName;
float position[3];
float rotationQ[4];
float scale[3];
/*1*/ int object_ID;
/*2*/ int teamId;
/*3*/ bool owner;
/*4*/ std::string name;
/*5*/ std::string meshName;
/*6 - 8*/ float position[3];
/*9 - 11*/ float rotationQ[4];
/*12 - 14*/ float scale[3];
Protocol_ObjectCreatePlayer()
{
@ -564,44 +564,47 @@ namespace GameLogic
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
//TEAM_ID
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
//OWNER
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
//PLAYER-NAME
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
//MESH-NAME
this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray;
//MESH-NAME
this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray;
//POSITION
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
this->protocol[7].type = Oyster::Network::NetAttributeType_Float;
//ROTATION
this->protocol[8].type = Oyster::Network::NetAttributeType_Float;
//ROTATION
this->protocol[9].type = Oyster::Network::NetAttributeType_Float;
this->protocol[10].type = Oyster::Network::NetAttributeType_Float;
//SCALE
this->protocol[11].type = Oyster::Network::NetAttributeType_Float;
//SCALE
this->protocol[12].type = Oyster::Network::NetAttributeType_Float;
this->protocol[13].type = Oyster::Network::NetAttributeType_Float;
this->protocol[14].type = Oyster::Network::NetAttributeType_Float;
}
Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p)
{
this->object_ID = p[1].value.netInt;
this->teamId = this->protocol[2].value.netInt;
this->name.assign(p[3].value.netCharPtr);
this->meshName.assign(p[4].value.netCharPtr);
this->owner = this->protocol[3].value.netBool;
this->name.assign(p[4].value.netCharPtr);
this->meshName.assign(p[5].value.netCharPtr);
this->position[0] = p[5].value.netFloat;
this->position[1] = p[6].value.netFloat;
this->position[2] = p[7].value.netFloat;
this->position[0] = p[6].value.netFloat;
this->position[1] = p[7].value.netFloat;
this->position[2] = p[8].value.netFloat;
this->rotationQ[0] = p[8].value.netFloat;
this->rotationQ[1] = p[9].value.netFloat;
this->rotationQ[2] = p[10].value.netFloat;
this->rotationQ[3] = p[11].value.netFloat;
this->rotationQ[0] = p[9].value.netFloat;
this->rotationQ[1] = p[10].value.netFloat;
this->rotationQ[2] = p[11].value.netFloat;
this->rotationQ[3] = p[12].value.netFloat;
this->scale[0] = p[12].value.netFloat;
this->scale[1] = p[13].value.netFloat;
this->scale[2] = p[14].value.netFloat;
this->scale[0] = p[13].value.netFloat;
this->scale[1] = p[14].value.netFloat;
this->scale[2] = p[15].value.netFloat;
}
Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, int teamID, std::string name, std::string meshName)
Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, bool owner, int teamID, std::string name, std::string meshName)
{
this->protocol[0].value = protocol_Gameplay_ObjectCreatePlayer;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
@ -610,26 +613,29 @@ namespace GameLogic
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
//TEAM_ID
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
//OWNER
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
//PLAYER-NAME
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
//MESH-NAME
this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray;
//MESH-NAME
this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray;
//POSITION
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
this->protocol[7].type = Oyster::Network::NetAttributeType_Float;
//ROTATION
this->protocol[8].type = Oyster::Network::NetAttributeType_Float;
//ROTATION
this->protocol[9].type = Oyster::Network::NetAttributeType_Float;
this->protocol[10].type = Oyster::Network::NetAttributeType_Float;
this->protocol[11].type = Oyster::Network::NetAttributeType_Float;
//SCALE
this->protocol[12].type = Oyster::Network::NetAttributeType_Float;
//SCALE
this->protocol[13].type = Oyster::Network::NetAttributeType_Float;
this->protocol[14].type = Oyster::Network::NetAttributeType_Float;
this->protocol[15].type = Oyster::Network::NetAttributeType_Float;
this->object_ID = ObjectID;
this->teamId = teamID;
this->owner = owner;
this->name = name;
this->meshName = meshName;
memcpy(&this->position[0], &position[0], sizeof(float)*3);
@ -641,22 +647,23 @@ namespace GameLogic
this->protocol[1].value = this->object_ID;
this->protocol[2].value = this->teamId;
this->protocol.Set(3, this->name);
this->protocol.Set(4, this->meshName);
this->protocol[3].value = this->owner;
this->protocol.Set(4, this->name);
this->protocol.Set(5, this->meshName);
//POSITION
this->protocol[5].value = this->position[0];
this->protocol[6].value = this->position[1];
this->protocol[7].value = this->position[2];
this->protocol[6].value = this->position[0];
this->protocol[7].value = this->position[1];
this->protocol[8].value = this->position[2];
//ROTATION
this->protocol[8].value = this->rotationQ[0];
this->protocol[9].value = this->rotationQ[1];
this->protocol[10].value = this->rotationQ[2];
this->protocol[11].value = this->rotationQ[3];
this->protocol[9].value = this->rotationQ[0];
this->protocol[10].value = this->rotationQ[1];
this->protocol[11].value = this->rotationQ[2];
this->protocol[12].value = this->rotationQ[3];
//SCALE
this->protocol[12].value = this->scale[0];
this->protocol[13].value = this->scale[1];
this->protocol[14].value = this->scale[2];
this->protocol[13].value = this->scale[0];
this->protocol[14].value = this->scale[1];
this->protocol[15].value = this->scale[2];
return protocol;
}

View File

@ -46,6 +46,7 @@ namespace DanBias
void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState:
void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType:
private:
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;

View File

@ -11,40 +11,46 @@ using namespace Oyster::Network;
using namespace Oyster;
using namespace GameLogic;
namespace DanBias
using namespace DanBias;
GameLobby::GameLobby()
{ }
GameLobby::~GameLobby()
{
GameLobby::GameLobby()
{ }
GameLobby::~GameLobby()
{
this->clients.Clear();
}
void GameLobby::Release()
{
}
void GameLobby::Release()
{
NetworkSession::CloseSession(true);
this->gameSession.CloseSession(true);
}
void GameLobby::Update()
}
void GameLobby::Update()
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->ProcessClients();
}
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
if(this->clients[i])
{
this->clients[i]->Update();
}
}
}
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
{
this->description.gameMode = desc.gameMode;
this->description.gameTime = desc.gameTime;
this->description.mapNumber = desc.mapNumber;
this->description.maxClients = desc.maxClients;
}
void GameLobby::GetGameDesc(LobbyLevelData& desc)
{
}
void GameLobby::GetGameDesc(LobbyLevelData& desc)
{
desc.gameMode = this->description.gameMode;
desc.gameTime = this->description.gameTime;
desc.mapNumber = this->description.mapNumber;
desc.maxClients = this->description.maxClients;
}
bool GameLobby::StartGameSession( )
{
//Check if all clients is ready
}
bool GameLobby::StartGameSession( )
{
//Check if all clients is ready
if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size())
{
GameSession::GameDescription desc;
@ -75,10 +81,10 @@ namespace DanBias
//?
}
return false;
}
}
void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
{
void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
{
switch (e.args.type)
{
case NetworkClient::ClientEventArgs::EventType_Disconnect:
@ -98,14 +104,14 @@ namespace DanBias
this->ParseProtocol(e.args.data.protocol, e.sender);
break;
}
}
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
{
}
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
{
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
if(this->gameSession)
{
this->gameSession.Attach(client);
Attach(client);
}
else
{
@ -132,6 +138,5 @@ namespace DanBias
client->Send(p1.GetProtocol());
client->Send(p2.GetProtocol());
}
}
}
}//End namespace DanBias

View File

@ -32,6 +32,8 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
break;
case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
break;
case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
break;
}
}
@ -112,4 +114,29 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster:
this->readyList.Remove(c);
}
}
void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c)
{
NetClient temp;
bool found = false;
//find client in waiting list
for (unsigned int i = 0; !found && i < this->clients.Size(); i++)
{
if(this->clients[i]->GetID() == c->GetID())
{
temp = this->clients[i];
found = true;
}
}
//Something is wrong
if(!found)
{
c->Disconnect();
}
else
{
//Send game data
this->gameSession.Attach(temp);
}
}

View File

@ -209,6 +209,7 @@ namespace DanBias
{
IPlayerData* p = this->clients[i]->GetPlayer();
Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
//Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
this->clients[i]->GetClient()->Send(oc);
}
}