]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
patch from VorteX that makes GAME_DELUXEQUAKE mode reset a cvar in the
[xonotic/darkplaces.git] / prvm_cmds.c
index 36cb5dbd56b004db67f3ffe50aa8723943ecae24..e0ec50e20957a3d74bd8f04f9625f5b688cdce5c 100644 (file)
@@ -4,6 +4,8 @@
 // cause large (I think they will) parts are from pr_cmds the same copyright like in pr_cmds
 // also applies here
 
+#include "quakedef.h"
+
 #include "prvm_cmds.h"
 #include <time.h>
 
@@ -2074,10 +2076,12 @@ int tokens[256];
 void VM_tokenize (void)
 {
        const char *p;
+       static char string[VM_STRINGTEMP_LENGTH]; // static, because it's big
 
        VM_SAFEPARMCOUNT(1,VM_tokenize);
 
-       p = PRVM_G_STRING(OFS_PARM0);
+       strlcpy(string, PRVM_G_STRING(OFS_PARM0), sizeof(string));
+       p = string;
 
        num_tokens = 0;
        while(COM_ParseToken_VM_Tokenize(&p, false))
@@ -2113,10 +2117,12 @@ void VM_tokenizebyseparator (void)
        const char *p;
        const char *token;
        char tokentext[MAX_INPUTLINE];
+       static char string[VM_STRINGTEMP_LENGTH]; // static, because it's big
 
        VM_SAFEPARMCOUNTRANGE(2, 8,VM_tokenizebyseparator);
 
-       p = PRVM_G_STRING(OFS_PARM0);
+       strlcpy(string, PRVM_G_STRING(OFS_PARM0), sizeof(string));
+       p = string;
 
        numseparators = 0;;
        for (j = 1;j < prog->argc;j++)
@@ -2729,6 +2735,24 @@ void VM_drawcolorcodedstring(void)
 }
 /*
 =========
+VM_stringwidth
+
+float  stringwidth(string text, float allowColorCodes)
+=========
+*/
+void VM_stringwidth(void)
+{
+       const char  *string;
+       int colors;
+       VM_SAFEPARMCOUNT(2,VM_drawstring);
+
+       string = PRVM_G_STRING(OFS_PARM0);
+       colors = (int)PRVM_G_FLOAT(OFS_PARM1);
+
+       PRVM_G_FLOAT(OFS_RETURN) = DrawQ_String(0, 0, string, 0, 1, 1, 0, 0, 0, 0, 0, NULL, !colors); // 1x1 characters, don't actually draw
+}
+/*
+=========
 VM_drawpic
 
 float  drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag)
@@ -2771,6 +2795,60 @@ void VM_drawpic(void)
        DrawQ_Pic(pos[0], pos[1], Draw_CachePic(picname, true), size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
+/*
+=========
+VM_drawsubpic
+
+float  drawsubpic(vector position, vector size, string pic, vector srcPos, vector srcSize, vector rgb, float alpha, float flag)
+
+=========
+*/
+void VM_drawsubpic(void)
+{
+       const char *picname;
+       float *size, *pos, *rgb, *srcPos, *srcSize, alpha;
+       int flag;
+
+       VM_SAFEPARMCOUNT(8,VM_drawsubpic);
+
+       picname = PRVM_G_STRING(OFS_PARM2);
+       VM_CheckEmptyString (picname);
+
+       // is pic cached ? no function yet for that
+       if(!1)
+       {
+               PRVM_G_FLOAT(OFS_RETURN) = -4;
+               VM_Warning("VM_drawsubpic: %s: %s not cached !\n", PRVM_NAME, picname);
+               return;
+       }
+
+       pos = PRVM_G_VECTOR(OFS_PARM0);
+       size = PRVM_G_VECTOR(OFS_PARM1);
+       srcPos = PRVM_G_VECTOR(OFS_PARM3);
+       srcSize = PRVM_G_VECTOR(OFS_PARM4);
+       rgb = PRVM_G_VECTOR(OFS_PARM5);
+       alpha = PRVM_G_FLOAT(OFS_PARM6);
+       flag = (int) PRVM_G_FLOAT(OFS_PARM7);
+
+       if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
+       {
+               PRVM_G_FLOAT(OFS_RETURN) = -2;
+               VM_Warning("VM_drawsubpic: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
+               return;
+       }
+
+       if(pos[2] || size[2])
+               Con_Printf("VM_drawsubpic: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
+
+       DrawQ_SuperPic(pos[0], pos[1], Draw_CachePic(picname, true),
+               size[0], size[1],
+               srcPos[0],              srcPos[1],              rgb[0], rgb[1], rgb[2], alpha,
+               srcPos[0] + srcSize[0], srcPos[1],              rgb[0], rgb[1], rgb[2], alpha,
+               srcPos[0],              srcPos[1] + srcSize[1], rgb[0], rgb[1], rgb[2], alpha,
+               srcPos[0] + srcSize[0], srcPos[1] + srcSize[1], rgb[0], rgb[1], rgb[2], alpha,
+               flag);
+       PRVM_G_FLOAT(OFS_RETURN) = 1;
+}
 
 /*
 =========