Remove old sync id reservation system
This commit is contained in:
parent
34dd9fee0d
commit
3477206253
|
@ -71,7 +71,7 @@ void create_respawner(s32 model, const BehaviorScript *behToSpawn, s32 minSpawnD
|
|||
respawner->oSyncID = syncID;
|
||||
}
|
||||
|
||||
if (syncID < RESERVED_IDS_SYNC_OBJECT_OFFSET) {
|
||||
if (syncID < SYNC_ID_BLOCK_SIZE) {
|
||||
if (respawner != NULL) {
|
||||
sync_object_override_object(syncID, respawner);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "engine/surface_load.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/network/network_player.h"
|
||||
#include "pc/network/reservation_area.h"
|
||||
#include "pc/lua/smlua.h"
|
||||
#include "pc/lua/utils/smlua_model_utils.h"
|
||||
#include "pc/lua/utils/smlua_obj_utils.h"
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include "hardcoded.h"
|
||||
#include "engine/surface_load.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/network/reservation_area.h"
|
||||
#include "pc/lua/utils/smlua_model_utils.h"
|
||||
#include "pc/lua/smlua_hooks.h"
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "spawn_object.h"
|
||||
#include "types.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/network/reservation_area.h"
|
||||
#include "pc/lua/smlua_hooks.h"
|
||||
|
||||
/**
|
||||
|
@ -216,10 +215,6 @@ void unload_object(struct Object *obj) {
|
|||
if (so && gNetworkType != NT_NONE) {
|
||||
if (so->syncDeathEvent) {
|
||||
network_send_object(obj);
|
||||
} else if (gNetworkType == NT_SERVER) {
|
||||
reservation_area_release(gNetworkPlayerLocal, obj->oSyncID);
|
||||
} else {
|
||||
network_send_reservation_release(obj->oSyncID);
|
||||
}
|
||||
|
||||
// forget sync object
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "types.h"
|
||||
#include "object_fields.h"
|
||||
#include "game/mario_misc.h"
|
||||
#include "reservation_area.h"
|
||||
#include "pc/djui/djui.h"
|
||||
#include "pc/debuglog.h"
|
||||
#include "pc/utils/misc.h"
|
||||
|
@ -346,7 +345,6 @@ u8 network_player_disconnected(u8 globalIndex) {
|
|||
djui_popup_create(popupMsg, 1);
|
||||
|
||||
packet_ordered_clear(globalIndex);
|
||||
reservation_area_change(np);
|
||||
|
||||
smlua_call_event_hooks_mario_param(HOOK_ON_PLAYER_DISCONNECTED, &gMarioStates[i]);
|
||||
|
||||
|
|
|
@ -61,11 +61,6 @@ void packet_process(struct Packet* p) {
|
|||
case PACKET_NETWORK_PLAYERS: network_receive_network_players(p); break;
|
||||
case PACKET_DEATH: network_receive_death(p); break;
|
||||
|
||||
// reservation area
|
||||
case PACKET_RESERVATION_LIST: network_receive_reservation_list(p); break;
|
||||
case PACKET_RESERVATION_USE: network_receive_reservation_use(p); break;
|
||||
case PACKET_RESERVATION_RELEASE: network_receive_reservation_release(p); break;
|
||||
|
||||
// location
|
||||
case PACKET_CHANGE_LEVEL: network_receive_change_level(p); break;
|
||||
case PACKET_CHANGE_AREA: network_receive_change_area(p); break;
|
||||
|
|
|
@ -35,9 +35,9 @@ enum PacketType {
|
|||
PACKET_NETWORK_PLAYERS,
|
||||
PACKET_DEATH,
|
||||
|
||||
PACKET_RESERVATION_LIST,
|
||||
PACKET_RESERVATION_USE,
|
||||
PACKET_RESERVATION_RELEASE,
|
||||
PACKET_UNUSED_21,
|
||||
PACKET_UNUSED_22,
|
||||
PACKET_UNUSED_23,
|
||||
|
||||
PACKET_CHANGE_LEVEL,
|
||||
PACKET_CHANGE_AREA,
|
||||
|
@ -314,18 +314,6 @@ void network_receive_level_area_inform(struct Packet* p);
|
|||
void network_send_level_respawn_info(struct Object* o, u8 respawnInfoBits);
|
||||
void network_receive_level_respawn_info(struct Packet* p);
|
||||
|
||||
// packet_reservation_list.c
|
||||
void network_send_reservation_list(struct NetworkPlayer* np, u32 syncIds[]);
|
||||
void network_receive_reservation_list(struct Packet* p);
|
||||
|
||||
// packet_reservation_use.c
|
||||
void network_send_reservation_use(u32 syncId);
|
||||
void network_receive_reservation_use(struct Packet* p);
|
||||
|
||||
// packet_reservation_release.c
|
||||
void network_send_reservation_release(u32 syncId);
|
||||
void network_receive_reservation_release(struct Packet* p);
|
||||
|
||||
// packet_debug_sync.c
|
||||
void network_send_debug_sync(void);
|
||||
void network_receive_debug_sync(struct Packet* p);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "game/interaction.h"
|
||||
#include "game/level_update.h"
|
||||
#include "game/area.h"
|
||||
|
@ -15,11 +14,11 @@
|
|||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
u32 sRemoveSyncIds[RESERVED_IDS_SYNC_OBJECT_OFFSET] = { 0 };
|
||||
u32 sRemoveSyncIds[SYNC_ID_BLOCK_SIZE] = { 0 };
|
||||
u32 sRemoveSyncIdsIndex = 0;
|
||||
|
||||
void area_remove_sync_ids_add(u32 syncId) {
|
||||
if (syncId >= RESERVED_IDS_SYNC_OBJECT_OFFSET) { return; }
|
||||
if (syncId >= SYNC_ID_BLOCK_SIZE) { return; }
|
||||
for (u32 i = 0; i < sRemoveSyncIdsIndex; i++) {
|
||||
if (sRemoveSyncIds[i] == syncId) { return; }
|
||||
}
|
||||
|
@ -98,7 +97,7 @@ void network_send_area(struct NetworkPlayer* toNp) {
|
|||
for (struct SyncObject* so = sync_object_get_first(); so != NULL; so = sync_object_get_next()) {
|
||||
if (so == NULL || so->o == NULL || so->o->oSyncID != so->id) { continue; }
|
||||
if (so->o->behavior == smlua_override_behavior(bhvRespawner)) { continue; }
|
||||
if (so->id < RESERVED_IDS_SYNC_OBJECT_OFFSET) { continue; }
|
||||
if (so->id < SYNC_ID_BLOCK_SIZE) { continue; }
|
||||
struct Object* spawn_objects[] = { so->o };
|
||||
|
||||
// TODO: move find model to a utility file/function
|
||||
|
@ -235,7 +234,7 @@ void network_receive_area(struct Packet* p) {
|
|||
}
|
||||
|
||||
LOG_INFO("rx respawner");
|
||||
if (syncId < RESERVED_IDS_SYNC_OBJECT_OFFSET) {
|
||||
if (syncId < SYNC_ID_BLOCK_SIZE) {
|
||||
struct Object* respawner = spawn_object_abs_with_rot(gMarioStates[0].marioObj, 0, MODEL_NONE, bhvRespawner, posX, posY, posZ, 0, 0, 0);
|
||||
if (respawner != NULL) {
|
||||
respawner->parentObj = respawner;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "level_table.h"
|
||||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
|
@ -9,7 +8,6 @@ static void player_changed_area(struct NetworkPlayer *np, s16 courseNum, s16 act
|
|||
// set NetworkPlayer variables
|
||||
np->currAreaSyncValid = false;
|
||||
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
|
||||
reservation_area_change(np);
|
||||
|
||||
// find a NetworkPlayer at that area
|
||||
struct NetworkPlayer *npLevelAreaMatch = get_network_player_from_area(courseNum, actNum, levelNum, areaIndex);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "level_table.h"
|
||||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
static void player_changed_level(struct NetworkPlayer *np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
|
||||
|
@ -10,7 +8,6 @@ static void player_changed_level(struct NetworkPlayer *np, s16 courseNum, s16 ac
|
|||
np->currLevelSyncValid = false;
|
||||
np->currAreaSyncValid = false;
|
||||
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
|
||||
reservation_area_change(np);
|
||||
|
||||
// find a NetworkPlayer around that location
|
||||
struct NetworkPlayer *npLevelAreaMatch = get_network_player_from_area(courseNum, actNum, levelNum, areaIndex);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "pc/djui/djui.h"
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "object_fields.h"
|
||||
#include "object_constants.h"
|
||||
#include "behavior_data.h"
|
||||
|
@ -353,11 +352,6 @@ void network_send_object_reliability(struct Object* o, bool reliable) {
|
|||
// check for object death
|
||||
if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) {
|
||||
sync_object_forget(so->id);
|
||||
if (gNetworkType == NT_SERVER) {
|
||||
reservation_area_release(gNetworkPlayerLocal, syncId);
|
||||
} else {
|
||||
network_send_reservation_release(syncId);
|
||||
}
|
||||
} else if (so->rememberLastReliablePacket) {
|
||||
// remember packet
|
||||
packet_duplicate(&p, &so->lastReliablePacket);
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "object_fields.h"
|
||||
#include "object_constants.h"
|
||||
#include "behavior_table.h"
|
||||
#include "course_table.h"
|
||||
#include "src/game/interaction.h"
|
||||
#include "src/engine/math_util.h"
|
||||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
void network_send_reservation_list(struct NetworkPlayer* np, u32 syncIds[]) {
|
||||
SOFT_ASSERT(gNetworkType == NT_SERVER);
|
||||
|
||||
struct Packet p = { 0 };
|
||||
packet_init(&p, PACKET_RESERVATION_LIST, true, PLMT_NONE);
|
||||
|
||||
packet_write(&p, &np->currCourseNum, sizeof(s16));
|
||||
packet_write(&p, &np->currActNum, sizeof(s16));
|
||||
packet_write(&p, &np->currLevelNum, sizeof(s16));
|
||||
packet_write(&p, &np->currAreaIndex, sizeof(s16));
|
||||
|
||||
for (s32 i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) {
|
||||
packet_write(&p, &syncIds[i], sizeof(u32));
|
||||
}
|
||||
|
||||
network_send_to(np->localIndex, &p);
|
||||
LOG_INFO("tx reservation list");
|
||||
}
|
||||
|
||||
void network_receive_reservation_list(struct Packet* p) {
|
||||
SOFT_ASSERT(gNetworkType == NT_CLIENT);
|
||||
LOG_INFO("rx reservation list");
|
||||
|
||||
s16 courseNum, actNum, levelNum, areaIndex;
|
||||
packet_read(p, &courseNum, sizeof(s16));
|
||||
packet_read(p, &actNum, sizeof(s16));
|
||||
packet_read(p, &levelNum, sizeof(s16));
|
||||
packet_read(p, &areaIndex, sizeof(s16));
|
||||
|
||||
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex;
|
||||
if (courseNum != gCurrCourseNum || actNum != gCurrActStarNum || levelNum != gCurrLevelNum || areaIndex != gCurrAreaIndex) {
|
||||
LOG_ERROR("received an improper location");
|
||||
return;
|
||||
}
|
||||
|
||||
u32 syncIds[RESERVED_IDS_PER_PLAYER_COUNT];
|
||||
for (s32 i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) {
|
||||
packet_read(p, &syncIds[i], sizeof(u32));
|
||||
}
|
||||
|
||||
reservation_area_local_update(courseNum, actNum, levelNum, areaIndex, syncIds);
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "object_fields.h"
|
||||
#include "object_constants.h"
|
||||
#include "behavior_table.h"
|
||||
#include "course_table.h"
|
||||
#include "src/game/interaction.h"
|
||||
#include "src/engine/math_util.h"
|
||||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
void network_send_reservation_release(u32 syncId) {
|
||||
SOFT_ASSERT(gNetworkType == NT_CLIENT);
|
||||
|
||||
// make sure this is a reserved id
|
||||
if (syncId < RESERVED_IDS_SYNC_OBJECT_OFFSET) { return; }
|
||||
|
||||
struct Packet p = { 0 };
|
||||
packet_init(&p, PACKET_RESERVATION_RELEASE, true, PLMT_NONE);
|
||||
|
||||
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex;
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrLevelNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrAreaIndex, sizeof(s16));
|
||||
|
||||
packet_write(&p, &syncId, sizeof(u32));
|
||||
|
||||
network_send_to(gNetworkPlayerServer->localIndex, &p);
|
||||
LOG_INFO("tx reservation release");
|
||||
}
|
||||
|
||||
void network_receive_reservation_release(struct Packet* p) {
|
||||
SOFT_ASSERT(gNetworkType == NT_SERVER);
|
||||
LOG_INFO("rx reservation release");
|
||||
|
||||
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];
|
||||
if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) {
|
||||
LOG_ERROR("Receiving from inactive player!");
|
||||
return;
|
||||
}
|
||||
|
||||
s16 courseNum, actNum, levelNum, areaIndex;
|
||||
packet_read(p, &courseNum, sizeof(s16));
|
||||
packet_read(p, &actNum, sizeof(s16));
|
||||
packet_read(p, &levelNum, sizeof(s16));
|
||||
packet_read(p, &areaIndex, sizeof(s16));
|
||||
|
||||
if (courseNum != np->currCourseNum || actNum != np->currActNum || levelNum != np->currLevelNum || areaIndex != np->currAreaIndex) {
|
||||
LOG_ERROR("received an improper location");
|
||||
return;
|
||||
}
|
||||
|
||||
u32 syncId;
|
||||
packet_read(p, &syncId, sizeof(u32));
|
||||
|
||||
reservation_area_release(np, syncId);
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "object_fields.h"
|
||||
#include "object_constants.h"
|
||||
#include "behavior_table.h"
|
||||
#include "course_table.h"
|
||||
#include "src/game/interaction.h"
|
||||
#include "src/engine/math_util.h"
|
||||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
void network_send_reservation_use(u32 syncId) {
|
||||
SOFT_ASSERT(gNetworkType == NT_CLIENT);
|
||||
|
||||
// make sure this is a reserved id
|
||||
if (syncId < RESERVED_IDS_SYNC_OBJECT_OFFSET) { return; }
|
||||
|
||||
struct Packet p = { 0 };
|
||||
packet_init(&p, PACKET_RESERVATION_USE, true, PLMT_NONE);
|
||||
|
||||
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex;
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrLevelNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrAreaIndex, sizeof(s16));
|
||||
|
||||
packet_write(&p, &syncId, sizeof(u32));
|
||||
|
||||
network_send_to(gNetworkPlayerServer->localIndex, &p);
|
||||
LOG_INFO("tx reservation use");
|
||||
}
|
||||
|
||||
void network_receive_reservation_use(struct Packet* p) {
|
||||
SOFT_ASSERT(gNetworkType == NT_SERVER);
|
||||
LOG_INFO("rx reservation use");
|
||||
|
||||
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];
|
||||
if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) {
|
||||
LOG_ERROR("Receiving from inactive player!");
|
||||
return;
|
||||
}
|
||||
|
||||
s16 courseNum, actNum, levelNum, areaIndex;
|
||||
packet_read(p, &courseNum, sizeof(s16));
|
||||
packet_read(p, &actNum, sizeof(s16));
|
||||
packet_read(p, &levelNum, sizeof(s16));
|
||||
packet_read(p, &areaIndex, sizeof(s16));
|
||||
|
||||
if (courseNum != np->currCourseNum || actNum != np->currActNum|| levelNum != np->currLevelNum || areaIndex != np->currAreaIndex) {
|
||||
LOG_ERROR("received an improper location");
|
||||
return;
|
||||
}
|
||||
|
||||
u32 syncId;
|
||||
packet_read(p, &syncId, sizeof(u32));
|
||||
|
||||
reservation_area_use(np, syncId);
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include "../network.h"
|
||||
#include "../reservation_area.h"
|
||||
#include "object_fields.h"
|
||||
#include "object_constants.h"
|
||||
#include "src/game/object_helpers.h"
|
||||
|
@ -190,7 +189,7 @@ void network_receive_spawn_objects(struct Packet* p) {
|
|||
// correct the temporary parent with the object itself
|
||||
if (data.parentId == (u32)-1) { o->parentObj = o; }
|
||||
|
||||
if (o->oSyncID != 0 && o->oSyncID >= RESERVED_IDS_SYNC_OBJECT_OFFSET) {
|
||||
if (o->oSyncID != 0 && o->oSyncID >= SYNC_ID_BLOCK_SIZE) {
|
||||
// check if they've allocated one of their reserved sync objects
|
||||
struct SyncObject* so = sync_object_get(o->oSyncID);
|
||||
if (so) {
|
||||
|
|
|
@ -1,300 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "reservation_area.h"
|
||||
#include "network.h"
|
||||
#include "object_fields.h"
|
||||
#include "object_constants.h"
|
||||
#include "behavior_table.h"
|
||||
#include "course_table.h"
|
||||
#include "src/game/interaction.h"
|
||||
#include "src/engine/math_util.h"
|
||||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
#define RESERVED_IDS_PER_AREA 127
|
||||
#define RESERVED_IDS_UNRESERVED ((u32)-1)
|
||||
#define RESERVED_IDS_USED ((u32)-2)
|
||||
|
||||
struct ReservationArea {
|
||||
s16 courseNum;
|
||||
s16 actNum;
|
||||
s16 levelNum;
|
||||
s16 areaIndex;
|
||||
u16 playersActive;
|
||||
u32 reservedIds[RESERVED_IDS_PER_AREA];
|
||||
struct ReservationArea* next;
|
||||
};
|
||||
|
||||
struct ReservationArea* sReservationAreas = NULL;
|
||||
struct ReservationArea* sReservationAreaPerPlayer[MAX_PLAYERS] = { NULL };
|
||||
|
||||
struct LocalReservationArea {
|
||||
s16 courseNum;
|
||||
s16 actNum;
|
||||
s16 levelNum;
|
||||
s16 areaIndex;
|
||||
u32 reservedIds[RESERVED_IDS_PER_PLAYER_COUNT];
|
||||
};
|
||||
struct LocalReservationArea sLocalReservationArea = { 0 };
|
||||
|
||||
void reservation_area_debug(void) {
|
||||
printf("\n============ %02d ============\n", gNetworkPlayerLocal->globalIndex);
|
||||
|
||||
printf("reservation area per player:\n");
|
||||
for (s32 i = 0; i < MAX_PLAYERS; i++) {
|
||||
struct ReservationArea* ra = sReservationAreaPerPlayer[i];
|
||||
if (ra != NULL) {
|
||||
printf(" %d : (%d, %d, %d, %d)\n", i, ra->courseNum, ra->actNum, ra->levelNum, ra->areaIndex);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("reservation areas:\n");
|
||||
struct ReservationArea* ra = sReservationAreas;
|
||||
while (ra != NULL) {
|
||||
printf(" (%d, %d, %d, %d) : %d\n", ra->courseNum, ra->actNum, ra->levelNum, ra->areaIndex, ra->playersActive);
|
||||
|
||||
printf(" ");
|
||||
u32 idsUntilBreak = 10;
|
||||
for (int i = 0; i < RESERVED_IDS_PER_AREA; i++) {
|
||||
switch (ra->reservedIds[i])
|
||||
{
|
||||
case RESERVED_IDS_UNRESERVED: printf("UNR "); break;
|
||||
case RESERVED_IDS_USED: printf("USD "); break;
|
||||
default: printf("%03d ", ra->reservedIds[i]); break;
|
||||
}
|
||||
if (--idsUntilBreak == 0) {
|
||||
printf("\n ");
|
||||
idsUntilBreak = 10;
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
ra = ra->next;
|
||||
}
|
||||
|
||||
printf("local reservation area:\n");
|
||||
struct LocalReservationArea* la = &sLocalReservationArea;
|
||||
printf(" (%d, %d, %d, %d) : ", la->courseNum, la->actNum, la->levelNum, la->areaIndex);
|
||||
for (int i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) {
|
||||
switch (la->reservedIds[i])
|
||||
{
|
||||
case RESERVED_IDS_UNRESERVED: printf("UNR "); break;
|
||||
case RESERVED_IDS_USED: printf("USD "); break;
|
||||
default: printf("%03d ", la->reservedIds[i]); break;
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
static void reservation_area_refresh_ids(struct NetworkPlayer* np) {
|
||||
bool informPlayer = false;
|
||||
|
||||
// make sure player has a RA
|
||||
struct ReservationArea* ra = sReservationAreaPerPlayer[np->globalIndex];
|
||||
if (ra == NULL) { return; }
|
||||
|
||||
// count current reserved ids
|
||||
u32 reservedIds[RESERVED_IDS_PER_PLAYER_COUNT] = { RESERVED_IDS_UNRESERVED };
|
||||
u32 reservedIdCount = 0;
|
||||
for (int i = 0; i < RESERVED_IDS_PER_AREA; i++) {
|
||||
if (ra->reservedIds[i] != np->globalIndex) { continue; }
|
||||
reservedIds[reservedIdCount] = i + RESERVED_IDS_SYNC_OBJECT_OFFSET;
|
||||
reservedIdCount++;
|
||||
}
|
||||
|
||||
// fill in missing reserved ids
|
||||
if (reservedIdCount < RESERVED_IDS_PER_PLAYER_COUNT) {
|
||||
for (int i = 0; i < RESERVED_IDS_PER_AREA; i++) {
|
||||
if (ra->reservedIds[i] != RESERVED_IDS_UNRESERVED) { continue; }
|
||||
ra->reservedIds[i] = np->globalIndex;
|
||||
informPlayer = true;
|
||||
reservedIds[reservedIdCount] = i + RESERVED_IDS_SYNC_OBJECT_OFFSET;
|
||||
reservedIdCount++;
|
||||
if (reservedIdCount >= RESERVED_IDS_PER_PLAYER_COUNT) { break; }
|
||||
}
|
||||
}
|
||||
|
||||
if (gNetworkType == NT_SERVER && np == gNetworkPlayerLocal) {
|
||||
// refresh server's local
|
||||
sLocalReservationArea.courseNum = np->currCourseNum;
|
||||
sLocalReservationArea.actNum = np->currActNum;
|
||||
sLocalReservationArea.levelNum = np->currLevelNum;
|
||||
sLocalReservationArea.areaIndex = np->currAreaIndex;
|
||||
|
||||
for (int i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) {
|
||||
sLocalReservationArea.reservedIds[i] = reservedIds[i];
|
||||
}
|
||||
} else if (informPlayer) {
|
||||
// inform remote player of reservation list
|
||||
network_send_reservation_list(np, reservedIds);
|
||||
}
|
||||
}
|
||||
|
||||
static void reservation_area_unload(struct ReservationArea* unloadRa) {
|
||||
struct ReservationArea* ra = sReservationAreas;
|
||||
struct ReservationArea* lastRa = NULL;
|
||||
while (ra != NULL) {
|
||||
if (ra == unloadRa) {
|
||||
if (lastRa == NULL) {
|
||||
sReservationAreas = ra->next;
|
||||
} else {
|
||||
lastRa->next = ra->next;
|
||||
}
|
||||
free(unloadRa);
|
||||
return;
|
||||
}
|
||||
lastRa = ra;
|
||||
ra = ra->next;
|
||||
}
|
||||
SOFT_ASSERT(false);
|
||||
}
|
||||
|
||||
static void reservation_area_player_left(struct NetworkPlayer* np) {
|
||||
// make sure player has a RA
|
||||
struct ReservationArea* ra = sReservationAreaPerPlayer[np->globalIndex];
|
||||
if (ra == NULL) { return; }
|
||||
|
||||
// remove player's reserved ids
|
||||
for (int i = 0; i < RESERVED_IDS_PER_AREA; i++) {
|
||||
if (ra->reservedIds[i] == np->globalIndex) {
|
||||
ra->reservedIds[i] = RESERVED_IDS_UNRESERVED;
|
||||
}
|
||||
}
|
||||
|
||||
// remove player from RA, unload if sensible
|
||||
ra->playersActive--;
|
||||
if (ra->playersActive == 0) {
|
||||
reservation_area_unload(ra);
|
||||
}
|
||||
sReservationAreaPerPlayer[np->globalIndex] = NULL;
|
||||
}
|
||||
|
||||
void reservation_area_change(struct NetworkPlayer* np) {
|
||||
// check for disconnection
|
||||
if (!np->connected) {
|
||||
reservation_area_player_left(np);
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the location actually changed
|
||||
struct ReservationArea* ra = sReservationAreaPerPlayer[np->globalIndex];
|
||||
if (ra != NULL && ra->courseNum == np->currCourseNum && ra->actNum == np->currActNum && ra->levelNum == np->currLevelNum && ra->areaIndex == np->currAreaIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove from the old reservation area
|
||||
reservation_area_player_left(np);
|
||||
|
||||
// find the reservation area
|
||||
ra = sReservationAreas;
|
||||
struct ReservationArea* lastRa = ra;
|
||||
while (ra != NULL) {
|
||||
if (ra->courseNum == np->currCourseNum && ra->actNum == np->currActNum && ra->levelNum == np->currLevelNum && ra->areaIndex == np->currAreaIndex) {
|
||||
// add to new reservation area
|
||||
ra->playersActive++;
|
||||
sReservationAreaPerPlayer[np->globalIndex] = ra;
|
||||
reservation_area_refresh_ids(np);
|
||||
return;
|
||||
}
|
||||
lastRa = ra;
|
||||
ra = ra->next;
|
||||
}
|
||||
|
||||
// allocate the reservation area
|
||||
ra = malloc(sizeof(struct ReservationArea));
|
||||
ra->courseNum = np->currCourseNum;
|
||||
ra->actNum = np->currActNum;
|
||||
ra->levelNum = np->currLevelNum;
|
||||
ra->areaIndex = np->currAreaIndex;
|
||||
for (int i = 0; i < RESERVED_IDS_PER_AREA; i++) {
|
||||
ra->reservedIds[i] = RESERVED_IDS_UNRESERVED;
|
||||
}
|
||||
|
||||
ra->playersActive = 1;
|
||||
ra->next = NULL;
|
||||
|
||||
sReservationAreaPerPlayer[np->globalIndex] = ra;
|
||||
|
||||
// fix up linked list
|
||||
if (lastRa == NULL) {
|
||||
sReservationAreas = ra;
|
||||
} else {
|
||||
lastRa->next = ra;
|
||||
}
|
||||
|
||||
// refresh ids
|
||||
reservation_area_refresh_ids(np);
|
||||
}
|
||||
|
||||
void reservation_area_use(struct NetworkPlayer* np, u32 syncId) {
|
||||
// make sure player has a RA
|
||||
struct ReservationArea* ra = sReservationAreaPerPlayer[np->globalIndex];
|
||||
if (ra == NULL) { return; }
|
||||
|
||||
u32 offset = syncId - RESERVED_IDS_SYNC_OBJECT_OFFSET;
|
||||
|
||||
// sanity check
|
||||
if (offset >= RESERVED_IDS_PER_AREA) { return; }
|
||||
|
||||
ra->reservedIds[offset] = RESERVED_IDS_USED;
|
||||
|
||||
reservation_area_refresh_ids(np);
|
||||
}
|
||||
|
||||
void reservation_area_release(struct NetworkPlayer* np, u32 syncId) {
|
||||
// make sure player has a RA
|
||||
struct ReservationArea* ra = sReservationAreaPerPlayer[np->globalIndex];
|
||||
if (ra == NULL) { return; }
|
||||
|
||||
u32 offset = syncId - RESERVED_IDS_SYNC_OBJECT_OFFSET;
|
||||
|
||||
// sanity check
|
||||
if (offset >= RESERVED_IDS_PER_AREA) { return; }
|
||||
|
||||
ra->reservedIds[offset] = RESERVED_IDS_UNRESERVED;
|
||||
|
||||
reservation_area_refresh_ids(np);
|
||||
}
|
||||
|
||||
void reservation_area_local_update(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex, u32 syncIds[]) {
|
||||
sLocalReservationArea.courseNum = courseNum;
|
||||
sLocalReservationArea.actNum = actNum;
|
||||
sLocalReservationArea.levelNum = levelNum;
|
||||
sLocalReservationArea.areaIndex = areaIndex;
|
||||
|
||||
for (int i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) {
|
||||
sLocalReservationArea.reservedIds[i] = syncIds[i];
|
||||
}
|
||||
}
|
||||
|
||||
u32 reservation_area_local_grab_id(void) {
|
||||
struct LocalReservationArea* la = &sLocalReservationArea;
|
||||
|
||||
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex;
|
||||
if (la->courseNum != gCurrCourseNum || la->actNum != gCurrActStarNum || la->levelNum != gCurrLevelNum || la->areaIndex != gCurrAreaIndex) {
|
||||
// invalid location
|
||||
return 0;
|
||||
}
|
||||
|
||||
// grab a sync id from reserved list
|
||||
u32 syncId = 0;
|
||||
for (int i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) {
|
||||
if (la->reservedIds[i] == 0 || la->reservedIds[i] == RESERVED_IDS_UNRESERVED || la->reservedIds[i] == RESERVED_IDS_USED) { continue; }
|
||||
|
||||
// found one
|
||||
syncId = la->reservedIds[i];
|
||||
la->reservedIds[i] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// sanity check
|
||||
if (syncId == 0) { return 0; }
|
||||
|
||||
// inform the server that we used that id
|
||||
if (gNetworkType == NT_SERVER) {
|
||||
reservation_area_use(gNetworkPlayerLocal, syncId);
|
||||
} else {
|
||||
network_send_reservation_use(syncId);
|
||||
}
|
||||
|
||||
return syncId;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef RESERVATION_AREA_H
|
||||
#define RESERVATION_AREA_H
|
||||
|
||||
#include "PR/ultratypes.h"
|
||||
#include <time.h>
|
||||
#include <types.h>
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define RESERVED_IDS_PER_PLAYER_COUNT 5
|
||||
#define RESERVED_IDS_SYNC_OBJECT_OFFSET 2048
|
||||
|
||||
struct NetworkPlayer;
|
||||
|
||||
void reservation_area_debug(void);
|
||||
void reservation_area_change(struct NetworkPlayer* np);
|
||||
void reservation_area_use(struct NetworkPlayer* np, u32 syncId);
|
||||
void reservation_area_release(struct NetworkPlayer* np, u32 syncId);
|
||||
void reservation_area_local_update(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex, u32 syncIds[]);
|
||||
u32 reservation_area_local_grab_id(void);
|
||||
|
||||
#endif
|
|
@ -4,7 +4,6 @@
|
|||
#include "behavior_table.h"
|
||||
#include "object_constants.h"
|
||||
#include "object_fields.h"
|
||||
#include "reservation_area.h"
|
||||
#include "game/area.h"
|
||||
#include "game/object_list_processor.h"
|
||||
#include "game/obj_behaviors.h"
|
||||
|
@ -89,7 +88,7 @@ void sync_object_forget(u32 syncId) {
|
|||
if (!so) { return; }
|
||||
|
||||
// invalidate last packet sent
|
||||
if (so != NULL && so->o != NULL && so->o->oSyncID < RESERVED_IDS_SYNC_OBJECT_OFFSET) {
|
||||
if (so != NULL && so->o != NULL && so->o->oSyncID < SYNC_ID_BLOCK_SIZE) {
|
||||
u32 syncId2 = so->o->oSyncID;
|
||||
struct SyncObject* so2 = sync_object_get(syncId2);
|
||||
if (so == so2) {
|
||||
|
@ -361,8 +360,8 @@ bool sync_object_should_own(u32 syncId) {
|
|||
}
|
||||
|
||||
u32 sync_object_get_available_local_id() {
|
||||
u32 startId = (gNetworkPlayers[0].globalIndex + 1) * RESERVED_IDS_SYNC_OBJECT_OFFSET;
|
||||
u32 endId = startId + RESERVED_IDS_SYNC_OBJECT_OFFSET;
|
||||
u32 startId = (gNetworkPlayers[0].globalIndex + 1) * SYNC_ID_BLOCK_SIZE;
|
||||
u32 endId = startId + SYNC_ID_BLOCK_SIZE;
|
||||
for (u32 id = startId; id < endId; id++) {
|
||||
struct SyncObject* so = sync_object_get(id);
|
||||
if (so) { continue; }
|
||||
|
@ -375,10 +374,10 @@ bool sync_object_set_id(struct Object* o) {
|
|||
u32 syncId = o->oSyncID;
|
||||
if (syncId == 0) {
|
||||
if (!gNetworkAreaLoaded) {
|
||||
// while loading, just fill in sync ids from 1 to RESERVED_IDS_SYNC_OBJECT_OFFSET
|
||||
for (s32 i = 1; i < RESERVED_IDS_SYNC_OBJECT_OFFSET; i++) {
|
||||
// while loading, just fill in sync ids from 1 to SYNC_ID_BLOCK_SIZE
|
||||
for (s32 i = 1; i < SYNC_ID_BLOCK_SIZE; i++) {
|
||||
sNextSyncId++;
|
||||
sNextSyncId = sNextSyncId % RESERVED_IDS_SYNC_OBJECT_OFFSET;
|
||||
sNextSyncId = sNextSyncId % SYNC_ID_BLOCK_SIZE;
|
||||
struct SyncObject* so = sync_object_get(sNextSyncId);
|
||||
if (so && so->o != NULL) { continue; }
|
||||
syncId = sNextSyncId;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define SYNC_OBJECT_H
|
||||
|
||||
#define MAX_SYNC_OBJECT_FIELDS 64
|
||||
#define SYNC_ID_BLOCK_SIZE 4096
|
||||
|
||||
#include "pc/network/packets/packet.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue