Sha256: a1849462d54287fe8eaf595dfc8f18fc6dbef620c2212a436de4d07aff77b4d1

Contents?: true

Size: 715 Bytes

Versions: 6

Compression:

Stored size: 715 Bytes

Contents

module Lotu
  class StalkerSystem < BaseSystem

    def initialize(user, opts={})
      super
      default_opts = {
        :stalk => [Actor],
        :ticks_per_update => 30
      }
      opts = default_opts.merge!(opts)
      @ticks = 0
      @ticks_per_update = opts[:ticks_per_update]
      @stalked = {}
      opts[:stalk].each do |type|
        @stalked[type] = 0
      end
    end

    def update
      @ticks += 1
      if @ticks >= @ticks_per_update
        @stalked.each_key do |type|
          @stalked[type] = ObjectSpace.each_object(type).count
        end
        @ticks = 0
      end
    end

    def to_s
      @stalked.map do |type, count|
        "#{type}: #{count}"
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lotu-0.1.22 lib/lotu/systems/stalker_system.rb
lotu-0.1.21 lib/lotu/systems/stalker_system.rb
lotu-0.1.20 lib/lotu/systems/stalker_system.rb
lotu-0.1.19 lib/lotu/systems/stalker_system.rb
lotu-0.1.18 lib/lotu/systems/stalker_system.rb
lotu-0.1.16 lib/lotu/systems/stalker_system.rb