Pop & Push don't work like they should

This commit is contained in:
Kayne Ruse
2015-01-01 03:37:13 +11:00
parent ebd8e54725
commit b4b7c0d877
3 changed files with 23 additions and 3 deletions
+1 -1
View File
@@ -253,7 +253,7 @@ CharacterData* CharacterManager::Get(int uid) {
return nullptr;
}
return &it->second;
return &(it->second);
}
int CharacterManager::GetLoadedCount() {
+19 -2
View File
@@ -26,6 +26,9 @@
#include <stdexcept>
#include <sstream>
//debug
#include <iostream>
//-------------------------
//public access methods
//-------------------------
@@ -43,6 +46,10 @@ int RoomManager::Create(std::string roomName, std::string tileset) {
}
void RoomManager::PushEntity(Entity* entity) {
if (!entity) {
throw(std::runtime_error("Failed to push null entity"));
}
std::map<int, RoomData>::iterator it = elementMap.find(entity->GetRoomIndex());
if (it == elementMap.end()) {
@@ -51,10 +58,16 @@ void RoomManager::PushEntity(Entity* entity) {
throw(std::runtime_error(msg.str()));
}
it->second.entityList.push_back(entity);
it->second.entityList.push_back(&(*entity));
std::cout << "\troom[" << it->first << "].entityList.size(): " << it->second.entityList.size() << std::endl;
}
void RoomManager::PopEntity(Entity* entity) {
if (!entity) {
throw(std::runtime_error("Failed to pop null entity"));
}
std::map<int, RoomData>::iterator it = elementMap.find(entity->GetRoomIndex());
if (it == elementMap.end()) {
@@ -64,8 +77,12 @@ void RoomManager::PopEntity(Entity* entity) {
}
it->second.entityList.remove_if([&](Entity* ptr) -> bool {
return ptr == entity;
bool b = &(*ptr) == &(*entity);
std::cout << "\tmatch(" << int(&(*ptr)) << "," << int(&(*entity)) << "): " << b << std::endl;
return b;
});
std::cout << "\troom[" << it->first << "].entityList.size(): " << it->second.entityList.size() << std::endl;
}
void RoomManager::UnloadAll() {
+3
View File
@@ -149,6 +149,9 @@ void ServerApplication::FullCharacterUnload(int index) {
return false;
}
//pop from the rooms
roomMgr.PopEntity(&character.second);
//pump character unload
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_DELETE;