![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Dead Reckoning API for latency hiding in networked games. More...
#include <stdbool.h>#include <math.h>
Include dependency graph for n_dead_reckoning.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | DR_ENTITY |
| Dead reckoned entity with extrapolation and convergence state. More... | |
| struct | DR_STATE |
| A snapshot of entity kinematic state at a point in time. More... | |
| struct | DR_VEC3 |
| 3D vector used for position, velocity, and acceleration More... | |
Enumerations | |
| enum | DR_ALGO { DR_ALGO_STATIC = 0 , DR_ALGO_VEL = 1 , DR_ALGO_VEL_ACC = 2 } |
| Dead reckoning extrapolation algorithm. More... | |
| enum | DR_BLEND { DR_BLEND_SNAP = 0 , DR_BLEND_PVB = 1 , DR_BLEND_CUBIC = 2 } |
| Dead reckoning convergence/blending mode. More... | |
Functions | |
| bool | dr_entity_check_threshold (const DR_ENTITY *entity, const DR_VEC3 *true_pos, const DR_VEC3 *true_vel, const DR_VEC3 *true_acc, double time) |
| check if the owner's true state has diverged beyond the threshold | |
| void | dr_entity_compute (DR_ENTITY *entity, double time, DR_VEC3 *out_pos) |
| compute the dead reckoned display position at a given time | |
| DR_ENTITY * | dr_entity_create (DR_ALGO algo, DR_BLEND blend_mode, double pos_threshold, double blend_time) |
| create a new dead reckoning entity | |
| void | dr_entity_destroy (DR_ENTITY **entity_ptr) |
| destroy a dead reckoning entity and free its memory | |
| DR_VEC3 | dr_entity_extrapolate (const DR_ENTITY *entity, const DR_STATE *state, double dt) |
| extrapolate a kinematic state forward by dt seconds | |
| void | dr_entity_receive_state (DR_ENTITY *entity, const DR_VEC3 *pos, const DR_VEC3 *vel, const DR_VEC3 *acc, double time) |
| receive a new authoritative state update from the network | |
| void | dr_entity_set_algo (DR_ENTITY *entity, DR_ALGO algo) |
| set the extrapolation algorithm | |
| void | dr_entity_set_blend_mode (DR_ENTITY *entity, DR_BLEND blend_mode) |
| set the convergence blending mode | |
| void | dr_entity_set_blend_time (DR_ENTITY *entity, double blend_time) |
| set the convergence blend duration | |
| void | dr_entity_set_position (DR_ENTITY *entity, const DR_VEC3 *pos, const DR_VEC3 *vel, const DR_VEC3 *acc, double time) |
| force-set entity position without blending | |
| void | dr_entity_set_threshold (DR_ENTITY *entity, double threshold) |
| set the position error threshold | |
| static DR_VEC3 | dr_vec3 (double x, double y, double z) |
| Create a DR_VEC3 from components. | |
| static DR_VEC3 | dr_vec3_add (DR_VEC3 a, DR_VEC3 b) |
| Vector addition: a + b. | |
| static double | dr_vec3_distance (DR_VEC3 a, DR_VEC3 b) |
| Distance between two points. | |
| static double | dr_vec3_length (DR_VEC3 v) |
| Length of vector. | |
| static double | dr_vec3_length_sq (DR_VEC3 v) |
| Squared length of vector. | |
| static DR_VEC3 | dr_vec3_lerp (DR_VEC3 a, DR_VEC3 b, double t) |
| Linear interpolation: a + (b - a) * t. | |
| static DR_VEC3 | dr_vec3_scale (DR_VEC3 v, double s) |
| Scalar multiplication: v * s. | |
| static DR_VEC3 | dr_vec3_sub (DR_VEC3 a, DR_VEC3 b) |
| Vector subtraction: a - b. | |
| static DR_VEC3 | dr_vec3_zero (void) |
| Zero vector. | |
Dead Reckoning API for latency hiding in networked games.
Implements dead reckoning (DR) as described in:
Dead reckoning is a technique where every participant in a networked game simulates all entities using agreed-upon extrapolation algorithms. When the owner's true state diverges from the extrapolated state beyond a configurable threshold, a new state update is sent. On receipt, the remote side uses a convergence algorithm to smoothly blend from the predicted position to the newly received authoritative state.
Can be used together with n_trajectory for cubic Hermite spline interpolation between known states, while dead reckoning provides the network-level threshold checking and convergence blending.
Supports three extrapolation models:
Supports three convergence/blending modes:
Usage:
Definition in file n_dead_reckoning.h.