1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

Replace more usages of pointers to packs with references

This commit is contained in:
Ivan Savenko 2024-10-04 14:01:10 +00:00
parent ee831c06e7
commit 786f80871e
9 changed files with 68 additions and 68 deletions

View File

@ -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<int3> & 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<int32_t> 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<const CGObjectInstance*>(obj)->id;
sendRequest(&bb);
sendRequest(bb);
}
CCallback::CCallback(CGameState * GS, std::optional<PlayerColor> 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<BattleAction> CBattleCallback::makeSurrenderRetreatDecision(const BattleID & battleID, const BattleStateInfoForRetreat & battleState)

View File

@ -127,7 +127,7 @@ class CBattleCallback : public IBattleCallback
std::optional<PlayerColor> 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:

View File

@ -938,7 +938,7 @@ void CServerHandler::visitForLobby(CPackForLobby & lobbyPack)
void CServerHandler::visitForClient(CPackForClient & clientPack)
{
client->handlePack(&clientPack);
client->handlePack(clientPack);
}

View File

@ -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<CBattleGameInterface> 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;
}

View File

@ -142,8 +142,8 @@ public:
static ThreadSafeVector<int> 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);

View File

@ -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)

View File

@ -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;

View File

@ -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)

View File

@ -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