]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - clvm_cmds.c
Add full support for csqc's sensitivityscale (no clamping yet, so you can actually...
[xonotic/darkplaces.git] / clvm_cmds.c
index f4cab9c58d70d50ba07abda1b21144ca745eb7ef..f19b66db13b1004b8971e88d311ce7a4c75ac94e 100644 (file)
@@ -1,3 +1,5 @@
+#include "quakedef.h"
+
 #include "prvm_cmds.h"
 #include "csprogs.h"
 #include "cl_collision.h"
@@ -22,7 +24,7 @@ void Sbar_SortFrags (void);
 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius);
 void CSQC_RelinkAllEntities (int drawmask);
 void CSQC_RelinkCSQCEntities (void);
-char *Key_GetBind (int key);
+const char *Key_GetBind (int key);
 
 
 
@@ -198,6 +200,7 @@ static void VM_CL_spawn (void)
 {
        prvm_edict_t *ed;
        ed = PRVM_ED_Alloc();
+       // FIXME: WTF.. this should be removed imo.. entnum points to the server.. [12/17/2007 Black]
        ed->fields.client->entnum = PRVM_NUM_FOR_EDICT(ed);     //[515]: not needed any more ?
        VM_RETURN_EDICT(ed);
 }
@@ -210,7 +213,7 @@ static void VM_CL_traceline (void)
        int             move;
        prvm_edict_t    *ent;
 
-       VM_SAFEPARMCOUNTRANGE(4, 8, VM_CL_traceline); // allow more parameters for future expansion
+       VM_SAFEPARMCOUNTRANGE(4, 4, VM_CL_traceline);
 
        prog->xfunction->builtinsprofile += 30;
 
@@ -344,7 +347,7 @@ static void VM_CL_precache_model (void)
        VM_SAFEPARMCOUNT(1, VM_CL_precache_model);
 
        name = PRVM_G_STRING(OFS_PARM0);
