mirror of https://github.com/mgba-emu/mgba.git
Qt: Pay down technical debt with map caches
This commit is contained in:
parent
fdd03e505e
commit
dfd44b280f
|
@ -31,6 +31,8 @@ DECL_BIT(mMapCacheEntryFlags, HMirror, 5);
|
||||||
DECL_BIT(mMapCacheEntryFlags, VMirror, 6);
|
DECL_BIT(mMapCacheEntryFlags, VMirror, 6);
|
||||||
DECL_BITS(mMapCacheEntryFlags, Mirror, 5, 2);
|
DECL_BITS(mMapCacheEntryFlags, Mirror, 5, 2);
|
||||||
|
|
||||||
|
#define mMapCacheTileCount(C) (1 << mMapCacheSystemInfoGetTilesWide((C)->sysConfig)) * (1 << mMapCacheSystemInfoGetTilesHigh((C)->sysConfig))
|
||||||
|
|
||||||
struct mMapCacheEntry {
|
struct mMapCacheEntry {
|
||||||
uint32_t vramVersion;
|
uint32_t vramVersion;
|
||||||
uint16_t tileId;
|
uint16_t tileId;
|
||||||
|
|
|
@ -32,7 +32,7 @@ static void _redoCacheSize(struct mMapCache* cache) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t tiles = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * (1 << mMapCacheSystemInfoGetTilesHigh(cache->sysConfig));
|
size_t tiles = mMapCacheTileCount(cache);
|
||||||
cache->cache = anonymousMemoryMap(8 * 8 * sizeof(color_t) * tiles);
|
cache->cache = anonymousMemoryMap(8 * 8 * sizeof(color_t) * tiles);
|
||||||
cache->status = anonymousMemoryMap(tiles * sizeof(*cache->status));
|
cache->status = anonymousMemoryMap(tiles * sizeof(*cache->status));
|
||||||
}
|
}
|
||||||
|
@ -54,12 +54,12 @@ void mMapCacheConfigureSystem(struct mMapCache* cache, mMapCacheSystemInfo confi
|
||||||
cache->sysConfig = config;
|
cache->sysConfig = config;
|
||||||
_redoCacheSize(cache);
|
_redoCacheSize(cache);
|
||||||
|
|
||||||
size_t mapSize = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * (1 << mMapCacheSystemInfoGetTilesHigh(cache->sysConfig));
|
size_t mapSize = mMapCacheTileCount(cache);
|
||||||
cache->mapSize = mapSize << mMapCacheSystemInfoGetMapAlign(cache->sysConfig);
|
cache->mapSize = mapSize << mMapCacheSystemInfoGetMapAlign(cache->sysConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mMapCacheConfigureMap(struct mMapCache* cache, uint32_t mapStart) {
|
void mMapCacheConfigureMap(struct mMapCache* cache, uint32_t mapStart) {
|
||||||
size_t tiles = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * (1 << mMapCacheSystemInfoGetTilesHigh(cache->sysConfig));
|
size_t tiles = mMapCacheTileCount(cache);
|
||||||
memset(cache->status, 0, tiles * sizeof(*cache->status));
|
memset(cache->status, 0, tiles * sizeof(*cache->status));
|
||||||
cache->mapStart = mapStart;
|
cache->mapStart = mapStart;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,15 +112,19 @@ void AssetView::compositeTile(const void* tBuffer, void* buffer, size_t stride,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage AssetView::compositeMap(int map, mMapCacheEntry* mapStatus) {
|
QImage AssetView::compositeMap(int map, QVector<mMapCacheEntry>* mapStatus) {
|
||||||
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, map);
|
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, map);
|
||||||
int tilesW = 1 << mMapCacheSystemInfoGetTilesWide(mapCache->sysConfig);
|
int tilesW = 1 << mMapCacheSystemInfoGetTilesWide(mapCache->sysConfig);
|
||||||
int tilesH = 1 << mMapCacheSystemInfoGetTilesHigh(mapCache->sysConfig);
|
int tilesH = 1 << mMapCacheSystemInfoGetTilesHigh(mapCache->sysConfig);
|
||||||
|
if (mapStatus->size() != tilesW * tilesH) {
|
||||||
|
mapStatus->resize(tilesW * tilesH);
|
||||||
|
mapStatus->fill({});
|
||||||
|
}
|
||||||
QImage rawMap = QImage(QSize(tilesW * 8, tilesH * 8), QImage::Format_ARGB32);
|
QImage rawMap = QImage(QSize(tilesW * 8, tilesH * 8), QImage::Format_ARGB32);
|
||||||
uchar* bgBits = rawMap.bits();
|
uchar* bgBits = rawMap.bits();
|
||||||
for (int j = 0; j < tilesH; ++j) {
|
for (int j = 0; j < tilesH; ++j) {
|
||||||
for (int i = 0; i < tilesW; ++i) {
|
for (int i = 0; i < tilesW; ++i) {
|
||||||
mMapCacheCleanTile(mapCache, mapStatus, i, j);
|
mMapCacheCleanTile(mapCache, mapStatus->data(), i, j);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
memcpy(static_cast<void*>(&bgBits[tilesW * 32 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), tilesW * 32);
|
memcpy(static_cast<void*>(&bgBits[tilesW * 32 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), tilesW * 32);
|
||||||
|
|
|
@ -54,7 +54,7 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
static void compositeTile(const void* tile, void* image, size_t stride, size_t x, size_t y, int depth = 8);
|
static void compositeTile(const void* tile, void* image, size_t stride, size_t x, size_t y, int depth = 8);
|
||||||
QImage compositeMap(int map, mMapCacheEntry*);
|
QImage compositeMap(int map, QVector<mMapCacheEntry>*);
|
||||||
QImage compositeObj(const ObjInfo&);
|
QImage compositeObj(const ObjInfo&);
|
||||||
|
|
||||||
bool lookupObj(int id, struct ObjInfo*);
|
bool lookupObj(int id, struct ObjInfo*);
|
||||||
|
|
|
@ -245,7 +245,7 @@ void FrameView::updateTilesGBA(bool) {
|
||||||
m_queue.append({
|
m_queue.append({
|
||||||
{ LayerId::BACKGROUND, bg },
|
{ LayerId::BACKGROUND, bg },
|
||||||
!m_disabled.contains({ LayerId::BACKGROUND, bg }),
|
!m_disabled.contains({ LayerId::BACKGROUND, bg }),
|
||||||
QPixmap::fromImage(compositeMap(bg, m_mapStatus[bg])),
|
QPixmap::fromImage(compositeMap(bg, &m_mapStatus[bg])),
|
||||||
{}, offset, true, false
|
{}, offset, true, false
|
||||||
});
|
});
|
||||||
if (m_queue.back().image.hasAlpha()) {
|
if (m_queue.back().image.hasAlpha()) {
|
||||||
|
|
|
@ -108,7 +108,7 @@ private:
|
||||||
QSet<LayerId> m_disabled;
|
QSet<LayerId> m_disabled;
|
||||||
QPixmap m_composited;
|
QPixmap m_composited;
|
||||||
QPixmap m_rendered;
|
QPixmap m_rendered;
|
||||||
mMapCacheEntry m_mapStatus[4][128 * 128] = {}; // TODO: Correct size
|
QVector<mMapCacheEntry> m_mapStatus[4];
|
||||||
ColorPicker m_backdropPicker;
|
ColorPicker m_backdropPicker;
|
||||||
QColor m_overrideBackdrop;
|
QColor m_overrideBackdrop;
|
||||||
|
|
||||||
|
|
|
@ -116,12 +116,18 @@ void MapView::selectMap(int map) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_map = map;
|
m_map = map;
|
||||||
|
m_mapStatus.fill({});
|
||||||
updateTiles(true);
|
updateTiles(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapView::selectTile(int x, int y) {
|
void MapView::selectTile(int x, int y) {
|
||||||
CoreController::Interrupter interrupter(m_controller);
|
CoreController::Interrupter interrupter(m_controller);
|
||||||
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, m_map);
|
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, m_map);
|
||||||
|
int tiles = mMapCacheTileCount(mapCache);
|
||||||
|
if (m_mapStatus.size() != tiles) {
|
||||||
|
m_mapStatus.resize(tiles);
|
||||||
|
m_mapStatus.fill({});
|
||||||
|
}
|
||||||
size_t tileCache = mTileCacheSetIndex(&m_cacheSet->tiles, mapCache->tileCache);
|
size_t tileCache = mTileCacheSetIndex(&m_cacheSet->tiles, mapCache->tileCache);
|
||||||
m_ui.tile->setBoundary(m_boundary, tileCache, tileCache);
|
m_ui.tile->setBoundary(m_boundary, tileCache, tileCache);
|
||||||
uint32_t location = mMapCacheTileId(mapCache, x, y);
|
uint32_t location = mMapCacheTileId(mapCache, x, y);
|
||||||
|
@ -221,7 +227,7 @@ void MapView::updateTilesGBA(bool) {
|
||||||
m_rawMap = QImage(QSize(width, height), QImage::Format_ARGB32);
|
m_rawMap = QImage(QSize(width, height), QImage::Format_ARGB32);
|
||||||
uchar* bgBits = m_rawMap.bits();
|
uchar* bgBits = m_rawMap.bits();
|
||||||
for (int j = 0; j < height; ++j) {
|
for (int j = 0; j < height; ++j) {
|
||||||
mBitmapCacheCleanRow(bitmapCache, m_bitmapStatus, j);
|
mBitmapCacheCleanRow(bitmapCache, m_bitmapStatus.data(), j);
|
||||||
memcpy(static_cast<void*>(&bgBits[width * j * 4]), mBitmapCacheGetRow(bitmapCache, j), width * 4);
|
memcpy(static_cast<void*>(&bgBits[width * j * 4]), mBitmapCacheGetRow(bitmapCache, j), width * 4);
|
||||||
}
|
}
|
||||||
m_rawMap = m_rawMap.convertToFormat(QImage::Format_RGB32).rgbSwapped();
|
m_rawMap = m_rawMap.convertToFormat(QImage::Format_RGB32).rgbSwapped();
|
||||||
|
@ -239,7 +245,7 @@ void MapView::updateTilesGBA(bool) {
|
||||||
m_ui.bgInfo->setCustomProperty("priority", priority);
|
m_ui.bgInfo->setCustomProperty("priority", priority);
|
||||||
m_ui.bgInfo->setCustomProperty("offset", offset);
|
m_ui.bgInfo->setCustomProperty("offset", offset);
|
||||||
m_ui.bgInfo->setCustomProperty("transform", transform);
|
m_ui.bgInfo->setCustomProperty("transform", transform);
|
||||||
m_rawMap = compositeMap(m_map, m_mapStatus);
|
m_rawMap = compositeMap(m_map, &m_mapStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QPixmap map = QPixmap::fromImage(m_rawMap.convertToFormat(QImage::Format_RGB32));
|
QPixmap map = QPixmap::fromImage(m_rawMap.convertToFormat(QImage::Format_RGB32));
|
||||||
|
|
|
@ -43,8 +43,8 @@ private:
|
||||||
Ui::MapView m_ui;
|
Ui::MapView m_ui;
|
||||||
|
|
||||||
std::shared_ptr<CoreController> m_controller;
|
std::shared_ptr<CoreController> m_controller;
|
||||||
mMapCacheEntry m_mapStatus[128 * 128] = {}; // TODO: Correct size
|
QVector<mMapCacheEntry> m_mapStatus;
|
||||||
mBitmapCacheEntry m_bitmapStatus[512 * 2] = {}; // TODO: Correct size
|
QVector<mBitmapCacheEntry> m_bitmapStatus{512 * 2}; // TODO: Correct size
|
||||||
int m_map = 0;
|
int m_map = 0;
|
||||||
QImage m_rawMap;
|
QImage m_rawMap;
|
||||||
int m_boundary;
|
int m_boundary;
|
||||||
|
|
Loading…
Reference in New Issue