Class: Darkholme::IteratingSystem

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

Overview

A subclass of System, IteratingSystem automatically loops through entities belonging to it and calls #process on them, along with a before and after callback

Instance Attribute Summary

Attributes inherited from System

#engine

Instance Method Summary collapse

Methods inherited from System

#added_to_engine, #entities, #family, has_family, #removed_from_engine

Instance Method Details

#after_processingObject

Called once a frame after the entities are looped over and processed



37
38
# File 'lib/darkholme/iterating_system.rb', line 37

def after_processing
end

#before_processingObject

Called once a frame before the entities are looped over and processed



33
34
# File 'lib/darkholme/iterating_system.rb', line 33

def before_processing
end

#process(entity, delta) ⇒ Object

Called on each entity in the collection. This where the various components’ data will be manipulated. This must be overridden by the subclass.

Parameters:

  • entity (Entity)

    The entity being manipulated

  • delta (Float)

    The difference in time between the last frame and this one

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/darkholme/iterating_system.rb', line 28

def process(entity, delta)
  raise NotImplementedError.new("You must override #process(entity, delta)")
end

#update(delta) ⇒ Object

Called by the engine, this calls #before_processing, then #process on each entity, then #after_processing

Parameters:

  • delta (Float)

    The difference in time between the last frame and this one

Returns:

  • The result of after_processing



13
14
15
16
17
18
19
# File 'lib/darkholme/iterating_system.rb', line 13

def update(delta)
  before_processing
  entities.each do |entity|
    process(entity, delta)
  end
  after_processing
end