Appearance
Appearance
Fixed-point numerics can be used instead of floating-point to achieve deterministic computations. This enables logic to be executed identically on both the client and server. Floating-point (float
and double
types in C#) values do not provide such guarantees.
The Metaplay SDK ships with the open-source FixPointCS math library to provide fixed-point functionality. The main data types from the library are F64
(a 32.32 signed fixed-point number) and F32
(a signed 16.16 fixed-point number).
Vector types are also included: F32Vec2
, F32Vec3
, F64Vec2
, and F64Vec3
provide both 2- and 3-component vectors for both 16.16 and 32.32 bit fixed-point values.
As a rule of thumb, F64
should be used as the default due to its larger range of values and accuracy. In situations where performance is of great concern, the F32
family of types can be used. The F32
family has a much smaller range and precision of values, so care should be taken to avoid any overflows and underflows.
📌 Note
The fixed-point types are also integrated into the game config parsing, meaning that they can be used in .csv files just as one would use floats. The importing of the files automatically detects any fixed-point types and invokes the correct parsing function.