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:
@@ -46,7 +46,6 @@ int main(int argc, char* argv[]) {
|
|||||||
MonsterManager::CreateSingleton();
|
MonsterManager::CreateSingleton();
|
||||||
RoomManager::CreateSingleton();
|
RoomManager::CreateSingleton();
|
||||||
UDPNetworkUtility::CreateSingleton();
|
UDPNetworkUtility::CreateSingleton();
|
||||||
WaypointManager::CreateSingleton();
|
|
||||||
|
|
||||||
//call the server's routines
|
//call the server's routines
|
||||||
ServerApplication::CreateSingleton();
|
ServerApplication::CreateSingleton();
|
||||||
@@ -66,7 +65,6 @@ int main(int argc, char* argv[]) {
|
|||||||
MonsterManager::DeleteSingleton();
|
MonsterManager::DeleteSingleton();
|
||||||
RoomManager::DeleteSingleton();
|
RoomManager::DeleteSingleton();
|
||||||
UDPNetworkUtility::DeleteSingleton();
|
UDPNetworkUtility::DeleteSingleton();
|
||||||
WaypointManager::DeleteSingleton();
|
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
#include "client_manager.hpp"
|
#include "client_manager.hpp"
|
||||||
#include "monster_manager.hpp"
|
#include "monster_manager.hpp"
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
#include "waypoint_manager.hpp"
|
|
||||||
|
|
||||||
//utilities
|
//utilities
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
@@ -120,7 +119,6 @@ private:
|
|||||||
ClientManager& clientMgr = ClientManager::GetSingleton();
|
ClientManager& clientMgr = ClientManager::GetSingleton();
|
||||||
MonsterManager& monsterMgr = MonsterManager::GetSingleton();
|
MonsterManager& monsterMgr = MonsterManager::GetSingleton();
|
||||||
RoomManager& roomMgr = RoomManager::GetSingleton();
|
RoomManager& roomMgr = RoomManager::GetSingleton();
|
||||||
WaypointManager& waypointMgr = WaypointManager::GetSingleton();
|
|
||||||
|
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ void ServerApplication::Init(int argc, char* argv[]) {
|
|||||||
characterMgr.SetDatabase(database);
|
characterMgr.SetDatabase(database);
|
||||||
|
|
||||||
roomMgr.SetLuaState(luaState);
|
roomMgr.SetLuaState(luaState);
|
||||||
waypointMgr.SetLuaState(luaState);
|
|
||||||
|
|
||||||
std::cout << "Internal managers initialized" << std::endl;
|
std::cout << "Internal managers initialized" << std::endl;
|
||||||
|
|
||||||
@@ -204,7 +203,6 @@ void ServerApplication::Quit() {
|
|||||||
clientMgr.UnloadAll();
|
clientMgr.UnloadAll();
|
||||||
monsterMgr.UnloadAll();
|
monsterMgr.UnloadAll();
|
||||||
roomMgr.UnloadAll();
|
roomMgr.UnloadAll();
|
||||||
waypointMgr.UnloadAll();
|
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
lua_close(luaState);
|
lua_close(luaState);
|
||||||
|
|||||||
@@ -23,8 +23,100 @@
|
|||||||
|
|
||||||
#include "waypoint_data.hpp"
|
#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[] = {
|
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}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -34,21 +34,21 @@ public:
|
|||||||
WaypointData() = default;
|
WaypointData() = default;
|
||||||
~WaypointData() = default;
|
~WaypointData() = default;
|
||||||
|
|
||||||
int SetTriggerReference(int i);
|
Vector2 SetOrigin(Vector2 v);
|
||||||
int GetTriggerReference();
|
Vector2 GetOrigin();
|
||||||
|
|
||||||
BoundingBox SetBoundingBox(BoundingBox b);
|
BoundingBox SetBoundingBox(BoundingBox b);
|
||||||
BoundingBox GetBoundingBox();
|
BoundingBox GetBoundingBox();
|
||||||
|
|
||||||
Vector2 SetOrigin(Vector2 v);
|
int SetTriggerReference(int i);
|
||||||
Vector2 GetOrigin();
|
int GetTriggerReference();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class WaypointManager;
|
friend class WaypointManager;
|
||||||
|
|
||||||
int triggerRef = LUA_NOREF;
|
|
||||||
BoundingBox bounds;
|
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
|
BoundingBox bounds;
|
||||||
|
int triggerRef = LUA_NOREF;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -21,34 +21,59 @@
|
|||||||
*/
|
*/
|
||||||
#include "waypoint_manager.hpp"
|
#include "waypoint_manager.hpp"
|
||||||
|
|
||||||
int WaypointManager::Create() {
|
int WaypointManager::Create(Vector2 origin, BoundingBox bounds) {
|
||||||
//TODO
|
//implicitly creates the element
|
||||||
|
WaypointData& waypointData = elementMap[counter];
|
||||||
|
|
||||||
|
waypointData.origin = origin;
|
||||||
|
waypointData.bounds = bounds;
|
||||||
|
|
||||||
|
return counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointManager::Unload(int uid) {
|
void WaypointManager::Unload(int uid) {
|
||||||
//TODO
|
elementMap.erase(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointManager::UnloadAll() {
|
void WaypointManager::UnloadAll() {
|
||||||
//TODO
|
elementMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointManager::UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn) {
|
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) {
|
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() {
|
int WaypointManager::GetLoadedCount() {
|
||||||
//TODO
|
return elementMap.size();
|
||||||
}
|
|
||||||
|
|
||||||
int WaypointManager::GetTotalCount() {
|
|
||||||
//TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, WaypointData>* WaypointManager::GetContainer() {
|
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;
|
||||||
}
|
}
|
||||||
@@ -22,9 +22,9 @@
|
|||||||
#ifndef WAYPOINTMANAGER_HPP_
|
#ifndef WAYPOINTMANAGER_HPP_
|
||||||
#define WAYPOINTMANAGER_HPP_
|
#define WAYPOINTMANAGER_HPP_
|
||||||
|
|
||||||
#include "waypoint_data.hpp"
|
#include "bounding_box.hpp"
|
||||||
#include "singleton.hpp"
|
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
|
#include "waypoint_data.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
|
||||||
@@ -32,11 +32,13 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//TODO: should waypoints be managed on a per-room basis?
|
class WaypointManager {
|
||||||
class WaypointManager: public Singleton<WaypointManager> {
|
|
||||||
public:
|
public:
|
||||||
|
WaypointManager() = default;
|
||||||
|
~WaypointManager() = default;
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create();
|
int Create(Vector2 origin, BoundingBox bounds);
|
||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
@@ -45,19 +47,13 @@ public:
|
|||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
WaypointData* Get(int uid);
|
WaypointData* Get(int uid);
|
||||||
int GetLoadedCount();
|
int GetLoadedCount();
|
||||||
int GetTotalCount();
|
|
||||||
std::map<int, WaypointData>* GetContainer();
|
std::map<int, WaypointData>* GetContainer();
|
||||||
|
|
||||||
//hooks
|
//hooks
|
||||||
lua_State* SetLuaState(lua_State* L) { return lua = L; }
|
lua_State* SetLuaState(lua_State* L);
|
||||||
lua_State* GetLuaState() { return lua; }
|
lua_State* GetLuaState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend Singleton<WaypointManager>;
|
|
||||||
|
|
||||||
WaypointManager() = default;
|
|
||||||
~WaypointManager() = default;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
std::map<int, WaypointData> elementMap;
|
std::map<int, WaypointData> elementMap;
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ TODO: Make a way for the server owner to control the server directly
|
|||||||
TODO: The TileSheet class should implement the surface itself
|
TODO: The TileSheet class should implement the surface itself
|
||||||
TODO: Time delay for requesting region packets
|
TODO: Time delay for requesting region packets
|
||||||
TODO: A proper logging system
|
TODO: A proper logging system
|
||||||
|
TODO: Fix the const-ness of accessors
|
||||||
Reference in New Issue
Block a user