diff --git a/AI/BattleAI/BattleEvaluator.cpp b/AI/BattleAI/BattleEvaluator.cpp index 98d1bf3e6..3fccb5e8c 100644 --- a/AI/BattleAI/BattleEvaluator.cpp +++ b/AI/BattleAI/BattleEvaluator.cpp @@ -291,10 +291,9 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector std::vector copy = targetHexes; for(auto hex : copy) - { vstd::concatenate(targetHexes, hex.allNeighbouringTiles()); - } + vstd::erase_if(targetHexes, [](const BattleHex & hex) {return !hex.isValid();}); vstd::removeDuplicates(targetHexes); } diff --git a/client/render/CAnimation.cpp b/client/render/CAnimation.cpp index 514540d79..faa45e559 100644 --- a/client/render/CAnimation.cpp +++ b/client/render/CAnimation.cpp @@ -33,6 +33,9 @@ bool CAnimation::loadFrame(size_t frame, size_t group) if(image) { images[group][frame] = image; + + if (player.isValidPlayer()) + image->playerColored(player); return true; } else @@ -188,8 +191,9 @@ void CAnimation::verticalFlip(size_t frame, size_t group) source[group][frame] = locator; } -void CAnimation::playerColored(PlayerColor player) +void CAnimation::playerColored(PlayerColor targetPlayer) { + player = targetPlayer; for(auto & group : images) for(auto & image : group.second) image.second->playerColored(player); diff --git a/lib/networkPacks/PacksForLobby.h b/lib/networkPacks/PacksForLobby.h index a0745fe7b..7f3348c08 100644 --- a/lib/networkPacks/PacksForLobby.h +++ b/lib/networkPacks/PacksForLobby.h @@ -157,10 +157,7 @@ struct DLL_LINKAGE LobbyStartGame : public CLobbyPackToPropagate { h & clientId; h & initializedStartInfo; - bool sps = h.smartPointerSerialization; - h.smartPointerSerialization = true; h & initializedGameState; - h.smartPointerSerialization = sps; } }; diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index e7de7de4a..9823e7fa2 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -37,39 +37,44 @@ public: /// Effectively revesed version of BinarySerializer class BinaryDeserializer : public CLoaderBase { - template - struct LoadIfStackInstance + template + static bool loadIfStackInstance(T &data) { - static bool invoke(Ser &s, T &data) - { - return false; - } - }; + return false; + } - template - struct LoadIfStackInstance + template + bool loadIfStackInstance(const CStackInstance* &data) { - static bool invoke(Ser &s, CStackInstance* &data) + CArmedInstance * armyPtr = nullptr; + ObjectInstanceID armyID; + SlotID slot; + load(armyID); + load(slot); + + if (armyID == ObjectInstanceID::NONE) + return false; + + if(reader->smartVectorMembersSerialization) { - CArmedInstance *armedObj; - SlotID slot; - s.load(armedObj); - s.load(slot); - if(slot != SlotID::COMMANDER_SLOT_PLACEHOLDER) - { - assert(armedObj->hasStackAtSlot(slot)); - data = armedObj->stacks[slot]; - } - else - { - auto * hero = dynamic_cast(armedObj); - assert(hero); - assert(hero->commander); - data = hero->commander; - } - return true; + if(const auto *info = reader->getVectorizedTypeInfo()) + armyPtr = static_cast(reader->getVectorItemFromId(*info, armyID)); } - }; + + if(slot != SlotID::COMMANDER_SLOT_PLACEHOLDER) + { + assert(armyPtr->hasStackAtSlot(slot)); + data = armyPtr->stacks[slot]; + } + else + { + auto * hero = dynamic_cast(armyPtr); + assert(hero); + assert(hero->commander); + data = hero->commander; + } + return true; + } template struct ClassObjectCreator @@ -331,7 +336,7 @@ public: if(reader->sendStackInstanceByIds) { - bool gotLoaded = LoadIfStackInstance::invoke(* this, data); + bool gotLoaded = loadIfStackInstance(data); if(gotLoaded) return; } diff --git a/lib/serializer/BinarySerializer.h b/lib/serializer/BinarySerializer.h index b86cc9cf6..49bb835f7 100644 --- a/lib/serializer/BinarySerializer.h +++ b/lib/serializer/BinarySerializer.h @@ -52,33 +52,33 @@ class BinarySerializer : public CSaverBase } }; - template - struct SaveIfStackInstance + template + bool saveIfStackInstance(const T &data) { - static bool invoke(Ser &s, const T &data) - { - return false; - } - }; + return false; + } - template - struct SaveIfStackInstance + template + bool saveIfStackInstance(const CStackInstance* const &data) { - static bool invoke(Ser &s, const CStackInstance* const &data) - { - assert(data->armyObj); - SlotID slot; + assert(data->armyObj); - if(data->getNodeType() == CBonusSystemNode::COMMANDER) - slot = SlotID::COMMANDER_SLOT_PLACEHOLDER; - else - slot = data->armyObj->findStack(data); + SlotID slot; - assert(slot != SlotID()); - s & data->armyObj & slot; + if(data->getNodeType() == CBonusSystemNode::COMMANDER) + slot = SlotID::COMMANDER_SLOT_PLACEHOLDER; + else + slot = data->armyObj->findStack(data); + + assert(slot != SlotID()); + save(data->armyObj->id); + save(slot); + + if (data->armyObj->id != ObjectInstanceID::NONE) return true; - } - }; + else + return false; + } template class CPointerSaver; @@ -252,7 +252,7 @@ public: if(writer->sendStackInstanceByIds) { - const bool gotSaved = SaveIfStackInstance::invoke(*this, data); + const bool gotSaved = saveIfStackInstance(data); if(gotSaved) return; } diff --git a/lib/serializer/Connection.cpp b/lib/serializer/Connection.cpp index c428a6044..cbf567d2e 100644 --- a/lib/serializer/Connection.cpp +++ b/lib/serializer/Connection.cpp @@ -84,6 +84,7 @@ void CConnection::sendPack(const CPack * pack) connectionPtr->sendPacket(packWriter->buffer); packWriter->buffer.clear(); + serializer->savedPointers.clear(); } CPack * CConnection::retrievePack(const std::vector & data) @@ -102,6 +103,8 @@ CPack * CConnection::retrievePack(const std::vector & data) throw std::runtime_error("Failed to retrieve pack! Not all data has been read!"); logNetwork->trace("Received CPack of type %s", typeid(*result).name()); + deserializer->loadedPointers.clear(); + deserializer->loadedSharedPointers.clear(); return result; } @@ -132,7 +135,6 @@ void CConnection::enterLobbyConnectionMode() deserializer->loadedPointers.clear(); serializer->savedPointers.clear(); disableSmartVectorMemberSerialization(); - disableSmartPointerSerialization(); disableStackSendingByID(); } @@ -144,7 +146,6 @@ void CConnection::setCallback(IGameCallback * cb) void CConnection::enterGameplayConnectionMode(CGameState * gs) { enableStackSendingByID(); - disableSmartPointerSerialization(); setCallback(gs->callback); enableSmartVectorMemberSerializatoin(gs);