From 212bc13ad615b40500c34a010e1a17bee41b7f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 25 Jun 2011 14:22:19 +0000 Subject: [PATCH] Fixed #755 and #759. --- CCallback.cpp | 7 +++++-- client/Client.cpp | 9 ++++++++- client/Client.h | 6 +++++- client/NetPacksClient.cpp | 4 ++-- lib/NetPacksLib.cpp | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index ccc19ecaf..9ca25cf43 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -236,7 +236,9 @@ void CCallback::setSelection(const CArmedInstance * obj) if(obj->ID == HEROI_TYPE) { - cl->gs->calculatePaths(static_cast(obj), *cl->pathInfo); + if(cl->pathInfo->hero != obj) //calculate new paths only if we selected a different hero + cl->calculatePaths(static_cast(obj)); + //nasty workaround. TODO: nice workaround cl->gs->getPlayer(player)->currentSelection = obj->id; } @@ -303,12 +305,13 @@ bool CCallback::getPath2( int3 dest, CGPath &ret ) { recalculatePaths(); } + boost::unique_lock pathLock(cl->pathMx); return cl->pathInfo->getPath(dest, ret); } void CCallback::recalculatePaths() { - gs->calculatePaths(cl->IGameCallback::getSelectedHero(player), *cl->pathInfo); + cl->calculatePaths(cl->IGameCallback::getSelectedHero(player)); } void CCallback::calculatePaths( const CGHeroInstance *hero, CPathsInfo &out, int3 src /*= int3(-1,-1,-1)*/, int movement /*= -1*/ ) diff --git a/client/Client.cpp b/client/Client.cpp index 2a2b86450..da8041a21 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -526,7 +526,7 @@ void CClient::updatePaths() { const CGHeroInstance *h = getSelectedHero(); if (h)//if we have selected hero... - gs->calculatePaths(h, *pathInfo); + calculatePaths(h); } void CClient::finishCampaign( CCampaignState * camp ) @@ -617,6 +617,13 @@ int CClient::getLocalPlayer() const return getCurrentPlayer(); } +void CClient::calculatePaths(const CGHeroInstance *h) +{ + assert(h); + boost::unique_lock pathLock(pathMx); + gs->calculatePaths(h, *pathInfo); +} + template void CClient::serialize( CISer &h, const int version ); template void CClient::serialize( COSer &h, const int version ); diff --git a/client/Client.h b/client/Client.h index 0dadcdbd0..30519cdd2 100644 --- a/client/Client.h +++ b/client/Client.h @@ -72,7 +72,10 @@ public: bool hotSeat; CConnection *serv; BattleAction *curbaction; + CPathsInfo *pathInfo; + boost::mutex pathMx; //protects the variable above + CScriptingModule *erm; CondSh waitingRequest; @@ -97,6 +100,8 @@ public: void run(); void finishCampaign( CCampaignState * camp ); void proposeNextMission( CCampaignState * camp ); + void calculatePaths(const CGHeroInstance *h); + void updatePaths(); //calls calculatePaths for same hero for which we previously calculated paths bool terminate; // tell to terminate boost::thread *connectionHandler; //thread running run() method @@ -159,7 +164,6 @@ public: friend void processCommand(const std::string &message, CClient *&client); //handling console void handlePack( CPack * pack ); //applies the given pack and deletes it - void updatePaths(); void battleStarted(const BattleInfo * info); void commitPackage(CPackForClient *pack) OVERRIDE; diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index d1bdba322..7e5f5fe98 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -154,7 +154,7 @@ void SetMovePoints::applyCl( CClient *cl ) if (cl->IGameCallback::getSelectedHero(LOCPLINT->playerID) == h)//if we have selected that hero { - GS(cl)->calculatePaths(h, *cl->pathInfo); + cl->calculatePaths(h); } INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroMovePointsChanged, h); @@ -329,7 +329,7 @@ void RemoveObject::applyFirstCl( CClient *cl ) void RemoveObject::applyCl( CClient *cl ) { if(cl->pathInfo->hero && cl->pathInfo->hero->id != id) - GS(cl)->calculatePaths(cl->pathInfo->hero, *cl->pathInfo); + cl->updatePaths(); } void TryMoveHero::applyFirstCl( CClient *cl ) diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 28dce199e..bf287be3a 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -477,7 +477,7 @@ DLL_EXPORT void NewObject::applyGs( CGameState *gs ) cre->character = 2; cre->gainedArtifact = -1; cre->identifier = -1; - cre->addToSlot(0, new CStackInstance(-1, -1)); //add placeholder stack + cre->addToSlot(0, new CStackInstance(subID, -1)); //add placeholder stack } break; default: