Discarding: pointers to object to push/pop was a bad idea
This commit is contained in:
@@ -45,7 +45,7 @@ int RoomManager::Create(std::string roomName, std::string tileset) {
|
|||||||
return counter++;
|
return counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomManager::PushEntity(Entity* entity) {
|
void RoomManager::PushEntity(Entity const* entity) {
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
throw(std::runtime_error("Failed to push null entity"));
|
throw(std::runtime_error("Failed to push null entity"));
|
||||||
}
|
}
|
||||||
@@ -54,17 +54,17 @@ void RoomManager::PushEntity(Entity* entity) {
|
|||||||
|
|
||||||
if (it == elementMap.end()) {
|
if (it == elementMap.end()) {
|
||||||
std::ostringstream msg;
|
std::ostringstream msg;
|
||||||
msg << "Failed to push entity; Room index not found: " << entity->GetRoomIndex() << std::endl;
|
// msg << "Failed to push entity; Room index not found: " << entity->GetRoomIndex() << std::endl;
|
||||||
throw(std::runtime_error(msg.str()));
|
throw(std::runtime_error(msg.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
it->second.entityList.push_back(entity);
|
it->second.entityList.push_back(const_cast<Entity*>(entity));
|
||||||
|
|
||||||
std::cout << "\troom[" << it->first << "].entityList.size(): " << it->second.entityList.size() << std::endl;
|
std::cout << "\troom[" << it->first << "].entityList.size(): " << it->second.entityList.size() << std::endl;
|
||||||
std::cout << "\tEntity: " << int(entity) << "," << int(it->second.entityList.front()) << std::endl;
|
std::cout << "\tEntity: " << int(entity) << "," << int(it->second.entityList.front()) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomManager::PopEntity(Entity* entity) {
|
void RoomManager::PopEntity(Entity const* entity) {
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
throw(std::runtime_error("Failed to pop null entity"));
|
throw(std::runtime_error("Failed to pop null entity"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ public:
|
|||||||
//common public methods
|
//common public methods
|
||||||
int Create(std::string name, std::string tileset);
|
int Create(std::string name, std::string tileset);
|
||||||
|
|
||||||
void PushEntity(Entity* entity);
|
void PushEntity(Entity const* entity);
|
||||||
void PopEntity(Entity* entity);
|
void PopEntity(Entity const* entity);
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ void ServerApplication::FullCharacterUnload(int index) {
|
|||||||
|
|
||||||
//pop from the rooms
|
//pop from the rooms
|
||||||
std::cout << "popping index " << index << std::endl;
|
std::cout << "popping index " << index << std::endl;
|
||||||
roomMgr.PopEntity(static_cast<Entity*>(&(character.second)));
|
roomMgr.PopEntity(reinterpret_cast<Entity const*>(&character.second));
|
||||||
|
|
||||||
//pump character unload
|
//pump character unload
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
|
|||||||
Reference in New Issue
Block a user