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

264 lines
6.1 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:41:37 +01:00
#include <GameLogicStates.h>
2013-12-12 09:33:59 +01:00
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-19 15:35:49 +01:00
using namespace GameLogic;
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>();
}
2013-12-19 15:35:49 +01:00
void GameSession::Send(CustomNetProtocol& protocol)
{
2013-12-19 15:35:49 +01:00
NetworkSession::Send(protocol);
}
void GameSession::Send(CustomNetProtocol& protocol, int ID)
{
2013-12-19 15:35:49 +01:00
NetworkSession::Send(protocol, ID);
}
void GameSession::SetPostbox(IPostBox<NetworkSession::NetEvent> *box)
{
2013-12-20 09:42:02 +01:00
NetworkSession::SetPostbox(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;
}
2013-12-20 08:59:46 +01:00
#ifndef ERIK
////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);
2013-12-19 15:35:49 +01:00
desc.clients[i]->CreatePlayer();
2013-12-19 12:32:23 +01:00
this->clients.Push(desc.clients[i]);
}
2013-12-20 08:59:46 +01:00
2013-12-19 12:32:23 +01:00
return true;
}
void GameSession::Frame()
{
2013-12-19 15:35:49 +01:00
}
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)
{
2013-12-20 09:42:02 +01:00
if( ProtocolIsGameplay(p[protocol_INDEX_ID].value.netShort) )
{
2013-12-20 09:42:02 +01:00
switch (p[protocol_INDEX_ID].value.netShort)
2013-12-19 12:32:23 +01:00
{
2013-12-20 09:42:02 +01:00
case protocol_Gameplay_PlayerNavigation:
{
if(p[1].value.netBool) //bool bForward;
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
//Oyster::Math::Float4x4 p;
//Protocol_ObjectPosition op(c.GetPlayer()->GetRigidBody()->GetOrientation(p));
//op.object_ID = c.GetPlayer()->GetID();
//this->Send(*op.GetProtocol());
2013-12-20 09:42:02 +01:00
}
break;
case protocol_Gameplay_PlayerMouseMovement:
2013-12-20 09:42:02 +01:00
break;
case protocol_Gameplay_PlayerPosition:
2013-12-19 12:32:23 +01:00
2013-12-20 09:42:02 +01:00
break;
case protocol_Gameplay_CreateObject:
break;
case protocol_Gameplay_ObjectPosition:
break;
}
}
2013-12-20 09:42:02 +01:00
else if(ProtocolIsGeneral(p[protocol_INDEX_ID].value.netShort) )
{
2013-12-12 09:33:59 +01:00
2013-12-20 09:42:02 +01:00
}
}
2013-12-20 08:59:46 +01:00
#else
#include "DynamicObject.h"
//#include "CollisionManager.h"
//#include "GameLogicStates.h"
//#include <GameProtocols.h>
/*
using namespace GameLogic;
2013-12-19 12:32:23 +01:00
//VARIABLES GOES HERE
2013-12-20 08:59:46 +01:00
DynamicObject* objectBox;
bool GameSession::Init(GameSessionDescription& desc)
{
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]);
}
CollisionManager::BoxCollision(0,0);
objectBox = new DynamicObject(CollisionManager::BoxCollision, OBJECT_TYPE::OBJECT_TYPE_BOX);
Protocol_CreateObject objectCreation;
objectCreation.object_ID = objectBox->GetID();
objectCreation.path = "crate";
Oyster::Math::Float4x4 worldMat = objectBox->GetRigidBody()->GetOrientation();
for (int i = 0; i < 16; i++)
{
objectCreation.worldMatrix[i] = worldMat[i];
}
for (int i = 0; i < clients.Size(); i++)
{
clients[i]->NetClient_Object()->Send(objectCreation);
}
return true;
}
void GameSession::Frame()
{
}
void GameSession::ParseEvents()
{
if(this->box && !this->box->IsEmpty())
{
NetEvent &e = this->box->Fetch();
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
ParseProtocol(e.protocol, *e.reciever);
}
}
void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c)
{
switch (p[0].value.netShort)
{
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:
break;
case protocol_Gamplay_PlayerPosition:
break;
case protocol_Gamplay_CreateObject:
break;
case protocol_Gamplay_ObjectPosition:
break;
}
}
*/
2013-12-19 12:32:23 +01:00
#endif
2013-12-12 09:33:59 +01:00
}//End namespace DanBias
2013-12-12 09:33:59 +01:00