|
@@ -47,22 +47,16 @@ void BattleObstacleController::loadObstacleImage(const CObstacleInstance & oi)
|
|
|
{
|
|
|
AnimationPath animationName = oi.getAnimation();
|
|
|
|
|
|
- if (animationsCache.count(animationName) == 0)
|
|
|
+ if (oi.obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)
|
|
|
{
|
|
|
- if (oi.obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)
|
|
|
- {
|
|
|
- // obstacle uses single bitmap image for animations
|
|
|
- auto animation = GH.renderHandler().createAnimation();
|
|
|
- animation->setCustom(animationName.getName(), 0, 0);
|
|
|
- animationsCache[animationName] = animation;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- auto animation = GH.renderHandler().loadAnimation(animationName, EImageBlitMode::COLORKEY);
|
|
|
- animationsCache[animationName] = animation;
|
|
|
- }
|
|
|
+ // obstacle uses single bitmap image for animations
|
|
|
+ obstacleImages[oi.uniqueID] = GH.renderHandler().loadImage(animationName.toType<EResType::IMAGE>(), EImageBlitMode::COLORKEY);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ obstacleAnimations[oi.uniqueID] = GH.renderHandler().loadAnimation(animationName, EImageBlitMode::COLORKEY);
|
|
|
+ obstacleImages[oi.uniqueID] = obstacleAnimations[oi.uniqueID]->getImage(0);
|
|
|
}
|
|
|
- obstacleAnimations[oi.uniqueID] = animationsCache[animationName];
|
|
|
}
|
|
|
|
|
|
void BattleObstacleController::obstacleRemoved(const std::vector<ObstacleChanges> & obstacles)
|
|
@@ -96,6 +90,7 @@ void BattleObstacleController::obstacleRemoved(const std::vector<ObstacleChanges
|
|
|
owner.stacksController->addNewAnim(new EffectAnimation(owner, animationPath, whereTo, obstacle["position"].Integer(), 0, true));
|
|
|
|
|
|
obstacleAnimations.erase(oi.id);
|
|
|
+ obstacleImages.erase(oi.id);
|
|
|
//so when multiple obstacles are removed, they show up one after another
|
|
|
owner.waitForAnimations();
|
|
|
}
|
|
@@ -182,26 +177,22 @@ void BattleObstacleController::collectRenderableObjects(BattleRenderer & rendere
|
|
|
void BattleObstacleController::tick(uint32_t msPassed)
|
|
|
{
|
|
|
timePassed += msPassed / 1000.f;
|
|
|
+ int framesCount = timePassed * AnimationControls::getObstaclesSpeed();
|
|
|
+
|
|
|
+ for(auto & animation : obstacleAnimations)
|
|
|
+ {
|
|
|
+ int frameIndex = framesCount % animation.second->size(0);
|
|
|
+ obstacleImages[animation.first] = animation.second->getImage(frameIndex, 0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
std::shared_ptr<IImage> BattleObstacleController::getObstacleImage(const CObstacleInstance & oi)
|
|
|
{
|
|
|
- int framesCount = timePassed * AnimationControls::getObstaclesSpeed();
|
|
|
- std::shared_ptr<CAnimation> animation;
|
|
|
-
|
|
|
// obstacle is not loaded yet, don't show anything
|
|
|
- if (obstacleAnimations.count(oi.uniqueID) == 0)
|
|
|
+ if (obstacleImages.count(oi.uniqueID) == 0)
|
|
|
return nullptr;
|
|
|
|
|
|
- animation = obstacleAnimations[oi.uniqueID];
|
|
|
- assert(animation);
|
|
|
-
|
|
|
- if(animation)
|
|
|
- {
|
|
|
- int frameIndex = framesCount % animation->size(0);
|
|
|
- return animation->getImage(frameIndex, 0);
|
|
|
- }
|
|
|
- return nullptr;
|
|
|
+ return obstacleImages[oi.uniqueID];
|
|
|
}
|
|
|
|
|
|
Point BattleObstacleController::getObstaclePosition(std::shared_ptr<IImage> image, const CObstacleInstance & obstacle)
|