ECS Components
Reference for the most commonly used ECS components in Xindeler. All of them are defined in common/src/comp/.
To understand the ECS model, see Architecture.
Position and movementβ
Posβ
pub struct Pos(pub Vec3<f32>);
Position in the world in voxel coordinates. Present on every entity with a physical existence.
Velβ
pub struct Vel(pub Vec3<f32>);
Current velocity in meters per tick. Modified every tick by the physics system according to forces and collisions.
Oriβ
pub struct Ori(/* internal quaternion */);
Orientation of the entity. Exposes methods such as look_dir(), right(), up().
Stats and healthβ
Healthβ
pub struct Health {
pub current: u32,
pub maximum: u32,
pub is_dead: bool,
}
Current and maximum health. When current reaches 0, is_dead is set to true and the death system processes the entity.
Energyβ
pub struct Energy {
pub current: u32,
pub maximum: u32,
}
Resource consumed by abilities. Regenerates passively. Some classes call it mana, stamina, or rage β the underlying type is the same.
Statsβ
pub struct Stats {
pub name: String,
pub level: u32,
pub exp: u32,
pub endurance: u32,
pub fitness: u32,
pub willpower: u32,
}
The entity's base stats. They affect damage calculations, maximum health, and energy regeneration.
Poiseβ
pub struct Poise {
pub current: f32,
pub maximum: f32,
pub poise_change_rate: f32,
}
Resistance to being staggered. If it reaches 0, the entity enters the Stunned state. It recovers over time.
Inventory and equipmentβ
Inventoryβ
pub struct Inventory {
slots: Vec<Option<Item>>,
loadout: Loadout,
}
Holds the character's items (backpack) and their active equipment (Loadout). Equipment slots include: mainhand, offhand, head, chest, back, hands, ring, neck, feet.
SkillSetβ
pub struct SkillSet {
pub skills: HashMap<Skill, u8>,
pub exp: HashMap<SkillGroupKind, u32>,
}
Unlocked skills and their level. The Skill key is an enum covering every skill in the game.
Behavior and alignmentβ
Alignmentβ
pub enum Alignment {
Wild, // wild creatures β attack if provoked
Enemy, // always hostile to players
Npc, // neutral, doesn't attack
Tame, // pets or tamed NPCs
Owned(Uid), // belongs to a specific entity
Passive, // never attacks
}
Defines the entity's default combat behavior.
Agentβ
Component that activates the server-side AI for an entity. Without Agent, the entity is static (doesn't patrol, doesn't react). Holds the current behavior state: patrolling, attacking, fleeing, interacting.
CharacterStateβ
Current animation/action state of the character: Idle, Run, Jump, Attack(ComboMelee { .. }), Roll, Glide, etc. The client uses it to animate the character; the server validates it.
Networking and synchronizationβ
Uidβ
pub struct Uid(pub u64);
Universal unique ID of an entity, synchronized between client and server. The specs Entity is local to the process β Uid is the network identifier.
Clientβ
Component present only on entities that have a connected player. Holds the QUIC stream used to send messages to the client.
Presenceβ
Indicates that the entity has an active player and defines its view range (which chunks and entities get synced to the client).
World and terrainβ
ChunkPosβ
Position of a chunk in chunk coordinates (not voxel coordinates). ChunkPos(x, y) corresponds to the chunk that contains voxel (x*32, y*32).
Usage conventionsβ
- Components are registered with specs'
Worldwhen the server starts up - To access a component in a system:
ReadStorage<'a, Health>orWriteStorage<'a, Health> - To add a new component, define it in
common/src/comp/, register it incommon/src/comp/mod.rs, and register its storage on the server - Components must implement specs'
Componentand typicallyClone,Debug, andserde::Serialize/Deserializeif they need to be synchronized over the network