]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
fix the EndIncreaseEdicts handlers as edicts beyond num_edicts are not initialized yet
[xonotic/darkplaces.git] / sv_main.c
index c92b4a8a2d0a816949128ced37caac49b993264a..6982ef3bbeefb245fa6df160d20d715d05bf8ec2 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -47,13 +47,14 @@ cvar_t slowmo = {0, "slowmo", "1.0", "controls game speed, 0.5 is half speed, 2
 
 cvar_t sv_accelerate = {0, "sv_accelerate", "10", "rate at which a player accelerates to sv_maxspeed"};
 cvar_t sv_aim = {CVAR_SAVE, "sv_aim", "2", "maximum cosine angle for quake's vertical autoaim, a value above 1 completely disables the autoaim, quake used 0.93"};
-cvar_t sv_airaccel_qw = {0, "sv_airaccel_qw", "1", "ratio of QW-style air control as opposed to simple acceleration"};
-cvar_t sv_airaccel_sideways_friction = {0, "sv_airaccel_sideways_friction", "", "anti-sideways movement stabilization (reduces speed gain when zigzagging)"};
+cvar_t sv_airaccel_qw = {0, "sv_airaccel_qw", "1", "ratio of QW-style air control as opposed to simple acceleration; when < 0, the speed is clamped against the maximum allowed forward speed after the move"};
+cvar_t sv_airaccel_sideways_friction = {0, "sv_airaccel_sideways_friction", "", "anti-sideways movement stabilization (reduces speed gain when zigzagging); when < 0, only so much friction is applied that braking (by accelerating backwards) cannot be stronger"};
 cvar_t sv_airaccelerate = {0, "sv_airaccelerate", "-1", "rate at which a player accelerates to sv_maxairspeed while in the air, if less than 0 the sv_accelerate variable is used instead"};
 cvar_t sv_airstopaccelerate = {0, "sv_airstopaccelerate", "0", "when set, replacement for sv_airaccelerate when moving backwards"};
 cvar_t sv_airstrafeaccelerate = {0, "sv_airstrafeaccelerate", "0", "when set, replacement for sv_airaccelerate when just strafing"};
 cvar_t sv_maxairstrafespeed = {0, "sv_maxairstrafespeed", "0", "when set, replacement for sv_maxairspeed when just strafing"};
 cvar_t sv_aircontrol = {0, "sv_aircontrol", "0", "CPMA-style air control"};
+cvar_t sv_aircontrol_power = {0, "sv_aircontrol", "2", "CPMA-style air control exponent"};
 cvar_t sv_allowdownloads = {0, "sv_allowdownloads", "1", "whether to allow clients to download files from the server (does not affect http downloads)"};
 cvar_t sv_allowdownloads_archive = {0, "sv_allowdownloads_archive", "0", "whether to allow downloads of archives (pak/pk3)"};
 cvar_t sv_allowdownloads_config = {0, "sv_allowdownloads_config", "0", "whether to allow downloads of config files (cfg)"};
@@ -86,7 +87,7 @@ cvar_t sv_fixedframeratesingleplayer = {0, "sv_fixedframeratesingleplayer", "1",
 cvar_t sv_freezenonclients = {CVAR_NOTIFY, "sv_freezenonclients", "0", "freezes time, except for players, allowing you to walk around and take screenshots of explosions"};
 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_consistentplayerprethink = {0, "sv_gameplayfix_consistentplayerprethink", "1", "improves fairness in multiplayer by running all PlayerPreThink functions (which fire weapons) before performing physics, then runing all PlayerPostThink functions"};
+cvar_t sv_gameplayfix_consistentplayerprethink = {0, "sv_gameplayfix_consistentplayerprethink", "0", "improves fairness in multiplayer by running all PlayerPreThink functions (which fire weapons) before performing physics, then runing all PlayerPostThink functions"};
 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"};
@@ -100,10 +101,12 @@ cvar_t sv_gameplayfix_noairborncorpse_allowsuspendeditems = {0, "sv_gameplayfix_
 cvar_t sv_gameplayfix_nudgeoutofsolid = {0, "sv_gameplayfix_nudgeoutofsolid", "1", "attempts to fix physics errors (where an object ended up in solid for some reason)"};
 cvar_t sv_gameplayfix_nudgeoutofsolid_bias = {0, "sv_gameplayfix_nudgeoutofsolid_bias", "0", "over-correction on nudgeoutofsolid logic, to prevent constant contact"};
 cvar_t sv_gameplayfix_q2airaccelerate = {0, "sv_gameplayfix_q2airaccelerate", "0", "Quake2-style air acceleration"};
+cvar_t sv_gameplayfix_nogravityonground = {0, "sv_gameplayfix_nogravityonground", "0", "Quake2-style air acceleration"};
 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_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_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_stepmultipletimes = {0, "sv_gameplayfix_stepmultipletimes", "1", "applies step-up onto a ledge more than once in a single frame, when running quickly up stairs"};
 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_downtracesupportsongroundflag = {0, "sv_gameplayfix_downtracesupportsongroundflag", "1", "prevents very short moves from clearing onground (which may make the player stick to the floor at high netfps)"};
@@ -115,7 +118,6 @@ cvar_t sv_maxairspeed = {0, "sv_maxairspeed", "30", "maximum speed a player can
 cvar_t sv_maxrate = {CVAR_SAVE | CVAR_NOTIFY, "sv_maxrate", "1000000", "upper limit on client rate cvar, should reflect your network connection quality"};
 cvar_t sv_maxspeed = {CVAR_NOTIFY, "sv_maxspeed", "320", "maximum speed a player can accelerate to when on ground (can be exceeded by tricks)"};
 cvar_t sv_maxvelocity = {CVAR_NOTIFY, "sv_maxvelocity","2000", "universal speed limit on all entities"};
-cvar_t sv_newflymove = {CVAR_NOTIFY, "sv_newflymove", "0", "enables simpler/buggier player physics (not recommended)"};
 cvar_t sv_nostep = {CVAR_NOTIFY, "sv_nostep","0", "prevents MOVETYPE_STEP entities (monsters) from moving"};
 cvar_t sv_playerphysicsqc = {CVAR_NOTIFY, "sv_playerphysicsqc", "1", "enables QuakeC function to override player physics"};
 cvar_t sv_progs = {0, "sv_progs", "progs.dat", "selects which quakec progs.dat file to run" };
@@ -174,6 +176,7 @@ cvar_t cutscene = {0, "cutscene", "1", "enables cutscenes in nehahra, can be use
 
 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 client number and the IP address + port number, separated by underscores (the date is encoded using strftime escapes)" };
+cvar_t sv_autodemo_perclient_discardable = {CVAR_SAVE, "sv_autodemo_perclient_discardable", "0", "Allow game code to decide whether a demo should be kept or discarded."};
 
 cvar_t halflifebsp = {0, "halflifebsp", "0", "indicates the current map is hlbsp format (useful to know because of different bounding box sizes)"};
 
@@ -366,6 +369,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_airstrafeaccelerate);
        Cvar_RegisterVariable (&sv_maxairstrafespeed);
        Cvar_RegisterVariable (&sv_aircontrol);
+       Cvar_RegisterVariable (&sv_aircontrol_power);
        Cvar_RegisterVariable (&sv_allowdownloads);
        Cvar_RegisterVariable (&sv_allowdownloads_archive);
        Cvar_RegisterVariable (&sv_allowdownloads_config);
@@ -412,10 +416,12 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_gameplayfix_nudgeoutofsolid);
        Cvar_RegisterVariable (&sv_gameplayfix_nudgeoutofsolid_bias);
        Cvar_RegisterVariable (&sv_gameplayfix_q2airaccelerate);
+       Cvar_RegisterVariable (&sv_gameplayfix_nogravityonground);
        Cvar_RegisterVariable (&sv_gameplayfix_setmodelrealbox);
        Cvar_RegisterVariable (&sv_gameplayfix_slidemoveprojectiles);
        Cvar_RegisterVariable (&sv_gameplayfix_stepdown);
        Cvar_RegisterVariable (&sv_gameplayfix_stepwhilejumping);
+       Cvar_RegisterVariable (&sv_gameplayfix_stepmultipletimes);
        Cvar_RegisterVariable (&sv_gameplayfix_swiminbmodels);
        Cvar_RegisterVariable (&sv_gameplayfix_upwardvelocityclearsongroundflag);
        Cvar_RegisterVariable (&sv_gameplayfix_downtracesupportsongroundflag);
@@ -427,7 +433,6 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_maxrate);
        Cvar_RegisterVariable (&sv_maxspeed);
        Cvar_RegisterVariable (&sv_maxvelocity);
-       Cvar_RegisterVariable (&sv_newflymove);
        Cvar_RegisterVariable (&sv_nostep);
        Cvar_RegisterVariable (&sv_playerphysicsqc);
        Cvar_RegisterVariable (&sv_progs);
@@ -490,6 +495,7 @@ void SV_Init (void)
 
        Cvar_RegisterVariable (&sv_autodemo_perclient);
        Cvar_RegisterVariable (&sv_autodemo_perclient_nameformat);
+       Cvar_RegisterVariable (&sv_autodemo_perclient_discardable);
 
        Cvar_RegisterVariable (&halflifebsp);
 
@@ -507,8 +513,8 @@ 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);                                                                                                                                   
+               // 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)
        {
@@ -517,7 +523,6 @@ void SV_Init (void)
        }
        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);
        }
 
