1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-01 23:12:49 +02:00

Temporarily(?) use weak_ptr to reduce ram usage increase during long

game sessions
This commit is contained in:
Ivan Savenko
2025-03-16 17:35:31 +00:00
parent ded12f2df9
commit 8a0fed7b3a
4 changed files with 27 additions and 18 deletions

View File

@@ -246,7 +246,7 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
else
algorithm = EScalingAlgorithm::XBRZ_ALPHA;
auto result = std::make_shared<SDLImageShared>(this, factor, algorithm);
auto result = SDLImageShared::createScaled(this, factor, algorithm);
if (surf->format->palette)
SDL_SetSurfacePalette(surf, originalPalette);
@@ -254,28 +254,31 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
return result;
}
SDLImageShared::SDLImageShared(const SDLImageShared * from, int integerScaleFactor, EScalingAlgorithm algorithm)
std::shared_ptr<SDLImageShared> SDLImageShared::createScaled(const SDLImageShared * from, int integerScaleFactor, EScalingAlgorithm algorithm)
{
auto self = std::make_shared<SDLImageShared>(nullptr);
static tbb::task_arena upscalingArena;
upscalingInProgress = true;
self->upscalingInProgress = true;
auto scaler = std::make_shared<SDLImageScaler>(from->surf, Rect(from->margins, from->fullSize), true);
const auto & scalingTask = [this, algorithm, scaler]()
const auto & scalingTask = [self, algorithm, scaler]()
{
scaler->scaleSurfaceIntegerFactor(GH.screenHandler().getScalingFactor(), algorithm);
surf = scaler->acquireResultSurface();
fullSize = scaler->getResultDimensions().dimensions();
margins = scaler->getResultDimensions().topLeft();
upscalingInProgress = false;
self->surf = scaler->acquireResultSurface();
self->fullSize = scaler->getResultDimensions().dimensions();
self->margins = scaler->getResultDimensions().topLeft();
self->upscalingInProgress = false;
};
if(settings["video"]["asyncUpscaling"].Bool())
upscalingArena.enqueue(scalingTask);
else
scalingTask();
return self;
}
bool SDLImageShared::isLoading() const