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:
@@ -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}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user