mirror of
https://github.com/specht/champ.git
synced 2024-06-24 09:29:32 +00:00
Added --no-animation arg
This commit is contained in:
parent
4fc6ef84ac
commit
68bfd5dadf
49
champ.rb
49
champ.rb
|
@ -20,17 +20,21 @@ class Champ
|
||||||
STDERR.puts 'Usage: ./champ.rb [options] <config.yaml>'
|
STDERR.puts 'Usage: ./champ.rb [options] <config.yaml>'
|
||||||
STDERR.puts 'Options:'
|
STDERR.puts 'Options:'
|
||||||
STDERR.puts ' --max-frames <n>'
|
STDERR.puts ' --max-frames <n>'
|
||||||
|
STDERR.puts ' --no-animation'
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
@files_dir = 'report-files'
|
@files_dir = 'report-files'
|
||||||
FileUtils.rm_rf(@files_dir)
|
FileUtils.rm_rf(@files_dir)
|
||||||
FileUtils.mkpath(@files_dir)
|
FileUtils.mkpath(@files_dir)
|
||||||
@max_frames = nil
|
@max_frames = nil
|
||||||
|
@record_frames = true
|
||||||
args = ARGV.dup
|
args = ARGV.dup
|
||||||
while args.size > 1
|
while args.size > 1
|
||||||
item = args.shift
|
item = args.shift
|
||||||
if item == '--max-frames'
|
if item == '--max-frames'
|
||||||
@max_frames = args.shift.to_i
|
@max_frames = args.shift.to_i
|
||||||
|
elsif item == '--no-animation'
|
||||||
|
@record_frames = false
|
||||||
else
|
else
|
||||||
STDERR.puts "Invalid argument: #{item}"
|
STDERR.puts "Invalid argument: #{item}"
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -141,11 +145,16 @@ class Champ
|
||||||
stdin.puts watch_input
|
stdin.puts watch_input
|
||||||
stdin.close
|
stdin.close
|
||||||
catch :sigint do
|
catch :sigint do
|
||||||
gi, go, gt = Open3.popen2("./pgif 280 192 4 > #{File.join(@files_dir, 'frames.gif')}")
|
gi = nil
|
||||||
gi.puts '000000'
|
go = nil
|
||||||
gi.puts 'ffffff'
|
gt = nil
|
||||||
gi.puts '000000'
|
if @record_frames
|
||||||
gi.puts 'ffffff'
|
gi, go, gt = Open3.popen2("./pgif 280 192 4 > #{File.join(@files_dir, 'frames.gif')}")
|
||||||
|
gi.puts '000000'
|
||||||
|
gi.puts 'ffffff'
|
||||||
|
gi.puts '000000'
|
||||||
|
gi.puts 'ffffff'
|
||||||
|
end
|
||||||
stdout.each_line do |line|
|
stdout.each_line do |line|
|
||||||
# puts "> #{line}"
|
# puts "> #{line}"
|
||||||
parts = line.split(' ')
|
parts = line.split(' ')
|
||||||
|
@ -177,17 +186,19 @@ class Champ
|
||||||
print "\rFrames: #{@frame_count}, Cycles: #{cycle_count}"
|
print "\rFrames: #{@frame_count}, Cycles: #{cycle_count}"
|
||||||
this_frame_cycles = parts[1].to_i
|
this_frame_cycles = parts[1].to_i
|
||||||
frame_cycles << this_frame_cycles
|
frame_cycles << this_frame_cycles
|
||||||
data = parts[2, parts.size - 2].map { |x| x.to_i }
|
if @record_frames
|
||||||
gi.puts 'l'
|
data = parts[2, parts.size - 2].map { |x| x.to_i }
|
||||||
(0...192).each do |y|
|
gi.puts 'l'
|
||||||
(0...280).each do |x|
|
(0...192).each do |y|
|
||||||
b = (data[y * 40 + (x / 7)] >> (x % 7)) & 1
|
(0...280).each do |x|
|
||||||
gi.print b
|
b = (data[y * 40 + (x / 7)] >> (x % 7)) & 1
|
||||||
|
gi.print b
|
||||||
|
end
|
||||||
|
gi.puts
|
||||||
end
|
end
|
||||||
gi.puts
|
|
||||||
end
|
|
||||||
|
|
||||||
gi.puts "d #{(this_frame_cycles - last_frame_time) / 10000}"
|
gi.puts "d #{(this_frame_cycles - last_frame_time) / 10000}"
|
||||||
|
end
|
||||||
last_frame_time = this_frame_cycles
|
last_frame_time = this_frame_cycles
|
||||||
|
|
||||||
if @max_frames && @frame_count >= @max_frames
|
if @max_frames && @frame_count >= @max_frames
|
||||||
|
@ -198,8 +209,10 @@ class Champ
|
||||||
print "\rFrames: #{@frame_count}, Cycles: #{cycle_count}"
|
print "\rFrames: #{@frame_count}, Cycles: #{cycle_count}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
gi.close
|
if @record_frames
|
||||||
gt.join
|
gi.close
|
||||||
|
gt.join
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts
|
puts
|
||||||
|
@ -223,7 +236,9 @@ class Champ
|
||||||
|
|
||||||
# write frames
|
# write frames
|
||||||
io = StringIO.new
|
io = StringIO.new
|
||||||
io.puts "<img class='screenshot' src='#{File.join(@files_dir, 'frames.gif')}' /><br />"
|
if @record_frames
|
||||||
|
io.puts "<img class='screenshot' src='#{File.join(@files_dir, 'frames.gif')}' /><br />"
|
||||||
|
end
|
||||||
if @cycles_per_frame.size > 0
|
if @cycles_per_frame.size > 0
|
||||||
io.puts '<p>'
|
io.puts '<p>'
|
||||||
io.puts "Frames recorded: #{@frame_count}<br />"
|
io.puts "Frames recorded: #{@frame_count}<br />"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user