class Crash::Engine

Included Modules

Defined in:

crash/engine.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def add_entity(entity : Crash::Entity) #

Add an entity to the engine.


[View source]
def 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.


[View source]
def add_system(system : Crash::System) #

[View source]
def entities : Array(Crash::Entity) #

[View source]
def 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.


[View source]
def get_entity_by_name(name : String) : Crash::Entity | Nil #

Get an entity based on its name.


[View source]
def get_system(type : Crash::System.class) : Crash::System | Nil #

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


[View source]
def 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.


[View source]
def remove_all_entities #

Remove all entities from the engine.


[View source]
def remove_all_systems #

Remove all systems from the engine.


[View source]
def remove_entity(entity : Crash::Entity) #

Remove an entity from the engine.


[View source]
def remove_system(system : Crash::System) #

Remove a system from the engine.


[View source]
def systems : Array(Crash::System) #

[View source]
def 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.

[View source]
def updating : Bool #

Indicates if the engine is currently in its update loop.


[View source]