]> 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 86436e03f92d1dd7eba462051e2da324cea3f100..6982ef3bbeefb245fa6df160d20d715d05bf8ec2 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -54,6 +54,7 @@ cvar_t sv_airstopaccelerate = {0, "sv_airstopaccelerate", "0", "when set, replac
 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,6 +101,7 @@ 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)"};
@@ -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,6 +416,7 @@ 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);
@@ -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);
 
@@ -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);
        }
 
@@ -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;
@@ -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);
                        }
                }
@@ -3003,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);
@@ -3259,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);
 }