Served time for crimes against C

Due to my compile & launch scripts, I was silently ignoring warnings
this whole time. I've fixed my process, and gone back to fixed all of
the warnings I could (even outside of my code).
This commit is contained in:
MysterD 2020-09-04 01:55:54 -07:00
parent 621533fae8
commit d5005c9f37
59 changed files with 297 additions and 249 deletions

View file

@ -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

View file

@ -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;

View file

@ -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];

View file

@ -1,5 +1,6 @@
#include <PR/ultratypes.h>
#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

View file

@ -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

View file

@ -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)) {

View file

@ -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) {

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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:

View file

@ -1,4 +1,5 @@
#include <ultra64.h>
#include <string.h>
#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);

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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
}

View file

@ -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

View file

@ -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
};
/**

View file

@ -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;

View file

@ -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

View file

@ -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) {

View file

@ -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++;

View file

@ -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);

View file

@ -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.

View file

@ -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

View file

@ -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;

View file

@ -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));

View file

@ -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);
}

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -3,6 +3,7 @@
#include "cheats.h"
#include "pc_main.h"
#include "platform.h"
#include "macros.h"
#include <strings.h>
#include <stdlib.h>
@ -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;

View file

@ -1,5 +1,6 @@
#include <stdbool.h>
#include <ultra64.h>
#include <string.h>
#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; }

View file

@ -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;

View file

@ -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,

View file

@ -4,6 +4,7 @@
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "pc/fs/fs.h"
#define LOGFILE_NAME "errorlog.txt"

View file

@ -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);

View file

@ -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++) {

View file

@ -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++) {

View file

@ -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);

View file

@ -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; }

View file

@ -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 {

View file

@ -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();
}

View file

@ -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);

View file

@ -1,6 +1,7 @@
#include <stdio.h>
#include "../network.h"
#include "object_fields.h"
#include "src/game/behavior_actions.h"
extern struct Object* gCurrentObject;

View file

@ -1,3 +1,4 @@
#include <stdio.h>
#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;

View file

@ -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

View file

@ -1,4 +1,5 @@
#ifdef WINSOCK
#include <stdio.h>
#include "socket_windows.h"
#include "../network.h"

View file

@ -5,7 +5,7 @@
#include <Ws2tcpip.h>
#define SOCKET_LAST_ERROR WSAGetLastError()
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ECONNRESET WSAECONNRESET
#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
#define SOCKET_ECONNRESET WSAECONNRESET
#endif