Esempio n. 1
0
 def on_idle(self, idle_event: events.Idle, signal):
     if self.last_tick is None:
         self.last_tick = ppb.get_time()
     this_tick = ppb.get_time()
     self.accumulated_time += this_tick - self.last_tick
     self.last_tick = this_tick
     while self.accumulated_time >= self.time_step:
         # This might need to change for the Idle event system to signal _only_ once per idle event.
         self.accumulated_time += -self.time_step
         signal(events.Update(self.time_step))
Esempio n. 2
0
 def on_update(self, event, signal):
     """
     Fires at the update rate (~60 times a second)
     """
     t = ppb.get_time() - self.start_time
     if t >= self.duration:
         signal(ppb.events.Quit())
Esempio n. 3
0
    def on_pre_render(self, event, signal):
        """
        Fires each frame.

        The frame rate is variable and different from the update rate.
        """
        t = ppb.get_time() - self.start_time
        self.frames += 1
        print(f"Frame {self.frames} rendered at {t}")
Esempio n. 4
0
 def __init__(self,
              *,
              fail: Callable[[GameEngine], bool],
              message: str,
              run_time: float = 1,
              engine,
              **kwargs):
     super().__init__(**kwargs)
     self.fail = fail
     self.message = message
     self.start = ppb.get_time()
     self.run_time = run_time
     self.engine = engine
Esempio n. 5
0
 def __enter__(self):
     self.start_time = ppb.get_time()
Esempio n. 6
0
 def on_idle(self, idle_event: Idle, signal):
     if ppb.get_time() - self.start > self.run_time:
         raise AssertionError("Test ran too long.")
     if self.fail(self.engine):
         raise AssertionError(self.message)
Esempio n. 7
0
    def __init__(self, *p, **kw):
        super().__init__(*p, **kw)

        self.frames = 0
        self.start_time = ppb.get_time()