Class: Darkholme::System

Inherits:
Object
  • Object
show all
Defined in:
lib/darkholme/system.rb

Overview

Updated every frame by the engine, a System manipulates and uses the data contained within a component

Direct Known Subclasses

IteratingSystem

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.familyObject (readonly)

Returns the value of attribute family.



6
7
8
# File 'lib/darkholme/system.rb', line 6

def family
  @family
end

Instance Attribute Details

#engineObject

Returns the value of attribute engine.



25
26
27
# File 'lib/darkholme/system.rb', line 25

def engine
  @engine
end

Class Method Details

.has_family(*component_classes) ⇒ Family

Set the family for a System. Call this from the body of the class.

Examples:

Standard usage

class MySystem < Darkholme::System
  has_family MyComponent, AnotherComponent, LastComponent
end

Parameters:

  • component_classes (Array<Class>)

    List of component classes the system is

Returns:

  • (Family)

    The family for the classes



19
20
21
# File 'lib/darkholme/system.rb', line 19

def has_family(*component_classes)
  @family = Family.for(*component_classes)
end

Instance Method Details

#added_to_engine(engine) ⇒ Object

Callback called after the system has been added to an Engine

Parameters:

  • engine (Engine)

    The engine the system was added to



38
39
40
# File 'lib/darkholme/system.rb', line 38

def added_to_engine(engine)
  self.engine = engine
end

#entitiesArray<Entity>

An Array of all the entities this system is interested in

Returns:

  • (Array<Entity>)

    All the entities with matching components



52
53
54
# File 'lib/darkholme/system.rb', line 52

def entities
  engine.entities_for_family(family)
end

#familyFamily

Get the system’s Family instance

Returns:

  • (Family)

    The system’s family, as defined by #has_family



59
60
61
# File 'lib/darkholme/system.rb', line 59

def family
  self.class.family
end

#removed_from_engine(engine) ⇒ Object

Callback called after the system has been removed from an Engine

Parameters:

  • engine (Engine)

    The engine the system was removed from



45
46
47
# File 'lib/darkholme/system.rb', line 45

def removed_from_engine(engine)
  self.engine = nil if self.engine == engine
end

#update(delta) ⇒ Object

Called once per frame by the engine. This must be overriden by the subclass.

Parameters:

  • delta (Float)

    Difference in time between the last frame and this one

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/darkholme/system.rb', line 31

def update(delta)
  raise NotImplementedError.new("You must override #update(delta)")
end