Python: Add hook preventing functions that need resets from being called

This commit is contained in:
Jeffrey Pfau 2016-11-06 21:23:18 -08:00
parent 3310210dc7
commit 6f591996a8
3 changed files with 17 additions and 2 deletions

View File

@ -31,9 +31,17 @@ def loadVF(vf):
return None
return core
def needsReset(f):
def wrapper(self, *args, **kwargs):
if not self._wasReset:
raise RuntimeError("Core must be reset first")
return f(self, *args, **kwargs)
return wrapper
class Core(object):
def __init__(self, native):
self._core = native
self._wasReset = False
@cached_property
def tiles(self):
@ -92,13 +100,17 @@ class Core(object):
def reset(self):
self._core.reset(self._core)
self._wasReset = True
@needsReset
def runFrame(self):
self._core.runFrame(self._core)
@needsReset
def runLoop(self):
self._core.runLoop(self._core)
@needsReset
def step(self):
self._core.step(self._core)
@ -120,6 +132,7 @@ class Core(object):
def clearKeys(self, *args, **kwargs):
self._core.clearKeys(self._core, self._keysToInt(*args, **kwargs))
@needsReset
def frameCounter(self):
return self._core.frameCounter(self._core)

View File

@ -5,7 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from ._pylib import ffi, lib
from .lr35902 import LR35902Core
from .core import Core
from .core import Core, needsReset
from .memory import Memory
from .tile import Sprite
@ -25,6 +25,7 @@ class GB(Core):
self.sprites = GBObjs(self)
self.cpu = LR35902Core(self._core.cpu)
@needsReset
def _initTileCache(self, cache):
lib.GBVideoTileCacheInit(cache)
lib.GBVideoTileCacheAssociate(cache, ffi.addressof(self._native.video))

View File

@ -5,7 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from ._pylib import ffi, lib
from .arm import ARMCore
from .core import Core
from .core import Core, needsReset
from .tile import Sprite
from .memory import Memory
@ -28,6 +28,7 @@ class GBA(Core):
self.cpu = ARMCore(self._core.cpu)
self.memory = GBAMemory(self._core)
@needsReset
def _initTileCache(self, cache):
lib.GBAVideoTileCacheInit(cache)
lib.GBAVideoTileCacheAssociate(cache, ffi.addressof(self._native.video))