diff --git a/CCallback.cpp b/CCallback.cpp index 57462db27..77bf4d72c 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -29,20 +29,20 @@ bool CCallback::teleportHero(const CGHeroInstance *who, const CGTownInstance *where) { CastleTeleportHero pack(who->id, where->id, 1); - sendRequest(&pack); + sendRequest(pack); return true; } void CCallback::moveHero(const CGHeroInstance *h, const int3 & destination, bool transit) { MoveHero pack({destination}, h->id, transit); - sendRequest(&pack); + sendRequest(pack); } void CCallback::moveHero(const CGHeroInstance *h, const std::vector & path, bool transit) { MoveHero pack(path, h->id, transit); - sendRequest(&pack); + sendRequest(pack); } int CCallback::selectionMade(int selection, QueryID queryID) @@ -61,7 +61,7 @@ int CCallback::sendQueryReply(std::optional reply, QueryID queryID) QueryReply pack(queryID, reply); pack.player = *player; - return sendRequest(&pack); + return sendRequest(pack); } void CCallback::recruitCreatures(const CGDwelling * obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level) @@ -71,7 +71,7 @@ void CCallback::recruitCreatures(const CGDwelling * obj, const CArmedInstance * return; RecruitCreatures pack(obj->id, dst->id, ID, amount, level); - sendRequest(&pack); + sendRequest(pack); } bool CCallback::dismissCreature(const CArmedInstance *obj, SlotID stackPos) @@ -80,14 +80,14 @@ bool CCallback::dismissCreature(const CArmedInstance *obj, SlotID stackPos) return false; DisbandCreature pack(stackPos,obj->id); - sendRequest(&pack); + sendRequest(pack); return true; } bool CCallback::upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID) { UpgradeCreature pack(stackPos,obj->id,newID); - sendRequest(&pack); + sendRequest(pack); return false; } @@ -95,54 +95,54 @@ void CCallback::endTurn() { logGlobal->trace("Player %d ended his turn.", player->getNum()); EndTurn pack; - sendRequest(&pack); + sendRequest(pack); } int CCallback::swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2) { ArrangeStacks pack(1,p1,p2,s1->id,s2->id,0); - sendRequest(&pack); + sendRequest(pack); return 0; } int CCallback::mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2) { ArrangeStacks pack(2,p1,p2,s1->id,s2->id,0); - sendRequest(&pack); + sendRequest(pack); return 0; } int CCallback::splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val) { ArrangeStacks pack(3,p1,p2,s1->id,s2->id,val); - sendRequest(&pack); + sendRequest(pack); return 0; } int CCallback::bulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot) { BulkMoveArmy pack(srcArmy, destArmy, srcSlot); - sendRequest(&pack); + sendRequest(pack); return 0; } int CCallback::bulkSplitStack(ObjectInstanceID armyId, SlotID srcSlot, int howMany) { BulkSplitStack pack(armyId, srcSlot, howMany); - sendRequest(&pack); + sendRequest(pack); return 0; } int CCallback::bulkSmartSplitStack(ObjectInstanceID armyId, SlotID srcSlot) { BulkSmartSplitStack pack(armyId, srcSlot); - sendRequest(&pack); + sendRequest(pack); return 0; } int CCallback::bulkMergeStacks(ObjectInstanceID armyId, SlotID srcSlot) { BulkMergeStacks pack(armyId, srcSlot); - sendRequest(&pack); + sendRequest(pack); return 0; } @@ -151,7 +151,7 @@ bool CCallback::dismissHero(const CGHeroInstance *hero) if(player!=hero->tempOwner) return false; DismissHero pack(hero->id); - sendRequest(&pack); + sendRequest(pack); return true; } @@ -160,7 +160,7 @@ bool CCallback::swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation ExchangeArtifacts ea; ea.src = l1; ea.dst = l2; - sendRequest(&ea); + sendRequest(ea); return true; } @@ -175,13 +175,13 @@ bool CCallback::swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation void CCallback::assembleArtifacts(const ObjectInstanceID & heroID, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo) { AssembleArtifacts aa(heroID, artifactSlot, assemble, assembleTo); - sendRequest(&aa); + sendRequest(aa); } void CCallback::bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap, bool equipped, bool backpack) { BulkExchangeArtifacts bma(srcHero, dstHero, swap, equipped, backpack); - sendRequest(&bma); + sendRequest(bma); } void CCallback::scrollBackpackArtifacts(ObjectInstanceID hero, bool left) @@ -189,7 +189,7 @@ void CCallback::scrollBackpackArtifacts(ObjectInstanceID hero, bool left) ManageBackpackArtifacts mba(hero, ManageBackpackArtifacts::ManageCmd::SCROLL_RIGHT); if(left) mba.cmd = ManageBackpackArtifacts::ManageCmd::SCROLL_LEFT; - sendRequest(&mba); + sendRequest(mba); } void CCallback::sortBackpackArtifactsBySlot(const ObjectInstanceID hero) @@ -213,13 +213,13 @@ void CCallback::sortBackpackArtifactsByClass(const ObjectInstanceID hero) void CCallback::manageHeroCostume(ObjectInstanceID hero, size_t costumeIndex, bool saveCostume) { ManageEquippedArtifacts mea(hero, costumeIndex, saveCostume); - sendRequest(&mea); + sendRequest(mea); } void CCallback::eraseArtifactByClient(const ArtifactLocation & al) { EraseArtifactByClient ea(al); - sendRequest(&ea); + sendRequest(ea); } bool CCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID) @@ -231,7 +231,7 @@ bool CCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID) return false; BuildStructure pack(town->id,buildingID); - sendRequest(&pack); + sendRequest(pack); return true; } @@ -241,7 +241,7 @@ bool CCallback::visitTownBuilding(const CGTownInstance *town, BuildingID buildin return false; VisitTownBuilding pack(town->id, buildingID); - sendRequest(&pack); + sendRequest(pack); return true; } @@ -250,10 +250,10 @@ void CBattleCallback::battleMakeSpellAction(const BattleID & battleID, const Bat assert(action.actionType == EActionType::HERO_SPELL); MakeAction mca(action); mca.battleID = battleID; - sendRequest(&mca); + sendRequest(mca); } -int CBattleCallback::sendRequest(const CPackForServer * request) +int CBattleCallback::sendRequest(const CPackForServer & request) { int requestID = cl->sendRequest(request, *getPlayerID()); if(waitTillRealize) @@ -278,7 +278,7 @@ void CCallback::swapGarrisonHero( const CGTownInstance *town ) if(town->tempOwner == *player || (town->garrisonHero && town->garrisonHero->tempOwner == *player )) { GarrisonHeroSwap pack(town->id); - sendRequest(&pack); + sendRequest(pack); } } @@ -287,7 +287,7 @@ void CCallback::buyArtifact(const CGHeroInstance *hero, ArtifactID aid) if(hero->tempOwner != *player) return; BuyArtifact pack(hero->id,aid); - sendRequest(&pack); + sendRequest(pack); } void CCallback::trade(const ObjectInstanceID marketId, EMarketMode mode, TradeItemSell id1, TradeItemBuy id2, ui32 val1, const CGHeroInstance * hero) @@ -304,13 +304,13 @@ void CCallback::trade(const ObjectInstanceID marketId, EMarketMode mode, const s pack.r1 = id1; pack.r2 = id2; pack.val = val1; - sendRequest(&pack); + sendRequest(pack); } void CCallback::setFormation(const CGHeroInstance * hero, EArmyFormation mode) { SetFormation pack(hero->id, mode); - sendRequest(&pack); + sendRequest(pack); } void CCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero, const HeroTypeID & nextHero) @@ -320,7 +320,7 @@ void CCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroIn HireHero pack(hero->getHeroType(), townOrTavern->id, nextHero); pack.player = *player; - sendRequest(&pack); + sendRequest(pack); } void CCallback::save( const std::string &fname ) @@ -334,7 +334,7 @@ void CCallback::gamePause(bool pause) { GamePause pack; pack.player = *player; - sendRequest(&pack); + sendRequest(pack); } else { @@ -348,14 +348,14 @@ void CCallback::sendMessage(const std::string &mess, const CGObjectInstance * cu PlayerMessage pm(mess, currentObject? currentObject->id : ObjectInstanceID(-1)); if(player) pm.player = *player; - sendRequest(&pm); + sendRequest(pm); } void CCallback::buildBoat( const IShipyard *obj ) { BuildBoat bb; bb.objid = dynamic_cast(obj)->id; - sendRequest(&bb); + sendRequest(bb); } CCallback::CCallback(CGameState * GS, std::optional Player, CClient * C) @@ -397,7 +397,7 @@ void CCallback::dig( const CGObjectInstance *hero ) { DigWithHero dwh; dwh.id = hero->id; - sendRequest(&dwh); + sendRequest(dwh); } void CCallback::castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos) @@ -406,7 +406,7 @@ void CCallback::castSpell(const CGHeroInstance *hero, SpellID spellID, const int cas.hid = hero->id; cas.sid = spellID; cas.pos = pos; - sendRequest(&cas); + sendRequest(cas); } int CCallback::mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2) @@ -439,7 +439,7 @@ void CBattleCallback::battleMakeUnitAction(const BattleID & battleID, const Batt MakeAction ma; ma.ba = action; ma.battleID = battleID; - sendRequest(&ma); + sendRequest(ma); } void CBattleCallback::battleMakeTacticAction(const BattleID & battleID, const BattleAction & action ) @@ -448,7 +448,7 @@ void CBattleCallback::battleMakeTacticAction(const BattleID & battleID, const Ba MakeAction ma; ma.ba = action; ma.battleID = battleID; - sendRequest(&ma); + sendRequest(ma); } std::optional CBattleCallback::makeSurrenderRetreatDecision(const BattleID & battleID, const BattleStateInfoForRetreat & battleState) diff --git a/CCallback.h b/CCallback.h index 1557b9254..39b9fc8ce 100644 --- a/CCallback.h +++ b/CCallback.h @@ -127,7 +127,7 @@ class CBattleCallback : public IBattleCallback std::optional player; protected: - int sendRequest(const CPackForServer * request); //returns requestID (that'll be matched to requestID in PackageApplied) + int sendRequest(const CPackForServer & request); //returns requestID (that'll be matched to requestID in PackageApplied) CClient *cl; public: diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 6214e6380..dcba9897f 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -938,7 +938,7 @@ void CServerHandler::visitForLobby(CPackForLobby & lobbyPack) void CServerHandler::visitForClient(CPackForClient & clientPack) { - client->handlePack(&clientPack); + client->handlePack(clientPack); } diff --git a/client/Client.cpp b/client/Client.cpp index c6b024198..0f55cbd52 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -163,7 +163,7 @@ void CClient::save(const std::string & fname) } SaveGame save_game(fname); - sendRequest(&save_game, PlayerColor::NEUTRAL); + sendRequest(save_game, PlayerColor::NEUTRAL); } void CClient::endNetwork() @@ -348,35 +348,35 @@ void CClient::installNewBattleInterface(std::shared_ptr ba } } -void CClient::handlePack(CPackForClient * pack) +void CClient::handlePack(CPackForClient & pack) { ApplyClientNetPackVisitor afterVisitor(*this, *gameState()); ApplyFirstClientNetPackVisitor beforeVisitor(*this, *gameState()); - pack->visit(beforeVisitor); - logNetwork->trace("\tMade first apply on cl: %s", typeid(*pack).name()); + pack.visit(beforeVisitor); + logNetwork->trace("\tMade first apply on cl: %s", typeid(pack).name()); { boost::unique_lock lock(CGameState::mutex); gs->apply(pack); } - logNetwork->trace("\tApplied on gs: %s", typeid(*pack).name()); - pack->visit(afterVisitor); - logNetwork->trace("\tMade second apply on cl: %s", typeid(*pack).name()); + logNetwork->trace("\tApplied on gs: %s", typeid(pack).name()); + pack.visit(afterVisitor); + logNetwork->trace("\tMade second apply on cl: %s", typeid(pack).name()); } -int CClient::sendRequest(const CPackForServer * request, PlayerColor player) +int CClient::sendRequest(const CPackForServer & request, PlayerColor player) { static ui32 requestCounter = 1; ui32 requestID = requestCounter++; - logNetwork->trace("Sending a request \"%s\". It'll have an ID=%d.", typeid(*request).name(), requestID); + logNetwork->trace("Sending a request \"%s\". It'll have an ID=%d.", typeid(request).name(), requestID); waitingRequest.pushBack(requestID); - request->requestID = requestID; - request->player = player; - CSH->logicConnection->sendPack(*request); + request.requestID = requestID; + request.player = player; + CSH->logicConnection->sendPack(request); if(vstd::contains(playerint, player)) - playerint[player]->requestSent(request, requestID); + playerint[player]->requestSent(&request, requestID); return requestID; } diff --git a/client/Client.h b/client/Client.h index b9e855ca5..a01d893aa 100644 --- a/client/Client.h +++ b/client/Client.h @@ -142,8 +142,8 @@ public: static ThreadSafeVector waitingRequest; //FIXME: make this normal field (need to join all threads before client destruction) - void handlePack(CPackForClient * pack); //applies the given pack and deletes it - int sendRequest(const CPackForServer * request, PlayerColor player); //returns ID given to that request + void handlePack(CPackForClient & pack); //applies the given pack and deletes it + int sendRequest(const CPackForServer & request, PlayerColor player); //returns ID given to that request void battleStarted(const BattleInfo * info); void battleFinished(const BattleID & battleID); diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index a378a796d..e35432cef 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -1143,9 +1143,9 @@ PlayerRelations CGameState::getPlayerRelations( PlayerColor color1, PlayerColor return PlayerRelations::ENEMIES; } -void CGameState::apply(CPackForClient *pack) +void CGameState::apply(CPackForClient & pack) { - pack->applyGs(this); + pack.applyGs(this); } void CGameState::calculatePaths(const CGHeroInstance *hero, CPathsInfo &out) diff --git a/lib/gameState/CGameState.h b/lib/gameState/CGameState.h index d247eb47b..a149575b4 100644 --- a/lib/gameState/CGameState.h +++ b/lib/gameState/CGameState.h @@ -98,7 +98,7 @@ public: /// picks next free hero type of the H3 hero init sequence -> chosen starting hero, then unused hero type randomly HeroTypeID pickNextHeroType(const PlayerColor & owner); - void apply(CPackForClient *pack); + void apply(CPackForClient & pack); BattleField battleGetBattlefieldType(int3 tile, vstd::RNG & rand); void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const override; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index aa29b9afc..765cf2d12 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1444,8 +1444,8 @@ void CGameHandler::sendToAllClients(CPackForClient * pack) void CGameHandler::sendAndApply(CPackForClient * pack) { sendToAllClients(pack); - gs->apply(pack); - logNetwork->trace("\tApplied on gs: %s", typeid(*pack).name()); + gs->apply(*pack); + logNetwork->trace("\tApplied on gs: %s", typeid(pack).name()); } void CGameHandler::sendAndApply(CGarrisonOperationPack * pack) diff --git a/test/game/CGameStateTest.cpp b/test/game/CGameStateTest.cpp index be71314fc..b720fdfd6 100644 --- a/test/game/CGameStateTest.cpp +++ b/test/game/CGameStateTest.cpp @@ -65,42 +65,42 @@ public: void apply(CPackForClient * pack) override { - gameState->apply(pack); + gameState->apply(*pack); } void apply(BattleLogMessage * pack) override { - gameState->apply(pack); + gameState->apply(*pack); } void apply(BattleStackMoved * pack) override { - gameState->apply(pack); + gameState->apply(*pack); } void apply(BattleUnitsChanged * pack) override { - gameState->apply(pack); + gameState->apply(*pack); } void apply(SetStackEffect * pack) override { - gameState->apply(pack); + gameState->apply(*pack); } void apply(StacksInjured * pack) override { - gameState->apply(pack); + gameState->apply(*pack); } void apply(BattleObstaclesChanged * pack) override { - gameState->apply(pack); + gameState->apply(*pack); } void apply(CatapultAttack * pack) override { - gameState->apply(pack); + gameState->apply(*pack); } void complain(const std::string & problem) override