Component is a functional unit that can be added to an Entity instance. This is the base class for all components in the ECS (Entity-Component-System) architecture. Components provide specific functionality and data to entities.

Hierarchy (view full)

Constructors

  • The constructor of the Component class. When creating a Component, use the createComponent method of the ComponentRepository class instead of directly calling this constructor.

    Parameters

    • entityUid: number

      Unique ID of the corresponding entity

    • componentSid: number

      Scoped ID of the Component

    • entityRepository: EntityRepository

      The instance of the EntityRepository class (Dependency Injection)

    • isReUse: boolean

      Whether this component is being reused from a pool

    Returns Component

Properties

__currentProcessStage: ProcessStageEnum = ProcessStage.Load
__entityRepository: EntityRepository

the instance of EntityRepository

__entityUid: number

the entity unique Id which this component belongs to

__memoryManager: MemoryManager

the instance of MemoryManager

_isAlive: boolean = true
_tags: RnTags = {}

Collection of tags associated with this object

InvalidObjectUID: -1 = -1

Invalid object UID constant

_processStages: ProcessStageEnum[] = ...
currentMaxObjectCount: number = 0

Current maximum object count for UID generation

Accessors

  • get componentSID(): number
  • Gets the Scoped ID of this Component instance. The SID is unique within the component type and represents the instance index.

    Returns number

    The component scoped ID

  • get componentTID(): number
  • Gets the Type ID of this Component instance. This is overridden by concrete component classes to provide unique type identification.

    Returns number

    The component type ID (default: 0)

  • get entityUID(): number
  • Gets the unique ID of the entity that owns this component.

    Returns number

    The entity unique ID

  • get maxNumberOfComponent(): number
  • Gets the maximum number of components of this type that can exist.

    Returns number

    The maximum number of components

  • get objectUID(): number
  • Gets the unique object identifier

    Returns number

    The object's UID

  • get uniqueName(): string
  • Gets the unique name of this object

    Returns string

    The unique name string

  • get componentTID(): number
  • Gets the Type ID of the Component class. This is overridden by concrete component classes to provide unique type identification.

    Returns number

    The component type ID (default: 0)

