New plugin headers for 64bit – ShiVa Engine

New plugin headers for 64bit

As you might know, Lua has only one built-in data type for numbers of any kind called number. This datatype can be used to represent any numeric type from integers to floating point numbers. In order to interface with C/C++, ShiVa offers the functions .Get/SetNumberValue() which, until now, always returned a 32bit float. The day Google made 64bit builds a requirement on Android, we had to change our plugin interface to allow for true 64bit floating point operations using the double datatype. This leads to incompatibilities between older plugins and new engine builds if you do not update the ShiVa header files in your plugin projects.

Silent failure

The problem with running old plugins with new engine cores is the way in which communication between them fails. The game will not crash, and you will exchange data in most cases, but the values will make no sense. You could waste days trying to find out why the return values of your numeric function never add up to your expectations. Strings are also affected, so if you are receiving nothing but Chinese characters from your plugins, you might suffer from the same header issue. Time to update!

Download new headers

You can get the new header files form this link: S3DX Headers 20200101
Simply extract the ZIP archive and move the files over from the S3DX directory into the Sources/S3DX folder in your plugin directory. Overwrite the old files where necessary.

32bit vs 64bit numbers

If you call .GetNumberValue() on a 32bit project, the return type will still be a 32bit float, just like before.

Now we change the project target from Win32 to x64.

With the new 64bit target, you will no longer receive a 32bit float, but an actual double.

Casting

To make a “code once run everywhere” solution, you could cast all your numbers to 32bit floats.

Please be aware that casting from double to float gives you the following warning on x64 builds, since you are trying to fit a potentially larger number into a smaller datatype with less precision:

Instead, you could cast everything to double, even on 32bit systems.

This however might come with a performance penalty on the old 32bit hardware you are compiling for, and also increases memory bandwidth requirements.

Outlook

Luckily, this problem is going away on its own in the near future, since the 32bit target is most likely going to become irrelevant. Apple is shipping 64bit systems exclusively for a number of years now in both the desktop and mobile space, many flagship Linux distributions are abandoning their 32bit x86 distributions, and now Android demands 64bit builds. In terms of performance, floats and doubles on modern processors have little to no performance difference, so it makes sense to use doubles over floats in new plugin projects.


  • slackBanner