mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Add network thread termination logic for adventure map animations
This commit is contained in:
parent
9bfe000724
commit
d502850054
@ -348,6 +348,7 @@ void CClient::save(const std::string & fname)
|
|||||||
|
|
||||||
void CClient::endNetwork()
|
void CClient::endNetwork()
|
||||||
{
|
{
|
||||||
|
CGI->mh->endNetwork();
|
||||||
if (CPlayerInterface::battleInt)
|
if (CPlayerInterface::battleInt)
|
||||||
CPlayerInterface::battleInt->endNetwork();
|
CPlayerInterface::battleInt->endNetwork();
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@
|
|||||||
#include "../../lib/CTownHandler.h"
|
#include "../../lib/CTownHandler.h"
|
||||||
#include "../../lib/CHeroHandler.h"
|
#include "../../lib/CHeroHandler.h"
|
||||||
#include "../../lib/StartInfo.h"
|
#include "../../lib/StartInfo.h"
|
||||||
#include "../ConditionalWait.h"
|
|
||||||
#include "../../lib/mapObjects/CGTownInstance.h"
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
||||||
#include "../../lib/networkPacks/PacksForClientBattle.h"
|
#include "../../lib/networkPacks/PacksForClientBattle.h"
|
||||||
#include "../../lib/TextOperations.h"
|
#include "../../lib/TextOperations.h"
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#include "../../lib/battle/BattleHex.h"
|
#include "../../lib/battle/BattleHex.h"
|
||||||
#include "../../lib/CRandomGenerator.h"
|
#include "../../lib/CRandomGenerator.h"
|
||||||
#include "../../lib/CStack.h"
|
#include "../../lib/CStack.h"
|
||||||
#include "../ConditionalWait.h"
|
|
||||||
#include "../../lib/TextOperations.h"
|
#include "../../lib/TextOperations.h"
|
||||||
|
|
||||||
static void onAnimationFinished(const CStack *stack, std::weak_ptr<CreatureAnimation> anim)
|
static void onAnimationFinished(const CStack *stack, std::weak_ptr<CreatureAnimation> anim)
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CGuiHandler.h"
|
#include "CGuiHandler.h"
|
||||||
#include "ConditionalWait.h"
|
|
||||||
|
|
||||||
#include "CIntObject.h"
|
#include "CIntObject.h"
|
||||||
#include "CursorHandler.h"
|
#include "CursorHandler.h"
|
||||||
|
@ -58,7 +58,6 @@
|
|||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
#include "../../lib/GameConstants.h"
|
#include "../../lib/GameConstants.h"
|
||||||
#include "../../lib/CRandomGenerator.h"
|
#include "../../lib/CRandomGenerator.h"
|
||||||
#include "../ConditionalWait.h"
|
|
||||||
|
|
||||||
std::shared_ptr<CMainMenu> CMM;
|
std::shared_ptr<CMainMenu> CMM;
|
||||||
ISelectionScreenInfo * SEL;
|
ISelectionScreenInfo * SEL;
|
||||||
|
@ -25,6 +25,8 @@ public:
|
|||||||
virtual ~IMapObjectObserver();
|
virtual ~IMapObjectObserver();
|
||||||
|
|
||||||
virtual bool hasOngoingAnimations() = 0;
|
virtual bool hasOngoingAnimations() = 0;
|
||||||
|
virtual void waitForOngoingAnimations(){};
|
||||||
|
virtual void endNetwork(){};
|
||||||
|
|
||||||
/// Plays fade-in animation and adds object to map
|
/// Plays fade-in animation and adds object to map
|
||||||
virtual void onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator) = 0;
|
virtual void onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator) = 0;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
#include "../../lib/StartInfo.h"
|
#include "../../lib/StartInfo.h"
|
||||||
|
#include "../../lib/UnlockGuard.h"
|
||||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||||
#include "../../lib/mapObjects/MiscObjects.h"
|
#include "../../lib/mapObjects/MiscObjects.h"
|
||||||
#include "../../lib/pathfinder/CGPathNode.h"
|
#include "../../lib/pathfinder/CGPathNode.h"
|
||||||
@ -346,6 +347,7 @@ bool MapViewController::isEventVisible(const CGHeroInstance * obj, const int3 &
|
|||||||
|
|
||||||
void MapViewController::fadeOutObject(const CGObjectInstance * obj)
|
void MapViewController::fadeOutObject(const CGObjectInstance * obj)
|
||||||
{
|
{
|
||||||
|
animationWait.setBusy();
|
||||||
logGlobal->debug("Starting fade out animation");
|
logGlobal->debug("Starting fade out animation");
|
||||||
fadingOutContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
|
fadingOutContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
|
||||||
fadingOutContext->animationTime = adventureContext->animationTime;
|
fadingOutContext->animationTime = adventureContext->animationTime;
|
||||||
@ -366,6 +368,7 @@ void MapViewController::fadeOutObject(const CGObjectInstance * obj)
|
|||||||
|
|
||||||
void MapViewController::fadeInObject(const CGObjectInstance * obj)
|
void MapViewController::fadeInObject(const CGObjectInstance * obj)
|
||||||
{
|
{
|
||||||
|
animationWait.setBusy();
|
||||||
logGlobal->debug("Starting fade in animation");
|
logGlobal->debug("Starting fade in animation");
|
||||||
fadingInContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
|
fadingInContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
|
||||||
fadingInContext->animationTime = adventureContext->animationTime;
|
fadingInContext->animationTime = adventureContext->animationTime;
|
||||||
@ -505,6 +508,7 @@ void MapViewController::onAfterHeroTeleported(const CGHeroInstance * obj, const
|
|||||||
|
|
||||||
if(isEventVisible(obj, from, dest))
|
if(isEventVisible(obj, from, dest))
|
||||||
{
|
{
|
||||||
|
animationWait.setBusy();
|
||||||
logGlobal->debug("Starting teleport animation");
|
logGlobal->debug("Starting teleport animation");
|
||||||
teleportContext = std::make_shared<MapRendererAdventureTransitionContext>(*state);
|
teleportContext = std::make_shared<MapRendererAdventureTransitionContext>(*state);
|
||||||
teleportContext->animationTime = adventureContext->animationTime;
|
teleportContext->animationTime = adventureContext->animationTime;
|
||||||
@ -540,6 +544,7 @@ void MapViewController::onHeroMoved(const CGHeroInstance * obj, const int3 & fro
|
|||||||
|
|
||||||
if(movementTime > 1)
|
if(movementTime > 1)
|
||||||
{
|
{
|
||||||
|
animationWait.setBusy();
|
||||||
logGlobal->debug("Starting movement animation");
|
logGlobal->debug("Starting movement animation");
|
||||||
movementContext = std::make_shared<MapRendererAdventureMovingContext>(*state);
|
movementContext = std::make_shared<MapRendererAdventureMovingContext>(*state);
|
||||||
movementContext->animationTime = adventureContext->animationTime;
|
movementContext->animationTime = adventureContext->animationTime;
|
||||||
@ -577,6 +582,17 @@ bool MapViewController::hasOngoingAnimations()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapViewController::waitForOngoingAnimations()
|
||||||
|
{
|
||||||
|
auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
|
||||||
|
animationWait.waitWhileBusy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapViewController::endNetwork()
|
||||||
|
{
|
||||||
|
animationWait.requestTermination();
|
||||||
|
}
|
||||||
|
|
||||||
void MapViewController::activateAdventureContext(uint32_t animationTime)
|
void MapViewController::activateAdventureContext(uint32_t animationTime)
|
||||||
{
|
{
|
||||||
resetContext();
|
resetContext();
|
||||||
@ -642,6 +658,7 @@ void MapViewController::resetContext()
|
|||||||
worldViewContext.reset();
|
worldViewContext.reset();
|
||||||
spellViewContext.reset();
|
spellViewContext.reset();
|
||||||
puzzleMapContext.reset();
|
puzzleMapContext.reset();
|
||||||
|
animationWait.setFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapViewController::setTerrainVisibility(bool showAllTerrain)
|
void MapViewController::setTerrainVisibility(bool showAllTerrain)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "IMapRendererObserver.h"
|
#include "IMapRendererObserver.h"
|
||||||
|
#include "../ConditionalWait.h"
|
||||||
#include "../../lib/Point.h"
|
#include "../../lib/Point.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
@ -34,6 +35,8 @@ class MapRendererPuzzleMapContext;
|
|||||||
/// such as its position and any animations
|
/// such as its position and any animations
|
||||||
class MapViewController : public IMapObjectObserver
|
class MapViewController : public IMapObjectObserver
|
||||||
{
|
{
|
||||||
|
ConditionalWait animationWait;
|
||||||
|
|
||||||
std::shared_ptr<IMapRendererContext> context;
|
std::shared_ptr<IMapRendererContext> context;
|
||||||
std::shared_ptr<MapRendererContextState> state;
|
std::shared_ptr<MapRendererContextState> state;
|
||||||
std::shared_ptr<MapViewModel> model;
|
std::shared_ptr<MapViewModel> model;
|
||||||
@ -68,6 +71,9 @@ private:
|
|||||||
|
|
||||||
// IMapObjectObserver impl
|
// IMapObjectObserver impl
|
||||||
bool hasOngoingAnimations() override;
|
bool hasOngoingAnimations() override;
|
||||||
|
void waitForOngoingAnimations() override;
|
||||||
|
void endNetwork() override;
|
||||||
|
|
||||||
void onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator) override;
|
void onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator) override;
|
||||||
void onObjectFadeOut(const CGObjectInstance * obj, const PlayerColor & initiator) override;
|
void onObjectFadeOut(const CGObjectInstance * obj, const PlayerColor & initiator) override;
|
||||||
void onObjectInstantAdd(const CGObjectInstance * obj, const PlayerColor & initiator) override;
|
void onObjectInstantAdd(const CGObjectInstance * obj, const PlayerColor & initiator) override;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "../../lib/CGeneralTextHandler.h"
|
#include "../../lib/CGeneralTextHandler.h"
|
||||||
#include "../../lib/TerrainHandler.h"
|
#include "../../lib/TerrainHandler.h"
|
||||||
#include "../../lib/UnlockGuard.h"
|
|
||||||
#include "../../lib/mapObjectConstructors/CObjectClassesHandler.h"
|
#include "../../lib/mapObjectConstructors/CObjectClassesHandler.h"
|
||||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||||
#include "../../lib/mapObjects/ObjectTemplate.h"
|
#include "../../lib/mapObjects/ObjectTemplate.h"
|
||||||
@ -36,13 +35,19 @@ bool CMapHandler::hasOngoingAnimations()
|
|||||||
|
|
||||||
void CMapHandler::waitForOngoingAnimations()
|
void CMapHandler::waitForOngoingAnimations()
|
||||||
{
|
{
|
||||||
while(CGI->mh->hasOngoingAnimations())
|
for(auto * observer : observers)
|
||||||
{
|
{
|
||||||
auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
|
if (observer->hasOngoingAnimations())
|
||||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(1));
|
observer->waitForOngoingAnimations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMapHandler::endNetwork()
|
||||||
|
{
|
||||||
|
for(auto * observer : observers)
|
||||||
|
observer->endNetwork();
|
||||||
|
}
|
||||||
|
|
||||||
std::string CMapHandler::getTerrainDescr(const int3 & pos, bool rightClick) const
|
std::string CMapHandler::getTerrainDescr(const int3 & pos, bool rightClick) const
|
||||||
{
|
{
|
||||||
const TerrainTile & t = map->getTile(pos);
|
const TerrainTile & t = map->getTile(pos);
|
||||||
|
@ -71,6 +71,7 @@ public:
|
|||||||
|
|
||||||
/// blocking wait until all ongoing animatins are over
|
/// blocking wait until all ongoing animatins are over
|
||||||
void waitForOngoingAnimations();
|
void waitForOngoingAnimations();
|
||||||
|
void endNetwork();
|
||||||
|
|
||||||
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
|
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user