Sunday, September 11, 2022
HomeGame Developmentc++ - Consistent cross platform procedural technology

c++ – Consistent cross platform procedural technology


What strategies have folks efficiently used or can recommend to cope with a constant cross platform math for procedural world technology? Also, you probably have carried out this, what had been the professionals and cons of your strategy?

Context: I’m constructing a sport (in C++) that includes producing a 400 billion star galaxy, for which I’m utilizing procedural technology. The goal platforms are Android (Arm-v8a), Linux (x86-64), and possibly Windows (x86-64). The problem is that this technology includes fairly a little bit of math, together with exp, pow, sqrt, sin, cos, tan and atan2, and the system is ill-conditioned (tiny variations within the calculations may propagate to giant variations within the output, like a star turning up or not, or perhaps a complete area of stars altering). I would like the identical seed to generate precisely the identical galaxy on all platforms in case I ever need a multi-player model of this.

My studying to date is that totally different processors, compilers or libraries can’t be assured to return the identical outcomes for transcendental capabilities, and even easy floating level math is likely to be an issue (equivalent to Arm utilizing a multiply-add instruction having higher intermediate precision than the x86-64 utilizing two directions).

Things I’ve thought-about:

  • Using double precision floating level, together with the identical transcendental operate code to generate the identical outcomes (which I’ve needed to do anyway in order that I can vectorize them), and tweaking the compiler flags in order that every little thing compiles precisely the identical means on each processors, and depend on IEE-754 conformance to care for the remaining. Pros: simple to do. Cons: cannot ensure that I’ve eradicated inconsistencies however makes them a lot tougher to seek out. Also setting these flags are going to lead to sub-optimal efficiency in different areas of the code the place consistency would not matter.

  • Using a light-weight mounted level framework equivalent to fixedptc.h so I’m solely doing integer math. Pros: will certainly be constant. Cons: numerous effort to scale every little thing accurately, notably as producing a galaxy requires some quite giant numbers.

  • Using a heavyweight multi-precision framework equivalent to GNU MPFR or Boost (which I believe is constructed on one thing like MPFR. Pros: that is simpler to make use of than a light-weight library. Cons: This is quite a lot of equipment to tug in to unravel this, and I have not discovered any assure that it’s fully constant cross platform.

Notes:

  • I’m not notably involved about efficiency, and even excessive accuracy. Most of the heavy math code isn’t known as fairly often, and I can use a light-weight strategy for the crucial stuff.

  • I’m not attempting to get the rendering the identical, as that seems to be a fools errand with all of the totally different graphics playing cards on the market, totally different display screen resolutions, and many others. I do need the underlying construction to be the identical although.

  • Generating it on one platform and storing it’s not an answer – the galaxy is simply too large for that.

  • This query is not asking about normal cross-platform improvement and frameworks, about which I do know there are various opinions (I’ve already made the foremost choices for my case), nearly getting constant math for procedural technology.

  • Edit: I’m not attempting to unravel the house scaling points – I’ve already solved this (with as an example 64 bit integers for the star positions). I’m coping with star distributions and properties which contain a little bit of math.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments