iendpoint of block.raycast, entities.raycast and world.raycast and
nodes of a pathfinding route are integer block positions, but they were
pushed to Lua through glm::vec3. An odd coordinate above 16.7M came
back as a neighbour block.
OpenAL takes positions as floats. Positions of the listener and of the
speakers were passed in the world space, so far from the world origin
both were rounded to the float step (2 m at 30M blocks): a sound next
to the player came from a wrong side and with a wrong volume.
A speaker keeps its position as worldvec3, the listener stays in the
OpenAL origin, and a source is placed at "speaker - listener". Sources
are refreshed in the speaker update, once per frame.
Positions of particles, of static emitters and of text notes are
worldvec3. gfx.particles, gfx.text3d, gfx.blockwraps, pathfinding and
generation.create_fragment read positions from Lua as doubles: a float
can not hold an odd block coordinate above 16.7M, the object went to a
neighbour block.
Transform::pos, Hitbox::position and Player::position were floats. At
65k blocks the float step is 8 mm, at 1M it is 6-12 cm, at 30M it is
2 m. The physics moves a body by 3 cm or less per substep and pushes it
out of a wall by 10 cm or less: steps got rounded to the grid (the body
changed its speed, then stopped), the AABB of a body was off by a float
step and gave false collisions with the blocks around.
Positions of bodies, entity transforms, players, spawn points and the
skeleton position interpolation are worldvec3 now. Collisions are still
calculated in floats, but in the coordinates relative to the block the
body is in: the solver takes the origin, block lookups and hitboxes of
other bodies are shifted by it, the result is added back in doubles.
So the precision of the physics is the same anywhere in the world.
A calculated sensor is stored relative to the position of its entity.
Entities::getAllInside takes the corners in doubles,
Entities::hasBlockingInside takes the origin of the AABB.
The save format does not change: positions are written as numbers
(float64) as before, saves are compatible in both directions. Lua
functions keep their signatures, they only stop rounding to float.
A float position has a step of 6 cm at 1M blocks and of 2 m at 30M:
the camera moved by jumps and rays started not where the camera is.
worldvec3 (glm::dvec3) is the type of a position in the world.
Camera::position, the start and the end of block and entity ray casts
and the hit position of the player selection use it. Lua numbers are
doubles already, so cameras.set_pos/get_pos, block.raycast,
entities.raycast and world.raycast only stop rounding to float.
Entities::rayCast intersects a hitbox in the coordinates relative to
its position instead of a float AABB in the world space.
World coordinates were passed to GPU as floats: u_model of a chunk and
of a model had the world translation, vertices of translucent blocks,
particles, precipitation, block wrappers, lines and 3D texts were built
in the world space, and the camera position was subtracted in shaders.
The float step grows with the distance from the world origin (6 cm at
1M blocks, 2 m at 30M): blocks got skewed, then stuck together.
Camera::getOrigin() is an integer point near the camera (X and Z are
rounded to 1024 blocks, Y is 0). Camera::getView() is relative to it,
and every position passed to GPU is "world - origin" calculated on CPU,
so the shaders keep working with small numbers and do not change:
u_cameraPos, a_modelpos, u_inverseView and the shadows matrices are in
the same space as before, shifted by the origin. Matrices of a shadow
map are converted from the origin of its camera to the origin of the
player camera. The clouds shader gets the origin wrapped by the period
of its waves, the waves stay bound to the world.
Vertices of translucent blocks are local to the chunk now, as vertices
of opaque ones, and drawn with u_model of the chunk.
Camera::getView built the view with lookAt(position, position + front):
the direction came back as a difference of large floats. Far from the
origin the view turned away from where the camera looks - at 16M blocks
by up to 24 degrees, at 30M the camera looked straight up or down
whatever its yaw (at pitch 0 the direction is a zero vector, the matrix
is NaN). The rotation is built from front itself now, then translated
by -position: the same matrix, without the subtraction.
ServerMainloop slept the rest of the tick and then restarted counting from
the moment it woke up, so every sleep overshoot made the tick longer. With a
coarse timer (a VirtualBox guest of a Windows host) --tps 20 gave 12-17 ticks
per second. Ticks now follow absolute deadlines on steady_clock; after falling
more than 5 ticks behind the schedule is reset instead of running a burst of
ticks.
The time of a tick is its scheduled time, so delta is exactly 1 / tps while
the loop keeps up, as in test mode. With the wake-up time deltas jitter
around 1 / tps, and the world tick clock, which calls on_world_tick at most
once per update, skipped every few ticks.