MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / EncodeFloat16

Function EncodeFloat16

engine/Poseidon/Network/NetworkMsg.cpp:576–589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

574const int MaxAbsInt16 = 0x4000;
575// we want to have 0.5 represented exactly
576// we also want to keep some reserve range in case small overflow will occur
577
578inline int EncodeFloat16(float x)
579{
580 constexpr float networkOrientationTolerance = 1e-3f;
581 if (x < -1.0f || x > 1.0f)
582 {
583 NET_ERROR(std::isfinite(x));
584 NET_ERROR(x >= -1.0f - networkOrientationTolerance);
585 NET_ERROR(x <= +1.0f + networkOrientationTolerance);
586 saturate(x, -1.0f, +1.0f);
587 }
588 int r = toInt(MaxAbsInt16 * x);
589 saturate(r, -MaxAbsInt16, +MaxAbsInt16);
590 return r;
591}
592

Callers 1

EncodeMethod · 0.85

Calls 2

saturateFunction · 0.85
toIntFunction · 0.50

Tested by

no test coverage detected