Qt: Improve tile view
Jeffrey Pfau jeffrey@endrift.com
Fri, 22 Jul 2016 23:43:00 -0700
6 files changed,
45 insertions(+),
19 deletions(-)
M
src/gba/renderers/video-software.c
→
src/gba/renderers/video-software.c
@@ -337,8 +337,9 @@ return value;
} 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) {@@ -369,6 +370,9 @@ if (softwareRenderer->blendEffect == BLEND_BRIGHTEN) {
softwareRenderer->variantPalette[address >> 1] = _brighten(color, softwareRenderer->bldy); } else if (softwareRenderer->blendEffect == BLEND_DARKEN) { softwareRenderer->variantPalette[address >> 1] = _darken(color, softwareRenderer->bldy); + } + if (renderer->cache) { + GBAVideoTileCacheWritePalette(renderer->cache, address); } }
M
src/gba/video.c
→
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 @@ .writePalette = GBAVideoDummyRendererWritePalette,
.writeOAM = GBAVideoDummyRendererWriteOAM, .drawScanline = GBAVideoDummyRendererDrawScanline, .finishFrame = GBAVideoDummyRendererFinishFrame, - .getPixels = GBAVideoDummyRendererGetPixels + .getPixels = GBAVideoDummyRendererGetPixels, + .cache = NULL }; void GBAVideoInit(struct GBAVideo* video) {@@ -104,6 +106,7 @@ }
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 @@ return value;
} 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) {
M
src/gba/video.h
→
src/gba/video.h
@@ -170,6 +170,7 @@
uint16_t* palette; uint16_t* vram; union GBAOAM* oam; + struct GBAVideoTileCache* cache; bool disableBG[4]; bool disableOBJ;
M
src/platform/qt/TileView.cpp
→
src/platform/qt/TileView.cpp
@@ -25,14 +25,16 @@ m_ui.setupUi(this);
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 @@ connect(m_ui.palette256, SIGNAL(toggled(bool)), this, SLOT(updateTiles()));
} TileView::~TileView() { + if (m_controller->isLoaded() && m_controller->thread() && m_controller->thread()->core) { + GBA* gba = static_cast<GBA*>(m_controller->thread()->core->board); + gba->video.renderer->cache = nullptr; + } + GBAVideoTileCacheDeinit(&m_tileCache); }@@ -124,8 +131,5 @@ updateTiles(true);
} void TileView::showEvent(QShowEvent*) { - // XXX: Figure out how to prevent the first resizeEvent - QTimer::singleShot(10, [this]() { - updateTiles(true); - }); + m_updateTimer.start(); }
M
src/platform/qt/TileView.h
→
src/platform/qt/TileView.h
@@ -42,6 +42,7 @@
GameController* m_controller; GBAVideoTileCache m_tileCache; int m_paletteId; + QTimer m_updateTimer; }; }
M
src/platform/qt/TileView.ui
→
src/platform/qt/TileView.ui
@@ -6,8 +6,8 @@ <property name="geometry">
<rect> <x>0</x> <y>0</y> - <width>509</width> - <height>265</height> + <width>498</width> + <height>335</height> </rect> </property> <property name="windowTitle">@@ -116,7 +116,20 @@ <enum>QSlider::TicksBelow</enum>
</property> </widget> </item> - <item row="0" column="1" rowspan="3"> + <item row="3" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="1" rowspan="4"> <widget class="QScrollArea" name="scrollArea"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Expanding">@@ -132,7 +145,7 @@ <property name="geometry">
<rect> <x>0</x> <y>0</y> - <width>282</width> + <width>271</width> <height>768</height> </rect> </property>