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

Spread `CGround::GetWater(Plane)Level` across engine code #1445

Open sprunk opened 3 months ago

sprunk commented 3 months ago

Most water-adjacent logic uses a hardcoded magic number 0 for water level. There is a CGround::GetWaterLevel(x, z) function which should be spread far and wide. For cases where we have no XZ coordinates there's also CGround::GetWaterPlaneLevel(). Using the appropriate one would let us discover how many places use the assumption that water is a flat plane.

The difficulty is to find all the uses (zero is a very specific number and is extremely good at hiding).

This is a technical chore task whose benefit is to enable further changes down the line, plus a bit of engine code self-documentation.

https://github.com/beyond-all-reason/spring/blob/e55ce6231a0b125f41f56688277dca95ddc7b3bd/rts/Map/Ground.h#L23-L38

6AKU66 commented 3 months ago

Offtopic: recently i was profiling a gamematch and saw that some functions like GetHeightReal can be called multiple times and it's make me wonder: "can we calculate once and then just cache result per simframe for those instead of recalculating over and over again." I expect an answer: "not in all cases".

Sorry, my random thoughts.

sprunk commented 3 months ago

These are constexpr/consteval for now so should not cause any perf overhead.