def run(self): print "Simulation started." self.ticking = True while self.ticking: # rate limit simulation now = time.time() if now >= self.next_tick_time: TheWorld.tick() self.next_tick_time = now + self.ticks_increment #self.next_tick_time = self.next_tick_time + self.ticks_increment #else: # print ".", # sys.stdout.flush() # rate limit redraw if now >= self.next_redraw_time: gtk.gdk.threads_enter() try: TheWorld.queue_draw() finally: gtk.gdk.flush() gtk.gdk.threads_leave() self.next_redraw_time = now + self.redraws_increment #self.next_redraw_time = self.next_redraw_time + self.redraws_increment else: time.sleep(0.00001) # don't suck 100% of cpu!
def run(self): print "Simulation started." self.ticking = True while self.ticking: time.sleep(0.001) # don't suck 100% of cpu! # rate limit simulation now = time.time() if now >= self.next_tick_time: TheWorld.tick() self.next_tick_time = now + self.ticks_increment tick_time = time.time() - now #print 'tick_time: ', time.time() - now # rate limit redraw now = time.time() if now >= self.next_redraw_time: gtk.gdk.threads_enter() try: TheWorld.queue_draw() finally: gtk.gdk.flush() gtk.gdk.threads_leave() self.next_redraw_time = now + self.redraws_increment #draw_time = time.time() - now #print 'draw_time: ', time.time() - now #print "Main loop: %.8f" % (tie.time() - now) #print " tick_time: %.8f" % tick_time #print " draw_time: %.8f" % draw_time # TODO How do we handle things cleanly when one or both elements of main loop is taking longer than tick times ? # We can optimize for constant frame rate - i.e. sim slows down # or we can optimize for constant sim speed - i.e. frame rate slows down # or something inbetween ? # What are the questions we should be asking ? while TheWorld.paused: time.sleep(0.001)
def tick(self): #print 'tick' TheWorld.tick() TheWorld.queue_draw() #print 'tok' return True
def tick(self): TheWorld.tick() return True