Skip to content

Commit

Permalink
Merge 'Code style fixes and guidelines' (#2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjohnson57 committed Nov 29, 2023
2 parents c0e1121 + d4f0ba2 commit d203790
Show file tree
Hide file tree
Showing 120 changed files with 2,091 additions and 2,216 deletions.
524 changes: 262 additions & 262 deletions ASM/build/c_symbols.txt

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions ASM/c/actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern int8_t curr_scene_setup;

// Called at the end of Actor_SetWorldToHome
// Reset the rotations for any actors that we may have passed data in through Actor_Spawn
void Actor_SetWorldToHome_End(z64_actor_t *actor) {
void Actor_SetWorldToHome_End(z64_actor_t* actor) {
switch (actor->actor_id) {
case BG_HAKA_TUBO:
case BG_SPOT18_BASKET:
Expand All @@ -50,7 +50,7 @@ void Actor_SetWorldToHome_End(z64_actor_t *actor) {
// Otherwise the actor would be rotated :)
// Now that we resized pots/crates/beehives we could probably just store this info in new space in the actor. But this works for now.
// Prior to being called, CURR_ACTOR_SPAWN_INDEX is set to the current position in the actor spawn list.
void Actor_After_UpdateAll_Hack(z64_actor_t *actor, z64_game_t *game) {
void Actor_After_UpdateAll_Hack(z64_actor_t* actor, z64_game_t* game) {
Actor_StoreFlagInRotation(actor, game, CURR_ACTOR_SPAWN_INDEX);
Actor_StoreChestType(actor, game);

Expand All @@ -59,7 +59,7 @@ void Actor_After_UpdateAll_Hack(z64_actor_t *actor, z64_game_t *game) {

// For pots/crates/beehives, store the flag in the actor's unused initial rotation fields
// Flag consists of the room # and the actor index
void Actor_StoreFlagInRotation(z64_actor_t *actor, z64_game_t *game, uint16_t actor_index) {
void Actor_StoreFlagInRotation(z64_actor_t* actor, z64_game_t* game, uint16_t actor_index) {
uint16_t flag = actor_index | (actor->room_index << 8); // Calculate the flag
switch (actor->actor_id) {
// For the following actors we store the flag in the z rotation
Expand Down Expand Up @@ -89,26 +89,26 @@ void Actor_StoreChestType(z64_actor_t* actor, z64_game_t* game) {

if (actor->actor_id == OBJ_TSUBO) { // Pots
override = get_pot_override(actor, game);
pChestType = &(((ObjTsubo *)actor)->chest_type);
pChestType = &(((ObjTsubo*)actor)->chest_type);
} else if (actor->actor_id == EN_TUBO_TRAP) { // Flying Pots
override = get_flying_pot_override(actor, game);
pChestType = &(((EnTuboTrap *)actor)->chest_type);
pChestType = &(((EnTuboTrap*)actor)->chest_type);
} else if (actor->actor_id == OBJ_KIBAKO2) { // Large Crates
override = get_crate_override(actor, game);
pChestType = &(((ObjKibako2 *)actor)->chest_type);
pChestType = &(((ObjKibako2*)actor)->chest_type);
} else if (actor->actor_id == OBJ_KIBAKO) { // Small wooden crates
override = get_smallcrate_override(actor, game);
pChestType = &(((ObjKibako *)actor)->chest_type);
pChestType = &(((ObjKibako*)actor)->chest_type);
} else if (actor->actor_id == OBJ_COMB) {
override = get_beehive_override(actor, game);
pChestType = &(((ObjComb *)actor)->chest_type);
pChestType = &(((ObjComb*)actor)->chest_type);
}
if (override.key.all != 0 && pChestType != NULL) { // If we don't have an override key, then either this item doesn't have an override entry, or it has already been collected.
if (POTCRATE_TEXTURES_MATCH_CONTENTS == PTMC_UNCHECKED && override.key.all > 0) { // For "unchecked" PTMC setting: Check if we have an override which means it wasn't collected.
*pChestType = GILDED_CHEST;
} else if(POTCRATE_TEXTURES_MATCH_CONTENTS == PTMC_CONTENTS) {
} else if (POTCRATE_TEXTURES_MATCH_CONTENTS == PTMC_CONTENTS) {
uint16_t item_id = resolve_upgrades(override);
item_row_t *row = get_item_row(override.value.looks_like_item_id);
item_row_t* row = get_item_row(override.value.looks_like_item_id);
if (row == NULL) {
row = get_item_row(override.value.base.item_id);
}
Expand All @@ -119,9 +119,9 @@ void Actor_StoreChestType(z64_actor_t* actor, z64_game_t* game) {
}
}

typedef void(*actor_after_spawn_func)(z64_actor_t* actor, bool overridden);
typedef void (*actor_after_spawn_func)(z64_actor_t* actor, bool overridden);

z64_actor_t *Actor_SpawnEntry_Hack(void *actorCtx, ActorEntry *actorEntry, z64_game_t *globalCtx) {
z64_actor_t* Actor_SpawnEntry_Hack(void* actorCtx, ActorEntry* actorEntry, z64_game_t* globalCtx) {
bool continue_spawn = true;
bool overridden = false;
actor_after_spawn_func after_spawn_func = NULL;
Expand All @@ -135,19 +135,19 @@ z64_actor_t *Actor_SpawnEntry_Hack(void *actorCtx, ActorEntry *actorEntry, z64_g
break;
}
}
z64_actor_t *spawned = NULL;
z64_actor_t* spawned = NULL;
if (continue_spawn) {
spawned = z64_SpawnActor(actorCtx, globalCtx, actorEntry->id, actorEntry->pos.x, actorEntry->pos.y, actorEntry->pos.z,
actorEntry->rot.x, actorEntry->rot.y, actorEntry->rot.z, actorEntry->params);
if(spawned && after_spawn_func) {
if (spawned && after_spawn_func) {
after_spawn_func(spawned, overridden);
}
}
return spawned;
}

// Override silver rupee spawns.
bool spawn_override_silver_rupee(ActorEntry *actorEntry, z64_game_t *globalCtx, bool* overridden) {
bool spawn_override_silver_rupee(ActorEntry* actorEntry, z64_game_t* globalCtx, bool* overridden) {
*overridden = false;
if (SHUFFLE_SILVER_RUPEES) { // Check if silver rupee shuffle is enabled.
// Build a dummy enitem00 actor
Expand Down Expand Up @@ -176,16 +176,15 @@ bool spawn_override_silver_rupee(ActorEntry *actorEntry, z64_game_t *globalCtx,
}

// After silver rupee spawns as enitem00
void after_spawn_override_silver_rupee(z64_actor_t* spawned, bool overridden)
{
if(overridden) {
void after_spawn_override_silver_rupee(z64_actor_t* spawned, bool overridden) {
if (overridden) {
EnItem00* this = (EnItem00*)spawned;
this->is_silver_rupee = true;
this->collider.info.bumper.dmgFlags = 0; //Remove clear the bumper collider flags so it doesn't interact w/ boomerang
this->collider.info.bumper.dmgFlags = 0; // Remove clear the bumper collider flags so it doesn't interact w/ boomerang
}
}

z64_actor_t *Player_SpawnEntry_Hack(void *actorCtx, ActorEntry *playerEntry, z64_game_t *globalCtx) {
z64_actor_t* Player_SpawnEntry_Hack(void* actorCtx, ActorEntry* playerEntry, z64_game_t* globalCtx) {
if (z64_file.entrance_index == 0x423) {
playerEntry->pos.y = 1000;
playerEntry->pos.z = -1960;
Expand Down
12 changes: 6 additions & 6 deletions ASM/c/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include "z64.h"
#include <stdbool.h>

void Actor_SetWorldToHome_End(z64_actor_t *actor);
void Actor_After_UpdateAll_Hack(z64_actor_t *actor, z64_game_t *game);
void Actor_StoreFlagInRotation(z64_actor_t *actor, z64_game_t *game, uint16_t actor_index);
void Actor_StoreChestType(z64_actor_t *actor, z64_game_t *game);
z64_actor_t *Actor_SpawnEntry_Hack(void *actorCtx, ActorEntry *actorEntry, z64_game_t *globalCtx);
bool spawn_override_silver_rupee(ActorEntry *actorEntry, z64_game_t *globalCtx, bool* overridden);
void Actor_SetWorldToHome_End(z64_actor_t* actor);
void Actor_After_UpdateAll_Hack(z64_actor_t* actor, z64_game_t* game);
void Actor_StoreFlagInRotation(z64_actor_t* actor, z64_game_t* game, uint16_t actor_index);
void Actor_StoreChestType(z64_actor_t* actor, z64_game_t* game);
z64_actor_t* Actor_SpawnEntry_Hack(void* actorCtx, ActorEntry* actorEntry, z64_game_t* globalCtx);
bool spawn_override_silver_rupee(ActorEntry* actorEntry, z64_game_t* globalCtx, bool* overridden);
void after_spawn_override_silver_rupee(z64_actor_t* actor, bool overridden);
#endif
5 changes: 2 additions & 3 deletions ASM/c/agony.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void draw_agony_graphic(int hoffset, int voffset, unsigned char alpha) {
alpha = maxalpha;
}

z64_disp_buf_t *db = &(z64_ctxt.gfx->overlay);
z64_disp_buf_t* db = &(z64_ctxt.gfx->overlay);
gSPDisplayList(db->p++, &setup_db);
gDPPipeSync(db->p++);
gDPSetCombineMode(db->p++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
Expand All @@ -97,7 +97,7 @@ void draw_agony() {
if (scene_index != dungeons[i].index) continue;

dungeon_entry_t dungeon = dungeons[i];
uint8_t *silver_rupee_puzzles = CFG_DUNGEON_IS_MQ[dungeon.index] ? dungeon.silver_rupee_puzzles_mq : dungeon.silver_rupee_puzzles_vanilla;
uint8_t* silver_rupee_puzzles = CFG_DUNGEON_IS_MQ[dungeon.index] ? dungeon.silver_rupee_puzzles_mq : dungeon.silver_rupee_puzzles_vanilla;
for (int puzzle_idx = 0; puzzle_idx < 4; puzzle_idx++) {
if (silver_rupee_puzzles[puzzle_idx] == (uint8_t) -1) break;
silver_rupee_data_t silver_rupee_info = silver_rupee_vars[silver_rupee_puzzles[puzzle_idx]][CFG_DUNGEON_IS_MQ[dungeon.index]];
Expand All @@ -112,4 +112,3 @@ void draw_agony() {
draw_agony_graphic(hoffset, voffset, alpha);
}
}

81 changes: 30 additions & 51 deletions ASM/c/chests.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define CHEST_BASE 1
#define CHEST_LID 3

#define box_obj_idx(actor) ((int8_t *)actor)[0x015A] // forest_hallway_actor->box_obj_idx
#define box_obj_idx(actor) ((int8_t*)actor)[0x015A] // forest_hallway_actor->box_obj_idx
#define OBJECT_BOX 0x000E

extern uint8_t SHUFFLE_CHEST_GAME;
Expand All @@ -23,8 +23,8 @@ uint32_t CHEST_SIZE_TEXTURE = 0;
extern Mtx_t* write_matrix_stack_top(z64_gfx_t* gfx);
asm(".equ write_matrix_stack_top, 0x800AB900");

void get_chest_override(z64_actor_t *actor) {
Chest *chest = (Chest *)actor;
void get_chest_override(z64_actor_t* actor) {
Chest* chest = (Chest*)actor;
uint8_t size = chest->en_box.type;
uint8_t color = size;

Expand All @@ -34,7 +34,7 @@ void get_chest_override(z64_actor_t *actor) {

override_t override = lookup_override(actor, scene, item_id);
if (override.value.base.item_id != 0) {
item_row_t *item_row = get_item_row(override.value.looks_like_item_id);
item_row_t* item_row = get_item_row(override.value.looks_like_item_id);
if (item_row == NULL) {
item_row = get_item_row(override.value.base.item_id);
}
Expand All @@ -60,18 +60,16 @@ void get_chest_override(z64_actor_t *actor) {
}
}

uint8_t get_chest_type(z64_actor_t *actor)
{
uint8_t chest_type = ((Chest *)actor)->color;
if (CHEST_SIZE_MATCH_CONTENTS && chest_type == SILVER_CHEST)
{
uint8_t get_chest_type(z64_actor_t* actor) {
uint8_t chest_type = ((Chest*)actor)->color;
if (CHEST_SIZE_MATCH_CONTENTS && chest_type == SILVER_CHEST) {
chest_type = GOLD_CHEST;
}

return chest_type;
}

void set_chest_texture(z64_gfx_t *gfx, uint8_t chest_type, Gfx **opa_ptr) {
void set_chest_texture(z64_gfx_t* gfx, uint8_t chest_type, Gfx** opa_ptr) {
//set texture type
void* frontTexture = (void*)BROWN_FRONT_TEXTURE;
void* baseTexture = (void*)BROWN_BASE_TEXTURE;
Expand Down Expand Up @@ -117,55 +115,41 @@ void set_chest_texture(z64_gfx_t *gfx, uint8_t chest_type, Gfx **opa_ptr) {
gSPSegment((*opa_ptr)++, 0x09, gfx->poly_opa.d);
}

void draw_chest_base(z64_game_t *game, z64_actor_t *actor, Gfx **opa_ptr)
{
z64_gfx_t *gfx = game->common.gfx;
void draw_chest_base(z64_game_t* game, z64_actor_t* actor, Gfx** opa_ptr) {
z64_gfx_t* gfx = game->common.gfx;
uint8_t chest_type = get_chest_type(actor);
gSPMatrix((*opa_ptr)++, write_matrix_stack_top(gfx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
if (chest_type != GOLD_CHEST)
{
if (chest_type != GOLD_CHEST) {
set_chest_texture(gfx, chest_type, opa_ptr);
gSPDisplayList((*opa_ptr)++, 0x060006F0);
}
else
{
} else {
gSPDisplayList((*opa_ptr)++, 0x06000AE8);
}
}

void draw_chest_lid(z64_game_t *game, z64_actor_t *actor, Gfx **opa_ptr)
{
z64_gfx_t *gfx = game->common.gfx;
void draw_chest_lid(z64_game_t* game, z64_actor_t* actor, Gfx** opa_ptr) {
z64_gfx_t* gfx = game->common.gfx;
uint8_t chest_type = get_chest_type(actor);
gSPMatrix((*opa_ptr)++, write_matrix_stack_top(gfx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
if (chest_type != GOLD_CHEST)
{
if (chest_type != GOLD_CHEST) {
set_chest_texture(gfx, chest_type, opa_ptr);
gSPDisplayList((*opa_ptr)++, 0x060010C0);
}
else
{
} else {
gSPDisplayList((*opa_ptr)++, 0x06001678);
}
}

void draw_chest(z64_game_t *game, int32_t part, void *unk, void *unk2, z64_actor_t *actor, Gfx **opa_ptr)
{
if (part == CHEST_BASE)
{
void draw_chest(z64_game_t* game, int32_t part, void* unk, void* unk2, z64_actor_t* actor, Gfx** opa_ptr) {
if (part == CHEST_BASE) {
draw_chest_base(game, actor, opa_ptr);
}
else if (part == CHEST_LID)
{
} else if (part == CHEST_LID) {
draw_chest_lid(game, actor, opa_ptr);
}
}

_Bool should_draw_forest_hallway_chest(z64_actor_t *actor, z64_game_t *game)
{
_Bool should_draw_forest_hallway_chest(z64_actor_t* actor, z64_game_t* game) {
// Do not draw the chest if it is invisible, not open, and lens is not active
if (CHEST_LENS_ONLY && !(game->chest_flags & 0x4000) && !game->actor_ctxt.lens_active)
{
if (CHEST_LENS_ONLY && !(game->chest_flags & 0x4000) && !game->actor_ctxt.lens_active) {
return false;
}

Expand All @@ -175,37 +159,32 @@ _Bool should_draw_forest_hallway_chest(z64_actor_t *actor, z64_game_t *game)
&& z64_ObjectIsLoaded(&game->obj_ctxt, box_obj_idx(actor));
}

void get_dummy_chest(Chest *dummy_chest)
{
void get_dummy_chest(Chest* dummy_chest) {
z64_actor_t dummy_actor;
dummy_actor.actor_id = 0x000A;
dummy_actor.variable = 0x27EE;
dummy_chest->en_box.dyna.actor = dummy_actor;
}

void draw_forest_hallway_chest_base()
{
void draw_forest_hallway_chest_base() {
// Use dummy forest hallway chest actor instance to get override
Chest dummy_chest;
get_dummy_chest(&dummy_chest);
get_chest_override((z64_actor_t *)&dummy_chest);
if (dummy_chest.size == SMALL_CHEST)
{
get_chest_override((z64_actor_t*)&dummy_chest);
if (dummy_chest.size == SMALL_CHEST) {
// Just scaled the matrix by 0.01 so matrix is now scaled by 0.005
scale_sys_matrix(0.5f, 0.5f, 0.5f, 1);
}

draw_chest_base(&z64_game, (z64_actor_t *)&dummy_chest, &z64_game.common.gfx->poly_opa.p);
draw_chest_base(&z64_game, (z64_actor_t*)&dummy_chest, &z64_game.common.gfx->poly_opa.p);
}

void draw_forest_hallway_chest_lid()
{
void draw_forest_hallway_chest_lid() {
// Use dummy forest hallway chest actor instance to get override
Chest dummy_chest;
get_dummy_chest(&dummy_chest);
get_chest_override((z64_actor_t *)&dummy_chest);
if (dummy_chest.size == SMALL_CHEST)
{
get_chest_override((z64_actor_t*)&dummy_chest);
if (dummy_chest.size == SMALL_CHEST) {
// Just scaled the matrix by 0.01 so matrix is now scaled by 0.005
scale_sys_matrix(0.5f, 0.5f, 0.5f, 1);

Expand All @@ -219,5 +198,5 @@ void draw_forest_hallway_chest_lid()
}
}

draw_chest_lid(&z64_game, (z64_actor_t *)&dummy_chest, &z64_game.common.gfx->poly_opa.p);
draw_chest_lid(&z64_game, (z64_actor_t*)&dummy_chest, &z64_game.common.gfx->poly_opa.p);
}
8 changes: 4 additions & 4 deletions ASM/c/chests.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern uint32_t CHEST_LENS_ONLY;

struct EnBox;

typedef void (*EnBoxActionFunc)(struct EnBox *, z64_game_t *);
typedef void (*EnBoxActionFunc)(struct EnBox*, z64_game_t*);

typedef struct EnBox
{
Expand Down Expand Up @@ -41,9 +41,9 @@ typedef struct Chest
/* 0x01ED */ uint8_t color; // added for rando
} Chest; // size = 0x01EE

void get_chest_override(z64_actor_t *actor);
void draw_chest(z64_game_t *game, int32_t part, void *unk, void *unk2, z64_actor_t *actor, Gfx **opa_ptr);
_Bool should_draw_forest_hallway_chest(z64_actor_t *actor, z64_game_t *game);
void get_chest_override(z64_actor_t* actor);
void draw_chest(z64_game_t* game, int32_t part, void* unk, void* unk2, z64_actor_t* actor, Gfx** opa_ptr);
_Bool should_draw_forest_hallway_chest(z64_actor_t* actor, z64_game_t* game);
void draw_forest_hallway_chest_base();
void draw_forest_hallway_chest_lid();

Expand Down
13 changes: 5 additions & 8 deletions ASM/c/dpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ extern uint8_t CFG_DISPLAY_DPAD;
//unknown 02 is a pointer to some kind of audio configuration Always 801043A0 in my testing
//unknown 03 is always a3 in my testing
//unknown 04 is always a3 + 0x08 in my testing (801043A8)
typedef void(*playsfx_t)(uint16_t sfx, z64_xyzf_t *unk_00_, int8_t unk_01_ , float *unk_02_, float *unk_03_, float *unk_04_);
typedef void(*usebutton_t)(z64_game_t *game, z64_link_t *link, uint8_t item, uint8_t button);
typedef void(*playsfx_t)(uint16_t sfx, z64_xyzf_t* unk_00_, int8_t unk_01_ , float* unk_02_, float* unk_03_, float* unk_04_);
typedef void(*usebutton_t)(z64_game_t* game, z64_link_t* link, uint8_t item, uint8_t button);

#define z64_playsfx ((playsfx_t) 0x800C806C)
#define z64_usebutton ((usebutton_t) 0x8038C9A0)
Expand Down Expand Up @@ -68,7 +68,7 @@ void handle_dpad() {
}

void draw_dpad_and_menu_utilities() {
z64_disp_buf_t *db = &(z64_ctxt.gfx->overlay);
z64_disp_buf_t* db = &(z64_ctxt.gfx->overlay);
if (CAN_DRAW_DUNGEON_INFO || (DISPLAY_DPAD && CFG_DISPLAY_DPAD) || CAN_DRAW_TRADE_DPAD || CAN_DRAW_OCARINA_BUTTONS) {

gSPDisplayList(db->p++, &setup_db);
Expand Down Expand Up @@ -220,15 +220,13 @@ void draw_dpad_and_menu_utilities() {
if (z64_file.items[Z64_SLOT_CHILD_TRADE] >= Z64_ITEM_WEIRD_EGG && z64_file.items[Z64_SLOT_CHILD_TRADE] <= Z64_ITEM_MASK_OF_TRUTH && z64_file.link_age == 1) {
if (!CAN_USE_DPAD || !CAN_USE_CHILD_TRADE) {
gDPSetPrimColor(db->p++, 0, 0, 0xFF, 0xFF, 0xFF, alpha * 0x46 / 0xFF);
}
else {
} else {
gDPSetPrimColor(db->p++, 0, 0, 0xFF, 0xFF, 0xFF, alpha);
}
sprite_load(db, &items_sprite, z64_file.items[Z64_SLOT_CHILD_TRADE], 1);
if (z64_link.current_mask >= 1 && z64_link.current_mask <= 9) {
sprite_draw(db, &items_sprite, 0, left_main_dpad + 12, top_main_dpad, 16, 16);
}
else {
} else {
sprite_draw(db, &items_sprite, 0, left_main_dpad + 14, top_main_dpad + 2, 12, 12);
}
}
Expand All @@ -247,4 +245,3 @@ void draw_dpad_and_menu_utilities() {
gDPPipeSync(db->p++);
}
}

Loading

0 comments on commit d203790

Please sign in to comment.