@@ -863,7 +868,7 @@ void SV_SendServerinfo (client_t *client)
                if(client->sv_demo_file != NULL)
                {
                        int i;
-                       char buf[NET_MAXMESSAGE];
+                       static char buf[NET_MAXMESSAGE];
                        sizebuf_t sb;
 
                        sb.data = (unsigned char *) buf;
@@ -1584,6 +1589,85 @@ void SV_MarkWriteEntityStateToClient(entity_state_t *s)
        sv.sententities[s->number] = sv.sententitiesmark;
 }
 
+#if MAX_LEVELNETWORKEYES > 0
+#define MAX_EYE_RECURSION 1 // increase if recursion gets supported by portals
+void SV_AddCameraEyes(void)
+{
+       int e, i, j, k;
+       prvm_edict_t *ed;
+       int cameras[MAX_LEVELNETWORKEYES];
+       vec3_t camera_origins[MAX_LEVELNETWORKEYES];
+       int eye_levels[MAX_CLIENTNETWORKEYES];
+       int n_cameras = 0;
+       vec3_t mi, ma;
+       prvm_eval_t *valendpos, *val;
+
+       if(!prog->fieldoffsets.camera_transform)
+               return;
+       valendpos = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_endpos);
+       if(!valendpos)
+               return;
+
+       for(i = 0; i < sv.writeentitiestoclient_numeyes; ++i)
+               eye_levels[i] = 0;
+
+       // check line of sight to portal entities and add them to PVS
+       for (e = 1, ed = PRVM_NEXT_EDICT(prog->edicts);e < prog->num_edicts;e++, ed = PRVM_NEXT_EDICT(ed))
+       {
+               if (!ed->priv.server->free)
+               {
+                       if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.camera_transform)) && val->function)
+                       {
+                               prog->globals.server->self = e;
+                               prog->globals.server->other = sv.writeentitiestoclient_cliententitynumber;
+                               VectorCopy(sv.writeentitiestoclient_eyes[0], valendpos->vector);
+                               VectorCopy(sv.writeentitiestoclient_eyes[0], PRVM_G_VECTOR(OFS_PARM0));
+                               VectorClear(PRVM_G_VECTOR(OFS_PARM1));
+                               PRVM_ExecuteProgram(val->function, "QC function e.camera_transform is missing");
+                               if(!VectorCompare(valendpos->vector, sv.writeentitiestoclient_eyes[0]))
+                                       VectorCopy(valendpos->vector, camera_origins[n_cameras]);
+                               cameras[n_cameras] = e;
+                               ++n_cameras;
+                               if(n_cameras >= MAX_LEVELNETWORKEYES)
+                                       break;
+                       }
+               }
+       }
+
+       if(!n_cameras)
+               return;
+
+       // i is loop counter, is reset to 0 when an eye got added
+       // j is camera index to check
+       for(i = 0, j = 0; sv.writeentitiestoclient_numeyes < MAX_CLIENTNETWORKEYES && i < n_cameras; ++i, ++j, j %= n_cameras)
+       {
+               if(!cameras[j])
+                       continue;
+               ed = PRVM_EDICT_NUM(cameras[j]);
+               VectorAdd(ed->fields.server->origin, ed->fields.server->mins, mi);
+               VectorAdd(ed->fields.server->origin, ed->fields.server->maxs, ma);
+               for(k = 0; k < sv.writeentitiestoclient_numeyes; ++k)
+               if(eye_levels[k] <= MAX_EYE_RECURSION)
+               {
+                       if(SV_CanSeeBox(sv_cullentities_trace_samples.integer, sv_cullentities_trace_enlarge.value, sv.writeentitiestoclient_eyes[k], mi, ma))
+                       {
+                               eye_levels[sv.writeentitiestoclient_numeyes] = eye_levels[k] + 1;
+                               VectorCopy(camera_origins[j], sv.writeentitiestoclient_eyes[sv.writeentitiestoclient_numeyes]);
+                               // Con_Printf("added eye %d: %f %f %f because we can see %f %f %f .. %f %f %f from eye %d\n", j, sv.writeentitiestoclient_eyes[sv.writeentitiestoclient_numeyes][0], sv.writeentitiestoclient_eyes[sv.writeentitiestoclient_numeyes][1], sv.writeentitiestoclient_eyes[sv.writeentitiestoclient_numeyes][2], mi[0], mi[1], mi[2], ma[0], ma[1], ma[2], k);
+                               sv.writeentitiestoclient_numeyes++;
+                               cameras[j] = 0;
+                               i = 0;
+                               break;
+                       }
+               }
+       }
+}
+#else
+void SV_AddCameraEyes(void)
+{
+}
+#endif
+
 void SV_WriteEntitiesToClient(client_t *client, prvm_edict_t *clent, sizebuf_t *msg, int maxsize)
 {
        qboolean need_empty = false;
@@ -1634,7 +1718,12 @@ void SV_WriteEntitiesToClient(client_t *client, prvm_edict_t *clent, sizebuf_t *
                //      Con_DPrintf("Trying to walk into solid in a pingtime... not predicting for culling\n");
        }
 
-       // TODO: check line of sight to portal entities and add them to PVS
+       SV_AddCameraEyes();
+
+       // build PVS from the new eyes
+       if (sv.worldmodel && sv.worldmodel->brush.FatPVS)
+               for(i = 1; i < sv.writeentitiestoclient_numeyes; ++i)
+                       sv.writeentitiestoclient_pvsbytes = sv.worldmodel->brush.FatPVS(sv.worldmodel, sv.writeentitiestoclient_eyes[i], 8, sv.writeentitiestoclient_pvs, sizeof(sv.writeentitiestoclient_pvs), sv.writeentitiestoclient_pvsbytes != 0);
 
        sv.sententitiesmark++;
 
@@ -1848,6 +1937,8 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
        // 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)
+               | (sv_gameplayfix_nogravityonground.integer ? MOVEFLAG_NOGRAVITYONGROUND : 0)
+               | (sv_gameplayfix_gravityunaffectedbyticrate.integer ? MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE : 0)
        ;
        statsf[STAT_MOVEVARS_TICRATE] = sys_ticrate.value;
        statsf[STAT_MOVEVARS_TIMESCALE] = slowmo.value;
@@ -1872,6 +1963,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
        statsf[STAT_MOVEVARS_AIRSTRAFEACCELERATE] = sv_airstrafeaccelerate.value;
        statsf[STAT_MOVEVARS_MAXAIRSTRAFESPEED] = sv_maxairstrafespeed.value;
        statsf[STAT_MOVEVARS_AIRCONTROL] = sv_aircontrol.value;
+       statsf[STAT_MOVEVARS_AIRCONTROL_POWER] = sv_aircontrol_power.value;
        statsf[STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL] = sv_warsowbunny_airforwardaccel.value;
        statsf[STAT_MOVEVARS_WARSOWBUNNY_ACCEL] = sv_warsowbunny_accel.value;
        statsf[STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED] = sv_warsowbunny_topspeed.value;
@@ -2055,7 +2147,7 @@ static void SV_SendClientDatagram (client_t *client)
        int clientrate, maxrate, maxsize, maxsize2, downloadsize;
        sizebuf_t msg;
        int stats[MAX_CL_STATS];
-       unsigned char sv_sendclientdatagram_buf[NET_MAXMESSAGE];
+       static unsigned char sv_sendclientdatagram_buf[NET_MAXMESSAGE];
 
        // obey rate limit by limiting packet frequency if the packet size
        // limiting fails
@@ -2279,7 +2371,7 @@ static void SV_UpdateToReliableMessages (void)
                        }
 
                        if( oldclientcamera != host_client->clientcamera ) {
-                               MSG_WriteByte (&sv.reliable_datagram, svc_setview );
+                               MSG_WriteByte (&host_client->netconnection->message, svc_setview );
                                MSG_WriteShort (&host_client->netconnection->message, host_client->clientcamera);
                        }
                }
