1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-14 03:44:34 +00:00

Fbdemo Docs: TransitionTile (#1471)

* TransitionTile'

* Final clean up

* PR

* Header comment

* vtx_tn

* Name background DL

* row <-> col

* Rename update functions

* Update header

* Enum

* Done -> Ready + cleanups

* Update include/z64transition.h

Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>

Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
This commit is contained in:
Derek Hensley 2022-12-28 13:29:59 -08:00 committed by GitHub
parent 89b42d0d3a
commit bd317dbb9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 178 additions and 143 deletions

View file

@ -1,9 +1,24 @@
/**
* @file z_fbdemo.c
*
* This file implements an unused transition system that takes the current screen, partitions it into large tiles, and
* can apply an effect to them.
*
* The screen is divided into 7 rows and 10 columns of tiles. (`gScreenWidth`/ 10 = `gScreenHeight` / 7 = 0x20)
*
* @note The only coded effect has a visual effect to blend the tiles to a single point, which looks like the screen
* gets sucked into.
*/
#include "global.h"
Gfx D_8012AFB0[] = {
// color framebuffer
extern u16 D_0F000000[];
// Unused background; a blue rectangle with a grey border that fills the screen
Gfx sTransTileBackgroundDL[] = {
gsDPPipeSync(),
gsDPSetCycleType(G_CYC_FILL),
gsDPSetColorImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, 0x0F000000),
gsDPSetColorImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, D_0F000000),
gsDPSetFillColor((GPACK_RGBA5551(65, 65, 65, 1) << 16) | GPACK_RGBA5551(65, 65, 65, 1)),
gsDPFillRectangle(0, 0, 319, 239),
gsDPPipeSync(),
@ -13,7 +28,7 @@ Gfx D_8012AFB0[] = {
gsSPEndDisplayList(),
};
Gfx D_8012B000[] = {
Gfx sTransTileSetupDL[] = {
gsDPPipeSync(),
gsSPTexture(0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON),
gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN |
@ -25,18 +40,15 @@ Gfx D_8012B000[] = {
gsSPEndDisplayList(),
};
void TransitionUnk_InitGraphics(TransitionUnk* this) {
s32 row2;
s32 pad2;
s32 pad3;
Vtx_t* vtx2;
void TransitionTile_InitGraphics(TransitionTile* this) {
s32 frame;
s32 rowTex;
s32 row;
Gfx* gfx;
Vtx* vtx;
s32 col;
s32 col2;
s32 colTex;
Vtx* vtx;
s32 row;
s32 rowTex;
Gfx* gfx;
guMtxIdent(&this->modelView);
guMtxIdent(&this->unk_98);
@ -45,74 +57,84 @@ void TransitionUnk_InitGraphics(TransitionUnk* this) {
for (frame = 0; frame < 2; frame++) {
this->frame = frame;
vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2;
for (colTex = 0, col = 0; col < this->col + 1; colTex += 0x20, col++) {
for (rowTex = 0, row = 0; row < this->row + 1; row++) {
vtx2 = &vtx->v;
vtx++;
rowTex = 0;
for (row = 0; row < this->rows + 1; row++) {
colTex = 0;
for (col = 0; col < this->cols + 1; col++) {
Vtx_tn* vtxn = &vtx->n;
vtx2->tc[0] = rowTex << 6;
vtx2->ob[0] = row * 0x20;
vtx2->ob[1] = col * 0x20;
vtx2->ob[2] = -5;
vtx2->flag = 0;
vtx2->tc[1] = colTex << 6;
vtx2->cn[0] = 0;
vtx2->cn[1] = 0;
vtx2->cn[2] = 120;
vtx2->cn[3] = 255;
rowTex += 0x20;
vtx++;
vtxn->tc[0] = colTex << 6;
vtxn->ob[0] = col * 0x20;
vtxn->ob[1] = row * 0x20;
vtxn->ob[2] = -5;
vtxn->flag = 0;
vtxn->tc[1] = rowTex << 6;
vtxn->n[0] = 0;
vtxn->n[1] = 0;
vtxn->n[2] = 120;
vtxn->a = 255;
colTex += 0x20;
}
rowTex += 0x20;
}
}
gfx = this->gfx;
for (colTex = 0, col = 0; col < this->col; colTex += 0x20, col++) {
rowTex = 0;
for (row = 0; row < this->rows; row++) {
gSPVertex(gfx++, SEGMENT_ADDR(0xA, (u32)row * (this->cols + 1) * sizeof(Vtx)), 2 * (this->cols + 1), 0);
gSPVertex(gfx++, SEGMENT_ADDR(0xA, (u32)col * (this->row + 1) * sizeof(Vtx)), 2 * (this->row + 1), 0);
for (rowTex = 0, row = 0, row2 = 0; row < this->row;) {
colTex = 0;
col2 = 0;
col = 0;
while (col < this->cols) {
gDPPipeSync(gfx++);
gDPLoadTextureTile(gfx++, SEGMENT_ADDR(0xB, 0), G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, SCREEN_HEIGHT,
rowTex, colTex, rowTex + 0x20, colTex + 0x20, 0, G_TX_NOMIRROR | G_TX_WRAP,
colTex, rowTex, colTex + 0x20, rowTex + 0x20, 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);
gSP1Quadrangle(gfx++, row, row + 1, row2 + this->row + 2, this->row + row2 + 1, 0);
gSP1Quadrangle(gfx++, col, col + 1, col2 + this->cols + 2, this->cols + col2 + 1, 0);
rowTex += 0x20;
row2++;
row++;
colTex += 0x20;
col2++;
col++;
}
rowTex += 0x20;
}
gDPPipeSync(gfx++);
gSPEndDisplayList(gfx++);
LOG_NUM("this->col * (1 + this->row * (1 + 7 + 1)) + 1 + 1", this->col * (1 + this->row * 9) + 2, "../z_fbdemo.c",
LOG_NUM("this->col * (1 + this->row * (1 + 7 + 1)) + 1 + 1", this->rows * (1 + this->cols * 9) + 2, "../z_fbdemo.c",
144);
LOG_NUM("gp - this->gfxtbl", gfx - this->gfx, "../z_fbdemo.c", 145);
}
void TransitionUnk_InitData(TransitionUnk* this) {
s32 col;
void TransitionTile_InitVtxData(TransitionTile* this) {
s32 row;
s32 col;
for (col = 0; col < this->col + 1; col++) {
for (row = 0; row < this->row + 1; row++) {
(this->unk_0C + row + col * (this->row + 1))->unk_0 = row * 32;
(this->unk_0C + row + col * (this->row + 1))->unk_4 = col * 32;
for (row = 0; row < this->rows + 1; row++) {
for (col = 0; col < this->cols + 1; col++) {
(this->vtxData + col + row * (this->cols + 1))->x = col * 0x20;
(this->vtxData + col + row * (this->cols + 1))->y = row * 0x20;
}
}
}
void TransitionUnk_Destroy(TransitionUnk* this) {
void TransitionTile_Destroy(TransitionTile* this) {
osSyncPrintf("fbdemo_cleanup(%08x)\n", this);
osSyncPrintf("msleep(100);\n");
Sleep_Msec(100);
if (this->unk_0C != NULL) {
SystemArena_FreeDebug(this->unk_0C, "../z_fbdemo.c", 180);
this->unk_0C = NULL;
if (this->vtxData != NULL) {
SystemArena_FreeDebug(this->vtxData, "../z_fbdemo.c", 180);
this->vtxData = NULL;
}
if (this->vtxFrame1 != NULL) {
SystemArena_FreeDebug(this->vtxFrame1, "../z_fbdemo.c", 181);
@ -128,22 +150,23 @@ void TransitionUnk_Destroy(TransitionUnk* this) {
}
}
TransitionUnk* TransitionUnk_Init(TransitionUnk* this, s32 row, s32 col) {
osSyncPrintf("fbdemo_init(%08x, %d, %d)\n", this, row, col);
bzero(this, sizeof(*this));
TransitionTile* TransitionTile_Init(TransitionTile* this, s32 cols, s32 rows) {
osSyncPrintf("fbdemo_init(%08x, %d, %d)\n", this, cols, rows);
bzero(this, sizeof(TransitionTile));
this->frame = 0;
this->row = row;
this->col = col;
this->unk_0C = SystemArena_MallocDebug((row + 1) * sizeof(TransitionUnkData) * (col + 1), "../z_fbdemo.c", 195);
this->vtxFrame1 = SystemArena_MallocDebug((row + 1) * sizeof(Vtx) * (col + 1), "../z_fbdemo.c", 196);
this->vtxFrame2 = SystemArena_MallocDebug((row + 1) * sizeof(Vtx) * (col + 1), "../z_fbdemo.c", 197);
this->gfx = SystemArena_MallocDebug((this->col * (1 + this->row * 9) + 2) * sizeof(Gfx), "../z_fbdemo.c", 198);
this->cols = cols;
this->rows = rows;
this->vtxData =
SystemArena_MallocDebug((cols + 1) * sizeof(TransitionTileVtxData) * (rows + 1), "../z_fbdemo.c", 195);
this->vtxFrame1 = SystemArena_MallocDebug((cols + 1) * sizeof(Vtx) * (rows + 1), "../z_fbdemo.c", 196);
this->vtxFrame2 = SystemArena_MallocDebug((cols + 1) * sizeof(Vtx) * (rows + 1), "../z_fbdemo.c", 197);
this->gfx = SystemArena_MallocDebug((this->rows * (1 + this->cols * 9) + 2) * sizeof(Gfx), "../z_fbdemo.c", 198);
if (this->unk_0C == NULL || this->vtxFrame1 == NULL || this->vtxFrame2 == NULL || this->gfx == NULL) {
if ((this->vtxData == NULL) || (this->vtxFrame1 == NULL) || (this->vtxFrame2 == NULL) || (this->gfx == NULL)) {
osSyncPrintf("fbdemo_init allocation error\n");
if (this->unk_0C != NULL) {
SystemArena_FreeDebug(this->unk_0C, "../z_fbdemo.c", 202);
this->unk_0C = NULL;
if (this->vtxData != NULL) {
SystemArena_FreeDebug(this->vtxData, "../z_fbdemo.c", 202);
this->vtxData = NULL;
}
if (this->vtxFrame1 != NULL) {
SystemArena_FreeDebug(this->vtxFrame1, "../z_fbdemo.c", 203);
@ -159,72 +182,75 @@ TransitionUnk* TransitionUnk_Init(TransitionUnk* this, s32 row, s32 col) {
}
return NULL;
}
TransitionUnk_InitGraphics(this);
TransitionUnk_InitData(this);
TransitionTile_InitGraphics(this);
TransitionTile_InitVtxData(this);
this->frame = 0;
return this;
}
void TransitionUnk_SetData(TransitionUnk* this) {
void TransitionTile_SetVtx(TransitionTile* this) {
s32 row;
s32 col;
Vtx* vtx;
s32 row;
for (col = 0; col < this->col + 1; col++) {
for (row = 0; row < this->row + 1; row++) {
for (row = 0; row < this->rows + 1; row++) {
for (col = 0; col < this->cols + 1; col++) {
vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2;
(vtx + row + col * (this->row + 1))->v.ob[0] = (this->unk_0C + row + col * (this->row + 1))->unk_0;
(vtx + col + row * (this->cols + 1))->n.ob[0] = (this->vtxData + col + row * (this->cols + 1))->x;
vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2;
(vtx + row + col * (this->row + 1))->v.ob[1] = (this->unk_0C + row + col * (this->row + 1))->unk_4;
(vtx + col + row * (this->cols + 1))->n.ob[1] = (this->vtxData + col + row * (this->cols + 1))->y;
}
}
}
void TransitionUnk_Draw(TransitionUnk* this, Gfx** gfxP) {
void TransitionTile_Draw(TransitionTile* this, Gfx** gfxP) {
Gfx* gfx = *gfxP;
gSPDisplayList(gfx++, D_8012B000);
TransitionUnk_SetData(this);
gSPDisplayList(gfx++, sTransTileSetupDL);
TransitionTile_SetVtx(this);
gSPMatrix(gfx++, &this->projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
gSPMatrix(gfx++, &this->modelView, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPSegment(gfx++, 0xA, this->frame == 0 ? this->vtxFrame1 : this->vtxFrame2);
gSPSegment(gfx++, 0xB, this->zBuffer);
gSPDisplayList(gfx++, D_8012B000);
gSPDisplayList(gfx++, sTransTileSetupDL);
gSPDisplayList(gfx++, this->gfx);
gDPPipeSync(gfx++);
this->frame ^= 1;
*gfxP = gfx;
}
void TransitionUnk_Update(TransitionUnk* this) {
f32 temp_f00;
f32 temp_f12;
s32 col;
f32 phi_f14;
/**
* Blends tiles which has the visual effect of sucking those tiles into a single point
*/
void TransitionTile_Suck(TransitionTile* this) {
s32 row;
s32 col;
f32 diffX;
f32 diffY;
f32 scale;
for (col = 0; col < this->col + 1; col++) {
for (row = 0; row < this->row + 1; row++) {
temp_f00 =
(this->unk_0C + row + col * (this->row + 1))->unk_0 - (this->unk_0C + 5 + 4 * (this->row + 1))->unk_0;
temp_f12 =
(this->unk_0C + row + col * (this->row + 1))->unk_4 - (this->unk_0C + 5 + 4 * (this->row + 1))->unk_4;
phi_f14 = (SQ(temp_f00) + SQ(temp_f12)) / 100.0f;
if (phi_f14 != 0.0f) {
if (phi_f14 < 1.0f) {
phi_f14 = 1.0f;
for (row = 0; row < this->rows + 1; row++) {
for (col = 0; col < this->cols + 1; col++) {
diffX = (this->vtxData + col + row * (this->cols + 1))->x - (this->vtxData + 5 + 4 * (this->cols + 1))->x;
diffY = (this->vtxData + col + row * (this->cols + 1))->y - (this->vtxData + 5 + 4 * (this->cols + 1))->y;
scale = (SQ(diffX) + SQ(diffY)) / 100.0f;
if (scale != 0.0f) {
if (scale < 1.0f) {
scale = 1.0f;
}
(this->unk_0C + row + col * (this->row + 1))->unk_0 -= temp_f00 / phi_f14;
(this->unk_0C + row + col * (this->row + 1))->unk_4 -= temp_f12 / phi_f14;
(this->vtxData + col + row * (this->cols + 1))->x -= diffX / scale;
(this->vtxData + col + row * (this->cols + 1))->y -= diffY / scale;
}
}
}
}
void func_800B23E8(TransitionUnk* this) {
void TransitionTile_Update(TransitionTile* this) {
}
s32 func_800B23F0(TransitionUnk* this) {
s32 func_800B23F0(TransitionTile* this) {
return 0;
}