]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
network CSQC and network entities separately (should prevent bugs when an entity...
[xonotic/darkplaces.git] / sv_main.c
index f18dd31ef90f7e8e7eb60f03730056a3fde14eb2..86820bbda583b02858133e284222a277c28a44bc 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 static void SV_SaveEntFile_f(void);
 static void SV_StartDownload_f(void);
 static void SV_Download_f(void);
-static void SV_VM_Setup();
+static void SV_VM_Setup(void);
 extern cvar_t net_connecttimeout;
 
 void VM_CustomStats_Clear (void);
@@ -63,7 +63,6 @@ cvar_t sv_areagrid_mingridsize = {CVAR_NOTIFY, "sv_areagrid_mingridsize", "64",
 cvar_t sv_checkforpacketsduringsleep = {0, "sv_checkforpacketsduringsleep", "0", "uses select() function to wait between frames which can be interrupted by packets being received, instead of Sleep()/usleep()/SDL_Sleep() functions which do not check for packets"};
 cvar_t sv_clmovement_enable = {0, "sv_clmovement_enable", "1", "whether to allow clients to use cl_movement prediction, which can cause choppy movement on the server which may annoy other players"};
 cvar_t sv_clmovement_minping = {0, "sv_clmovement_minping", "0", "if client ping is below this time in milliseconds, then their ability to use cl_movement prediction is disabled for a while (as they don't need it)"};
-cvar_t sv_clmovement_maxnetfps = {0, "sv_clmovement_maxnetfps", "0", "max amount of movement packets to accept per second"};
 cvar_t sv_clmovement_minping_disabletime = {0, "sv_clmovement_minping_disabletime", "1000", "when client falls below minping, disable their prediction for this many milliseconds (should be at least 1000 or else their prediction may turn on/off frequently)"};
 cvar_t sv_clmovement_inputtimeout = {0, "sv_clmovement_inputtimeout", "0.2", "when a client does not send input for this many seconds, force them to move anyway (unlike QuakeWorld)"};
 cvar_t sv_cullentities_nevercullbmodels = {0, "sv_cullentities_nevercullbmodels", "0", "if enabled the clients are always notified of moving doors and lifts and other submodels of world (warning: eats a lot of network bandwidth on some levels!)"};
@@ -93,13 +92,15 @@ cvar_t sv_gameplayfix_findradiusdistancetobox = {0, "sv_gameplayfix_findradiusdi
 cvar_t sv_gameplayfix_grenadebouncedownslopes = {0, "sv_gameplayfix_grenadebouncedownslopes", "1", "prevents MOVETYPE_BOUNCE (grenades) from getting stuck when fired down a downward sloping surface"};
 cvar_t sv_gameplayfix_multiplethinksperframe = {0, "sv_gameplayfix_multiplethinksperframe", "1", "allows entities to think more often than the server framerate, primarily useful for very high fire rate weapons"};
 cvar_t sv_gameplayfix_slidemoveprojectiles = {0, "sv_gameplayfix_slidemoveprojectiles", "1", "allows MOVETYPE_FLY/FLYMISSILE/TOSS/BOUNCE/BOUNCEMISSILE entities to finish their move in a frame even if they hit something, fixes 'gravity accumulation' bug for grenades on steep slopes"};
-cvar_t sv_gameplayfix_noairborncorpse = {0, "sv_gameplayfix_noairborncorpse", "1", "causes entities (corpses) sitting ontop of moving entities (players) to fall when the moving entity (player) is no longer supporting them"};
+cvar_t sv_gameplayfix_noairborncorpse = {0, "sv_gameplayfix_noairborncorpse", "1", "causes entities (corpses, items, etc) sitting ontop of moving entities (players) to fall when the moving entity (player) is no longer supporting them"};
+cvar_t sv_gameplayfix_noairborncorpse_allowsuspendeditems = {0, "sv_gameplayfix_noairborncorpse_allowsuspendeditems", "1", "causes entities sitting ontop of objects that are instantaneously remove to float in midair (special hack to allow a common level design trick for floating items)"};
 cvar_t sv_gameplayfix_setmodelrealbox = {0, "sv_gameplayfix_setmodelrealbox", "1", "fixes a bug in Quake that made setmodel always set the entity box to ('-16 -16 -16', '16 16 16') rather than properly checking the model box, breaks some poorly coded mods"};
 cvar_t sv_gameplayfix_stepdown = {0, "sv_gameplayfix_stepdown", "0", "attempts to step down stairs, not just up them (prevents the familiar thud..thud..thud.. when running down stairs and slopes)"};
 cvar_t sv_gameplayfix_stepwhilejumping = {0, "sv_gameplayfix_stepwhilejumping", "1", "applies step-up onto a ledge even while airborn, useful if you would otherwise just-miss the floor when running across small areas with gaps (for instance running across the moving platforms in dm2, or jumping to the megahealth and red armor in dm2 rather than using the bridge)"};
 cvar_t sv_gameplayfix_swiminbmodels = {0, "sv_gameplayfix_swiminbmodels", "1", "causes pointcontents (used to determine if you are in a liquid) to check bmodel entities as well as the world model, so you can swim around in (possibly moving) water bmodel entities"};
 cvar_t sv_gameplayfix_upwardvelocityclearsongroundflag = {0, "sv_gameplayfix_upwardvelocityclearsongroundflag", "1", "prevents monsters, items, and most other objects from being stuck to the floor when pushed around by damage, and other situations in mods"};
 cvar_t sv_gameplayfix_gravityunaffectedbyticrate = {0, "sv_gameplayfix_gravityunaffectedbyticrate", "0", "fix some ticrate issues in physics."};
+cvar_t sv_gameplayfix_q2airaccelerate = {0, "sv_gameplayfix_q2airaccelerate", "0", "Quake2-style air acceleration"};
 cvar_t sv_gravity = {CVAR_NOTIFY, "sv_gravity","800", "how fast you fall (512 = roughly earth gravity)"};
 cvar_t sv_idealpitchscale = {0, "sv_idealpitchscale","0.8", "how much to look up/down slopes and stairs when not using freelook"};
 cvar_t sv_jumpstep = {CVAR_NOTIFY, "sv_jumpstep", "0", "whether you can step up while jumping (sv_gameplayfix_stepwhilejumping must also be 1)"};
@@ -350,7 +351,6 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_areagrid_mingridsize);
        Cvar_RegisterVariable (&sv_checkforpacketsduringsleep);
        Cvar_RegisterVariable (&sv_clmovement_enable);
-       Cvar_RegisterVariable (&sv_clmovement_maxnetfps);
        Cvar_RegisterVariable (&sv_clmovement_minping);
        Cvar_RegisterVariable (&sv_clmovement_minping_disabletime);
        Cvar_RegisterVariable (&sv_clmovement_inputtimeout);
@@ -382,12 +382,14 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_gameplayfix_multiplethinksperframe);
        Cvar_RegisterVariable (&sv_gameplayfix_slidemoveprojectiles);
        Cvar_RegisterVariable (&sv_gameplayfix_noairborncorpse);
+       Cvar_RegisterVariable (&sv_gameplayfix_noairborncorpse_allowsuspendeditems);
        Cvar_RegisterVariable (&sv_gameplayfix_setmodelrealbox);
        Cvar_RegisterVariable (&sv_gameplayfix_stepdown);
        Cvar_RegisterVariable (&sv_gameplayfix_stepwhilejumping);
        Cvar_RegisterVariable (&sv_gameplayfix_swiminbmodels);
        Cvar_RegisterVariable (&sv_gameplayfix_upwardvelocityclearsongroundflag);
        Cvar_RegisterVariable (&sv_gameplayfix_gravityunaffectedbyticrate);
+       Cvar_RegisterVariable (&sv_gameplayfix_q2airaccelerate);
        Cvar_RegisterVariable (&sv_gravity);
        Cvar_RegisterVariable (&sv_idealpitchscale);
        Cvar_RegisterVariable (&sv_jumpstep);
@@ -475,12 +477,19 @@ void SV_Init (void)
                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);
