Fixed sync ID assignments

This commit is contained in:
MysterD 2023-03-27 15:34:22 -07:00
parent f2c9c6ca8a
commit ec7cb86c2c
8 changed files with 34 additions and 14 deletions

View file

@ -416,9 +416,10 @@ struct TextureInfo
#define MAX_PLAYERS 16
#define COOP_OBJ_FLAG_NETWORK (1 << 0)
#define COOP_OBJ_FLAG_LUA (1 << 1)
#define COOP_OBJ_FLAG_NON_SYNC (1 << 2)
#define COOP_OBJ_FLAG_NETWORK (1 << 0)
#define COOP_OBJ_FLAG_LUA (1 << 1)
#define COOP_OBJ_FLAG_NON_SYNC (1 << 2)
#define COOP_OBJ_FLAG_INITIALIZED (1 << 3)
#include "src/game/characters.h"
#include "data/dynos.c.h"

View file

@ -251,7 +251,9 @@ void load_area(s32 index) {
if (gCurrentArea == NULL && gAreaData[index].unk04 != NULL) {
gCurrentArea = &gAreaData[index];
gCurrentArea->localAreaTimer = 0;
gCurrentArea->nextSyncID = 10;
if (gCurrentArea->objectSpawnInfos) {
gCurrentArea->nextSyncID = gCurrentArea->objectSpawnInfos->syncID + 10;
}
gCurrAreaIndex = gCurrentArea->index;
if (gCurrentArea->terrainData != NULL) {

View file

@ -51,7 +51,8 @@ static struct Object* spawn_object_internal(enum BehaviorId behaviorId, enum Mod
obj->oHomeY = y;
obj->oHomeZ = z;
obj->coopFlags = COOP_OBJ_FLAG_LUA;
obj->coopFlags = COOP_OBJ_FLAG_LUA | (obj->coopFlags & COOP_OBJ_FLAG_INITIALIZED);
if (!doSync) { obj->coopFlags |= COOP_OBJ_FLAG_NON_SYNC; }
if (objSetupFunction != 0) {

View file

@ -148,6 +148,9 @@ void network_player_palette_to_color(struct NetworkPlayer *np, enum PlayerParts
void network_player_update(void) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i];
if (np->connected && gMarioStates[np->localIndex].interactObj) {
//LOG_INFO("%u :: %u", np->globalIndex, gMarioStates[np->localIndex].interactObj->oSyncID); // DO NOT COMMIT
}
if (!np->connected && i > 0) { continue; }
network_player_update_model(i);

View file

@ -1,6 +1,7 @@
#include "../network.h"
#include "behavior_table.h"
#include "pc/debuglog.h"
#include "object_fields.h"
void print_sync_object_table(void) {
LOG_INFO("Sync Object Table");
@ -11,6 +12,9 @@ void print_sync_object_table(void) {
char* behaviorName = (char*)get_behavior_name_from_id(behaviorId);
if (!behaviorName) { behaviorName = "UNKNOWN"; }
LOG_INFO("%04d: %08X :: %s", so->id, behaviorId, behaviorName);
if (so->o->oSyncID != so->id) {
LOG_INFO("^^^^^^^^^^^^^^^^^^^^^ %u != %u", so->o->oSyncID, so->id);
}
behaviorId = behaviorId; // suppress warning
}
LOG_INFO(" ");

View file

@ -273,7 +273,7 @@ void network_send_object(struct Object* o) {
// sanity check SyncObject
if (!sync_object_is_initialized(o->oSyncID)) {
LOG_ERROR("tried to send uninitialized sync obj");
//LOG_ERROR("tried to send uninitialized sync obj");
return;
}
if (o->behavior == smlua_override_behavior(bhvRespawner)) {
@ -307,7 +307,7 @@ void network_send_object_reliability(struct Object* o, bool reliable) {
// sanity check SyncObject
if (!sync_object_is_initialized(o->oSyncID)) {
LOG_ERROR("tried to send uninitialized sync obj");
//LOG_ERROR("tried to send uninitialized sync obj");
return;
}

View file

@ -1,7 +1,6 @@
#include <stdio.h>
#include "../network.h"
#include "pc/utils/misc.h"
#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h"
void network_send_ping(struct NetworkPlayer* toNp) {
@ -15,11 +14,11 @@ void network_send_ping(struct NetworkPlayer* toNp) {
packet_write(&p, &timestamp, sizeof(f64));
network_send_to(toNp->localIndex, &p);
LOG_INFO("tx ping");
//LOG_INFO("tx ping");
}
void network_receive_ping(struct Packet* p) {
LOG_INFO("rx ping");
//LOG_INFO("rx ping");
u8 globalIndex;
f64 timestamp;
@ -52,5 +51,5 @@ void network_receive_pong(struct Packet* p) {
u32 ping = (now - timestamp) * 1000;
np->ping = np->ping * 0.5f + ping * 0.5f;
if (np->ping > 1000) { np->ping = 1000; }
LOG_INFO("rx pong from %u: %u", globalIndex, ping);
//LOG_INFO("rx pong from %u: %u", globalIndex, ping);
}

View file

@ -158,6 +158,11 @@ struct SyncObject* sync_object_init(struct Object *o, float maxSyncDistance) {
LOG_ERROR("Failed to get sync object in init");
return NULL;
}
if (o->coopFlags & COOP_OBJ_FLAG_INITIALIZED) {
return so;
}
so->id = id;
so->o = o;
so->maxSyncDistance = maxSyncDistance;
@ -191,6 +196,7 @@ struct SyncObject* sync_object_init(struct Object *o, float maxSyncDistance) {
memset(so->extraFieldsSize, 0, sizeof(u8) * MAX_SYNC_OBJECT_FIELDS);
so->lastReliablePacket.error = true;
o->coopFlags |= COOP_OBJ_FLAG_INITIALIZED;
return so;
}
@ -256,8 +262,8 @@ struct Object* sync_object_get_object(u32 syncId) {
bool sync_object_is_initialized(u32 syncId) {
if (syncId == 0) { return false; }
struct SyncObject* so = sync_object_get(syncId);
if (so == NULL || so->behavior == NULL) { return false; }
return true;
if (so == NULL || so->o == NULL) { return false; }
return so->o->coopFlags & COOP_OBJ_FLAG_INITIALIZED;
}
bool sync_object_is_owned_locally(u32 syncId) {
@ -403,10 +409,11 @@ bool sync_object_set_id(struct Object* o) {
if (!so) {
so = calloc(1, sizeof(struct SyncObject));
so->id = syncId;
so->extendedModelId = 0xFFFF;
hmap_put(sSoMap, syncId, so);
LOG_INFO("Allocated sync object @ %u, size %ld", syncId, hmap_len(sSoMap));
} else if (so->o != o) {
LOG_INFO("Already exists...");
}
if (!so) {
@ -414,6 +421,9 @@ bool sync_object_set_id(struct Object* o) {
return false;
}
so->id = syncId;
so->o = o;
so->behavior = (BehaviorScript*) o->behavior;
o->oSyncID = syncId;
if (gNetworkAreaLoaded) {