summaryrefslogtreecommitdiff
path: root/engine-ecs/src
diff options
context:
space:
mode:
Diffstat (limited to 'engine-ecs/src')
-rw-r--r--engine-ecs/src/entity.rs22
-rw-r--r--engine-ecs/src/extension.rs12
-rw-r--r--engine-ecs/src/lib.rs17
-rw-r--r--engine-ecs/src/phase.rs8
-rw-r--r--engine-ecs/src/sole.rs18
5 files changed, 38 insertions, 39 deletions
diff --git a/engine-ecs/src/entity.rs b/engine-ecs/src/entity.rs
index 9ef9da0..b9829e1 100644
--- a/engine-ecs/src/entity.rs
+++ b/engine-ecs/src/entity.rs
@@ -3,16 +3,12 @@ use std::borrow::Cow;
use std::ops::Deref;
use std::sync::LazyLock;
-use crate::Component;
use crate::component::storage::archetype::{
Archetype,
Entity as ArchetypeEntity,
MatchingComponentIter as ArchetypeMatchingComponentIter,
};
-use crate::component::{
- Handle as ComponentHandle,
- HandleMut as ComponentHandleMut,
-};
+use crate::component::{Handle as ComponentHandle, HandleMut as ComponentHandleMut};
use crate::pair::{
ComponentOrWildcard,
MultipleWithWildcard as PairMultipleWithWildcard,
@@ -20,7 +16,7 @@ use crate::pair::{
WithWildcard as PairWithWildcard,
};
use crate::uid::Uid;
-use crate::{EntityComponentRef, World};
+use crate::{Component, EntityComponentRef, World};
pub mod obtainer;
@@ -288,22 +284,22 @@ impl<'a> Iterator for MatchingComponentIter<'a>
pub struct Declaration
{
uid: LazyLock<Uid>,
- create_func: fn(&mut World),
+ spawn_func: fn(&mut World),
}
impl Declaration
{
- pub(crate) fn create(&self, world: &mut World)
+ pub(crate) fn spawn(&self, world: &mut World)
{
- (self.create_func)(world);
+ (self.spawn_func)(world);
}
#[doc(hidden)]
- pub const fn new(create_func: fn(&mut World)) -> Self
+ pub const fn new(spawn_func: fn(&mut World)) -> Self
{
Self {
uid: LazyLock::new(|| Uid::new_unique()),
- create_func,
+ spawn_func,
}
}
}
@@ -324,7 +320,7 @@ macro_rules! declare_entity {
($visibility: vis $ident: ident, $components: expr) => {
$visibility static $ident: $crate::entity::Declaration =
$crate::entity::Declaration::new(|world| {
- world.create_entity_with_uid(*$ident, $components);
+ world.spawn_with_uid(*$ident, $components);
});
}
}
@@ -333,5 +329,5 @@ macro_rules! declare_entity {
#[derive(Debug, Clone, Component)]
pub struct Name
{
- pub name: Cow<'static, str>
+ pub name: Cow<'static, str>,
}
diff --git a/engine-ecs/src/extension.rs b/engine-ecs/src/extension.rs
index 9c6614b..1975933 100644
--- a/engine-ecs/src/extension.rs
+++ b/engine-ecs/src/extension.rs
@@ -46,23 +46,23 @@ impl<'world> Collector<'world>
}
/// Adds a entity to the [`World`].
- pub fn add_entity<Comps>(&mut self, components: Comps)
+ pub fn spawn<Comps>(&mut self, components: Comps)
where
Comps: ComponentSequence,
{
- self.world.create_entity(components);
+ self.world.spawn(components);
}
/// Adds a declared entity to the [`World`].
- pub fn add_declared_entity(&mut self, entity_decl: &EntityDeclaration)
+ pub fn spawn_declared_entity(&mut self, entity_decl: &EntityDeclaration)
{
- self.world.create_declared_entity(entity_decl);
+ self.world.spawn_declared_entity(entity_decl);
}
- /// Adds a globally shared singleton value to the [`World`].
+ /// Adds a singleton component to the [`World`].
///
/// # Errors
- /// Returns `Err` if this [`Sole`] has already been added.
+ /// Returns `Err` if the [`Sole`] already exists.
pub fn add_sole<SoleT>(&mut self, sole: SoleT) -> Result<(), SoleAlreadyExistsError>
where
SoleT: Sole,
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs
index 88acca9..190eab7 100644
--- a/engine-ecs/src/lib.rs
+++ b/engine-ecs/src/lib.rs
@@ -127,13 +127,13 @@ impl World
/// Creates a entity with the given components. A new unique [`Uid`] will be generated
/// for this entity.
- pub fn create_entity<Comps>(&mut self, components: Comps) -> Uid
+ pub fn spawn<Comps>(&mut self, components: Comps) -> Uid
where
Comps: ComponentSequence,
{
let entity_uid = Uid::new_unique();
- self.create_entity_with_uid(entity_uid, components);
+ self.spawn_with_uid(entity_uid, components);
entity_uid
}
@@ -141,7 +141,7 @@ impl World
/// Creates a entity with the given components. The entity will have the specified
/// [`Uid`].
#[tracing::instrument(skip_all)]
- pub fn create_entity_with_uid<Comps>(&mut self, entity_uid: Uid, components: Comps)
+ pub fn spawn_with_uid<Comps>(&mut self, entity_uid: Uid, components: Comps)
where
Comps: ComponentSequence,
{
@@ -158,12 +158,12 @@ impl World
);
}
- pub fn create_declared_entity(&mut self, entity_decl: &EntityDeclaration)
+ pub fn spawn_declared_entity(&mut self, entity_decl: &EntityDeclaration)
{
- entity_decl.create(self);
+ entity_decl.spawn(self);
}
- /// Adds a singleton.
+ /// Adds a singleton component.
///
/// # Errors
/// Returns `Err` if this [`Sole`] has already been added.
@@ -214,12 +214,11 @@ impl World
{
let (type_erased_system, mut system_callbacks) = system.finish();
- let system_ent_id =
- self.create_entity((SystemComponent { system: type_erased_system },));
+ let system_ent_id = self.spawn((SystemComponent { system: type_erased_system },));
system_callbacks.on_created(self, SystemMetadata { ent_id: system_ent_id });
- self.create_entity_with_uid(
+ self.spawn_with_uid(
phase_euid,
(Pair::builder()
.relation::<PhaseHasSystem>()
diff --git a/engine-ecs/src/phase.rs b/engine-ecs/src/phase.rs
index 434e728..cb87cc6 100644
--- a/engine-ecs/src/phase.rs
+++ b/engine-ecs/src/phase.rs
@@ -10,10 +10,10 @@ declare_entity!(pub POST_UPDATE, (Phase,));
pub(crate) fn spawn_entities(world: &mut World)
{
- world.create_declared_entity(&START);
- world.create_declared_entity(&PRE_UPDATE);
- world.create_declared_entity(&UPDATE);
- world.create_declared_entity(&POST_UPDATE);
+ world.spawn_declared_entity(&START);
+ world.spawn_declared_entity(&PRE_UPDATE);
+ world.spawn_declared_entity(&UPDATE);
+ world.spawn_declared_entity(&POST_UPDATE);
}
#[derive(Debug, Component)]
diff --git a/engine-ecs/src/sole.rs b/engine-ecs/src/sole.rs
index 9409bcb..21dafc9 100644
--- a/engine-ecs/src/sole.rs
+++ b/engine-ecs/src/sole.rs
@@ -2,13 +2,15 @@ use std::any::{type_name, Any};
use std::fmt::Debug;
use std::ops::{Deref, DerefMut};
-use crate::uid::Uid;
-use crate::component::HandleMut as ComponentHandleMut;
-use crate::component::IntoParts as IntoComponentParts;
+use crate::component::{
+ HandleMut as ComponentHandleMut,
+ IntoParts as IntoComponentParts,
+};
use crate::system::{Metadata as SystemMetadata, Param as SystemParam};
+use crate::uid::Uid;
use crate::World;
-/// A type which has a single instance and is shared globally.
+/// A component which has a single instance in the [`World`].
pub trait Sole: Any + IntoComponentParts
{
fn id() -> Uid
@@ -49,14 +51,13 @@ impl Debug for dyn Sole
}
}
-/// Holds a reference to a globally shared singleton value.
+/// Holds a reference to a singleton component.
#[derive(Debug)]
pub struct Single<'world, SoleT: Sole>
{
sole: ComponentHandleMut<'world, SoleT>,
}
-
impl<'world, SoleT> Single<'world, SoleT>
where
SoleT: Sole,
@@ -79,7 +80,10 @@ where
.get_entity(SoleT::id())
.and_then(|ent| ent.get_with_id_mut::<SoleT>(SoleT::id()))
.unwrap_or_else(|| {
- panic!("Sole component {} was not found in world", type_name::<SoleT>())
+ panic!(
+ "Sole component {} was not found in world",
+ type_name::<SoleT>()
+ )
});
Self::new(sole)