Skip to content

Commit

Permalink
Remove [[maybe_unused]]animationTime as indeed buildings with anima…
Browse files Browse the repository at this point in the history
…tion (radar) is not cached.

Clean up `cUnitDrawingEngine::drawUnit`.
  • Loading branch information
Jarod42 committed Mar 9, 2024
1 parent e0a56ee commit 75ef752
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 36 deletions.
6 changes: 2 additions & 4 deletions src/ui/graphical/game/temp/drawingcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ void cDrawingCache::setPlayer (const cPlayer* player_)
}

//------------------------------------------------------------------------------
SDL_Surface* cDrawingCache::getCachedImage (const cBuilding& building, double zoom, [[maybe_unused]]unsigned long long animationTime)
SDL_Surface* cDrawingCache::getCachedImage (const cBuilding& building, double zoom)
{
// TODO: handle animationTime
if (!canCache (building)) return nullptr;

for (unsigned int i = 0; i < cacheSize; i++)
Expand Down Expand Up @@ -250,9 +249,8 @@ SDL_Surface* cDrawingCache::getCachedImage (const cVehicle& vehicle, double zoom
}

//------------------------------------------------------------------------------
SDL_Surface* cDrawingCache::createNewEntry (const cBuilding& building, double zoom, [[maybe_unused]]unsigned long long animationTime)
SDL_Surface* cDrawingCache::createNewEntry (const cBuilding& building, double zoom)
{
// TODO: handle animationTime
if (!canCache (building))
return nullptr;

Expand Down
4 changes: 2 additions & 2 deletions src/ui/graphical/game/temp/drawingcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ class cDrawingCache
* This method looks for a cached image, that matches the properties of the passed building.
* @return a pointer to a surface, which contains the already rendered image of the building or nullptr when no matching cache entry exists.
*/
SDL_Surface* getCachedImage (const cBuilding& building, double zoom, unsigned long long animationTime);
SDL_Surface* getCachedImage (const cBuilding& building, double zoom);
SDL_Surface* getCachedImage (const cVehicle& vehicle, double zoom, const cMapView& map, unsigned long long animationTime);
/**
* This method creates a new chace entry, when there is space in the cache.
* When there is no free space, an old entry is reused.
* When there is no free space and no old entries, nullptr is returned.
* @return a surface to which the building has to be drawn, after calling this function. Returns nullptr when the cache is full.
*/
SDL_Surface* createNewEntry (const cBuilding& building, double zoom, unsigned long long animationTime);
SDL_Surface* createNewEntry (const cBuilding& building, double zoom);
SDL_Surface* createNewEntry (const cVehicle& vehicle, double zoom, const cMapView& map, unsigned long long animationTime);
/**
* Deletes all cache entries.
Expand Down
51 changes: 21 additions & 30 deletions src/ui/graphical/game/temp/unitdrawingengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,24 @@ void cUnitDrawingEngine::setDrawColor (bool drawColor)
//------------------------------------------------------------------------------
void cUnitDrawingEngine::drawUnit (const cBuilding& building, SDL_Rect destination, float zoomFactor, const cUnitSelection* unitSelection, const cPlayer* player, const std::vector<cResearch::eResearchArea>& currentTurnResearchAreasFinished)
{
unsigned long long animationTime = animationTimer->getAnimationTime(); //call getAnimationTime only once in this method and save the result,
//to avoid a changing time within this method
// call getAnimationTime only once in this method and save the result,
// to avoid a changing time within this method
const unsigned long long animationTime = animationTimer->getAnimationTime();

SDL_Rect dest = {0, 0, 0, 0};
bool bDraw = false;
SDL_Surface* drawingSurface = drawingCache.getCachedImage (building, zoomFactor, animationTime);
SDL_Surface* drawingSurface = drawingCache.getCachedImage (building, zoomFactor);
if (drawingSurface == nullptr)
{
// no cached image found. building needs to be redrawn.
bDraw = true;
drawingSurface = drawingCache.createNewEntry (building, zoomFactor, animationTime);
}
drawingSurface = drawingCache.createNewEntry (building, zoomFactor);

if (drawingSurface == nullptr)
{
// image will not be cached. So blitt directly to the screen buffer.
dest = destination;
drawingSurface = cVideo::buffer;
}
if (drawingSurface == nullptr)
{
// image will not be cached. So blitt directly to the screen buffer.
dest = destination;
drawingSurface = cVideo::buffer;
}

if (bDraw)
{
render (building, animationTime, *drawingSurface, dest, zoomFactor, cSettings::getInstance().isShadows(), true);
}

Expand Down Expand Up @@ -179,8 +175,9 @@ void cUnitDrawingEngine::drawUnit (const cBuilding& building, SDL_Rect destinati
//------------------------------------------------------------------------------
void cUnitDrawingEngine::drawUnit (const cVehicle& vehicle, SDL_Rect destination, float zoomFactor, const cMapView& map, const cUnitSelection* unitSelection, const cPlayer* player)
{
unsigned long long animationTime = animationTimer->getAnimationTime(); //call getAnimationTime only once in this method and save the result,
//to avoid a changing time within this method
// call getAnimationTime only once in this method and save the result,
// to avoid a changing time within this method
const unsigned long long animationTime = animationTimer->getAnimationTime();

// calculate screen position
int ox = (int) (vehicle.getMovementOffset().x() * zoomFactor);
Expand All @@ -195,26 +192,20 @@ void cUnitDrawingEngine::drawUnit (const cVehicle& vehicle, SDL_Rect destination
destination.y += vehicle.dither.y();
}

SDL_Rect dest;
dest.x = dest.y = 0;
bool bDraw = false;
SDL_Rect dest{};
SDL_Surface* drawingSurface = drawingCache.getCachedImage (vehicle, zoomFactor, map, animationTime);
if (drawingSurface == nullptr)
{
// no cached image found. building needs to be redrawn.
bDraw = true;
drawingSurface = drawingCache.createNewEntry (vehicle, zoomFactor, map, animationTime);
}

if (drawingSurface == nullptr)
{
// image will not be cached. So blitt directly to the screen buffer.
dest = destination;
drawingSurface = cVideo::buffer;
}
if (drawingSurface == nullptr)
{
// image will not be cached. So blitt directly to the screen buffer.
dest = destination;
drawingSurface = cVideo::buffer;
}

if (bDraw)
{
render (vehicle, &map, animationTime, player, *drawingSurface, dest, zoomFactor, cSettings::getInstance().isShadows());
}

Expand Down

0 comments on commit 75ef752

Please sign in to comment.