@@ -2705,7 +2797,9 @@ int SV_ParticleEffectIndex(const char *name)
        int filepass;
        fs_offset_t filesize;
        unsigned char *filedata;
-       const char *text, *textstart, *textend;
+       const char *text;
+       const char *textstart;
+       //const char *textend;
        char argv[16][1024];
        char filename[MAX_QPATH];
        if (!sv.particleeffectnamesloaded)
@@ -2726,7 +2820,7 @@ int SV_ParticleEffectIndex(const char *name)
                        if (!filedata)
                                continue;
                        textstart = (const char *)filedata;
-                       textend = (const char *)filedata + filesize;
+                       //textend = (const char *)filedata + filesize;
                        text = textstart;
                        for (linenumber = 1;;linenumber++)
                        {
@@ -3001,7 +3095,7 @@ void SV_SpawnServer (const char *server)
        // free q3 shaders so that any newly downloaded shaders will be active
        Mod_FreeQ3Shaders();
 
-       worldmodel = Mod_ForName(modelname, false, true, NULL);
+       worldmodel = Mod_ForName(modelname, false, developer.integer > 0, NULL);
        if (!worldmodel || !worldmodel->TraceBox)
        {
                Con_Printf("Couldn't load map %s\n", modelname);
@@ -3257,7 +3351,7 @@ static void SV_VM_CB_EndIncreaseEdicts(void)
        prvm_edict_t *ent;
 
        // link every entity except world
-       for (i = 1, ent = prog->edicts;i < prog->max_edicts;i++, ent++)
+       for (i = 1, ent = prog->edicts;i < prog->num_edicts;i++, ent++)
                if (!ent->priv.server->free)
                        SV_LinkEdict(ent);
 }