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

c++ – Constant 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? Additionally, in case you have finished this, what have been the professionals and cons of your strategy?

Context: I am constructing a recreation (in C++) that entails producing a 400 billion star galaxy, for which I am utilizing procedural technology. The goal platforms are Android (Arm-v8a), Linux (x86-64), and possibly Home windows (x86-64). The problem is that this technology entails 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 need 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 could be an issue (resembling Arm utilizing a multiply-add instruction having higher intermediate precision than the x86-64 utilizing two directions).

Issues I’ve thought of:

  • Utilizing 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 all the things compiles precisely the identical means on each processors, and depend on IEE-754 conformance to deal with the remainder. [EDIT – this part answered. It’s nearly impossible to get right]

  • Utilizing a light-weight mounted level framework resembling fixedptc.h so I am solely doing integer math. Professionals: will certainly be constant. Cons: a number of effort to scale all the things accurately, notably as producing a galaxy requires some moderately giant numbers.

  • Utilizing a heavyweight multi-precision framework resembling GNU MPFR or Increase (which I feel is constructed on one thing like MPFR. Professionals: that is simpler to make use of than a light-weight library. Cons: It is a lot of equipment to drag in to unravel this, and I have not discovered any assure that it’s utterly constant cross platform.

Notes:

  • I am not notably involved about efficiency, and even excessive accuracy. Many of the heavy math code just isn’t referred to as fairly often, and I can use a light-weight strategy for the vital stuff.

  • I am 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 resolutions, and many others. I do need the underlying construction to be the identical although.

  • Producing it on one platform and storing it’s not an answer – the galaxy is just too huge for that.

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

  • Edit: I am not attempting to unravel the area scaling points – I’ve already solved this (with for example 64 bit integers for the star positions). I am 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

- Advertisment -
Google search engine

Most Popular

Recent Comments