Browse files

Frame rate is capped; prevent hyper warp speed.

  • Loading branch information...
1 parent d62bb38 commit d4962dfd36b1b3484b4466cf13e299774749c9b9 @pda committed Jan 15, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 asc.rb
View
14 asc.rb
@@ -10,21 +10,22 @@ def reset
end
def run
loop do
+ start_time = Time.new.to_f
unless @world.tick
reset
end
- render
+ render start_time
end
end
- def render
+ def render start_time
@world.buildings.each do |building|
@screen.draw(building)
end
@screen.draw(@world.player)
@world.misc.each do |object|
@screen.draw(object)
end
- @screen.render
+ @screen.render start_time
end
end
@@ -45,7 +46,7 @@ def draw renderable
@fb.set x, y, char
end
end
- def render
+ def render start_time
print "\e[H"
buffer = ''
(0...height).each do |y|
@@ -55,6 +56,11 @@ def render
buffer << "\n"
end
buffer << " ." * (width / 2)
+
+ dt = Time.new.to_f - start_time;
+ target_time = 0.04
+ sleep target_time - dt if dt < target_time
+
print buffer
create_frame_buffer
end

0 comments on commit d4962df

Please sign in to comment.