Beginning to create the placeholder classes

This commit is contained in:
Kayne Ruse
2013-08-29 19:57:25 +10:00
parent d5f7363c33
commit b675f516e7
13 changed files with 135 additions and 50 deletions
+4
View File
@@ -0,0 +1,4 @@
#include "account_manager.hpp"
AccountManager AccountManager::instance;
+23
View File
@@ -0,0 +1,23 @@
#ifndef ACCOUNTMANAGER_HPP_
#define ACCOUNTMANAGER_HPP_
#include <list>
class AccountManager {
private:
AccountManager() = default;
~AccountManager() = default;
static AccountManager instance;
public:
static AccountManager* GetInstance() { return &instance; }
private:
struct AccountEntry {
int index;
};
std::list<AccountEntry> list;
};
#endif
+2 -4
View File
@@ -6,9 +6,10 @@
#include <map>
#include <string>
//The abstract base class for all rooms
class BaseRoom {
public:
BaseRoom(std::map<std::string, std::string> args);
BaseRoom() = default;
~BaseRoom() = default;
virtual void Init() = 0;
@@ -21,13 +22,10 @@ public:
MailBox* GetMailBox() { return& mailBox; }
protected:
std::map<std::string, std::string> const arguments;
MailBox mailBox;
private:
bool running = true;
};
int roomThread(void*);
#endif
+4
View File
@@ -0,0 +1,4 @@
#include "client_manager.hpp"
ClientManager ClientManager::instance;
+23
View File
@@ -0,0 +1,23 @@
#ifndef CLIENTMANAGER_HPP_
#define CLIENTMANAGER_HPP_
#include <list>
class ClientManager {
private:
ClientManager() = default;
~ClientManager() = default;
static ClientManager instance;
public:
static ClientManager* GetInstance() { return &instance; }
private:
struct ClientEntry {
int index;
};
std::list<ClientEntry> list;
};
#endif
+1 -1
View File
@@ -6,7 +6,7 @@
#include <deque>
#include <string>
//Thread safe mailbox
//Thread safe messaging system
class MailBox {
public:
MailBox();
+3 -4
View File
@@ -12,10 +12,9 @@ int main(int, char**) {
cout << "Beginning server" << endl;
#endif
try {
ServerApplication app;
app.Init();
app.Loop();
app.Quit();
ServerApplication::GetInstance()->Init();
ServerApplication::GetInstance()->Loop();
ServerApplication::GetInstance()->Quit();
}
catch(exception& e) {
cerr << "Fatal error: " << e.what() << endl;
+4
View File
@@ -0,0 +1,4 @@
#include "player_manager.hpp"
PlayerManager PlayerManager::instance;
+23
View File
@@ -0,0 +1,23 @@
#ifndef PLAYERMANAGER_HPP_
#define PLAYERMANAGER_HPP_
#include <list>
class PlayerManager {
private:
PlayerManager() = default;
~PlayerManager() = default;
static PlayerManager instance;
public:
static PlayerManager* GetInstance() { return &instance; }
private:
struct PlayerEntry {
int index;
};
std::list<PlayerEntry> list;
};
#endif
@@ -1,19 +1,11 @@
#include "base_room.hpp"
#include "SDL/SDL_thread.h"
#include "room_manager.hpp"
#include <iostream>
BaseRoom::BaseRoom(std::map<std::string, std::string> args):
arguments(args)
{
//
}
RoomManager RoomManager::instance;
int roomThread(void* ptr) {
#ifdef DEBUG
std::cout << "Opening room" << std::endl;
#endif
try {
reinterpret_cast<BaseRoom*>(ptr)->Init();
reinterpret_cast<BaseRoom*>(ptr)->Loop();
@@ -23,8 +15,7 @@ int roomThread(void* ptr) {
std::cerr << "Fatal room error: " << e.what() << std::endl;
return 1;
}
#ifdef DEBUG
std::cout << "Closing room" << std::endl;
#endif
return 0;
}
+33
View File
@@ -0,0 +1,33 @@
#ifndef ROOMMANAGER_HPP_
#define ROOMMANAGER_HPP_
#include "base_room.hpp"
#include "SDL/SDL_thread.h"
#include <list>
class RoomManager {
private:
RoomManager() = default;
~RoomManager() = default;
static RoomManager instance;
public:
static RoomManager* GetInstance() { return &instance; }
//open room
//close room
//get room
//set?
private:
struct RoomHandle {
SDL_Thread* thread = nullptr;
BaseRoom* room = nullptr;
};
std::list<RoomHandle> rooms;
};
#endif
+6 -8
View File
@@ -1,5 +1,7 @@
#include "server_application.hpp"
ServerApplication ServerApplication::instance;
ServerApplication::ServerApplication() {
//TODO
}
@@ -10,6 +12,10 @@ ServerApplication::~ServerApplication() {
void ServerApplication::Init() {
//TODO
//Init SDL
//Init lua
//Init SQL
}
void ServerApplication::Loop() {
@@ -19,11 +25,3 @@ void ServerApplication::Loop() {
void ServerApplication::Quit() {
//TODO
}
void ServerApplication::OpenRoom(std::map<std::string, std::string> args) {
//TODO
}
void ServerApplication::CloseRoom(RoomHandle roomHandle) {
//TODO
}
+6 -21
View File
@@ -1,36 +1,21 @@
#ifndef SERVERAPPLICATION_HPP_
#define SERVERAPPLICATION_HPP_
#include "base_room.hpp"
#include "SDL/SDL_thread.h"
#include <list>
#include <map>
#include <string>
struct RoomHandle {
SDL_Thread* thread = nullptr;
BaseRoom* room = nullptr;
};
//The main application class
class ServerApplication {
public:
private:
ServerApplication();
~ServerApplication();
static ServerApplication instance;
public:
static ServerApplication* GetInstance() { return &instance; }
void Init();
void Loop();
void Quit();
bool SetRunning(bool b) { return running = b; }
bool GetRunning() const { return running; }
private:
void OpenRoom(std::map<std::string, std::string>);
void CloseRoom(RoomHandle);
std::list<RoomHandle> rooms;
bool running = true;
};