Skip to content

Commit

Permalink
Improved multiplayer support in sync mode #228
Browse files Browse the repository at this point in the history
  • Loading branch information
mwydmuch committed Aug 1, 2017
1 parent ef95c27 commit cda3ed1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/vizdoom/src/d_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,6 @@ void GetPackets (void)
netnode = doomcom.remotenode;
netconsole = playerfornode[netnode] & ~PL_DRONE;

//VIZDOOM_CODE
vizNodesRecv[netconsole] += 1;
VIZ_InterruptionPoint();

// [RH] Get "ping" times - totally useless, since it's bound to the frequency
// packets go out at.
lastrecvtime[netconsole] = currrecvtime[netconsole];
Expand Down Expand Up @@ -933,6 +929,10 @@ void GetPackets (void)
nettics[nodeforplayer[playerbytes[i]]] = realend;
}
}

//VIZDOOM_CODE
vizNodesRecv[netconsole] += nettics[netnode];
VIZ_InterruptionPoint();
}
}

Expand Down Expand Up @@ -1910,16 +1910,22 @@ void TryRunTics (void)

//VIZDOOM_CODE
if(*viz_controlled && !*viz_async && netgame){
int lowRecv;
unsigned int enterTime = I_MSTime ();
do {
int lowRecv = INT_MAX;

for (i = 1; i < numplaying; i++) {
if (lowRecv > vizNodesRecv[i]) lowRecv = vizNodesRecv[i];
}

unsigned int enterTime = I_MSTime ();
while(lowRecv == lowtic && *viz_sync_timeout > I_MSTime() - enterTime) {
//VIZ_Sleep(1);
NetUpdate();
lowRecv = INT_MAX;
lowRecv = INT_MAX;

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
Expand Down
16 changes: 15 additions & 1 deletion src/vizdoom/src/viz_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
#include <boost/thread.hpp>
#endif

#ifdef VIZ_OS_WIN
#include <Windows.h>
#else
#include <unistd.h>
#endif

#include "viz_main.h"
#include "viz_defines.h"
#include "viz_input.h"
Expand Down Expand Up @@ -83,7 +89,7 @@ CVAR (Bool, viz_cmd_filter, true, 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)
CVAR (Int, viz_sync_timeout, 1000, CVAR_NOSET)

// buffers
CVAR (Int, viz_screen_format, 0, 0)
Expand Down Expand Up @@ -500,3 +506,11 @@ void VIZ_InterruptionPoint(){
}
#endif
}

void VIZ_Sleep(unsigned int ms){
#ifdef VIZ_OS_WIN
Sleep(ms);
#else
usleep(ms);
#endif
}
2 changes: 2 additions & 0 deletions src/vizdoom/src/viz_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ void VIZ_DebugMsg(int level, const char *func, const char *msg, ...);

void VIZ_InterruptionPoint();

void VIZ_Sleep(unsigned int ms);

#endif

0 comments on commit cda3ed1

Please sign in to comment.