diff --git a/Makefile b/Makefile index 05d6da5f..790762c3 100644 --- a/Makefile +++ b/Makefile @@ -558,7 +558,11 @@ endif CC_CHECK += -DCOOP CFLAGS += -DCOOP -# Check for enhancement options +# Enforce -Werror in debug mode +ifeq ($(DEBUG),1) + CC_CHECK += -Werror -Wno-error=unused-variable -Wno-error=unused-parameter + CFLAGS += -Werror -Wno-error=unused-variable -Wno-error=unused-parameter +endif # Check for debug option ifeq ($(DEBUG),1) @@ -566,6 +570,8 @@ ifeq ($(DEBUG),1) CFLAGS += -DDEBUG endif +# Check for enhancement options + # Check for immediate load option ifeq ($(IMMEDIATELOAD),1) CC_CHECK += -DIMMEDIATELOAD diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index a19667f3..4e50cc54 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -15,6 +15,7 @@ #include "game/object_list_processor.h" #include "surface_load.h" #include "game/game_init.h" +#include "engine/math_util.h" s32 unused8038BE90; diff --git a/src/game/area.c b/src/game/area.c index 9fd492b1..68c42149 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -21,8 +21,8 @@ #include "engine/geo_layout.h" #include "save_file.h" #include "level_table.h" - #include "gfx_dimensions.h" +#include "game/ingame_menu.h" struct SpawnInfo gPlayerSpawnInfos[MAX_PLAYERS]; struct GraphNode *D_8033A160[0x100]; diff --git a/src/game/behavior_actions.c b/src/game/behavior_actions.c index 21d45976..deca25d9 100644 --- a/src/game/behavior_actions.c +++ b/src/game/behavior_actions.c @@ -1,5 +1,6 @@ #include +#include "src/pc/network/network.h" #include "types.h" #include "actors/common1.h" #include "actors/group12.h" @@ -43,7 +44,6 @@ #include "spawn_object.h" #include "spawn_sound.h" #include "thread6.h" -#include "src/pc/network/network.h" #define o gCurrentObject diff --git a/src/game/behaviors/bbh_tilting_trap.inc.c b/src/game/behaviors/bbh_tilting_trap.inc.c index 63c01d00..ae6544f6 100644 --- a/src/game/behaviors/bbh_tilting_trap.inc.c +++ b/src/game/behaviors/bbh_tilting_trap.inc.c @@ -36,7 +36,7 @@ void bhv_bbh_tilting_trap_platform_loop(void) { y /= (f32)playersTouched; z /= (f32)playersTouched; distanceToPlayer = dist_between_object_and_point(o, x, y, z); - angleToPlayer = obj_angle_to_point(o, x, y, z); + angleToPlayer = obj_angle_to_point(o, x, z); } // US (and probably later) versions use oAction for the diff --git a/src/game/behaviors/boo.inc.c b/src/game/behaviors/boo.inc.c index 36b7b25e..7082fa86 100644 --- a/src/game/behaviors/boo.inc.c +++ b/src/game/behaviors/boo.inc.c @@ -730,8 +730,12 @@ static void (*sBooGivingStarActions[])(void) = { big_boo_act_4 }; -u8 big_boo_ignore_update(void) { - return cur_obj_has_behavior(bhvGhostHuntBigBoo) && !bigBooActivated; +u8 big_boo_ignore_update(struct Object* obj) { + struct Object* tmp = gCurrentObject; + gCurrentObject = obj; + u8 rc = cur_obj_has_behavior(bhvGhostHuntBigBoo) && !bigBooActivated; + gCurrentObject = tmp; + return rc; } void bhv_big_boo_loop(void) { @@ -740,7 +744,7 @@ void bhv_big_boo_loop(void) { bigBooActivated = FALSE; struct SyncObject* so = boo_network_init_object(); so->syncDeathEvent = FALSE; - so->ignore_if_true = big_boo_ignore_update; + so->ignore_if_true = &big_boo_ignore_update; } } else if (o->oHealth <= 0) { if (network_sync_object_initialized(o)) { diff --git a/src/game/behaviors/bowser_bomb.inc.c b/src/game/behaviors/bowser_bomb.inc.c index 97c7b215..e62eae06 100644 --- a/src/game/behaviors/bowser_bomb.inc.c +++ b/src/game/behaviors/bowser_bomb.inc.c @@ -1,6 +1,6 @@ // bowser_bomb.c.inc -static s32 networkBowserBombHit = 0; +static u32 networkBowserBombHit = 0; static void bhv_bowser_bomb_hit_player(void) { if (networkBowserBombHit == 0) { diff --git a/src/game/behaviors/chain_chomp.inc.c b/src/game/behaviors/chain_chomp.inc.c index 4e93d53f..2eb94737 100644 --- a/src/game/behaviors/chain_chomp.inc.c +++ b/src/game/behaviors/chain_chomp.inc.c @@ -30,7 +30,7 @@ static struct ObjectHitbox sChainChompHitbox = { void bhv_chain_chomp_chain_part_update(void) { struct ChainSegment *segment; - if (o->parentObj->behavior != &bhvChainChomp || o->parentObj->oAction == CHAIN_CHOMP_ACT_UNLOAD_CHAIN) { + if (o->parentObj->behavior != (BehaviorScript*)&bhvChainChomp || o->parentObj->oAction == CHAIN_CHOMP_ACT_UNLOAD_CHAIN) { obj_mark_for_deletion(o); } else if (o->oBehParams2ndByte != CHAIN_CHOMP_CHAIN_PART_BP_PIVOT) { segment = &o->parentObj->oChainChompSegments[o->oBehParams2ndByte]; @@ -480,7 +480,7 @@ static void chain_chomp_act_unload_chain(void) { if (o->oChainChompReleaseStatus != CHAIN_CHOMP_NOT_RELEASED) { for (u8 i = 0; i < 5; i++) { - obj_mark_for_deletion(&o->oChainChompSegments[i]); + obj_mark_for_deletion((struct Object*)&o->oChainChompSegments[i]); } obj_mark_for_deletion(o); obj_mark_for_deletion(o->parentObj); diff --git a/src/game/behaviors/elevator.inc.c b/src/game/behaviors/elevator.inc.c index 3b4de8ff..ca2d82e7 100644 --- a/src/game/behaviors/elevator.inc.c +++ b/src/game/behaviors/elevator.inc.c @@ -91,7 +91,6 @@ void elevator_act_2(void) { // Pretty similar code to action 1 void elevator_act_4(void) { struct MarioState* marioState = nearest_mario_state_to_object(o); - struct Object* player = marioState->marioObj; o->oVelY = 0; if (o->oTimer == 0) { @@ -108,7 +107,6 @@ void elevator_act_4(void) { void elevator_act_3(void) // nearly identical to action 2 { struct MarioState* marioState = nearest_mario_state_to_object(o); - struct Object* player = marioState->marioObj; o->oVelY = 0; if (o->oTimer == 0) { @@ -136,7 +134,7 @@ void bhv_elevator_init(void) { o->oElevatorUnk100 = 2; } - struct SyncObject* so = network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS); + network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS); network_init_object_field(o, &o->oAction); network_init_object_field(o, &o->oPosY); network_init_object_field(o, &o->oVelY); diff --git a/src/game/behaviors/falling_pillar.inc.c b/src/game/behaviors/falling_pillar.inc.c index 46e90ee9..fc75995d 100644 --- a/src/game/behaviors/falling_pillar.inc.c +++ b/src/game/behaviors/falling_pillar.inc.c @@ -61,7 +61,6 @@ s16 bhv_falling_pillar_calculate_angle_in_front_of_mario(void) { */ void bhv_falling_pillar_loop(void) { struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); int angleToPlayer = obj_angle_to_object(o, player); s16 angleInFrontOfMario; diff --git a/src/game/behaviors/fish.inc.c b/src/game/behaviors/fish.inc.c index 7ad3552e..e69b14af 100644 --- a/src/game/behaviors/fish.inc.c +++ b/src/game/behaviors/fish.inc.c @@ -46,6 +46,9 @@ void fish_act_spawn(void) { struct Object* player = nearest_player_to_object(o); int distanceToPlayer = dist_between_objects(o, player); if (distanceToPlayer < minDistToMario || gCurrLevelNum == LEVEL_SA) { +#else + // get rid of warning + minDistToMario = minDistToMario; #endif for (i = 0; i < schoolQuantity; i++) { fishObject = spawn_object(o, model, bhvFish); diff --git a/src/game/behaviors/flying_bookend_switch.inc.c b/src/game/behaviors/flying_bookend_switch.inc.c index c819962f..09198b6e 100644 --- a/src/game/behaviors/flying_bookend_switch.inc.c +++ b/src/game/behaviors/flying_bookend_switch.inc.c @@ -163,7 +163,7 @@ void bookshelf_manager_act_0(void) { //if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { for (val04 = 0; val04 < 3; val04++) { - struct Object* book = spawn_object_relative(val04, D_80331B30[val04].unk00, D_80331B30[val04].unk02, 0, o, MODEL_BOOKEND, bhvBookSwitch); + spawn_object_relative(val04, D_80331B30[val04].unk00, D_80331B30[val04].unk02, 0, o, MODEL_BOOKEND, bhvBookSwitch); } o->oAction = 1; @@ -185,7 +185,6 @@ void bookshelf_manager_act_1(void) { } void bookshelf_manager_act_2(void) { - struct MarioState* marioState = nearest_mario_state_to_object(o); if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { if (o->oBookSwitchManagerUnkF4 < 0) { if (o->oTimer > 30) { @@ -224,7 +223,6 @@ void bookshelf_manager_act_2(void) { } void bookshelf_manager_act_3(void) { - struct MarioState* marioState = nearest_mario_state_to_object(o); if (o->oTimer > 85) { if (networkType == NT_SERVER) { o->oAction = 4; @@ -237,7 +235,6 @@ void bookshelf_manager_act_3(void) { } void bookshelf_manager_act_4(void) { - struct MarioState* marioState = nearest_mario_state_to_object(o); if (o->oBookSwitchManagerUnkF4 >= 3) { obj_mark_for_deletion(o); } else if (networkType == NT_SERVER) { @@ -296,7 +293,6 @@ void bhv_book_switch_loop(void) { struct MarioState* marioState = nearest_mario_state_to_object(o); struct Object* player = marioState->marioObj; int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); o->header.gfx.scale[0] = 2.0f; o->header.gfx.scale[1] = 0.9f; diff --git a/src/game/behaviors/goomba.inc.c b/src/game/behaviors/goomba.inc.c index 3a1ca208..2a9e66e4 100644 --- a/src/game/behaviors/goomba.inc.c +++ b/src/game/behaviors/goomba.inc.c @@ -74,7 +74,6 @@ void bhv_goomba_triplet_spawner_update(void) { s32 dAngle; s16 dx; s16 dz; - struct Object* player = nearest_player_to_object(o); // If mario is close enough and the goombas aren't currently loaded, then // spawn them diff --git a/src/game/behaviors/koopa.inc.c b/src/game/behaviors/koopa.inc.c index 59a19568..b90cec64 100644 --- a/src/game/behaviors/koopa.inc.c +++ b/src/game/behaviors/koopa.inc.c @@ -445,7 +445,6 @@ static void koopa_unshelled_act_dive(void) { struct Object* player = nearest_player_to_object(o); int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); // If we got the shell and mario didn't, put on the shell //! The shell comes after koopa in processing order, and the shell is diff --git a/src/game/behaviors/mr_blizzard.inc.c b/src/game/behaviors/mr_blizzard.inc.c index 88921f6e..4a2b08e4 100644 --- a/src/game/behaviors/mr_blizzard.inc.c +++ b/src/game/behaviors/mr_blizzard.inc.c @@ -234,7 +234,6 @@ static void mr_blizzard_act_rotate(void) { static void mr_blizzard_act_death(void) { struct Object* player = nearest_player_to_object(o); int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); cur_obj_become_intangible(); struct Object *cap; diff --git a/src/game/behaviors/seesaw_platform.inc.c b/src/game/behaviors/seesaw_platform.inc.c index f28930fc..80c21e06 100644 --- a/src/game/behaviors/seesaw_platform.inc.c +++ b/src/game/behaviors/seesaw_platform.inc.c @@ -59,7 +59,7 @@ void bhv_seesaw_platform_update(void) { z /= (f32)playersTouched; int distanceToPlayer = dist_between_object_and_point(o, x, y, z); - int angleToPlayer = obj_angle_to_point(o, x, y, z); + int angleToPlayer = obj_angle_to_point(o, x, z); // Rotate toward mario f32 rotation = distanceToPlayer * coss(angleToPlayer - o->oMoveAngleYaw); diff --git a/src/game/behaviors/tuxie.inc.c b/src/game/behaviors/tuxie.inc.c index 71eada26..9b684adc 100644 --- a/src/game/behaviors/tuxie.inc.c +++ b/src/game/behaviors/tuxie.inc.c @@ -226,7 +226,6 @@ void small_penguin_act_4(void) { void small_penguin_act_0(void) { struct Object* player = nearest_player_to_object(o); int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); s32 sp1C; diff --git a/src/game/envfx_bubbles.c b/src/game/envfx_bubbles.c index ee1b029d..22e4ebce 100644 --- a/src/game/envfx_bubbles.c +++ b/src/game/envfx_bubbles.c @@ -10,6 +10,7 @@ #include "engine/behavior_script.h" #include "audio/external.h" #include "textures.h" +#include "game/rendering_graph_node.h" /** * This file implements environment effects that are not snow: diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index a4d89509..1e01c1f5 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -1,4 +1,5 @@ #include +#include #include "actors/common1.h" #include "area.h" @@ -411,7 +412,7 @@ void render_multi_text_string(s16 *xPos, s16 *yPos, s8 multiTextID) } #endif -void str_ascii_to_dialog(char* string, char* dialog, int length) { +void str_ascii_to_dialog(const char* string, u8* dialog, u16 length) { for (int i = 0; i < length; i++) { switch (string[i]) { case '\'': dialog[i] = 0x3E; break; @@ -435,7 +436,7 @@ void str_ascii_to_dialog(char* string, char* dialog, int length) { dialog[length] = DIALOG_CHAR_TERMINATOR; } -void print_generic_ascii_string(s16 x, s16 y, const u8* ascii) { +void print_generic_ascii_string(s16 x, s16 y, const char* ascii) { u8 dialog[256] = { DIALOG_CHAR_TERMINATOR }; str_ascii_to_dialog(ascii, dialog, strlen(ascii)); print_generic_string(x, y, dialog); diff --git a/src/game/ingame_menu.h b/src/game/ingame_menu.h index ccab3a1e..958919e0 100644 --- a/src/game/ingame_menu.h +++ b/src/game/ingame_menu.h @@ -116,8 +116,8 @@ extern s8 gRedCoinsCollected; void create_dl_identity_matrix(void); void create_dl_translation_matrix(s8 pushOp, f32 x, f32 y, f32 z); void create_dl_ortho_matrix(void); -void str_ascii_to_dialog(char* string, char* dialog, int length); -void print_generic_ascii_string(s16 x, s16 y, const u8* ascii); +void str_ascii_to_dialog(const char* string, u8* dialog, u16 length); +void print_generic_ascii_string(s16 x, s16 y, const char* ascii); void print_generic_string(s16 x, s16 y, const u8 *str); void print_hud_lut_string(s8 hudLUT, s16 x, s16 y, const u8 *str); void print_menu_generic_string(s16 x, s16 y, const u8 *str); @@ -149,5 +149,6 @@ void do_cutscene_handler(void); void render_hud_cannon_reticle(void); void reset_red_coins_collected(void); s16 render_menus_and_dialogs(void); +s16 render_sync_level_screen(void); #endif // INGAME_MENU_H diff --git a/src/game/interaction.c b/src/game/interaction.c index bd708378..b52baa8a 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -25,6 +25,8 @@ #include "sound_init.h" #include "thread6.h" +#include "pc/network/network.h" + #define INT_GROUND_POUND_OR_TWIRL (1 << 0) // 0x01 #define INT_PUNCH (1 << 1) // 0x02 #define INT_KICK (1 << 2) // 0x04 @@ -786,7 +788,7 @@ u32 interact_water_ring(struct MarioState *m, UNUSED u32 interactType, struct Ob u32 interact_star_or_key(struct MarioState *m, UNUSED u32 interactType, struct Object *o) { // only allow for local player - if (m != &gMarioStates[0]) { return; } + if (m != &gMarioStates[0]) { return FALSE; } u32 starIndex; u32 starGrabAction = ACT_STAR_DANCE_EXIT; @@ -1098,7 +1100,7 @@ u32 interact_door(struct MarioState *m, UNUSED u32 interactType, struct Object * } u32 interact_cannon_base(struct MarioState *m, UNUSED u32 interactType, struct Object *o) { - if (o->oAction != 0) { return; } + if (o->oAction != 0) { return FALSE; } if (m->action != ACT_IN_CANNON) { mario_stop_riding_and_holding(m); @@ -1121,7 +1123,7 @@ static void resolve_player_collision(struct MarioState* m, struct MarioState* m2 f32 marioRelY = localTorso[1] - remoteTorso[1]; if (marioRelY < 0) { marioRelY = -marioRelY; } - if (marioRelY >= extentY) { return FALSE; } + if (marioRelY >= extentY) { return; } f32 marioRelX = localTorso[0] - remoteTorso[0]; @@ -1643,7 +1645,7 @@ u32 interact_pole(struct MarioState *m, UNUSED u32 interactType, struct Object * u32 interact_hoot(struct MarioState *m, UNUSED u32 interactType, struct Object *o) { s32 actionId = m->action & ACT_ID_MASK; - if (m != &gMarioStates[0]) { return; } + if (m != &gMarioStates[0]) { return FALSE; } //! Can pause to advance the global timer without falling too far, allowing // you to regrab after letting go. @@ -1665,7 +1667,7 @@ u32 interact_hoot(struct MarioState *m, UNUSED u32 interactType, struct Object * u32 interact_cap(struct MarioState *m, UNUSED u32 interactType, struct Object *o) { // only allow for local - if (m != &gMarioStates[0]) { return; } + if (m != &gMarioStates[0]) { return FALSE; } u32 capFlag = get_mario_cap_flag(o); u16 capMusic = 0; diff --git a/src/game/level_geo.c b/src/game/level_geo.c index abc51213..19e009d0 100644 --- a/src/game/level_geo.c +++ b/src/game/level_geo.c @@ -13,7 +13,7 @@ * Geo function that generates a displaylist for environment effects such as * snow or jet stream bubbles. */ -Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf) { +Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtxf) { Vec3s marioPos; Vec3s camFrom; Vec3s camTo; diff --git a/src/game/mario.c b/src/game/mario.c index de02da8b..5393d4c6 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -40,6 +40,7 @@ #include "pc/configfile.h" #include "pc/cheats.h" #include "pc/network/network.h" +#include "pc/logfile.h" #ifdef BETTERCAMERA #include "bettercamera.h" #endif diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index f31f6fa8..64f8ed55 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -18,6 +18,7 @@ #include "bettercamera.h" #endif #include "behavior_table.h" +#include "object_helpers.h" void play_flip_sounds(struct MarioState *m, s16 frame1, s16 frame2, s16 frame3) { s32 animFrame = m->marioObj->header.gfx.unk38.animFrame; diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index 2afbd16d..e9c0f3b1 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -16,6 +16,7 @@ #include "camera.h" #include "level_table.h" #include "thread6.h" +#include "object_helpers.h" #define POLE_NONE 0 #define POLE_TOUCHED_FLOOR 1 @@ -769,7 +770,7 @@ s32 act_in_cannon(struct MarioState *m) { } s32 act_tornado_twirling(struct MarioState *m) { - if (m->usedObj = NULL) { return; } + if (m->usedObj == NULL) { return FALSE; } struct Surface *floor; Vec3f nextPos; diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index daa4e2a2..9f5c800f 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -377,7 +377,7 @@ s32 set_mario_npc_dialog(struct MarioState* m, s32 actionArg) { } else if (actionArg != 0 && mario_ready_to_speak(m)) { m->usedObj = gCurrentObject; set_mario_action(m, ACT_READING_NPC_DIALOG, actionArg); - if (m->playerIndex == 0) { localDialogNPCBehavior = m->usedObj->behavior; } + if (m->playerIndex == 0) { localDialogNPCBehavior = (BehaviorScript*)m->usedObj->behavior; } dialogState = 1; // starting dialog } diff --git a/src/game/mario_actions_object.c b/src/game/mario_actions_object.c index 56543ce3..e506467c 100644 --- a/src/game/mario_actions_object.c +++ b/src/game/mario_actions_object.c @@ -12,6 +12,7 @@ #include "thread6.h" #include "behavior_data.h" #include "pc/network/network.h" +#include "object_helpers.h" /** * Used by act_punching() to determine Mario's forward velocity during each diff --git a/src/game/mario_step.c b/src/game/mario_step.c index ba8315ca..fe67ff11 100644 --- a/src/game/mario_step.c +++ b/src/game/mario_step.c @@ -14,6 +14,7 @@ static s16 sMovingSandSpeeds[] = { 12, 8, 4, 0 }; struct Surface gWaterSurfacePseudoFloor = { SURFACE_VERY_SLIPPERY, 0, 0, 0, 0, 0, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0.0f, 1.0f, 0.0f }, 0.0f, NULL, + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }; /** diff --git a/src/game/obj_behaviors.c b/src/game/obj_behaviors.c index 0952a5d6..eed6f68b 100644 --- a/src/game/obj_behaviors.c +++ b/src/game/obj_behaviors.c @@ -556,12 +556,12 @@ s32 is_point_close_to_object(struct Object *obj, f32 x, f32 y, f32 z, s32 dist) /** * Sets an object as visible if within a certain distance of Mario's graphical position. */ -void set_object_visibility(struct Object *obj, s32 dist) { +void set_object_visibility(struct Object *obj, UNUSED s32 dist) { +#ifndef NODRAWINGDISTANCE f32 objX = obj->oPosX; f32 objY = obj->oPosY; f32 objZ = obj->oPosZ; -#ifndef NODRAWINGDISTANCE if (is_point_within_radius_of_mario(objX, objY, objZ, dist) == TRUE) { #endif obj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; diff --git a/src/game/obj_behaviors.h b/src/game/obj_behaviors.h index 0fee830d..36095cb5 100644 --- a/src/game/obj_behaviors.h +++ b/src/game/obj_behaviors.h @@ -161,5 +161,6 @@ void bhv_free_bowling_ball_loop(void); /* likely unused */ void bhv_rr_cruiser_wing_init(void); void bhv_rr_cruiser_wing_loop(void); struct Object* spawn_default_star(f32 sp20, f32 sp24, f32 sp28); - +struct MarioState* nearest_mario_state_to_object(struct Object* obj); +struct Object* nearest_player_to_object(struct Object* obj); #endif // OBJ_BEHAVIORS_H diff --git a/src/game/object_collision.c b/src/game/object_collision.c index 900a0a5a..d7676b7e 100644 --- a/src/game/object_collision.c +++ b/src/game/object_collision.c @@ -23,8 +23,8 @@ struct Object *debug_print_obj_collision(struct Object *a) { } int detect_player_hitbox_overlap(struct MarioState* local, struct MarioState* remote) { - if (local->marioObj == NULL || local->marioObj->oIntangibleTimer != 0) { return; } - if (remote->marioObj == NULL || remote->marioObj->oIntangibleTimer != 0) { return; } + if (local->marioObj == NULL || local->marioObj->oIntangibleTimer != 0) { return FALSE; } + if (remote->marioObj == NULL || remote->marioObj->oIntangibleTimer != 0) { return FALSE; } struct Object* a = local->marioObj; f32* aTorso = local->marioBodyState->torsoPos; @@ -45,16 +45,16 @@ int detect_player_hitbox_overlap(struct MarioState* local, struct MarioState* re f32 sp1C = b->hitboxHeight + sp38; if (sp3C > sp1C) { - return 0; + return FALSE; } if (sp20 < sp38) { - return 0; + return FALSE; } if (a->numCollidedObjs >= 4) { - return 0; + return FALSE; } if (b->numCollidedObjs >= 4) { - return 0; + return FALSE; } a->collidedObjs[a->numCollidedObjs] = b; b->collidedObjs[b->numCollidedObjs] = a; @@ -62,10 +62,11 @@ int detect_player_hitbox_overlap(struct MarioState* local, struct MarioState* re b->collidedObjInteractTypes |= a->oInteractType; a->numCollidedObjs++; b->numCollidedObjs++; - return 1; + return TRUE; } //! no return value + return FALSE; } int detect_object_hitbox_overlap(struct Object *a, struct Object *b) { diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index ecadbf10..7eead6f5 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -408,7 +408,7 @@ s16 obj_angle_to_object(struct Object *obj1, struct Object *obj2) { return angle; } -s16 obj_angle_to_point(struct Object *obj, f32 pointX, f32 pointY, f32 pointZ) { +s16 obj_angle_to_point(struct Object *obj, f32 pointX, f32 pointZ) { f32 z1, x1, z2, x2; s16 angle; @@ -1166,7 +1166,7 @@ void cur_obj_get_thrown_or_placed(f32 forwardVel, f32 velY, s32 thrownAction) { cur_obj_move_after_thrown_or_dropped(forwardVel, velY); } - if (o->oSyncID != NULL && syncObjects[o->oSyncID].owned) { + if (o->oSyncID != 0 && syncObjects[o->oSyncID].owned) { network_send_object(o); } } @@ -1178,7 +1178,7 @@ void cur_obj_get_dropped(void) { o->oHeldState = HELD_FREE; cur_obj_move_after_thrown_or_dropped(0.0f, 0.0f); - if (o->oSyncID != NULL && syncObjects[o->oSyncID].owned) { + if (o->oSyncID != 0 && syncObjects[o->oSyncID].owned) { network_send_object(o); } } @@ -2674,7 +2674,7 @@ s32 cur_obj_can_mario_activate_textbox_2(struct MarioState* m, f32 radius, f32 h } static void cur_obj_end_dialog(struct MarioState* m, s32 dialogFlags, s32 dialogResult) { - if (m->playerIndex != 0) { return 0; } + if (m->playerIndex != 0) { return; } o->oDialogResponse = dialogResult; o->oDialogState++; diff --git a/src/game/object_helpers.h b/src/game/object_helpers.h index 6b1ada53..23a39010 100644 --- a/src/game/object_helpers.h +++ b/src/game/object_helpers.h @@ -92,7 +92,7 @@ f32 approach_f32_symmetric(f32 value, f32 target, f32 increment); s16 approach_s16_symmetric(s16 value, s16 target, s16 increment); s32 cur_obj_rotate_yaw_toward(s16 target, s16 increment); s16 obj_angle_to_object(struct Object *obj1, struct Object *obj2); -s16 obj_angle_to_point(struct Object *obj, f32 pointX, f32 pointY, f32 pointZ); +s16 obj_angle_to_point(struct Object *obj, f32 pointX, f32 pointZ); s16 obj_turn_toward_object(struct Object *obj, struct Object *target, s16 angleIndex, s16 turnAmount); void obj_set_parent_relative_pos(struct Object *obj, s16 relX, s16 relY, s16 relZ); void obj_set_pos(struct Object *obj, s16 x, s16 y, s16 z); @@ -299,6 +299,8 @@ void enable_time_stop_including_mario(void); void disable_time_stop_including_mario(void); s32 cur_obj_check_interacted(void); void cur_obj_spawn_loot_blue_coin(void); +s32 cur_obj_is_any_player_on_platform(void); +f32 cur_obj_lateral_dist_from_obj_to_home(struct Object* obj); #ifndef VERSION_JP void cur_obj_spawn_star_at_y_offset(f32 targetX, f32 targetY, f32 targetZ, f32 offsetY); diff --git a/src/game/object_list_processor.c b/src/game/object_list_processor.c index 440ccc29..a95826d1 100644 --- a/src/game/object_list_processor.c +++ b/src/game/object_list_processor.c @@ -20,6 +20,7 @@ #include "profiler.h" #include "spawn_object.h" #include "engine/math_util.h" +#include "pc/network/network.h" /** * Flags controlling what debug info is displayed. diff --git a/src/game/rendering_graph_node.h b/src/game/rendering_graph_node.h index 097c7876..cf1e1798 100644 --- a/src/game/rendering_graph_node.h +++ b/src/game/rendering_graph_node.h @@ -29,5 +29,7 @@ extern u16 gAreaUpdateCounter; void geo_process_node_and_siblings(struct GraphNode *firstNode); void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor); +void interpolate_vectors(Vec3f res, Vec3f a, Vec3f b); +void interpolate_vectors_s16(Vec3s res, Vec3s a, Vec3s b); #endif // RENDERING_GRAPH_NODE_H diff --git a/src/game/thread6.c b/src/game/thread6.c index c78a807f..c30d802f 100644 --- a/src/game/thread6.c +++ b/src/game/thread6.c @@ -4,6 +4,7 @@ #include "buffers/buffers.h" #include "main.h" #include "thread6.h" +#include "object_helpers.h" static s8 D_SH_8030CCB4; static s32 sUnusedDisableRumble; diff --git a/src/goddard/debug_utils.c b/src/goddard/debug_utils.c index 10984bbb..e87150a5 100644 --- a/src/goddard/debug_utils.c +++ b/src/goddard/debug_utils.c @@ -411,7 +411,7 @@ void fatal_printf(const char *fmt, ...) { gd_printf("%s", va_arg(vl, char *)); break; case 'c': - gd_printf("%c", va_arg(vl, char)); + gd_printf("%c", va_arg(vl, int)); break; case 'x': gd_printf("%x", va_arg(vl, s32)); diff --git a/src/menu/file_select.c b/src/menu/file_select.c index 8a27113d..4ca0454e 100644 --- a/src/menu/file_select.c +++ b/src/menu/file_select.c @@ -21,6 +21,7 @@ #include "sm64.h" #include "text_strings.h" +#include "game/ingame_menu.h" #include "pc/controller/controller_keyboard.h" #include "pc/network/network.h" @@ -371,6 +372,169 @@ static void bhv_menu_button_growing_from_main_menu(struct Object *button) { } } +// ---------------------------------------- // +// ------- custom network menu code ------- // +// ---------------------------------------- // + +void exit_join_to_network_menu(void) { + // Begin exit + if (sMainMenuButtons[MENU_BUTTON_JOIN]->oMenuButtonState == MENU_BUTTON_STATE_FULLSCREEN + && sCursorClickingTimer == 2) { + play_sound(SOUND_MENU_CAMERA_ZOOM_OUT, gDefaultSoundArgs); + sMainMenuButtons[MENU_BUTTON_JOIN]->oMenuButtonState = MENU_BUTTON_STATE_SHRINKING; + keyboard_stop_text_input(); + } + // End exit + if (sMainMenuButtons[MENU_BUTTON_JOIN]->oMenuButtonState == MENU_BUTTON_STATE_DEFAULT) { + sSelectedButtonID = MENU_BUTTON_NETWORK_MODE; + if (sCurrentMenuLevel == MENU_LAYER_SUBMENU) { + sCurrentMenuLevel = MENU_LAYER_MAIN; + } + } +} + +void keyboard_exit_join_to_network_menu(void) { + sCursorClickingTimer = 2; + exit_join_to_network_menu(); +} + +void join_server_as_client(void) { + sCursorClickingTimer = 2; + char delims[] = { ' ' }; + + // trim whitespace + char* text = textInput; + while (*text == ' ') { text++; } + + // grab IP + char* ip = strtok(text, delims); + if (ip == NULL) { + exit_join_to_network_menu(); + return; + } + + // grab port + char* port = strtok(NULL, delims); + if (port != NULL && atoi(port) == 0) { + exit_join_to_network_menu(); + return; + } + + network_init(NT_CLIENT, textInput, port); + sSelectedFileNum = 1; +} + +void render_network_mode_menu_buttons(struct Object* soundModeButton) { +#define NETWORK_BUTTON_Y 0 + // Host option button + sMainMenuButtons[MENU_BUTTON_HOST] = spawn_object_rel_with_rot( + soundModeButton, MODEL_MAIN_MENU_MARIO_NEW_BUTTON, bhvMenuButton, 266, NETWORK_BUTTON_Y, -100, 0, -0x8000, 0); + sMainMenuButtons[MENU_BUTTON_HOST]->oMenuButtonScale = 0.11111111f; + sMainMenuButtons[MENU_BUTTON_HOST]->oFaceAngleRoll = 0; + + // Join option button + sMainMenuButtons[MENU_BUTTON_JOIN] = spawn_object_rel_with_rot( + soundModeButton, MODEL_MAIN_MENU_MARIO_NEW_BUTTON, bhvMenuButton, -266, NETWORK_BUTTON_Y, -100, 0, -0x8000, 0); + sMainMenuButtons[MENU_BUTTON_JOIN]->oMenuButtonScale = 0.11111111f; + sMainMenuButtons[MENU_BUTTON_JOIN]->oFaceAngleRoll = 0; +} + +void check_network_mode_menu_clicked_buttons(struct Object* networkModeButton) { + if (networkModeButton->oMenuButtonState == MENU_BUTTON_STATE_FULLSCREEN) { + s32 buttonID; + // Configure sound mode menu button group + for (buttonID = MENU_BUTTON_NETWORK_MIN; buttonID < MENU_BUTTON_NETWORK_MAX; buttonID++) { + s16 buttonX = sMainMenuButtons[buttonID]->oPosX; + s16 buttonY = sMainMenuButtons[buttonID]->oPosY; + + if (check_clicked_button(buttonX, buttonY, 22.0f) == TRUE) { + if (buttonID == MENU_BUTTON_HOST) { + if (networkModeButton->oMenuButtonActionPhase == SOUND_MODE_PHASE_MAIN) { + play_sound(SOUND_MENU_CLICK_FILE_SELECT, gDefaultSoundArgs); + sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN_OUT; + sSelectedButtonID = buttonID; + //sSoundMode = buttonID - MENU_BUTTON_OPTION_MIN; + } + } + else if (buttonID == MENU_BUTTON_JOIN) { + play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gDefaultSoundArgs); + sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_GROWING; + sSelectedButtonID = buttonID; + keyboard_start_text_input(TIM_IP, keyboard_exit_join_to_network_menu, join_server_as_client); + } + sCurrentMenuLevel = MENU_LAYER_SUBMENU; + + break; + } + } + } +} + +void print_network_mode_menu_strings(void) { + s32 mode; + s16 textX; +#define HEADER_HUD_X 106 + unsigned char textHeader[10]; + str_ascii_to_dialog("SM64 COOP", textHeader, 9); + + // Print header text + gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); + gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, sTextBaseAlpha); + + print_hud_lut_string(HUD_LUT_DIFF, HEADER_HUD_X, 35, textHeader); + + gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end); + + gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); + +#define TEXT_HOST 0x11,0x18,0x1C,0x1D,0xFF +#define TEXT_JOIN 0x13,0x18,0x12,0x17,0xFF + static unsigned char textNetworkModes[][5] = { { TEXT_HOST }, { TEXT_JOIN } }; + + // Print network mode names + for (mode = 0; mode < 2; mode++) { + gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, sTextBaseAlpha); + + textX = get_str_x_pos_from_center(mode * 72 + 124, textNetworkModes[mode], 10.0f); + print_generic_string(textX, 87, textNetworkModes[mode]); + } + + gSPDisplayList(gDisplayListHead++, dl_ia_text_end); +} + +void print_join_mode_menu_strings(void) { +#define JOIN_MARIO_X 25 +#define JOIN_FILE_LETTER_X 95 +#define JOIN_LEVEL_NAME_X 25 +#define JOIN_SECRET_STARS_X 171 +#define JOIN_MYSCORE_X 238 +#define JOIN_HISCORE_X 231 + + unsigned char textMario[8]; + str_ascii_to_dialog("CONNECT", textMario, 7); + + // Print file name at top + gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); + gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, sTextBaseAlpha); + print_hud_lut_string(HUD_LUT_DIFF, JOIN_MARIO_X, 15, textMario); + + // Print course scores + gSPDisplayList(gDisplayListHead++, dl_menu_ia8_text_begin); + gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, sTextBaseAlpha); + + // Print level name + print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 0), "Type or paste the host's IP."); + print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 2), textInput); + + if (strlen(textInput) > 0) { + print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 14), "Press (ENTER) to join."); + } + + gSPDisplayList(gDisplayListHead++, dl_menu_ia8_text_end); +} + +// ---------------------------------------- // + /** * Shrink back to main menu, used to return back while inside menus. */ @@ -2935,164 +3099,3 @@ s32 lvl_update_obj_and_load_file_selected(UNUSED s32 arg, UNUSED s32 unused) { area_update_objects(); return sSelectedFileNum; } - -// --- custom network menu code --- // - -void exit_join_to_network_menu(void) { - // Begin exit - if (sMainMenuButtons[MENU_BUTTON_JOIN]->oMenuButtonState == MENU_BUTTON_STATE_FULLSCREEN - && sCursorClickingTimer == 2) { - play_sound(SOUND_MENU_CAMERA_ZOOM_OUT, gDefaultSoundArgs); - sMainMenuButtons[MENU_BUTTON_JOIN]->oMenuButtonState = MENU_BUTTON_STATE_SHRINKING; - keyboard_stop_text_input(); - } - // End exit - if (sMainMenuButtons[MENU_BUTTON_JOIN]->oMenuButtonState == MENU_BUTTON_STATE_DEFAULT) { - sSelectedButtonID = MENU_BUTTON_NETWORK_MODE; - if (sCurrentMenuLevel == MENU_LAYER_SUBMENU) { - sCurrentMenuLevel = MENU_LAYER_MAIN; - } - } -} - -void keyboard_exit_join_to_network_menu(void) { - sCursorClickingTimer = 2; - exit_join_to_network_menu(); -} - -void join_server_as_client(void) { - sCursorClickingTimer = 2; - char delims[] = { ' ' }; - - // trim whitespace - char* text = textInput; - while (*text == ' ') { text++; } - - // grab IP - char* ip = strtok(text, delims); - if (ip == NULL) { - exit_join_to_network_menu(); - return; - } - - // grab port - char* port = strtok(NULL, delims); - if (port != NULL && atoi(port) == 0) { - exit_join_to_network_menu(); - return; - } - - network_init(NT_CLIENT, textInput, port); - sSelectedFileNum = 1; -} - -void render_network_mode_menu_buttons(struct Object* soundModeButton) { - #define NETWORK_BUTTON_Y 0 - // Host option button - sMainMenuButtons[MENU_BUTTON_HOST] = spawn_object_rel_with_rot( - soundModeButton, MODEL_MAIN_MENU_MARIO_NEW_BUTTON, bhvMenuButton, 266, NETWORK_BUTTON_Y, -100, 0, -0x8000, 0); - sMainMenuButtons[MENU_BUTTON_HOST]->oMenuButtonScale = 0.11111111f; - sMainMenuButtons[MENU_BUTTON_HOST]->oFaceAngleRoll = 0; - - // Join option button - sMainMenuButtons[MENU_BUTTON_JOIN] = spawn_object_rel_with_rot( - soundModeButton, MODEL_MAIN_MENU_MARIO_NEW_BUTTON, bhvMenuButton, -266, NETWORK_BUTTON_Y, -100, 0, -0x8000, 0); - sMainMenuButtons[MENU_BUTTON_JOIN]->oMenuButtonScale = 0.11111111f; - sMainMenuButtons[MENU_BUTTON_JOIN]->oFaceAngleRoll = 0; -} - -void check_network_mode_menu_clicked_buttons(struct Object* networkModeButton) { - if (networkModeButton->oMenuButtonState == MENU_BUTTON_STATE_FULLSCREEN) { - s32 buttonID; - // Configure sound mode menu button group - for (buttonID = MENU_BUTTON_NETWORK_MIN; buttonID < MENU_BUTTON_NETWORK_MAX; buttonID++) { - s16 buttonX = sMainMenuButtons[buttonID]->oPosX; - s16 buttonY = sMainMenuButtons[buttonID]->oPosY; - - if (check_clicked_button(buttonX, buttonY, 22.0f) == TRUE) { - if (buttonID == MENU_BUTTON_HOST) { - if (networkModeButton->oMenuButtonActionPhase == SOUND_MODE_PHASE_MAIN) { - play_sound(SOUND_MENU_CLICK_FILE_SELECT, gDefaultSoundArgs); - sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN_OUT; - sSelectedButtonID = buttonID; - //sSoundMode = buttonID - MENU_BUTTON_OPTION_MIN; - } - } - else if (buttonID == MENU_BUTTON_JOIN) { - play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gDefaultSoundArgs); - sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_GROWING; - sSelectedButtonID = buttonID; - keyboard_start_text_input(TIM_IP, keyboard_exit_join_to_network_menu, join_server_as_client); - } - sCurrentMenuLevel = MENU_LAYER_SUBMENU; - - break; - } - } - } -} - -void print_network_mode_menu_strings(void) { - s32 mode; - s16 textX; - #define HEADER_HUD_X 106 - unsigned char textHeader[10]; - str_ascii_to_dialog("SM64 COOP", textHeader, 9); - - // Print header text - gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); - gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, sTextBaseAlpha); - - print_hud_lut_string(HUD_LUT_DIFF, HEADER_HUD_X, 35, textHeader); - - gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end); - - gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); - - #define TEXT_HOST 0x11,0x18,0x1C,0x1D,0xFF - #define TEXT_JOIN 0x13,0x18,0x12,0x17,0xFF - static unsigned char textNetworkModes[][5] = { { TEXT_HOST }, { TEXT_JOIN } }; - - // Print network mode names - for (mode = 0; mode < 2; mode++) { - gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, sTextBaseAlpha); - - textX = get_str_x_pos_from_center(mode * 72 + 124, textNetworkModes[mode], 10.0f); - print_generic_string(textX, 87, textNetworkModes[mode]); - } - - gSPDisplayList(gDisplayListHead++, dl_ia_text_end); -} - -void print_join_mode_menu_strings(void) { - #define JOIN_MARIO_X 25 - #define JOIN_FILE_LETTER_X 95 - #define JOIN_LEVEL_NAME_X 25 - #define JOIN_SECRET_STARS_X 171 - #define JOIN_MYSCORE_X 238 - #define JOIN_HISCORE_X 231 - - unsigned char textMario[8]; - str_ascii_to_dialog("CONNECT", textMario, 7); - - void** levelNameTable = segmented_to_virtual(seg2_course_name_table); - - // Print file name at top - gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); - gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, sTextBaseAlpha); - print_hud_lut_string(HUD_LUT_DIFF, JOIN_MARIO_X, 15, textMario); - - // Print course scores - gSPDisplayList(gDisplayListHead++, dl_menu_ia8_text_begin); - gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, sTextBaseAlpha); - - // Print level name - print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 0), "Type or paste the host's IP."); - print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 2), textInput); - - if (strlen(textInput) > 0) { - print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 14), "Press (ENTER) to join."); - } - - gSPDisplayList(gDisplayListHead++, dl_menu_ia8_text_end); -} diff --git a/src/menu/intro_geo.c b/src/menu/intro_geo.c index d823d40f..79566dd0 100644 --- a/src/menu/intro_geo.c +++ b/src/menu/intro_geo.c @@ -11,6 +11,7 @@ #include "prevent_bss_reordering.h" #include "gfx_dimensions.h" +#include "game/rendering_graph_node.h" // frame counts for the zoom in, hold, and zoom out of title model #define INTRO_STEPS_ZOOM_IN 20 diff --git a/src/menu/level_select_menu.c b/src/menu/level_select_menu.c index b48478d3..df8b1a6c 100644 --- a/src/menu/level_select_menu.c +++ b/src/menu/level_select_menu.c @@ -82,7 +82,7 @@ int start_demo(int timer) // if the next demo sequence ID is the count limit, reset it back to // the first sequence. - if((++gDemoInputListID_2) == gDemo.animDmaTable->count) + if((++gDemoInputListID_2) == (int)gDemo.animDmaTable->count) gDemoInputListID_2 = 0; gCurrDemoInput = ((struct DemoInput *) gDemo.targetAnim) + 1; // add 1 (+4) to the pointer to skip the demoID. diff --git a/src/menu/star_select.c b/src/menu/star_select.c index 6810e2fa..19e80000 100644 --- a/src/menu/star_select.c +++ b/src/menu/star_select.c @@ -19,6 +19,7 @@ #include "star_select.h" #include "text_strings.h" #include "prevent_bss_reordering.h" +#include "pc/network/network.h" /** * @file star_select.c diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 72903944..c3c7e3c5 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -3,6 +3,7 @@ #include "cheats.h" #include "pc_main.h" #include "platform.h" +#include "macros.h" #include #include @@ -25,7 +26,7 @@ static void print_help(void) { static inline int arg_string(const char *name, const char *value, char *target, int maxLength) { const unsigned int arglen = strlen(value); - if (arglen >= maxLength) { + if (arglen >= (unsigned int) maxLength) { fprintf(stderr, "Supplied value for `%s` is too long.\n", name); return 0; } @@ -34,7 +35,7 @@ static inline int arg_string(const char *name, const char *value, char *target, return 1; } -static inline int arg_uint(const char *name, const char *value, unsigned int *target) { +static inline int arg_uint(UNUSED const char *name, const char *value, unsigned int *target) { const unsigned long int v = strtoul(value, NULL, 0); *target = v; return 1; diff --git a/src/pc/controller/controller_keyboard.c b/src/pc/controller/controller_keyboard.c index efa6f9e6..1cc5d646 100644 --- a/src/pc/controller/controller_keyboard.c +++ b/src/pc/controller/controller_keyboard.c @@ -1,5 +1,6 @@ #include #include +#include #include "controller_api.h" @@ -11,7 +12,7 @@ #include "controller_keyboard.h" #include "pc/gfx/gfx_window_manager_api.h" -#include "pc/pc_main.h"" +#include "pc/pc_main.h" #include "engine/math_util.h" #define SCANCODE_BACKSPACE 0x0E @@ -182,7 +183,7 @@ void keyboard_on_text_input(char* text) { if (text == NULL) { return; } int i = strlen(textInput); - while (*text != NULL) { + while (*text != '\0') { // make sure we don't overrun the buffer if (i >= MAX_TEXT_INPUT) { break; } diff --git a/src/pc/gfx/gfx_opengl.c b/src/pc/gfx/gfx_opengl.c index 324f082e..f332946f 100644 --- a/src/pc/gfx/gfx_opengl.c +++ b/src/pc/gfx/gfx_opengl.c @@ -529,7 +529,7 @@ static void gfx_opengl_select_texture(int tile, GLuint texture_id) { gfx_opengl_set_texture_uniforms(opengl_prg, tile); } -static void gfx_opengl_upload_texture(uint8_t *rgba32_buf, int width, int height) { +static void gfx_opengl_upload_texture(const uint8_t *rgba32_buf, int width, int height) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgba32_buf); opengl_tex[opengl_curtex]->size[0] = width; opengl_tex[opengl_curtex]->size[1] = height; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 053de7e4..e9563bee 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -369,7 +369,7 @@ static void gfx_sdl_shutdown(void) { static void gfx_sdl_start_text_input(void) { SDL_StartTextInput(); } static void gfx_sdl_stop_text_input(void) { SDL_StopTextInput(); } -static char* gfx_sdl_get_clipboard_text(void) { SDL_GetClipboardText(); } +static char* gfx_sdl_get_clipboard_text(void) { return SDL_GetClipboardText(); } struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_init, diff --git a/src/pc/logfile.c b/src/pc/logfile.c index d49b985e..d301daa9 100644 --- a/src/pc/logfile.c +++ b/src/pc/logfile.c @@ -4,6 +4,7 @@ #include #include #include +#include "pc/fs/fs.h" #define LOGFILE_NAME "errorlog.txt" diff --git a/src/pc/network/network.h b/src/pc/network/network.h index b1a00a2d..4b002859 100644 --- a/src/pc/network/network.h +++ b/src/pc/network/network.h @@ -72,6 +72,7 @@ void network_on_loaded_level(void); void network_clear_sync_objects(void); struct SyncObject* network_init_object(struct Object *object, float maxSyncDistance); +void network_init_object_field(struct Object* o, void* field); void network_send(struct Packet* p); void network_update(void); void network_shutdown(void); @@ -111,6 +112,7 @@ void network_send_level_warp(void); void network_receive_level_warp(struct Packet* p); void network_update_inside_painting(void); +void network_send_inside_painting(void); void network_receive_inside_painting(struct Packet* p); void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex); diff --git a/src/pc/network/packets/packet_collect_coin.c b/src/pc/network/packets/packet_collect_coin.c index 33f9da2e..7f76c848 100644 --- a/src/pc/network/packets/packet_collect_coin.c +++ b/src/pc/network/packets/packet_collect_coin.c @@ -6,6 +6,11 @@ #include "course_table.h" #include "src/game/interaction.h" #include "src/engine/math_util.h" +#include "src/game/memory.h" +#include "src/game/object_helpers.h" + +// defined in sparkle_spawn_star.inc.c +void bhv_spawn_star_no_level_exit(struct Object* object, u32 sp20); static u8 localCoinId = 1; @@ -64,7 +69,6 @@ void network_send_collect_coin(struct Object* o) { void network_receive_collect_coin(struct Packet* p) { u8 remoteCoinId = 0; enum BehaviorId behaviorId; - void* behavior = NULL; f32 pos[3] = { 0 }; s16 numCoins = 0; s32 coinValue = 0; @@ -75,7 +79,7 @@ void network_receive_collect_coin(struct Packet* p) { packet_read(p, &numCoins, sizeof(s16)); packet_read(p, &coinValue, sizeof(s32)); - behavior = get_behavior_from_id(behaviorId); + const void* behavior = get_behavior_from_id(behaviorId); // check if remote coin id has already been seen for (int i = 0; i < MAX_REMOTE_COIN_IDS; i++) { diff --git a/src/pc/network/packets/packet_collect_item.c b/src/pc/network/packets/packet_collect_item.c index 75ecbff3..9d523cc1 100644 --- a/src/pc/network/packets/packet_collect_item.c +++ b/src/pc/network/packets/packet_collect_item.c @@ -6,6 +6,8 @@ #include "course_table.h" #include "src/game/interaction.h" #include "src/engine/math_util.h" +#include "src/game/memory.h" +#include "src/game/object_helpers.h" static u8 localItemId = 1; @@ -62,14 +64,13 @@ void network_send_collect_item(struct Object* o) { void network_receive_collect_item(struct Packet* p) { u8 remoteItemId = 0; enum BehaviorId behaviorId; - void* behavior = NULL; f32 pos[3] = { 0 }; packet_read(p, &remoteItemId, sizeof(u8)); packet_read(p, &behaviorId, sizeof(enum BehaviorId)); packet_read(p, &pos, sizeof(f32) * 3); - behavior = get_behavior_from_id(behaviorId); + const void* behavior = get_behavior_from_id(behaviorId); // check if remote item id has already been seen for (int i = 0; i < MAX_REMOTE_ITEM_IDS; i++) { diff --git a/src/pc/network/packets/packet_collect_star.c b/src/pc/network/packets/packet_collect_star.c index f81af50d..75ea0942 100644 --- a/src/pc/network/packets/packet_collect_star.c +++ b/src/pc/network/packets/packet_collect_star.c @@ -5,18 +5,21 @@ #include "object_fields.h" #include "object_constants.h" #include "game/interaction.h" +#include "src/game/memory.h" +#include "src/game/object_helpers.h" +#include "src/game/save_file.h" extern s16 gCurrSaveFileNum; extern s16 gCurrCourseNum; -static f32 dist_to_pos(struct Object* o, f32* pos) { +static f32 dist_to_pos(struct Object* o, u32* pos) { f32 x = (f32)o->oPosX - pos[0]; x *= x; f32 y = (f32)o->oPosY - pos[1]; y *= y; f32 z = (f32)o->oPosZ - pos[2]; z *= z; return (f32)sqrt(x + y + z); } -static struct Object* find_nearest_star(const BehaviorScript* behavior, f32* pos, float minDist) { +static struct Object* find_nearest_star(const BehaviorScript* behavior, u32* pos, float minDist) { uintptr_t* behaviorAddr = segmented_to_virtual(behavior); struct Object* closestObj = NULL; struct Object* obj; @@ -59,7 +62,6 @@ void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex) { void network_receive_collect_star(struct Packet* p) { u32 pos[3] = { 0 }; enum BehaviorId behaviorId; - void* behavior = NULL; s16 coinScore, starIndex; s16 lastSaveFileNum = gCurrSaveFileNum; s16 lastCourseNum = gCurrCourseNum; @@ -71,7 +73,7 @@ void network_receive_collect_star(struct Packet* p) { packet_read(p, &coinScore, sizeof(s16)); packet_read(p, &starIndex, sizeof(s16)); - behavior = get_behavior_from_id(behaviorId); + const void* behavior = get_behavior_from_id(behaviorId); save_file_collect_star_or_key(coinScore, starIndex); diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index ab78cbbf..47e60246 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -5,6 +5,8 @@ #include "object_constants.h" #include "behavior_data.h" #include "behavior_table.h" +#include "src/game/memory.h" +#include "src/game/object_helpers.h" static u8 nextSyncID = 1; struct SyncObject syncObjects[MAX_SYNC_OBJECTS] = { 0 }; @@ -58,7 +60,7 @@ struct SyncObject* network_init_object(struct Object *o, float maxSyncDistance) so->owned = false; so->clockSinceUpdate = clock(); so->extraFieldCount = 0; - so->behavior = o->behavior; + so->behavior = (BehaviorScript*)o->behavior; so->rxEventId = 0; so->txEventId = 0; so->fullObjectSync = false; @@ -103,12 +105,13 @@ static void packet_write_object_header(struct Packet* p, struct Object* o) { packet_write(p, &behaviorId, sizeof(enum BehaviorId)); } -static bool allowable_behavior_change(struct SyncObject* so, struct BehaviorScript* behavior) { +static bool allowable_behavior_change(struct SyncObject* so, BehaviorScript* behavior) { struct Object* o = so->o; - bool allow = false; // bhvPenguinBaby can be set to bhvSmallPenguin - allow = allow || ((o->behavior == bhvPenguinBaby || o->behavior == bhvSmallPenguin) && (behavior == bhvPenguinBaby || behavior == bhvSmallPenguin)); + bool oBehaviorPenguin = (o->behavior == segmented_to_virtual(bhvPenguinBaby) || o->behavior == segmented_to_virtual(bhvSmallPenguin)); + bool inBehaviorPenguin = (behavior == segmented_to_virtual(bhvPenguinBaby) || behavior == segmented_to_virtual(bhvSmallPenguin)); + bool allow = (oBehaviorPenguin && inBehaviorPenguin); if (!allow) { return false; } @@ -122,7 +125,7 @@ static struct SyncObject* packet_read_object_header(struct Packet* p) { u32 syncId = 0; packet_read(p, &syncId, sizeof(u32)); if (syncId == 0 || syncId >= MAX_SYNC_OBJECTS) { - printf("%s invalid SyncID!\n", NETWORKTYPESTR, syncId); + printf("%s invalid SyncID %d!\n", NETWORKTYPESTR, syncId); return NULL; } @@ -151,7 +154,7 @@ static struct SyncObject* packet_read_object_header(struct Packet* p) { // make sure the behaviors match enum BehaviorId behaviorId; packet_read(p, &behaviorId, sizeof(enum BehaviorId)); - struct BehaviorScript* behavior = get_behavior_from_id(behaviorId); + BehaviorScript* behavior = (BehaviorScript*)get_behavior_from_id(behaviorId); if (o->behavior != behavior && !allowable_behavior_change(so, behavior)) { printf("network_receive_object() behavior mismatch!\n"); network_forget_sync_object(so); @@ -379,7 +382,7 @@ void network_forget_sync_object(struct SyncObject* so) { } void network_update_objects(void) { - for (int i = 1; i < nextSyncID; i++) { + for (u32 i = 1; i < nextSyncID; i++) { struct SyncObject* so = &syncObjects[i]; if (so->o == NULL) { continue; } diff --git a/src/pc/network/packets/packet_player.c b/src/pc/network/packets/packet_player.c index df68cc42..2c600bb7 100644 --- a/src/pc/network/packets/packet_player.c +++ b/src/pc/network/packets/packet_player.c @@ -3,15 +3,16 @@ #include "object_fields.h" #include "object_constants.h" #include "sm64.h" +#include "src/audio/external.h" void network_send_player(void) { if (gMarioStates[0].marioObj == NULL) { return; } u32 heldSyncID = (gMarioStates[0].heldObj != NULL) ? gMarioStates[0].heldObj->oSyncID - : NULL; + : 0; u32 heldBySyncID = (gMarioStates[0].heldByObj != NULL) ? gMarioStates[0].heldByObj->oSyncID - : NULL; + : 0; struct Packet p; packet_init(&p, PACKET_PLAYER, false); @@ -35,8 +36,8 @@ void network_receive_player(struct Packet* p) { if (gMarioStates[1].marioObj == NULL) { return; } // save previous state - u32 heldSyncID = NULL; - u32 heldBySyncID = NULL; + u32 heldSyncID = 0; + u32 heldBySyncID = 0; u32 oldAction = gMarioStates[1].action; u16 oldActionState = gMarioStates[1].actionState; u16 oldActionArg = gMarioStates[1].actionArg; @@ -65,7 +66,7 @@ void network_receive_player(struct Packet* p) { } // find and set their held object - if (heldSyncID != NULL && syncObjects[heldSyncID].o != NULL) { + if (heldSyncID != 0 && syncObjects[heldSyncID].o != NULL) { // TODO: do we have to move graphics nodes around to make this visible? struct Object* heldObj = syncObjects[heldSyncID].o; gMarioStates[1].heldObj = heldObj; @@ -76,7 +77,7 @@ void network_receive_player(struct Packet* p) { } // find and set their held-by object - if (heldBySyncID != NULL && syncObjects[heldBySyncID].o != NULL) { + if (heldBySyncID != 0 && syncObjects[heldBySyncID].o != NULL) { // TODO: do we have to move graphics nodes around to make this visible? gMarioStates[1].heldByObj = syncObjects[heldBySyncID].o; } else { diff --git a/src/pc/network/packets/packet_reservation.c b/src/pc/network/packets/packet_reservation.c index edc92367..c492ea2b 100644 --- a/src/pc/network/packets/packet_reservation.c +++ b/src/pc/network/packets/packet_reservation.c @@ -17,7 +17,7 @@ void network_send_reservation_request(void) { network_send(&p); } -void network_receive_reservation_request(struct Packet* p) { +void network_receive_reservation_request(UNUSED struct Packet* p) { assert(networkType == NT_SERVER); network_send_reservation(); } diff --git a/src/pc/network/packets/packet_spawn_objects.c b/src/pc/network/packets/packet_spawn_objects.c index 70207e1f..dc51acd2 100644 --- a/src/pc/network/packets/packet_spawn_objects.c +++ b/src/pc/network/packets/packet_spawn_objects.c @@ -2,6 +2,7 @@ #include "../network.h" #include "object_fields.h" #include "object_constants.h" +#include "src/game/object_helpers.h" #include "behavior_data.h" #include "behavior_table.h" @@ -34,7 +35,7 @@ static u8 generate_parent_id(struct Object* objects[], u8 onIndex) { return (u8)o->parentObj->oSyncID; } - for (u8 i = onIndex; i >= 0; i--) { + for (u8 i = onIndex; i < onIndex; i--) { if (o->parentObj == objects[i]) { return i; } } @@ -110,7 +111,7 @@ void network_receive_spawn_objects(struct Packet* p) { if (parentObj == NULL) { continue; } } - void* behavior = get_behavior_from_id(data.behaviorId); + void* behavior = (void*)get_behavior_from_id(data.behaviorId); struct Object* o = spawn_object(parentObj, data.model, behavior); memcpy(o->rawData.asU32, data.rawData, sizeof(u32) * 80); diff --git a/src/pc/network/packets/packet_spawn_star.c b/src/pc/network/packets/packet_spawn_star.c index f2ac029b..4f4f2f08 100644 --- a/src/pc/network/packets/packet_spawn_star.c +++ b/src/pc/network/packets/packet_spawn_star.c @@ -1,6 +1,7 @@ #include #include "../network.h" #include "object_fields.h" +#include "src/game/behavior_actions.h" extern struct Object* gCurrentObject; diff --git a/src/pc/network/socket/socket.c b/src/pc/network/socket/socket.c index fe2dd90f..57911e06 100644 --- a/src/pc/network/socket/socket.c +++ b/src/pc/network/socket/socket.c @@ -1,3 +1,4 @@ +#include #include "socket.h" #include "../network.h" @@ -17,7 +18,7 @@ int socket_bind(SOCKET sock, unsigned int port) { int socket_send(SOCKET sock, struct sockaddr_in* txAddr, char* buffer, int bufferLength) { int txAddrSize = sizeof(struct sockaddr_in); - int rc = sendto(sock, buffer, bufferLength, 0, txAddr, txAddrSize); + int rc = sendto(sock, buffer, bufferLength, 0, (struct sockaddr*)txAddr, txAddrSize); if (rc == SOCKET_ERROR) { printf("%s sendto failed with error: %d\n", NETWORKTYPESTR, SOCKET_LAST_ERROR); } @@ -29,10 +30,10 @@ int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, char* buffer, int bu *receiveLength = 0; int rxAddrSize = sizeof(struct sockaddr_in); - int rc = recvfrom(sock, buffer, bufferLength, 0, rxAddr, &rxAddrSize); + int rc = recvfrom(sock, buffer, bufferLength, 0, (struct sockaddr*)rxAddr, &rxAddrSize); if (rc == SOCKET_ERROR) { int error = SOCKET_LAST_ERROR; - if (error != EWOULDBLOCK && error != ECONNRESET) { + if (error != SOCKET_EWOULDBLOCK && error != SOCKET_ECONNRESET) { printf("%s recvfrom failed with error %d\n", NETWORKTYPESTR, SOCKET_LAST_ERROR); } return rc; diff --git a/src/pc/network/socket/socket_linux.h b/src/pc/network/socket/socket_linux.h index 282b35dc..5bb91da8 100644 --- a/src/pc/network/socket/socket_linux.h +++ b/src/pc/network/socket/socket_linux.h @@ -14,5 +14,7 @@ #define SOCKADDR struct sockaddr #define SOCKET_ERROR (-1) #define closesocket(fd) close(fd) +#define SOCKET_EWOULDBLOCK EWOULDBLOCK +#define SOCKET_ECONNRESET ECONNRESET #endif diff --git a/src/pc/network/socket/socket_windows.c b/src/pc/network/socket/socket_windows.c index f6017077..0a2c2639 100644 --- a/src/pc/network/socket/socket_windows.c +++ b/src/pc/network/socket/socket_windows.c @@ -1,4 +1,5 @@ #ifdef WINSOCK +#include #include "socket_windows.h" #include "../network.h" diff --git a/src/pc/network/socket/socket_windows.h b/src/pc/network/socket/socket_windows.h index 5c37c3b3..86bef6eb 100644 --- a/src/pc/network/socket/socket_windows.h +++ b/src/pc/network/socket/socket_windows.h @@ -5,7 +5,7 @@ #include #define SOCKET_LAST_ERROR WSAGetLastError() -#define EWOULDBLOCK WSAEWOULDBLOCK -#define ECONNRESET WSAECONNRESET +#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK +#define SOCKET_ECONNRESET WSAECONNRESET #endif