Danbias/Code/Game/DanBiasServer/GameSession/GameSession.h

101 lines
3.3 KiB
C
Raw Normal View History

2014-01-07 10:26:09 +01:00
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_GAME_SESSION_H
#define DANBIASSERVER_GAME_SESSION_H
//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)
#include "..\LobbySessions\NetworkSession.h"
#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>
#include <Queue.h>
2014-01-07 10:26:09 +01:00
namespace DanBias
{
class LobbyClient;
class GameClient;
class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession
{
public:
/**
* A container to use when initiating a new session
*/
2014-01-07 10:26:09 +01:00
struct GameDescription
{
std::wstring mapName;
NetworkSession* owner;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
};
static GameSession* gameSession;
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
*/
bool Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client);
/**
* Closes the game session
* @param disconnectClients If set to true clients is dissconnected from the server, if false the clients is sent to the given owner of the session.
2014-01-07 10:26:09 +01:00
*/
void CloseSession(bool disconnectClients = false);
2014-01-07 10:26:09 +01:00
inline bool IsCreated() const { return this->isCreated; }
inline bool IsRunning() const { return this->isRunning; }
//Private member functions
2014-01-07 10:26:09 +01:00
private:
//Handles all events recieved
2014-01-07 10:26:09 +01:00
void ParseEvents();
//Handles all gameplay events
2014-01-07 10:26:09 +01:00
void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Handles all general events
2014-01-07 10:26:09 +01:00
void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Adds a client to the client list
2014-01-20 15:47:52 +01:00
void InsertClient(Utility::DynamicMemory::SmartPointer<GameClient> obj);
//Removes a client from the client list
void RemoveClient(DanBias::GameClient* obj);
//Sends a protocol ta all clients in session
2014-01-07 10:26:09 +01:00
void Send(Oyster::Network::CustomNetProtocol* p);
//Frame function, derived from IThreadObject
2014-01-07 10:26:09 +01:00
bool DoWork ( ) override;
//Sends a client to the owner, if obj is NULL then all clients is sent
void SendToOwner(DanBias::GameClient* obj);
//Do a cleanup on all the private data
void Clean();
//Update game objects if needed
void UpdateGameObjects();
2014-01-07 10:26:09 +01:00
//Private member variables
2014-01-07 10:26:09 +01:00
private:
2014-01-07 10:26:09 +01:00
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker;
2014-01-20 15:47:52 +01:00
GameLogic::GameAPI& gameInstance;
GameLogic::ILevelData *levelData;
NetworkSession* owner;
2014-01-07 10:26:09 +01:00
bool isCreated;
bool isRunning;
2014-01-20 15:47:52 +01:00
Utility::WinTimer timer;
static void ObjectMove(GameLogic::IObjectData* movedObject);
2014-01-07 10:26:09 +01:00
private:
friend class AdminInterface;
};//End GameSession
}//End namespace DanBias
#endif // !DANBIASSERVER_GAME_SESSION_H