rewrote memory system entirely (hunk, cache, and zone are gone, memory pools replaced...
[xonotic/darkplaces.git] / net_main.c
index 39b57cc..df40cad 100644 (file)
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 See the GNU General Public License for more details.
 
@@ -56,8 +56,8 @@ int messagesReceived = 0;
 int unreliableMessagesSent = 0;
 int unreliableMessagesReceived = 0;
 
-cvar_t net_messagetimeout = {"net_messagetimeout","300"};
-cvar_t hostname = {"hostname", "UNNAMED"};
+cvar_t net_messagetimeout = {0, "net_messagetimeout","300"};
+cvar_t hostname = {CVAR_SAVE, "hostname", "UNNAMED"};
 
 qboolean       configRestored = false;
 
@@ -72,7 +72,7 @@ double                        net_time;
 
 double SetNetTime(void)
 {
-       net_time = Sys_FloatTime();
+       net_time = Sys_DoubleTime();
        return net_time;
 }
 
@@ -284,7 +284,7 @@ void NET_Slist_f (void)
        }
 
        slistInProgress = true;
-       slistStartTime = Sys_FloatTime();
+       slistStartTime = Sys_DoubleTime();
 
        SchedulePollProcedure(&slistSendProcedure, 0.0);
        SchedulePollProcedure(&slistPollProcedure, 0.1);
@@ -304,7 +304,7 @@ static void Slist_Send(void)
                dfunc.SearchForHosts (true);
        }
 
-       if ((Sys_FloatTime() - slistStartTime) < 0.5)
+       if ((Sys_DoubleTime() - slistStartTime) < 0.5)
                SchedulePollProcedure(&slistSendProcedure, 0.75);
 }
 
@@ -323,7 +323,7 @@ static void Slist_Poll(void)
        if (! slistSilent)
                PrintSlist();
 
-       if ((Sys_FloatTime() - slistStartTime) < 1.5)
+       if ((Sys_DoubleTime() - slistStartTime) < 1.5)
        {
                SchedulePollProcedure(&slistPollProcedure, 0.1);
                return;
@@ -641,7 +641,7 @@ int NET_SendToAll(sizebuf_t *data, int blocktime)
                }
        }
 
-       start = Sys_FloatTime();
+       start = Sys_DoubleTime();
        while (count)
        {
                count = 0;
@@ -676,7 +676,7 @@ int NET_SendToAll(sizebuf_t *data, int blocktime)
                                continue;
                        }
                }
-               if ((Sys_FloatTime() - start) > blocktime)
+               if ((Sys_DoubleTime() - start) > blocktime)
                        break;
        }
        return count;
@@ -691,6 +691,8 @@ NET_Init
 ====================
 */
 
+static mempool_t *net_mempool;
+
 void NET_Init (void)
 {
        int                     i;
@@ -720,16 +722,18 @@ void NET_Init (void)
 
        SetNetTime();
 
+       net_mempool = Mem_AllocPool("qsocket");
+       s = Mem_Alloc(net_mempool, net_numsockets * sizeof(qsocket_t));
        for (i = 0; i < net_numsockets; i++)
        {
-               s = (qsocket_t *)Hunk_AllocName(sizeof(qsocket_t), "qsocket");
                s->next = net_freeSockets;
                net_freeSockets = s;
                s->disconnected = true;
+               s++;
        }
 
        // allocate space for network message buffer
-       SZ_Alloc (&net_message, NET_MAXMESSAGE);
+       SZ_Alloc (&net_message, NET_MAXMESSAGE, "net_message");
 
        Cvar_RegisterVariable (&net_messagetimeout);
        Cvar_RegisterVariable (&hostname);
@@ -783,6 +787,8 @@ void                NET_Shutdown (void)
                        net_drivers[net_driverlevel].initialized = false;
                }
        }
+
+       Mem_FreePool(&net_mempool);
 }
 
 
@@ -811,7 +817,7 @@ void SchedulePollProcedure(PollProcedure *proc, double timeOffset)
 {
        PollProcedure *pp, *prev;
 
-       proc->nextTime = Sys_FloatTime() + timeOffset;
+       proc->nextTime = Sys_DoubleTime() + timeOffset;
        for (pp = pollProcedureList, prev = NULL; pp; pp = pp->next)
        {
                if (pp->nextTime >= proc->nextTime)