1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
This commit is contained in:
Michał W. Urbańczyk 2011-06-25 14:22:19 +00:00
parent 5fdb5aa494
commit 212bc13ad6
5 changed files with 21 additions and 7 deletions

View File

@ -236,7 +236,9 @@ void CCallback::setSelection(const CArmedInstance * obj)
if(obj->ID == HEROI_TYPE) if(obj->ID == HEROI_TYPE)
{ {
cl->gs->calculatePaths(static_cast<const CGHeroInstance *>(obj), *cl->pathInfo); if(cl->pathInfo->hero != obj) //calculate new paths only if we selected a different hero
cl->calculatePaths(static_cast<const CGHeroInstance *>(obj));
//nasty workaround. TODO: nice workaround //nasty workaround. TODO: nice workaround
cl->gs->getPlayer(player)->currentSelection = obj->id; cl->gs->getPlayer(player)->currentSelection = obj->id;
} }
@ -303,12 +305,13 @@ bool CCallback::getPath2( int3 dest, CGPath &ret )
{ {
recalculatePaths(); recalculatePaths();
} }
boost::unique_lock<boost::mutex> pathLock(cl->pathMx);
return cl->pathInfo->getPath(dest, ret); return cl->pathInfo->getPath(dest, ret);
} }
void CCallback::recalculatePaths() 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*/ ) void CCallback::calculatePaths( const CGHeroInstance *hero, CPathsInfo &out, int3 src /*= int3(-1,-1,-1)*/, int movement /*= -1*/ )

View File

@ -526,7 +526,7 @@ void CClient::updatePaths()
{ {
const CGHeroInstance *h = getSelectedHero(); const CGHeroInstance *h = getSelectedHero();
if (h)//if we have selected hero... if (h)//if we have selected hero...
gs->calculatePaths(h, *pathInfo); calculatePaths(h);
} }
void CClient::finishCampaign( CCampaignState * camp ) void CClient::finishCampaign( CCampaignState * camp )
@ -617,6 +617,13 @@ int CClient::getLocalPlayer() const
return getCurrentPlayer(); return getCurrentPlayer();
} }
void CClient::calculatePaths(const CGHeroInstance *h)
{
assert(h);
boost::unique_lock<boost::mutex> pathLock(pathMx);
gs->calculatePaths(h, *pathInfo);
}
template void CClient::serialize( CISer<CLoadFile> &h, const int version ); template void CClient::serialize( CISer<CLoadFile> &h, const int version );
template void CClient::serialize( COSer<CSaveFile> &h, const int version ); template void CClient::serialize( COSer<CSaveFile> &h, const int version );

View File

@ -72,7 +72,10 @@ public:
bool hotSeat; bool hotSeat;
CConnection *serv; CConnection *serv;
BattleAction *curbaction; BattleAction *curbaction;
CPathsInfo *pathInfo; CPathsInfo *pathInfo;
boost::mutex pathMx; //protects the variable above
CScriptingModule *erm; CScriptingModule *erm;
CondSh<bool> waitingRequest; CondSh<bool> waitingRequest;
@ -97,6 +100,8 @@ public:
void run(); void run();
void finishCampaign( CCampaignState * camp ); void finishCampaign( CCampaignState * camp );
void proposeNextMission( 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 bool terminate; // tell to terminate
boost::thread *connectionHandler; //thread running run() method boost::thread *connectionHandler; //thread running run() method
@ -159,7 +164,6 @@ public:
friend void processCommand(const std::string &message, CClient *&client); //handling console friend void processCommand(const std::string &message, CClient *&client); //handling console
void handlePack( CPack * pack ); //applies the given pack and deletes it void handlePack( CPack * pack ); //applies the given pack and deletes it
void updatePaths();
void battleStarted(const BattleInfo * info); void battleStarted(const BattleInfo * info);
void commitPackage(CPackForClient *pack) OVERRIDE; void commitPackage(CPackForClient *pack) OVERRIDE;

View File

@ -154,7 +154,7 @@ void SetMovePoints::applyCl( CClient *cl )
if (cl->IGameCallback::getSelectedHero(LOCPLINT->playerID) == h)//if we have selected that hero 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); INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroMovePointsChanged, h);
@ -329,7 +329,7 @@ void RemoveObject::applyFirstCl( CClient *cl )
void RemoveObject::applyCl( CClient *cl ) void RemoveObject::applyCl( CClient *cl )
{ {
if(cl->pathInfo->hero && cl->pathInfo->hero->id != id) if(cl->pathInfo->hero && cl->pathInfo->hero->id != id)
GS(cl)->calculatePaths(cl->pathInfo->hero, *cl->pathInfo); cl->updatePaths();
} }
void TryMoveHero::applyFirstCl( CClient *cl ) void TryMoveHero::applyFirstCl( CClient *cl )

View File

@ -477,7 +477,7 @@ DLL_EXPORT void NewObject::applyGs( CGameState *gs )
cre->character = 2; cre->character = 2;
cre->gainedArtifact = -1; cre->gainedArtifact = -1;
cre->identifier = -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; break;
default: default: