Qt: Initial mask support for transformed sprites

This commit is contained in:
Vicki Pfau 2019-06-01 23:41:28 -07:00
parent 2743905845
commit b99d8164dd
4 changed files with 31 additions and 16 deletions

View File

@ -81,9 +81,6 @@ struct GBAObj {
uint16_t d;
};
union GBAOAM {
struct GBAObj obj[128];
struct GBAOAMMatrix {
int16_t padding0[3];
int16_t a;
@ -93,8 +90,11 @@ union GBAOAM {
int16_t c;
int16_t padding3[3];
int16_t d;
} mat[32];
};
union GBAOAM {
struct GBAObj obj[128];
struct GBAOAMMatrix mat[32];
uint16_t raw[512];
};

View File

@ -204,9 +204,18 @@ bool AssetView::lookupObjGBA(int id, struct ObjInfo* info) {
GBAObjAttributesCGetPriority(obj->c),
GBAObjAttributesBGetX(obj->b),
GBAObjAttributesAGetY(obj->a),
bool(GBAObjAttributesBIsHFlip(obj->b)),
bool(GBAObjAttributesBIsVFlip(obj->b)),
false,
false,
};
if (GBAObjAttributesAIsTransformed(obj->a)) {
int matIndex = GBAObjAttributesBGetMatIndex(obj->b);
const GBAOAMMatrix* mat = &gba->video.oam.mat[matIndex];
QTransform invXform(mat->a / 256., mat->c / 256., mat->b / 256., mat->d / 256., 0, 0);
newInfo.xform = invXform.inverted();
} else {
newInfo.hflip = bool(GBAObjAttributesBIsHFlip(obj->b));
newInfo.vflip = bool(GBAObjAttributesBIsVFlip(obj->b));
}
GBARegisterDISPCNT dispcnt = gba->memory.io[0]; // FIXME: Register name can't be imported due to namespacing issues
if (!GBARegisterDISPCNTIsObjCharacterMapping(dispcnt)) {
newInfo.stride = 0x20 >> (GBAObjAttributesAGet256Color(obj->a));

View File

@ -6,6 +6,7 @@
#pragma once
#include <QTimer>
#include <QTransform>
#include <QWidget>
#include <mgba/core/cache-set.h>
@ -58,6 +59,7 @@ protected:
unsigned y : 9;
bool hflip : 1;
bool vflip : 1;
QTransform xform;
bool operator!=(const ObjInfo&) const;
};

View File

@ -6,7 +6,6 @@
#include "FrameView.h"
#include <QMouseEvent>
#include <QPainter>
#include <QPalette>
#include <array>
@ -177,6 +176,11 @@ void FrameView::updateTilesGBA(bool force) {
if (info.hflip || info.vflip) {
obj = obj.mirrored(info.hflip, info.vflip);
}
if (!info.xform.isIdentity()) {
offset += QPointF(obj.width(), obj.height()) / 2;
obj = obj.transformed(info.xform);
offset -= QPointF(obj.width() / 2, obj.height() / 2);
}
m_queue.append({
{ LayerId::SPRITE, sprite },
!m_disabled.contains({ LayerId::SPRITE, sprite }),
@ -243,7 +247,7 @@ void FrameView::injectGBA() {
}
QPalette palette;
gba->video.renderer->highlightColor = palette.color(QPalette::HighlightedText).rgb();
gba->video.renderer->highlightAmount = sin(m_glowFrame * M_PI / 30) * 64 + 64;
gba->video.renderer->highlightAmount = sin(m_glowFrame * M_PI / 30) * 48 + 64;
if (!m_overrideBackdrop.isValid()) {
QRgb backdrop = M_RGB5_TO_RGB8(gba->video.palette[0]) | 0xFF000000;
m_backdropPicker.setColor(backdrop);