]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
replaced World_Clear with World_SetSize and World_UnlinkAll
[xonotic/darkplaces.git] / sv_main.c
index 539568693ea00baa323c578e96b5f5b7979aabed..08a362665455b5f028fc08493b021600897adb48 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -79,6 +79,7 @@ cvar_t sv_friction = {CVAR_NOTIFY, "sv_friction","4", "how fast you slow down"};
 cvar_t sv_gameplayfix_blowupfallenzombies = {0, "sv_gameplayfix_blowupfallenzombies", "1", "causes findradius to detect SOLID_NOT entities such as zombies and corpses on the floor, allowing splash damage to apply to them"};
 cvar_t sv_gameplayfix_delayprojectiles = {0, "sv_gameplayfix_delayprojectiles", "1", "causes entities to not move on the same frame they are spawned, meaning that projectiles wait until the next frame to perform their first move, giving proper interpolation and rocket trails, but making weapons harder to use at low framerates"};
 cvar_t sv_gameplayfix_droptofloorstartsolid = {0, "sv_gameplayfix_droptofloorstartsolid", "1", "prevents items and monsters that start in a solid area from falling out of the level (makes droptofloor treat trace_startsolid as an acceptable outcome)"};
+cvar_t sv_gameplayfix_droptofloorstartsolid_nudgetocorrect = {0, "sv_gameplayfix_droptofloorstartsolid_nudgetocorrect", "1", "tries to nudge stuck items and monsters out of walls before droptofloor is performed"};
 cvar_t sv_gameplayfix_easierwaterjump = {0, "sv_gameplayfix_easierwaterjump", "1", "changes water jumping to make it easier to get out of water (exactly like in QuakeWorld)"};
 cvar_t sv_gameplayfix_findradiusdistancetobox = {0, "sv_gameplayfix_findradiusdistancetobox", "1", "causes findradius to check the distance to the corner of a box rather than the center of the box, makes findradius detect bmodels such as very large doors that would otherwise be unaffected by splash damage"};
 cvar_t sv_gameplayfix_grenadebouncedownslopes = {0, "sv_gameplayfix_grenadebouncedownslopes", "1", "prevents MOVETYPE_BOUNCE (grenades) from getting stuck when fired down a downward sloping surface"};
@@ -148,7 +149,7 @@ cvar_t nehx18 = {0, "nehx18", "0", "nehahra data storage cvar (used in singlepla
 cvar_t nehx19 = {0, "nehx19", "0", "nehahra data storage cvar (used in singleplayer)"};
 cvar_t cutscene = {0, "cutscene", "1", "enables cutscenes in nehahra, can be used by other mods"};
 
-cvar_t sv_autodemo_perclient = {CVAR_SAVE, "sv_autodemo_perclient", "0", "set to 1 to enable autorecorded per-client demos (they'll start to record at the beginning of a match)"};
+cvar_t sv_autodemo_perclient = {CVAR_SAVE, "sv_autodemo_perclient", "0", "set to 1 to enable autorecorded per-client demos (they'll start to record at the beginning of a match); set it to 2 to also record client->server packets (for debugging)"};
 cvar_t sv_autodemo_perclient_nameformat = {CVAR_SAVE, "sv_autodemo_perclient_nameformat", "sv_autodemos/%Y-%m-%d_%H-%M", "The format of the sv_autodemo_perclient filename, followed by the map name, the IP address + port number, and the client number, separated by underscores" };
 
 
@@ -349,6 +350,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_gameplayfix_blowupfallenzombies);
        Cvar_RegisterVariable (&sv_gameplayfix_delayprojectiles);
        Cvar_RegisterVariable (&sv_gameplayfix_droptofloorstartsolid);
+       Cvar_RegisterVariable (&sv_gameplayfix_droptofloorstartsolid_nudgetocorrect);
        Cvar_RegisterVariable (&sv_gameplayfix_easierwaterjump);
        Cvar_RegisterVariable (&sv_gameplayfix_findradiusdistancetobox);
        Cvar_RegisterVariable (&sv_gameplayfix_grenadebouncedownslopes);
