Performance is being killed by the trajectory calculation
The calculation of the trajectory of the ship and the targeted planet/station/star consumes a lot of cpu slowing down the whole game. It could be worked around by decreasing the ship.trajectory
value to something where you get an acceptable framerate but it would make the game quite harder to reach other bodies if ship.trajectory
is too low.
Vaguely speaking it takes an astounding amount of cpu time,say when it is disabled (ship.trajectory = 0
) the framerate i could achieve without vsync is +200fps
while when it is enabled with a value around 160
it delivers <50fps
.
By a quick look thru the code the algorithm being used is the 'All-pairs N-Body' algorithm wich computational complexity is O(N^2), not a big deal since for the case of the game N is teh amount of bodies in the simulation, those being the stars in the current system when playing and those are quite low (say 32 of less bodies), the performance drop is due to that algorithm being called many many times (especifically ship.trajectory
times) for each frame being calculated. That ends being A LOT of cpu time.
Suggestions:
-
As of now the simulation is done in "realtime" and it is smooth if a decent framerate is achieved, but maybe the calculations could be done each 2 frames and see if it's still accurate enough and/or bumps up the overrall performance enough for it being worthy.
-
Another suggestion could be checking if off-loading some work to another compute device like a gpu could achieve enough performance to being worth of caring, although it could bring destabilization to the game or become exclusive to players featuring specific devices (maybe the latter could be avoided by making it optional).
EDIT: Forked the project to test out an initial opencl integration made for the trajectory calculation, so far it does hold a little speed gain but there are many things to tweak yet and it needs more testing. If interested you can check it out and try it. (https://gitlab.com/No-one-you-know/bussard/tree/opencl)