mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Fix graphical artifact in hero movement animation
This commit is contained in:
@@ -88,7 +88,7 @@ std::shared_ptr<IMapRendererContext> MapViewController::getContext() const
|
||||
return context;
|
||||
}
|
||||
|
||||
void MapViewController::update(uint32_t timeDelta)
|
||||
void MapViewController::updateBefore(uint32_t timeDelta)
|
||||
{
|
||||
// confirmed to match H3 for
|
||||
// - hero embarking on boat (500 ms)
|
||||
@@ -116,56 +116,32 @@ void MapViewController::update(uint32_t timeDelta)
|
||||
settings["adventure"]["enemyMoveTime"].Float();
|
||||
|
||||
movementContext->progress += timeDelta / heroMoveTime;
|
||||
movementContext->progress = std::min( 1.0, movementContext->progress);
|
||||
|
||||
Point positionFrom = Point(hero->convertToVisitablePos(movementContext->tileFrom)) * model->getSingleTileSize() + model->getSingleTileSize() / 2;
|
||||
Point positionDest = Point(hero->convertToVisitablePos(movementContext->tileDest)) * model->getSingleTileSize() + model->getSingleTileSize() / 2;
|
||||
|
||||
Point positionCurr = vstd::lerp(positionFrom, positionDest, movementContext->progress);
|
||||
|
||||
if(movementContext->progress >= 1.0)
|
||||
{
|
||||
setViewCenter(hero->getSightCenter());
|
||||
|
||||
removeObject(context->getObject(movementContext->target));
|
||||
addObject(context->getObject(movementContext->target));
|
||||
|
||||
activateAdventureContext(movementContext->animationTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
setViewCenter(positionCurr, movementContext->tileDest.z);
|
||||
}
|
||||
setViewCenter(positionCurr, movementContext->tileDest.z);
|
||||
}
|
||||
|
||||
if(teleportContext)
|
||||
{
|
||||
teleportContext->progress += timeDelta / heroTeleportDuration;
|
||||
if(teleportContext->progress >= 1.0)
|
||||
{
|
||||
activateAdventureContext(teleportContext->animationTime);
|
||||
}
|
||||
teleportContext->progress = std::min( 1.0, teleportContext->progress);
|
||||
}
|
||||
|
||||
if(fadingOutContext)
|
||||
{
|
||||
fadingOutContext->progress -= timeDelta / fadeOutDuration;
|
||||
|
||||
if(fadingOutContext->progress <= 0.0)
|
||||
{
|
||||
removeObject(context->getObject(fadingOutContext->target));
|
||||
|
||||
activateAdventureContext(fadingOutContext->animationTime);
|
||||
}
|
||||
fadingOutContext->progress = std::max( 0.0, fadingOutContext->progress);
|
||||
}
|
||||
|
||||
if(fadingInContext)
|
||||
{
|
||||
fadingInContext->progress += timeDelta / fadeInDuration;
|
||||
|
||||
if(fadingInContext->progress >= 1.0)
|
||||
{
|
||||
activateAdventureContext(fadingInContext->animationTime);
|
||||
}
|
||||
fadingInContext->progress = std::min( 1.0, fadingInContext->progress);
|
||||
}
|
||||
|
||||
if(adventureContext)
|
||||
@@ -180,6 +156,48 @@ void MapViewController::update(uint32_t timeDelta)
|
||||
}
|
||||
}
|
||||
|
||||
void MapViewController::updateAfter(uint32_t timeDelta)
|
||||
{
|
||||
if(movementContext)
|
||||
{
|
||||
const auto * object = context->getObject(movementContext->target);
|
||||
const auto * hero = dynamic_cast<const CGHeroInstance *>(object);
|
||||
const auto * boat = dynamic_cast<const CGBoat *>(object);
|
||||
|
||||
assert(boat || hero);
|
||||
|
||||
if(!hero)
|
||||
hero = boat->hero;
|
||||
|
||||
if(movementContext->progress >= 1.0)
|
||||
{
|
||||
setViewCenter(hero->getSightCenter());
|
||||
|
||||
removeObject(context->getObject(movementContext->target));
|
||||
addObject(context->getObject(movementContext->target));
|
||||
|
||||
activateAdventureContext(movementContext->animationTime);
|
||||
}
|
||||
}
|
||||
|
||||
if(teleportContext && teleportContext->progress >= 1.0)
|
||||
{
|
||||
activateAdventureContext(teleportContext->animationTime);
|
||||
}
|
||||
|
||||
if(fadingOutContext && fadingOutContext->progress <= 0.0)
|
||||
{
|
||||
removeObject(context->getObject(fadingOutContext->target));
|
||||
|
||||
activateAdventureContext(fadingOutContext->animationTime);
|
||||
}
|
||||
|
||||
if(fadingInContext && fadingInContext->progress >= 1.0)
|
||||
{
|
||||
activateAdventureContext(fadingInContext->animationTime);
|
||||
}
|
||||
}
|
||||
|
||||
bool MapViewController::isEventVisible(const CGObjectInstance * obj)
|
||||
{
|
||||
if(adventureContext == nullptr)
|
||||
|
||||
Reference in New Issue
Block a user