Skip to content

Commit

Permalink
docs: document world module
Browse files Browse the repository at this point in the history
  • Loading branch information
LechintanTudor committed Aug 30, 2024
1 parent c2389e1 commit d8a6872
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 100 deletions.
8 changes: 7 additions & 1 deletion src/component/component_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ impl ComponentStorage {
where
T: Component,
{
self.metadata.contains_key(&TypeId::of::<T>())
self.is_registered_dyn(TypeId::of::<T>())
}

#[inline]
#[must_use]
pub fn is_registered_dyn(&self, type_id: TypeId) -> bool {
self.metadata.contains_key(&type_id)
}

pub fn strip(&mut self, entity: Entity) {
Expand Down
9 changes: 9 additions & 0 deletions src/world/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::component::{Component, ComponentData, GroupDescriptor, GroupLayout};
use crate::world::World;
use alloc::vec::Vec;

/// Builder struct for creating a [`World`].
#[must_use]
#[derive(Clone, Default, Debug)]
pub struct WorldBuilder {
Expand All @@ -10,38 +11,46 @@ pub struct WorldBuilder {
}

impl WorldBuilder {
/// Sets a group `layout` for the world.
#[inline]
pub fn set_layout(&mut self, layout: GroupLayout) -> &mut Self {
self.layout = layout;
self
}

/// Adds a new component group to the world.
pub fn add_group<G>(&mut self) -> &mut Self
where
G: GroupDescriptor,
{
self.add_group_dyn(G::COMPONENTS)
}

/// Adds a new component group to the world.
#[inline]
pub fn add_group_dyn(&mut self, components: &[ComponentData]) -> &mut Self {
self.layout.add_group_dyn(components);
self
}

/// Registers a new component type on the world.
pub fn register<T>(&mut self) -> &mut Self
where
T: Component,
{
self.register_dyn(ComponentData::new::<T>())
}

/// Registers a new component type on the world.
#[inline]
pub fn register_dyn(&mut self, component: ComponentData) -> &mut Self {
self.components.push(component);
self
}

/// Buidls the world with the previously specified options.
///
/// Returns the newly created world.
#[must_use]
pub fn build(&self) -> World {
let mut world = World::new(&self.layout);
Expand Down
Loading

0 comments on commit d8a6872

Please sign in to comment.