WaypointManager is no longer a Singleton, wrote waypoint API outline

I'm planning on giving each room it's own waypoint manager, so it can
compare it's waypoints against the characters in that room alone. If it
turns out to be a good pattern, I'll do thae same for monsters.
This commit is contained in:
Kayne Ruse
2015-01-09 13:21:09 +11:00
parent be67906218
commit b391dde089
8 changed files with 146 additions and 38 deletions
-2
View File
@@ -46,7 +46,6 @@ int main(int argc, char* argv[]) {
MonsterManager::CreateSingleton();
RoomManager::CreateSingleton();
UDPNetworkUtility::CreateSingleton();
WaypointManager::CreateSingleton();
//call the server's routines
ServerApplication::CreateSingleton();
@@ -66,7 +65,6 @@ int main(int argc, char* argv[]) {
MonsterManager::DeleteSingleton();
RoomManager::DeleteSingleton();
UDPNetworkUtility::DeleteSingleton();
WaypointManager::DeleteSingleton();
}
catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl;
-2
View File
@@ -28,7 +28,6 @@
#include "client_manager.hpp"
#include "monster_manager.hpp"
#include "room_manager.hpp"
#include "waypoint_manager.hpp"
//utilities
#include "config_utility.hpp"
@@ -120,7 +119,6 @@ private:
ClientManager& clientMgr = ClientManager::GetSingleton();
MonsterManager& monsterMgr = MonsterManager::GetSingleton();
RoomManager& roomMgr = RoomManager::GetSingleton();
WaypointManager& waypointMgr = WaypointManager::GetSingleton();
ConfigUtility& config = ConfigUtility::GetSingleton();
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
-2
View File
@@ -105,7 +105,6 @@ void ServerApplication::Init(int argc, char* argv[]) {
characterMgr.SetDatabase(database);
roomMgr.SetLuaState(luaState);
waypointMgr.SetLuaState(luaState);
std::cout << "Internal managers initialized" << std::endl;
@@ -204,7 +203,6 @@ void ServerApplication::Quit() {
clientMgr.UnloadAll();
monsterMgr.UnloadAll();
roomMgr.UnloadAll();
waypointMgr.UnloadAll();
//APIs
lua_close(luaState);
+93 -1
View File
@@ -23,8 +23,100 @@
#include "waypoint_data.hpp"
//TODO: Can I alias the entity API for this?
//origin
static int setOriginX(lua_State* L) {
//TODO
return 0;
}
static int setOriginY(lua_State* L) {
//TODO
return 0;
}
static int getOriginX(lua_State* L) {
//TODO
return 0;
}
static int getOriginY(lua_State* L) {
//TODO
return 0;
}
//bounds
static int setBoundingBoxX(lua_State* L) {
//TODO
return 0;
}
static int setBoundingBoxY(lua_State* L) {
//TODO
return 0;
}
static int setBoundingBoxW(lua_State* L) {
//TODO
return 0;
}
static int setBoundingBoxH(lua_State* L) {
//TODO
return 0;
}
static int getBoundingBoxX(lua_State* L) {
//TODO
return 0;
}
static int getBoundingBoxY(lua_State* L) {
//TODO
return 0;
}
static int getBoundingBoxW(lua_State* L) {
//TODO
return 0;
}
static int getBoundingBoxH(lua_State* L) {
//TODO
return 0;
}
//triggers
static int setTriggerReference(lua_State* L) {
//TODO
return 0;
}
static int getTriggerReference(lua_State* L) {
//TODO
return 0;
}
static const luaL_Reg waypointLib[] = {
//origin
{"SetOriginX",setOriginX},
{"SetOriginY",setOriginY},
{"GetOriginX",getOriginX},
{"GetOriginY",getOriginY},
//bounds
{"SetBoundsX",setBoundingBoxX},
{"SetBoundsY",setBoundingBoxY},
{"SetBoundsW",setBoundingBoxW},
{"SetBoundsH",setBoundingBoxH},
{"GetBoundsX",getBoundingBoxX},
{"GetBoundsY",getBoundingBoxY},
{"GetBoundsW",getBoundingBoxW},
{"GetBoundsH",getBoundingBoxH},
//triggers
{"SetTrigger",setTriggerReference},
{"GetTrigger",getTriggerReference},
{nullptr, nullptr}
};
+6 -6
View File
@@ -34,21 +34,21 @@ public:
WaypointData() = default;
~WaypointData() = default;
int SetTriggerReference(int i);
int GetTriggerReference();
Vector2 SetOrigin(Vector2 v);
Vector2 GetOrigin();
BoundingBox SetBoundingBox(BoundingBox b);
BoundingBox GetBoundingBox();
Vector2 SetOrigin(Vector2 v);
Vector2 GetOrigin();
int SetTriggerReference(int i);
int GetTriggerReference();
private:
friend class WaypointManager;
int triggerRef = LUA_NOREF;
BoundingBox bounds;
Vector2 origin;
BoundingBox bounds;
int triggerRef = LUA_NOREF;
};
#endif
+37 -12
View File
@@ -21,34 +21,59 @@
*/
#include "waypoint_manager.hpp"
int WaypointManager::Create() {
//TODO
int WaypointManager::Create(Vector2 origin, BoundingBox bounds) {
//implicitly creates the element
WaypointData& waypointData = elementMap[counter];
waypointData.origin = origin;
waypointData.bounds = bounds;
return counter++;
}
void WaypointManager::Unload(int uid) {
//TODO
elementMap.erase(uid);
}
void WaypointManager::UnloadAll() {
//TODO
elementMap.clear();
}
void WaypointManager::UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn) {
//TODO
std::map<int, WaypointData>::iterator it = elementMap.begin();
while (it != elementMap.end()) {
if (fn(*it)) {
it = elementMap.erase(it);
}
else {
++it;
}
}
}
WaypointData* WaypointManager::Get(int uid) {
//TODO
std::map<int, WaypointData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) {
return nullptr;
}
return &it->second;
}
int WaypointManager::GetLoadedCount() {
//TODO
}
int WaypointManager::GetTotalCount() {
//TODO
return elementMap.size();
}
std::map<int, WaypointData>* WaypointManager::GetContainer() {
//TODO
return &elementMap;
}
//hooks
lua_State* WaypointManager::SetLuaState(lua_State* L) {
return lua = L;
}
lua_State* WaypointManager::GetLuaState() {
return lua;
}
+9 -13
View File
@@ -22,9 +22,9 @@
#ifndef WAYPOINTMANAGER_HPP_
#define WAYPOINTMANAGER_HPP_
#include "waypoint_data.hpp"
#include "singleton.hpp"
#include "bounding_box.hpp"
#include "vector2.hpp"
#include "waypoint_data.hpp"
#include "lua.hpp"
@@ -32,11 +32,13 @@
#include <map>
#include <string>
//TODO: should waypoints be managed on a per-room basis?
class WaypointManager: public Singleton<WaypointManager> {
class WaypointManager {
public:
WaypointManager() = default;
~WaypointManager() = default;
//common public methods
int Create();
int Create(Vector2 origin, BoundingBox bounds);
void Unload(int uid);
void UnloadAll();
@@ -45,19 +47,13 @@ public:
//accessors & mutators
WaypointData* Get(int uid);
int GetLoadedCount();
int GetTotalCount();
std::map<int, WaypointData>* GetContainer();
//hooks
lua_State* SetLuaState(lua_State* L) { return lua = L; }
lua_State* GetLuaState() { return lua; }
lua_State* SetLuaState(lua_State* L);
lua_State* GetLuaState();
private:
friend Singleton<WaypointManager>;
WaypointManager() = default;
~WaypointManager() = default;
//members
std::map<int, WaypointData> elementMap;
lua_State* lua = nullptr;