From b2452fb6fe1279e8a36108a2a0486a2ab567cf18 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 2 Jan 2015 06:57:20 +1100 Subject: [PATCH] Committing incomplete work; need to fix an urgent bug --- server/characters/character_data.hpp | 24 ++++++++++++++++++++++++ server/rooms/room_manager.cpp | 9 +++++---- server/server_character_methods.cpp | 6 ++++-- server/server_methods.cpp | 4 +++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp index 873bfa4..c074ec8 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -30,9 +30,33 @@ #include #include +#include + class CharacterData: public Entity { public: CharacterData() = default; + CharacterData(CharacterData const& rhs) { + std::cerr << "Character copy detected" << std::endl; + owner = rhs.owner; + handle = rhs.handle; + avatar = rhs.avatar; + + //entity stuff + roomIndex = rhs.roomIndex; + origin = rhs.origin; + motion = rhs.motion; + } + CharacterData(CharacterData&& rhs) { + std::cerr << "Character move detected" << std::endl; + owner = rhs.owner; + handle = rhs.handle; + avatar = rhs.avatar; + + //entity stuff + roomIndex = rhs.roomIndex; + origin = rhs.origin; + motion = rhs.motion; + } ~CharacterData() = default; //accessors and mutators diff --git a/server/rooms/room_manager.cpp b/server/rooms/room_manager.cpp index 414c026..860caf5 100644 --- a/server/rooms/room_manager.cpp +++ b/server/rooms/room_manager.cpp @@ -58,9 +58,10 @@ 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; + std::cout << "\tEntity: " << int(entity) << "," << int(it->second.entityList.front()) << std::endl; } void RoomManager::PopEntity(Entity* entity) { @@ -76,9 +77,9 @@ void RoomManager::PopEntity(Entity* entity) { throw(std::runtime_error(msg.str())); } - it->second.entityList.remove_if([&](Entity* ptr) -> bool { - bool b = &(*ptr) == &(*entity); - std::cout << "\tmatch(" << int(&(*ptr)) << "," << int(&(*entity)) << "): " << b << std::endl; + it->second.entityList.remove_if([entity](Entity* ptr) -> bool { + bool b = (entity == ptr); + std::cout << "\tmatch(" << int(ptr) << "," << int(entity) << "): " << b << std::endl; return b; }); diff --git a/server/server_character_methods.cpp b/server/server_character_methods.cpp index 26c4bb8..56990b6 100644 --- a/server/server_character_methods.cpp +++ b/server/server_character_methods.cpp @@ -46,7 +46,7 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) } //push this character to the rooms - roomMgr.PushEntity(static_cast(characterMgr.Get(characterIndex))); +// roomMgr.PushEntity(static_cast(characterMgr.Get(characterIndex))); //pump this character to all clients CharacterPacket newPacket; @@ -90,7 +90,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) } //delete the character - roomMgr.PopEntity(static_cast(characterMgr.Get(characterIndex))); +// roomMgr.PopEntity(static_cast(characterMgr.Get(characterIndex))); characterMgr.Delete(characterIndex); //pump character delete @@ -124,6 +124,7 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { } //push this character to the rooms + std::cout << "pushing index " << characterIndex << std::endl; roomMgr.PushEntity(static_cast(characterMgr.Get(characterIndex))); //pump this character to all clients @@ -157,6 +158,7 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) } //unload the character + std::cout << "poping index " << argPacket->characterIndex << std::endl; roomMgr.PopEntity(static_cast(characterData)); characterMgr.Unload(argPacket->characterIndex); diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 6cdc600..1aafc71 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -143,6 +143,7 @@ void ServerApplication::FullAccountUnload(int index) { } void ServerApplication::FullCharacterUnload(int index) { + //BUG: #38 UnloadIf() lambas are taking COPIES of data structures, rather than the structures themselves characterMgr.UnloadIf([&](std::pair character) -> bool { //skip the wrong characters if (character.first != index) { @@ -150,7 +151,8 @@ void ServerApplication::FullCharacterUnload(int index) { } //pop from the rooms - roomMgr.PopEntity(static_cast(&character.second)); + std::cout << "popping index " << index << std::endl; + roomMgr.PopEntity(static_cast(&(character.second))); //pump character unload CharacterPacket newPacket;