2014-01-07 10:26:09 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef DANBIASSERVER_GAME_SESSION_H
|
|
|
|
#define DANBIASSERVER_GAME_SESSION_H
|
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
//warning C4150: deletion of pointer to incomplete type, no destructor called, because of forward decleration and the use of smartpointer.
|
2014-01-07 10:26:09 +01:00
|
|
|
#pragma warning(disable: 4150)
|
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
#include "GameClient.h"
|
2014-01-13 12:44:33 +01:00
|
|
|
#include <WinTimer.h>
|
2014-01-07 10:26:09 +01:00
|
|
|
#include <PostBox\IPostBox.h>
|
|
|
|
#include <Thread\OysterThread.h>
|
2014-01-20 15:47:52 +01:00
|
|
|
#include <GameAPI.h>
|
2014-01-15 11:03:25 +01:00
|
|
|
#include <Queue.h>
|
2014-01-28 09:00:02 +01:00
|
|
|
#include <NetworkSession.h>
|
2014-01-29 10:18:01 +01:00
|
|
|
#include <DynamicArray.h>
|
2014-01-29 15:01:14 +01:00
|
|
|
#include <Protocols.h>
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2014-01-07 10:26:09 +01:00
|
|
|
|
|
|
|
namespace DanBias
|
|
|
|
{
|
2014-01-29 10:18:01 +01:00
|
|
|
class GameSession : public Oyster::Network::NetworkSession
|
|
|
|
, public Oyster::Thread::IThreadObject
|
2014-01-07 10:26:09 +01:00
|
|
|
{
|
|
|
|
public:
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
/**
|
|
|
|
* A container to use when initiating a new session
|
|
|
|
*/
|
2014-01-07 10:26:09 +01:00
|
|
|
struct GameDescription
|
|
|
|
{
|
2014-02-18 08:55:38 +01:00
|
|
|
unsigned int maxClients;
|
2014-02-18 11:34:24 +01:00
|
|
|
std::wstring mapName;
|
|
|
|
std::wstring gameMode;
|
2014-02-18 08:55:38 +01:00
|
|
|
int gameTimeMinutes;
|
2014-01-29 10:18:01 +01:00
|
|
|
Oyster::Network::NetworkSession* owner;
|
2014-02-18 11:34:24 +01:00
|
|
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
|
2014-01-07 10:26:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
GameSession();
|
|
|
|
virtual~GameSession();
|
|
|
|
|
|
|
|
/** Initiates and creates a game session. */
|
|
|
|
bool Create(GameDescription& desc);
|
|
|
|
|
|
|
|
/** Runs the game session (ie starts the game loop). */
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
/** Join an existing/running game session
|
|
|
|
* @param client The client to attach to the session
|
|
|
|
*/
|
2014-02-18 11:34:24 +01:00
|
|
|
bool Join(gClient client);
|
|
|
|
|
|
|
|
//void CloseSession( bool dissconnectClients ) override;
|
2014-01-07 10:26:09 +01:00
|
|
|
|
|
|
|
inline bool IsCreated() const { return this->isCreated; }
|
|
|
|
inline bool IsRunning() const { return this->isRunning; }
|
2014-02-18 11:34:24 +01:00
|
|
|
operator bool() { return (this->isCreated && this->isRunning); }
|
2014-01-07 10:26:09 +01:00
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
//Private member functions
|
2014-01-07 10:26:09 +01:00
|
|
|
private:
|
2014-02-18 08:55:38 +01:00
|
|
|
// Client event callback function
|
2014-01-29 10:18:01 +01:00
|
|
|
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
2014-02-18 11:34:24 +01:00
|
|
|
void ProcessClients() override;
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2014-02-18 08:55:38 +01:00
|
|
|
//Sends a client to the owner, if param is NULL then all clients is sent
|
2014-01-13 12:44:33 +01:00
|
|
|
void SendToOwner(DanBias::GameClient* obj);
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2014-02-04 16:07:10 +01:00
|
|
|
//Derived from IThreadObject
|
2014-02-18 08:55:38 +01:00
|
|
|
void ThreadEntry( ) override;
|
2014-01-29 10:18:01 +01:00
|
|
|
bool DoWork ( ) override;
|
2014-01-29 15:01:14 +01:00
|
|
|
|
2014-02-04 16:07:10 +01:00
|
|
|
|
2014-01-29 15:01:14 +01:00
|
|
|
private:
|
2014-02-04 16:07:10 +01:00
|
|
|
void ParseProtocol ( Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c );
|
2014-01-29 15:01:14 +01:00
|
|
|
|
2014-02-11 10:21:47 +01:00
|
|
|
void Gameplay_PlayerMovementRight ( DanBias::GameClient* c );
|
|
|
|
void Gameplay_PlayerMovementLeft ( DanBias::GameClient* c );
|
|
|
|
void Gameplay_PlayerMovementBack ( DanBias::GameClient* c );
|
|
|
|
void Gameplay_PlayerMovementForth ( DanBias::GameClient* c );
|
|
|
|
void Gameplay_PlayerJump ( DanBias::GameClient* c );
|
2014-01-29 15:01:14 +01:00
|
|
|
void Gameplay_PlayerLookDir ( GameLogic::Protocol_PlayerLook& p, DanBias::GameClient* c );
|
|
|
|
void Gameplay_PlayerChangeWeapon ( GameLogic::Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c );
|
|
|
|
void Gameplay_PlayerShot ( GameLogic::Protocol_PlayerShot& p, DanBias::GameClient* c );
|
|
|
|
void Gameplay_ObjectPickup ( GameLogic::Protocol_ObjectPickup& p, DanBias::GameClient* c );
|
|
|
|
void Gameplay_ObjectDamage ( GameLogic::Protocol_ObjectDamage& p, DanBias::GameClient* c );
|
|
|
|
void Gameplay_ObjectPosition ( GameLogic::Protocol_ObjectPosition& p, DanBias::GameClient* c );
|
|
|
|
void Gameplay_ObjectEnabled ( GameLogic::Protocol_ObjectEnable& p, DanBias::GameClient* c );
|
|
|
|
void Gameplay_ObjectDisabled ( GameLogic::Protocol_ObjectDisable& p, DanBias::GameClient* c );
|
|
|
|
void Gameplay_ObjectCreate ( GameLogic::Protocol_ObjectCreate& p, DanBias::GameClient* c );
|
|
|
|
void General_Status ( GameLogic::Protocol_General_Status& p, DanBias::GameClient* c );
|
|
|
|
void General_Text ( GameLogic::Protocol_General_Text& p, DanBias::GameClient* c );
|
2014-02-15 22:33:40 +01:00
|
|
|
|
2014-01-30 00:19:00 +01:00
|
|
|
//Callback method recieving from gamelogic
|
2014-02-04 16:07:10 +01:00
|
|
|
static void ObjectMove ( GameLogic::IObjectData* movedObject );
|
2014-02-09 16:42:26 +01:00
|
|
|
static void ObjectDisabled ( GameLogic::IObjectData* movedObject, float seconds );
|
2014-01-30 00:19:00 +01:00
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
//Private member variables
|
2014-01-07 10:26:09 +01:00
|
|
|
private:
|
2014-02-18 11:34:24 +01:00
|
|
|
Utility::DynamicMemory::DynamicArray<gClient> gClients;
|
|
|
|
gClient sessionOwner;
|
2014-01-07 10:26:09 +01:00
|
|
|
Oyster::Thread::OysterThread worker;
|
2014-01-20 15:47:52 +01:00
|
|
|
GameLogic::GameAPI& gameInstance;
|
|
|
|
GameLogic::ILevelData *levelData;
|
2014-01-13 12:44:33 +01:00
|
|
|
NetworkSession* owner;
|
2014-01-07 10:26:09 +01:00
|
|
|
bool isCreated;
|
|
|
|
bool isRunning;
|
2014-02-09 16:42:26 +01:00
|
|
|
float logicFrameTime;
|
|
|
|
float networkFrameTime;
|
2014-01-31 22:52:52 +01:00
|
|
|
Utility::WinTimer logicTimer;
|
|
|
|
Utility::WinTimer networkTimer;
|
2014-01-30 00:19:00 +01:00
|
|
|
GameDescription description;
|
2014-01-20 15:47:52 +01:00
|
|
|
|
2014-01-30 00:19:00 +01:00
|
|
|
//TODO: Remove this uggly hax
|
|
|
|
static GameSession* gameSession;
|
2014-01-07 10:26:09 +01:00
|
|
|
|
2014-02-18 11:34:24 +01:00
|
|
|
|
2014-01-07 10:26:09 +01:00
|
|
|
};//End GameSession
|
|
|
|
}//End namespace DanBias
|
|
|
|
#endif // !DANBIASSERVER_GAME_SESSION_H
|