basalt_api/components/mod.rs
1//! Component types and marker trait for the Entity Component System.
2//!
3//! These types define the data model for all game entities. They live
4//! in `basalt-api` so that plugin crates can reference them through
5//! the `basalt-api` facade without depending on the ECS storage engine.
6
7mod container;
8mod crafting;
9mod identity;
10mod inventory;
11mod item;
12mod recipe_book;
13mod spatial;
14
15pub use container::VirtualContainerSlots;
16pub use crafting::CraftingGrid;
17pub use identity::{EntityKind, Health, PlayerRef, Sneaking};
18pub use inventory::Inventory;
19pub use item::{DroppedItem, Lifetime, OpenContainer, PickupDelay};
20pub use recipe_book::KnownRecipes;
21pub use spatial::{BlockPosition, BoundingBox, ChunkPosition, Position, Rotation, Velocity};
22
23/// Marker trait for component types stored in the ECS.
24///
25/// Components must be `Send + Sync + 'static` so they can be
26/// accessed from the game loop thread and (in the future) from
27/// parallel system threads via rayon.
28pub trait Component: Send + Sync + 'static {}
29
30/// A unique entity identifier.
31///
32/// Entities are just IDs — all data lives in component stores.
33/// IDs are never reused within a server session.
34pub type EntityId = u32;
35
36/// Execution phase within a game loop tick.
37///
38/// Systems are grouped by phase and run in phase order.
39/// Within a phase, independent systems can run in parallel.
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
41pub enum Phase {
42 /// Drain input channels and convert to events/state.
43 Input,
44 /// Validation checks (permissions, anti-cheat). Can cancel.
45 Validate,
46 /// Active simulation: physics, AI, pathfinding, block updates.
47 Simulate,
48 /// Logical state mutations from event handlers.
49 Process,
50 /// Collect diffs, encode packets, push to output channels.
51 Output,
52 /// Side effects: logs, analytics, persistence.
53 Post,
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn phase_ordering() {
62 assert!(Phase::Input < Phase::Validate);
63 assert!(Phase::Validate < Phase::Simulate);
64 assert!(Phase::Simulate < Phase::Process);
65 assert!(Phase::Process < Phase::Output);
66 assert!(Phase::Output < Phase::Post);
67 }
68}