mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Minor fixes (possible surface leak);
This commit is contained in:
parent
4c636c15e9
commit
5a7a208617
@ -1272,12 +1272,15 @@ CFadeAnimation::~CFadeAnimation()
|
||||
SDL_FreeSurface(fadingSurface);
|
||||
}
|
||||
|
||||
void CFadeAnimation::init(EMode mode, float animDelta /* = DEFAULT_DELTA */, SDL_Surface * sourceSurface /* = nullptr */, bool freeSurfaceAtEnd /* = false */)
|
||||
void CFadeAnimation::init(EMode mode, SDL_Surface * sourceSurface, bool freeSurfaceAtEnd /* = false */, float animDelta /* = DEFAULT_DELTA */)
|
||||
{
|
||||
if (fading)
|
||||
{
|
||||
// in that case, immediately finish the previous fade
|
||||
// (alternatively, we could just return here to ignore the new fade request until this one finished (but we'd need to free the passed bitmap to avoid leaks))
|
||||
logGlobal->warnStream() << "Tried to init fading animation that is already running.";
|
||||
return;
|
||||
if (fadingSurface && shouldFreeSurface)
|
||||
SDL_FreeSurface(fadingSurface);
|
||||
}
|
||||
if (animDelta <= 0.0f)
|
||||
{
|
||||
|
@ -243,7 +243,7 @@ public:
|
||||
|
||||
CFadeAnimation();
|
||||
~CFadeAnimation();
|
||||
void init(EMode mode, float animDelta = DEFAULT_DELTA, SDL_Surface * sourceSurface = nullptr, bool freeSurfaceAtEnd = false);
|
||||
void init(EMode mode, SDL_Surface * sourceSurface, bool freeSurfaceAtEnd = false, float animDelta = DEFAULT_DELTA);
|
||||
void update();
|
||||
void draw(SDL_Surface * targetSurface, const SDL_Rect * sourceRect, SDL_Rect * destRect);
|
||||
bool isFading() const { return fading; }
|
||||
|
@ -1228,7 +1228,7 @@ bool CMapHandler::printObject(const CGObjectInstance *obj, bool fadein /* = fals
|
||||
auto tmp = CSDL_Ext::newSurface(bitmap->w, bitmap->h);
|
||||
SDL_BlitSurface(bitmap, nullptr, tmp, nullptr); // can't be 8bpp for fading
|
||||
auto anim = new CFadeAnimation();
|
||||
anim->init(CFadeAnimation::EMode::IN, 0.05f, tmp, true);
|
||||
anim->init(CFadeAnimation::EMode::IN, tmp, true);
|
||||
fadeAnims[++fadeAnimCounter] = std::pair<int3, CFadeAnimation*>(int3(fx, fy, obj->pos.z), anim);
|
||||
toAdd.fadeAnimKey = fadeAnimCounter;
|
||||
}
|
||||
@ -1276,7 +1276,7 @@ bool CMapHandler::hideObject(const CGObjectInstance *obj, bool fadeout /* = fals
|
||||
SDL_BlitSurface(bitmap, nullptr, tmp, nullptr); // can't be 8bpp for fading
|
||||
|
||||
auto anim = new CFadeAnimation();
|
||||
anim->init(CFadeAnimation::EMode::OUT, 0.05f, tmp, true);
|
||||
anim->init(CFadeAnimation::EMode::OUT, tmp, true);
|
||||
fadeAnims[++fadeAnimCounter] = std::pair<int3, CFadeAnimation*>(int3(i, j, k), anim);
|
||||
ttiles[i][j][k].objects[x].fadeAnimKey = fadeAnimCounter;
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ void CTerrainRect::fadeFromCurrentView()
|
||||
if (!fadeSurface)
|
||||
fadeSurface = CSDL_Ext::newSurface(pos.w, pos.h);
|
||||
SDL_BlitSurface(screen, &pos, fadeSurface, nullptr);
|
||||
fadeAnim->init(CFadeAnimation::EMode::OUT, 0.05f, fadeSurface);
|
||||
fadeAnim->init(CFadeAnimation::EMode::OUT, fadeSurface);
|
||||
}
|
||||
|
||||
bool CTerrainRect::needsAnimUpdate()
|
||||
@ -979,11 +979,11 @@ void CAdvMapInt::selectionChanged()
|
||||
select(to);
|
||||
}
|
||||
|
||||
void CAdvMapInt::centerOn(int3 on, bool fadeIfZChanged /* = false */)
|
||||
void CAdvMapInt::centerOn(int3 on, bool fade /* = false */)
|
||||
{
|
||||
bool switchedLevels = on.z != position.z;
|
||||
|
||||
if (fadeIfZChanged)
|
||||
if (fade)
|
||||
{
|
||||
terrain.fadeFromCurrentView();
|
||||
}
|
||||
@ -1018,9 +1018,9 @@ void CAdvMapInt::centerOn(int3 on, bool fadeIfZChanged /* = false */)
|
||||
terrain.redraw();
|
||||
}
|
||||
|
||||
void CAdvMapInt::centerOn(const CGObjectInstance *obj, bool fadeIfZChanged /* = false */)
|
||||
void CAdvMapInt::centerOn(const CGObjectInstance *obj, bool fade /* = false */)
|
||||
{
|
||||
centerOn(obj->getSightCenter(), fadeIfZChanged);
|
||||
centerOn(obj->getSightCenter(), fade);
|
||||
}
|
||||
|
||||
void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
|
||||
|
@ -186,8 +186,8 @@ public:
|
||||
|
||||
void select(const CArmedInstance *sel, bool centerView = true);
|
||||
void selectionChanged();
|
||||
void centerOn(int3 on, bool fadeIfZChanged = false);
|
||||
void centerOn(const CGObjectInstance *obj, bool fadeIfZChanged = false);
|
||||
void centerOn(int3 on, bool fade = false);
|
||||
void centerOn(const CGObjectInstance *obj, bool fade = false);
|
||||
int3 verifyPos(int3 ver);
|
||||
void handleRightClick(std::string text, tribool down);
|
||||
void keyPressed(const SDL_KeyboardEvent & key);
|
||||
|
Loading…
Reference in New Issue
Block a user