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