diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/d_loop.c | 82 | ||||
-rw-r--r-- | src/d_loop.h | 12 | ||||
-rw-r--r-- | src/doom/d_net.c | 77 | ||||
-rw-r--r-- | src/heretic/d_net.c | 67 | ||||
-rw-r--r-- | src/hexen/d_net.c | 71 | ||||
-rw-r--r-- | src/strife/d_net.c | 70 |
6 files changed, 160 insertions, 219 deletions
diff --git a/src/d_loop.c b/src/d_loop.c index 618c7240..a22c1bd2 100644 --- a/src/d_loop.c +++ b/src/d_loop.c @@ -327,11 +327,8 @@ void D_BlockUntilStart(net_gamesettings_t *settings) } } -boolean D_InitNetGame(net_connect_data_t *connect_data, - net_gamesettings_t *settings) +void D_StartNetGame(net_gamesettings_t *settings) { - net_addr_t *addr = NULL; - boolean result = false; int i; offsetms = 0; @@ -381,6 +378,50 @@ boolean D_InitNetGame(net_connect_data_t *connect_data, else settings->ticdup = 1; + if (net_client_connected) + { + // Send our game settings and block until game start is received + // from the server. + + NET_CL_StartGame(settings); + D_BlockUntilStart(settings); + + // Read the game settings that were received. + + NET_CL_GetSettings(settings); + } + + if (drone) + { + settings->consoleplayer = 0; + } + + // Set the local player and playeringame[] values. + + localplayer = settings->consoleplayer; + + for (i = 0; i < NET_MAXPLAYERS; ++i) + { + local_playeringame[i] = i < settings->num_players; + } + + // Copy settings to global variables. + + ticdup = settings->ticdup; + new_sync = settings->new_sync; + + if (!new_sync) + { + printf("Syncing netgames like Vanilla Doom.\n"); + } +} + +boolean D_InitNetGame(net_connect_data_t *connect_data) +{ + boolean result = false; + net_addr_t *addr = NULL; + int i; + #ifdef FEATURE_MULTIPLAYER //! @@ -452,49 +493,20 @@ boolean D_InitNetGame(net_connect_data_t *connect_data, if (!NET_CL_Connect(addr, connect_data)) { - I_Error("D_CheckNetGame: Failed to connect to %s\n", + I_Error("D_InitNetGame: Failed to connect to %s\n", NET_AddrToString(addr)); } - printf("D_CheckNetGame: Connected to %s\n", NET_AddrToString(addr)); + printf("D_InitNetGame: Connected to %s\n", NET_AddrToString(addr)); // Wait for launch message received from server. NET_WaitForLaunch(); - // Send our game settings and block until game start is received - // from the server. - - NET_CL_StartGame(settings); - D_BlockUntilStart(settings); - - // Read the game settings that were received. - - NET_CL_GetSettings(settings); - result = true; } - #endif - // Set the local player and playeringame[] values. - - localplayer = settings->consoleplayer; - - for (i = 0; i < NET_MAXPLAYERS; ++i) - { - local_playeringame[i] = i < settings->num_players; - } - - // Check for sync mode. - - new_sync = settings->new_sync; - - if (new_sync == false) - { - printf("Syncing netgames like Vanilla Doom.\n"); - } - return result; } diff --git a/src/d_loop.h b/src/d_loop.h index d6d7a026..9ff30b4c 100644 --- a/src/d_loop.h +++ b/src/d_loop.h @@ -65,10 +65,14 @@ void TryRunTics (void); // Called at start of game loop to initialize timers void D_StartGameLoop(void); -// Initialize networking code; structures contain desired game settings, -// these may be changed. -boolean D_InitNetGame(net_connect_data_t *connect_data, - net_gamesettings_t *settings); +// Initialize networking code and connect to server. + +boolean D_InitNetGame(net_connect_data_t *connect_data); + +// Start game with specified settings. The structure will be updated +// with the actual settings for the game. + +void D_StartNetGame(net_gamesettings_t *settings); extern boolean singletics; extern int gametic, ticdup; diff --git a/src/doom/d_net.c b/src/doom/d_net.c index 4ab61425..29e2e7c6 100644 --- a/src/doom/d_net.c +++ b/src/doom/d_net.c @@ -109,16 +109,14 @@ static loop_interface_t doom_loop_interface = { }; -// Load game settings from the specified structure and +// Load game settings from the specified structure and // set global variables. -static void LoadGameSettings(net_gamesettings_t *settings, - net_connect_data_t *connect_data) +static void LoadGameSettings(net_gamesettings_t *settings) { unsigned int i; deathmatch = settings->deathmatch; - ticdup = settings->ticdup; startepisode = settings->episode; startmap = settings->map; startskill = settings->skill; @@ -128,6 +126,7 @@ static void LoadGameSettings(net_gamesettings_t *settings, fastparm = settings->fast_monsters; respawnparm = settings->respawn_monsters; timelimit = settings->timelimit; + consoleplayer = settings->consoleplayer; if (lowres_turn) { @@ -135,16 +134,7 @@ static void LoadGameSettings(net_gamesettings_t *settings, "because there is a client recording a Vanilla demo.\n"); } - if (!connect_data->drone) - { - consoleplayer = settings->consoleplayer; - } - else - { - consoleplayer = 0; - } - - for (i=0; i<MAXPLAYERS; ++i) + for (i = 0; i < MAXPLAYERS; ++i) { playeringame[i] = i < settings->num_players; } @@ -153,8 +143,7 @@ static void LoadGameSettings(net_gamesettings_t *settings, // 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) +static void SaveGameSettings(net_gamesettings_t *settings) { // Fill in game settings structure with appropriate parameters // for the new game @@ -172,9 +161,12 @@ static void SaveGameSettings(net_gamesettings_t *settings, settings->lowres_turn = M_CheckParm("-record") > 0 && M_CheckParm("-longtics") == 0; +} - connect_data->drone = false; +static void InitConnectData(net_connect_data_t *connect_data) +{ connect_data->max_players = MAXPLAYERS; + connect_data->drone = false; //! // @category net @@ -211,7 +203,8 @@ static void SaveGameSettings(net_gamesettings_t *settings, // Are we recording a demo? Possibly set lowres turn mode - connect_data->lowres_turn = settings->lowres_turn; + connect_data->lowres_turn = M_CheckParm("-record") > 0 + && M_CheckParm("-longtics") == 0; // Read checksums of our WAD directory and dehacked information @@ -223,29 +216,6 @@ static void SaveGameSettings(net_gamesettings_t *settings, connect_data->is_freedoom = W_CheckNumForName("FREEDOOM") >= 0; } -void D_InitSinglePlayerGame(net_gamesettings_t *settings) -{ - // default values for single player - - settings->consoleplayer = 0; - settings->num_players = 1; - - netgame = false; - - //! - // @category net - // - // Start the game playing as though in a netgame with a single - // player. This can also be used to play back single player netgame - // demos. - // - - if (M_CheckParm("-solo-net") > 0) - { - netgame = true; - } -} - // // D_CheckNetGame // Works out player numbers among the net participants @@ -257,23 +227,34 @@ void D_CheckNetGame (void) D_RegisterLoopCallbacks(&doom_loop_interface); - // Call D_QuitNetGame on exit + // Call D_QuitNetGame on exit I_AtExit(D_QuitNetGame, true); - SaveGameSettings(&settings, &connect_data); + InitConnectData(&connect_data); + netgame = D_InitNetGame(&connect_data); - if (D_InitNetGame(&connect_data, &settings)) + //! + // @category net + // + // Start the game playing as though in a netgame with a single + // player. This can also be used to play back single player netgame + // demos. + // + + if (M_CheckParm("-solo-net") > 0) { netgame = true; - autostart = true; } - else + + if (netgame) { - D_InitSinglePlayerGame(&settings); + autostart = true; } - LoadGameSettings(&settings, &connect_data); + SaveGameSettings(&settings); + D_StartNetGame(&settings); + LoadGameSettings(&settings); DEH_printf("startskill %i deathmatch: %i startmap: %i startepisode: %i\n", startskill, deathmatch, startmap, startepisode); diff --git a/src/heretic/d_net.c b/src/heretic/d_net.c index 73a09ec6..3950b129 100644 --- a/src/heretic/d_net.c +++ b/src/heretic/d_net.c @@ -112,8 +112,7 @@ static loop_interface_t doom_loop_interface = { // Load game settings from the specified structure and // set global variables. -static void LoadGameSettings(net_gamesettings_t *settings, - net_connect_data_t *connect_data) +static void LoadGameSettings(net_gamesettings_t *settings) { unsigned int i; @@ -125,17 +124,9 @@ static void LoadGameSettings(net_gamesettings_t *settings, // TODO startloadgame = settings->loadgame; nomonsters = settings->nomonsters; respawnparm = settings->respawn_monsters; + consoleplayer = settings->consoleplayer; - if (!connect_data->drone) - { - consoleplayer = settings->consoleplayer; - } - else - { - consoleplayer = 0; - } - - for (i=0; i<MAXPLAYERS; ++i) + for (i = 0; i < MAXPLAYERS; ++i) { playeringame[i] = i < settings->num_players; } @@ -144,8 +135,7 @@ static void LoadGameSettings(net_gamesettings_t *settings, // 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) +static void SaveGameSettings(net_gamesettings_t *settings) { // Fill in game settings structure with appropriate parameters // for the new game @@ -160,7 +150,10 @@ static void SaveGameSettings(net_gamesettings_t *settings, settings->respawn_monsters = respawnparm; settings->timelimit = 0; settings->lowres_turn = false; +} +static void InitConnectData(net_connect_data_t *connect_data) +{ connect_data->drone = false; connect_data->max_players = MAXPLAYERS; @@ -183,29 +176,6 @@ static void SaveGameSettings(net_gamesettings_t *settings, connect_data->is_freedoom = 0; } -void D_InitSinglePlayerGame(net_gamesettings_t *settings) -{ - // default values for single player - - settings->consoleplayer = 0; - settings->num_players = 1; - - netgame = false; - - //! - // @category net - // - // Start the game playing as though in a netgame with a single - // player. This can also be used to play back single player netgame - // demos. - // - - if (M_CheckParm("-solo-net") > 0) - { - netgame = true; - } -} - // // D_CheckNetGame // Works out player numbers among the net participants @@ -222,17 +192,28 @@ void D_CheckNetGame (void) I_AtExit(D_QuitNetGame, true); - SaveGameSettings(&settings, &connect_data); + InitConnectData(&connect_data); + netgame = D_InitNetGame(&connect_data); + + //! + // @category net + // + // Start the game playing as though in a netgame with a single + // player. This can also be used to play back single player netgame + // demos. + // - if (D_InitNetGame(&connect_data, &settings)) + if (M_CheckParm("-solo-net") > 0) { netgame = true; - autostart = true; } - else + + if (netgame) { - D_InitSinglePlayerGame(&settings); + autostart = true; } - LoadGameSettings(&settings, &connect_data); + SaveGameSettings(&settings); + D_StartNetGame(&settings); + LoadGameSettings(&settings); } diff --git a/src/hexen/d_net.c b/src/hexen/d_net.c index 7d663154..16525340 100644 --- a/src/hexen/d_net.c +++ b/src/hexen/d_net.c @@ -112,8 +112,7 @@ static loop_interface_t hexen_loop_interface = { // Load game settings from the specified structure and // set global variables. -static void LoadGameSettings(net_gamesettings_t *settings, - net_connect_data_t *connect_data) +static void LoadGameSettings(net_gamesettings_t *settings) { unsigned int i; @@ -125,15 +124,7 @@ static void LoadGameSettings(net_gamesettings_t *settings, // TODO startloadgame = settings->loadgame; nomonsters = settings->nomonsters; respawnparm = settings->respawn_monsters; - - if (!connect_data->drone) - { - consoleplayer = settings->consoleplayer; - } - else - { - consoleplayer = 0; - } + consoleplayer = settings->consoleplayer; for (i=0; i<MAXPLAYERS; ++i) { @@ -150,11 +141,8 @@ static void LoadGameSettings(net_gamesettings_t *settings, // 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) +static void SaveGameSettings(net_gamesettings_t *settings) { - int i; - // jhaley 20120715: Some parts of the structure are being left // uninitialized. If -class is not used on the command line, this // can lead to a crash in SB_Init due to player class == 0xCCCCCCCC. @@ -173,6 +161,11 @@ static void SaveGameSettings(net_gamesettings_t *settings, settings->respawn_monsters = respawnparm; settings->timelimit = 0; settings->lowres_turn = false; +} + +static void InitConnectData(net_connect_data_t *connect_data) +{ + int i; // // Connect data @@ -213,29 +206,6 @@ static void SaveGameSettings(net_gamesettings_t *settings, connect_data->is_freedoom = 0; } -void D_InitSinglePlayerGame(net_gamesettings_t *settings) -{ - // default values for single player - - settings->consoleplayer = 0; - settings->num_players = 1; - - netgame = false; - - //! - // @category net - // - // Start the game playing as though in a netgame with a single - // player. This can also be used to play back single player netgame - // demos. - // - - if (M_CheckParm("-solo-net") > 0) - { - netgame = true; - } -} - // // D_CheckNetGame // Works out player numbers among the net participants @@ -248,23 +218,34 @@ void D_CheckNetGame (void) D_RegisterLoopCallbacks(&hexen_loop_interface); - // Call D_QuitNetGame on exit + // Call D_QuitNetGame on exit I_AtExit(D_QuitNetGame, true); - SaveGameSettings(&settings, &connect_data); + InitConnectData(&connect_data); + netgame = D_InitNetGame(&connect_data); - if (D_InitNetGame(&connect_data, &settings)) + //! + // @category net + // + // Start the game playing as though in a netgame with a single + // player. This can also be used to play back single player netgame + // demos. + // + + if (M_CheckParm("-solo-net") > 0) { netgame = true; - autostart = true; } - else + + if (netgame) { - D_InitSinglePlayerGame(&settings); + autostart = true; } - LoadGameSettings(&settings, &connect_data); + SaveGameSettings(&settings); + D_StartNetGame(&settings); + LoadGameSettings(&settings); } //========================================================================== diff --git a/src/strife/d_net.c b/src/strife/d_net.c index a3f5513c..355dde56 100644 --- a/src/strife/d_net.c +++ b/src/strife/d_net.c @@ -117,8 +117,7 @@ static loop_interface_t strife_loop_interface = { // Load game settings from the specified structure and // set global variables. -static void LoadGameSettings(net_gamesettings_t *settings, - net_connect_data_t *connect_data) +static void LoadGameSettings(net_gamesettings_t *settings) { unsigned int i; @@ -133,6 +132,7 @@ static void LoadGameSettings(net_gamesettings_t *settings, fastparm = settings->fast_monsters; respawnparm = settings->respawn_monsters; timelimit = settings->timelimit; + consoleplayer = settings->consoleplayer; if (lowres_turn) { @@ -140,16 +140,7 @@ static void LoadGameSettings(net_gamesettings_t *settings, "because there is a client recording a Vanilla demo.\n"); } - if (!connect_data->drone) - { - consoleplayer = settings->consoleplayer; - } - else - { - consoleplayer = 0; - } - - for (i=0; i<MAXPLAYERS; ++i) + for (i = 0; i < MAXPLAYERS; ++i) { playeringame[i] = i < settings->num_players; } @@ -158,8 +149,7 @@ static void LoadGameSettings(net_gamesettings_t *settings, // 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) +static void SaveGameSettings(net_gamesettings_t *settings) { // Fill in game settings structure with appropriate parameters // for the new game @@ -177,7 +167,10 @@ static void SaveGameSettings(net_gamesettings_t *settings, settings->lowres_turn = M_CheckParm("-record") > 0 && M_CheckParm("-longtics") == 0; +} +static void InitConnectData(net_connect_data_t *connect_data) +{ connect_data->drone = false; connect_data->max_players = MAXPLAYERS; @@ -216,7 +209,8 @@ static void SaveGameSettings(net_gamesettings_t *settings, // Are we recording a demo? Possibly set lowres turn mode - connect_data->lowres_turn = settings->lowres_turn; + connect_data->lowres_turn = M_CheckParm("-record") > 0 + && M_CheckParm("-longtics") == 0; // Read checksums of our WAD directory and dehacked information @@ -226,29 +220,6 @@ static void SaveGameSettings(net_gamesettings_t *settings, connect_data->is_freedoom = 0; } -void D_InitSinglePlayerGame(net_gamesettings_t *settings) -{ - // default values for single player - - settings->consoleplayer = 0; - settings->num_players = 1; - - netgame = false; - - //! - // @category net - // - // Start the game playing as though in a netgame with a single - // player. This can also be used to play back single player netgame - // demos. - // - - if (M_CheckParm("-solo-net") > 0) - { - netgame = true; - } -} - // // D_CheckNetGame // Works out player numbers among the net participants @@ -264,19 +235,30 @@ void D_CheckNetGame (void) I_AtExit(D_QuitNetGame, true); - SaveGameSettings(&settings, &connect_data); + InitConnectData(&connect_data); + netgame = D_InitNetGame(&connect_data); + + //! + // @category net + // + // Start the game playing as though in a netgame with a single + // player. This can also be used to play back single player netgame + // demos. + // - if (D_InitNetGame(&connect_data, &settings)) + if (M_CheckParm("-solo-net") > 0) { netgame = true; - autostart = true; } - else + + if (netgame) { - D_InitSinglePlayerGame(&settings); + autostart = true; } - LoadGameSettings(&settings, &connect_data); + SaveGameSettings(&settings); + D_StartNetGame(&settings); + LoadGameSettings(&settings); // Strife games are always deathmatch, though -altdeath is // supported for respawning items. |