class

Crash::Engine

Inherits EventHandler < Reference < Object

Constructors

Instance methods

add_entity(entity : Crash::Entity)

Add an entity to the engine.

Source
add_system(system : Crash::System, priority : Int32)

Add a system to the engine, and set its priority for the order in which the systems are updated by the engine update loop.

The priority dictates the order in which the systems are updated by the engine update loop. Lower numbers for priority are updated first. i.e. a priority of 1 is updated before a priority of 2.

Source
add_system(system : Crash::System)
Source
entities
Source
get_entities(*components : Crash::Component.class) : Array(Crash::Entity)

Get a collection of entities from the engine, based on the type of the components required.

The engine will create the appropriate entity list if it doesn't already exist and will keep its contents up to date as entities are added to and removed from the engine.

If a entity list is no longer required, release it with the release_entities method.

Source
get_entity_by_name(name : String) : Crash::Entity | Nil

Get an entity based on its name.

Source
get_system(type : Crash::System.class) : Crash::System | Nil

Get the system instance of a particular type from within the engine.

Source
release_entities(*components : Crash::Component.class)

If a entity list is no longer required, this method will stop the engine updating the list and will release all references to the list within the framework classes, enabling it to be garbage collected.

It is not essential to release a list, but releasing it will free up memory and processor resources.

Source
remove_all_entities

Remove all entities from the engine.

Source
remove_all_systems

Remove all systems from the engine.

Source
remove_entity(entity : Crash::Entity)

Remove an entity from the engine.

Source
remove_system(system : Crash::System)

Remove a system from the engine.

Source
systems
Source
update

Update the engine. This causes the engine update loop to run, calling update on all the systems in the engine.

If you need to pass variables to your systems you can extend this class.

Example

# in your code
module Crash
  class Engine
    def update(*args : Float32)
      @updating = true
      @systems.each do |system|
        system.update(args)
      end
      @updating = false
      emit UpdateCompleteEvent
    end
  end
end
```

You can do the same for `System ` to then receive the args.
You can also add additional methds in this fashion. E.g. you could add an `input` method.
Source
updating

Indicates if the engine is currently in its update loop.

Source

Nested types