From 57b092c26b7b5600655c098174dbddefff1cc8a0 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sat, 3 Oct 2020 00:18:18 -0700 Subject: [PATCH] Synchronized BITFS platforms --- src/game/behaviors/activated_bf_plat.inc.c | 26 +++++++++++++++-- .../behaviors/falling_rising_platform.inc.c | 28 +++++++++++++++++++ src/game/behaviors/sliding_platform_2.inc.c | 15 ++++------ src/pc/controller/controller_keyboard_debug.c | 2 +- 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/game/behaviors/activated_bf_plat.inc.c b/src/game/behaviors/activated_bf_plat.inc.c index 49fa5657..bcfa3c2c 100644 --- a/src/game/behaviors/activated_bf_plat.inc.c +++ b/src/game/behaviors/activated_bf_plat.inc.c @@ -55,17 +55,37 @@ void bhv_activated_back_and_forth_platform_init(void) { o->oActivatedBackAndForthPlatformVertical = (u16)(o->oBehParams >> 16) & 0x0080; o->oActivatedBackAndForthPlatformStartYaw = o->oFaceAngleYaw; + + network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS); + network_init_object_field(o, &o->oPosX); + network_init_object_field(o, &o->oPosY); + network_init_object_field(o, &o->oPosZ); + network_init_object_field(o, &o->oVelX); + network_init_object_field(o, &o->oVelY); + network_init_object_field(o, &o->oVelZ); + network_init_object_field(o, &o->oActivatedBackAndForthPlatformMaxOffset); + network_init_object_field(o, &o->oActivatedBackAndForthPlatformOffset); + network_init_object_field(o, &o->oActivatedBackAndForthPlatformVel); + network_init_object_field(o, &o->oActivatedBackAndForthPlatformCountdown); + network_init_object_field(o, &o->oActivatedBackAndForthPlatformStartYaw); + network_init_object_field(o, &o->oActivatedBackAndForthPlatformVertical); + network_init_object_field(o, &o->oActivatedBackAndForthPlatformFlipRotation); } /** * Activated back-and-forth platform update function. */ void bhv_activated_back_and_forth_platform_update(void) { + u8 doSendNetwork = FALSE; UNUSED s32 unused[3]; + struct Object* player = nearest_player_to_object(o); + int distanceToPlayer = dist_between_objects(o, player); + int angleToPlayer = obj_angle_to_object(o, player); + // oVelY is used for vertical platforms' movement and also for // horizontal platforms' dipping up/down when Mario gets on/off them - if (gMarioObject->platform == o) { + if (cur_obj_is_any_player_on_platform()) { o->oVelY = -6.0f; } else { o->oVelY = 6.0f; @@ -91,7 +111,7 @@ void bhv_activated_back_and_forth_platform_update(void) { o->oActivatedBackAndForthPlatformMaxOffset) || // The platform will not reset if Mario goes far away and it's travelling backwards - (o->oActivatedBackAndForthPlatformVel > 0.0f && o->oDistanceToMario > 3000.0f)) { + (o->oActivatedBackAndForthPlatformVel > 0.0f && distanceToPlayer > 3000.0f)) { // Reset the wait timer o->oActivatedBackAndForthPlatformCountdown = 20; @@ -115,6 +135,7 @@ void bhv_activated_back_and_forth_platform_update(void) { // oVelY is only negative if Mario is on the platform if (o->oVelY < 0.0f) { o->oActivatedBackAndForthPlatformVel = 10.0f; + doSendNetwork = TRUE; } // Set waiting countdown to 20 frames @@ -143,4 +164,5 @@ void bhv_activated_back_and_forth_platform_update(void) { // Compute the object's velocity using the old saved position. obj_perform_position_op(POS_OP_COMPUTE_VELOCITY); + if (doSendNetwork) { network_send_object(o); } } diff --git a/src/game/behaviors/falling_rising_platform.inc.c b/src/game/behaviors/falling_rising_platform.inc.c index 4bd7ecd5..f44ec574 100644 --- a/src/game/behaviors/falling_rising_platform.inc.c +++ b/src/game/behaviors/falling_rising_platform.inc.c @@ -1,11 +1,28 @@ // falling_rising_platform.c.inc void bhv_squishable_platform_loop(void) { + if (!network_sync_object_initialized(o)) { + struct SyncObject* so = network_init_object(o, 4000.0f); + so->minUpdateRate = 5.0f; + network_init_object_field(o, &o->oPlatformTimer); + network_init_object_field(o, &o->header.gfx.scale[1]); + } + + if ((((o->oPlatformTimer / 0x80) % 300) == 0) && network_owns_object(o)) { + network_send_object(o); + } + o->header.gfx.scale[1] = (sins(o->oPlatformTimer) + 1.0) * 0.3 + 0.4; o->oPlatformTimer += 0x80; } void bhv_bitfs_sinking_platform_loop(void) { + if (!network_sync_object_initialized(o)) { + struct SyncObject* so = network_init_object(o, 4000.0f); + so->minUpdateRate = 5.0f; + network_init_object_field(o, &o->oPlatformTimer); + } + o->oPosY -= sins(o->oPlatformTimer) * 0.58; //! f32 double conversion error accumulates on Wii VC causing the platform to rise up @@ -18,6 +35,16 @@ void bhv_ddd_moving_pole_loop(void) { } void bhv_bitfs_sinking_cage_platform_loop(void) { + if (!network_sync_object_initialized(o)) { + struct SyncObject* so = network_init_object(o, 4000.0f); + so->minUpdateRate = 5.0f; + network_init_object_field(o, &o->oPlatformTimer); + } + + if ((((o->oPlatformTimer / 0x100) % 60) == 0) && network_owns_object(o)) { + network_send_object(o); + } + if (o->oBehParams2ndByte != 0) { if (o->oTimer == 0) o->oPosY -= 300.0f; @@ -25,4 +52,5 @@ void bhv_bitfs_sinking_cage_platform_loop(void) { } else o->oPosY -= sins(o->oPlatformTimer) * 3.0f; o->oPlatformTimer += 0x100; + } diff --git a/src/game/behaviors/sliding_platform_2.inc.c b/src/game/behaviors/sliding_platform_2.inc.c index 41f6f61a..cf3a0706 100644 --- a/src/game/behaviors/sliding_platform_2.inc.c +++ b/src/game/behaviors/sliding_platform_2.inc.c @@ -34,18 +34,13 @@ void bhv_sliding_plat_2_init(void) { } void bhv_sliding_plat_2_loop(void) { - if (network_sync_object_initialized(o)) { - struct SyncObject* so = network_init_object(o, 1000.0f); - so->maxUpdateRate = 5.0f; + if (!network_sync_object_initialized(o)) { + struct SyncObject* so = network_init_object(o, 4000.0f); + so->minUpdateRate = 5.0f; + network_init_object_field(o, &o->oBackAndForthPlatformUnkF4); + network_init_object_field(o, &o->oBackAndForthPlatformUnkF8); network_init_object_field(o, &o->oBackAndForthPlatformUnkFC); network_init_object_field(o, &o->oBackAndForthPlatformUnk100); - network_init_object_field(o, &o->oPosX); - network_init_object_field(o, &o->oPosY); - network_init_object_field(o, &o->oPosZ); - network_init_object_field(o, &o->oVelX); - network_init_object_field(o, &o->oVelY); - network_init_object_field(o, &o->oVelZ); - network_init_object_field(o, &o->oTimer); } if (o->oTimer > 10) { diff --git a/src/pc/controller/controller_keyboard_debug.c b/src/pc/controller/controller_keyboard_debug.c index e934ca17..d124bddb 100644 --- a/src/pc/controller/controller_keyboard_debug.c +++ b/src/pc/controller/controller_keyboard_debug.c @@ -7,7 +7,7 @@ #ifdef DEBUG -static u8 warpToLevel = LEVEL_HMC; +static u8 warpToLevel = LEVEL_BITFS; #define SCANCODE_0 0x0B #define SCANCODE_1 0x02