@@ -430,6 +432,8 @@ void SV_Init (void)
        {
                // hipnotic mission pack has issues in their 'friendly monster' ai, which seem to attempt to attack themselves for some reason when findradius() returns non-solid entities.
                Cvar_SetValueQuick (&sv_gameplayfix_blowupfallenzombies, 0);
+               // hipnotic mission pack has issues with bobbing water entities 'jittering' between different heights on alternate frames at the default 0.0138889 ticrate, 0.02 avoids this issue
+               Cvar_SetValueQuick (&sys_ticrate, 0.02);
        }
        if (gamemode == GAME_ROGUE)
        {
@@ -790,9 +794,11 @@ void SV_SendServerinfo (client_t *client)
        MSG_WriteByte (&client->netconnection->message, (int)prog->edicts->fields.server->sounds);
 
 // set view
+// store this in clientcamera, too
+       client->clientcamera = PRVM_NUM_FOR_EDICT(client->edict);
        MSG_WriteByte (&client->netconnection->message, svc_setview);
-       MSG_WriteShort (&client->netconnection->message, PRVM_NUM_FOR_EDICT(client->edict));
-
+       MSG_WriteShort (&client->netconnection->message, client->clientcamera);
+       
        MSG_WriteByte (&client->netconnection->message, svc_signonnum);
        MSG_WriteByte (&client->netconnection->message, 1);
 
@@ -1323,6 +1329,7 @@ void SV_WriteEntitiesToClient(client_t *client, prvm_edict_t *clent, sizebuf_t *
 {
        int i, numsendstates;
        entity_state_t *s;
+       prvm_edict_t *camera;
 
        // if there isn't enough space to accomplish anything, skip it
        if (msg->cursize + 25 > msg->maxsize)
@@ -1338,7 +1345,8 @@ void SV_WriteEntitiesToClient(client_t *client, prvm_edict_t *clent, sizebuf_t *
 
 // find the client's PVS
        // the real place being tested from
-       VectorAdd(clent->fields.server->origin, clent->fields.server->view_ofs, sv.writeentitiestoclient_testeye);
+       camera = PRVM_EDICT_NUM( client->clientcamera );
+       VectorAdd(camera->fields.server->origin, clent->fields.server->view_ofs, sv.writeentitiestoclient_testeye);
        sv.writeentitiestoclient_pvsbytes = 0;
        if (sv.worldmodel && sv.worldmodel->brush.FatPVS)
                sv.writeentitiestoclient_pvsbytes = sv.worldmodel->brush.FatPVS(sv.worldmodel, sv.writeentitiestoclient_testeye, 8, sv.writeentitiestoclient_pvs, sizeof(sv.writeentitiestoclient_pvs), false);
@@ -1745,32 +1753,50 @@ static void SV_SendClientDatagram (client_t *client)
 
        if (LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) == LHNETADDRESSTYPE_LOOP && !sv_ratelimitlocalplayer.integer)
        {
-               // for good singleplayer, send huge packets and never limit frequency
-               clientrate = 1000000000;
+               // for good singleplayer, send huge packets
                maxsize = sizeof(sv_sendclientdatagram_buf);
                maxsize2 = sizeof(sv_sendclientdatagram_buf);
+               // never limit frequency in singleplayer
+               clientrate = 1000000000;
        }
-       else if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3 || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4)
+       else if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3 || sv.protocol == PROTOCOL_QUAKEWORLD)
        {
-               // no packet size limit support on older protocols because DP1-4 kick
-               // the client off if they overflow, and quake protocol shows less than
-               // the full entity set if rate limited
-               clientrate = max(NET_MINRATE, client->rate);
+               // no packet size limit support on Quake protocols because it just
+               // causes missing entities/effects
+               // packets are simply sent less often to obey the rate limit
                maxsize = 1024;
                maxsize2 = 1024;
        }
+       else if (sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4)
+       {
+               // no packet size limit support on DP1-4 protocols because they kick
+               // the client off if they overflow, and miss effects
+               // packets are simply sent less often to obey the rate limit
+               maxsize = sizeof(sv_sendclientdatagram_buf);
+               maxsize2 = sizeof(sv_sendclientdatagram_buf);
+       }
        else
        {
                // DP5 and later protocols support packet size limiting which is a
                // better method than limiting packet frequency as QW does
                //
-               // this rate limiting does not understand sys_ticrate 0
-               // (but no one should be running that on a server!)
+               // at very low rates (or very small sys_ticrate) the packet size is
+               // not reduced below 128, but packets may be sent less often
                maxsize = (int)(clientrate * sys_ticrate.value);
-               maxsize = bound(100, maxsize, 1400);
+               maxsize = bound(128, maxsize, 1400);
                maxsize2 = 1400;
+               // csqc entities can easily exceed 128 bytes, so disable throttling in
+               // mods that use csqc (they are likely to use less bandwidth anyway)
+               if (sv.csqc_progsize > 0)
+                       maxsize = maxsize2;
        }
 
+       // obey rate limit by limiting packet frequency if the packet size
+       // limiting fails
+       // (usually this is caused by reliable messages)
+       if (!NetConn_CanSend(client->netconnection))
+               return;
+
        // while downloading, limit entity updates to half the packet
        // (any leftover space will be used for downloading)
        if (host_client->download_file)
@@ -1779,18 +1805,11 @@ static void SV_SendClientDatagram (client_t *client)
        msg.data = sv_sendclientdatagram_buf;
        msg.maxsize = maxsize;
        msg.cursize = 0;
+       msg.allowoverflow = false;
 
-       // obey rate limit by limiting packet frequency if the packet size
-       // limiting fails
-       // (usually this is caused by reliable messages)
-       if (!NetConn_CanSend(client->netconnection))
-       {
-               // send the datagram
-               //NetConn_SendUnreliableMessage (client->netconnection, &msg, sv.protocol, clientrate, true);
-               return;
-       }
-       else if (host_client->spawned)
+       if (host_client->spawned)
        {
+               // the player is in the game
                MSG_WriteByte (&msg, svc_time);
                MSG_WriteFloat (&msg, sv.time);
 
@@ -1816,6 +1835,7 @@ static void SV_SendClientDatagram (client_t *client)
        {
                // the player isn't totally in the game yet
                // send small keepalive messages if too much time has passed
+               // (may also be sending downloads)
                msg.maxsize = maxsize2;
                client->keepalivetime = realtime + 5;
                MSG_WriteChar (&msg, svc_nop);
@@ -1848,9 +1868,9 @@ static void SV_SendClientDatagram (client_t *client)
 
        // reliable only if none is in progress
        if(client->sendsignon != 2 && !client->netconnection->sendMessageLength)
-               SV_WriteDemoMessage(client, &(client->netconnection->message));
+               SV_WriteDemoMessage(client, &(client->netconnection->message), false);
        // unreliable
-       SV_WriteDemoMessage(client, &msg);
+       SV_WriteDemoMessage(client, &msg, false);
 
 // send the datagram
        NetConn_SendUnreliableMessage (client->netconnection, &msg, sv.protocol, clientrate, client->sendsignon == 2);
@@ -1930,6 +1950,21 @@ static void SV_UpdateToReliableMessages (void)
                        PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.playerskin)->string = PRVM_SetEngineString(host_client->playerskin);
                }
 
+               // TODO: add an extension name for this [1/17/2008 Black]
+               if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.clientcamera)) && val->edict > 0 ) {
+                       int oldclientcamera = host_client->clientcamera;
+                       if( val->edict >= prog->max_edicts || PRVM_EDICT_NUM( val->edict )->priv.required->free ) {
+                               val->edict = host_client->clientcamera = PRVM_NUM_FOR_EDICT( host_client->edict );
+                       } else {
+                               host_client->clientcamera = val->edict;
+                       }
+
+                       if( oldclientcamera != host_client->clientcamera ) {
+                               MSG_WriteByte (&sv.reliable_datagram, svc_setview );
+                               MSG_WriteShort (&host_client->netconnection->message, host_client->clientcamera);
+                       }
+               }
+
                // frags
                host_client->frags = (int)host_client->edict->fields.server->frags;
                if(gamemode == GAME_NEXUIZ)
