I’m working on a scrolling arcade shooter in C++ with SDL2 and I’d like to have a replay function so players can save, share, and replay good runs. I understand that floating point math is not consistent from CPU to CPU, so saving inputs with frame counters won’t give you stable replays. I saw someone mention that fixed point math is a possible solution, so I’m currently working on a C++ engine using Libfixmath
fix16_t datatypes in place of anything that would be a floating point.
Should this give me 100% deterministic replays across hardware if I save the random seed? From my understanding of how a fixed point math library works that should be the case, but I would like some confirmation before I bank my entire engine around this. Really my only concern is that I’m using literal floats to set the starting values for some things, like
fix16_from_float(1.2) to set the player’s movement speed and I’m not entirely sure if CPU inconsistency could mess up that initial value and thus defeat the purpose. If so, could I solve the problem by using
fix16_from_int() paired with some Libfixmath arithmetic to get the same non-integer values without ever using floats? I don’t quite have a complete grasp on how literals are stored into a compiled program.
I am also a tad worried about performance with potentially hundreds of onscreen bullets using high level fixed point math every frame, but I’ll have to see how much impact that has when I get to it.