GL - merge with gameServer

This commit is contained in:
lindaandersson 2014-01-21 14:36:46 +01:00
commit 8792aab992
11 changed files with 142 additions and 89 deletions

View File

@ -61,6 +61,7 @@ GameState::gameStateState GameState::LoadGame()
plight.Color = Oyster::Math::Float3(0,0,1); plight.Color = Oyster::Math::Float3(0,0,1);
plight.Radius = 50; plight.Radius = 50;
plight.Bright = 2; plight.Bright = 2;
Oyster::Graphics::API::AddLight(plight); Oyster::Graphics::API::AddLight(plight);
LoadModels(L"map"); LoadModels(L"map");
InitCamera(Oyster::Math::Float3(0,0,20.0f)); InitCamera(Oyster::Math::Float3(0,0,20.0f));
@ -283,7 +284,7 @@ void GameState::Protocol( ObjPos* pos )
world[i] = pos->worldPos[i]; world[i] = pos->worldPos[i];
} }
for (int i = 0; i < privData->object.size(); i++) for (unsigned int i = 0; i < privData->object.size(); i++)
{ {
if(privData->object[i]->GetId() == pos->object_ID) if(privData->object[i]->GetId() == pos->object_ID)
{ {

View File

@ -43,7 +43,7 @@ bool LobbyState::LoadModels(std::wstring file)
plight.Pos = Oyster::Math::Float3(-2,3,0); plight.Pos = Oyster::Math::Float3(-2,3,0);
plight.Color = Oyster::Math::Float3(0,1,0); plight.Color = Oyster::Math::Float3(0,1,0);
plight.Radius = 10; plight.Radius = 10;
plight.Bright = 3; plight.Bright = 1;
Oyster::Graphics::API::AddLight(plight); Oyster::Graphics::API::AddLight(plight);
// open file // open file
// read file // read file

View File

@ -63,7 +63,7 @@ namespace DanBias
case protocol_Gameplay_PlayerChangeWeapon: case protocol_Gameplay_PlayerChangeWeapon:
break; break;
case protocol_Gameplay_PlayerDamage: case protocol_Gameplay_ObjectDamage:
break; break;
} }

View File

@ -37,7 +37,7 @@ namespace DanBias
if(GetAsyncKeyState(VK_DOWN)) if(GetAsyncKeyState(VK_DOWN))
{ {
Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity;
Protocol_CreateObject p(world, 2, "../Content/crate"); Protocol_ObjectCreate p(world, 2, "../Content/crate");
Send(p.GetProtocol()); Send(p.GetProtocol());
Sleep(100); Sleep(100);
} }

View File

@ -104,7 +104,7 @@ namespace DanBias
void MainLobby::SendUpdate() void MainLobby::SendUpdate()
{ {
//Send Lobbys //Send Lobbys
GameLogic::Protocol_LobbyUpdate(); GameLogic::Protocol_LobbyRefresh();
} }
}//End namespace DanBias }//End namespace DanBias

View File

@ -7,57 +7,7 @@
namespace GameLogic namespace GameLogic
{ {
struct Protocol_GameplayInitiateSession :public Oyster::Network::CustomProtocolObject
{
struct SessionInitData
{
int id;
int type;
//std::string text;
};
std::vector<SessionInitData> element;
Protocol_GameplayInitiateSession()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_Initiate;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
}
Protocol_GameplayInitiateSession(Oyster::Network::CustomNetProtocol& p)
{
int size = p[1].value.netInt;
for (int i = 0; i < size; i++)
{
SessionInitData d = { p[i+2].value.netInt, p[i+3].value.netInt /*, p[i+4].value.netCharPtr */ };
element.push_back(d);
}
}
void Add(int id, int type, std::string text)
{
SessionInitData d = { id, type /*, text*/ };
element.push_back(d);
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
//Store the elements count
this->protocol[1].value = element.size();
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (unsigned int i = 0; i < element.size(); i+=3)
{
this->protocol[i+2].value = element[i].id;
this->protocol[i+3].value = element[i].type;
//element[i].text.copy(this->protocol[i+4].value.netCharPtr, element[i].text.size());
this->protocol[i+2].type = Oyster::Network::NetAttributeType_Int;
this->protocol[i+3].type = Oyster::Network::NetAttributeType_Int;
//this->protocol[i+4].type = Oyster::Network::NetAttributeType_CharArray;
}
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
} }
#endif // !GAMEPROTOCOLS_GAMEPLAYPROTOCOLS_H #endif // !GAMEPROTOCOLS_GAMEPLAYPROTOCOLS_H

View File

@ -9,6 +9,13 @@
#include <CustomNetProtocol.h> #include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h" #include "ProtocolIdentificationID.h"
//#define protocol_Lobby_CreateGame 200
//#define protocol_Lobby_StartGame 201
//#define protocol_Lobby_JoinGame 202
//#define protocol_Lobby_JoinLobby 203
//#define protocol_Lobby_LeaveLobby 204
//#define protocol_Lobby_Refresh 205
namespace GameLogic namespace GameLogic
{ {
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
@ -40,13 +47,13 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
struct Protocol_LobbyJoinGame :public Oyster::Network::CustomProtocolObject struct Protocol_LobbyStartGame :public Oyster::Network::CustomProtocolObject
{ {
char gameId; char gameId;
Protocol_LobbyJoinGame() Protocol_LobbyStartGame()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_JoinGame; this->protocol[protocol_INDEX_ID].value = protocol_Lobby_StartGame;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Char; this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
@ -61,13 +68,13 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
struct Protocol_LobbyStartGame :public Oyster::Network::CustomProtocolObject struct Protocol_LobbyJoinGame :public Oyster::Network::CustomProtocolObject
{ {
char gameId; char gameId;
Protocol_LobbyStartGame() Protocol_LobbyJoinGame()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_StartGame; this->protocol[protocol_INDEX_ID].value = protocol_Lobby_JoinGame;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Char; this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
@ -125,7 +132,7 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
struct Protocol_LobbyUpdate :public Oyster::Network::CustomProtocolObject struct Protocol_LobbyRefresh :public Oyster::Network::CustomProtocolObject
{ {
struct LobbyUpdateData struct LobbyUpdateData
{ {
@ -134,14 +141,14 @@ namespace GameLogic
}; };
int count; int count;
LobbyUpdateData* data; LobbyUpdateData* data;
Protocol_LobbyUpdate() Protocol_LobbyRefresh()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_LeaveLobby; this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Refresh;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
} }
Protocol_LobbyUpdate( Oyster::Network::CustomNetProtocol* p ) Protocol_LobbyRefresh( Oyster::Network::CustomNetProtocol* p )
{ {
count = (*p)[1].value.netInt; count = (*p)[1].value.netInt;
data = new LobbyUpdateData[count]; data = new LobbyUpdateData[count];
@ -150,7 +157,7 @@ namespace GameLogic
//data[i].mapName = (*p)[i].value. //data[i].mapName = (*p)[i].value.
} }
} }
~Protocol_LobbyUpdate() ~Protocol_LobbyRefresh()
{ {
delete [] data; delete [] data;
data = 0; data = 0;

View File

@ -4,14 +4,99 @@
#include <CustomNetProtocol.h> #include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h" #include "ProtocolIdentificationID.h"
//protocol_Gameplay_PlayerMovement 300
//protocol_Gameplay_PlayerMouseMovement 301
//protocol_Gameplay_PlayerChangeWeapon 302
//#define protocol_Gameplay_ObjectPickup 303
//#define protocol_Gameplay_ObjectDamage 304
//#define protocol_Gameplay_ObjectPosition 305
//#define protocol_Gameplay_ObjectEnabled 306
//#define protocol_Gameplay_ObjectDisabled 307
//#define protocol_Gameplay_ObjectCreate 308
namespace GameLogic namespace GameLogic
{ {
struct Protocol_ObjectPickup :public Oyster::Network::CustomProtocolObject
{
int object_ID;
short pickup_ID;
Protocol_ObjectPickup()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPickup;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Short;
object_ID = -1;
pickup_ID = -1;
}
Protocol_ObjectPickup(int objectID, short pickupID)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Short;
object_ID = objectID;
pickup_ID = pickupID;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
this->protocol[2].value = pickup_ID;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_ObjectDamage :public Oyster::Network::CustomProtocolObject
{
int object_ID;
float health; //Precentage%
Protocol_ObjectDamage()
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDamage;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
object_ID = -1;
health = 0.0f;
}
Protocol_ObjectDamage(int id, float hp)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDamage;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
object_ID = id;
health = hp;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
this->protocol[2].value = health;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject
{ {
int object_ID; int object_ID;
float worldMatrix[16]; float worldMatrix[16];
// look at dir
Protocol_ObjectPosition() Protocol_ObjectPosition()
{ {
@ -60,7 +145,6 @@ namespace GameLogic
{ {
int object_ID; int object_ID;
float worldMatrix[16]; float worldMatrix[16];
// look at dir
Protocol_ObjectEnable() Protocol_ObjectEnable()
{ {
@ -116,6 +200,17 @@ namespace GameLogic
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
} }
Protocol_ObjectDisable(int id, float time)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDisabled;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
object_ID = id;
timer = time;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol* GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
@ -127,14 +222,13 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
struct Protocol_CreateObject :public Oyster::Network::CustomProtocolObject struct Protocol_ObjectCreate :public Oyster::Network::CustomProtocolObject
{ {
int object_ID; int object_ID;
char *path; char *name;
float worldMatrix[16]; float worldMatrix[16];
Protocol_ObjectCreate()
Protocol_CreateObject()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate; this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
@ -147,7 +241,7 @@ namespace GameLogic
this->protocol[i].type = Oyster::Network::NetAttributeType_Float; this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
} }
} }
Protocol_CreateObject(float m[16], int id, char *path) Protocol_ObjectCreate(float m[16], int id, char *path)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate; this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int;
@ -161,14 +255,14 @@ namespace GameLogic
} }
object_ID = id; object_ID = id;
this->path = path; this->name = path;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override Oyster::Network::CustomNetProtocol* GetProtocol() override
{ {
this->protocol[1].value = object_ID; this->protocol[1].value = object_ID;
this->protocol[2].value = path; this->protocol[2].value = name;
this->protocol[3].value = worldMatrix[0]; this->protocol[3].value = worldMatrix[0];
this->protocol[4].value = worldMatrix[1]; this->protocol[4].value = worldMatrix[1];
this->protocol[5].value = worldMatrix[2]; this->protocol[5].value = worldMatrix[2];

View File

@ -124,7 +124,7 @@ namespace GameLogic
Protocol_PlayerDamage() Protocol_PlayerDamage()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerDamage; this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDamage;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
@ -151,7 +151,7 @@ namespace GameLogic
Protocol_PlayerPickup() Protocol_PlayerPickup()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerPickup; this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPickup;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;

View File

@ -15,46 +15,47 @@
/***********************************/ /***********************************/
/********* RESERVERD PROTOCOLS ***************************************************************************************************/ /********* RESERVERD PROTOCOLS ***************************************************************************************************/
/********** [ 0 - 100 ] *********/ /********** [ 0 - 99 ] *********/
#define protocol_RESERVED_MIN 0 #define protocol_RESERVED_MIN 0
#define protocol_RESERVED_MAX 99 #define protocol_RESERVED_MAX 99
/***********************************/ /***********************************/
/********* GENERAL PROTOCOLS ***************************************************************************************************/ /********* GENERAL PROTOCOLS ***************************************************************************************************/
/***********[ 100 - 200 ]***********/ /***********[ 100 - 199 ]***********/
#define protocol_GeneralMIN 100 #define protocol_GeneralMIN 100
#define protocol_General_Status 100 #define protocol_General_Status 100
#define protocol_General_Text 101 #define protocol_General_Text 101
#define protocol_General_Disconnect 102
#define protocol_General_Login 110
#define protocol_GeneralMAX 199 #define protocol_GeneralMAX 199
/***********************************/ /***********************************/
/********* LOBBY PROTOCOLS ***************************************************************************************************/ /********* LOBBY PROTOCOLS ***************************************************************************************************/
/***********[ 200 - 300 ]***********/ /***********[ 200 - 299 ]***********/
#define protocol_LobbyMIN 200 #define protocol_LobbyMIN 200
#define protocol_Lobby_CreateGame 200 #define protocol_Lobby_CreateGame 200
#define protocol_Lobby_JoinGame 201 #define protocol_Lobby_StartGame 201
#define protocol_Lobby_StartGame 202 #define protocol_Lobby_JoinGame 202
#define protocol_Lobby_JoinLobby 203 #define protocol_Lobby_JoinLobby 203
#define protocol_Lobby_LeaveLobby 204 #define protocol_Lobby_LeaveLobby 204
#define protocol_Lobby_CreateGameLobby 205 #define protocol_Lobby_Refresh 205
#define protocol_LobbyMAX 299 #define protocol_LobbyMAX 299
/***********************************/ /***********************************/
/********* GAMEPLAY PROTOCOLS ***************************************************************************************************/ /********* GAMEPLAY PROTOCOLS ***************************************************************************************************/
/***********[ 300 - 400 ]***********/ /***********[ 300 - 399 ]***********/
#define protocol_GameplayMIN 300 #define protocol_GameplayMIN 300
#define protocol_Gameplay_PlayerMovement 300 #define protocol_Gameplay_PlayerMovement 300
#define protocol_Gameplay_PlayerMouseMovement 301 #define protocol_Gameplay_PlayerMouseMovement 301
#define protocol_Gameplay_PlayerChangeWeapon 302 #define protocol_Gameplay_PlayerChangeWeapon 302
#define protocol_Gameplay_PlayerDamage 303 #define protocol_Gameplay_ObjectPickup 303
#define protocol_Gameplay_PlayerPickup 304 #define protocol_Gameplay_ObjectDamage 304
#define protocol_Gameplay_ObjectPosition 305 #define protocol_Gameplay_ObjectPosition 305
#define protocol_Gameplay_ObjectEnabled 306 #define protocol_Gameplay_ObjectEnabled 306
#define protocol_Gameplay_ObjectDisabled 307 #define protocol_Gameplay_ObjectDisabled 307
#define protocol_Gameplay_ObjectCreate 308 #define protocol_Gameplay_ObjectCreate 308
#define protocol_Gameplay_Initiate 309
#define protocol_GameplayMAX 399 #define protocol_GameplayMAX 399

View File

@ -59,11 +59,11 @@ namespace Oyster
switch (callbackType) switch (callbackType)
{ {
case CallbackType_Function: case CallbackType_Function:
value.callbackFunction(e); if(value.callbackFunction) value.callbackFunction(e);
return true; return true;
break; break;
case CallbackType_Object: case CallbackType_Object:
value.callbackObject->ObjectCallback(e); if(value.callbackObject) value.callbackObject->ObjectCallback(e);
return true; return true;
break; break;
case CallbackType_PostBox: case CallbackType_PostBox: