X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=prvm_cmds.c;h=b7cae0d24e345234b08789055f888fcaed3820e4;hb=0a094efd4075f5a4adf37b391e047b150c902b17;hp=543fd23c4fd13b698b2c6309b8695164b9d10ad0;hpb=52346e02f29e08dd01f1b723245d06a214700a26;p=xonotic%2Fdarkplaces.git diff --git a/prvm_cmds.c b/prvm_cmds.c index 543fd23c..b7cae0d2 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -9,19 +9,28 @@ #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; + } } @@ -320,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_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; + VM_SAFEPARMCOUNTRANGE(1, 2,VM_vectoangles); - 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); } /* @@ -2762,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_Font(0, 0, string, 0, 1, 1, 0, 0, 0, 0, 0, NULL, !colors, getdrawfont()); // 1x1 characters, don't actually draw + PRVM_G_FLOAT(OFS_RETURN) = DrawQ_TextWidth_Font(string, 0, !colors, getdrawfont()); // 1x1 characters, don't actually draw } /* ========= @@ -3101,9 +3074,30 @@ void VM_cin_restart( void ) } #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_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; + } } /* @@ -3115,13 +3109,28 @@ 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 ); - if( !CL_Gecko_CreateBrowser( vm_gecko_getfullname( 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; @@ -3144,7 +3153,7 @@ void VM_gecko_destroy( void ) { name = PRVM_G_STRING( OFS_PARM0 ); VM_CheckEmptyString( name ); - instance = CL_Gecko_FindBrowser( vm_gecko_getfullname( name ) ); + instance = CL_Gecko_FindBrowser( name ); if( !instance ) { return; } @@ -3170,7 +3179,7 @@ void VM_gecko_navigate( void ) { VM_CheckEmptyString( name ); VM_CheckEmptyString( URI ); - instance = CL_Gecko_FindBrowser( vm_gecko_getfullname( name ) ); + instance = CL_Gecko_FindBrowser( name ); if( !instance ) { return; } @@ -3195,7 +3204,7 @@ void VM_gecko_keyevent( void ) { 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 ) ) { + switch( (unsigned int) PRVM_G_FLOAT( OFS_PARM2 ) ) { case 0: eventtype = CLG_BET_DOWN; break; @@ -3214,7 +3223,7 @@ void VM_gecko_keyevent( void ) { return; } - instance = CL_Gecko_FindBrowser( vm_gecko_getfullname( name ) ); + instance = CL_Gecko_FindBrowser( name ); if( !instance ) { PRVM_G_FLOAT( OFS_RETURN ) = 0; return; @@ -3242,12 +3251,69 @@ void VM_gecko_movemouse( void ) { x = PRVM_G_FLOAT( OFS_PARM1 ); y = PRVM_G_FLOAT( OFS_PARM2 ); - instance = CL_Gecko_FindBrowser( vm_gecko_getfullname( name ) ); + 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 /* @@ -4461,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(); } @@ -4469,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(); }