mirror of https://github.com/mgba-emu/mgba.git
Core: Start work on wider maps
This commit is contained in:
parent
2c59cb8211
commit
13e1f988c9
|
@ -114,8 +114,23 @@ static inline void _cleanTile(struct mMapCache* cache, const color_t* tile, colo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
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];
|
struct mMapCacheEntry* status = &cache->status[location];
|
||||||
int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags);
|
int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags);
|
||||||
const color_t* tile = NULL;
|
const color_t* tile = NULL;
|
||||||
|
@ -141,7 +156,7 @@ void mMapCacheCleanTile(struct mMapCache* cache, struct mMapCacheEntry* entry, u
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mMapCacheCheckTile(struct mMapCache* cache, const struct mMapCacheEntry* entry, unsigned x, unsigned y) {
|
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];
|
struct mMapCacheEntry* status = &cache->status[location];
|
||||||
int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags);
|
int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags);
|
||||||
const color_t* tile = NULL;
|
const color_t* tile = NULL;
|
||||||
|
|
|
@ -114,7 +114,7 @@ static void GBAVideoCacheWriteBGCNT(struct mCacheSet* cache, size_t bg, uint16_t
|
||||||
if (map->mapParser == mapParser0) {
|
if (map->mapParser == mapParser0) {
|
||||||
sysconfig = mMapCacheSystemInfoSetPaletteBPP(sysconfig, 2 + p);
|
sysconfig = mMapCacheSystemInfoSetPaletteBPP(sysconfig, 2 + p);
|
||||||
sysconfig = mMapCacheSystemInfoSetPaletteCount(sysconfig, 4 * !p);
|
sysconfig = mMapCacheSystemInfoSetPaletteCount(sysconfig, 4 * !p);
|
||||||
sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 512);
|
sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 1024);
|
||||||
sysconfig = mMapCacheSystemInfoSetMapAlign(sysconfig, 1);
|
sysconfig = mMapCacheSystemInfoSetMapAlign(sysconfig, 1);
|
||||||
tilesWide = 5;
|
tilesWide = 5;
|
||||||
tilesHigh = 5;
|
tilesHigh = 5;
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
#include "CoreController.h"
|
#include "CoreController.h"
|
||||||
#include "GBAApp.h"
|
#include "GBAApp.h"
|
||||||
|
|
||||||
|
#include <QButtonGroup>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
#include <QRadioButton>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
@ -38,19 +40,51 @@ MapView::MapView(std::shared_ptr<CoreController> controller, QWidget* parent)
|
||||||
connect(m_ui.magnification, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() {
|
connect(m_ui.magnification, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() {
|
||||||
updateTiles(true);
|
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
|
#ifdef M_CORE_GBA
|
||||||
void MapView::updateTilesGBA(bool force) {
|
void MapView::updateTilesGBA(bool force) {
|
||||||
QImage bg(QSize(256, 256), QImage::Format_ARGB32);
|
QImage bg;
|
||||||
uchar* bgBits = bg.bits();
|
{
|
||||||
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, 0);
|
CoreController::Interrupter interrupter(m_controller);
|
||||||
for (int j = 0; j < 32; ++j) {
|
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, m_map);
|
||||||
for (int i = 0; i < 32; ++i) {
|
int tilesW = 1 << mMapCacheSystemInfoGetTilesWide(mapCache->sysConfig);
|
||||||
mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * 32], i, j);
|
int tilesH = 1 << mMapCacheSystemInfoGetTilesHigh(mapCache->sysConfig);
|
||||||
}
|
bg = QImage(QSize(tilesW * 8, tilesH * 8), QImage::Format_ARGB32);
|
||||||
for (int i = 0; i < 8; ++i) {
|
uchar* bgBits = bg.bits();
|
||||||
memcpy(static_cast<void*>(&bgBits[256 * 4 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), 256 * 4);
|
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();
|
bg = bg.convertToFormat(QImage::Format_RGB32).rgbSwapped();
|
||||||
|
|
|
@ -21,6 +21,9 @@ Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MapView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
|
MapView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void selectMap(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef M_CORE_GBA
|
#ifdef M_CORE_GBA
|
||||||
void updateTilesGBA(bool force) override;
|
void updateTilesGBA(bool force) override;
|
||||||
|
@ -33,6 +36,7 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<CoreController> m_controller;
|
std::shared_ptr<CoreController> m_controller;
|
||||||
mMapCacheEntry m_mapStatus[1024 * 1024] = {}; // TODO: Correct size
|
mMapCacheEntry m_mapStatus[1024 * 1024] = {}; // TODO: Correct size
|
||||||
|
int m_map = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,14 @@
|
||||||
<string>Maps</string>
|
<string>Maps</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0">
|
<item row="0" column="1" rowspan="4">
|
||||||
<widget class="QGBA::AssetTile" name="tile"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" rowspan="3">
|
|
||||||
<widget class="QScrollArea" name="scrollArea">
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
<property name="widgetResizable">
|
<property name="widgetResizable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -44,6 +44,9 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
|
<widget class="QGBA::AssetTile" name="tile"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
|
@ -56,7 +59,7 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="1" column="0">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="magnification">
|
<widget class="QSpinBox" name="magnification">
|
||||||
|
@ -86,6 +89,9 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<layout class="QVBoxLayout" name="bgLayout"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
Loading…
Reference in New Issue