README

Milky2018/selene/entity does not have a README file

#
Entity

#
Entity::Entity

fn Entity::Entity() -> Entity

#
Entity::destroy

fn Entity::destroy(e : Entity) -> Unit

#
Entity::get_children

fn Entity::get_children(parent : Entity) -> Array[Entity]

Retrieves all child entities attached to the specified parent entity.

Parameters:

  • parent : The parent entity whose children to retrieve.

Returns an array of child entities. Returns an empty array if the entity has no children.

Example:

let parent = @entity.Entity()
let child1 = parent.spawn_child()
let child2 = parent.spawn_child()

let children = parent.get_children()
inspect(children.length(), content="2")
inspect(child1 == children[0], content="true")
inspect(child2 == children[1], content="true")

parent.destroy()

#
Entity::get_parent

fn Entity::get_parent(child : Entity) -> Entity?

Retrieves the parent entity of a child entity.

Parameters:

  • child : The child entity whose parent to retrieve.

Returns Some(parent_entity) if the entity has a parent, or None if the entity is not a child.

Example:

let parent = @entity.Entity()
let child = parent.spawn_child()

inspect(child.get_parent().unwrap() == parent, content="true")
inspect(parent.get_parent(), content="None")

parent.destroy()

#
Entity::id

fn Entity::id(self : Entity) -> UInt

#
Entity::is_alive

fn Entity::is_alive(e : Entity) -> Bool

#
Entity::is_child

fn Entity::is_child(entity : Entity) -> Bool

Checks whether an entity is a child of another entity.

Parameters:

  • entity : The entity to check.

Returns true if the entity is a child (has a parent), false otherwise.

Example:

let parent = @entity.Entity()
let child = parent.spawn_child()
let standalone = @entity.Entity()

inspect(child.is_child(), content="true")
inspect(standalone.is_child(), content="false")

parent.destroy()
standalone.destroy()

#
Entity::remove_parent

fn Entity::remove_parent(child : Entity) -> Unit

#
Entity::reserve_spawn

fn Entity::reserve_spawn() -> Entity

Reserves an entity id that becomes alive on the next flush. This matches deferred-spawn semantics used by commands.

#
Entity::respawn

fn Entity::respawn(e : Entity) -> Unit

#
Entity::set_parent

fn Entity::set_parent(child : Entity, parent : Entity) -> Unit

#
Entity::spawn_child

fn Entity::spawn_child(parent : Entity) -> Entity

Creates a new child entity attached to the specified parent entity.

The child entity is automatically registered in the entity system and linked to its parent. The parent-child relationship enables hierarchical transforms and cascading lifecycle operations (destroying a parent destroys all its children, and respawning a parent respawns all its children).

Parameters:

  • parent : The parent entity to attach the new child to. Returns a new child Entity that is linked to the parent.

Example:

let parent = @entity.Entity()
@transform.transforms().set(parent, @transform.Transform::from_xyz(100.0, 100.0, 0.0))

let child = parent.spawn_child()
@transform.transforms().set(child, @transform.Transform::from_xyz(10.0, 5.0, 0.0))

inspect(parent.get_children().length(), content="1")
inspect(child.is_child(), content="true")

parent.destroy()

#
EntityLifecycleState

type EntityLifecycleState derive(Eq,
Debug
)

#
alive_entity_count

fn alive_entity_count() -> Int

#
entity_flush_system

fn entity_flush_system(_delta : Double) -> Unit

#
get_roots

fn get_roots() -> Iter[Entity]

Returns an iterator over all root entities in the hierarchy.

Root entities are parent entities (entities that have spawned children) that are not themselves children of another entity. They serve as the starting points for hierarchical transform propagation in the @transform.transform_propagate_system.

Important: Only entities that have called spawn_child() at least once can be root entities. Standalone entities created with Entity() that have never spawned children are not considered roots and will not be returned by this function.

Returns an Iter[Entity] that yields all root parent entities.

Example:

@entity.entity_flush_system(0.0)

let root1 = @entity.Entity()
let root2 = @entity.Entity()
let child1 = root1.spawn_child()
let _grandchild = child1.spawn_child()

// root1 and root2 are roots (parents but not children)
// child1 is not a root (it's both a parent and a child)
let roots = @entity.get_roots().collect()
inspect(roots.length(), content="1")

root1.destroy()
root2.destroy()

#
iter_entities

fn iter_entities() -> Iter[Entity]

Source Files