Danbias/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp

136 lines
3.5 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
2014-01-28 09:00:02 +01:00
#include "..\GameSession.h"
#include "..\GameClient.h"
#include <Protocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <OysterMath.h>
2014-01-29 10:18:01 +01:00
#define NOMINMAX
#include <Windows.h>
2014-01-29 10:18:01 +01:00
#define DELTA_TIME_20 0.05f
#define DELTA_TIME_24 0.04166666666666666666666666666667f
#define DELTA_TIME_30 0.03333333333333333333333333333333f
#define DELTA_TIME_60 0.01666666666666666666666666666667f
#define DELTA_TIME_120 0.00833333333333333333333333333333f
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
2014-01-29 10:18:01 +01:00
bool GameSession::DoWork( )
{
2014-01-29 10:18:01 +01:00
if(this->isRunning)
{
2014-01-29 10:18:01 +01:00
double dt = this->timer.getElapsedSeconds();
gameInstance.SetFrameTimeLength((float)dt);
2014-01-20 15:47:52 +01:00
2014-01-29 10:18:01 +01:00
if(dt >= DELTA_TIME_20)
{
this->ProcessClients();
2014-01-29 10:18:01 +01:00
this->gameInstance.NewFrame();
2014-01-29 10:18:01 +01:00
this->timer.reset();
}
}
2014-01-29 10:18:01 +01:00
return this->isRunning;
}
2014-01-29 10:18:01 +01:00
//void GameSession::ParseEvents()
//{
// if( !this->box->IsEmpty() )
// {
// NetworkSession::NetEvent &e = this->box->Fetch();
// static int ii = 0;
// printf("%i - Message recieved! [%i]\n", ii++, e.protocol[0].value);
//
// if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
//
// if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) )
// ParseGameplayEvent(e.protocol, e.gameClient);
//
// if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) )
// ParseGeneralEvent(e.protocol, e.gameClient);
// }
//}
void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerMovement:
{
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[3].value.netBool) //bool bStrafeLeft;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
if(p[4].value.netBool) //bool bStrafeRight;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
}
break;
2014-01-29 10:18:01 +01:00
case protocol_Gameplay_PlayerLookDir:
{
2014-01-29 10:18:01 +01:00
Protocol_PlayerLook m; m = p;
//c->GetPlayer()->Rotate(m.dxMouse, m.dyMouse);
}
break;
case protocol_Gameplay_PlayerChangeWeapon:
break;
2014-01-21 14:32:42 +01:00
case protocol_Gameplay_ObjectDamage:
break;
case protocol_General_Status:
switch (p[1].value.netInt)
{
case GameLogic::Protocol_General_Status::States_disconected:
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
2014-01-29 10:18:01 +01:00
this->Detach(c->GetClient()->GetID());
break;
case GameLogic::Protocol_General_Status::States_idle:
break;
case GameLogic::Protocol_General_Status::States_ready:
break;
case GameLogic::Protocol_General_Status::States_leave:
break;
}
break;
case protocol_General_Text:
{
GameLogic::Protocol_General_Text temp(p);
printf("Message recieved from (%i):\t %s\n", c->GetID(), temp.text.c_str());
}
break;
}
}
2014-01-20 15:47:52 +01:00
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
{
movedObject->GetID();
movedObject->GetOrientation();
2014-01-20 15:47:52 +01:00
}
2014-01-29 10:18:01 +01:00
void GameSession::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
{
}
}//End namespace DanBias