Removed ManagerInterface, it was a bad idea
This commit is contained in:
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "account_data.hpp"
|
#include "account_data.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
#include "manager_interface.hpp"
|
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
#include "sqlite3/sqlite3.h"
|
#include "sqlite3/sqlite3.h"
|
||||||
@@ -35,26 +34,23 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class AccountManager:
|
class AccountManager: public Singleton<AccountManager> {
|
||||||
public Singleton<AccountManager>,
|
|
||||||
public ManagerInterface<AccountData, std::string, int>
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create(std::string username, int clientIndex) override;
|
int Create(std::string username, int clientIndex);
|
||||||
int Load(std::string username, int clientIndex) override;
|
int Load(std::string username, int clientIndex);
|
||||||
int Save(int uid) override;
|
int Save(int uid);
|
||||||
void Unload(int uid) override;
|
void Unload(int uid);
|
||||||
void Delete(int uid) override;
|
void Delete(int uid);
|
||||||
|
|
||||||
void UnloadAll() override;
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, AccountData>)> fn) override;
|
void UnloadIf(std::function<bool(std::pair<const int, AccountData>)> fn);
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
AccountData* Get(int uid) override;
|
AccountData* Get(int uid);
|
||||||
int GetLoadedCount() override;
|
int GetLoadedCount();
|
||||||
int GetTotalCount() override;
|
int GetTotalCount();
|
||||||
std::map<int, AccountData>* GetContainer() override;
|
std::map<int, AccountData>* GetContainer();
|
||||||
|
|
||||||
sqlite3* SetDatabase(sqlite3* db);
|
sqlite3* SetDatabase(sqlite3* db);
|
||||||
sqlite3* GetDatabase();
|
sqlite3* GetDatabase();
|
||||||
@@ -65,6 +61,8 @@ private:
|
|||||||
AccountManager() = default;
|
AccountManager() = default;
|
||||||
~AccountManager() = default;
|
~AccountManager() = default;
|
||||||
|
|
||||||
|
//members
|
||||||
|
std::map<int, AccountData> elementMap;
|
||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "character_data.hpp"
|
#include "character_data.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
#include "manager_interface.hpp"
|
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
#include "sqlite3/sqlite3.h"
|
#include "sqlite3/sqlite3.h"
|
||||||
@@ -35,26 +34,23 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class CharacterManager:
|
class CharacterManager: public Singleton<CharacterManager> {
|
||||||
public Singleton<CharacterManager>,
|
|
||||||
public ManagerInterface<CharacterData, int, std::string, std::string>
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create(int owner, std::string handle, std::string avatar) override;
|
int Create(int owner, std::string handle, std::string avatar);
|
||||||
int Load(int owner, std::string handle, std::string avatar) override;
|
int Load(int owner, std::string handle, std::string avatar);
|
||||||
int Save(int uid) override;
|
int Save(int uid);
|
||||||
void Unload(int uid) override;
|
void Unload(int uid);
|
||||||
void Delete(int uid) override;
|
void Delete(int uid);
|
||||||
|
|
||||||
void UnloadAll() override;
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, CharacterData>)> fn) override;
|
void UnloadIf(std::function<bool(std::pair<const int, CharacterData>)> fn);
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
CharacterData* Get(int uid) override;
|
CharacterData* Get(int uid);
|
||||||
int GetLoadedCount() override;
|
int GetLoadedCount();
|
||||||
int GetTotalCount() override;
|
int GetTotalCount();
|
||||||
std::map<int, CharacterData>* GetContainer() override;
|
std::map<int, CharacterData>* GetContainer();
|
||||||
|
|
||||||
sqlite3* SetDatabase(sqlite3* db);
|
sqlite3* SetDatabase(sqlite3* db);
|
||||||
sqlite3* GetDatabase();
|
sqlite3* GetDatabase();
|
||||||
@@ -65,6 +61,8 @@ private:
|
|||||||
CharacterManager() = default;
|
CharacterManager() = default;
|
||||||
~CharacterManager() = default;
|
~CharacterManager() = default;
|
||||||
|
|
||||||
|
//members
|
||||||
|
std::map<int, CharacterData> elementMap;
|
||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,35 +23,32 @@
|
|||||||
#define CLIENTMANAGER_HPP_
|
#define CLIENTMANAGER_HPP_
|
||||||
|
|
||||||
#include "client_data.hpp"
|
#include "client_data.hpp"
|
||||||
#include "manager_interface.hpp"
|
|
||||||
#include "server_packet.hpp"
|
#include "server_packet.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include "SDL/SDL_net.h"
|
#include "SDL/SDL_net.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class ClientManager:
|
class ClientManager: public Singleton<ClientManager> {
|
||||||
public Singleton<ClientManager>,
|
|
||||||
public ManagerInterface<ClientData, IPaddress>
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
//methods
|
//methods
|
||||||
int CheckConnections();
|
int CheckConnections();
|
||||||
void HandlePong(ServerPacket* const argPacket);
|
void HandlePong(ServerPacket* const argPacket);
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create(IPaddress) override;
|
int Create(IPaddress);
|
||||||
void Unload(int uid) override;
|
void Unload(int uid);
|
||||||
|
|
||||||
void UnloadAll() override;
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, ClientData>)> fn) override;
|
void UnloadIf(std::function<bool(std::pair<const int, ClientData>)> fn);
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
ClientData* Get(int uid) override;
|
ClientData* Get(int uid);
|
||||||
int GetLoadedCount() override;
|
int GetLoadedCount();
|
||||||
int GetTotalCount() override;
|
int GetTotalCount();
|
||||||
std::map<int, ClientData>* GetContainer() override;
|
std::map<int, ClientData>* GetContainer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend Singleton<ClientManager>;
|
friend Singleton<ClientManager>;
|
||||||
@@ -59,11 +56,8 @@ private:
|
|||||||
ClientManager() = default;
|
ClientManager() = default;
|
||||||
~ClientManager() = default;
|
~ClientManager() = default;
|
||||||
|
|
||||||
//EMPTY
|
//members
|
||||||
int Load(IPaddress) override { return -1; }
|
std::map<int, ClientData> elementMap;
|
||||||
int Save(int uid) override { return -1; }
|
|
||||||
void Delete(int uid) override { return; }
|
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
#ifndef MONSTERMANAGER_HPP_
|
#ifndef MONSTERMANAGER_HPP_
|
||||||
#define MONSTERMANAGER_HPP_
|
#define MONSTERMANAGER_HPP_
|
||||||
|
|
||||||
#include "manager_interface.hpp"
|
|
||||||
#include "monster_data.hpp"
|
#include "monster_data.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
@@ -35,28 +34,26 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class MonsterManager:
|
class MonsterManager: public Singleton<MonsterManager> {
|
||||||
public Singleton<MonsterManager>,
|
|
||||||
public ManagerInterface<MonsterData, std::string>
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create(std::string) override;
|
int Create(std::string);
|
||||||
int Load(std::string) override;
|
int Load(std::string);
|
||||||
int Save(int uid) override;
|
int Save(int uid);
|
||||||
void Unload(int uid) override;
|
void Unload(int uid);
|
||||||
void Delete(int uid) override;
|
void Delete(int uid);
|
||||||
|
|
||||||
void UnloadAll() override;
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, MonsterData>)> fn) override;
|
void UnloadIf(std::function<bool(std::pair<const int, MonsterData>)> fn);
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
MonsterData* Get(int uid) override;
|
MonsterData* Get(int uid);
|
||||||
int GetLoadedCount() override;
|
int GetLoadedCount();
|
||||||
int GetTotalCount() override;
|
int GetTotalCount();
|
||||||
std::map<int, MonsterData>* GetContainer() override;
|
std::map<int, MonsterData>* GetContainer();
|
||||||
|
|
||||||
//hooks
|
//hooks
|
||||||
sqlite3* SetDatabase(sqlite3* db);
|
sqlite3* SetDatabase(sqlite3* db);
|
||||||
@@ -70,6 +67,8 @@ private:
|
|||||||
MonsterManager() = default;
|
MonsterManager() = default;
|
||||||
~MonsterManager() = default;
|
~MonsterManager() = default;
|
||||||
|
|
||||||
|
//members
|
||||||
|
std::map<int, MonsterData> elementMap;
|
||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
#include "manager_interface.hpp"
|
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
@@ -32,23 +31,23 @@
|
|||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class RoomManager:
|
#include <functional>
|
||||||
public Singleton<RoomManager>,
|
#include <map>
|
||||||
public ManagerInterface<RoomData, std::string>
|
|
||||||
{
|
class RoomManager: public Singleton<RoomManager> {
|
||||||
public:
|
public:
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create(std::string) override;
|
int Create(std::string);
|
||||||
void Unload(int uid) override;
|
void Unload(int uid);
|
||||||
|
|
||||||
void UnloadAll() override;
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int,RoomData>)> fn) override;
|
void UnloadIf(std::function<bool(std::pair<const int,RoomData>)> fn);
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
RoomData* Get(int uid) override;
|
RoomData* Get(int uid);
|
||||||
int GetLoadedCount() override;
|
int GetLoadedCount();
|
||||||
int GetTotalCount() override;
|
int GetTotalCount();
|
||||||
std::map<int, RoomData>* GetContainer() override;
|
std::map<int, RoomData>* GetContainer();
|
||||||
|
|
||||||
//hooks
|
//hooks
|
||||||
lua_State* SetLuaState(lua_State* L) { return lua = L; }
|
lua_State* SetLuaState(lua_State* L) { return lua = L; }
|
||||||
@@ -60,10 +59,8 @@ private:
|
|||||||
RoomManager() = default;
|
RoomManager() = default;
|
||||||
~RoomManager() = default;
|
~RoomManager() = default;
|
||||||
|
|
||||||
int Load(std::string) override { return -1; }
|
//members
|
||||||
int Save(int uid) override { return -1; }
|
std::map<int, RoomData> elementMap;
|
||||||
void Delete(int uid) override { }
|
|
||||||
|
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#ifndef MANAGERINTERFACE_HPP_
|
|
||||||
#define MANAGERINTERFACE_HPP_
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
template<typename T, typename... Arguments>
|
|
||||||
class ManagerInterface {
|
|
||||||
public:
|
|
||||||
//common public methods
|
|
||||||
virtual int Create(Arguments... parameters) = 0;
|
|
||||||
virtual int Load(Arguments... parameters) = 0;
|
|
||||||
virtual int Save(int uid) = 0;
|
|
||||||
virtual void Unload(int uid) = 0;
|
|
||||||
virtual void Delete(int uid) = 0;
|
|
||||||
|
|
||||||
virtual void UnloadAll() = 0;
|
|
||||||
virtual void UnloadIf(std::function<bool(std::pair<const int, T>)> fn) = 0;
|
|
||||||
|
|
||||||
//accessors & mutators
|
|
||||||
virtual T* Get(int uid) = 0;
|
|
||||||
virtual int GetLoadedCount() = 0;
|
|
||||||
virtual int GetTotalCount() = 0; //can be an alias of GetLoadedCount()
|
|
||||||
virtual std::map<int, T>* GetContainer() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ManagerInterface() = default;
|
|
||||||
~ManagerInterface() = default;
|
|
||||||
|
|
||||||
//members
|
|
||||||
std::map<int, T> elementMap;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -23,39 +23,39 @@
|
|||||||
#define WAYPOINTMANAGER_HPP_
|
#define WAYPOINTMANAGER_HPP_
|
||||||
|
|
||||||
#include "waypoint_data.hpp"
|
#include "waypoint_data.hpp"
|
||||||
#include "manager_interface.hpp"
|
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class WaypointManager:
|
class WaypointManager: public Singleton<WaypointManager> {
|
||||||
public Singleton<WaypointManager>,
|
|
||||||
public ManagerInterface<WaypointData>
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create() override;
|
int Create();
|
||||||
int Load() override;
|
int Load();
|
||||||
int Save(int uid) override;
|
int Save(int uid);
|
||||||
void Unload(int uid) override;
|
void Unload(int uid);
|
||||||
void Delete(int uid) override;
|
void Delete(int uid);
|
||||||
|
|
||||||
void UnloadAll() override;
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, WaypointData>)> fn) override;
|
void UnloadIf(std::function<bool(std::pair<const int, WaypointData>)> fn);
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
WaypointData* Get(int uid) override;
|
WaypointData* Get(int uid);
|
||||||
int GetLoadedCount() override;
|
int GetLoadedCount();
|
||||||
int GetTotalCount() override;
|
int GetTotalCount();
|
||||||
std::map<int, WaypointData>* GetContainer() override;
|
std::map<int, WaypointData>* GetContainer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend Singleton<WaypointManager>;
|
friend Singleton<WaypointManager>;
|
||||||
|
|
||||||
WaypointManager() = default;
|
WaypointManager() = default;
|
||||||
~WaypointManager() = default;
|
~WaypointManager() = default;
|
||||||
|
|
||||||
|
//members
|
||||||
|
std::map<int, WaypointData> elementMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user