1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-22 21:35:27 +00:00
oot/src/code/z_eff_shield_particle.c

219 lines
9.2 KiB
C
Raw Normal View History

#include "global.h"
#include "vt.h"
Decompile Gameplay_Keep and fix all existing decompiled objects (#595) * First batch of files * Add missing folders back * Fix missing folders again * Finish fixing existing texture files * Gameplay_Keep XML finished * Most actor gameplay_keep undefined syms removed * Only ~200 gkeep symbols remain * All gkeep symbols that ZAP supports are fixed * Cleanup, and make gkeep names more accurate * Starting to figure out what some unknown blobs are, merge zeldaret in * fix a few more things * refactor gkeep * Change how gitkeep is handled * gkeep xml cleanup * Gkeep finished, now just waiting up ZAP updates * 100 link animations finished * 150 link animations finished * 200 link animations finished * 250 link animations finished * 350 link animations finished * 400 link animations finished * 450 link animations finished * 500 link animations finished * 550 link animations finished * All Link animations finished cannot build yet because ZAP doesn't have LinkAnimationHeader yet * xml changes for new zap stuff * finish gameplay_keep * fixing existing objects * ready for pr besides zap padding issue * mostly ready for pr * format all c files * all conflicts fixed * make changes that roman requested * fix thing i didn't mean to change * some animation symbols renamed * fixed roman's stuff * lifemeter hardcoded pointers removed * fix issue with incorrect data in gameplay_keep * removed unused asm * fixed most of fig's comments * fix all of fig's comments * reformat files * Update assets/xml/textures/icon_item_static.xml Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com> * Update assets/xml/textures/icon_item_static.xml Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com> * fixed stuff * fixed most of roman's comments * remove leading zeroes * should build now * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "f84d8337b" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "f84d8337b" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * all of gkeep symbols fixed * compiler error fixed * format files * final changes Co-authored-by: Zelllll <elijah@DESKTOP-NMP1I89.localdomain> Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com>
2021-01-25 00:36:40 +00:00
#include "objects/gameplay_keep/gameplay_keep.h"
2020-03-17 04:31:30 +00:00
static Vtx sVertices[5] = {
VTX(-32, -32, 0, 0, 1024, 0xFF, 0xFF, 0xFF, 0xFF),
VTX(32, 32, 0, 1024, 0, 0xFF, 0xFF, 0xFF, 0xFF),
VTX(-32, 32, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF),
VTX(32, -32, 0, 1024, 1024, 0xFF, 0xFF, 0xFF, 0xFF),
};
2020-03-17 04:31:30 +00:00
// original name: "EffectShieldParticle_ct"
void EffectShieldParticle_Init(void* thisx, void* initParamsx) {
EffectShieldParticle* this = (EffectShieldParticle*)thisx;
EffectShieldParticleInit* initParams = (EffectShieldParticleInit*)initParamsx;
EffectShieldParticleElement* elem;
2020-03-17 04:31:30 +00:00
if ((this != NULL) && (initParams != NULL)) {
this->numElements = initParams->numElements;
if (this->numElements > ARRAY_COUNT(this->elements)) {
osSyncPrintf(VT_FGCOL(RED));
osSyncPrintf("EffectShieldParticle_ct():パーティクル数がオーバしてます。\n");
osSyncPrintf(VT_RST);
return;
}
2020-03-17 04:31:30 +00:00
this->position = initParams->position;
this->primColorStart = initParams->primColorStart;
this->envColorStart = initParams->envColorStart;
this->primColorMid = initParams->primColorMid;
this->envColorMid = initParams->envColorMid;
this->primColorEnd = initParams->primColorEnd;
this->envColorEnd = initParams->envColorEnd;
this->deceleration = initParams->deceleration;
this->maxInitialSpeed = initParams->maxInitialSpeed;
this->lengthCutoff = initParams->lengthCutoff;
this->duration = initParams->duration;
this->timer = 0;
for (elem = &this->elements[0]; elem < &this->elements[this->numElements]; elem++) {
elem->initialSpeed = (Rand_ZeroOne() * (this->maxInitialSpeed * 0.5f)) + (this->maxInitialSpeed * 0.5f);
elem->endX = 0.0f;
elem->startXChange = 0.0f;
elem->startX = 0.0f;
elem->endXChange = elem->initialSpeed;
elem->yaw = Rand_ZeroOne() * 65534.0f;
elem->pitch = Rand_ZeroOne() * 65534.0f;
}
this->lightDecay = initParams->lightDecay;
if (this->lightDecay == true) {
this->lightInfo.type = LIGHT_POINT_NOGLOW;
this->lightInfo.params.point = initParams->lightPoint;
this->lightNode =
LightContext_InsertLight(Effect_GetGlobalCtx(), &Effect_GetGlobalCtx()->lightCtx, &this->lightInfo);
} else {
this->lightNode = NULL;
}
}
}
void EffectShieldParticle_Destroy(void* thisx) {
EffectShieldParticle* this = (EffectShieldParticle*)thisx;
if ((this != NULL) && (this->lightDecay == true)) {
if (this->lightNode == Effect_GetGlobalCtx()->lightCtx.listHead) {
Effect_GetGlobalCtx()->lightCtx.listHead = this->lightNode->next;
}
LightContext_RemoveLight(Effect_GetGlobalCtx(), &Effect_GetGlobalCtx()->lightCtx, this->lightNode);
}
}
s32 EffectShieldParticle_Update(void* thisx) {
EffectShieldParticle* this = (EffectShieldParticle*)thisx;
EffectShieldParticleElement* elem;
if (this == NULL) {
return 0;
}
for (elem = &this->elements[0]; elem < &this->elements[this->numElements]; elem++) {
elem->endXChange -= this->deceleration;
if (elem->endXChange < 0.0f) {
elem->endXChange = 0.0f;
}
if (elem->startXChange > 0.0f) {
elem->startXChange -= this->deceleration;
if (elem->startXChange < 0.0f) {
elem->startXChange = 0.0f;
}
}
elem->endX += elem->endXChange;
elem->startX += elem->startXChange;
if ((elem->startXChange == 0.0f) && (this->lengthCutoff < (elem->endX - elem->startX))) {
elem->startXChange = elem->initialSpeed;
}
}
if (this->lightDecay == true) {
this->lightInfo.params.point.radius /= 2;
}
this->timer++;
if (this->duration < this->timer) {
return 1;
}
return 0;
}
void EffectShieldParticle_GetColors(EffectShieldParticle* this, Color_RGBA8* primColor, Color_RGBA8* envColor) {
s32 halfDuration = this->duration * 0.5f;
f32 ratio;
if (halfDuration == 0) {
primColor->r = this->primColorStart.r;
primColor->g = this->primColorStart.g;
primColor->b = this->primColorStart.b;
primColor->a = this->primColorStart.a;
envColor->r = this->envColorStart.r;
envColor->g = this->envColorStart.g;
envColor->b = this->envColorStart.b;
envColor->a = this->envColorStart.a;
} else if (this->timer < halfDuration) {
ratio = this->timer / (f32)halfDuration;
primColor->r = this->primColorStart.r + (this->primColorMid.r - this->primColorStart.r) * ratio;
primColor->g = this->primColorStart.g + (this->primColorMid.g - this->primColorStart.g) * ratio;
primColor->b = this->primColorStart.b + (this->primColorMid.b - this->primColorStart.b) * ratio;
primColor->a = this->primColorStart.a + (this->primColorMid.a - this->primColorStart.a) * ratio;
envColor->r = this->envColorStart.r + (this->envColorMid.r - this->envColorStart.r) * ratio;
envColor->g = this->envColorStart.g + (this->envColorMid.g - this->envColorStart.g) * ratio;
envColor->b = this->envColorStart.b + (this->envColorMid.b - this->envColorStart.b) * ratio;
envColor->a = this->envColorStart.a + (this->envColorMid.a - this->envColorStart.a) * ratio;
} else {
ratio = (this->timer - halfDuration) / (f32)halfDuration;
primColor->r = this->primColorMid.r + (this->primColorEnd.r - this->primColorMid.r) * ratio;
primColor->g = this->primColorMid.g + (this->primColorEnd.g - this->primColorMid.g) * ratio;
primColor->b = this->primColorMid.b + (this->primColorEnd.b - this->primColorMid.b) * ratio;
primColor->a = this->primColorMid.a + (this->primColorEnd.a - this->primColorMid.a) * ratio;
envColor->r = this->envColorMid.r + (this->envColorEnd.r - this->envColorMid.r) * ratio;
envColor->g = this->envColorMid.g + (this->envColorEnd.g - this->envColorMid.g) * ratio;
envColor->b = this->envColorMid.b + (this->envColorEnd.b - this->envColorMid.b) * ratio;
envColor->a = this->envColorMid.a + (this->envColorEnd.a - this->envColorMid.a) * ratio;
}
}
void EffectShieldParticle_Draw(void* thisx, GraphicsContext* gfxCtx) {
EffectShieldParticle* this = (EffectShieldParticle*)thisx;
EffectShieldParticleElement* elem;
Color_RGBA8 primColor;
Color_RGBA8 envColor;
OPEN_DISPS(gfxCtx, "../z_eff_shield_particle.c", 272);
if (this != NULL) {
POLY_XLU_DISP = Gfx_CallSetupDL(POLY_XLU_DISP, 0x26);
gDPSetCycleType(POLY_XLU_DISP++, G_CYC_2CYCLE);
gDPPipeSync(POLY_XLU_DISP++);
gSPTexture(POLY_XLU_DISP++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
Decompile Gameplay_Keep and fix all existing decompiled objects (#595) * First batch of files * Add missing folders back * Fix missing folders again * Finish fixing existing texture files * Gameplay_Keep XML finished * Most actor gameplay_keep undefined syms removed * Only ~200 gkeep symbols remain * All gkeep symbols that ZAP supports are fixed * Cleanup, and make gkeep names more accurate * Starting to figure out what some unknown blobs are, merge zeldaret in * fix a few more things * refactor gkeep * Change how gitkeep is handled * gkeep xml cleanup * Gkeep finished, now just waiting up ZAP updates * 100 link animations finished * 150 link animations finished * 200 link animations finished * 250 link animations finished * 350 link animations finished * 400 link animations finished * 450 link animations finished * 500 link animations finished * 550 link animations finished * All Link animations finished cannot build yet because ZAP doesn't have LinkAnimationHeader yet * xml changes for new zap stuff * finish gameplay_keep * fixing existing objects * ready for pr besides zap padding issue * mostly ready for pr * format all c files * all conflicts fixed * make changes that roman requested * fix thing i didn't mean to change * some animation symbols renamed * fixed roman's stuff * lifemeter hardcoded pointers removed * fix issue with incorrect data in gameplay_keep * removed unused asm * fixed most of fig's comments * fix all of fig's comments * reformat files * Update assets/xml/textures/icon_item_static.xml Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com> * Update assets/xml/textures/icon_item_static.xml Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com> * fixed stuff * fixed most of roman's comments * remove leading zeroes * should build now * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "f84d8337b" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "f84d8337b" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * all of gkeep symbols fixed * compiler error fixed * format files * final changes Co-authored-by: Zelllll <elijah@DESKTOP-NMP1I89.localdomain> Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com>
2021-01-25 00:36:40 +00:00
gDPLoadTextureBlock(POLY_XLU_DISP++, gUnknownCircle6Tex, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 5, 5, G_TX_NOLOD, G_TX_NOLOD);
if (1) {} // Necessary to match
gDPSetCombineLERP(POLY_XLU_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, PRIMITIVE, 0, TEXEL0, 0, 0, 0,
0, COMBINED, 0, 0, 0, COMBINED);
gDPSetRenderMode(POLY_XLU_DISP++, G_RM_PASS, G_RM_ZB_CLD_SURF2);
gSPClearGeometryMode(POLY_XLU_DISP++, G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR);
gSPSetGeometryMode(POLY_XLU_DISP++, G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH);
EffectShieldParticle_GetColors(this, &primColor, &envColor);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, primColor.r, primColor.g, primColor.b, primColor.a);
gDPSetEnvColor(POLY_XLU_DISP++, envColor.r, envColor.g, envColor.b, envColor.a);
gDPPipeSync(POLY_XLU_DISP++);
for (elem = &this->elements[0]; elem < &this->elements[this->numElements]; elem++) {
Mtx* mtx;
MtxF sp104;
MtxF spC4;
MtxF sp84;
f32 temp1 = (s16)((elem->endX + elem->startX) * 0.5f);
f32 temp2 = elem->endX - elem->startX;
f32 temp3 = (s16)((temp2 * (1.0f / 64.0f)) / 0.02f);
if (temp3 < 1.0f) {
temp3 = 1.0f;
}
z_skin_matrix.c decompiled (1 non matching, 1 non equivalent) (#243) * func_800A7BE4 and func_800A7C20 done - func_800A7BE4 copy of "Math_Vec3f_ToVec3s" in z_lib.c - func_800A7C20 copy of "Math_Vec3s_ToVec3f" in z_lib.c * done func_800A7A24 * func_800A76A4 done * func_800A6E10 done * func_800A6EF4 done * func_800A6FA0 done * func_800A72FC done * Deleted z_skin_matrix.data.s and updated spec * func_800A730C done * func_800A735C done * func_800A7E70 done, func_800A7C60 matching but I'm not happy with it (weird types in function params) * Corrections. func_800A7C60 in skin_matrix done, Matrix_MtxFToMtx in sys_matrix done. * func_800A7EC0 nonmatching * func_800A8030 nonmatching but VERY close (two registers swapped) * func_800A8030 done * updating comments * func_800A7704 done * func_800A7894 done * halfway through deciphering mips_to_c for func_800A73E0 * func_800A73E0 functional but non-matching (saved register differences and probably regalloc) * Renaming some arguments and rewriting comments * Renamed files across whole project and deleted asm nonmatchings * ran format.sh * fixed function name * fixing multiplcation order in SkinMatrix_MtxFMtxFMult * Corrections in SkinMatrix_MtxFMtxFMult * Formatting changes after review * Changes as per code review * fixing rename error * fixing rename error * rename fixes * fixing function rename error * ran ./format.sh * last couple of changes as per code review * renamed SetScaling -> SetScale * Skin_Matrix_Invert -> SkinMatrix_Invert * Renaming and fixing debug message print * Renamed argument "mf" to more specific "clear" in SkinMatrix_GetClear * renamed again to "mfp" * snake case to camel case changes
2020-08-08 15:23:16 +00:00
SkinMatrix_SetTranslate(&spC4, this->position.x, this->position.y, this->position.z);
SkinMatrix_SetRotateRPY(&sp104, 0, elem->yaw, 0);
SkinMatrix_MtxFMtxFMult(&spC4, &sp104, &sp84);
SkinMatrix_SetRotateRPY(&sp104, 0, 0, elem->pitch);
SkinMatrix_MtxFMtxFMult(&sp84, &sp104, &spC4);
SkinMatrix_SetTranslate(&sp104, temp1, 0.0f, 0.0f);
SkinMatrix_MtxFMtxFMult(&spC4, &sp104, &sp84);
SkinMatrix_SetScale(&sp104, temp3 * 0.02f, 0.02f, 0.02f);
SkinMatrix_MtxFMtxFMult(&sp84, &sp104, &spC4);
mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &spC4);
if (mtx == NULL) {
break;
}
gSPMatrix(POLY_XLU_DISP++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPVertex(POLY_XLU_DISP++, sVertices, 4, 0);
gSP2Triangles(POLY_XLU_DISP++, 0, 1, 2, 0, 0, 3, 1, 0);
}
}
CLOSE_DISPS(gfxCtx, "../z_eff_shield_particle.c", 359);
}