diff --git a/src/pc/network/network.c b/src/pc/network/network.c index db1ca74c..045079ef 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -94,7 +94,7 @@ void network_on_init_level(void) { } void network_on_loaded_level(void) { - // check for level change + area_remove_sync_ids_clear(); struct NetworkPlayer* np = gNetworkPlayerLocal; if (np != NULL) { bool levelMatch = (np->currCourseNum == gCurrCourseNum diff --git a/src/pc/network/packets/packet.h b/src/pc/network/packets/packet.h index 7f5f5e50..d01d986d 100644 --- a/src/pc/network/packets/packet.h +++ b/src/pc/network/packets/packet.h @@ -220,6 +220,9 @@ void network_send_area_request(struct NetworkPlayer* fromNp, struct NetworkPlaye void network_receive_area_request(struct Packet* p); // packet_area.c + +void area_remove_sync_ids_add(u8 syncId); +void area_remove_sync_ids_clear(void); void network_send_area(struct NetworkPlayer* toNp); void network_receive_area(struct Packet* p); diff --git a/src/pc/network/packets/packet_area.c b/src/pc/network/packets/packet_area.c index e289f807..8864f66e 100644 --- a/src/pc/network/packets/packet_area.c +++ b/src/pc/network/packets/packet_area.c @@ -12,6 +12,23 @@ //#define DISABLE_MODULE_LOG 1 #include "pc/debuglog.h" +u8 sRemoveSyncIds[RESERVED_IDS_SYNC_OBJECT_OFFSET] = { 0 }; +u8 sRemoveSyncIdsIndex = 0; + +void area_remove_sync_ids_add(u8 syncId) { + if (syncId >= RESERVED_IDS_SYNC_OBJECT_OFFSET) { return; } + for (int i = 0; i < sRemoveSyncIdsIndex; i++) { + if (sRemoveSyncIds[i] == syncId) { return; } + } + sRemoveSyncIds[sRemoveSyncIdsIndex++] = syncId; +} + +void area_remove_sync_ids_clear(void) { + sRemoveSyncIdsIndex = 0; +} + +///////////////////////////////////////////////// + void network_send_area(struct NetworkPlayer* toNp) { extern s16 gCurrCourseNum, gCurrActNum, gCurrLevelNum, gCurrAreaIndex; @@ -26,6 +43,13 @@ void network_send_area(struct NetworkPlayer* toNp) { packet_write(&p, &gCurrLevelNum, sizeof(s16)); packet_write(&p, &gCurrAreaIndex, sizeof(s16)); + // write sync id removals + packet_write(&p, &sRemoveSyncIdsIndex, sizeof(u8)); + for (int i = 0; i < sRemoveSyncIdsIndex; i++) { + packet_write(&p, &sRemoveSyncIds[i], sizeof(u8)); + LOG_INFO("tx remove sync id %d", sRemoveSyncIds[i]); + } + // count respawners and write u8 respawnerCount = 0; for (int i = 0; i < MAX_SYNC_OBJECTS; i++) { @@ -111,6 +135,19 @@ void network_receive_area(struct Packet* p) { return; } + // read removed sync ids + area_remove_sync_ids_clear(); + packet_read(p, &sRemoveSyncIdsIndex, sizeof(u8)); + for (int i = 0; i < sRemoveSyncIdsIndex; i++) { + packet_read(p, &sRemoveSyncIds[i], sizeof(u8)); + struct SyncObject* so = &gSyncObjects[sRemoveSyncIds[i]]; + if (so->o != NULL) { + so->o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } + network_forget_sync_object(so); + LOG_INFO("rx remove sync id %d", sRemoveSyncIds[i]); + } + // read respawner count u8 respawnerCount = 0; packet_read(p, &respawnerCount, sizeof(u8)); diff --git a/src/pc/network/packets/packet_level_macro.c b/src/pc/network/packets/packet_level_macro.c index 41c3d07d..cc23d5ae 100644 --- a/src/pc/network/packets/packet_level_macro.c +++ b/src/pc/network/packets/packet_level_macro.c @@ -88,7 +88,7 @@ static void network_send_level_macro_area(struct NetworkPlayer* destNp, u8 areaI // check for special cases const BehaviorScript* behavior = MacroObjectPresets[presetID].behavior; - if ((behavior == bhvCoinFormation || behavior == bhvGoombaTripletSpawner) && *respawnInfo != 0) { + if ((behavior == bhvCoinFormation) && *respawnInfo != 0) { *macroSpecialCount = *macroSpecialCount + 1; u16 offset = respawnInfo - area->macroObjects; packet_write(&p, &offset, sizeof(u16)); @@ -197,21 +197,6 @@ void network_receive_level_macro(struct Packet* p) { } LOG_INFO("rx macro special: coin formation"); } - else if (behavior == bhvGoombaTripletSpawner) { - o->oBehParams = *respawnInfo; - u8 goombaParams = (o->oBehParams >> 8) & 0xFF; - - u8 childIndex = 0; - for (int i = 0; i < OBJECT_POOL_CAPACITY; i++) { - struct Object* o2 = &gObjectPool[i]; - if (o2->parentObj != o) { continue; } - if (o2 == o) { continue; } - if (goombaParams & (1 << childIndex++)) { - obj_mark_for_deletion(o2); - } - } - LOG_INFO("rx macro special: goomba triplet %d", *respawnInfo); - } } } } \ No newline at end of file diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index 989a485c..22cca5fa 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -13,6 +13,7 @@ struct SyncObject gSyncObjects[MAX_SYNC_OBJECTS] = { 0 }; struct Packet sLastSyncEntReliablePacket[MAX_SYNC_OBJECTS] = { 0 }; +u8 sNextSyncId = 0; struct Packet* get_last_sync_ent_reliable_packet(u8 syncId) { return &sLastSyncEntReliablePacket[syncId]; @@ -137,6 +138,7 @@ bool network_sync_object_initialized(struct Object* o) { } void network_clear_sync_objects(void) { + sNextSyncId = 0; network_on_init_level(); for (u16 i = 0; i < MAX_SYNC_OBJECTS; i++) { network_forget_sync_object(&gSyncObjects[i]); @@ -150,8 +152,10 @@ void network_set_sync_id(struct Object* o) { if (!gNetworkLevelLoaded) { // while loading, just fill in sync ids from 1 to MAX_SYNC_OBJECTS for (int i = 1; i < MAX_SYNC_OBJECTS; i++) { - if (gSyncObjects[i].o != NULL) { continue; } - syncId = i; + sNextSyncId++; + sNextSyncId = sNextSyncId % RESERVED_IDS_SYNC_OBJECT_OFFSET; + if (gSyncObjects[sNextSyncId].o != NULL) { continue; } + syncId = sNextSyncId; break; } } else { @@ -517,6 +521,7 @@ void network_forget_sync_object(struct SyncObject* so) { if (so == so2) { sLastSyncEntReliablePacket[syncId].error = true; } + area_remove_sync_ids_add(syncId); } so->o = NULL;