Added PushEntity() & PopEntity() to RoomManager
Calling them from server_character_methods.cpp.
This commit is contained in:
@@ -56,8 +56,6 @@ static int getPager(lua_State* L) {
|
||||
static int initialize(lua_State* L) {
|
||||
//set the members of the given room
|
||||
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
room->SetName(lua_tostring(L, 2));
|
||||
room->SetTileset(lua_tostring(L, 3));
|
||||
|
||||
//set the refs of these parameters (backwards, since it pops from the top of the stack)
|
||||
room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "room_api.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
//-------------------------
|
||||
//public access methods
|
||||
@@ -41,6 +42,32 @@ int RoomManager::Create(std::string roomName, std::string tileset) {
|
||||
return counter++;
|
||||
}
|
||||
|
||||
void RoomManager::PushEntity(Entity* entity) {
|
||||
std::map<int, RoomData>::iterator it = elementMap.find(entity->GetRoomIndex());
|
||||
|
||||
if (it == elementMap.end()) {
|
||||
std::ostringstream msg;
|
||||
msg << "Failed to push entity; Room index not found: " << entity->GetRoomIndex() << std::endl;
|
||||
throw(std::runtime_error(msg.str()));
|
||||
}
|
||||
|
||||
it->second.entityList.push_back(entity);
|
||||
}
|
||||
|
||||
void RoomManager::PopEntity(Entity* entity) {
|
||||
std::map<int, RoomData>::iterator it = elementMap.find(entity->GetRoomIndex());
|
||||
|
||||
if (it == elementMap.end()) {
|
||||
std::ostringstream msg;
|
||||
msg << "Failed to pop entity; Room index not found: " << entity->GetRoomIndex() << std::endl;
|
||||
throw(std::runtime_error(msg.str()));
|
||||
}
|
||||
|
||||
it->second.entityList.remove_if([&](Entity* ptr) -> bool {
|
||||
return ptr == entity;
|
||||
});
|
||||
}
|
||||
|
||||
void RoomManager::UnloadAll() {
|
||||
elementMap.clear();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#ifndef ROOMMANAGER_HPP_
|
||||
#define ROOMMANAGER_HPP_
|
||||
|
||||
#include "entity.hpp"
|
||||
#include "room_data.hpp"
|
||||
#include "singleton.hpp"
|
||||
|
||||
@@ -39,6 +40,9 @@ public:
|
||||
//common public methods
|
||||
int Create(std::string name, std::string tileset);
|
||||
|
||||
void PushEntity(Entity* entity);
|
||||
void PopEntity(Entity* entity);
|
||||
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int,RoomData>)> fn);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user