Gamlogic - Merge with Linda
This commit is contained in:
commit
8700824d12
|
@ -31,38 +31,55 @@ namespace DanBias
|
|||
{
|
||||
|
||||
int pType = p[0].value.netInt;
|
||||
Client::GameClientState::ProtocolStruct* protocolData;
|
||||
//Client::GameClientState::ProtocolStruct* protocolData;
|
||||
switch (pType)
|
||||
{
|
||||
case protocol_Gamplay_PlayerNavigation:
|
||||
{
|
||||
|
||||
|
||||
Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput;
|
||||
for(int i = 0; i< 6; i++)
|
||||
{
|
||||
protocolData->key[i] = p[i+1].value.netBool;
|
||||
}
|
||||
|
||||
((Client::GameState*)gameClientState)->Protocol(protocolData);
|
||||
delete protocolData;
|
||||
protocolData = NULL;
|
||||
}
|
||||
break;
|
||||
case protocol_Gamplay_PlayerPosition:
|
||||
protocolData = new Client::GameClientState::PlayerPos;
|
||||
for(int i = 0; i< 3; i++)
|
||||
{
|
||||
((Client::GameClientState::PlayerPos*)protocolData)->playerPos[i] = p[i].value.netFloat;
|
||||
Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos;
|
||||
for(int i = 0; i< 3; i++)
|
||||
{
|
||||
protocolData->playerPos[i] = p[i].value.netFloat;
|
||||
}
|
||||
//if(dynamic_cast<Client::GameState*>(gameClientState))
|
||||
gameClientState->Protocol(protocolData);
|
||||
delete protocolData;
|
||||
protocolData = NULL;
|
||||
}
|
||||
if(dynamic_cast<Client::GameState*>(gameClientState))
|
||||
((Client::GameState*)gameClientState)->Protocol(protocolData);
|
||||
delete protocolData;
|
||||
protocolData = NULL;
|
||||
break;
|
||||
|
||||
|
||||
case protocol_Gamplay_ObjectPosition:
|
||||
protocolData = new Client::GameClientState::ObjPos;
|
||||
((Client::GameClientState::ObjPos*)protocolData)->object_ID = p[1].value.netInt;
|
||||
for(int i = 0; i< 16; i++)
|
||||
{
|
||||
((Client::GameClientState::ObjPos*)protocolData)->worldPos[i] = p[i+2].value.netFloat;
|
||||
|
||||
Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos;
|
||||
protocolData->object_ID = p[1].value.netInt;
|
||||
for(int i = 0; i< 16; i++)
|
||||
{
|
||||
protocolData->worldPos[i] = p[i+2].value.netFloat;
|
||||
}
|
||||
|
||||
|
||||
gameClientState->Protocol(protocolData);
|
||||
|
||||
delete protocolData;
|
||||
protocolData = NULL;
|
||||
}
|
||||
|
||||
if(dynamic_cast<Client::GameState*>(gameClientState))
|
||||
((Client::GameState*)gameClientState)->Protocol(protocolData);
|
||||
|
||||
delete protocolData;
|
||||
protocolData = NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -116,8 +133,10 @@ namespace DanBias
|
|||
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
|
||||
|
||||
m_data->recieverObj = new MyRecieverObject;
|
||||
m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient();
|
||||
|
||||
m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object);
|
||||
m_data->recieverObj->nwClient->Connect(desc.port, desc.IP);
|
||||
|
||||
if (!m_data->recieverObj->nwClient->IsConnected())
|
||||
{
|
||||
// failed to connect
|
||||
|
|
|
@ -22,6 +22,10 @@ public:
|
|||
int object_ID;
|
||||
float worldPos[16];
|
||||
};
|
||||
struct KeyInput :public ProtocolStruct
|
||||
{
|
||||
bool key[6];
|
||||
};
|
||||
struct PlayerPos :public ProtocolStruct
|
||||
{
|
||||
float playerPos[3];
|
||||
|
|
|
@ -92,6 +92,7 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
|
|||
// read server data
|
||||
// update objects
|
||||
{
|
||||
bool send = false;
|
||||
GameLogic::Protocol_PlayerMovement movePlayer;
|
||||
movePlayer.bForward = false;
|
||||
movePlayer.bBackward = false;
|
||||
|
@ -104,21 +105,25 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
|
|||
if(KeyInput->IsKeyPressed(DIK_W))
|
||||
{
|
||||
movePlayer.bForward = true;
|
||||
send = true;
|
||||
}
|
||||
if(KeyInput->IsKeyPressed(DIK_S))
|
||||
{
|
||||
movePlayer.bBackward = true;
|
||||
send = true;
|
||||
}
|
||||
if(KeyInput->IsKeyPressed(DIK_A))
|
||||
{
|
||||
movePlayer.bStrafeLeft = true;
|
||||
send = true;
|
||||
}
|
||||
if(KeyInput->IsKeyPressed(DIK_D))
|
||||
{
|
||||
movePlayer.bStrafeRight = true;
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (privData->nwClient->IsConnected())
|
||||
if (privData->nwClient->IsConnected() && send)
|
||||
{
|
||||
privData->nwClient->Send(movePlayer);
|
||||
}
|
||||
|
@ -167,13 +172,18 @@ bool GameState::Release()
|
|||
|
||||
void GameState::Protocol(ProtocolStruct* pos)
|
||||
{
|
||||
// move message
|
||||
/*
|
||||
if ((KeyInput*)pos)
|
||||
{
|
||||
}
|
||||
if((ObjPos*)pos)
|
||||
ObjectPosProtocol((ObjPos*)pos);
|
||||
else if((PlayerPos*)pos)
|
||||
PlayerPosProtocol((PlayerPos*)pos);
|
||||
PlayerPosProtocol((PlayerPos*)pos);*/
|
||||
}
|
||||
|
||||
void DanBias::Client::GameState::Protocol( PlayerPos* pos )
|
||||
void GameState::Protocol( PlayerPos* pos )
|
||||
{
|
||||
Oyster::Math::Float4x4 world, translate;
|
||||
|
||||
|
@ -184,7 +194,7 @@ void DanBias::Client::GameState::Protocol( PlayerPos* pos )
|
|||
privData->object[0]->setPos( world );
|
||||
}
|
||||
|
||||
void DanBias::Client::GameState::Protocol( ObjPos* pos )
|
||||
void GameState::Protocol( ObjPos* pos )
|
||||
{
|
||||
Oyster::Math::Float4x4 world;
|
||||
for(int i = 0; i<16; i++)
|
||||
|
@ -194,6 +204,15 @@ void DanBias::Client::GameState::Protocol( ObjPos* pos )
|
|||
privData->object[pos->object_ID]->setPos(world);
|
||||
}
|
||||
|
||||
void GameState::Protocol( KeyInput* pos )
|
||||
{
|
||||
bool key = false;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
key = pos->key[i];
|
||||
}
|
||||
}
|
||||
|
||||
void GameState::PlayerPosProtocol(PlayerPos* pos)
|
||||
{
|
||||
Oyster::Math::Float4x4 world, translate;
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
void Protocol(ProtocolStruct* pos)override;
|
||||
void Protocol(PlayerPos* pos);
|
||||
void Protocol(ObjPos* pos);
|
||||
void Protocol(KeyInput* pos);
|
||||
void PlayerPosProtocol(PlayerPos* pos);
|
||||
void ObjectPosProtocol(ObjPos* pos);
|
||||
//void Protocol(LightPos pos);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <Windows.h>
|
||||
#include <vld.h>
|
||||
|
||||
#include "DanBiasServerAPI.h"
|
||||
//#include "DanBiasServerAPI.h"
|
||||
#include "DanBiasGame.h"
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ struct ClientDataContainer
|
|||
sendPostBox = new PostBox<CustomNetProtocol>();
|
||||
connection.InitiateClient();
|
||||
connection.SetBlockingMode(false);
|
||||
|
||||
}
|
||||
ClientDataContainer(IThreadObject* o, unsigned int socket )
|
||||
:connection(socket), ID(currID++)
|
||||
|
@ -170,13 +171,14 @@ NetworkClient::NetworkClient(unsigned int socket)
|
|||
NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type)
|
||||
{
|
||||
privateData = new PrivateData();
|
||||
this->privateData->data->recvObj = SmartPointer<RecieverObject>(&recvObj);;
|
||||
this->privateData->data->callbackType = type;
|
||||
this->privateData->data->recvObj = recvObj;
|
||||
}
|
||||
|
||||
NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type, unsigned int socket)
|
||||
{
|
||||
privateData = new PrivateData(socket);
|
||||
this->privateData->data->recvObj = SmartPointer<RecieverObject>(&recvObj);
|
||||
this->privateData->data->recvObj = recvObj;
|
||||
this->privateData->data->callbackType = type;
|
||||
this->privateData->data->thread.Create(this->privateData, true);
|
||||
}
|
||||
|
@ -213,11 +215,11 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[])
|
|||
if(this->privateData->data->thread.IsCreated()) return false;
|
||||
|
||||
this->privateData->data->thread.Create(this->privateData, true);
|
||||
|
||||
privateData->data->connection.SetBlockingMode(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
privateData->data->connection.SetBlockingMode(false);
|
||||
|
||||
|
||||
//Connect has failed
|
||||
return false;
|
||||
|
|
|
@ -44,7 +44,7 @@ struct Translator::PrivateData
|
|||
headerString.push_back(it->second.type);
|
||||
}
|
||||
|
||||
message.PackShort(size, bytes);
|
||||
message.PackShort(headerString.size(), bytes);
|
||||
size += 2;
|
||||
|
||||
for(int i = 0; i < (int)headerString.size(); i++)
|
||||
|
@ -217,6 +217,7 @@ void Translator::Pack(OysterByte &bytes, CustomNetProtocol& protocol)
|
|||
|
||||
privateData->PackHeader(bytes, protocol);
|
||||
privateData->PackMessage(bytes, protocol);
|
||||
this->privateData->headerString.clear();
|
||||
}
|
||||
|
||||
bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes)
|
||||
|
@ -227,6 +228,6 @@ bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes)
|
|||
}
|
||||
|
||||
privateData->UnpackMessage(protocol, bytes);
|
||||
|
||||
this->privateData->headerString.clear();
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue