spawn method
Spawns a new entity. If components are provided, they are attached
immediately. Otherwise an alive-tag component is inserted so the entity
remains visible to entities / queries until it gets real components.
Implementation
WorldEntity spawn([
Option<Iterable<Component>> components = const None(),
]) {
assert(
!_disposed,
'World.spawn: cannot be called after dispose. Construct a fresh World.',
);
final entity = WorldEntity._(_nextEntityId++, this);
final cs = switch (components) {
Some(value: final c) when c.isNotEmpty => c,
_ => const <Component>[],
};
if (cs.isEmpty) {
_writeComponent(entity, const _AliveTag());
} else {
for (final c in cs) {
_writeComponent(entity, c);
}
}
return entity;
}