Synchronized BITFS platforms

This commit is contained in:
MysterD 2020-10-03 00:18:18 -07:00
parent c6da1a057a
commit 57b092c26b
4 changed files with 58 additions and 13 deletions

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@
#ifdef DEBUG
static u8 warpToLevel = LEVEL_HMC;
static u8 warpToLevel = LEVEL_BITFS;
#define SCANCODE_0 0x0B
#define SCANCODE_1 0x02