]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
improved pr_fields command to list how many entities are using each entity field...
[xonotic/darkplaces.git] / sv_main.c
index fb24afd7093155931eaa732b151ce5e0e4874fdf..0a5b5bdf8c500f8de57c1d204f52d538106b5d40 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -36,6 +36,7 @@ static mempool_t *sv_edicts_mempool = NULL;
 //============================================================================
 
 extern void SV_Phys_Init (void);
+extern void SV_World_Init (void);
 
 /*
 ===============
@@ -64,6 +65,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_cullentities_stats);
 
        SV_Phys_Init();
+       SV_World_Init();
 
        for (i = 0;i < MAX_MODELS;i++)
                sprintf (localmodels[i], "*%i", i);
@@ -520,7 +522,7 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg)
        int culled_pvs, culled_portal, culled_trace, visibleentities, totalentities;
        qbyte *pvs;
        vec3_t origin, angles, entmins, entmaxs, testorigin, testeye;
-       float nextfullupdate;
+       float nextfullupdate, alphaf;
        edict_t *ent;
        eval_t *val;
        entity_state_t *baseline; // LordHavoc: delta or startup baseline
@@ -688,23 +690,23 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg)
                        visibleentities++;
                }
 
-               alpha = 255;
+               alphaf = 255.0f;
                scale = 16;
                glowcolor = 254;
                effects = ent->v.effects;
 
                if ((val = GETEDICTFIELDVALUE(ent, eval_alpha)))
                if (val->_float != 0)
-                       alpha = (int) (val->_float * 255.0);
+                       alphaf = val->_float * 255.0f;
 
                // HalfLife support
                if ((val = GETEDICTFIELDVALUE(ent, eval_renderamt)))
                if (val->_float != 0)
-                       alpha = (int) val->_float;
+                       alphaf = val->_float;
 
-               if (alpha == 0)
-                       alpha = 255;
-               alpha = bound(0, alpha, 255);
+               if (alphaf == 0.0f)
+                       alphaf = 255.0f;
+               alpha = bound(0, alphaf, 255);
 
                if ((val = GETEDICTFIELDVALUE(ent, eval_scale)))
                if ((scale = (int) (val->_float * 16.0)) == 0) scale = 16;
@@ -863,6 +865,7 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg)
 {
        int e, clentnum, flags, alpha, glowcolor, glowsize, scale, effects;
        int culled_pvs, culled_portal, culled_trace, visibleentities, totalentities;
+       float alphaf;
        qbyte *pvs;
        vec3_t origin, angles, entmins, entmaxs, testorigin, testeye;
        edict_t *ent;
@@ -878,9 +881,19 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg)
        Mod_CheckLoaded(sv.worldmodel);
 
 // find the client's PVS
+       // the real place being tested from
        VectorAdd (clent->v.origin, clent->v.view_ofs, testeye);
        pvs = SV_FatPVS (testeye);
-       EntityFrame_Clear(&entityframe, testeye);
+
+       // the place being reported (to consider the fact the client still
+       // applies the view_ofs[2], so we have to only send the fractional part
+       // of view_ofs[2], undoing what the client will redo)
+       VectorCopy (testeye, testorigin);
+       e = (int) clent->v.view_ofs[2] & 255;
+       if (e >= 128)
+               e -= 256;
+       testorigin[2] -= (float) e;
+       EntityFrame_Clear(&entityframe, testorigin);
 
        culled_pvs = 0;
        culled_portal = 0;
@@ -1023,23 +1036,23 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg)
                        visibleentities++;
                }
 
-               alpha = 255;
+               alphaf = 255.0f;
                scale = 16;
                glowcolor = 254;
                effects = ent->v.effects;
 
                if ((val = GETEDICTFIELDVALUE(ent, eval_alpha)))
                if (val->_float != 0)
-                       alpha = (int) (val->_float * 255.0);
+                       alphaf = val->_float * 255.0;
 
                // HalfLife support
                if ((val = GETEDICTFIELDVALUE(ent, eval_renderamt)))
                if (val->_float != 0)
-                       alpha = (int) val->_float;
+                       alphaf = val->_float;
 
-               if (alpha == 0)
-                       alpha = 255;
-               alpha = bound(0, alpha, 255);
+               if (alphaf == 0.0f)
+                       alphaf = 255.0f;
+               alpha = bound(0, alphaf, 255);
 
                if ((val = GETEDICTFIELDVALUE(ent, eval_scale)))
                if ((scale = (int) (val->_float * 16.0)) == 0) scale = 16;
@@ -1084,6 +1097,8 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg)
                        break;
                VectorCopy(origin, s->origin);
                VectorCopy(angles, s->angles);
+               if (ent->v.colormap >= 1024)
+                       flags |= RENDER_COLORMAPPED;
                s->colormap = ent->v.colormap;
                s->skin = ent->v.skin;
                s->frame = ent->v.frame;
@@ -1167,7 +1182,8 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
 
        bits = 0;
 
-       bits |= SU_VIEWHEIGHT;
+       if (ent->v.view_ofs[2] != DEFAULT_VIEWHEIGHT)
+               bits |= SU_VIEWHEIGHT;
 
        if (ent->v.idealpitch)
                bits |= SU_IDEALPITCH;
@@ -1241,8 +1257,7 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
                MSG_WriteByte(msg, bits >> 24);
 
        if (bits & SU_VIEWHEIGHT)
-               //MSG_WriteChar (msg, ent->v.view_ofs[2]);
-               MSG_WriteChar (msg, 0);
+               MSG_WriteChar (msg, ent->v.view_ofs[2]);
 
        if (bits & SU_IDEALPITCH)
                MSG_WriteChar (msg, ent->v.idealpitch);