From 6f591996a8307bde8d424ab37a0db67956097187 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 6 Nov 2016 21:23:18 -0800 Subject: [PATCH] Python: Add hook preventing functions that need resets from being called --- src/platform/python/mgba/core.py | 13 +++++++++++++ src/platform/python/mgba/gb.py | 3 ++- src/platform/python/mgba/gba.py | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/platform/python/mgba/core.py b/src/platform/python/mgba/core.py index ad051e33d..8d86e3127 100644 --- a/src/platform/python/mgba/core.py +++ b/src/platform/python/mgba/core.py @@ -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) diff --git a/src/platform/python/mgba/gb.py b/src/platform/python/mgba/gb.py index eed40e189..0caf7ec99 100644 --- a/src/platform/python/mgba/gb.py +++ b/src/platform/python/mgba/gb.py @@ -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)) diff --git a/src/platform/python/mgba/gba.py b/src/platform/python/mgba/gba.py index 40e059a4c..123c953ce 100644 --- a/src/platform/python/mgba/gba.py +++ b/src/platform/python/mgba/gba.py @@ -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))