Components module
Enumerations
- InactiveNodes
The policy to include inactive nodes.
- Values:
Exclude = 0 - Exclude inactive nodes.
Include = 1 - Include inactive nodes.
Classes
- Component
Represents a base class for components.
- Fields:
thisHash : uint64 - The hash value of the component.
nodeId : NodeId - The scene node ID that the component is attached to.
- NativeComponent : Component
Represents a base class for native (not user-defined) components.
Functions
add_component_once (node: NodeId; var component: auto(T)?) : T?
has_component (node: NodeId; component: Component const?) : bool
get_components (node: NodeId; var buffer: array<Component?>) : int
get_components (node: NodeId; cb: block<(comp:Component?):void>) : int
remove_component (node: NodeId; component: Component?) : bool
has_component (node: NodeId; component_type: auto(TT)) : bool
remove_component (node: NodeId; component_type: auto(TT)) : bool
get_component (node: NodeId; blk: block<(var comp:auto(TT)? ==const):void>) : bool
get_component (node: NodeId; blk: block<(comp:auto(TT)? ==const):void>) : bool
get_component (node: NodeId; component_type: auto(TT)) : TT?
get_component_as (node: NodeId; blk: block<(var comp:auto(TT)? ==const):void>) : bool
get_component_as (node: NodeId; blk: block<(comp:auto(TT)? ==const):void>) : bool
require_component (node: NodeId; component_type: auto(TT)) : TT?
find_components (component: auto(TT); policy: InactiveNodes = InactiveNodes.Exclude) : array<TT?>
find_components (var buffer: array<auto(TT)?>; policy: InactiveNodes = InactiveNodes.Exclude) : int
find_component (blk: block<(comp:auto(TT)? ==const):void>) : bool
find_component (policy: InactiveNodes; blk: block<(comp:auto(TT)? ==const):void>) : bool
find_component (blk: block<(var comp:auto(TT)? ==const):void>) : bool
find_component (policy: InactiveNodes; blk: block<(var comp:auto(TT)? ==const):void>) : bool
find_component (component_type: auto(TT); policy: InactiveNodes = InactiveNodes.Exclude) : TT?
- add_component(node: NodeId; component: auto(T)?): T?
Adds a component to a node. If component already exists, applies the new component values to the existing component and returns it.
- Arguments:
node : NodeId - The node to add the component to.
component : auto(T)? - The component to add.
- Returns:
T? - The added component. If component of the same type already exists, returns the existing component.
Usage example:
add_component(node, new Mesh(meshId = cubeMesh, materialId = greenMaterial))
- add_component_once(node: NodeId; component: auto(T)?): T?
Adds a component to a node. If component of the same type already exists, returns previous component and ignores the new one.
- Arguments:
node : NodeId - The node to add the component to.
component : auto(T)? - The component to add.
- Returns:
T? - The added component.
Usage example:
add_component_once(node, new Camera(fov = 0.2))
- has_component(node: NodeId; component: Component const?): bool
Checks if a scene node has a specific component.
- Arguments:
- Returns:
bool - True if the scene node has the component, false otherwise.
Usage example:
if has_component(node, someComponent) {
print("node still has someComponent")
}
- get_components(node: NodeId): array<Component?>
Gets all components attached to a scene node.
- Arguments:
node : NodeId - The scene node ID.
- Returns:
array< Component ?> - An array of components.
Usage example:
var inscope components = get_components(node)
// do something with the components array
- get_components(node: NodeId; buffer: array<Component?>): int
Gets all components attached to a scene node and fills the provided buffer.
- Arguments:
- Returns:
int - The number of components.
Usage example:
var inscope components : array<Component?>
get_components(node, components)
// do something with the components array
- get_components(node: NodeId; cb: block<(comp:Component?):void>): int
Warning
This is unsafe operation.
Gets all components attached to a scene node and calls the provided block for each component.
- Arguments:
- Returns:
int - The number of components.
- remove_component(node: NodeId; component: Component?): bool
Removes a component from a node.
- Arguments:
- Returns:
bool - True if the component was removed, false otherwise.
Usage example:
remove_component(node, cameraComp)
- has_component(node: NodeId; component_type: auto(TT)): bool
Checks if a scene node has a specific component type.
- Arguments:
node : NodeId - The scene node ID.
component_type : auto(TT) - The component type to check.
- Returns:
bool - True if the scene node has the component by type, false otherwise.
Usage example:
if has_component(node, type<RigidBody>) {
print("node has RigidBody component")
}
- has_component_as(node: NodeId; component: auto(TT)): bool
Checks if a scene node has a component of the given type or any of its subclasses.
- Arguments:
node : NodeId - The scene node ID.
component : auto(TT) - The component type to check for.
- Returns:
bool - True if the node has a matching component (taking inheritance into account), false otherwise.
Usage example:
if has_component_as(node, type<BaseComponent>) {
print("node has a BaseComponent or derived type")
}
Note
This function performs a linear search through all components attached to the node, so it may be less efficient than has_component function.
- remove_component(node: NodeId; component_type: auto(TT)): bool
Removes a component from a node.
- Arguments:
node : NodeId - The node to remove the component from.
component_type : auto(TT) - The type of the component to remove.
- Returns:
bool - True if the component was removed, false otherwise.
Usage example:
remove_component(node, type<RigidBody>)
- get_component(node: NodeId; blk: block<(var comp:auto(TT)? ==const):void>): bool
Gets a specific component attached to a scene node and calls the provided block for the component. The component can change within the block.
- Arguments:
node : NodeId - The scene node ID.
blk : block<(comp:auto(TT)?!):void> - The block to call for the component.
- Returns:
bool - True if the component was found, false otherwise.
Usage example:
get_component(node) $(var rigidBodyComp : RigidBody?) {
// do something with the component
}
- get_component(node: NodeId; blk: block<(var comp1:auto(TT1)? ==const;var comp2:auto(TT2)? ==const):void>): bool
Gets a specific components attached to a node and calls the provided block for the components. The components can change within the block.
- Arguments:
node : NodeId - The scene node ID.
blk : block<(comp1:auto(TT1)?!;comp2:auto(TT2)?!):void> - The block to call for the components.
- Returns:
bool - True if the components were found, false otherwise.
Usage example:
get_component(node) $(var comp1 : T1?; var comp2 : T2?) {
// do something with the components
}
- get_component(node: NodeId; blk: block<(var comp1:auto(TT1)? ==const;var comp2:auto(TT2)? ==const;var comp3:auto(TT3)? ==const):void>): bool
Gets a specific components attached to a node and calls the provided block for the components. The components can’t change within the block.
- Arguments:
node : NodeId - The scene node ID.
blk : block<(comp1:auto(TT1)?!;comp2:auto(TT2)?!;comp3:auto(TT3)?!):void> - The block to call for the components.
- Returns:
bool - True if the components were found, false otherwise.
Usage example:
get_component(node) $(var comp1 : T1?; var comp2 : T2?; var comp3 : T3?) {
// do something with the components
}
- get_component(node: NodeId; blk: block<(comp:auto(TT)? ==const):void>): bool
Gets a specific component attached to a scene node and calls the provided block for the component. The component can’t change within the block.
- Arguments:
node : NodeId - The scene node ID.
blk : block<(comp:auto(TT)?!):void> - The block to call for the component.
- Returns:
bool - True if the component was found, false otherwise.
Usage example:
get_component(node) $(rigidBodyComp : RigidBody?) {
// do something with the component
}
- get_component(node: NodeId; blk: block<(comp1:auto(TT1)? ==const;comp2:auto(TT2)? ==const):void>): bool
Gets a specific components attached to a node and calls the provided block for the components. The components can’t change within the block.
- Arguments:
node : NodeId - The scene node ID.
blk : block<(comp1:auto(TT1)?!;comp2:auto(TT2)?!):void> - The block to call for the components.
- Returns:
bool - True if the components were found, false otherwise.
Usage example:
get_component(node) $(comp1 : T1?; comp2 : T2?) {
// do something with the components
}
- get_component(node: NodeId; blk: block<(comp1:auto(TT1)? ==const;comp2:auto(TT2)? ==const;comp3:auto(TT3)? ==const):void>): bool
Gets a specific components attached to a node and calls the provided block for the components. The components can’t change within the block.
- Arguments:
node : NodeId - The scene node ID.
blk : block<(comp1:auto(TT1)?!;comp2:auto(TT2)?!;comp3:auto(TT3)?!):void> - The block to call for the components.
- Returns:
bool - True if the components were found, false otherwise.
Usage example:
get_component(node) $(comp1 : T1?; comp2 : T2?; comp3 : T3?) {
// do something with the components
}
- get_component(node: NodeId; component_type: auto(TT)): TT?
Gets a specific component attached to a scene node.
- Arguments:
node : NodeId - The scene node ID.
component_type : auto(TT) - The component type.
- Returns:
TT? - The component if found, null otherwise.
Usage example:
var rigidBodyComp = get_component(node, type<RigidBody>)
if (rigidBodyComp != null) {
// do something with the component
}
- get_component_as(node: NodeId; blk: block<(var comp:auto(TT)? ==const):void>): bool
Retrieves a component attached to a scene node by type, considering inheritance.
Unlike get_component(), this function will also return components that
derive from the requested type.
- Arguments:
node : NodeId - The scene node ID.
blk : block<(comp:auto(TT)?!):void> - The block to call for the component.
- Returns:
bool - True if the component was found, false otherwise.
Usage example:
get_component(node) $(var comp : BaseComponent?) {
comp.do_something()
}
Note
This function performs a linear search through all components attached to the node, so it may be less efficient than get_component function.
- get_component_as(node: NodeId; blk: block<(comp:auto(TT)? ==const):void>): bool
Retrieves a component attached to a scene node by type, considering inheritance.
Unlike get_component(), this function will also return components that
derive from the requested type.
- Arguments:
node : NodeId - The scene node ID.
blk : block<(comp:auto(TT)?!):void> - The block to call for the component.
- Returns:
bool - True if the component was found, false otherwise.
Usage example:
get_component(node) $(comp : BaseComponent?) {
comp.do_something()
}
Note
This function performs a linear search through all components attached to the node, so it may be less efficient than get_component function.
- get_component_as(node: NodeId; component: auto(TT)): TT?
Retrieves a component attached to a scene node by type, considering inheritance.
Unlike get_component(), this function will also return components that
derive from the requested type.
- Arguments:
node : NodeId - The scene node ID.
component : auto(TT) - The component type to search for.
- Returns:
TT? - The component instance if found, or null if no matching component exists.
Usage example:
let comp : BaseComponent? = get_component_as(node, type<BaseComponent>)
if (comp != null) {
comp.do_something()
}
Note
This function performs a linear search through all components attached to the node, so it may be less efficient than get_component function.
- require_component(node: NodeId; component_type: auto(TT)): TT?
Gets a specific component attached to a scene node. If the component is not found, it will be added to the node. In case then node is invalid, an error will be printed and null will be returned.
- Arguments:
node : NodeId - The scene node ID.
component_type : auto(TT) - The component type.
- Returns:
TT? - The component if found, null otherwise.
Usage example:
var rigidBodyComp = require_component(node, type<RigidBody>)
// do something with the component
- find_components(component: auto(TT); policy: InactiveNodes = InactiveNodes.Exclude): array<TT?>
Gets all scene components by type.
Note
This function performs a linear search through all nodes present in the scene, so it is not recommended to use it in performance-critical code.
- Arguments:
component : auto(TT) - The component type.
policy : InactiveNodes - The policy to include inactive components. By default, inactive components are excluded.
- Returns:
array<TT?> - An array of components.
Usage example:
for (rigidBody in find_components(type<RigidBody>)) {
// do something with each rigidBody
}
- find_components(buffer: array<auto(TT)?>; policy: InactiveNodes = InactiveNodes.Exclude): int
Gets all scene components by type and fills the provided buffer.
Note
This function performs a linear search through all nodes present in the scene, so it is not recommended to use it in performance-critical code.
- Arguments:
buffer : array<auto(TT)?> - The buffer to store the scene nodes.
policy : InactiveNodes - The policy to include inactive components. By default, inactive components are excluded.
- Returns:
int - The number of found components.
Usage example:
var inscope rigidBodies : array<RigidBody>
find_components(rigidBodies)
// do something with rigidBodies
- find_component(blk: block<(comp:auto(TT)? ==const):void>): bool
Finds the first component that matches the type of the argument and calls the provided block for the component. Returns only components attached to active nodes.
Note
This function performs a linear search through all nodes present in the scene, so it is not recommended to use it in performance-critical code. It might be better to use the get_component() function with a previously cached node instead.
- Arguments:
blk : block<(comp:auto(TT)?!):void> - The block to call for the component.
- Returns:
bool - True if the component was found, false otherwise.
Usage example:
find_component() $(camera : Camera?) {
// do something with active camera
}
- find_component(policy: InactiveNodes; blk: block<(comp:auto(TT)? ==const):void>): bool
Finds the first component that matches the type of the argument and calls the provided block for the component.
Note
This function performs a linear search through all nodes present in the scene, so it is not recommended to use it in performance-critical code. It might be better to use the get_component() function with a previously cached node instead.
- Arguments:
policy : InactiveNodes - The policy to include inactive components.
blk : block<(comp:auto(TT)?!):void> - The block to call for the component.
- Returns:
bool - True if the component was found, false otherwise.
Usage example:
find_component(InactiveNodes.Include) $(camera : Camera?) {
// do something with camera, camera can be inactive
}
- find_component(blk: block<(var comp:auto(TT)? ==const):void>): bool
Finds the first component that matches the type of the argument and calls the provided block for the component. Returns only active components.
Note
This function performs a linear search through all nodes present in the scene, so it is not recommended to use it in performance-critical code. It might be better to use the get_component() function with a previously cached node instead.
- Arguments:
blk : block<(comp:auto(TT)?!):void> - The block to call for the component.
- Returns:
bool - True if the component was found, false otherwise.
Usage example:
find_component() $(var camera : Camera?) {
// do something with camera
}
- find_component(policy: InactiveNodes; blk: block<(var comp:auto(TT)? ==const):void>): bool
Finds the first component that matches the type of the argument and calls the provided block for the component.
Note
This function performs a linear search through all nodes present in the scene, so it is not recommended to use it in performance-critical code. It might be better to use the get_component() function with a previously cached node instead.
- Arguments:
policy : InactiveNodes - The policy to include inactive components.
blk : block<(comp:auto(TT)?!):void> - The block to call for the component.
- Returns:
bool - True if the component was found, false otherwise.
Usage example:
find_component(InactiveNodes.Include) $(var camera : Camera?) {
// do something with camera
}
- find_component(component_type: auto(TT); policy: InactiveNodes = InactiveNodes.Exclude): TT?
Finds the first component that matches the given type.
Note
This function performs a linear search through all nodes present in the scene, so it is not recommended to use it in performance-critical code. It might be better to use the get_component() function with a previously cached node instead.
- Arguments:
component_type : auto(TT) - The component type.
policy : InactiveNodes - The policy to include inactive components. By default, inactive components are excluded.
- Returns:
TT? - The component if found, null otherwise.
Usage example:
var camera : Camera? = find_component(type<Camera>)
if (camera != null) {
// do something with camera
}