Discarding: pointers to object to push/pop was a bad idea

This commit is contained in:
Kayne Ruse
2015-01-02 07:18:21 +11:00
parent e4d7ece99c
commit 29a09cf71f
3 changed files with 7 additions and 7 deletions
+4 -4
View File
@@ -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"));
} }
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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;