Crate resequence

Crate resequence 

Source
Expand description

§Resequence

A time-travel simulation engine based on patterns reverse-engineered from Achron’s Resequence engine (2011). This crate preserves the intellectual heritage of Achron’s innovative time manipulation mechanics for future game development and research.

§Design Patterns

The engine implements four core patterns from the original:

§Pattern 1: Event-Linked Entities

Entities store their history as a list of timestamped events, not full snapshots. This provides O(log n) historical queries via binary search while minimizing storage.

§Pattern 2: Iterator-Based Time Views (Timewaves)

Timewaves are execution contexts that move through time at variable speeds. Multiple waves can view the same timeline at different positions, enabling parallel timeline observation, replay debugging, and what-if analysis.

§Pattern 3: Identity Linking (Same-Name Groups)

When entities travel through time (chronoport), they create linked duplicates sharing a “name ID”. This enables paradox detection - scripts can iterate through all temporal copies of an entity to detect conflicts.

§Pattern 4: Sorted Wave Processing with Propagation

Timewaves are sorted by position each tick. Earlier waves propagate state changes to later waves, ensuring causal consistency. Entity view caches maintain what each wave “sees” for efficient lookups.

§Lifecycle States

Entities transition through lifecycle states matching the original engine:

  • Unborn: Empty slot or not yet scheduled
  • Prebirth: Scheduled to appear (e.g., destination of chronoport)
  • Born: Normal active state
  • Chronoporting: Mid-time-travel
  • Dead: Destroyed

Prebirth entities automatically transition to Born when a timewave reaches them.

§Time Window Constraints

Chronoport operations can be constrained to a time window, preventing entities from traveling too far into the past or future.

§Example

use resequence::{Engine, EntityState};

#[derive(Clone, Default, Debug)]
struct UnitState {
    hp: i32,
    x: f32,
    y: f32,
}

impl EntityState for UnitState {}

let mut engine = Engine::<UnitState>::new();

// Spawn a unit
let unit = engine.spawn(UnitState { hp: 100, x: 0.0, y: 0.0 });

// Advance time
for _ in 0..10 {
    engine.tick();
}

// Time travel! Create a duplicate at t=5
engine.chronoport(unit, 5).unwrap();

// Now there are two linked copies of the unit
let duplicates = engine.get_same_name_entities(unit);
assert_eq!(duplicates.len(), 2);

§Applications Beyond Games

These patterns are useful for:

  • Simulation debugging: Add past observation waves to inspect state
  • What-if analysis: Fork timelines, apply different decisions, compare
  • Undo/redo systems: Position-based state views without explicit snapshots
  • Distributed consensus: Multiple nodes as waves at different timestamps

Structs§

Engine
Main engine coordinating timeline and timewaves
Entity
An entity with its event history
EntityId
Unique identifier for an entity
Event
A single event (state snapshot) in an entity’s timeline
NameId
Identifier linking temporal duplicates (“same name” in original engine)
Timeline
The timeline stores all entity state across time
Timewave
A timewave is an execution context moving through time
TimewaveId
Unique identifier for a timewave

Enums§

Error
Errors that can occur in the resequence engine
LifecycleState
Entity lifecycle state (matches original engine’s high-nibble flags)

Traits§

EntityState
Trait for entity state data

Type Aliases§

Result
Result type alias for resequence operations
Tick
Simulation tick (discrete time unit)