vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
quantize.h
1#pragma once
2
3#include <cstdint>
4
5#include <glm/glm.hpp>
6#include <glm/gtc/quaternion.hpp>
7
8#include "net/wire/bit_stream.h"
9
10namespace Vkm::Engine::Quantize {
11
17constexpr float POSITION_STEP = 0.001f;
18
24constexpr float MAX_SPEED = 200.0f;
25
32constexpr float WORLD_EXTENT = 512.0f;
33
39constexpr uint32_t positionBits() {
40 uint32_t bits = 1;
41 float range = 2.0f;
42 const float need = (WORLD_EXTENT * 2.0f) / POSITION_STEP;
43 while (range < need && bits < 32u) {
44 range *= 2.0f;
45 ++bits;
46 }
47 return bits;
48}
49
56constexpr uint32_t ROTATION_BITS = 11;
57
59constexpr uint32_t VELOCITY_BITS = 16;
60
73uint32_t toSigned(float value, float range, uint32_t width);
74
76float fromSigned(uint32_t raw, float range, uint32_t width);
77
88void writePosition(BitWriter& out, float value);
89
91float readPosition(BitReader& in);
92
102void writeRotation(BitWriter& out, const glm::quat& value);
103
105glm::quat readRotation(BitReader& in);
106
108void writeVelocity(BitWriter& out, float value);
109
111float readVelocity(BitReader& in);
112
113} // namespace Vkm::Engine::Quantize
float range(float min, float max)
Uniform float in [min, max), from the per-thread generator.
Definition random.h:135