-       for (i = 1;i < MAX_MODELS && cl.csqc_model_precache[i];i++)
+       for (i = 0;i < MAX_MODELS && cl.csqc_model_precache[i];i++)
        {
                if(!strcmp(cl.csqc_model_precache[i]->name, name))
                {
@@ -356,7 +359,7 @@ static void VM_CL_precache_model (void)
        m = Mod_ForName(name, false, false, false);
        if(m && m->loaded)
        {
-               for (i = 1;i < MAX_MODELS;i++)
+               for (i = 0;i < MAX_MODELS;i++)
                {
                        if (!cl.csqc_model_precache[i])
                        {
@@ -724,79 +727,103 @@ static void VM_CL_R_SetView (void)
 
        switch(c)
        {
-       case VF_MIN:                    r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
-                                                       r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_MIN_X:                  r_view.x = (int)(k * vid.width / vid_conwidth.value);
-                                                       break;
-       case VF_MIN_Y:                  r_view.y = (int)(k * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_SIZE:                   r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
-                                                       r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_SIZE_Y:                 r_view.width = (int)(k * vid.width / vid_conwidth.value);
-                                                       break;
-       case VF_SIZE_X:                 r_view.height = (int)(k * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_VIEWPORT:               r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
-                                                       r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
-                                                       f = PRVM_G_VECTOR(OFS_PARM2);
-                                                       r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
-                                                       r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_FOV:                    r_view.frustum_x = tan(f[0] * M_PI / 360.0);r_view.ortho_x = f[0];
-                                                       r_view.frustum_y = tan(f[1] * M_PI / 360.0);r_view.ortho_y = f[1];
-                                                       break;
-       case VF_FOVX:                   r_view.frustum_x = tan(k * M_PI / 360.0);r_view.ortho_x = k;
-                                                       break;
-       case VF_FOVY:                   r_view.frustum_y = tan(k * M_PI / 360.0);r_view.ortho_y = k;
-                                                       break;
-       case VF_ORIGIN:                 VectorCopy(f, cl.csqc_origin);
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ORIGIN_X:               cl.csqc_origin[0] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ORIGIN_Y:               cl.csqc_origin[1] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ORIGIN_Z:               cl.csqc_origin[2] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ANGLES:                 VectorCopy(f, cl.csqc_angles);
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ANGLES_X:               cl.csqc_angles[0] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ANGLES_Y:               cl.csqc_angles[1] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ANGLES_Z:               cl.csqc_angles[2] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_DRAWWORLD:              cl.csqc_vidvars.drawworld = k;
-                                                       break;
-       case VF_DRAWENGINESBAR: cl.csqc_vidvars.drawenginesbar = k;
-                                                       break;
-       case VF_DRAWCROSSHAIR:  cl.csqc_vidvars.drawcrosshair = k;
-                                                       break;
-
-       case VF_CL_VIEWANGLES:  VectorCopy(f, cl.viewangles);
-                                                       break;
-       case VF_CL_VIEWANGLES_X:cl.viewangles[0] = k;
-                                                       break;
-       case VF_CL_VIEWANGLES_Y:cl.viewangles[1] = k;
-                                                       break;
-       case VF_CL_VIEWANGLES_Z:cl.viewangles[2] = k;
-                                                       break;
-
-       case VF_PERSPECTIVE:    r_view.useperspective = k != 0;
-                                                       break;
-
-       default:                                PRVM_G_FLOAT(OFS_RETURN) = 0;
-                                                       VM_Warning("VM_CL_R_SetView : unknown parm %i\n", c);
-                                                       return;
+       case VF_MIN:
+               r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
+               r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
+               break;
+       case VF_MIN_X:
+               r_view.x = (int)(k * vid.width / vid_conwidth.value);
+               break;
+       case VF_MIN_Y:
+               r_view.y = (int)(k * vid.height / vid_conheight.value);
+               break;
+       case VF_SIZE:
+               r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
+               r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
+               break;
+       case VF_SIZE_Y:
+               r_view.width = (int)(k * vid.width / vid_conwidth.value);
+               break;
+       case VF_SIZE_X:
+               r_view.height = (int)(k * vid.height / vid_conheight.value);
+               break;
+       case VF_VIEWPORT:
+               r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
+               r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
+               f = PRVM_G_VECTOR(OFS_PARM2);
+               r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
+               r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
+               break;
+       case VF_FOV:
+               r_view.frustum_x = tan(f[0] * M_PI / 360.0);r_view.ortho_x = f[0];
+               r_view.frustum_y = tan(f[1] * M_PI / 360.0);r_view.ortho_y = f[1];
+               break;
+       case VF_FOVX:
+               r_view.frustum_x = tan(k * M_PI / 360.0);r_view.ortho_x = k;
+               break;
+       case VF_FOVY:
+               r_view.frustum_y = tan(k * M_PI / 360.0);r_view.ortho_y = k;
+               break;
+       case VF_ORIGIN:
+               VectorCopy(f, cl.csqc_origin);
+               CSQC_R_RecalcView();
+               break;
+       case VF_ORIGIN_X:
+               cl.csqc_origin[0] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ORIGIN_Y:
+               cl.csqc_origin[1] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ORIGIN_Z:
+               cl.csqc_origin[2] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ANGLES:
+               VectorCopy(f, cl.csqc_angles);
+               CSQC_R_RecalcView();
+               break;
+       case VF_ANGLES_X:
+               cl.csqc_angles[0] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ANGLES_Y:
+               cl.csqc_angles[1] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ANGLES_Z:
+               cl.csqc_angles[2] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_DRAWWORLD:
+               cl.csqc_vidvars.drawworld = k;
+               break;
+       case VF_DRAWENGINESBAR:
+               cl.csqc_vidvars.drawenginesbar = k;
+               break;
+       case VF_DRAWCROSSHAIR:
+               cl.csqc_vidvars.drawcrosshair = k;
+               break;
+       case VF_CL_VIEWANGLES:
+               VectorCopy(f, cl.viewangles);
+               break;
+       case VF_CL_VIEWANGLES_X:
+               cl.viewangles[0] = k;
+               break;
+       case VF_CL_VIEWANGLES_Y:
+               cl.viewangles[1] = k;
+               break;
+       case VF_CL_VIEWANGLES_Z:
+               cl.viewangles[2] = k;
+               break;
+       case VF_PERSPECTIVE:
+               r_view.useperspective = k != 0;
+               break;
+       default:
+               PRVM_G_FLOAT(OFS_RETURN) = 0;
+               VM_Warning("VM_CL_R_SetView : unknown parm %i\n", c);
+               return;
        }
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
@@ -817,7 +844,7 @@ static void VM_CL_R_AddDynamicLight (void)
 {
        float           *pos, *col;
        matrix4x4_t     matrix;
-       VM_SAFEPARMCOUNTRANGE(3, 8, VM_CL_R_AddDynamicLight); // allow more than 3 because we may extend this in the future
+       VM_SAFEPARMCOUNTRANGE(3, 3, VM_CL_R_AddDynamicLight);
 
        // if we've run out of dlights, just return
        if (r_refdef.numlights >= MAX_DLIGHTS)
@@ -1652,7 +1679,7 @@ static void VM_CL_te_explosion2 (void)
        colorLength = (int)PRVM_G_FLOAT(OFS_PARM2);
        CL_FindNonSolidLocation(pos, pos2, 10);
        CL_ParticleExplosion2(pos2, colorStart, colorLength);
-       tempcolor = (unsigned char *)&palette_complete[(rand()%colorLength) + colorStart];
+       tempcolor = palette_rgb[(rand()%colorLength) + colorStart];
        color[0] = tempcolor[0] * (2.0f / 255.0f);
        color[1] = tempcolor[1] * (2.0f / 255.0f);
        color[2] = tempcolor[2] * (2.0f / 255.0f);
@@ -1764,7 +1791,81 @@ static void VM_CL_getsurfacepoint(void)
        // FIXME: implement rotation/scaling
        VectorAdd(&(model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.client->origin, PRVM_G_VECTOR(OFS_RETURN));
 }
+//PF_getsurfacepointattribute,     // #486 vector(entity e, float s, float n, float a) getsurfacepointattribute = #486;
+// float SPA_POSITION = 0;
+// float SPA_S_AXIS = 1;
+// float SPA_R_AXIS = 2;
+// float SPA_T_AXIS = 3; // same as SPA_NORMAL
+// float SPA_TEXCOORDS0 = 4;
+// float SPA_LIGHTMAP0_TEXCOORDS = 5;
+// float SPA_LIGHTMAP0_COLOR = 6;
+// TODO: add some wrapper code and merge VM_CL/SV_getsurface* [12/16/2007 Black]
+static void VM_CL_getsurfacepointattribute(void)
+{
+       prvm_edict_t *ed;
+       model_t *model;
+       msurface_t *surface;
+       int pointnum;
+       int attributetype;
+
+       VM_SAFEPARMCOUNT(3, VM_CL_getsurfacenumpoints);
+       VectorClear(PRVM_G_VECTOR(OFS_RETURN));
+       ed = PRVM_G_EDICT(OFS_PARM0);
+       if (!(model = CL_GetModelFromEdict(ed)) || !(surface = cl_getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1))))
+               return;
+       // note: this (incorrectly) assumes it is a simple polygon
+       pointnum = (int)PRVM_G_FLOAT(OFS_PARM2);
+       if (pointnum < 0 || pointnum >= surface->num_vertices)
+               return;
+
+       // FIXME: implement rotation/scaling
+       attributetype = (int) PRVM_G_FLOAT(OFS_PARM3);
 
+       switch( attributetype ) {
+               // float SPA_POSITION = 0;
+               case 0:
+                       VectorAdd(&(model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.server->origin, PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               // float SPA_S_AXIS = 1;
+               case 1:
+                       VectorCopy(&(model->surfmesh.data_svector3f + 3 * surface->num_firstvertex)[pointnum * 3], PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               // float SPA_R_AXIS = 2;
+               case 2:
+                       VectorCopy(&(model->surfmesh.data_tvector3f + 3 * surface->num_firstvertex)[pointnum * 3], PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               // float SPA_T_AXIS = 3; // same as SPA_NORMAL
+               case 3:
+                       VectorCopy(&(model->surfmesh.data_normal3f + 3 * surface->num_firstvertex)[pointnum * 3], PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               // float SPA_TEXCOORDS0 = 4;
+               case 4: {
+                       float *ret = PRVM_G_VECTOR(OFS_RETURN);
+                       float *texcoord = &(model->surfmesh.data_texcoordtexture2f + 2 * surface->num_firstvertex)[pointnum * 2];
+                       ret[0] = texcoord[0];
+                       ret[1] = texcoord[1];
+                       ret[2] = 0.0f;
+                       break;
+               }
+               // float SPA_LIGHTMAP0_TEXCOORDS = 5;
+               case 5: {
+                       float *ret = PRVM_G_VECTOR(OFS_RETURN);
+                       float *texcoord = &(model->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[pointnum * 2];
+                       ret[0] = texcoord[0];
+                       ret[1] = texcoord[1];
+                       ret[2] = 0.0f;
+                       break;
+               }
+               // float SPA_LIGHTMAP0_COLOR = 6;
+               case 6:
+                       // ignore alpha for now..
+                       VectorCopy( &(model->surfmesh.data_normal3f + 4 * surface->num_firstvertex)[pointnum * 4], PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               default:
+                       VectorSet( PRVM_G_VECTOR(OFS_RETURN), 0.0f, 0.0f, 0.0f );
+                       break;
+       }
+}
 // #436 vector(entity e, float s) getsurfacenormal
 static void VM_CL_getsurfacenormal(void)
 {
@@ -3076,8 +3177,8 @@ VM_drawfill,                                      // #323 float(vector position, vector size, vector rgb, float a
 VM_drawsetcliparea,                            // #324 void(float x, float y, float width, float height) drawsetcliparea
 VM_drawresetcliparea,                  // #325 void(void) drawresetcliparea
 VM_drawcolorcodedstring,               // #326 float drawcolorcodedstring(vector position, string text, vector scale, vector rgb, float alpha, float flag) (EXT_CSQC)
-NULL,                                                  // #327
-NULL,                                                  // #328
+NULL,                                                  // #327 // FIXME add stringwidth() here?
+NULL,                                                  // #328 // FIXME add drawsubpic() here?
 NULL,                                                  // #329
 VM_CL_getstatf,                                        // #330 float(float stnum) getstatf (EXT_CSQC)
 VM_CL_getstati,                                        // #331 float(float stnum) getstati (EXT_CSQC)
@@ -3236,12 +3337,20 @@ VM_cvar_defstring,                              // #482 string(string s) cvar_defstring (DP_QC_CVAR_DEFSTR
 VM_CL_pointsound,                              // #483 void(vector origin, string sample, float volume, float attenuation) (DP_SV_POINTSOUND)
 VM_strreplace,                                 // #484 string(string search, string replace, string subject) strreplace (DP_QC_STRREPLACE)
 VM_strireplace,                                        // #485 string(string search, string replace, string subject) strireplace (DP_QC_STRREPLACE)
-NULL,                                                  // #486
-NULL,                                                  // #487
-NULL,                                                  // #488
-NULL,                                                  // #489
-NULL,                                                  // #490
-NULL,                                                  // #491
+VM_CL_getsurfacepointattribute,// #486 vector(entity e, float s, float n, float a) getsurfacepointattribute = #486;
+#ifdef SUPPORT_GECKO
+VM_gecko_create,                                       // #487
+VM_gecko_destroy,                                      // #488
+VM_gecko_navigate,                             // #489
+VM_gecko_keyevent,                             // #490
+VM_gecko_movemouse,                            // #491
+#else
+NULL,                                                                  // #487
+NULL,                                                                  // #488
+NULL,                                                                  // #489
+NULL,                                                                  // #490
+NULL,                                                                  // #491
+#endif
 NULL,                                                  // #492
 NULL,                                                  // #493
 NULL,                                                  // #494
@@ -3256,6 +3365,7 @@ const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t);
 
 void VM_CL_Cmd_Init(void)
 {
+       VM_Cmd_Init();
        // TODO: replace vm_polygons stuff with a more general debugging polygon system, and make vm_polygons functions use that system
        if(vm_polygons_initialized)
        {
@@ -3266,6 +3376,7 @@ void VM_CL_Cmd_Init(void)
 
 void VM_CL_Cmd_Reset(void)
 {
+       VM_Cmd_Reset();
        if(vm_polygons_initialized)
        {
                Mem_FreePool(&vm_polygons_pool);