class Rsrb::Engine::ActionQueue

Stores a queue of pending actions.

Attributes

current_action[R]

The current Action being processed.

queue[R]

A queue of Action objects.

Public Class Methods

new() click to toggle source

Creates an empty action queue.

# File lib/rsrb/core/engine.rb, line 125
def initialize
  @queue = []
  @current_action = nil
end

Public Instance Methods

add(action) click to toggle source

Adds an Action to the queue.

# File lib/rsrb/core/engine.rb, line 143
def add(action)
  return if @queue.size >= @@max_size

  if action.queue_policy == QueuePolicy::NEVER
    size = @queue.size + (@current_action == nil ? 0 : 1)
    return if size > 0
  end

  @queue << action
  next_action
end
cancel() click to toggle source

Cancels all queued action events.

# File lib/rsrb/core/engine.rb, line 131
def cancel
  @queue.each {|action|
    action.stop
  }
  @queue.clear
  unless @current_action == nil
    @current_action.stop
    @current_action = nil
  end
end
clear_non_walkable() click to toggle source

Purges actions in the queue with a WalkablePolicy of NON_WALKABLE.

# File lib/rsrb/core/engine.rb, line 156
def clear_non_walkable
  if @current_action != nil and @current_action.walkable_policy != WalkablePolicy::WALKABLE
    @current_action.stop
    @current_action = nil
  end

  @queue.each {|action|
    if action.walkable_policy != WalkablePolicy::WALKABLE
      action.stop
      @queue.delete action
    end
  }
end
next_action() click to toggle source

Processes next action.

# File lib/rsrb/core/engine.rb, line 171
def next_action
  unless @current_action == nil
    @current_action = nil unless @current_action.running
  end

  if @queue.size > 0
    @current_action = @queue.shift
    WORLD.submit_event @current_action
  end
end