use resequence::{Engine, EntityState, LifecycleState};
#[derive(Clone, Default, Debug)]
struct CombatUnit {
name: String,
hp: i32,
damage: i32,
owner: u8,
}
impl EntityState for CombatUnit {}
fn main() {
println!("Resequence Engine - Paradox Detection Example");
println!("==============================================\n");
let mut engine = Engine::<CombatUnit>::new();
let marine = engine.spawn(CombatUnit {
name: "Marine".to_string(),
hp: 100,
damage: 10,
owner: 1,
});
println!("Player 1 spawned Marine at t=0");
for _ in 0..20 {
engine.tick();
}
println!("Advanced to t={}", engine.current_tick);
engine
.set_state(
marine,
CombatUnit {
name: "Marine".to_string(),
hp: 30, damage: 10,
owner: 1,
},
)
.unwrap();
println!("Marine took damage, now at 30 HP");
println!("\nChronoporting Marine to t=5 to create reinforcement...");
let marine_past = engine.chronoport(marine, 5).unwrap();
let marine_mid = engine.chronoport(marine, 10).unwrap();
println!("Chronoported again to t=10");
println!("\n--- Same-Name Chain (Temporal Duplicates) ---");
let duplicates = engine.get_same_name_entities(marine);
println!("Found {} temporal duplicates:", duplicates.len());
for dup_id in &duplicates {
if let Some(event) = engine.get_state(*dup_id) {
println!(
" {:?}: HP={}, lifecycle={:?}, owner={}",
dup_id, event.state.hp, event.lifecycle, event.state.owner
);
}
}
println!("\n--- Paradox Detection ---");
println!("Checking for temporal conflicts...\n");
for &check_id in &duplicates {
let Some(check_event) = engine.get_state(check_id) else {
continue;
};
if check_event.lifecycle == LifecycleState::Chronoporting {
println!(
"{:?} is currently chronoporting, skipping",
check_id
);
continue;
}
for &other_id in &duplicates {
if other_id == check_id {
continue;
}
let Some(other_event) = engine.get_state(other_id) else {
continue;
};
if check_event.state.owner != other_event.state.owner {
println!(
"PARADOX! {:?} (owner {}) conflicts with {:?} (owner {})",
check_id, check_event.state.owner, other_id, other_event.state.owner
);
}
}
}
println!("\n--- Simulating Enemy Capture ---");
engine
.set_state(
marine_past,
CombatUnit {
name: "Marine".to_string(),
hp: 100,
damage: 10,
owner: 2, },
)
.unwrap();
println!("Enemy (player 2) captured the t=5 duplicate!");
println!("\nRe-checking for paradoxes...\n");
for &check_id in &duplicates {
let Some(check_event) = engine.get_state(check_id) else {
continue;
};
if check_event.lifecycle == LifecycleState::Chronoporting {
continue;
}
for &other_id in &duplicates {
if other_id == check_id {
continue;
}
let Some(other_event) = engine.get_state(other_id) else {
continue;
};
if other_event.lifecycle == LifecycleState::Chronoporting {
continue;
}
if check_event.state.owner != other_event.state.owner {
println!(
"PARADOX DETECTED! {:?} (owner {}) vs {:?} (owner {})",
check_id, check_event.state.owner, other_id, other_event.state.owner
);
println!(" -> In Achron, this would cause temporal damage!");
}
}
}
println!("\n--- Timeline Summary ---");
println!("Total entities: {}", engine.entity_count());
println!("Active entities: {}", engine.active_entity_count());
println!("\nDone!");
}