cxong / cdogs-sdl

Classic overhead run-and-gun game
https://cxong.github.io/cdogs-sdl/
GNU General Public License v2.0
901 stars 115 forks source link

Optimisations for GCW-Zero, Pandora #500

Closed cxong closed 5 years ago

cxong commented 7 years ago

capture capture1 capture2 capture3 capture4 capture5 capture6

Profiling from visual studio on doom mission 3 shows update and draw both taking about 40% CPU. Expensive operations include:

Two obvious optimisations: HUD is unexpectedly expensive, even more expensive than drawing the game, and also the map has lots of actors so lots of the update expense is on basic updating and collision detection.

cxong commented 7 years ago

FPS on GCW-Zero is about 8

cxong commented 7 years ago

Update AI every 4 frames; this reduced the cost of UpdateAllActors, so approximately 3% speedup. image More can be done; on this mission there are about 114 enemies. Updating a fixed number of AIs per frame (say 10) should make the AI a fixed cost. This can be improved so that enemies closer to the players are prioritised.

Next most expensive function:

cxong commented 6 years ago

New profiling:

image

Areas to improve:

cxong commented 6 years ago

Optimised DrawFloor by drawing as textures - percent of time dropped to 1.22%. Strangely now the whole game takes 75% CPU instead of 99% before.

image

One side effect is that the blob shadows need to be redone otherwise they don't show up properly over the floor.

cxong commented 6 years ago

Some of the optimisations have to do with rendering textures instead of to a pixel array. However we still need to render to a single "surface", for the game background and for the editor. But in this case, we should be using SDL_SetRenderTarget, so that the drawing code doesn't change. Replace the renderToTex parameters added recently.

cxong commented 6 years ago

image

Converted more blitting functions to use texture rendering. This has dropped DrawWallsAndThings from 8% down to 4%, although strangely total CPU has dropped to 50% and DrawDebris has gone up from 2% to 4%. Maybe there's some extra graphics latency here?

This has also introduced some graphics glitches. Map objects like barrels appear behind walls - perhaps walls are still being blitted. "Background" tinted objects like gas clouds no longer look right, will need to redo them.

cxong commented 6 years ago

image Profiling results after character blitting converted to texture renders. Curiously the overall draw time hasn't reduced by much, although DrawFloor has shot up.

Need to benchmark under GCW-Zero; perhaps there is too much slowdown caused by rendering many small textures. Switching to texture atlases may be necessary.

cxong commented 6 years ago

Unfortunately performance on GCW-Zero has become worse, at about 6fps.

cxong commented 5 years ago

Abandoning this for now; will possibly revisit once we look into a handheld platform again