Prevent level/area/object sync during credits sequence

This commit is contained in:
MysterD 2021-08-05 00:22:03 -07:00
parent 0d05853138
commit cbb7eb419c
4 changed files with 20 additions and 4 deletions

View file

@ -17,7 +17,8 @@ static void player_changed_area(struct NetworkPlayer* np, s16 courseNum, s16 act
// find a NetworkPlayer at that area
struct NetworkPlayer* npLevelAreaMatch = get_network_player_from_area(courseNum, actNum, levelNum, areaIndex);
if (npLevelAreaMatch == NULL) {
bool inCredits = (np->currActNum == 99);
if (npLevelAreaMatch == NULL || inCredits) {
// no NetworkPlayer in the level
network_send_sync_valid(np);
network_send_level_area_inform(np);

View file

@ -20,7 +20,8 @@ static void player_changed_level(struct NetworkPlayer* np, s16 courseNum, s16 ac
struct NetworkPlayer* npLevelMatch = get_network_player_from_level(courseNum, actNum, levelNum);
struct NetworkPlayer* npAny = (npLevelAreaMatch == NULL) ? npLevelMatch : npLevelAreaMatch;
if (npAny == NULL) {
bool inCredits = (np->currActNum == 99);
if (npAny == NULL || inCredits) {
// no NetworkPlayer in the level
network_send_sync_valid(np);
network_send_level_area_inform(np);

View file

@ -9,6 +9,7 @@
#include "src/game/memory.h"
#include "src/game/object_helpers.h"
#include "src/game/obj_behaviors.h"
#include "src/game/area.h"
#include "pc/debuglog.h"
#include "pc/utils/misc.h"
@ -40,6 +41,9 @@ static float player_distance(struct MarioState* marioState, struct Object* o) {
}
static bool should_own_object(struct SyncObject* so) {
// always own objects in credit sequence
if (gCurrActStarNum == 99) { return true; }
// check for override
u8 shouldOverride = FALSE;
u8 shouldOwn = FALSE;
@ -407,6 +411,8 @@ void network_send_object(struct Object* o) {
}
void network_send_object_reliability(struct Object* o, bool reliable) {
// prevent sending objects during credits sequence
if (gCurrActStarNum == 99) { return; }
// sanity check SyncObject
if (!network_sync_object_initialized(o)) { return; }
u8 syncId = o->oSyncID;
@ -453,6 +459,9 @@ void network_send_object_reliability(struct Object* o, bool reliable) {
}
void network_receive_object(struct Packet* p) {
// prevent receiving objects during credits sequence
if (gCurrActStarNum == 99) { return; }
// read the header and sanity check the packet
u8 fromLocalIndex = 0;
struct SyncObject* so = packet_read_object_header(p, &fromLocalIndex);
@ -570,7 +579,8 @@ void network_update_objects(void) {
if (timeSinceUpdate < updateRate) { continue; }
// update!
if (network_player_any_connected()) {
bool inCredits = (gCurrActStarNum == 99);
if (network_player_any_connected() && !inCredits) {
network_send_object(gSyncObjects[i].o);
}
}

View file

@ -4,6 +4,7 @@
#include "object_fields.h"
#include "object_constants.h"
#include "src/game/object_helpers.h"
#include "src/game/area.h"
#include "behavior_data.h"
#include "behavior_table.h"
//#define DISABLE_MODULE_LOG 1
@ -47,7 +48,8 @@ void network_send_spawn_objects(struct Object* objects[], u32 models[], u8 objec
void network_send_spawn_objects_to(u8 sendToLocalIndex, struct Object* objects[], u32 models[], u8 objectCount) {
assert(objectCount < MAX_SPAWN_OBJECTS_PER_PACKET);
if (sendToLocalIndex == gNetworkPlayerLocal->localIndex) { return; }
// prevent sending spawn objects during credits
if (gCurrActStarNum == 99) { return; }
struct Packet p;
packet_init(&p, PACKET_SPAWN_OBJECTS, true, true);
@ -81,6 +83,8 @@ void network_send_spawn_objects_to(u8 sendToLocalIndex, struct Object* objects[]
void network_receive_spawn_objects(struct Packet* p) {
LOG_INFO("rx spawn objects");
// prevent receiving spawn objects during credits
if (gCurrActStarNum == 99) { return; }
u8 objectCount = 0;
packet_read(p, &objectCount, sizeof(u8));