=================
VM_vectoangles
-vector vectoangles(vector)
+vector vectoangles(vector[, vector])
=================
*/
void VM_vectoangles (void)
{
- float *value1;
- float forward;
- float yaw, pitch;
-
- VM_SAFEPARMCOUNT(1,VM_vectoangles);
-
- value1 = PRVM_G_VECTOR(OFS_PARM0);
-
- if (value1[1] == 0 && value1[0] == 0)
- {
- yaw = 0;
- if (value1[2] > 0)
- pitch = 90;
- else
- pitch = 270;
- }
- else
- {
- // LordHavoc: optimized a bit
- if (value1[0])
- {
- yaw = (atan2(value1[1], value1[0]) * 180 / M_PI);
- if (yaw < 0)
- yaw += 360;
- }
- else if (value1[1] > 0)
- yaw = 90;
- else
- yaw = 270;
-
- forward = sqrt(value1[0]*value1[0] + value1[1]*value1[1]);
- pitch = (atan2(value1[2], forward) * 180 / M_PI);
- if (pitch < 0)
- pitch += 360;
- }
+ VM_SAFEPARMCOUNTRANGE(1, 2,VM_vectoangles);
- PRVM_G_FLOAT(OFS_RETURN+0) = pitch;
- PRVM_G_FLOAT(OFS_RETURN+1) = yaw;
- PRVM_G_FLOAT(OFS_RETURN+2) = 0;
+ AnglesFromVectors(PRVM_G_VECTOR(OFS_RETURN), PRVM_G_VECTOR(OFS_PARM0), prog->argc >= 2 ? PRVM_G_VECTOR(OFS_PARM1) : NULL, true);
}
/*
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))
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++)
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
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;
}
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;
}
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;
}
/*
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
+ 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
}
/*
=========
CL_RestartVideo( video );
}
+#ifdef SUPPORT_GECKO
+/*
+========================
+VM_Gecko_Init
+========================
+*/
+void VM_Gecko_Init( void ) {
+ // the prog struct is memset to 0 by Initprog? [12/6/2007 Black]
+ // FIXME: remove the other _Init functions then, too? [12/6/2007 Black]
+}
+
+/*
+========================
+VM_Gecko_Destroy
+========================
+*/
+void VM_Gecko_Destroy( void ) {
+ int i;
+ for( i = 0 ; i < PRVM_MAX_GECKOINSTANCES ; i++ ) {
+ clgecko_t **instance = &prog->opengeckoinstances[ i ];
+ if( *instance ) {
+ CL_Gecko_DestroyBrowser( *instance );
+ }
+ *instance = NULL;
+ }
+}
+
+/*
+========================
+VM_gecko_create
+
+float[bool] gecko_create( string name )
+========================
+*/
+void VM_gecko_create( void ) {
+ const char *name;
+ int i;
+ clgecko_t *instance;
+
+ VM_SAFEPARMCOUNT( 1, VM_gecko_create );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ // find an empty slot for this gecko browser..
+ for( i = 0 ; i < PRVM_MAX_GECKOINSTANCES ; i++ ) {
+ if( prog->opengeckoinstances[ i ] == NULL ) {
+ break;
+ }
+ }
+ if( i == PRVM_MAX_GECKOINSTANCES ) {
+ VM_Warning("VM_gecko_create: %s ran out of gecko handles (%i)\n", PRVM_NAME, PRVM_MAX_GECKOINSTANCES);
+ PRVM_G_FLOAT( OFS_RETURN ) = 0;
+ return;
+ }
+
+ instance = prog->opengeckoinstances[ i ] = CL_Gecko_CreateBrowser( name );
+ if( !instance ) {
+ // 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( 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( 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_PARM2 ) ) {
+ 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( 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( name );
+ if( !instance ) {
+ return;
+ }
+ CL_Gecko_Event_CursorMove( instance, x, y );
+}
+
+
+/*
+========================
+VM_gecko_resize
+
+void gecko_resize( string name, float w, float h )
+========================
+*/
+void VM_gecko_resize( void ) {
+ const char *name;
+ float w, h;
+ clgecko_t *instance;
+
+ VM_SAFEPARMCOUNT( 3, VM_gecko_movemouse );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+ w = PRVM_G_FLOAT( OFS_PARM1 );
+ h = PRVM_G_FLOAT( OFS_PARM2 );
+
+ instance = CL_Gecko_FindBrowser( name );
+ if( !instance ) {
+ return;
+ }
+ CL_Gecko_Resize( instance, w, h );
+}
+
+
+/*
+========================
+VM_gecko_get_texture_extent
+
+vector gecko_get_texture_extent( string name )
+========================
+*/
+void VM_gecko_get_texture_extent( void ) {
+ const char *name;
+ clgecko_t *instance;
+
+ VM_SAFEPARMCOUNT( 1, VM_gecko_movemouse );
+
+ name = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( name );
+
+ PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+ instance = CL_Gecko_FindBrowser( name );
+ if( !instance ) {
+ PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
+ PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
+ return;
+ }
+ CL_Gecko_GetTextureExtent( instance,
+ PRVM_G_VECTOR(OFS_RETURN), PRVM_G_VECTOR(OFS_RETURN)+1 );
+}
+
+
+#endif
+
/*
==============
VM_makevectors
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)
{
/*
========================
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)
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;
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;
// only init the stuff for the current prog
VM_Files_Init();
VM_Search_Init();
+#ifdef SUPPORT_GECKO
+ VM_Gecko_Init();
+#endif
// VM_BufStr_Init();
}
CL_PurgeOwner( MENUOWNER );
VM_Search_Reset();
VM_Files_CloseAll();
+#ifdef SUPPORT_GECKO
+ VM_Gecko_Destroy();
+#endif
// VM_BufStr_ShutDown();
}