mirror of https://github.com/mgba-emu/mgba.git
Python: Reindent, fix up TileView interface
This commit is contained in:
parent
5e0641cb0e
commit
303a7685a2
|
@ -4,6 +4,8 @@
|
|||
# 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'))
|
||||
|
@ -43,6 +45,10 @@ class Core:
|
|||
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_GBA'):
|
|||
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
|
||||
|
|
|
@ -8,3 +8,11 @@ from ._pylib import ffi, lib
|
|||
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)
|
||||
|
|
|
@ -8,3 +8,11 @@ from ._pylib import ffi, lib
|
|||
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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -14,7 +14,7 @@ setup(name="${BINARY_NAME}",
|
|||
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
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue