GL - control protocol added

This commit is contained in:
Linda Andersson 2013-12-18 15:28:47 +01:00
parent 0c98e2847d
commit a4907c8e2e
9 changed files with 120 additions and 30 deletions

View File

@ -6,6 +6,7 @@
#include "GameClientState\GameState.h" #include "GameClientState\GameState.h"
#include "GameClientState\LobbyState.h" #include "GameClientState\LobbyState.h"
#include "PlayerProtocols.h" #include "PlayerProtocols.h"
#include "ControlProtocols.h"
#include "NetworkClient.h" #include "NetworkClient.h"
#include "../WindowManager/WindowShell.h" #include "../WindowManager/WindowShell.h"
@ -29,9 +30,15 @@ namespace DanBias
int pType = p[0].value.netInt; int pType = p[0].value.netInt;
switch (pType) switch (pType)
{ {
case protocol_Gamplay_PlayerNavigation: case protocol_Status:
{
GameLogic::Protocol_Status::States state;
state = (GameLogic::Protocol_Status::States)p[1].value.netShort;
}
break;
case protocol_Gameplay_PlayerNavigation:
{ {
Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput; Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput;
for(int i = 0; i< 6; i++) for(int i = 0; i< 6; i++)
{ {
@ -44,7 +51,7 @@ namespace DanBias
protocolData = NULL; protocolData = NULL;
} }
break; break;
case protocol_Gamplay_PlayerPosition: case protocol_Gameplay_PlayerPosition:
{ {
Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos; Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos;
for(int i = 0; i< 3; i++) for(int i = 0; i< 3; i++)
@ -58,7 +65,7 @@ namespace DanBias
} }
break; break;
case protocol_Gamplay_CreateObject: case protocol_Gameplay_CreateObject:
{ {
Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj;
@ -76,7 +83,19 @@ namespace DanBias
protocolData = NULL; protocolData = NULL;
} }
break; break;
case protocol_Gamplay_ObjectPosition: case protocol_Gameplay_RemoveObject:
{
Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj;
protocolData->object_ID = p[1].value.netInt;
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
}
break;
case protocol_Gameplay_ObjectPosition:
{ {
Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos; Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos;
@ -113,7 +132,6 @@ namespace DanBias
} }
public: public:
//Client::GameClientState* gameClientState;
WindowShell* window; WindowShell* window;
InputClass* inputObj; InputClass* inputObj;
Utility::WinTimer* timer; Utility::WinTimer* timer;

View File

@ -28,6 +28,11 @@ public:
char* path; char* path;
float worldPos[16]; float worldPos[16];
}; };
struct RemoveObj :public ProtocolStruct
{
int object_ID;
//particle effect
};
struct KeyInput :public ProtocolStruct struct KeyInput :public ProtocolStruct
{ {
bool key[6]; bool key[6];

View File

@ -4,6 +4,7 @@
#include "C_obj/C_DynamicObj.h" #include "C_obj/C_DynamicObj.h"
#include "NetworkClient.h" #include "NetworkClient.h"
#include "PlayerProtocols.h" #include "PlayerProtocols.h"
#include "ControlProtocols.h"
using namespace DanBias::Client; using namespace DanBias::Client;
@ -83,10 +84,15 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
switch (privData->state) switch (privData->state)
{ {
case gameStateState_loading: case gameStateState_loading:
// load map {
// wait for all players // load map
LoadGame(); // wait for all players
privData->state = gameStateState_playing; LoadGame();
GameLogic::Protocol_Status gameStatus;
gameStatus.status = GameLogic::Protocol_Status::States_ready;
privData->nwClient->Send(gameStatus);
privData->state = gameStateState_playing;
}
break; break;
case gameStateState_playing: case gameStateState_playing:
// read server data // read server data
@ -180,15 +186,7 @@ bool GameState::Release()
void GameState::Protocol(ProtocolStruct* pos) void GameState::Protocol(ProtocolStruct* pos)
{ {
// move message
/*
if ((KeyInput*)pos)
{
}
if((ObjPos*)pos)
ObjectPosProtocol((ObjPos*)pos);
else if((PlayerPos*)pos)
PlayerPosProtocol((PlayerPos*)pos);*/
} }
void GameState::Protocol( PlayerPos* pos ) void GameState::Protocol( PlayerPos* pos )
@ -224,6 +222,7 @@ void GameState::Protocol( NewObj* pos )
modelData.world = world; modelData.world = world;
modelData.visible = true; modelData.visible = true;
//not sure if this is good parsing rom char* to wstring
const char* path = pos->path; const char* path = pos->path;
modelData.modelPath = std::wstring(path, path + strlen(path)); modelData.modelPath = std::wstring(path, path + strlen(path));
// load models // load models
@ -240,6 +239,11 @@ void GameState::Protocol( KeyInput* pos )
} }
} }
void DanBias::Client::GameState::Protocol( RemoveObj* obj )
{
privData->object[obj->object_ID]->Release( );
}
void GameState::PlayerPosProtocol(PlayerPos* pos) void GameState::PlayerPosProtocol(PlayerPos* pos)
{ {
Oyster::Math::Float4x4 world, translate; Oyster::Math::Float4x4 world, translate;

View File

@ -36,6 +36,7 @@ public:
void Protocol(ObjPos* pos); void Protocol(ObjPos* pos);
void Protocol(KeyInput* pos); void Protocol(KeyInput* pos);
void Protocol( NewObj* pos ); void Protocol( NewObj* pos );
void Protocol(RemoveObj* obj);
void PlayerPosProtocol(PlayerPos* pos); void PlayerPosProtocol(PlayerPos* pos);
void ObjectPosProtocol(ObjPos* pos); void ObjectPosProtocol(ObjPos* pos);
//void Protocol(LightPos pos); //void Protocol(LightPos pos);

View File

@ -0,0 +1,38 @@
#ifndef GAMELOGIC_CONTROL_PROTOCOLS_H
#define GAMELOGIC_CONTROL_PROTOCOLS_H
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"
namespace GameLogic
{
struct Protocol_Status :public Oyster::Network::CustomProtocolObject
{
enum States
{
States_ready,
States_idle,
States_bussy,
States_disconected,
};
States status;
Protocol_Status()
{
this->protocol[0].value = protocol_Status;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = status;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
}
#endif //!GAMELOGIC_CONTROL_PROTOCOLS_H

View File

@ -154,6 +154,7 @@
</Lib> </Lib>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="ControlProtocols.h" />
<ClInclude Include="ObjectProtocols.h" /> <ClInclude Include="ObjectProtocols.h" />
<ClInclude Include="PlayerProtocols.h" /> <ClInclude Include="PlayerProtocols.h" />
<ClInclude Include="ProtocolIdentificationID.h" /> <ClInclude Include="ProtocolIdentificationID.h" />

View File

@ -17,8 +17,8 @@ namespace GameLogic
Protocol_CreateObject() Protocol_CreateObject()
{ {
this->protocol[0].value = protocol_Gamplay_CreateObject; this->protocol[0].value = protocol_Gameplay_CreateObject;
this->protocol[0].type = Oyster::Network::NetAttributeType_Int; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray; this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray;
@ -79,7 +79,7 @@ namespace GameLogic
Protocol_ObjectPosition() Protocol_ObjectPosition()
{ {
this->protocol[0].value = protocol_Gamplay_ObjectPosition; this->protocol[0].value = protocol_Gameplay_ObjectPosition;
this->protocol[0].type = Oyster::Network::NetAttributeType_Int; this->protocol[0].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
@ -129,6 +129,27 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
struct Protocol_RemoveObject :public Oyster::Network::CustomProtocolObject
{
int object_ID;
Protocol_RemoveObject()
{
this->protocol[0].value = protocol_Gameplay_RemoveObject;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
} }
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H

View File

@ -25,7 +25,7 @@ namespace GameLogic
Protocol_PlayerMovement() Protocol_PlayerMovement()
{ {
this->protocol[0].value = protocol_Gamplay_PlayerNavigation; this->protocol[0].value = protocol_Gameplay_PlayerNavigation;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
@ -60,7 +60,7 @@ namespace GameLogic
Protocol_PlayerMouse() Protocol_PlayerMouse()
{ {
this->protocol[0].value = protocol_Gamplay_PlayerMouseMovement; this->protocol[0].value = protocol_Gameplay_PlayerMouseMovement;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
@ -87,7 +87,7 @@ namespace GameLogic
Protocol_PlayerPosition() Protocol_PlayerPosition()
{ {
this->protocol[0].value = protocol_Gamplay_PlayerPosition; this->protocol[0].value = protocol_Gameplay_PlayerPosition;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[1].type = Oyster::Network::NetAttributeType_Float;

View File

@ -7,12 +7,14 @@
/* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */
#define protocol_Gamplay_PlayerNavigation 0 #define protocol_Gameplay_PlayerNavigation 0
#define protocol_Gamplay_PlayerMouseMovement 1 #define protocol_Gameplay_PlayerMouseMovement 1
#define protocol_Gamplay_PlayerPosition 2 #define protocol_Gameplay_PlayerPosition 2
#define protocol_Gamplay_CreateObject 3 #define protocol_Gameplay_CreateObject 3
#define protocol_Gamplay_ObjectPosition 4 #define protocol_Gameplay_RemoveObject 4
#define protocol_Gameplay_ObjectPosition 5
#define protocol_Status 50
#define protocol_Lobby_Msg 100 #define protocol_Lobby_Msg 100