From 64a31a1d630180e1fbe91ce2d3779025a675816f Mon Sep 17 00:00:00 2001 From: Marqt Date: Sat, 26 Nov 2016 17:50:33 +0100 Subject: [PATCH] Fixed synchronisation in multiplayer when using PLAYER mode Former-commit-id: 6c7063182187d275ff819e0e76d7b8ac135a3913 --- src/vizdoom/src/d_net.cpp | 71 ++++++++++++++++++------------------ src/vizdoom/src/viz_main.cpp | 23 ++++++------ src/vizdoom/src/viz_main.h | 6 +-- 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/vizdoom/src/d_net.cpp b/src/vizdoom/src/d_net.cpp index 51d1a17f5..bd7710306 100644 --- a/src/vizdoom/src/d_net.cpp +++ b/src/vizdoom/src/d_net.cpp @@ -69,6 +69,7 @@ EXTERN_CVAR (Bool, viz_controlled) EXTERN_CVAR (Bool, viz_async) EXTERN_CVAR (Bool, viz_allow_input) +EXTERN_CVAR (Int, viz_sync_timeout) EXTERN_CVAR (Bool, viz_nosound) EXTERN_CVAR (Int, disableautosave) @@ -96,7 +97,7 @@ BYTE NetMode = NET_PeerToPeer; // // gametic is the tic about to (or currently being) run // maketic is the tick that hasn't had control made for it yet -// nettics[] has the maketics for all players +// nettics[] has the maketics for all players // // a gametic cannot be run until nettics[] > gametic for all players // @@ -128,8 +129,8 @@ int maketic; int skiptics; int ticdup; -void D_ProcessEvents (void); -void G_BuildTiccmd (ticcmd_t *cmd); +void D_ProcessEvents (void); +void G_BuildTiccmd (ticcmd_t *cmd); void D_DoAdvanceDemo (void); static void SendSetup (DWORD playersdetected[MAXNETNODES], BYTE gotsetup[MAXNETNODES], int len); @@ -422,14 +423,14 @@ int ExpandTics (int low) int mt = maketic / ticdup; delta = low - (mt&0xff); - + if (delta >= -64 && delta <= 64) return (mt&~0xff) + low; if (delta > 64) return (mt&~0xff) - 256 + low; if (delta < -64) return (mt&~0xff) + 256 + low; - + I_Error ("ExpandTics: strange value %i at maketic %i", low, maketic); return 0; } @@ -481,7 +482,7 @@ void HSendPacket (int node, int len) node, ExpandTics(netbuffer[1]), numtics, realretrans, len); - + for (i = 0; i < len; i++) fprintf (debugfile, "%c%2x", i==k?'|':' ', ((BYTE *)netbuffer)[i]); } @@ -584,7 +585,7 @@ bool HGetPacket (void) InBuffer.Push(store); doomcom.remotenode = -1; } - + if (doomcom.remotenode == -1) { bool gotmessage = false; @@ -607,7 +608,7 @@ bool HGetPacket (void) return false; } #endif - + if (debugfile) { int i, k, realretrans; @@ -649,7 +650,7 @@ bool HGetPacket (void) doomcom.remotenode, ExpandTics(netbuffer[1]), numtics, realretrans, doomcom.datalength); - + for (i = 0; i < doomcom.datalength; i++) fprintf (debugfile, "%c%2x", i==k?'|':' ', ((BYTE *)netbuffer)[i]); if (numtics) @@ -671,7 +672,7 @@ bool HGetPacket (void) return false; } - return true; + return true; } void PlayerIsGone (int netnode, int netconsole) @@ -762,7 +763,7 @@ void GetPackets (void) int k; BYTE playerbytes[MAXNETNODES]; int numplayers; - + while ( HGetPacket() ) { if (netbuffer[0] & NCMD_SETUP) @@ -775,12 +776,13 @@ void GetPackets (void) } continue; // extra setup packet } - + netnode = doomcom.remotenode; netconsole = playerfornode[netnode] & ~PL_DRONE; //VIZDOOM_CODE - vizNodesInSync[netconsole] = 1; + vizNodesRecv[netconsole] += 1; + VIZ_InterruptionPoint(); // [RH] Get "ping" times - totally useless, since it's bound to the frequency // packets go out at. @@ -873,9 +875,9 @@ void GetPackets (void) // Figure out what the rest of the bytes are realstart = ExpandTics (netbuffer[1]); realend = (realstart + numtics); - + nodeforplayer[netconsole] = netnode; - + // check for retransmit request if (resendcount[netnode] <= 0 && (netbuffer[0] & NCMD_RETRANSMIT)) { @@ -888,11 +890,11 @@ void GetPackets (void) { resendcount[netnode]--; } - - // check for out of order / duplicated packet + + // check for out of order / duplicated packet if (realend == nettics[netnode]) continue; - + if (realend < nettics[netnode]) { if (debugfile) @@ -900,7 +902,7 @@ void GetPackets (void) realstart, numtics); continue; } - + // check for a missed packet if (realstart > nettics[netnode]) { @@ -1177,7 +1179,7 @@ void NetUpdate (void) switch (net_extratic) { case 0: - default: + default: resendto[i] = lowtic; break; case 1: resendto[i] = MAX(0, lowtic - 1); break; case 2: resendto[i] = nettics[i]; break; @@ -1352,7 +1354,7 @@ void NetUpdate (void) totalavg = lastaverage; } } - + mastertics = nettics[nodeforplayer[Net_Arbitrator]] + totalavg; } if (nettics[0] <= mastertics) @@ -1881,7 +1883,7 @@ void TryRunTics (void) // } VIZ_DebugMsg(2, VIZ_FUNC, "gametic: %d, lowtic %d, availabletics: %d, realtics: %d, counts: %d", gametic, lowtic, availabletics, realtics, counts); - + // Uncapped framerate needs seprate checks if (counts == 0 && !doWait) { @@ -1907,18 +1909,17 @@ void TryRunTics (void) realtics, availabletics, counts); //VIZDOOM_CODE - vizNetticsSum = netticsSum; if(*viz_controlled && !*viz_async && netgame){ - int syncCount; + int lowRecv; + unsigned int enterTime = I_MSTime (); do { - syncCount = 0; NetUpdate(); - for (i = 0; i < numplaying; ++i) - syncCount += vizNodesInSync[i]; - } while(syncCount!= numplaying); + lowRecv = INT_MAX; - for (i = 0; i < MAXPLAYERS; i++) - vizNodesInSync[i] = 0; + for (i = 1; i < numplaying; i++) { + if (lowRecv > vizNodesRecv[i]) lowRecv = vizNodesRecv[i]; + } + } while(lowRecv == lowtic && *viz_sync_timeout * numplaying > I_MSTime() - enterTime); } // wait for new tics if needed @@ -2097,7 +2098,7 @@ void FDynamicBuffer::SetData (const BYTE *data, int len) m_Len = len; memcpy (m_Data, data, len); } - else + else { m_Len = 0; } @@ -2144,7 +2145,7 @@ static int RemoveClass(const PClass *cls) player = true; continue; } - removecount++; + removecount++; actor->ClearCounters(); actor->Destroy(); } @@ -2366,7 +2367,7 @@ void Net_DoCommand (int type, BYTE **stream, int player) { if (type == DEM_SUMMONFRIEND || type == DEM_SUMMONFRIEND2 || type == DEM_SUMMONMBF) { - if (spawned->CountsAsKill()) + if (spawned->CountsAsKill()) { level.total_monsters--; } @@ -2563,7 +2564,7 @@ void Net_DoCommand (int type, BYTE **stream, int player) break; case DEM_CROUCH: - if (gamestate == GS_LEVEL && players[player].mo != NULL && + if (gamestate == GS_LEVEL && players[player].mo != NULL && players[player].health > 0 && !(players[player].oldbuttons & BT_JUMP) && !P_IsPlayerTotallyFrozen(&players[player])) { @@ -2727,7 +2728,7 @@ static void RunScript(BYTE **stream, APlayerPawn *pawn, int snum, int argn, int { int arg[4] = { 0, 0, 0, 0 }; int i; - + for (i = 0; i < argn; ++i) { int argval = ReadLong(stream); diff --git a/src/vizdoom/src/viz_main.cpp b/src/vizdoom/src/viz_main.cpp index 4bf01777b..3f44ea031 100644 --- a/src/vizdoom/src/viz_main.cpp +++ b/src/vizdoom/src/viz_main.cpp @@ -70,7 +70,6 @@ CVAR (Int, viz_debug, 0, CVAR_NOSET) CVAR (Bool, viz_debug_instances, 0, CVAR_NOSET) // prints instance id with every message - // control CVAR (Bool, viz_controlled, false, CVAR_NOSET) CVAR (String, viz_instance_id, "0", CVAR_NOSET) @@ -79,6 +78,7 @@ CVAR (Int, viz_seed, 0, CVAR_NOSET) // modes CVAR (Bool, viz_async, false, CVAR_NOSET) CVAR (Bool, viz_allow_input, false, CVAR_NOSET) +CVAR (Int, viz_sync_timeout, 3500, CVAR_NOSET) // buffers CVAR (Int, viz_screen_format, 0, 0) @@ -113,9 +113,11 @@ CCMD(viz_set_seed){ /* Flow */ /*--------------------------------------------------------------------------------------------------------------------*/ -int vizNetticsSum = -1; -int vizNodesInSync[VIZ_MAX_PLAYERS]; -int vizNodesLastSync[VIZ_MAX_PLAYERS]; +int vizTime = 0; +bool vizNextTic = false; +bool vizUpdate = false; +int vizLastUpdate = 0; +int vizNodesRecv[VIZ_MAX_PLAYERS]; int vizSavedTime = 0; bool vizFreeze = false; @@ -123,11 +125,6 @@ int (*_I_GetTime)(bool); int (*_I_WaitForTic)(int); void (*_I_FreezeTime)(bool); -int vizTime = 0; -bool vizNextTic = false; -bool vizUpdate = false; -unsigned int vizLastUpdate = 0; - int VIZ_GetTime(bool saveMS){ if(saveMS) vizSavedTime = vizTime; return vizTime; @@ -170,6 +167,8 @@ void VIZ_Init(){ I_WaitForTic = &VIZ_WaitForTic; I_FreezeTime = &VIZ_FreezeTime; } + + //for(size_t i = 0; i < VIZ_MAX_PLAYERS; ++i) vizNodesRecv[i] = 0; } } @@ -221,7 +220,7 @@ void VIZ_Tic(){ } void VIZ_Update(){ - VIZ_DebugMsg(3, VIZ_FUNC, "tic: %d, vizTime: %d, lastupdate: %d", gametic, vizTime, vizLastUpdate); + VIZ_DebugMsg(3, VIZ_FUNC, "tic: %d, vizTime: %d, lastupdate: %d", gametic, VIZ_TIME, vizLastUpdate); if(!*viz_nocheat){ VIZ_D_MapDisplay(); @@ -231,7 +230,7 @@ void VIZ_Update(){ VIZ_ScreenUpdate(); VIZ_GameStateUpdateLabels(); - vizLastUpdate = vizTime; + vizLastUpdate = VIZ_TIME; vizUpdate = false; } @@ -437,7 +436,7 @@ void VIZ_InterruptionPoint(){ try{ bt::interruption_point(); } - catch(b::thread_interrupted &ex ){ + catch(b::thread_interrupted &ex){ exit(0); } } diff --git a/src/vizdoom/src/viz_main.h b/src/vizdoom/src/viz_main.h index 46fd6b15e..3b442ce94 100644 --- a/src/vizdoom/src/viz_main.h +++ b/src/vizdoom/src/viz_main.h @@ -26,12 +26,10 @@ #include "viz_defines.h" extern int vizTime; -extern int vizNetticsSum; -extern int vizNodesInSync[VIZ_MAX_PLAYERS]; -extern int vizNodesLastSync[VIZ_MAX_PLAYERS]; extern bool vizNextTic; extern bool vizUpdate; -extern unsigned int vizLastUpdate; +extern int vizLastUpdate; +extern int vizNodesRecv[VIZ_MAX_PLAYERS]; void VIZ_Init();