]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - csprogs.c
first part of fog changes: no longer use a complex glsl equation; modify the table...
[xonotic/darkplaces.git] / csprogs.c
index 116381fc8154eb22b3ef17f9f8037f23ce380134..4b04475c81b0a10c56c2266affc8599921b6b2ba 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -3,6 +3,7 @@
 #include "clprogdefs.h"
 #include "csprogs.h"
 #include "cl_collision.h"
+#include "snd_main.h"
 
 //============================================================================
 // Client prog handling
@@ -77,10 +78,18 @@ static void CSQC_SetGlobals (void)
                prog->globals.client->clientcommandframe = cl.movecmd[0].sequence;
                VectorCopy(cl.viewangles, prog->globals.client->input_angles);
                VectorCopy(cl.viewangles, cl.csqc_angles);
+               // // FIXME: this actually belongs into getinputstate().. [12/17/2007 Black]
                prog->globals.client->input_buttons = cl.movecmd[0].buttons;
                VectorSet(prog->globals.client->input_movevalues, cl.movecmd[0].forwardmove, cl.movecmd[0].sidemove, cl.movecmd[0].upmove);
                //VectorCopy(cl.movement_origin, cl.csqc_origin);
                Matrix4x4_OriginFromMatrix(&cl.entities[cl.viewentity].render.matrix, cl.csqc_origin);
+
+               // LordHavoc: Spike says not to do this, but without pmove_org the
+               // CSQC is useless as it can't alter the view origin without
+               // completely replacing it
+               VectorCopy(cl.csqc_origin, prog->globals.client->pmove_org);
+               VectorCopy(cl.velocity, prog->globals.client->pmove_vel);
+
                if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.view_angles)))
                        VectorCopy(cl.viewangles, val->vector);
                prog->globals.client->maxclients = cl.maxclients;
@@ -116,6 +125,7 @@ extern cvar_t cl_noplayershadow;
 qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
 {
        int renderflags;
+       int c;
        float scale;
        prvm_eval_t *val;
        entity_t *e;
@@ -131,7 +141,6 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
                return false;
 
        e->render.model = model;
-       e->render.colormap = (int)ed->fields.client->colormap;
        e->render.skinnum = (int)ed->fields.client->skin;
        e->render.effects |= e->render.model->effects;
        scale = 1;
@@ -186,8 +195,6 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
 
        // concat the matrices to make the entity relative to its tag
        Matrix4x4_Concat(&e->render.matrix, &tagmatrix, &matrix2);
-       // make the other useful stuff
-       CL_UpdateRenderEntity(&e->render);
 
        if(renderflags)
        {
@@ -197,24 +204,13 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
                if(renderflags & RF_ADDITIVE)           e->render.effects |= EF_ADDITIVE;
        }
 
-       if ((e->render.colormap > 0 && e->render.colormap <= cl.maxclients) || e->render.colormap >= 1024)
-       {
-               unsigned char *cbcolor;
-               int palcol;
-               if (e->render.colormap >= 1024)
-                       palcol = (unsigned char)(e->render.colormap-1024);
-               else
-                       palcol = cl.scores[e->render.colormap-1].colors;
-
-               cbcolor = (unsigned char *) (&palette_pantscolormap[palcol & 0xF]);
-               e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f);
-               e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f);
-               e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f);
-               cbcolor = (unsigned char *) (&palette_shirtcolormap[(palcol & 0xF0) >> 4]);
-               e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f);
-               e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f);
-               e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f);
-       }
+       c = (int)ed->fields.client->colormap;
+       if (c <= 0)
+               CL_SetEntityColormapColors(&e->render, -1);
+       else if (c <= cl.maxclients && cl.scores != NULL)
+               CL_SetEntityColormapColors(&e->render, cl.scores[c-1].colors);
+       else
+               CL_SetEntityColormapColors(&e->render, c);
 
        // either fullbright or lit
        if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer)
@@ -228,10 +224,13 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
        if (e->render.flags & RENDER_VIEWMODEL)
                e->render.flags |= RENDER_NOSELFSHADOW;
 
+       // make the other useful stuff
+       CL_UpdateRenderEntity(&e->render);
+
        return true;
 }
 
-qboolean CL_VM_InputEvent (qboolean pressed, int key)
+qboolean CL_VM_InputEvent (qboolean down, int key)
 {
        qboolean r;
        if(!cl.csqc_loaded)
@@ -242,7 +241,7 @@ qboolean CL_VM_InputEvent (qboolean pressed, int key)
                else
                {
                        prog->globals.client->time = cl.time;
-                       PRVM_G_FLOAT(OFS_PARM0) = pressed;
+                       PRVM_G_FLOAT(OFS_PARM0) = !down; // 0 is down, 1 is up
                        PRVM_G_FLOAT(OFS_PARM1) = key;
                        PRVM_ExecuteProgram(prog->funcoffsets.CSQC_InputEvent, "QC function CSQC_InputEvent is missing");
                        r = CSQC_RETURNVAL;
@@ -436,6 +435,41 @@ void CL_VM_UpdateIntermissionState (int intermission)
                CSQC_END
        }
 }
+void CL_VM_UpdateShowingScoresState (int showingscores)
+{
+       prvm_eval_t *val;
+       if(cl.csqc_loaded)
+       {
+               CSQC_BEGIN
+               val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.sb_showscores);
+               if(val)
+                       val->_float = showingscores;
+               CSQC_END
+       }
+}
+qboolean CL_VM_Event_Sound(int sound_num, int volume, int channel, float attenuation, int ent, vec3_t pos)
+{
+       qboolean r = false;
+       if(cl.csqc_loaded)
+       {
+               CSQC_BEGIN
+               if(prog->funcoffsets.CSQC_Event_Sound)
+               {
+                       prog->globals.client->time = cl.time;
+                       PRVM_G_FLOAT(OFS_PARM0) = ent;
+                       PRVM_G_FLOAT(OFS_PARM1) = channel;
+                       PRVM_G_INT(OFS_PARM2) = PRVM_SetTempString(cl.sound_name[sound_num] );
+                       PRVM_G_FLOAT(OFS_PARM3) = volume;
+                       PRVM_G_FLOAT(OFS_PARM4) = attenuation;
+                       VectorCopy(pos, PRVM_G_VECTOR(OFS_PARM5) );
+                       PRVM_ExecuteProgram(prog->funcoffsets.CSQC_Event_Sound, "QC function CSQC_Event_Sound is missing");
+                       r = CSQC_RETURNVAL;
+               }
+               CSQC_END
+       }
+
+       return r;
+}
 void CL_VM_UpdateCoopDeathmatchGlobals (int gametype)
 {
        // Avoid global names for clean(er) coding
@@ -675,6 +709,7 @@ void CL_VM_Init (void)
        prog->limit_edicts = CL_MAX_EDICTS;
        prog->reserved_edicts = 0;
        prog->edictprivate_size = sizeof(edict_engineprivate_t);
+       // TODO: add a shared extension string #define and add real support for csqc extension strings [12/5/2007 Black]
        prog->extensionstring = vm_sv_extensions;
        prog->builtins = vm_cl_builtins;
        prog->numbuiltins = vm_cl_numbuiltins;