Methods

  • Internal

    Marks this component as destroyed and no longer alive. This is used internally to manage component lifecycle.

    Returns void

  • Internal

    Sets the maximum number of components of this type that can exist. This method is intended to be called by component classes only.

    Parameters

    • value: number

      The maximum number of components

    Returns void

  • Performs a shallow copy of data from another component of the same type. This method should be implemented by concrete component classes as needed.

    Parameters

    • component: Component

      The source component to copy from

    Returns void

  • Gets detailed byte information about a specific member field of this component. This includes offsets, lengths, and location information for GPU access.

    Parameters

    • memberName: string

      The name of the member field

    Returns {
        byteLength: number;
        byteOffsetInBuffer: number;
        byteOffsetInThisComponent: any;
        componentNumber: number;
        locationOffsetInBuffer: number;
        locationOffsetInThisComponent: any;
        thisComponentByteOffsetInBuffer: number;
        thisComponentLocationOffsetInBuffer: number;
    }

    Detailed byte information object

    • byteLength: number
    • byteOffsetInBuffer: number
    • byteOffsetInThisComponent: any
    • componentNumber: number
    • locationOffsetInBuffer: number
    • locationOffsetInThisComponent: any
    • thisComponentByteOffsetInBuffer: number
    • thisComponentLocationOffsetInBuffer: number
  • Retrieves a complete tag object (name and value) for the specified tag name

    Parameters

    • tagName: string

      The name of the tag to retrieve

    Returns Tag

    A Tag object containing the name and value

  • Retrieves the value associated with a specific tag name

    Parameters

    • tagName: string

      The name of the tag whose value to retrieve

    Returns any

    The tag value, or undefined if the tag doesn't exist

  • Checks whether this object has a tag with the specified name

    Parameters

    • tagName: string

      The name of the tag to check for

    Returns boolean

    True if the tag exists (value is not null/undefined), false otherwise

  • Checks whether the specified ProcessStage method exists in this Component instance. This is used to determine if this component can handle a particular process stage.

    Parameters

    Returns boolean

    True if the method exists, false otherwise

  • Checks if this object has a tag with the specified name and value

    Parameters

    • tagName: string

      The tag name to match

    • tagValue: string

      The tag value to match

    Returns boolean

    True if the object has a matching tag, false otherwise

  • Checks if this object has all the specified tags with exactly matching values

    Parameters

    • tags: RnTags

      Object containing tag names as keys and expected values

    Returns boolean

    True if all specified tags exist with matching values, false otherwise

  • Checks if the object's combined tag string contains all the provided search strings. This allows for flexible searching within tag names and values.

    Parameters

    • stringArray: string[]

      Array of strings that must all be present in the combined tag string

    Returns boolean

    True if all strings are found in the combined tag string, false otherwise

  • Transitions the component to a different process stage. This affects which update methods will be called during the frame processing.

    Parameters

    Returns void

  • Registers a dependency relationship with another component. This method is intended for future use in managing component dependencies.

    Parameters

    • component: Component

      The component to depend on

    • isMust: boolean

      Whether this dependency is required

    Returns void

    This method is not used yet and needs implementation

  • Registers a member field of the component class for memory allocation. This method defines the memory layout and characteristics of component data members.

    Parameters

    • bufferUse: EnumIO

      The intended purpose/type of buffer use

    • memberName: string

      The name of the member field

    • dataClassType: unknown

      The class type of the data

    • componentType: ComponentTypeEnum

      The primitive data type (e.g., Float32, Int32)

    • initValues: number[]

      Initial values for the member field

    Returns void

  • Allocates memory for all member fields of this component instance. This method is called during component initialization to set up memory layout and allocate space for the specified number of entities.

    Parameters

    • count: number

      The number of entities to allocate memory for

    • isReUse: boolean

      Whether to reuse existing memory allocations

    Returns void

  • Allocates memory for a specific member field of this component instance. This method takes one memory slot from the shared memory pool for the specified member.

    Parameters

    • memberName: string

      The name of the member field

    • dataClassType: any

      The data class type for the member

    • initValues: number[]

      Initial values to set for the member

    • isReUse: boolean

      Whether to reuse an existing memory slot

    • componentSid: number

      The component scoped ID

    Returns any

    null on success

  • Attempts to set a tag on this object. If the tag already exists, it will be replaced.

    Parameters

    • tag: Tag

      The tag object containing the name and value to set

    Returns boolean

    True if the tag was successfully set, false if the tag name contains invalid characters

  • Attempts to set a unique name for this object

    Parameters

    • name: string

      The desired unique name

    • toAddNameIfConflict: boolean

      If true, appends UID to make name unique when conflicts occur; if false, fails on conflict

    Returns boolean

    True if the name was successfully set, false if there was a conflict and toAddNameIfConflict was false

  • Validates that a tag string contains only allowed characters (alphanumeric and underscore)

    Parameters

    • val: string

      The string to validate

    Returns boolean

    True if the string contains only valid characters, false if it contains invalid characters

  • Checks whether the specified ProcessStage method exists in the given Component class. This is used to determine if a component can handle a particular process stage.

    Parameters

    Returns boolean

    True if the method exists, false otherwise

  • Gets the memory accessor for a specific member field of a component class. The accessor provides access to the underlying typed array data.

    Parameters

    • memberName: string

      The name of the member field

    • componentClass: Function

      The component class

    Returns Accessor

    The accessor for the member field

  • Gets the total byte length of all member fields for a specific buffer use type in the given component class.

    Parameters

    • bufferUse: EnumIO

      The buffer use type

    • componentClass: Function

      The component class

    Returns number

    The total byte length of members

  • Gets the byte offset of the first element of a specific member field within the buffer.

    Parameters

    • memberName: string

      The name of the member field

    • componentClass: Function

      The component class

    Returns number

    The byte offset in the buffer

  • Gets the byte offset of the first element of a specific member field within the buffer view.

    Parameters

    • memberName: string

      The name of the member field

    • componentClass: Function

      The component class

    Returns number

    The byte offset in the buffer view

  • Gets the byte offset of the component type's data within the buffer.

    Parameters

    • bufferUse: EnumIO

      The buffer use type

    • componentClass: Function

      The component class

    Returns number

    The byte offset in the buffer

  • Gets the ComponentType of a specific member field in a component class. This is useful for understanding the primitive data type of component members.

    Parameters

    • memberName: string

      The name of the member field

    • componentClass: Function

      The component class to query

    Returns undefined | ComponentTypeEnum

    The ComponentType of the member or undefined if not found

  • Gets the CompositionType of a specific member field in a component class. This is useful for understanding the data structure of component members.

    Parameters

    • memberName: string

      The name of the member field

    • componentClass: Function

      The component class to query

    Returns undefined | CompositionTypeEnum

    The CompositionType of the member or undefined if not found

  • Gets detailed byte information about a member field by Component SID. This is a static version that looks up the component by its scoped ID.

    Parameters

    • componentType: typeof Component

      The component class type

    • componentSID: number

      The scoped ID of the component

    • memberName: string

      The name of the member field

    Returns undefined | {
        byteLength: number;
        byteOffsetInBuffer: number;
        byteOffsetInThisComponent: any;
        componentNumber: number;
        locationOffsetInBuffer: number;
        locationOffsetInThisComponent: any;
        thisComponentByteOffsetInBuffer: number;
        thisComponentLocationOffsetInBuffer: number;
    }

    Detailed byte information object or undefined if component not found

  • Gets detailed byte information about a specific member field of a component. This includes offsets, lengths, and location information for GPU access.

    Parameters

    • component: Component

      The component instance to analyze

    • memberName: string

      The name of the member field

    Returns {
        byteLength: number;
        byteOffsetInBuffer: number;
        byteOffsetInThisComponent: any;
        componentNumber: number;
        locationOffsetInBuffer: number;
        locationOffsetInThisComponent: any;
        thisComponentByteOffsetInBuffer: number;
        thisComponentLocationOffsetInBuffer: number;
    }

    Detailed byte information object

    • byteLength: number
    • byteOffsetInBuffer: number
    • byteOffsetInThisComponent: any
    • componentNumber: number
    • locationOffsetInBuffer: number
    • locationOffsetInThisComponent: any
    • thisComponentByteOffsetInBuffer: number
    • thisComponentLocationOffsetInBuffer: number
  • Gets the pixel location offset in the buffer for a specific member of a component type. This is useful for GPU texture-based data access where locations are measured in pixels.

    Parameters

    • componentType: typeof Component

      The component class type

    • memberName: string

      The name of the member field

    Returns number

    The pixel location offset in the buffer

  • Retrieves an RnObject instance by its unique identifier

    Parameters

    • objectUid: number

      The unique identifier of the object to retrieve

    Returns undefined | RnObject

    The RnObject instance or undefined if not found or garbage collected

  • Processes all components of a given type for a specific process stage. This method iterates through all components of the specified type and calls their corresponding process stage method if they are in that stage.

    Parameters

    Returns void

  • Searches for the first object that has a specific tag with the given value

    Parameters

    • tag: string

      The tag name to search for

    • value: string

      The tag value to match

    Returns undefined | WeakRef<RnObject>

    WeakRef to the first matching object, or undefined if not found

  • Creates and configures a memory accessor for a specific member field. This method allocates buffer memory and creates an accessor for efficient data access.

    Parameters

    • bufferUse: EnumIO

      The intended use of the buffer

    • memberName: string

      The name of the member field

    • componentClass: Function

      The component class

    • compositionType: CompositionTypeEnum

      The composition type (e.g., Vec3, Mat4)

    • componentType: ComponentTypeEnum

      The component data type (e.g., Float32, Int32)

    • count: number

      The number of components to allocate for

    Returns Result<Accessor, undefined>

    Result containing the accessor or an error

  • Updates components specifically for the render stage with render pass context. This method calls the sort_$render method of the component class to handle render-specific processing and sorting.

    Parameters

    Returns any

    The result of the sort_$render method