]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
Remove the NG_MENU additions as it has never really been used.
[xonotic/darkplaces.git] / prvm_cmds.c
index 36cb5dbd56b004db67f3ffe50aa8723943ecae24..543fd23c4fd13b698b2c6309b8695164b9d10ad0 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++)
@@ -2598,6 +2604,19 @@ void VM_freepic(void)
        Draw_FreePic(s);
 }
 
+dp_font_t *getdrawfont()
+{
+       if(prog->globaloffsets.drawfont >= 0)
+       {
+               int f = PRVM_G_FLOAT(prog->globaloffsets.drawfont);
+               if(f < 0 || f >= MAX_FONTS)
+                       return FONT_DEFAULT;
+               return &dp_fonts[f];
+       }
+       else
+               return FONT_DEFAULT;
+}
+
 /*
 =========
 VM_drawcharacter
@@ -2642,7 +2661,7 @@ void VM_drawcharacter(void)
                return;
        }
 
-       DrawQ_String (pos[0], pos[1], &character, 1, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true);
+       DrawQ_String_Font(pos[0], pos[1], &character, 1, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 
@@ -2683,7 +2702,7 @@ void VM_drawstring(void)
        if(pos[2] || scale[2])
                Con_Printf("VM_drawstring: z value%s from %s discarded\n",(pos[2] && scale[2]) ? "s" : " ",((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
 
-       DrawQ_String (pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true);
+       DrawQ_String_Font(pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 
@@ -2724,11 +2743,29 @@ void VM_drawcolorcodedstring(void)
                Con_Printf("VM_drawcolorcodedstring: z value%s from %s discarded\n",(pos[2] && scale[2]) ? "s" : " ",((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
 
        color = -1;
-       DrawQ_String (pos[0], pos[1], string, 0, scale[0], scale[1], 1, 1, 1, PRVM_G_FLOAT(OFS_PARM3), flag, NULL, false);
+       DrawQ_String_Font(pos[0], pos[1], string, 0, scale[0], scale[1], 1, 1, 1, PRVM_G_FLOAT(OFS_PARM3), flag, NULL, false, getdrawfont());
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 /*
 =========
+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_Font(0, 0, string, 0, 1, 1, 0, 0, 0, 0, 0, NULL, !colors, getdrawfont()); // 1x1 characters, don't actually draw
+}
+/*
+=========
 VM_drawpic
 
 float  drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag)
@@ -2771,6 +2808,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;
+}
 
 /*
 =========
@@ -3009,6 +3100,156 @@ void VM_cin_restart( void )
                CL_RestartVideo( video );
 }
 
+#ifdef SUPPORT_GECKO
+static const char *vm_gecko_getfullname( const char *name ) {
+       // FIXME: assert that PRVM_NAME is not empty.. [12/3/2007 Black]
+       return va( "%s/%s", PRVM_NAME, name );
+}
+
+/*
+========================
+VM_gecko_create
+
+float[bool] gecko_create( string name )
+========================
+*/
+void VM_gecko_create( void ) {
+       const char *name;
+       
+       VM_SAFEPARMCOUNT( 1, VM_gecko_create );
+
+       name = PRVM_G_STRING( OFS_PARM0 );
+       VM_CheckEmptyString( name );
+
+       if( !CL_Gecko_CreateBrowser( vm_gecko_getfullname( name ) ) ) {
+               // TODO: error handling [12/3/2007 Black]
+               PRVM_G_FLOAT( OFS_RETURN ) = 0;
+               return;
+       }
+       PRVM_G_FLOAT( OFS_RETURN ) = 1;
+}
+
+/*
+========================
+VM_gecko_destroy
+
+void gecko_destroy( string name )
+========================
+*/
+void VM_gecko_destroy( void ) {
+       const char *name;
+       clgecko_t *instance;
+
+       VM_SAFEPARMCOUNT( 1, VM_gecko_destroy );
+
+       name = PRVM_G_STRING( OFS_PARM0 );
+       VM_CheckEmptyString( name );
+       instance = CL_Gecko_FindBrowser( vm_gecko_getfullname( name ) );
+       if( !instance ) {
+               return;
+       }
+       CL_Gecko_DestroyBrowser( instance );
+}
+
+/*
+========================
+VM_gecko_navigate
+
+void gecko_navigate( string name, string URI )
+========================
+*/
+void VM_gecko_navigate( void ) {
+       const char *name;
+       const char *URI;
+       clgecko_t *instance;
+
+       VM_SAFEPARMCOUNT( 2, VM_gecko_navigate );
+
+       name = PRVM_G_STRING( OFS_PARM0 );
+       URI = PRVM_G_STRING( OFS_PARM1 );
+       VM_CheckEmptyString( name );
+       VM_CheckEmptyString( URI );
+
+   instance = CL_Gecko_FindBrowser( vm_gecko_getfullname( name ) );
+       if( !instance ) {
+               return;
+       }
+       CL_Gecko_NavigateToURI( instance, URI );
+}
+
+/*
+========================
+VM_gecko_keyevent
+
+float[bool] gecko_keyevent( string name, float key, float eventtype ) 
+========================
+*/
+void VM_gecko_keyevent( void ) {
+       const char *name;
+       unsigned int key;
+       clgecko_buttoneventtype_t eventtype;
+       clgecko_t *instance;
+
+       VM_SAFEPARMCOUNT( 3, VM_gecko_keyevent );
+
+       name = PRVM_G_STRING( OFS_PARM0 );
+       VM_CheckEmptyString( name );
+       key = (unsigned int) PRVM_G_FLOAT( OFS_PARM1 );
+       switch( (unsigned int) PRVM_G_FLOAT( OFS_PARM3 ) ) {
+       case 0:
+               eventtype = CLG_BET_DOWN;
+               break;
+       case 1:
+               eventtype = CLG_BET_UP;
+               break;
+       case 2:
+               eventtype = CLG_BET_PRESS;
+               break;
+       case 3:
+               eventtype = CLG_BET_DOUBLECLICK;
+               break;
+       default:
+               // TODO: console printf? [12/3/2007 Black]
+               PRVM_G_FLOAT( OFS_RETURN ) = 0;
+               return;
+       }
+
+       instance = CL_Gecko_FindBrowser( vm_gecko_getfullname( name ) );
+       if( !instance ) {
+               PRVM_G_FLOAT( OFS_RETURN ) = 0;
+               return;
+       }
+
+       PRVM_G_FLOAT( OFS_RETURN ) = (CL_Gecko_Event_Key( instance, key, eventtype ) == true);
+}
+
+/*
+========================
+VM_gecko_movemouse
+
+void gecko_mousemove( string name, float x, float y )
+========================
+*/
+void VM_gecko_movemouse( void ) {
+       const char *name;
+       float x, y;
+       clgecko_t *instance;
+
+       VM_SAFEPARMCOUNT( 3, VM_gecko_movemouse );
+
+       name = PRVM_G_STRING( OFS_PARM0 );
+       VM_CheckEmptyString( name );
+       x = PRVM_G_FLOAT( OFS_PARM1 );
+       y = PRVM_G_FLOAT( OFS_PARM2 );
+       
+       instance = CL_Gecko_FindBrowser( vm_gecko_getfullname( name ) );
+       if( !instance ) {
+               return;
+       }
+       CL_Gecko_Event_CursorMove( instance, x, y );
+}
+#endif
+
 /*
 ==============
 VM_makevectors
@@ -3079,10 +3320,6 @@ void VM_drawline (void)
        DrawQ_Line(width, c1[0], c1[1], c2[0], c2[1], rgb[0], rgb[1], rgb[2], alpha, flags);
 }
 
-
-
-
-
 // float(float number, float quantity) bitshift (EXT_BITSHIFT)
 void VM_bitshift (void)
 {
@@ -3499,9 +3736,9 @@ void VM_buf_copy (void)
 /*
 ========================
 VM_buf_sort
-sort buffer by beginnings of strings (sortpower defaults it's lenght)
+sort buffer by beginnings of strings (cmplength defaults it's length)
 "backward == TRUE" means that sorting goes upside-down
-void buf_sort(float bufhandle, float sortpower, float backward) = #464;
+void buf_sort(float bufhandle, float cmplength, float backward) = #464;
 ========================
 */
 void VM_buf_sort (void)
@@ -3521,6 +3758,7 @@ void VM_buf_sort (void)
                VM_Warning("VM_buf_sort: tried to sort empty buffer %i in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
                return;
        }
+       // TODO: please someone rename this to buf_cmplength [12/3/2007 Black]
        buf_sortpower = (int)PRVM_G_FLOAT(OFS_PARM1);
        if(buf_sortpower <= 0)
                buf_sortpower = 99999999;
@@ -3867,7 +4105,7 @@ void VM_changepitch (void)
        PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.angles)->vector[0] = ANGLEMOD (current + move);
 }
 
-
+// TODO: adapt all static function names to use a single naming convention... [12/3/2007 Black]
 static int Is_Text_Color (char c, char t)
 {
        int a = 0;