Make palette address part of texture cache key

This commit is contained in:
Emil Lenngren 2022-04-01 22:51:09 +02:00
parent 9ef130eb40
commit f709ffa99a
6 changed files with 46 additions and 18 deletions

View File

@ -490,8 +490,8 @@ void gfx_texture_cache_clear()
gfx_texture_cache.lru.clear();
}
static bool gfx_texture_cache_lookup(int i, TextureCacheNode **n, const uint8_t *orig_addr, uint32_t fmt, uint32_t siz, uint32_t palette_index) {
TextureCacheKey key = { orig_addr, fmt, siz, palette_index };
static bool gfx_texture_cache_lookup(int i, TextureCacheNode **n, const uint8_t *orig_addr, const uint8_t *palette_addr, uint32_t fmt, uint32_t siz, uint32_t palette_index) {
TextureCacheKey key = { orig_addr, palette_addr, fmt, siz, palette_index };
auto it = gfx_texture_cache.map.find(key);
if (it != gfx_texture_cache.map.end()) {
@ -815,7 +815,7 @@ static void import_texture(int i, int tile) {
// if (ModInternal::callBindHook(0))
// return;
if (gfx_texture_cache_lookup(i, &rendering_state.textures[i], rdp.loaded_texture[tmem_index].addr, fmt, siz, rdp.texture_tile[tile].palette))
if (gfx_texture_cache_lookup(i, &rendering_state.textures[i], rdp.loaded_texture[tmem_index].addr, fmt == G_IM_FMT_CI ? rdp.palette : nullptr, fmt, siz, rdp.texture_tile[tile].palette))
{
return;
}

View File

@ -17,6 +17,7 @@ struct GfxDimensions
struct TextureCacheKey {
const uint8_t* texture_addr;
const uint8_t* palette_addr;
uint8_t fmt, siz;
uint8_t palette_index;

View File

@ -80,7 +80,7 @@ namespace Ship {
if (!this->TextureCache.contains(path)) this->TextureCache[path].resize(10);
TextureCacheKey key = { orig_addr, static_cast<uint8_t>(fmt), static_cast<uint8_t>(siz), static_cast<uint8_t>(palette) };
TextureCacheKey key = { orig_addr, nullptr, static_cast<uint8_t>(fmt), static_cast<uint8_t>(siz), static_cast<uint8_t>(palette) };
TextureCacheValue value = { api->new_texture(), 0, 0, false };
const auto entry = new TextureCacheNode(key, value);
api->select_texture(tile, entry->second.texture_id);

View File

@ -336,16 +336,17 @@ typedef enum {
} SkyboxId;
typedef struct {
/* 0x000 */ char unk_00[0x128];
/* 0x128 */ void* textures[2][6];
/* 0x130 */ void* palettes[6];
/* 0x134 */ Gfx (*dListBuf)[150];
/* 0x138 */ Gfx* unk_138;
/* 0x13C */ Vtx* roomVtx;
/* 0x140 */ s16 unk_140;
/* 0x144 */ Vec3f rot;
/* 0x150 */ char unk_150[0x10];
} SkyboxContext; // size = 0x160
char unk_00[0x128];
s16 skyboxId;
void* textures[2][6];
void* palettes[6];
Gfx (*dListBuf)[150];
Gfx* unk_138;
Vtx* roomVtx;
s16 unk_140;
Vec3f rot;
char unk_150[0x10];
} SkyboxContext;
typedef enum {
/* 0 */ OCARINA_SONG_MINUET,

View File

@ -679,6 +679,8 @@ void Environment_UpdateSkybox(GlobalContext* globalCtx, u8 skyboxId, Environment
for (int i = 0; i < 5; i++)
LoadSkyboxTex(skyboxCtx, 0, i, entryA.textures[i], 128, i == 4 ? 128 : 64, 128, 64);
Skybox_Update(skyboxCtx);
envCtx->skybox1Index = newSkybox1Index;
//size = gSkyboxFiles[newSkybox1Index].file.vromEnd - gSkyboxFiles[newSkybox1Index].file.vromStart;
@ -697,6 +699,8 @@ void Environment_UpdateSkybox(GlobalContext* globalCtx, u8 skyboxId, Environment
for (int i = 0; i < 5; i++)
LoadSkyboxTex(skyboxCtx, 1, i, entryA.textures[i], 128, i == 4 ? 128 : 64, 128, 64);
Skybox_Update(skyboxCtx);
envCtx->skybox2Index = newSkybox2Index;
//size = gSkyboxFiles[newSkybox2Index].file.vromEnd - gSkyboxFiles[newSkybox2Index].file.vromStart;
@ -712,7 +716,7 @@ void Environment_UpdateSkybox(GlobalContext* globalCtx, u8 skyboxId, Environment
if ((newSkybox1Index & 1) ^ ((newSkybox1Index & 4) >> 2)) {
SkyboxTableEntry entryA = sSkyboxTable[newSkybox1Index];
LoadSkyboxPalette(globalCtx, skyboxCtx, 0, entryA.palettes[0], 16, 8);
LoadSkyboxPalette(skyboxCtx, 0, entryA.palettes[0], 16, 8);
//size = gSkyboxFiles[newSkybox1Index].palette.vromEnd - gSkyboxFiles[newSkybox1Index].palette.vromStart;
//osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
@ -721,7 +725,7 @@ void Environment_UpdateSkybox(GlobalContext* globalCtx, u8 skyboxId, Environment
//"../z_kankyo.c", 1307);
} else {
SkyboxTableEntry entryA = sSkyboxTable[newSkybox1Index];
LoadSkyboxPalette(globalCtx, skyboxCtx, 1, entryA.palettes[0], 16, 8);
LoadSkyboxPalette(skyboxCtx, 1, entryA.palettes[0], 16, 8);
//size = gSkyboxFiles[newSkybox1Index].palette.vromEnd - gSkyboxFiles[newSkybox1Index].palette.vromStart;
//osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
@ -729,6 +733,8 @@ void Environment_UpdateSkybox(GlobalContext* globalCtx, u8 skyboxId, Environment
//gSkyboxFiles[newSkybox1Index].palette.vromStart, size, 0, &envCtx->loadQueue, NULL,
//"../z_kankyo.c", 1320);
}
Skybox_Update(skyboxCtx);
}
if (envCtx->skyboxDmaState == SKYBOX_DMA_FILE2_DONE) {
@ -737,7 +743,7 @@ void Environment_UpdateSkybox(GlobalContext* globalCtx, u8 skyboxId, Environment
if ((newSkybox2Index & 1) ^ ((newSkybox2Index & 4) >> 2))
{
SkyboxTableEntry entryA = sSkyboxTable[newSkybox2Index];
LoadSkyboxPalette(globalCtx, skyboxCtx, 0, entryA.palettes[0], 16, 8);
LoadSkyboxPalette(skyboxCtx, 0, entryA.palettes[0], 16, 8);
/*size = gSkyboxFiles[newSkybox2Index].palette.vromEnd - gSkyboxFiles[newSkybox2Index].palette.vromStart;
osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
@ -747,7 +753,7 @@ void Environment_UpdateSkybox(GlobalContext* globalCtx, u8 skyboxId, Environment
} else
{
SkyboxTableEntry entryA = sSkyboxTable[newSkybox2Index];
LoadSkyboxPalette(globalCtx, skyboxCtx, 1, entryA.palettes[0], 16, 8);
LoadSkyboxPalette(skyboxCtx, 1, entryA.palettes[0], 16, 8);
/*size = gSkyboxFiles[newSkybox2Index].palette.vromEnd - gSkyboxFiles[newSkybox2Index].palette.vromStart;
osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
@ -755,6 +761,8 @@ void Environment_UpdateSkybox(GlobalContext* globalCtx, u8 skyboxId, Environment
gSkyboxFiles[newSkybox2Index].palette.vromStart, size, 0, &envCtx->loadQueue, NULL,
"../z_kankyo.c", 1355);*/
}
Skybox_Update(skyboxCtx);
}
if ((envCtx->skyboxDmaState == SKYBOX_DMA_FILE1_START) || (envCtx->skyboxDmaState == SKYBOX_DMA_FILE2_START)) {

View File

@ -945,6 +945,7 @@ void Skybox_Setup(GlobalContext* globalCtx, SkyboxContext* skyboxCtx, s16 skybox
void Skybox_Init(GameState* state, SkyboxContext* skyboxCtx, s16 skyboxId) {
GlobalContext* globalCtx = (GlobalContext*)state;
skyboxCtx->skyboxId = skyboxId;
skyboxCtx->unk_140 = 0;
skyboxCtx->rot.x = skyboxCtx->rot.y = skyboxCtx->rot.z = 0.0f;
@ -984,3 +985,20 @@ void Skybox_Init(GameState* state, SkyboxContext* skyboxCtx, s16 skyboxId) {
osSyncPrintf(VT_RST);
}
}
void Skybox_Update(SkyboxContext* skyboxCtx) {
if (skyboxCtx->skyboxId != SKYBOX_NONE) {
osSyncPrintf(VT_FGCOL(GREEN));
if (skyboxCtx->unk_140 != 0) {
func_800AEFC8(skyboxCtx, skyboxCtx->skyboxId);
} else {
if (skyboxCtx->skyboxId == SKYBOX_CUTSCENE_MAP) {
func_800AF178(skyboxCtx, 6);
} else {
func_800AF178(skyboxCtx, 5);
}
}
osSyncPrintf(VT_RST);
}
}