port: net: set client rng at the same time the server sends it

This commit is contained in:
fgsfds committed 2023-12-28 12:10:43 +01:00
1 parent a5d1c25fea
commit 312c752205
5 files changed
+29 -7

No files matched your search

+5
View File
@@ -103,6 +103,9 @@ extern s32 g_NetMode;
extern u32 g_NetTick; extern u32 g_NetTick;
extern u32 g_NetNextSyncId; extern u32 g_NetNextSyncId;
extern u64 g_NetRngSeeds[2];
extern u32 g_NetRngLatch;
extern u32 g_NetInterpTicks; extern u32 g_NetInterpTicks;
extern u32 g_NetServerPort; extern u32 g_NetServerPort;
extern char g_NetLastJoinAddr[NET_MAX_ADDR + 1]; extern char g_NetLastJoinAddr[NET_MAX_ADDR + 1];
@@ -135,6 +138,8 @@ void netServerStageStart(void);
void netServerStageEnd(void); void netServerStageEnd(void);
void netServerKick(struct netclient *cl, const u32 reason); void netServerKick(struct netclient *cl, const u32 reason);
void netClientSyncRng(void);
void netPlayersAllocate(void); void netPlayersAllocate(void);
void netSyncIdsAllocate(void); void netSyncIdsAllocate(void);
+12
View File
@@ -42,6 +42,9 @@ u32 g_NetNextSyncId = 1;
s32 g_NetSimPacketLoss = 0; s32 g_NetSimPacketLoss = 0;
s32 g_NetDebugDraw = 0; s32 g_NetDebugDraw = 0;
u64 g_NetRngSeeds[2];
u32 g_NetRngLatch = 0;
s32 g_NetMaxClients = NET_MAX_CLIENTS; s32 g_NetMaxClients = NET_MAX_CLIENTS;
s32 g_NetNumClients = 0; s32 g_NetNumClients = 0;
struct netclient g_NetClients[NET_MAX_CLIENTS + 1]; // last is an extra temporary client struct netclient g_NetClients[NET_MAX_CLIENTS + 1]; // last is an extra temporary client
@@ -605,6 +608,15 @@ static void netClientEvReceive(struct netclient *cl)
} }
} }
void netClientSyncRng(void)
{
if (g_NetMode == NETMODE_CLIENT && g_NetRngLatch) {
g_NetRngLatch = 0;
g_RngSeed = g_NetRngSeeds[0];
g_Rng2Seed = g_NetRngSeeds[1];
}
}
void netStartFrame(void) void netStartFrame(void)
{ {
if (!g_NetMode) { if (!g_NetMode) {
+3 -5
View File
@@ -29,9 +29,6 @@
#include "net/netbuf.h" #include "net/netbuf.h"
#include "net/netmsg.h" #include "net/netmsg.h"
extern u64 g_RngSeed;
extern u64 g_Rng2Seed;
/* utils */ /* utils */
static inline u32 netbufWriteRooms(struct netbuf *buf, const s16 *rooms, const s32 num) static inline u32 netbufWriteRooms(struct netbuf *buf, const s16 *rooms, const s32 num)
@@ -404,8 +401,9 @@ u32 netmsgSvcStageStartRead(struct netbuf *src, struct netclient *srccl)
g_NetTick = netbufReadU32(src); g_NetTick = netbufReadU32(src);
g_RngSeed = netbufReadU64(src); g_NetRngSeeds[0] = netbufReadU64(src);
g_Rng2Seed = netbufReadU64(src); g_NetRngSeeds[1] = netbufReadU64(src);
g_NetRngLatch = true;
const u8 stagenum = netbufReadU8(src); const u8 stagenum = netbufReadU8(src);
+7 -2
View File
@@ -324,8 +324,13 @@ void lvReset(s32 stagenum)
s32 j; s32 j;
#ifndef PLATFORM_N64 #ifndef PLATFORM_N64
// if we're a server, signal to clients that the level is changing if (g_NetMode == NETMODE_SERVER) {
netServerStageStart(); // if we're a server, signal to clients that the level is changing
netServerStageStart();
} else if (g_NetMode == NETMODE_CLIENT) {
// if we're a client, now is the time to apply the server's RNG seeds
netClientSyncRng();
}
#endif #endif
tilesReset(); tilesReset();
+2
View File
@@ -513,6 +513,8 @@ extern u8 g_ChrBioSlot;
extern u8 g_HangarBioSlot; extern u8 g_HangarBioSlot;
extern u8 g_DtSlot; extern u8 g_DtSlot;
extern u8 var80088bb4; extern u8 var80088bb4;
extern u64 g_RngSeed;
extern u64 g_Rng2Seed;
extern struct vtxstoretype g_VtxstoreTypes[4]; extern struct vtxstoretype g_VtxstoreTypes[4];
extern struct menudialogdef g_FrWeaponListMenuDialog; extern struct menudialogdef g_FrWeaponListMenuDialog;
extern struct menudialogdef g_FrTrainingInfoInGameMenuDialog; extern struct menudialogdef g_FrTrainingInfoInGameMenuDialog;