Added PushEntity() & PopEntity() to RoomManager

Calling them from server_character_methods.cpp.
This commit is contained in:
Kayne Ruse
2015-01-01 02:50:52 +11:00
parent 963aca218a
commit ebd8e54725
6 changed files with 57 additions and 2 deletions
+27
View File
@@ -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();
}