1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-25 06:06:05 +00:00

Clean up custom LoadTextureBlock in z_map_mark.c and z_lmap_mark.c (#1896)

* experimental inc.c

* make it look proper

* make table types u32

* ZCONST -> COND_CONST

* Tharo suggestion and comment

* implement MM Decomp suggestions

* fix minor nits

* Update header guard
This commit is contained in:
mzxrules 2024-07-17 17:35:37 -04:00 committed by GitHub
parent bf3339a16d
commit 7eee97429f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 82 additions and 34 deletions

View file

@ -0,0 +1,68 @@
#ifndef GDP_LOADTEXTUREBLOCK_RUNTIME_INC_C
#define GDP_LOADTEXTUREBLOCK_RUNTIME_INC_C
#include "gfx.h"
#ifndef GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS
#define GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS
#endif
// The Following arrays must be defined as const in z_lmap_mark.c to appear in rodata
static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz[] = {
G_IM_SIZ_4b,
G_IM_SIZ_8b,
G_IM_SIZ_16b,
G_IM_SIZ_32b,
};
static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_LOAD_BLOCK[] = {
G_IM_SIZ_4b_LOAD_BLOCK,
G_IM_SIZ_8b_LOAD_BLOCK,
G_IM_SIZ_16b_LOAD_BLOCK,
G_IM_SIZ_32b_LOAD_BLOCK,
};
static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_INCR[] = {
G_IM_SIZ_4b_INCR,
G_IM_SIZ_8b_INCR,
G_IM_SIZ_16b_INCR,
G_IM_SIZ_32b_INCR,
};
static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_SHIFT[] = {
G_IM_SIZ_4b_SHIFT,
G_IM_SIZ_8b_SHIFT,
G_IM_SIZ_16b_SHIFT,
G_IM_SIZ_32b_SHIFT,
};
static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_BYTES[] = {
G_IM_SIZ_4b_BYTES,
G_IM_SIZ_8b_BYTES,
G_IM_SIZ_16b_BYTES,
G_IM_SIZ_32b_BYTES,
};
static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_LINE_BYTES[] = {
G_IM_SIZ_4b_LINE_BYTES,
G_IM_SIZ_8b_LINE_BYTES,
G_IM_SIZ_16b_LINE_BYTES,
G_IM_SIZ_32b_LINE_BYTES,
};
/**
* Implements a version of gDPLoadTextureBlock using table lookups instead of token pasting, to allow values to be
* passed into `siz` during runtime.
*/
#define gDPLoadTextureBlock_Runtime(pkt, timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
_DW({ \
gDPSetTextureImage(pkt, fmt, sLoadTextureBlock_siz_LOAD_BLOCK[siz], 1, timg); \
gDPSetTile(pkt, fmt, sLoadTextureBlock_siz_LOAD_BLOCK[siz], 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, \
masks, shifts); \
gDPLoadSync(pkt); \
gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \
(((width) * (height) + sLoadTextureBlock_siz_INCR[siz]) >> sLoadTextureBlock_siz_SHIFT[siz]) - 1, \
CALC_DXT(width, sLoadTextureBlock_siz_BYTES[siz])); \
gDPPipeSync(pkt); \
gDPSetTile(pkt, fmt, sLoadTextureBlock_siz[siz], (((width)*sLoadTextureBlock_siz_LINE_BYTES[siz]) + 7) >> 3, \
0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, shifts); \
gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \
((height)-1) << G_TEXTURE_IMAGE_FRAC); \
})
#endif

View file

