diff --git a/patches/particle_transform_tagging.c b/patches/particle_transform_tagging.c index 1975bc9..4a569c7 100644 --- a/patches/particle_transform_tagging.c +++ b/patches/particle_transform_tagging.c @@ -8,16 +8,7 @@ #include "core2/particle.h" #include "core2/timedfunc.h" -// 2 bytes of padding between alpha and particleAccerationRange_4C. Must be at least 16-bit to fit the full range of PARTICLE_EMITTER_MAX_ID. -#define PARTICLE_EMITTER_ID(x) (*(u16*)&((x)->pad4A)) - -// 2 bytes of padding between unk104 and unk108. Must be at least 16-bit to fit the full range of PARTICLE_EMITTER_TRANSFORM_ID_COUNT. -#define PARTICLE_EMITTER_SPAWN_COUNT(x) (*(u16*)&((x)->pad106)) - -// 2 bytes of padding after unk5C (skipping 1 byte for alignment). Must be at least as bit as the emitter spawn count field. -#define PARTICLE_ID(x) (*(u16*)&(&(x)->unk5C)[2]) - -u32 particle_emitter_spawn_count = 0; +u32 particle_spawn_count = 0; extern ParticleEmitter **partEmitMgr; extern s32 partEmitMgrLength; @@ -40,6 +31,21 @@ typedef struct particle{ //u8 pad5D[3]; } Particle; +u32 get_particle_id(Particle *p) { + u8 *padding = &p->unk5C + 1; + + u32 id = (padding[0] << 16) | (padding[1] << 8) | (padding[2] << 0); + return id; +} + +void set_particle_id(Particle *p, u32 id) { + u8 *padding = &p->unk5C + 1; + + padding[0] = (id >> 16) & 0xFF; + padding[1] = (id >> 8) & 0xFF; + padding[2] = (id >> 0) & 0xFF; +} + extern Gfx D_80368978[]; extern Gfx D_80368940[]; @@ -62,9 +68,6 @@ RECOMP_PATCH void __particleEmitter_drawOnPass(ParticleEmitter *this, Gfx **gfx, f32 scale[3]; Particle *iPtr; - // @recomp Get the particle emitter's ID. - u32 cur_particle_emitter_index = PARTICLE_EMITTER_ID(this); - if(reinterpret_cast(u32, draw_pass) != (this->draw_mode & 0x4) != 0) return; @@ -77,16 +80,11 @@ RECOMP_PATCH void __particleEmitter_drawOnPass(ParticleEmitter *this, Gfx **gfx, modelRender_setAlpha((s32) (iPtr->fade*this->alpha)); }//L802EEF5C modelRender_setDepthMode((this->draw_mode & PART_EMIT_NO_DEPTH)? MODEL_RENDER_DEPTH_NONE : MODEL_RENDER_DEPTH_FULL); - // @recomp Get the particle's ID. Restrict it to the model particle emitter ID count to account for the smaller number of base transform IDs for - // model particle emitters. - u32 particle_id = PARTICLE_ID(iPtr) % PARTICLE_EMITTER_MODEL_ID_COUNT; - // @recomp Set the current model transform ID. Divide the total per-emitter transform ID count by the per-model transform ID count to get the - // base transform ID for the current model particle. - cur_drawn_model_transform_id = - PARTICLE_TRANSFORM_ID_START + - PARTICLE_EMITTER_TRANSFORM_ID_COUNT * cur_particle_emitter_index + - particle_id * PARTICLE_EMITTER_MODEL_ID_COUNT; + // @recomp Get the particle's ID and use it to set the current model transform ID. + cur_drawn_model_transform_id = MODEL_PARTICLE_TRANSFORM_ID_START + (get_particle_id(iPtr) % MODEL_PARTICLE_ID_MAX) * MARKER_TRANSFORM_ID_COUNT; + modelRender_draw(gfx, mtx, position, iPtr->rotation, iPtr->scale, NULL, this->model_20); + // @recomp Reset the current model transform ID. cur_drawn_model_transform_id = 0; } @@ -132,11 +130,8 @@ RECOMP_PATCH void __particleEmitter_drawOnPass(ParticleEmitter *this, Gfx **gfx, func_802EED1C(this, iPtr->age_48, scale); } func_80344C2C(this->unk0_16); - // @recomp Set the matrix group for this particle. - u32 transform_id = - PARTICLE_TRANSFORM_ID_START + - PARTICLE_EMITTER_TRANSFORM_ID_COUNT * cur_particle_emitter_index + - PARTICLE_ID(iPtr); + // @recomp Get the particle's ID and use it to set a matrix group for this particle. + u32 transform_id = NORMAL_PARTICLE_TRANSFORM_ID_START + get_particle_id(iPtr); gEXMatrixGroupDecomposedNormal((*gfx)++, transform_id, G_EX_PUSH, G_MTX_MODELVIEW, G_EX_EDIT_ALLOW); if(this->draw_mode & PART_EMIT_ROTATABLE){ @@ -156,19 +151,6 @@ RECOMP_PATCH void __particleEmitter_drawOnPass(ParticleEmitter *this, Gfx **gfx, } } -// @recomp Patched to set an incrementing ID for the emitter. -RECOMP_PATCH ParticleEmitter *partEmitMgr_newEmitter(u32 cnt){ - partEmitMgr = realloc(partEmitMgr, (++partEmitMgrLength)*4); - partEmitMgr[partEmitMgrLength - 1] = particleEmitter_new(cnt); - partEmitMgr[partEmitMgrLength - 1]->auto_free = TRUE; - // @recomp Set the particle emitter's ID based on the emitter spawn count and increment the spawn count. - PARTICLE_EMITTER_ID(partEmitMgr[partEmitMgrLength - 1]) = particle_emitter_spawn_count; - particle_emitter_spawn_count++; - particle_emitter_spawn_count = particle_emitter_spawn_count % PARTICLE_EMITTER_MAX_ID; - - return partEmitMgr[partEmitMgrLength - 1]; -} - // @recomp Patched to set an incrementing ID for the particle. RECOMP_PATCH void __particleEmitter_initParticle(ParticleEmitter *this, Particle *particle){ particle->acceleration[0] = randf2(this->particleAccerationRange_4C_min_x, this->particleAccerationRange_4C_max_x); @@ -219,10 +201,13 @@ RECOMP_PATCH void __particleEmitter_initParticle(ParticleEmitter *this, Particle ); } - // @recomp Set the particle's ID based on the particle emitters's spawn count. - PARTICLE_ID(particle) = PARTICLE_EMITTER_SPAWN_COUNT(this); - // @recomp Increment the particle emitter's spawn count. - PARTICLE_EMITTER_SPAWN_COUNT(this)++; + // @recomp Set the particle's ID based on the particle spawn count. + set_particle_id(particle, particle_spawn_count); + // @recomp Increment the particle spawn count. + particle_spawn_count++; + if (particle_spawn_count >= NORMAL_PARTICLE_ID_MAX) { + particle_spawn_count = 0; + } } extern void mlMtxRotatePYR(f32, f32, f32); diff --git a/patches/transform_ids.h b/patches/transform_ids.h index 2400e99..39a3f05 100644 --- a/patches/transform_ids.h +++ b/patches/transform_ids.h @@ -4,6 +4,9 @@ #include "PR/ultratypes.h" #include "rt64_extended_gbi.h" +#define MARKER_TRANSFORM_ID_COUNT 256 // Number of transform IDs for each ActorMarker. + +// Projections: 0x00001000 - 0x00001FFF #define PROJECTION_GAMEPLAY_TRANSFORM_ID 0x00001000 #define PROJECTION_SKYBOX_TRANSFORM_ID 0x00001001 #define PROJECTION_TRANSITION_TRANSFORM_ID 0x00001002 @@ -15,43 +18,55 @@ #define PROJECTION_THE_END_TRANSFORM_ID 0x00001008 #define PROJECTION_PORTRAIT_TRANSFORM_ID_START 0x00001100 // 1 for each portrait ID +// Map models: 0x00400000 - 0x00EFFFFF #define MAP_MODEL_OPA_TRANSFORM_ID_START 0x00400000 #define MAP_MODEL_XLU_TRANSFORM_ID_START 0x00800000 +// Transition model: 0x00F00000 - 0x00F1FFFF #define TRANSITION_MODEL_TRANSFORM_ID_START 0x00F00000 +// Skybox: 0x00F20000 - 0x00F2FFFF #define SKYBOX_MODEL_TRANSFORM_ID_COUNT 256 #define SKYBOX_TRANSFORM_ID_START 0x00F20000 +// Zoombox: 0x00F30000 - 0x00F31FFFF #define ZOOMBOX_TRANSFORM_ID_START 0x00F30000 #define ZOOMBOX_PORTRAIT_TRANSFORM_ID_START 0x00F31000 +// Projectiles: 0x00F32000 - 0x00F33FFF #define PROJECTILE_TRANSFORM_ID_START 0x00F32000 -#define MARKER_TRANSFORM_ID_COUNT 256 // Number of transform IDs for each ActorMarker. -#define BANJO_TRANSFORM_ID_START 0x01000000 -#define MARKER_TRANSFORM_ID_START (BANJO_TRANSFORM_ID_START + MARKER_TRANSFORM_ID_COUNT) - +// HUD Honeycomb: 0x00F34000 - 0x00F3400F #define HUD_HONEYCOMB_TRANSFORM_ID_START 0x00F34000 #define HUD_HONEYCOMB_TRANSFORM_ID_COUNT 6 +// HUD Honeycomb: 0x00F34010 - 0x00F3FFFF #define HUD_SCORE3_TRANSFORM_ID_START 0x00F34010 #define HUD_SCORE3_TRANSFORM_ID_COUNT (0x2B * MARKER_TRANSFORM_ID_COUNT) +// Lens flare: 0x00F40000 - 0x00F40FFF #define LENS_FLARE_TRANSFORM_ID_START 0x00F40000 #define LENS_FLARE_TRANSFORM_ID_COUNT 256 +// Snow: 0x00F41000 - 0x00F410FF #define SNOW_TRANSFORM_ID_START 0x00F41000 -#define PROP_TRANSFORM_ID_COUNT 256 -#define PROP_TRANSFORM_ID_START 0x02000000 +// Normal Particles: 0x01000000 - 0x01FFFFFF +#define NORMAL_PARTICLE_TRANSFORM_ID_START 0x01000000 +#define NORMAL_PARTICLE_ID_MAX 0x01000000 -#define PARTICLE_EMITTER_TRANSFORM_ID_COUNT (256 * 256) // Number of transform IDs for each particle manager. -#define PARTICLE_MODEL_TRANSFORM_ID_COUNT 256 // Number of transform IDs for each model particle. -#define PARTICLE_EMITTER_MODEL_ID_COUNT (PARTICLE_EMITTER_TRANSFORM_ID_COUNT / PARTICLE_MODEL_TRANSFORM_ID_COUNT) // Number of model transform IDs for a model particle emitter. -#define PARTICLE_TRANSFORM_ID_START 0x03000000 -#define PARTICLE_EMITTER_TRANSFORM_ID_TOTAL 0x02000000 -#define PARTICLE_EMITTER_MAX_ID (PARTICLE_EMITTER_TRANSFORM_ID_TOTAL / PARTICLE_EMITTER_TRANSFORM_ID_COUNT) +// Model Particles: 0x02000000 - 0x03FFFFFF +#define MODEL_PARTICLE_TRANSFORM_ID_START 0x02000000 +#define MODEL_PARTICLE_TRANSFORM_ID_COUNT 0x02000000 +#define MODEL_PARTICLE_ID_MAX (MODEL_PARTICLE_TRANSFORM_ID_COUNT / MARKER_TRANSFORM_ID_COUNT) + +// Markers: 0x10000000 - 0x1FFFFFFF +#define BANJO_TRANSFORM_ID_START 0x10000000 +#define MARKER_TRANSFORM_ID_START (BANJO_TRANSFORM_ID_START + MARKER_TRANSFORM_ID_COUNT) + +// Props: 0x20000000 - 0x2FFFFFFF +#define PROP_TRANSFORM_ID_COUNT 256 +#define PROP_TRANSFORM_ID_START 0x20000000 void reset_projection_ids();