X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=prvm_cmds.c;h=b7cae0d24e345234b08789055f888fcaed3820e4;hb=44fe4c427b5e62a2ccc81f8ff04f62887c214d2c;hp=57f192b39212fbefd1994a514b815cbf80c4b104;hpb=cb16a7014e2bf0080ea13bd228e09a7e9e7e611e;p=xonotic%2Fdarkplaces.git diff --git a/prvm_cmds.c b/prvm_cmds.c index 57f192b3..b7cae0d2 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -4,22 +4,33 @@ // 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 +extern cvar_t prvm_backtraceforwarnings; + // LordHavoc: changed this to NOT use a return statement, so that it can be used in functions that must return a value void VM_Warning(const char *fmt, ...) { va_list argptr; char msg[MAX_INPUTLINE]; + static double recursive = -1; va_start(argptr,fmt); dpvsnprintf(msg,sizeof(msg),fmt,argptr); va_end(argptr); - Con_Print(msg); + Con_Printf(msg); + // TODO: either add a cvar/cmd to control the state dumping or replace some of the calls with Con_Printf [9/13/2006 Black] - //PRVM_PrintState(); + if(prvm_backtraceforwarnings.integer && recursive != realtime) // NOTE: this compares to the time, just in case if PRVM_PrintState causes a Host_Error and keeps recursive set + { + recursive = realtime; + PRVM_PrintState(); + recursive = -1; + } } @@ -318,50 +329,14 @@ void VM_vectoyaw (void) ================= VM_vectoangles -vector vectoangles(vector) +vector vectoangles(vector[, vector]) ================= */ void VM_vectoangles (void) { - float *value1; - float forward; - float yaw, pitch; + VM_SAFEPARMCOUNTRANGE(1, 2,VM_vectoangles); - 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; - } - - 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); } /* @@ -2074,10 +2049,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 +2090,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 +2577,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 +2634,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 +2675,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,7 +2716,7 @@ 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; } /* @@ -2743,7 +2735,7 @@ void VM_stringwidth(void) 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_TextWidth_Font(string, 0, !colors, getdrawfont()); // 1x1 characters, don't actually draw } /* ========= @@ -3081,6 +3073,249 @@ void VM_cin_restart( void ) 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 @@ -3151,10 +3386,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) { @@ -3571,9 +3802,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) @@ -3593,6 +3824,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; @@ -3939,7 +4171,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; @@ -4295,6 +4527,9 @@ void VM_Cmd_Init(void) // only init the stuff for the current prog VM_Files_Init(); VM_Search_Init(); +#ifdef SUPPORT_GECKO + VM_Gecko_Init(); +#endif // VM_BufStr_Init(); } @@ -4303,6 +4538,9 @@ void VM_Cmd_Reset(void) CL_PurgeOwner( MENUOWNER ); VM_Search_Reset(); VM_Files_CloseAll(); +#ifdef SUPPORT_GECKO + VM_Gecko_Destroy(); +#endif // VM_BufStr_ShutDown(); }