Add queue info
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
class Game::Queue
|
||||
struct Item
|
||||
def initialize(@ts : Int64, @command : Game::Command)
|
||||
def initialize(@ts : Int64, @command : Command)
|
||||
end
|
||||
|
||||
getter ts
|
||||
@ -11,7 +11,7 @@ class Game::Queue
|
||||
@data = [] of Item
|
||||
end
|
||||
|
||||
def push(ts : Int64, value : Game::Command)
|
||||
def push(ts : Int64, value : Command)
|
||||
# very unoptimal algo
|
||||
@data.push(Item.new(ts, value))
|
||||
@data.sort! do |a, b|
|
||||
@ -25,4 +25,8 @@ class Game::Queue
|
||||
end
|
||||
@data[-1].ts <= ts ? @data.pop : nil
|
||||
end
|
||||
|
||||
def top(n : Int32)
|
||||
@data.last(n).reverse!
|
||||
end
|
||||
end
|
||||
|
@ -6,22 +6,23 @@ class Game::World
|
||||
def initialize(@ts = 0_i64)
|
||||
@map = Map.new
|
||||
@resources = Resources.new
|
||||
@tasks = Queue.new
|
||||
@queue = Queue.new
|
||||
end
|
||||
|
||||
getter ts
|
||||
getter resources
|
||||
getter map
|
||||
getter queue
|
||||
|
||||
def push(command : Command)
|
||||
dur = command.start(self)
|
||||
done_at = @ts + dur.to_i64
|
||||
@tasks.push(done_at, command)
|
||||
@queue.push(done_at, command)
|
||||
end
|
||||
|
||||
def run(ts : Int64)
|
||||
loop do
|
||||
item = @tasks.pop(ts)
|
||||
item = @queue.pop(ts)
|
||||
if item.nil?
|
||||
break
|
||||
end
|
||||
|
Reference in New Issue
Block a user