shithub: choc

Download patch

ref: 6617f41db080196a0e0844c2fcf6e4f982e161b3
parent: 2840213616978c2d806c35b586ff1c4beff0f187
author: Simon Howard <[email protected]>
date: Fri Apr 5 15:42:26 EDT 2013

Split D_InitNetGame() into two separate functions for startup.

Subversion-branch: /branches/v2-branch
Subversion-revision: 2582

--- a/src/d_loop.c
+++ b/src/d_loop.c
@@ -327,11 +327,8 @@
     }
 }
 
-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 @@
     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,48 +493,19 @@
 
         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;
 }
--- a/src/d_loop.h
+++ b/src/d_loop.h
@@ -65,10 +65,14 @@
 // 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;
--- a/src/doom/d_net.c
+++ b/src/doom/d_net.c
@@ -109,16 +109,14 @@
 };
 
 
-// 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 @@
     fastparm = settings->fast_monsters;
     respawnparm = settings->respawn_monsters;
     timelimit = settings->timelimit;
+    consoleplayer = settings->consoleplayer;
 
     if (lowres_turn)
     {
@@ -135,17 +134,8 @@
                "because there is a client recording a Vanilla demo.\n");
     }
 
-    if (!connect_data->drone)
+    for (i = 0; i < MAXPLAYERS; ++i)
     {
-        consoleplayer = settings->consoleplayer;
-    }
-    else
-    {
-        consoleplayer = 0;
-    }
-    
-    for (i=0; i<MAXPLAYERS; ++i) 
-    {
         playeringame[i] = i < settings->num_players;
     }
 }
@@ -153,8 +143,7 @@
 // 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 @@
 
     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 @@
 
     // 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,15 +216,24 @@
     connect_data->is_freedoom = W_CheckNumForName("FREEDOOM") >= 0;
 }
 
-void D_InitSinglePlayerGame(net_gamesettings_t *settings)
+//
+// D_CheckNetGame
+// Works out player numbers among the net participants
+//
+void D_CheckNetGame (void)
 {
-    // default values for single player
+    net_connect_data_t connect_data;
+    net_gamesettings_t settings;
 
-    settings->consoleplayer = 0;
-    settings->num_players = 1;
+    D_RegisterLoopCallbacks(&doom_loop_interface);
 
-    netgame = false;
+    // Call D_QuitNetGame on exit
 
+    I_AtExit(D_QuitNetGame, true);
+
+    InitConnectData(&connect_data);
+    netgame = D_InitNetGame(&connect_data);
+
     //!
     // @category net
     //
@@ -244,36 +246,15 @@
     {
         netgame = true;
     }
-}
 
-//
-// D_CheckNetGame
-// Works out player numbers among the net participants
-//
-void D_CheckNetGame (void)
-{
-    net_connect_data_t connect_data;
-    net_gamesettings_t settings;
-
-    D_RegisterLoopCallbacks(&doom_loop_interface);
-
-    // Call D_QuitNetGame on exit 
-
-    I_AtExit(D_QuitNetGame, true);
-
-    SaveGameSettings(&settings, &connect_data);
-
-    if (D_InitNetGame(&connect_data, &settings))
+    if (netgame)
     {
-        netgame = true;
         autostart = true;
     }
-    else
-    {
-        D_InitSinglePlayerGame(&settings);
-    }
 
-    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);
--- a/src/heretic/d_net.c
+++ b/src/heretic/d_net.c
@@ -112,8 +112,7 @@
 // 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,18 +124,10 @@
     // TODO startloadgame = settings->loadgame;
     nomonsters = settings->nomonsters;
     respawnparm = settings->respawn_monsters;
+    consoleplayer = settings->consoleplayer;
 
-    if (!connect_data->drone)
+    for (i = 0; i < MAXPLAYERS; ++i)
     {
-        consoleplayer = settings->consoleplayer;
-    }
-    else
-    {
-        consoleplayer = 0;
-    }
-    
-    for (i=0; i<MAXPLAYERS; ++i) 
-    {
         playeringame[i] = i < settings->num_players;
     }
 }
@@ -144,8 +135,7 @@
 // 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 @@
     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 @@
     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 @@
 
     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);
 }
--- a/src/hexen/d_net.c
+++ b/src/hexen/d_net.c
@@ -112,8 +112,7 @@
 // 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,16 +124,8 @@
     // 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)
     {
         playeringame[i] = i < settings->num_players;
@@ -150,11 +141,8 @@
 // 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,7 +161,12 @@
     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 @@
     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 @@
 
     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);
 }
 
 //==========================================================================
--- a/src/strife/d_net.c
+++ b/src/strife/d_net.c
@@ -117,8 +117,7 @@
 // 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 @@
     fastparm = settings->fast_monsters;
     respawnparm = settings->respawn_monsters;
     timelimit = settings->timelimit;
+    consoleplayer = settings->consoleplayer;
 
     if (lowres_turn)
     {
@@ -140,17 +140,8 @@
                "because there is a client recording a Vanilla demo.\n");
     }
 
-    if (!connect_data->drone)
+    for (i = 0; i < MAXPLAYERS; ++i)
     {
-        consoleplayer = settings->consoleplayer;
-    }
-    else
-    {
-        consoleplayer = 0;
-    }
-    
-    for (i=0; i<MAXPLAYERS; ++i) 
-    {
         playeringame[i] = i < settings->num_players;
     }
 }
@@ -158,8 +149,7 @@
 // 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 @@
 
     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 @@
 
     // 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 @@
     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 @@
 
     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);
 
     // Strife games are always deathmatch, though -altdeath is
     // supported for respawning items.