dreamwell-engine 1.0.0

Dreamwell pure-logic engine library — transforms, hierarchy, canon pipeline, spatial math, hashing, tile rules, validation, waymark schema, material/lighting descriptors. No SpacetimeDB dependency.
Documentation
//! Typed ID newtypes for stable cross-crate identification.

use serde::{Deserialize, Serialize};

/// Actor identity in the simulation.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ActorId(pub u64);

/// Entity identity (scene objects, topology nodes).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct EntityId(pub u64);

/// Event identity in the canon pipeline.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct EventId(pub u64);

/// World/universe identity.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct WorldId(pub u64);

/// Scope key for canon event partitioning.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ScopeKey(pub u64);

/// Tick counter for deterministic time.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Tick(pub u64);

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn actor_id_equality() {
        assert_eq!(ActorId(42), ActorId(42));
        assert_ne!(ActorId(1), ActorId(2));
    }

    #[test]
    fn entity_id_hash_stable() {
        use std::collections::HashSet;
        let mut set = HashSet::new();
        set.insert(EntityId(100));
        assert!(set.contains(&EntityId(100)));
        assert!(!set.contains(&EntityId(101)));
    }

    #[test]
    fn tick_ordering() {
        assert!(Tick(1) < Tick(2));
        assert!(Tick(0) <= Tick(0));
    }

    #[test]
    fn serde_roundtrip() {
        let id = ActorId(999);
        let json = serde_json::to_string(&id).unwrap();
        let back: ActorId = serde_json::from_str(&json).unwrap();
        assert_eq!(id, back);
    }
}