Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved performance of city strategy view mode #247

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

redv
Copy link
Collaborator

@redv redv commented Nov 14, 2017

The city strategy view mode on steroids.

  • All layers of the strategy view mode prerendered separately into a cache.
  • Surfaces for the cache provided on demand i.e. if the layer 0 hasn't objects for render then surface 0 almost not consume memory.
  • Surface will be invalidated and rerendered when any tile at this layer will be changed.

@@ -76,6 +77,8 @@ class TileMap
private:
std::vector<Tile> tiles;
std::vector<std::set<TileObject::Type>> layerMap;
// Cache for the strategy view mode.
std::vector<sp<Surface>> strategyViewCache;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I like the cached images being stored in the game/state - it feels very much like a UI-specific thing. Perhaps this is the best place to keep the "dirty" state though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point.
Possible approach may be to create cache in the TileView. But in this case the TileObjectScenery and the TileObjectBattleMapPart should to know about TileView (or at least about the cache). It's not so easy to find a clever way to do this.

The TileMap lies in the key place which can be easily accessed as for CityTileView and for the BattleTileView and for TileObjects too. Thus the cache easely accessed for each who should to use it.

@@ -1486,6 +1488,7 @@ void Scenery::updateFalling(GameState &state, unsigned int ticks)
{
auto fallTicksRemaining = ticks;
auto newPosition = currentPosition;
state.current_city->map->setViewSurfaceDirty(currentPosition.z);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the setViewSurfaceDirty() should be moved to the TileObject parent class? So that at TileObject add/remove/move it can mark the correct dirty bit? Perhaps have a dirty bit per "layer" (TileMap::layerMap) to

This will still need special handling for sprites that can change (if you want to handle more than the scenery layer) -
e.g. doodads/animations changing frame, vehicles/agents/projectiles when they rotate - or just not enable caches for those layers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, its a good architectural approach.
I think only Scenery and BattleMapParts should be drawn to the cache. Thus only these classes can set the cache dirty.

Vehicles, units, projectiles etc should be handled separately because they movable.

@redv
Copy link
Collaborator Author

redv commented Nov 27, 2017

The same for the battle strategy view mode.

@makus82
Copy link
Contributor

makus82 commented Nov 28, 2017

Hey redv great work
can you pls also turn off night in strategy view?)
#242
... if i correctly understand what you doing =P
in this issue i mean map mode from top view

@redv
Copy link
Collaborator Author

redv commented Nov 28, 2017

It's a GOOD question. Possible a mess of dark and light layers. Need to find a way to avoid this.

@JonnyH
Copy link
Collaborator

JonnyH commented Nov 29, 2017

You could store off the palette for the last time the cache was created, compare it at the beginning of the render and if it's changed invalidate it?

The palette values will change by (worst cast 0->255 palette swing) 255 over 3 in-game hours (from what I remember), so there should be ~40 ingame seconds between each palette change - still likely worth this optimisation for everything but the fastest turbo mode.

@redv
Copy link
Collaborator Author

redv commented Nov 29, 2017

The palette changes every update. First of all because of the colorCurrent.
Secondly because of interpolated_palette.

Possible to check colors inside palette, but in this case from time to time will be need to redraw whole map. This behavior will lead to jerks which will looks annoying.

In the other hand, dark palette for strategy view is good as an option but not for regular game. I think the sprites for the strategy view mode were not designed for dark palette.

BTW recalculate interpolated_palette every update not so good idea. Even in worst case the interpolated_palette should be recalculated every 6h * 60min/h / 256 = 1,4 ingame mins (once per 3000-5000 updates at normal speed). Last 4 color easy to set during each update.
I think it possible to optimize.

@FilmBoy84
Copy link
Collaborator

Please see issue #339 for another problem that slows cityscape performance. Many thanks.

@FilmBoy84 FilmBoy84 added the STALLED Work In Progress but for whatever reason, nothing's been done for a while. New coders may be needed! label Jan 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STALLED Work In Progress but for whatever reason, nothing's been done for a while. New coders may be needed!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants