Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Major bug fix to simulation.rb. Was leaking events

  • Loading branch information...
commit 71a41f8e0222e98abc662082024dc460bcb8b1a4 1 parent d2be8e5
Cyrus Hall authored
Showing with 11 additions and 3 deletions.
  1. +3 −1 goviz
  2. +5 −1 lib/gosim/data.rb
  3. +3 −1 lib/gosim/simulation.rb
View
4 goviz
@@ -1,13 +1,15 @@
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
+
+require 'rational'
require 'gosim/view'
if ARGV[0] and File.exists?(ARGV[0])
$LOAD_PATH.unshift(File.expand_path(File.dirname(ARGV[0])))
puts "Loading simulation file: #{File.basename(ARGV[0])}"
- require ARGV[0]
+ load ARGV[0]
end
GoSim::View.instance.run
View
6 lib/gosim/data.rb
@@ -12,6 +12,10 @@ def add_handler(key, &block)
@@handlers[key] ||= []
@@handlers[key] << block
end
+
+ def [](set)
+ @@sets[set]
+ end
end
def initialize(name, location='./')
@@ -28,7 +32,7 @@ def log(*args)
if @@handlers[@name]
@@handlers[@name].each {|h| h.call(*args) }
elsif @data_file
- @data_file.write(@sim.time.to_s + ', ' + args.join(', ') + "\n")
+ @data_file.write(@sim.time.to_s + ': ' + args.join(', ') + "\n")
end
end
View
4 lib/gosim/simulation.rb
@@ -189,9 +189,11 @@ def run(end_time = MAX_INT)
#log ("Running simulation until: #{end_time}")
begin
- while(@running and (cur_event = @event_queue.pop) and (cur_event.time <= end_time))
+ while(@running and (cur_event = @event_queue.top) and (cur_event.time <= end_time))
#log ("Handling %s event at %d\n" % [cur_event.data.class, cur_event.time])
+ @event_queue.pop
+
@time = last_time = cur_event.time
@entities[cur_event.dest_id].send(cur_event.event_id, cur_event.data)
Please sign in to comment.
Something went wrong with that request. Please try again.