Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions include/gDPLoadTextureBlock_Runtime.inc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef GDP_LOADTEXTUREBLOCK_RUNTIME_C
#define GDP_LOADTEXTUREBLOCK_RUNTIME_C

#include "global.h"
#include "gfx.h"

// The Following arrays must be defined as const in z_lmap_mark.c to appear in rodata

#ifndef GDP_LOADTEXTUREBLOCK_RUNTIME_CONST
#define ZCONST
#else
#define ZCONST const
#endif
mzxrules marked this conversation as resolved.
Show resolved Hide resolved

static ZCONST u32 sLoadTextureBlock_siz[] = {
G_IM_SIZ_4b,
G_IM_SIZ_8b,
G_IM_SIZ_16b,
G_IM_SIZ_32b,
};
static ZCONST 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 ZCONST u32 sLoadTextureBlock_siz_INCR[] = {
mzxrules marked this conversation as resolved.
Show resolved Hide resolved
G_IM_SIZ_4b_INCR,
G_IM_SIZ_8b_INCR,
G_IM_SIZ_16b_INCR,
G_IM_SIZ_32b_INCR,
};
static ZCONST 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 ZCONST 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 ZCONST 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,
};

#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
25 changes: 7 additions & 18 deletions src/code/z_map_mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,9 @@ 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 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[] = {
#include "gDPLoadTextureBlock_Runtime.inc.c"

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
};
Expand Down Expand Up @@ -114,9 +102,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 = (GREG(94) + markPoint->x + 204) << 2;
rectTop = (GREG(95) + markPoint->y + 140) << 2;
Expand Down
24 changes: 7 additions & 17 deletions src/overlays/misc/ovl_kaleido_scope/z_lmap_mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,14 @@ typedef struct {
/* 0x20 */ u32 dtdy;
} PauseMapMarkInfo; // size = 0x24

#define GDP_LOADTEXTUREBLOCK_RUNTIME_CONST
#include "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) {
Expand Down Expand Up @@ -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();
Matrix_Translate(GREG(92) + markPoint->x, GREG(93) + markPoint->y, 0.0f, MTXMODE_APPLY);
Expand Down