diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index e2f444403..71c8ffa93 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -337,8 +337,9 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender } static void GBAVideoSoftwareRendererWriteVRAM(struct GBAVideoRenderer* renderer, uint32_t address) { - UNUSED(renderer); - UNUSED(address); + if (renderer->cache) { + GBAVideoTileCacheWriteVRAM(renderer->cache, address); + } } static void GBAVideoSoftwareRendererWriteOAM(struct GBAVideoRenderer* renderer, uint32_t oam) { @@ -370,6 +371,9 @@ static void GBAVideoSoftwareRendererWritePalette(struct GBAVideoRenderer* render } else if (softwareRenderer->blendEffect == BLEND_DARKEN) { softwareRenderer->variantPalette[address >> 1] = _darken(color, softwareRenderer->bldy); } + if (renderer->cache) { + GBAVideoTileCacheWritePalette(renderer->cache, address); + } } static void _breakWindow(struct GBAVideoSoftwareRenderer* softwareRenderer, struct WindowN* win, int y) { diff --git a/src/gba/video.c b/src/gba/video.c index d4f9d256e..9ec7aa6fe 100644 --- a/src/gba/video.c +++ b/src/gba/video.c @@ -8,6 +8,7 @@ #include "core/sync.h" #include "gba/gba.h" #include "gba/io.h" +#include "gba/renderers/tile-cache.h" #include "gba/rr/rr.h" #include "gba/serialize.h" @@ -55,7 +56,8 @@ static struct GBAVideoRenderer dummyRenderer = { .writeOAM = GBAVideoDummyRendererWriteOAM, .drawScanline = GBAVideoDummyRendererDrawScanline, .finishFrame = GBAVideoDummyRendererFinishFrame, - .getPixels = GBAVideoDummyRendererGetPixels + .getPixels = GBAVideoDummyRendererGetPixels, + .cache = NULL }; void GBAVideoInit(struct GBAVideo* video) { @@ -104,6 +106,7 @@ void GBAVideoDeinit(struct GBAVideo* video) { void GBAVideoAssociateRenderer(struct GBAVideo* video, struct GBAVideoRenderer* renderer) { video->renderer->deinit(video->renderer); + renderer->cache = video->renderer->cache; video->renderer = renderer; renderer->palette = video->palette; renderer->vram = video->vram; @@ -262,16 +265,16 @@ static uint16_t GBAVideoDummyRendererWriteVideoRegister(struct GBAVideoRenderer* } static void GBAVideoDummyRendererWriteVRAM(struct GBAVideoRenderer* renderer, uint32_t address) { - UNUSED(renderer); - UNUSED(address); - // Nothing to do + if (renderer->cache) { + GBAVideoTileCacheWriteVRAM(renderer->cache, address); + } } static void GBAVideoDummyRendererWritePalette(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) { - UNUSED(renderer); - UNUSED(address); UNUSED(value); - // Nothing to do + if (renderer->cache) { + GBAVideoTileCacheWritePalette(renderer->cache, address); + } } static void GBAVideoDummyRendererWriteOAM(struct GBAVideoRenderer* renderer, uint32_t oam) { diff --git a/src/gba/video.h b/src/gba/video.h index 04c96ee75..4dac3d55b 100644 --- a/src/gba/video.h +++ b/src/gba/video.h @@ -170,6 +170,7 @@ struct GBAVideoRenderer { uint16_t* palette; uint16_t* vram; union GBAOAM* oam; + struct GBAVideoTileCache* cache; bool disableBG[4]; bool disableOBJ; diff --git a/src/platform/qt/TileView.cpp b/src/platform/qt/TileView.cpp index 86087c4bf..bad8129d9 100644 --- a/src/platform/qt/TileView.cpp +++ b/src/platform/qt/TileView.cpp @@ -25,14 +25,16 @@ TileView::TileView(GameController* controller, QWidget* parent) GBAVideoTileCacheInit(&m_tileCache); m_ui.preview->setDimensions(QSize(8, 8)); - updateTiles(); + m_updateTimer.setSingleShot(true); + m_updateTimer.setInterval(10); + connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTiles())); const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); m_ui.tileId->setFont(font); m_ui.address->setFont(font); - connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(updateTiles())); + connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), &m_updateTimer, SLOT(start())); connect(m_controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close())); connect(m_ui.tiles, SIGNAL(indexPressed(int)), this, SLOT(selectIndex(int))); connect(m_ui.paletteId, SIGNAL(valueChanged(int)), this, SLOT(updatePalette(int))); @@ -40,6 +42,11 @@ TileView::TileView(GameController* controller, QWidget* parent) } TileView::~TileView() { + if (m_controller->isLoaded() && m_controller->thread() && m_controller->thread()->core) { + GBA* gba = static_cast(m_controller->thread()->core->board); + gba->video.renderer->cache = nullptr; + } + GBAVideoTileCacheDeinit(&m_tileCache); } @@ -124,8 +131,5 @@ void TileView::resizeEvent(QResizeEvent*) { } void TileView::showEvent(QShowEvent*) { - // XXX: Figure out how to prevent the first resizeEvent - QTimer::singleShot(10, [this]() { - updateTiles(true); - }); + m_updateTimer.start(); } diff --git a/src/platform/qt/TileView.h b/src/platform/qt/TileView.h index fec37afd2..28fc4b8a8 100644 --- a/src/platform/qt/TileView.h +++ b/src/platform/qt/TileView.h @@ -42,6 +42,7 @@ private: GameController* m_controller; GBAVideoTileCache m_tileCache; int m_paletteId; + QTimer m_updateTimer; }; } diff --git a/src/platform/qt/TileView.ui b/src/platform/qt/TileView.ui index d3adae10d..87aa22833 100644 --- a/src/platform/qt/TileView.ui +++ b/src/platform/qt/TileView.ui @@ -6,8 +6,8 @@ 0 0 - 509 - 265 + 498 + 335 @@ -116,7 +116,20 @@ - + + + + Qt::Vertical + + + + 0 + 0 + + + + + @@ -132,7 +145,7 @@ 0 0 - 282 + 271 768