Skip to content

Commit

Permalink
Change tick to "count=*, render=*" and remove return of Image
Browse files Browse the repository at this point in the history
  • Loading branch information
Baekalfen committed Nov 23, 2023
1 parent eca6c0b commit b139eac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyboy/pyboy.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions pyboy/pyboy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 7 additions & 10 deletions tests/test_external_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,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
Expand Down Expand Up @@ -188,21 +183,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()
Expand Down

0 comments on commit b139eac

Please sign in to comment.