Add environment options

This commit is contained in:
Llennpie 2022-09-21 14:08:45 -04:00
parent 491e695557
commit aacadc8030
4 changed files with 19 additions and 52 deletions

View file

@ -12,6 +12,9 @@
#include "audio/external.h"
#include "obj_behaviors.h"
s16 gChromaEnv;
s32 gLevelEnv;
/**
* This file contains the function that handles 'environment effects',
* which are particle effects related to the level type that, unlike
@ -54,26 +57,6 @@ extern void *tiny_bubble_dl_0B006AB0;
extern void *tiny_bubble_dl_0B006A50;
extern void *tiny_bubble_dl_0B006CD8;
static struct {
Gfx *pos;
Vtx vertices[15];
} sPrevSnowVertices[140 / 5];
static s16 sPrevSnowParticleCount;
static u32 sPrevSnowTimestamp;
void patch_interpolated_snow_particles(void) {
int i;
if (gGlobalTimer != sPrevSnowTimestamp + 1) {
return;
}
for (i = 0; i < sPrevSnowParticleCount; i += 5) {
gSPVertex(sPrevSnowVertices[i / 5].pos,
VIRTUAL_TO_PHYSICAL(sPrevSnowVertices[i / 5].vertices), 15, 0);
}
}
/**
* Initialize snow particles by allocating a buffer for storing their state
* and setting a start amount.
@ -237,7 +220,6 @@ void envfx_update_snow_normal(s32 snowCylinderX, s32 snowCylinderY, s32 snowCyli
400.0f * random_float() - 200.0f + snowCylinderZ + (s16)(deltaZ * 2);
(gEnvFxBuffer + i)->yPos = 200.0f * random_float() + snowCylinderY;
(gEnvFxBuffer + i)->isAlive = 1;
(gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer;
} else {
(gEnvFxBuffer + i)->xPos += random_float() * 2 - 1.0f + (s16)(deltaX / 1.2);
(gEnvFxBuffer + i)->yPos -= 2 -(s16)(deltaY * 0.8);
@ -272,7 +254,6 @@ void envfx_update_snow_blizzard(s32 snowCylinderX, s32 snowCylinderY, s32 snowCy
400.0f * random_float() - 200.0f + snowCylinderZ + (s16)(deltaZ * 2);
(gEnvFxBuffer + i)->yPos = 400.0f * random_float() - 200.0f + snowCylinderY;
(gEnvFxBuffer + i)->isAlive = 1;
(gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer;
} else {
(gEnvFxBuffer + i)->xPos += random_float() * 2 - 1.0f + (s16)(deltaX / 1.2) + 20.0f;
(gEnvFxBuffer + i)->yPos -= 5 -(s16)(deltaY * 0.8);
@ -316,7 +297,6 @@ void envfx_update_snow_water(s32 snowCylinderX, s32 snowCylinderY, s32 snowCylin
(gEnvFxBuffer + i)->zPos = 400.0f * random_float() - 200.0f + snowCylinderZ;
(gEnvFxBuffer + i)->yPos = 400.0f * random_float() - 200.0f + snowCylinderY;
(gEnvFxBuffer + i)->isAlive = 1;
(gEnvFxBuffer + i)->spawnTimestamp = gGlobalTimer;
}
}
}
@ -369,8 +349,6 @@ void rotate_triangle_vertices(Vec3s vertex1, Vec3s vertex2, Vec3s vertex3, s16 p
void append_snowflake_vertex_buffer(Gfx *gfx, s32 index, Vec3s vertex1, Vec3s vertex2, Vec3s vertex3) {
s32 i = 0;
Vtx *vertBuf = (Vtx *) alloc_display_list(15 * sizeof(Vtx));
Vtx *vertBufInterpolated = (Vtx *) alloc_display_list(15 * sizeof(Vtx));
Vtx *v;
#ifdef VERSION_EU
Vtx *p;
#endif
@ -420,23 +398,7 @@ void append_snowflake_vertex_buffer(Gfx *gfx, s32 index, Vec3s vertex1, Vec3s ve
#endif
}
for (i = 0; i < 15; i++) {
v = &sPrevSnowVertices[index / 5].vertices[i];
vertBufInterpolated[i] = gSnowTempVtx[i % 3];
if (index < sPrevSnowParticleCount && gGlobalTimer == sPrevSnowTimestamp + 1 &&
gGlobalTimer != gEnvFxBuffer[index + i / 3].spawnTimestamp) {
vertBufInterpolated[i].v.ob[0] = (v->v.ob[0] + vertBuf[i].v.ob[0]) / 2;
vertBufInterpolated[i].v.ob[1] = (v->v.ob[1] + vertBuf[i].v.ob[1]) / 2;
vertBufInterpolated[i].v.ob[2] = (v->v.ob[2] + vertBuf[i].v.ob[2]) / 2;
} else {
vertBufInterpolated[i].v.ob[0] = vertBuf[i].v.ob[0];
vertBufInterpolated[i].v.ob[1] = vertBuf[i].v.ob[1];
vertBufInterpolated[i].v.ob[2] = vertBuf[i].v.ob[2];
}
*v = vertBuf[i];
}
sPrevSnowVertices[index / 5].pos = gfx;
gSPVertex(gfx, VIRTUAL_TO_PHYSICAL(vertBufInterpolated), 15, 0);
gSPVertex(gfx, VIRTUAL_TO_PHYSICAL(vertBuf), 15, 0);
}
/**
@ -520,8 +482,6 @@ Gfx *envfx_update_snow(s32 snowMode, Vec3s marioPos, Vec3s camFrom, Vec3s camTo)
gSP1Triangle(gfx++, 9, 10, 11, 0);
gSP1Triangle(gfx++, 12, 13, 14, 0);
}
sPrevSnowParticleCount = gSnowParticleCount;
sPrevSnowTimestamp = gGlobalTimer;
gSPDisplayList(gfx++, &tiny_bubble_dl_0B006AB0) gSPEndDisplayList(gfx++);

View file

@ -25,10 +25,12 @@ struct EnvFxParticle {
s32 angleAndDist[2]; // for whirpools, [0] = angle from center, [1] = distance from center
s32 unusedBubbleVar; // set to zero for bubbles when respawning, never used elsewhere
s32 bubbleY; // for Bubbles, yPos is always set to this
//s8 filler20[56 - 0x20];
u32 spawnTimestamp;
s8 filler20[56 - 0x20];
};
extern s16 gChromaEnv;
extern s32 gLevelEnv;
extern s8 gEnvFxMode;
extern UNUSED s32 D_80330644;

View file

@ -28,22 +28,23 @@ Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf) {
if (GET_HIGH_U16_OF_32(*params) != gAreaUpdateCounter) {
UNUSED struct Camera *sp2C = gCurGraphNodeCamera->config.camera;
s32 snowMode = GET_LOW_U16_OF_32(*params);
// environment stuff
if (gLevelEnv != 0) {
snowMode = (gLevelEnv - 1);
if (gLevelEnv == 3) snowMode = 3;
}
vec3f_to_vec3s(camTo, gCurGraphNodeCamera->focus);
vec3f_to_vec3s(camFrom, gCurGraphNodeCamera->pos);
vec3f_to_vec3s(marioPos, gPlayerCameraState->pos);
particleList = envfx_update_particles(snowMode, marioPos, camTo, camFrom);
if (particleList != NULL) {
#if 0
Mtx *mtx = alloc_display_list(sizeof(*mtx));
gfx = alloc_display_list(2 * sizeof(*gfx));
mtxf_to_mtx(mtx, mtxf);
gSPMatrix(&gfx[0], VIRTUAL_TO_PHYSICAL(mtx), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
gSPBranchList(&gfx[1], VIRTUAL_TO_PHYSICAL(particleList));
#else
gfx = particleList;
#endif
execNode->fnNode.node.flags = (execNode->fnNode.node.flags & 0xFF) | 0x400;
}
SET_HIGH_U16_OF_32(*params, gAreaUpdateCounter);

View file

@ -22,6 +22,7 @@ extern "C" {
#include "game/level_update.h"
#include "engine/level_script.h"
#include "engine/geo_layout.h"
#include "src/game/envfx_snow.h"
}
using namespace std;
@ -60,7 +61,7 @@ void schroma_imgui_update() {
ImGui::ColorEdit4("Chroma Key Color", (float*)&uiChromaColor, ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine(); ImGui::Text("Color");
ImGui::Checkbox("Render Floor", &renderFloor);
ImGui::SameLine(); imgui_bundled_help_marker("Renders a floor object. Useful for animations that clip through the ground.");
ImGui::SameLine(); imgui_bundled_help_marker("Renders a floor object; Useful for animations that clip through the ground.");
} else {
const char* mSkyboxSettings[] = { "Ocean Sky", "Flaming Sky", "Underwater City", "Below Clouds", "Snow Mountains", "Desert", "Haunted", "Green Sky", "Above Clouds", "Purple Sky" };
ImGui::Combo("###skybox_background", (int*)&gChromaKeyBackground, mSkyboxSettings, IM_ARRAYSIZE(mSkyboxSettings));
@ -80,5 +81,8 @@ void schroma_imgui_update() {
ImGui::Checkbox("Shadows###chroma_shadows", &enable_shadows);
ImGui::Checkbox("Dust Particles###chroma_dust", &enable_dust_particles);
imgui_bundled_tooltip("Displays dust particles when Mario moves - better to leave off when chroma keying.");
imgui_bundled_tooltip("Displays dust particles when Mario moves; Better to leave off when chroma keying.");
const char* mEnvSettings[] = { "Default", "None", "Snow", "Blizzard" };
ImGui::Combo("Environment###env_dropdown", (int*)&gLevelEnv, mEnvSettings, IM_ARRAYSIZE(mEnvSettings));
}