Danbias/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp

165 lines
3.4 KiB
C++
Raw Normal View History

2013-12-12 09:33:59 +01:00
#include <GameProtocols.h>
#include <PostBox\PostBox.h>
2013-12-19 12:32:23 +01:00
#include "GameSession.h"
#include "ClientObject.h"
2013-12-19 12:32:23 +01:00
#include "..\Helpers\ProtocolParser.h"
2013-12-19 12:41:37 +01:00
#include <GameLogicStates.h>
2013-12-12 09:33:59 +01:00
#define ERIK
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
2013-12-19 12:32:23 +01:00
using namespace Oyster::Thread;
2013-12-12 09:33:59 +01:00
namespace DanBias
{
GameSession::GameSession()
{
2013-12-19 12:32:23 +01:00
this->box = 0;
}
GameSession::~GameSession()
{
2013-12-19 12:32:23 +01:00
delete this->box;
this->box = 0;
}
2013-12-19 12:32:23 +01:00
void GameSession::Run(GameSessionDescription& desc)
{
2013-12-19 12:32:23 +01:00
if(this->Init(desc))
{
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return;
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
}
}
2013-12-19 12:32:23 +01:00
void GameSession::Join(Utility::DynamicMemory::SmartPointer<ClientObject> client)
{
AttachClient(client, this->box);
}
2013-12-19 12:32:23 +01:00
////private: overriden NetworkSession functions
void GameSession::AttachClient(SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box )
{
2013-12-19 12:32:23 +01:00
NetworkSession::AttachClient(client, box);
}
void GameSession::Close()
{
}
SmartPointer<ClientObject> GameSession::DetachClient(NetworkClient* client)
{
return SmartPointer<ClientObject>();
}
SmartPointer<ClientObject> GameSession::DetachClient(ClientObject* client)
{
return SmartPointer<ClientObject>();
}
SmartPointer<ClientObject> GameSession::DetachClient(short ID)
{
return SmartPointer<ClientObject>();
}
void GameSession::Send(::CustomNetProtocol& protocol)
{
}
void GameSession::Send(CustomNetProtocol& protocol, int ID)
{
}
void GameSession::SetPostbox(IPostBox<NetworkSession::NetEvent> *box)
{
}
void GameSession::CloseSession(NetworkSession* clientDestination)
{
}
////private: //overriden Threading functions
void GameSession::ThreadEntry()
{
}
void GameSession::ThreadExit()
{
}
bool GameSession::DoWork ( )
{
this->ParseEvents();
this->Frame();
return true;
}
////private:
2013-12-19 12:32:23 +01:00
bool GameSession::Init(GameSessionDescription& desc)
{
2013-12-19 12:32:23 +01:00
if(desc.clients.Size() == 0) return false;
this->box = new PostBox<NetEvent>();
this->owner = desc.owner;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
desc.clients[i]->SetPostbox(this->box);
this->clients.Push(desc.clients[i]);
}
return true;
}
void GameSession::Frame()
{
}
void GameSession::ParseEvents()
{
if(this->box && !this->box->IsEmpty())
{
NetEvent &e = this->box->Fetch();
2013-12-19 12:32:23 +01:00
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
2013-12-19 12:32:23 +01:00
ParseProtocol(e.protocol, *e.reciever);
}
}
2013-12-19 12:32:23 +01:00
void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c)
{
switch (p[0].value.netShort)
{
2013-12-19 12:32:23 +01:00
case protocol_Gamplay_PlayerNavigation:
{
if(p[1].value.netBool) //bool bForward;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
}
break;
case protocol_Gamplay_PlayerMouseMovement:
2013-12-19 12:32:23 +01:00
break;
case protocol_Gamplay_PlayerPosition:
break;
case protocol_Gamplay_CreateObject:
break;
case protocol_Gamplay_ObjectPosition:
break;
}
2013-12-19 12:32:23 +01:00
}
2013-12-19 12:32:23 +01:00
#ifdef ERIK
//VARIABLES GOES HERE
#endif
2013-12-12 09:33:59 +01:00
}//End namespace DanBias
2013-12-12 09:33:59 +01:00