class Crash::Engine
- Crash::Engine
- Reference
- Object
Included Modules
- EventHandler
Defined in:
crash/engine.crConstructors
Instance Method Summary
-
#add_entity(entity : Crash::Entity)
Add an entity to the engine.
-
#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.
- #add_system(system : Crash::System)
- #entities : Array(Crash::Entity)
-
#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.
-
#get_entity_by_name(name : String) : Crash::Entity | Nil
Get an entity based on its name.
-
#get_system(type : Crash::System.class) : Crash::System | Nil
Get the system instance of a particular type from within the engine.
-
#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.
-
#remove_all_entities
Remove all entities from the engine.
-
#remove_all_systems
Remove all systems from the engine.
-
#remove_entity(entity : Crash::Entity)
Remove an entity from the engine.
-
#remove_system(system : Crash::System)
Remove a system from the engine.
- #systems : Array(Crash::System)
-
#update
Update the engine.
-
#updating : Bool
Indicates if the engine is currently in its update loop.
Constructor Detail
Instance Method Detail
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.
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.
Get the system instance of a particular type from within the engine.
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.
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.