From 63712ec1880bf0df7df6c215b01da9bafb9b6976 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 18 Sep 2010 16:58:29 +0000 Subject: Move Doom-specific code from net_client.c into d_net.c. Subversion-branch: /branches/raven-branch Subversion-revision: 2109 --- src/doom/d_net.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'src/doom') diff --git a/src/doom/d_net.c b/src/doom/d_net.c index 464922d4..a081b72a 100644 --- a/src/doom/d_net.c +++ b/src/doom/d_net.c @@ -64,6 +64,7 @@ ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS]; int nettics[MAXPLAYERS]; int maketic; +int recvtic; // Used for original sync code. @@ -214,6 +215,97 @@ void NetUpdate (void) } } +// Called when a player leaves the game + +static void D_PlayerQuitGame(player_t *player) +{ + static char exitmsg[80]; + unsigned int player_num; + + player_num = player - players; + + // Do this the same way as Vanilla Doom does, to allow dehacked + // replacements of this message + + strncpy(exitmsg, DEH_String("Player 1 left the game"), sizeof(exitmsg)); + exitmsg[sizeof(exitmsg) - 1] = '\0'; + + exitmsg[7] += player_num; + + playeringame[player_num] = false; + players[consoleplayer].message = exitmsg; + + // TODO: check if it is sensible to do this: + + if (demorecording) + { + G_CheckDemoStatus (); + } +} + +static void D_Disconnected(void) +{ + int i; + + // In drone mode, the game cannot continue once disconnected. + + if (drone) + { + I_Error("Disconnected from server in drone mode."); + } + + // disconnected from server + + printf("Disconnected from server.\n"); + + for (i=0; i gametic for all players +// a gametic cannot be run until ticcmds are received for it +// from all players. // -ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS]; -int nettics[MAXPLAYERS]; +ticcmd_set_t ticdata[BACKUPTICS]; +ticcmd_t *netcmds; int maketic; int recvtic; @@ -208,10 +216,10 @@ void NetUpdate (void) } #endif - netcmds[consoleplayer][maketic % BACKUPTICS] = cmd; + ticdata[maketic % BACKUPTICS].cmds[consoleplayer] = cmd; + ticdata[maketic % BACKUPTICS].ingame[consoleplayer] = true; ++maketic; - nettics[consoleplayer] = maketic; } } @@ -245,8 +253,6 @@ static void D_PlayerQuitGame(player_t *player) static void D_Disconnected(void) { - int i; - // In drone mode, the game cannot continue once disconnected. if (drone) @@ -257,14 +263,6 @@ static void D_Disconnected(void) // disconnected from server printf("Disconnected from server.\n"); - - for (i=0; i recvtic; + oldnettics = maketic; + + if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3]) + { + skiptics = 1; + // printf ("+"); + } + } } -static int GetLowTic(void) +// Returns true if there are players in the game: + +static boolean PlayersInGame(void) { - int lowtic; + boolean result = false; + unsigned int i; + + // If we are connected to a server, check if there are any players + // in the game. -#ifdef FEATURE_MULTIPLAYER if (net_client_connected) { - int i; - - lowtic = INT_MAX; - - for (i=0; icmds[i]; + cmd->chatchar = 0; + if (cmd->buttons & BT_SPECIAL) + cmd->buttons = 0; + } +} + +static void D_RunTic(ticcmd_set_t *set) +{ + extern boolean advancedemo; + unsigned int i; + + // Check for player quits. + + for (i = 0; i < MAXPLAYERS; ++i) + { + if (playeringame[i] && !set->ingame[i]) + { + D_PlayerQuitGame(&players[i]); + } + } + + netcmds = set->cmds; + + // check that there are players in the game. if not, we cannot + // run a tic. + + if (advancedemo) + D_DoAdvanceDemo (); + + G_Ticker (); +} + +// When running in single player mode, clear all the ingame[] array +// except the consoleplayer. + +static void SinglePlayerClear(ticcmd_set_t *set) +{ + unsigned int i; + + for (i = 0; i < MAXPLAYERS; ++i) + { + if (i != consoleplayer) + { + set->ingame[i] = false; + } + } } // // TryRunTics // -int oldnettics; -int frametics[4]; -int frameon; -int frameskip[4]; -int oldnettics; - -extern boolean advancedemo; void TryRunTics (void) { @@ -601,52 +704,9 @@ void TryRunTics (void) if (counts < 1) counts = 1; - frameon++; - - if (!demoplayback) + if (net_client_connected) { - int keyplayer = -1; - - // ideally maketic should be 1 - 3 tics above lowtic - // if we are consistantly slower, speed up time - - for (i=0 ; i nettics[keyplayer]); - oldnettics = maketic; - - if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3]) - { - skiptics = 1; - // printf ("+"); - } - } + OldNetSync(); } } @@ -678,41 +738,33 @@ void TryRunTics (void) // run the count * ticdup dics while (counts--) { + ticcmd_set_t *set; + + if (!PlayersInGame()) + { + return; + } + + set = &ticdata[(gametic / ticdup) % BACKUPTICS]; + + if (!net_client_connected) + { + SinglePlayerClear(set); + } + for (i=0 ; i lowtic) - I_Error ("gametic>lowtic"); - if (advancedemo) - D_DoAdvanceDemo (); + if (gametic/ticdup > lowtic) + I_Error ("gametic>lowtic"); - G_Ticker (); + D_RunTic(set); gametic++; // modify command for duplicated tics - if (i != ticdup-1) - { - ticcmd_t *cmd; - int buf; - int j; - - buf = (gametic/ticdup)%BACKUPTICS; - for (j=0 ; jchatchar = 0; - if (cmd->buttons & BT_SPECIAL) - cmd->buttons = 0; - } - } + + TicdupSquash(set); } + NetUpdate (); // check for new console commands } } diff --git a/src/doom/doomstat.h b/src/doom/doomstat.h index 40147833..15a8d743 100644 --- a/src/doom/doomstat.h +++ b/src/doom/doomstat.h @@ -289,7 +289,7 @@ extern int rndindex; extern int maketic; extern int nettics[MAXPLAYERS]; -extern ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS]; +extern ticcmd_t *netcmds; extern int ticdup; diff --git a/src/doom/g_game.c b/src/doom/g_game.c index ad7155a0..0aaf8ee7 100644 --- a/src/doom/g_game.c +++ b/src/doom/g_game.c @@ -986,9 +986,9 @@ void G_Ticker (void) if (playeringame[i]) { cmd = &players[i].cmd; - - memcpy (cmd, &netcmds[i][buf], sizeof(ticcmd_t)); - + + memcpy(cmd, &netcmds[i], sizeof(ticcmd_t)); + if (demoplayback) G_ReadDemoTiccmd (cmd); if (demorecording) -- cgit v1.2.3 From 005747a6174d2d5b72e1af196a72cafb9b801a58 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 20 Nov 2010 16:45:27 +0000 Subject: Remove dependency of network code on Doom code. Subversion-branch: /branches/raven-branch Subversion-revision: 2163 --- src/doom/d_net.c | 354 +++++++++++++++++++++++++++++++++++++++---------------- src/doom/d_net.h | 1 - 2 files changed, 252 insertions(+), 103 deletions(-) (limited to 'src/doom') diff --git a/src/doom/d_net.c b/src/doom/d_net.c index a15d3b1a..05d1875f 100644 --- a/src/doom/d_net.c +++ b/src/doom/d_net.c @@ -25,7 +25,7 @@ // //----------------------------------------------------------------------------- - +#include #include "doomfeatures.h" @@ -76,8 +76,7 @@ int recvtic; // Used for original sync code. -int lastnettic; -int skiptics = 0; +static int skiptics = 0; // Reduce the bandwidth needed by sampling game input less and transmitting // less. If ticdup is 2, sample half normal, 3 = one third normal, etc. @@ -94,11 +93,7 @@ fixed_t offsetms; // Use new client syncronisation code -boolean net_cl_new_sync = true; - -// Connected but not participating in the game (observer) - -boolean drone = false; +boolean new_sync = true; // 35 fps clock adjusted by offsetms milliseconds @@ -108,7 +103,7 @@ static int GetAdjustedTime(void) time_ms = I_GetTimeMS(); - if (net_cl_new_sync) + if (new_sync) { // Use the adjustments from net_client.c only if we are // using the new sync mode. @@ -186,7 +181,7 @@ void NetUpdate (void) continue; } - if (net_cl_new_sync) + if (new_sync) { // If playing single player, do not allow tics to buffer // up very far @@ -309,21 +304,144 @@ void D_StartGameLoop(void) lasttime = GetAdjustedTime() / ticdup; } +// Load game settings from the specified structure and +// set global variables. -// -// D_CheckNetGame -// Works out player numbers among the net participants -// -extern int viewangleoffset; +static void LoadGameSettings(net_gamesettings_t *settings) +{ + unsigned int i; -void D_CheckNetGame (void) + deathmatch = settings->deathmatch; + ticdup = settings->ticdup; + extratics = settings->extratics; + startepisode = settings->episode; + startmap = settings->map; + startskill = settings->skill; + startloadgame = settings->loadgame; + lowres_turn = settings->lowres_turn; + nomonsters = settings->nomonsters; + fastparm = settings->fast_monsters; + respawnparm = settings->respawn_monsters; + timelimit = settings->timelimit; + + if (lowres_turn) + { + printf("NOTE: Turning resolution is reduced; this is probably " + "because there is a client recording a Vanilla demo.\n"); + } + + new_sync = settings->new_sync; + + if (new_sync == false) + { + printf("Syncing netgames like Vanilla Doom.\n"); + } + + netgame = true; + autostart = true; + + if (!drone) + { + consoleplayer = settings->consoleplayer; + } + else + { + consoleplayer = 0; + } + + for (i=0; inum_players; + } +} + +// Save the game settings from global variables to the specified +// game settings structure. + +static void SaveGameSettings(net_gamesettings_t *settings, + net_connect_data_t *connect_data) { int i; - int num_players; - // Call D_QuitNetGame on exit + // Fill in game settings structure with appropriate parameters + // for the new game + + settings->deathmatch = deathmatch; + settings->episode = startepisode; + settings->map = startmap; + settings->skill = startskill; + settings->loadgame = startloadgame; + settings->gameversion = gameversion; + settings->nomonsters = nomonsters; + settings->fast_monsters = fastparm; + settings->respawn_monsters = respawnparm; + settings->timelimit = timelimit; + + settings->lowres_turn = M_CheckParm("-record") > 0 + && M_CheckParm("-longtics") == 0; + + //! + // @category net + // + // Use original game sync code. + // + + if (M_CheckParm("-oldsync") > 0) + settings->new_sync = 0; + else + settings->new_sync = 1; + + //! + // @category net + // @arg + // + // Send n extra tics in every packet as insurance against dropped + // packets. + // + + i = M_CheckParm("-extratics"); + + if (i > 0) + settings->extratics = atoi(myargv[i+1]); + else + settings->extratics = 1; - I_AtExit(D_QuitNetGame, true); + //! + // @category net + // @arg + // + // Reduce the resolution of the game by a factor of n, reducing + // the amount of network bandwidth needed. + // + + i = M_CheckParm("-dup"); + + if (i > 0) + settings->ticdup = atoi(myargv[i+1]); + else + settings->ticdup = 1; + + // + // Connect data + // + + // Game type fields: + + connect_data->gamemode = gamemode; + connect_data->gamemission = gamemission; + + // Drone mode? + + connect_data->drone = M_CheckParm("-drone") > 0; + + // Are we recording a demo? Possibly set lowres turn mode + + connect_data->lowres_turn = settings->lowres_turn; +} + +void D_InitSinglePlayerGame(void) +{ + int i; // default values for single player @@ -342,128 +460,160 @@ void D_CheckNetGame (void) recvtic = 0; playeringame[0] = true; +} + +boolean D_InitNetGame(net_connect_data_t *connect_data, + net_gamesettings_t *settings) +{ + net_addr_t *addr = NULL; + int i; #ifdef FEATURE_MULTIPLAYER + //! + // @category net + // + // Start a multiplayer server, listening for connections. + // + + if (M_CheckParm("-server") > 0) { - net_addr_t *addr = NULL; + NET_SV_Init(); + NET_SV_AddModule(&net_loop_server_module); + NET_SV_AddModule(&net_sdl_module); - //! + net_loop_client_module.InitClient(); + addr = net_loop_client_module.ResolveAddress(NULL); + } + else + { + //! // @category net // - // Start a multiplayer server, listening for connections. + // Automatically search the local LAN for a multiplayer + // server and join it. // - if (M_CheckParm("-server") > 0) + i = M_CheckParm("-autojoin"); + + if (i > 0) { - NET_SV_Init(); - NET_SV_AddModule(&net_loop_server_module); - NET_SV_AddModule(&net_sdl_module); + addr = NET_FindLANServer(); - net_loop_client_module.InitClient(); - addr = net_loop_client_module.ResolveAddress(NULL); + if (addr == NULL) + { + I_Error("No server found on local LAN"); + } } - else - { - //! - // @category net - // - // Automatically search the local LAN for a multiplayer - // server and join it. - // - i = M_CheckParm("-autojoin"); + //! + // @arg
+ // @category net + // + // Connect to a multiplayer server running on the given + // address. + // + + i = M_CheckParm("-connect"); - if (i > 0) - { - addr = NET_FindLANServer(); + if (i > 0) + { + net_sdl_module.InitClient(); + addr = net_sdl_module.ResolveAddress(myargv[i+1]); - if (addr == NULL) - { - I_Error("No server found on local LAN"); - } + if (addr == NULL) + { + I_Error("Unable to resolve '%s'\n", myargv[i+1]); } + } + } - //! - // @arg
- // @category net - // - // Connect to a multiplayer server running on the given - // address. - // - - i = M_CheckParm("-connect"); - - if (i > 0) - { - net_sdl_module.InitClient(); - addr = net_sdl_module.ResolveAddress(myargv[i+1]); + if (addr != NULL) + { + if (M_CheckParm("-drone") > 0) + { + connect_data->drone = true; + } - if (addr == NULL) - { - I_Error("Unable to resolve '%s'\n", myargv[i+1]); - } - } + //! + // @category net + // + // Run as the left screen in three screen mode. + // + + if (M_CheckParm("-left") > 0) + { + viewangleoffset = ANG90; + connect_data->drone = true; } - if (addr != NULL) + //! + // @category net + // + // Run as the right screen in three screen mode. + // + + if (M_CheckParm("-right") > 0) { - if (M_CheckParm("-drone") > 0) - { - drone = true; - } + viewangleoffset = ANG270; + connect_data->drone = true; + } - //! - // @category net - // - // Run as the left screen in three screen mode. - // + if (!NET_CL_Connect(addr, connect_data)) + { + I_Error("D_CheckNetGame: Failed to connect to %s\n", + NET_AddrToString(addr)); + } - if (M_CheckParm("-left") > 0) - { - viewangleoffset = ANG90; - drone = true; - } + printf("D_CheckNetGame: Connected to %s\n", NET_AddrToString(addr)); - //! - // @category net - // - // Run as the right screen in three screen mode. - // + // Wait for game start message received from server. - if (M_CheckParm("-right") > 0) - { - viewangleoffset = ANG270; - drone = true; - } + NET_WaitForStart(settings); - if (!NET_CL_Connect(addr)) - { - I_Error("D_CheckNetGame: Failed to connect to %s\n", - NET_AddrToString(addr)); - } + // Read the game settings that were received. - printf("D_CheckNetGame: Connected to %s\n", NET_AddrToString(addr)); + NET_CL_GetSettings(settings); - NET_WaitForStart(); - } + return true; } #endif - num_players = 0; + return false; +} + +// +// D_CheckNetGame +// Works out player numbers among the net participants +// +extern int viewangleoffset; + +void D_CheckNetGame (void) +{ + net_connect_data_t connect_data; + net_gamesettings_t settings; + + // Call D_QuitNetGame on exit - for (i=0; iconsoleplayer; @@ -439,27 +436,14 @@ static void SaveGameSettings(net_gamesettings_t *settings, connect_data->lowres_turn = settings->lowres_turn; } -void D_InitSinglePlayerGame(void) +void D_InitSinglePlayerGame(net_gamesettings_t *settings) { - int i; - // default values for single player - consoleplayer = 0; - netgame = false; - ticdup = 1; - extratics = 1; - lowres_turn = false; - offsetms = 0; - - for (i=0; iconsoleplayer = 0; + settings->num_players = 1; - playeringame[0] = true; + netgame = false; //! // @category net @@ -609,6 +593,9 @@ void D_CheckNetGame (void) net_connect_data_t connect_data; net_gamesettings_t settings; + offsetms = 0; + recvtic = 0; + // Call D_QuitNetGame on exit I_AtExit(D_QuitNetGame, true); @@ -617,13 +604,16 @@ void D_CheckNetGame (void) if (D_InitNetGame(&connect_data, &settings)) { - LoadGameSettings(&settings); + netgame = true; + autostart = true; } else { - D_InitSinglePlayerGame(); + D_InitSinglePlayerGame(&settings); } + LoadGameSettings(&settings); + DEH_printf("startskill %i deathmatch: %i startmap: %i startepisode: %i\n", startskill, deathmatch, startmap, startepisode); -- cgit v1.2.3 From 59d5d0d646f3d4ca1eb2370154db4b4371185e2f Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 11 Dec 2010 01:01:45 +0000 Subject: Fix problem with -autojoin apparently caused by merge error. Subversion-branch: /branches/raven-branch Subversion-revision: 2218 --- src/doom/d_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/doom') diff --git a/src/doom/d_net.c b/src/doom/d_net.c index 93a48b41..73e7368f 100644 --- a/src/doom/d_net.c +++ b/src/doom/d_net.c @@ -479,6 +479,7 @@ boolean D_InitNetGame(net_connect_data_t *connect_data, NET_SV_Init(); NET_SV_AddModule(&net_loop_server_module); NET_SV_AddModule(&net_sdl_module); + NET_SV_RegisterWithMaster(); net_loop_client_module.InitClient(); addr = net_loop_client_module.ResolveAddress(NULL); @@ -497,7 +498,6 @@ boolean D_InitNetGame(net_connect_data_t *connect_data, if (i > 0) { addr = NET_FindLANServer(); - NET_SV_RegisterWithMaster(); if (addr == NULL) { -- cgit v1.2.3