Python: Reindent, fix up TileView interface
Jeffrey Pfau jeffrey@endrift.com
Tue, 18 Oct 2016 14:32:17 -0700
5 files changed,
42 insertions(+),
25 deletions(-)
M
src/platform/python/mgba/core.py
→
src/platform/python/mgba/core.py
@@ -4,6 +4,8 @@ # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from ._pylib import ffi, lib +from . import tile +from cached_property import cached_property def find(path): core = lib.mCoreFind(path.encode('UTF-8'))@@ -42,6 +44,10 @@ self.board = GBA(self._core.board)
if hasattr(self, 'PLATFORM_GB') and self.platform() == self.PLATFORM_GB: self.cpu = LR35902Core(self._core.cpu) self.board = GB(self._core.board) + + @cached_property + def tiles(self): + return tile.TileView(self) def _deinit(self): self._core.deinit(self._core)@@ -112,4 +118,4 @@
if hasattr(lib, 'PLATFORM_GB'): from .gb import GB from .lr35902 import LR35902Core - Core.PLATFORM_GB = lib.PLATFORM_GB+ Core.PLATFORM_GB = lib.PLATFORM_GB
M
src/platform/python/mgba/gb.py
→
src/platform/python/mgba/gb.py
@@ -8,3 +8,11 @@
class GB: def __init__(self, native): self._native = ffi.cast("struct GB*", native) + + def _initTileCache(self, cache): + lib.GBVideoTileCacheInit(cache) + lib.GBVideoTileCacheAssociate(cache, ffi.addressof(self._native.video)) + + def _deinitTileCache(self, cache): + self._native.video.renderer.cache = ffi.NULL + lib.mTileCacheDeinit(cache)
M
src/platform/python/mgba/gba.py
→
src/platform/python/mgba/gba.py
@@ -8,3 +8,11 @@
class GBA: def __init__(self, native): self._native = ffi.cast("struct GBA*", native) + + def _initTileCache(self, cache): + lib.GBAVideoTileCacheInit(cache) + lib.GBAVideoTileCacheAssociate(cache, ffi.addressof(self._native.video)) + + def _deinitTileCache(self, cache): + self._native.video.renderer.cache = ffi.NULL + lib.mTileCacheDeinit(cache)
M
src/platform/python/mgba/tile.py
→
src/platform/python/mgba/tile.py
@@ -7,30 +7,25 @@ from ._pylib import ffi, lib
from . import image class Tile: - def __init__(self, data): - self.buffer = data + def __init__(self, data): + self.buffer = data - def toImage(self): - i = image.Image(8, 8) - self.composite(i, 0, 0) - return i + def toImage(self): + i = image.Image(8, 8) + self.composite(i, 0, 0) + return i - def composite(self, i, x, y): - for iy in range(8): - for ix in range(8): - i.buffer[ix + x + (iy + y) * i.stride] = image.u16ToColor(self.buffer[ix + iy * 8]) + def composite(self, i, x, y): + for iy in range(8): + for ix in range(8): + i.buffer[ix + x + (iy + y) * i.stride] = image.u16ToColor(self.buffer[ix + iy * 8]) class TileView: - def __init__(self, core): - self.core = core - self.cache = ffi.gc(ffi.new("struct mTileCache*"), lib.mTileCacheDeinit) - if core.platform() == core.PLATFORM_GBA: - lib.GBAVideoTileCacheInit(self.cache) - lib.GBAVideoTileCacheAssociate(self.cache, ffi.addressof(self.core.board._native, "video")) - if core.platform() == core.PLATFORM_GB: - lib.GBVideoTileCacheInit(self.cache) - lib.GBVideoTileCacheAssociate(self.cache, ffi.addressof(self.core.board._native, "video")) - lib.mTileCacheSetPalette(self.cache, 0) + def __init__(self, core): + self.core = core + self.cache = ffi.gc(ffi.new("struct mTileCache*"), core.board._deinitTileCache) + core.board._initTileCache(self.cache) + lib.mTileCacheSetPalette(self.cache, 0) - def getTile(self, tile, palette): - return Tile(lib.mTileCacheGetTile(self.cache, tile, palette)) + def getTile(self, tile, palette): + return Tile(lib.mTileCacheGetTile(self.cache, tile, palette))
M
src/platform/python/setup.py.in
→
src/platform/python/setup.py.in
@@ -14,7 +14,7 @@ author_email="jeffrey@endrift.com",
url="http://github.com/mgba-emu/mgba/", packages=["mgba"], setup_requires=['cffi>=1.6'], - install_requires=['cffi>=1.6'], + install_requires=['cffi>=1.6', 'cached-property'], license="MPL 2.0", classifiers=classifiers - )+ )