Skip to content

Commit

Permalink
Merge pull request #30 from Kautenja/backup_improvements
Browse files Browse the repository at this point in the history
Backup improvements
  • Loading branch information
Kautenja authored Aug 12, 2018
2 parents 7e9ee88 + 3e14c4c commit de05792
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion nes_py/nes_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def __init__(self, rom_path, frameskip=1, max_episode_steps=float('inf')):
self._screen_data = np.empty(SCREEN_SHAPE_32_BIT, dtype=np.uint8)
# setup the screen for the environment (24-bit RGB format for Python)
self.screen = np.empty(SCREEN_SHAPE_24_BIT, dtype=np.uint8)
# determines whether the env has a backup stored
self._has_backup = False

def _copy_screen(self):
"""Copy screen data from the C++ shared object library."""
Expand Down Expand Up @@ -205,6 +207,11 @@ def _frame_advance(self, action):
def _backup(self):
"""Backup the NES state in the emulator."""
_LIB.NESEnv_backup(self._env)
self._has_backup = True

def _del_backup(self):
"""Delete the backup for the environment."""
self._has_backup = False

def _restore(self):
"""Restore the backup state into the NES emulator."""
Expand All @@ -228,7 +235,10 @@ def reset(self):
# call the before reset callback
self._will_reset()
# reset the emulator
_LIB.NESEnv_reset(self._env)
if not self._has_backup:
_LIB.NESEnv_reset(self._env)
else:
self._restore()
# call the after reset callback
self._did_reset()
# copy the screen from the emulator
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def README():

setup(
name='nes_py',
version='0.9.0',
version='0.10.0',
description='An NES Emulator and OpenAI Gym interface',
long_description=README(),
long_description_content_type='text/markdown',
Expand Down

0 comments on commit de05792

Please sign in to comment.