@@ -2571,9 +2606,7 @@ void SV_SpawnServer (const char *server)
 //
 // clear world interaction links
 //
-       VectorCopy(sv.worldmodel->normalmins, sv.world.areagrid_mins);
-       VectorCopy(sv.worldmodel->normalmaxs, sv.world.areagrid_maxs);
-       World_Clear(&sv.world);
+       World_SetSize(&sv.world, sv.worldmodel->normalmins, sv.worldmodel->normalmaxs);
 
        strlcpy(sv.sound_precache[0], "", sizeof(sv.sound_precache[0]));
 
@@ -2691,17 +2724,8 @@ void SV_SpawnServer (const char *server)
 
 static void SV_VM_CB_BeginIncreaseEdicts(void)
 {
-       int i;
-       prvm_edict_t *ent;
-
        // links don't survive the transition, so unlink everything
-       for (i = 0, ent = prog->edicts;i < prog->max_edicts;i++, ent++)
-       {
-               if (!ent->priv.server->free)
-                       World_UnlinkEdict(prog->edicts + i);
-               memset(&ent->priv.server->areagrid, 0, sizeof(ent->priv.server->areagrid));
-       }
-       World_Clear(&sv.world);
+       World_UnlinkAll(&sv.world);
 }
 
 static void SV_VM_CB_EndIncreaseEdicts(void)
@@ -2836,6 +2860,7 @@ static void SV_VM_Setup(void)
        prog->builtins = vm_sv_builtins;
        prog->numbuiltins = vm_sv_numbuiltins;
        prog->headercrc = PROGHEADER_CRC;
+       prog->headercrc2 = PROGHEADER_CRC_TENEBRAE;
        prog->max_edicts = 512;
        if (sv.protocol == PROTOCOL_QUAKE)
                prog->limit_edicts = 640; // before quake mission pack 1 this was 512