all repos — mgba @ 13e1f988c981f6663f6b1d59bdbf4d61036ed5e4

mGBA Game Boy Advance Emulator

Core: Start work on wider maps
Vicki Pfau vi@endrift.com
Sun, 17 Sep 2017 23:22:58 -0700
commit

13e1f988c981f6663f6b1d59bdbf4d61036ed5e4

parent

2c59cb8211c4bf46665d12ed174cf7efe512e0d0

M src/core/map-cache.csrc/core/map-cache.c

@@ -114,8 +114,23 @@ break;

} } +static inline size_t _tileId(struct mMapCache* cache, unsigned x, unsigned y) { + int tilesWide = mMapCacheSystemInfoGetTilesWide(cache->sysConfig); + int tilesHigh = mMapCacheSystemInfoGetTilesHigh(cache->sysConfig); + int stride = tilesHigh < 5 ? (1 << tilesHigh) : 32; + x &= (1 << tilesWide) - 1; + y &= (1 << tilesHigh) - 1; + unsigned xMajor = x & ~0x1F; + unsigned yMajor = y >> 5; + x &= 0x1F; + y &= 0x1F; + yMajor <<= tilesHigh; + y += xMajor + yMajor; + return stride * y + x; +} + void mMapCacheCleanTile(struct mMapCache* cache, struct mMapCacheEntry* entry, unsigned x, unsigned y) { - size_t location = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * y + x; + size_t location = _tileId(cache, x, y); struct mMapCacheEntry* status = &cache->status[location]; int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags); const color_t* tile = NULL;

@@ -141,7 +156,7 @@ entry[location] = *status;

} bool mMapCacheCheckTile(struct mMapCache* cache, const struct mMapCacheEntry* entry, unsigned x, unsigned y) { - size_t location = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * y + x; + size_t location = _tileId(cache, x, y); struct mMapCacheEntry* status = &cache->status[location]; int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags); const color_t* tile = NULL;
M src/gba/renderers/cache-set.csrc/gba/renderers/cache-set.c

@@ -114,7 +114,7 @@ mMapCacheSystemInfo sysconfig = 0;

if (map->mapParser == mapParser0) { sysconfig = mMapCacheSystemInfoSetPaletteBPP(sysconfig, 2 + p); sysconfig = mMapCacheSystemInfoSetPaletteCount(sysconfig, 4 * !p); - sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 512); + sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 1024); sysconfig = mMapCacheSystemInfoSetMapAlign(sysconfig, 1); tilesWide = 5; tilesHigh = 5;
M src/platform/qt/MapView.cppsrc/platform/qt/MapView.cpp

@@ -8,7 +8,9 @@

#include "CoreController.h" #include "GBAApp.h" +#include <QButtonGroup> #include <QFontDatabase> +#include <QRadioButton> #include <QTimer> using namespace QGBA;

@@ -38,19 +40,51 @@

connect(m_ui.magnification, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() { updateTiles(true); }); + + CoreController::Interrupter interrupter(m_controller); + const mCoreChannelInfo* videoLayers; + size_t nVideo = m_controller->thread()->core->listVideoLayers(m_controller->thread()->core, &videoLayers); + QButtonGroup* group = new QButtonGroup(this); + for (size_t i = 0; i < nVideo; ++i) { + if (strncmp(videoLayers[i].internalName, "bg", 2) != 0) { + continue; + } + QRadioButton* button = new QRadioButton(tr(videoLayers[i].visibleName)); + if (!i) { + button->setChecked(true); + } + m_ui.bgLayout->addWidget(button); + connect(button, &QAbstractButton::pressed, button, [this, i]() { + selectMap(i); + }); + group->addButton(button); + } +} + +void MapView::selectMap(int map) { + if (map >= mMapCacheSetSize(&m_cacheSet->maps)) { + return; + } + m_map = map; } #ifdef M_CORE_GBA void MapView::updateTilesGBA(bool force) { - QImage bg(QSize(256, 256), QImage::Format_ARGB32); - uchar* bgBits = bg.bits(); - mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, 0); - for (int j = 0; j < 32; ++j) { - for (int i = 0; i < 32; ++i) { - mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * 32], i, j); - } - for (int i = 0; i < 8; ++i) { - memcpy(static_cast<void*>(&bgBits[256 * 4 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), 256 * 4); + QImage bg; + { + CoreController::Interrupter interrupter(m_controller); + mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, m_map); + int tilesW = 1 << mMapCacheSystemInfoGetTilesWide(mapCache->sysConfig); + int tilesH = 1 << mMapCacheSystemInfoGetTilesHigh(mapCache->sysConfig); + bg = QImage(QSize(tilesW * 8, tilesH * 8), QImage::Format_ARGB32); + uchar* bgBits = bg.bits(); + for (int j = 0; j < tilesH; ++j) { + for (int i = 0; i < tilesW; ++i) { + mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * tilesW], i, j); + } + for (int i = 0; i < 8; ++i) { + memcpy(static_cast<void*>(&bgBits[tilesW * 32 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), tilesW * 32); + } } } bg = bg.convertToFormat(QImage::Format_RGB32).rgbSwapped();
M src/platform/qt/MapView.hsrc/platform/qt/MapView.h

@@ -21,6 +21,9 @@

public: MapView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr); +private slots: + void selectMap(int); + private: #ifdef M_CORE_GBA void updateTilesGBA(bool force) override;

@@ -33,6 +36,7 @@ Ui::MapView m_ui;

std::shared_ptr<CoreController> m_controller; mMapCacheEntry m_mapStatus[1024 * 1024] = {}; // TODO: Correct size + int m_map = 0; }; }
M src/platform/qt/MapView.uisrc/platform/qt/MapView.ui

@@ -14,13 +14,13 @@ <property name="windowTitle">

<string>Maps</string> </property> <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="0"> - <widget class="QGBA::AssetTile" name="tile"/> - </item> - <item row="0" column="1" rowspan="3"> + <item row="0" column="1" rowspan="4"> <widget class="QScrollArea" name="scrollArea"> <property name="widgetResizable"> <bool>true</bool> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> </property> <widget class="QWidget" name="scrollAreaWidgetContents"> <property name="geometry">

@@ -44,6 +44,9 @@ </widget>

</widget> </item> <item row="2" column="0"> + <widget class="QGBA::AssetTile" name="tile"/> + </item> + <item row="3" column="0"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum>

@@ -56,7 +59,7 @@ </size>

</property> </spacer> </item> - <item row="0" column="0"> + <item row="1" column="0"> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> <widget class="QSpinBox" name="magnification">

@@ -85,6 +88,9 @@ </property>

</widget> </item> </layout> + </item> + <item row="0" column="0"> + <layout class="QVBoxLayout" name="bgLayout"/> </item> </layout> </widget>