+               // hipnotic mission pack has issues in their proximity mine sticking code, which causes them to bounce off.                                                                                     
+               Cvar_SetValueQuick (&sv_gameplayfix_slidemoveprojectiles, 0);                                                                                                                                   
        }
        if (gamemode == GAME_ROGUE)
        {
                // rogue mission pack has a guardian boss that does not wake up if findradius returns one of the entities around its spawn area
                Cvar_SetValueQuick (&sv_gameplayfix_findradiusdistancetobox, 0);
        }
+       if (gamemode == GAME_NEXUIZ)
+       {
+               // rogue mission pack has a guardian boss that does not wake up if findradius returns one of the entities around its spawn area
+               Cvar_SetValueQuick (&sv_gameplayfix_q2airaccelerate, 1);
+       }
 
        sv_mempool = Mem_AllocPool("server", 0, NULL);
 }
@@ -1094,7 +1103,7 @@ static qboolean SV_PrepareEntityForSending (prvm_edict_t *ent, entity_state_t *c
                return false;
 
        *cs = defaultstate;
-       cs->active = true;
+       cs->active = ACTIVE_NETWORK;
        cs->number = enumber;
        VectorCopy(ent->fields.server->origin, cs->origin);
        VectorCopy(ent->fields.server->angles, cs->angles);
@@ -1259,6 +1268,8 @@ static qboolean SV_PrepareEntityForSending (prvm_edict_t *ent, entity_state_t *c
                if (sendflags)
                        for (i = 0;i < svs.maxclients;i++)
                                svs.clients[i].csqcentitysendflags[enumber] |= sendflags;
+               // mark it as inactive for non-csqc networking
+               cs->active = ACTIVE_SHARED;
        }
 
        return true;
@@ -1440,7 +1451,7 @@ void SV_MarkWriteEntityStateToClient(entity_state_t *s)
 void SV_WriteEntitiesToClient(client_t *client, prvm_edict_t *clent, sizebuf_t *msg, int maxsize)
 {
        qboolean need_empty = false;
-       int i, numsendstates;
+       int i, numsendstates, numcsqcsendstates;
        entity_state_t *s;
        prvm_edict_t *camera;
        qboolean success;
@@ -1473,14 +1484,22 @@ void SV_WriteEntitiesToClient(client_t *client, prvm_edict_t *clent, sizebuf_t *
                SV_MarkWriteEntityStateToClient(sv.sendentities + i);
 
        numsendstates = 0;
+       numcsqcsendstates = 0;
        for (i = 0;i < sv.numsendentities;i++)
        {
                if (sv.sententities[sv.sendentities[i].number] == sv.sententitiesmark)
                {
-                       s = &sv.writeentitiestoclient_sendstates[numsendstates++];
-                       *s = sv.sendentities[i];
-                       if (s->exteriormodelforclient && s->exteriormodelforclient == sv.writeentitiestoclient_cliententitynumber)
-                               s->flags |= RENDER_EXTERIORMODEL;
+                       if(sv.sendentities[i].active == ACTIVE_NETWORK)
+                       {
+                               s = &sv.writeentitiestoclient_sendstates[numsendstates++];
+                               *s = sv.sendentities[i];
+                               if (s->exteriormodelforclient && s->exteriormodelforclient == sv.writeentitiestoclient_cliententitynumber)
+                                       s->flags |= RENDER_EXTERIORMODEL;
+                       }
+                       else if(sv.sendentities[i].active == ACTIVE_SHARED)
+                               sv.writeentitiestoclient_csqcsendstates[numcsqcsendstates++] = sv.sendentities[i].number;
+                       else
+                               Con_Printf("entity %d is in sv.sendentities and marked, but not active, please breakpoint me\n", sv.sendentities[i].number);
                }
        }
 
@@ -1488,12 +1507,12 @@ void SV_WriteEntitiesToClient(client_t *client, prvm_edict_t *clent, sizebuf_t *
                Con_Printf("client \"%s\" entities: %d total, %d visible, %d culled by: %d pvs %d trace\n", client->name, sv.writeentitiestoclient_stats_totalentities, sv.writeentitiestoclient_stats_visibleentities, sv.writeentitiestoclient_stats_culled_pvs + sv.writeentitiestoclient_stats_culled_trace, sv.writeentitiestoclient_stats_culled_pvs, sv.writeentitiestoclient_stats_culled_trace);
 
        if(client->entitydatabase5)
-               need_empty = EntityFrameCSQC_WriteFrame(msg, maxsize, numsendstates, sv.writeentitiestoclient_sendstates, client->entitydatabase5->latestframenum + 1);
+               need_empty = EntityFrameCSQC_WriteFrame(msg, maxsize, numcsqcsendstates, sv.writeentitiestoclient_csqcsendstates, client->entitydatabase5->latestframenum + 1);
        else
-               EntityFrameCSQC_WriteFrame(msg, maxsize, numsendstates, sv.writeentitiestoclient_sendstates, 0);
+               EntityFrameCSQC_WriteFrame(msg, maxsize, numcsqcsendstates, sv.writeentitiestoclient_csqcsendstates, 0);
 
-       if(client->num_skippedentityframes >= 5)
-               need_empty = true; // force every 5th frame to be not empty (or cl_movement replay takes too long)
+       if(client->num_skippedentityframes >= 10)
+               need_empty = true; // force every 10th frame to be not empty (or cl_movement replay takes too long)
 
        if (client->entitydatabase5)
                success = EntityFrame5_WriteFrame(msg, maxsize, client->entitydatabase5, numsendstates, sv.writeentitiestoclient_sendstates, client - svs.clients + 1, client->movesequence, need_empty);
@@ -1664,6 +1683,9 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
 
        // movement settings for prediction
        // note: these are not sent in protocols with lower MAX_CL_STATS limits
+       stats[STAT_MOVEFLAGS] = MOVEFLAG_VALID
+               | (sv_gameplayfix_q2airaccelerate.integer ? MOVEFLAG_Q2AIRACCELERATE : 0)
+       ;
        statsf[STAT_MOVEVARS_TICRATE] = sys_ticrate.value;
        statsf[STAT_MOVEVARS_TIMESCALE] = slowmo.value;
        statsf[STAT_MOVEVARS_GRAVITY] = sv_gravity.value;
@@ -1827,7 +1849,7 @@ void SV_FlushBroadcastMessages(void)
        SZ_Clear(&sv.datagram);
 }
 
-static void SV_WriteUnreliableMessages(client_t *client, sizebuf_t *msg, int maxsize)
+static void SV_WriteUnreliableMessages(client_t *client, sizebuf_t *msg, int maxsize, int maxsize2)
 {
        // scan the splitpoints to find out how many we can fit in
        int numsegments, j, split;
@@ -1836,34 +1858,28 @@ static void SV_WriteUnreliableMessages(client_t *client, sizebuf_t *msg, int max
        // always accept the first one if it's within 1024 bytes, this ensures
        // that very big datagrams which are over the rate limit still get
        // through, just to keep it working
-       j = msg->cursize + client->unreliablemsg_splitpoint[0];
-       if (maxsize < 1024 && j > maxsize && j <= 1024)
-       {
-               numsegments = 1;
-               maxsize = 1024;
-       }
-       else
-               for (numsegments = 0;numsegments < client->unreliablemsg_splitpoints;numsegments++)
-                       if (msg->cursize + client->unreliablemsg_splitpoint[numsegments] > maxsize)
-                               break;
-       if (numsegments > 0)
-       {
-               // some will fit, so add the ones that will fit
-               split = client->unreliablemsg_splitpoint[numsegments-1];
-               // note this discards ones that were accepted by the segments scan but
-               // can not fit, such as a really huge first one that will never ever
-               // fit in a packet...
-               if (msg->cursize + split <= maxsize)
-                       SZ_Write(msg, client->unreliablemsg.data, split);
-               // remove the part we sent, keeping any remaining data
-               client->unreliablemsg.cursize -= split;
-               if (client->unreliablemsg.cursize > 0)
-                       memmove(client->unreliablemsg.data, client->unreliablemsg.data + split, client->unreliablemsg.cursize);
-               // adjust remaining splitpoints
-               client->unreliablemsg_splitpoints -= numsegments;
-               for (j = 0;j < client->unreliablemsg_splitpoints;j++)
-                       client->unreliablemsg_splitpoint[j] = client->unreliablemsg_splitpoint[numsegments + j] - split;
-       }
+       for (numsegments = 1;numsegments < client->unreliablemsg_splitpoints;numsegments++)
+               if (msg->cursize + client->unreliablemsg_splitpoint[numsegments] > maxsize)
+                       break;
+       // the first segment gets an exemption from the rate limiting, otherwise
+       // it could get dropped consistently due to a low rate limit
+       if (numsegments == 1)
+               maxsize = maxsize2;
+       // some will fit, so add the ones that will fit
+       split = client->unreliablemsg_splitpoint[numsegments-1];
+       // note this discards ones that were accepted by the segments scan but
+       // can not fit, such as a really huge first one that will never ever
+       // fit in a packet...
+       if (msg->cursize + split <= maxsize)
+               SZ_Write(msg, client->unreliablemsg.data, split);
+       // remove the part we sent, keeping any remaining data
+       client->unreliablemsg.cursize -= split;
+       if (client->unreliablemsg.cursize > 0)
+               memmove(client->unreliablemsg.data, client->unreliablemsg.data + split, client->unreliablemsg.cursize);
+       // adjust remaining splitpoints
+       client->unreliablemsg_splitpoints -= numsegments;
+       for (j = 0;j < client->unreliablemsg_splitpoints;j++)
+               client->unreliablemsg_splitpoint[j] = client->unreliablemsg_splitpoint[numsegments + j] - split;
 }
 
 /*
@@ -1969,7 +1985,7 @@ static void SV_SendClientDatagram (client_t *client)
                // add as many queued unreliable messages (effects) as we can fit
                // limit effects to half of the remaining space
                if (client->unreliablemsg.cursize)
-                       SV_WriteUnreliableMessages (client, &msg, (msg.cursize + maxsize) / 2);
+                       SV_WriteUnreliableMessages (client, &msg, maxsize/2, maxsize2);
 
                // now write as many entities as we can fit, and also sends stats
                SV_WriteEntitiesToClient (client, client->edict, &msg, maxsize);
@@ -2281,7 +2297,7 @@ static void SV_Download_f(void)
                
                Con_DPrintf("Downloading %s to %s\n", host_client->download_name, host_client->name);
 
-               if(host_client->download_deflate)
+               if(host_client->download_deflate && svs.csqc_progdata_deflated)
                        host_client->download_file = FS_FileFromData(svs.csqc_progdata_deflated, svs.csqc_progsize_deflated, true);
                else
                        host_client->download_file = FS_FileFromData(svs.csqc_progdata, sv.csqc_progsize, true);
@@ -2715,8 +2731,13 @@ void SV_Prepare_CSQC(void)
                //unsigned char *FS_Deflate(const unsigned char *data, size_t size, size_t *deflated_size, int level, mempool_t *mempool);
                svs.csqc_progdata_deflated = FS_Deflate(svs.csqc_progdata, progsize, &deflated_size, -1, sv_mempool);
                svs.csqc_progsize_deflated = (int)deflated_size;
-               Con_Printf("Deflated: %g%%\n", 100.0 - 100.0 * (deflated_size / (float)progsize));
-               Con_DPrintf("Uncompressed: %u\nCompressed:   %u\n", (unsigned)sv.csqc_progsize, (unsigned)svs.csqc_progsize_deflated);
+               if(svs.csqc_progdata_deflated)
+               {
+                       Con_Printf("Deflated: %g%%\n", 100.0 - 100.0 * (deflated_size / (float)progsize));
+                       Con_DPrintf("Uncompressed: %u\nCompressed:   %u\n", (unsigned)sv.csqc_progsize, (unsigned)svs.csqc_progsize_deflated);
+               }
+               else
+                       Con_Printf("Cannot compress - need zlib for this. Using uncompressed progs only.\n");
        }
 }