beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
182 stars 95 forks source link

Large grid of building placements lags #1472

Open jacobguenther opened 2 months ago

jacobguenther commented 2 months ago

There is already a BAR issue for this but I believe it is an engine optimization problem. When you use shift+alt to make a large grid of buildings the game goes to 1fps.

jacobguenther commented 2 months ago

By commenting out various parts of drawMapStuff I found that unitDrawer->ShowUnitBuildSquare is the slowest part. Perhaps a new function ShowUnitBuildSquares could be introduced which takes a vector of buildInfos and draws all of them at once. Even A naive approach could be beneficial.

I'm not sure what facilities the engine has for instanced rendering but with instanced rendering we could reduce the amount of processing on the cpu and data that we send. Instead of calculating each vertex for each square on the cpu that could be done gpu side. We could send just the quad for a square and as instance data a offset(vec3) and type(int) which can be mapped to a color.

jacobguenther commented 2 months ago

I also found some redundant or unused things.

unitDrawer->ShowUnitBuildSquare is used in an if else statement where each branch has glcolor4f(...) but glcolor4f wouldn't do anything there.

buildColors gets cleared and reserved but isn't used for anything.

The constructor for BuildInfo makes sure buildFacing is valid by using the % operator. In FillRowOfBuildPos the % is used again to make sure buildFacing is valid. I think a copy constructor for BuildInfo could be added that doesn't check buildFacing.

In GetBuildPositions buildInfos gets clear() and reserve(16) called on it and then we find the max size it could be with xnum and znum. There is also a comment // circle build around building. I haven't seen that in a game.