diff --git a/pyboy/pyboy.pxd b/pyboy/pyboy.pxd index 96f4cff70..5f37dcd8b 100644 --- a/pyboy/pyboy.pxd +++ b/pyboy/pyboy.pxd @@ -62,7 +62,7 @@ cdef class PyBoy: @cython.locals(t_start=int64_t, t_pre=int64_t, t_tick=int64_t, t_post=int64_t, nsecs=int64_t) cpdef bint _tick(self, bint) noexcept @cython.locals(running=bint) - cpdef object tick(self, int, bint) noexcept + cpdef bint tick(self, count=*, render=*) noexcept cpdef void stop(self, save=*) noexcept cpdef int save_state(self, object) except -1 cpdef int load_state(self, object) except -1 diff --git a/pyboy/pyboy.py b/pyboy/pyboy.py index 39065f077..1d12fad6b 100644 --- a/pyboy/pyboy.py +++ b/pyboy/pyboy.py @@ -200,7 +200,7 @@ def _tick(self, render): return not self.quitting - def tick(self, count, render): + def tick(self, count=1, render=True): """ Progresses the emulator ahead by one frame. @@ -230,11 +230,7 @@ def tick(self, count, render): _render = render and count == 1 # Only render on last tick to improve performance running = self._tick(_render) count -= 1 - - if render and running: - return self.screen.image - else: - return running + return running def _handle_events(self, events): # This feeds events into the tick-loop from the window. There might already be events in the list from the API. diff --git a/tests/test_external_api.py b/tests/test_external_api.py index 3c41357c7..de3f2f0ed 100644 --- a/tests/test_external_api.py +++ b/tests/test_external_api.py @@ -146,12 +146,7 @@ def test_screen_buffer_and_image(tetris_rom, boot_rom): pyboy = PyBoy(tetris_rom, window_type="null", bootrom_file=boot_rom) pyboy.set_emulation_speed(0) - image1 = pyboy.tick(275, True) # Iterate to boot logo - - # Returned screen image - image2 = pyboy.screen.image - diff = ImageChops.difference(image1, image2) - assert not diff.getbbox() + pyboy.tick(275, True) # Iterate to boot logo assert pyboy.screen.raw_buffer_dims == (144, 160) assert pyboy.screen.raw_buffer_format == cformat @@ -189,21 +184,23 @@ def test_screen_buffer_and_image(tetris_rom, boot_rom): # b"\xd6\x8e\x91R( H7\xd8a*B+\xc7\x1f\x19") # Check PIL image is reference for performance - new_image1 = pyboy.tick(1, True) + pyboy.tick(1, True) + new_image1 = pyboy.screen.image _new_image1 = new_image1.copy() diff = ImageChops.difference(new_image1, _new_image1) assert not diff.getbbox() nd_image = pyboy.screen.ndarray - nd_image[:, :] = 0 + nd_image[:, :] = 0 # This should change the original image! diff = ImageChops.difference(new_image1, _new_image1) assert diff.getbbox() - new_image2 = pyboy.tick(1, True) + pyboy.tick(1, True) + new_image2 = pyboy.screen.image diff = ImageChops.difference(new_image1, new_image2) assert not diff.getbbox() - new_image3 = new_image1.copy() + new_image3 = new_image2.copy() nd_image[:, :] = 0xFF diff = ImageChops.difference(new_image1, new_image3) assert diff.getbbox()