@ -22,21 +22,10 @@ typedef struct {
/* 0x14 */ void* vramTable;
} MapMarkDataOverlay; // size = 0x18
static u32 sBaseImageSizes[] = { 0, 1, 2, 3 };
static u32 sLoadBlockImageSizes[] = { 2, 2, 2, 3 };
static u32 sIncrImageSizes[] = { 3, 1, 0, 0 };
static u32 sShiftImageSizes[] = { 2, 1, 0, 0 };
static u32 sBytesImageSizes[] = { 0, 1, 2, 4 };
static u32 sLineBytesImageSizes[] = { 0, 1, 2, 2 };
#define GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS
#include "src/code/gDPLoadTextureBlock_Runtime.inc.c"
#define G_IM_SIZ_MARK sBaseImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_LOAD_BLOCK sLoadBlockImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_INCR sIncrImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_SHIFT sShiftImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_BYTES sBytesImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_LINE_BYTES sLineBytesImageSizes[markInfo->imageSize]
static MapMarkInfo sMapMarkInfoTable[] = {
MapMarkInfo sMapMarkInfoTable[] = {
{ gMapChestIconTex, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 8, 32, 32, 1 << 10, 1 << 10 }, // Chest Icon
{ gMapBossIconTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 8, 32, 32, 1 << 10, 1 << 10 }, // Boss Skull Icon
};
@ -109,9 +98,10 @@ void MapMark_DrawForDungeon(PlayState* play) {
markInfo = &sMapMarkInfoTable[mapMarkIconData->markType];
gDPPipeSync(OVERLAY_DISP++);
gDPLoadTextureBlock(OVERLAY_DISP++, markInfo->texture, markInfo->imageFormat, G_IM_SIZ_MARK,
markInfo->textureWidth, markInfo->textureHeight, 0, G_TX_NOMIRROR | G_TX_WRAP,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gDPLoadTextureBlock_Runtime(OVERLAY_DISP++, markInfo->texture, markInfo->imageFormat,
markInfo->imageSize, markInfo->textureWidth, markInfo->textureHeight, 0,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK,
G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
rectLeft = ((OOT_DEBUG ? GREG(94) : 0) + markPoint->x + 204) << 2;
rectTop = ((OOT_DEBUG ? GREG(95) : 0) + markPoint->y + 140) << 2;

View file

@ -13,25 +13,14 @@ typedef struct {
/* 0x20 */ u32 dtdy;
} PauseMapMarkInfo; // size = 0x24
#define GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS const
#include "src/code/gDPLoadTextureBlock_Runtime.inc.c"
static PauseMapMarkInfo sMapMarkInfoTable[] = {
{ gMapChestIconTex, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 8, 32, 32, 1 << 10, 1 << 10 },
{ gMapBossIconTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 8, 32, 32, 1 << 10, 1 << 10 },
};
static const u32 sBaseImageSizes[] = { 0, 1, 2, 3 };
static const u32 sLoadBlockImageSizes[] = { 2, 2, 2, 3 };
static const u32 sIncrImageSizes[] = { 3, 1, 0, 0 };
static const u32 sShiftImageSizes[] = { 2, 1, 0, 0 };
static const u32 sBytesImageSizes[] = { 0, 1, 2, 4 };
static const u32 sLineBytesImageSizes[] = { 0, 1, 2, 2 };
#define G_IM_SIZ_MARK sBaseImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_LOAD_BLOCK sLoadBlockImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_INCR sIncrImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_SHIFT sShiftImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_BYTES sBytesImageSizes[markInfo->imageSize]
#define G_IM_SIZ_MARK_LINE_BYTES sLineBytesImageSizes[markInfo->imageSize]
extern PauseMapMarksData gPauseMapMarkDataTable[];
void PauseMapMark_Init(PlayState* play) {
@ -122,9 +111,10 @@ void PauseMapMark_DrawForDungeon(PlayState* play) {
markInfo = &sMapMarkInfoTable[mapMarkData->markType];
gDPPipeSync(POLY_OPA_DISP++);
gDPLoadTextureBlock(POLY_OPA_DISP++, markInfo->texture, markInfo->imageFormat, G_IM_SIZ_MARK,
markInfo->textureWidth, markInfo->textureHeight, 0, G_TX_NOMIRROR | G_TX_WRAP,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gDPLoadTextureBlock_Runtime(POLY_OPA_DISP++, markInfo->texture, markInfo->imageFormat,
markInfo->imageSize, markInfo->textureWidth, markInfo->textureHeight, 0,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK,
G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
Matrix_Push();