Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_dead_reckoning.c File Reference

Dead Reckoning implementation for latency hiding in networked games. More...

#include "nilorea/n_dead_reckoning.h"
#include "nilorea/n_common.h"
#include <stdlib.h>
+ Include dependency graph for n_dead_reckoning.c:

Go to the source code of this file.

Functions

static DR_VEC3 cubic_bezier (DR_VEC3 p0, DR_VEC3 p1, DR_VEC3 p2, DR_VEC3 p3, double t)
 Evaluate a cubic Bezier curve at parameter t in [0, 1].
 
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 whether the owner's true state has diverged from the dead reckoned prediction beyond the configured 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_ENTITYdr_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 set the pointer to NULL.
 
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 triggering convergence blending.
 
void dr_entity_set_threshold (DR_ENTITY *entity, double threshold)
 Set the position error threshold for triggering network updates.
 

Detailed Description

Dead Reckoning implementation for latency hiding in networked games.

Implements the algorithms described in:

  • "Dead Reckoning: Latency Hiding for Networked Games" (Game Developer)
  • "Believable Dead Reckoning for Networked Games" by Curtiss Murphy (Game Engine Gems 2, 2011)

The three convergence modes:

  1. SNAP: Immediately jump to the new position. Cheap but visually jarring.
  2. PVB (Projective Velocity Blending): Extrapolate both old (before update) and new (after update) states forward, and linearly blend between the two extrapolated positions over blend_time seconds. Works well for straight-line motion.
  3. CUBIC (Cubic Bezier): Fit a cubic Bezier curve from the old predicted position to the new extrapolated position. Control points ensure C1 continuity (velocity matching). Works well for curved paths.
Author
Castagnier Mickael
Version
1.0
Date
01/03/2026

Definition in file n_dead_reckoning.c.

Function Documentation

◆ cubic_bezier()

static DR_VEC3 cubic_bezier ( DR_VEC3  p0,
DR_VEC3  p1,
DR_VEC3  p2,
DR_VEC3  p3,
double  t 
)
static

Evaluate a cubic Bezier curve at parameter t in [0, 1].

B(t) = (1-t)^3 * P0 + 3(1-t)^2*t * P1 + 3(1-t)*t^2 * P2 + t^3 * P3

Parameters
p0start point
p1control point 1
p2control point 2
p3end point
tparameter in [0, 1]
Returns
interpolated point

Definition at line 61 of file n_dead_reckoning.c.

References DR_VEC3::x, DR_VEC3::y, and DR_VEC3::z.

Referenced by dr_entity_compute().

+ Here is the caller graph for this function: