c++ - Same simulation on every platform with correct compiler flags -


i developing game remnants of naezith around 2.5 years , backbone of game leaderboard has replays. game deterministic same inputs lead same simulation every single time. game fully written scratch in c++ , sfml.

months ago changed gcc compiler 64bit 32bit or reverse, don't remember correctly problem was, old replays not working in new compiler. when searched it, floating point math being different between two.

i fixed putting -msse2 -mfpmath=sse. working same.

today compiled , ran game in debug mode , first time saw of replays desync again. when searched it, it's caused -ofast flag use @ release build. because -ofast flag has -ffast-math in it. makes difference in calculations, simulation differs.

currently using -ofast flag not cause issues because plays in build has flag.

in future i'd port game mac, linux, ps4, xbox or else. leaderboards on own server want use same leaderboards shared platforms. that's why need game work same on every platform.

my doubt if keep -ofast, play , when need port game platform, might need change compiler , compiler might not have same flag, or math may working differently in compiler.

which flags should avoid , flags should choose make sure simulate same replay, same in every platform?

edit: avoiding -ofast rid of -ffast-math sounds obvious else should use , fine after that?

this difficult achieve.

certainly if targeting 32bit , 64bit x86/amd64 architectures want use sse both, otherwise on 32 bit x86 may end using x87 cause differences.

even if can iron out differences in own compiled code, encounter differences in standard library. instance, i've come across differences in implementation of std::pow() between freebsd/solaris , linux.

i suppose using fixed point representation out of question?


Comments