X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=prvm_cmds.c;h=e79bfce593b7fa4be5f81e651d21d7cd00a7ae8b;hb=8d7671158db57358a5f7eec510adbd05cdf62189;hp=dbfd5723548c62c1cf436de4afe1d9b4a1e45c17;hpb=83d32b98d1fec43cc350aadbd83aab2d4c5248da;p=xonotic%2Fdarkplaces.git diff --git a/prvm_cmds.c b/prvm_cmds.c index dbfd5723..e79bfce5 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -99,6 +99,10 @@ string chr(float ascii) float itof(intt ent) intt ftoi(float num) + +float altstr_count(string) +string altstr_prepare(string) +string altstr_get(string,float) perhaps only : Menu : WriteMsg =============================== @@ -112,8 +116,8 @@ perhaps only : Menu : WriteMsg WriteString(string data, float dest, float desto) WriteEntity(entity data, float dest, float desto) -Client & Menu : draw functions -=============================== +Client & Menu : draw functions & video functions +=================================================== float iscachedpic(string pic) string precache_pic(string pic) @@ -125,7 +129,12 @@ float drawfill(vector position, vector size, vector rgb, float alpha, float flag drawsetcliparea(float x, float y, float width, float height) drawresetcliparea() vector getimagesize(string pic) - + +float cin_open(string file, string name) +void cin_close(string name) +void cin_setstate(string name, float type) +float cin_getstate(string name) +void cin_restart(string name) ============================================================================== menu cmd list: @@ -154,6 +163,8 @@ string gethostcachestring(float type, float hostnr) #include "clprogdefs.h" #include "mprogdefs.h" +#include "cl_video.h" + //============================================================================ // nice helper macros @@ -392,8 +403,6 @@ void VM_sprint (void) } client = svs.clients + clientnum; - if (!client->netconnection) - return; VM_VarString(1, string, sizeof(string)); MSG_WriteChar(&client->message,svc_print); MSG_WriteString(&client->message, string); @@ -561,13 +570,9 @@ float random() */ void VM_random (void) { - float num; - VM_SAFEPARMCOUNT(0,VM_random); - num = (rand ()&0x7fff) / ((float)0x7fff); - - PRVM_G_FLOAT(OFS_RETURN) = num; + PRVM_G_FLOAT(OFS_RETURN) = lhrandom(0, 1); } /* @@ -1042,7 +1047,7 @@ void VM_findchain (void) if (strcmp(t,s)) continue; - PRVM_E_FLOAT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain); + PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain); chain = ent; } @@ -1085,10 +1090,10 @@ void VM_findchainfloat (void) prog->xfunction->builtinsprofile++; if (ent->p.e->free) continue; - if (E_FLOAT(ent,f) != s) + if (PRVM_E_FLOAT(ent,f) != s) continue; - PRVM_E_FLOAT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain); + PRVM_E_INT(ent,chain_of) = PRVM_EDICT_TO_PROG(chain); chain = ent; } @@ -1138,7 +1143,7 @@ void VM_precache_sound (void) s = PRVM_G_STRING(OFS_PARM0); PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0); VM_CheckEmptyString (s); - + if(!S_PrecacheSound (s,true, true)) Con_Printf("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME); } @@ -1596,7 +1601,7 @@ void VM_max (void) for (i = 1;i < prog->argc;i++) if (PRVM_G_FLOAT((OFS_PARM0+i*3)) > f) f = PRVM_G_FLOAT((OFS_PARM0+i*3)); - G_FLOAT(OFS_RETURN) = f; + PRVM_G_FLOAT(OFS_RETURN) = f; } else PRVM_ERROR("VM_max: %s must supply at least 2 floats\n", PRVM_NAME); @@ -1836,7 +1841,7 @@ void VM_fgets(void) // remove \n following \r if (c == '\r') c = FS_Getc(VM_FILES[filenum]); - if (developer.integer) + if (developer.integer >= 3) Con_Printf("fgets: %s: %s\n", PRVM_NAME, string); if (c >= 0 || end) PRVM_G_INT(OFS_RETURN) = PRVM_SetString(string); @@ -2527,7 +2532,7 @@ void VM_iscachedpic(void) VM_SAFEPARMCOUNT(1,VM_iscachedpic); // drawq hasnt such a function, thus always return true - PRVM_G_FLOAT(OFS_RETURN) = TRUE; + PRVM_G_FLOAT(OFS_RETURN) = false; } /* @@ -2648,7 +2653,7 @@ void VM_drawstring(void) return; } - VM_CheckEmptyString(string); + //VM_CheckEmptyString(string); Why should it be checked - perhaps the menu wants to the precolored letters, too? pos = PRVM_G_VECTOR(OFS_PARM0); scale = PRVM_G_VECTOR(OFS_PARM2); @@ -2774,12 +2779,12 @@ void VM_drawsetcliparea(void) float x,y,w,h; VM_SAFEPARMCOUNT(4,VM_drawsetcliparea); - x = bound(0,PRVM_G_FLOAT(OFS_PARM0),vid.conwidth); - y = bound(0,PRVM_G_FLOAT(OFS_PARM1),vid.conheight); - w = bound(0,PRVM_G_FLOAT(OFS_PARM2),(vid.conwidth - x)); - h = bound(0,PRVM_G_FLOAT(OFS_PARM3),(vid.conheight - y)); + x = bound(0, PRVM_G_FLOAT(OFS_PARM0), vid.conwidth); + y = bound(0, PRVM_G_FLOAT(OFS_PARM1), vid.conheight); + w = bound(0, PRVM_G_FLOAT(OFS_PARM2) + PRVM_G_FLOAT(OFS_PARM0) - x, (vid.conwidth - x)); + h = bound(0, PRVM_G_FLOAT(OFS_PARM3) + PRVM_G_FLOAT(OFS_PARM1) - y, (vid.conheight - y)); - DrawQ_SetClipArea(x,y,w,h); + DrawQ_SetClipArea(x, y, w, h); } /* @@ -2824,6 +2829,231 @@ void VM_getimagesize(void) PRVM_G_VECTOR(OFS_RETURN)[2] = 0; } +// CL_Video interface functions + +/* +======================== +VM_cin_open + +float cin_open(string file, string name) +======================== +*/ +void VM_cin_open( void ) +{ + char *file; + char *name; + + VM_SAFEPARMCOUNT( 2, VM_cin_open ); + + file = PRVM_G_STRING( OFS_PARM0 ); + name = PRVM_G_STRING( OFS_PARM1 ); + + VM_CheckEmptyString( file ); + VM_CheckEmptyString( name ); + + if( CL_OpenVideo( file, name, MENUOWNER ) ) + PRVM_G_FLOAT( OFS_RETURN ) = 1; + else + PRVM_G_FLOAT( OFS_RETURN ) = 0; +} + +/* +======================== +VM_cin_close + +void cin_close(string name) +======================== +*/ +void VM_cin_close( void ) +{ + char *name; + + VM_SAFEPARMCOUNT( 1, VM_cin_close ); + + name = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( name ); + + CL_CloseVideo( CL_GetVideo( name ) ); +} + +/* +======================== +VM_cin_setstate +void cin_setstate(string name, float type) +======================== +*/ +void VM_cin_setstate( void ) +{ + char *name; + clvideostate_t state; + clvideo_t *video; + + VM_SAFEPARMCOUNT( 2, VM_cin_netstate ); + + name = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( name ); + + state = PRVM_G_FLOAT( OFS_PARM1 ); + + video = CL_GetVideo( name ); + if( video && state > CLVIDEO_UNUSED && state < CLVIDEO_STATECOUNT ) + CL_SetVideoState( video, state ); +} + +/* +======================== +VM_cin_getstate + +float cin_getstate(string name) +======================== +*/ +void VM_cin_getstate( void ) +{ + char *name; + clvideo_t *video; + + VM_SAFEPARMCOUNT( 1, VM_cin_getstate ); + + name = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( name ); + + video = CL_GetVideo( name ); + if( video ) + PRVM_G_FLOAT( OFS_RETURN ) = (int)video->state; + else + PRVM_G_FLOAT( OFS_RETURN ) = 0; +} + +/* +======================== +VM_cin_restart + +void cin_restart(string name) +======================== +*/ +void VM_cin_restart( void ) +{ + char *name; + clvideo_t *video; + + VM_SAFEPARMCOUNT( 1, VM_cin_restart ); + + name = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( name ); + + video = CL_GetVideo( name ); + if( video ) + CL_RestartVideo( video ); +} + +//////////////////////////////////////// +// AltString functions +//////////////////////////////////////// + +/* +======================== +VM_altstr_count + +float altstr_count(string) +======================== +*/ +void VM_altstr_count( void ) +{ + char *altstr, *pos; + int count; + + VM_SAFEPARMCOUNT( 1, VM_altstr_count ); + + altstr = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( altstr ); + + for( count = 0, pos = altstr ; *pos ; pos++ ) + if( *pos == '\\' && !*++pos ) + break; + else if( *pos == '\'' ) + count++; + + PRVM_G_FLOAT( OFS_RETURN ) = (float) (count / 2); +} + +/* +======================== +VM_altstr_prepare + +string altstr_prepare(string) +======================== +*/ +void VM_altstr_prepare( void ) +{ + char *outstr, *out; + char *instr, *in; + int size; + + VM_SAFEPARMCOUNT( 1, VM_altstr_prepare ); + + instr = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( instr ); + outstr = VM_GetTempString(); + + for( out = outstr, in = instr, size = VM_STRINGTEMP_LENGTH - 1 ; size && *in ; size--, in++, out++ ) + if( *in == '\'' ) { + *out++ = '\\'; + *out = '\''; + size--; + } else + *out = *in; + *out = 0; + + PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( outstr ); +} + +/* +======================== +VM_altstr_get + +string altstr_get(string, float) +======================== +*/ +void VM_altstr_get( void ) +{ + char *altstr, *pos, *outstr, *out; + int count, size; + + VM_SAFEPARMCOUNT( 2, VM_altstr_get ); + + altstr = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( altstr ); + + count = PRVM_G_FLOAT( OFS_PARM1 ); + count = count * 2 + 1; + + for( pos = altstr ; *pos && count ; pos++ ) + if( *pos == '\\' && !*++pos ) + break; + else if( *pos == '\'' ) + count--; + + if( !*pos ) { + PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( "" ); + return; + } + + outstr = VM_GetTempString(); + for( out = outstr, size = VM_STRINGTEMP_LENGTH - 1 ; size && *pos ; size--, pos++, out++ ) + if( *pos == '\\' ) { + if( !*++pos ) + break; + *out = *pos; + size--; + } else if( *pos == '\'' ) + break; + else + *out = *pos; + + *out = 0; + PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( outstr ); +} + void VM_Cmd_Init(void) { // only init the stuff for the current prog @@ -2835,7 +3065,16 @@ void VM_Cmd_Init(void) void VM_Cmd_Reset(void) { //Mem_EmptyPool(VM_STRINGS_MEMPOOL); + if( developer.integer >= 2 && VM_STRINGS_MEMPOOL ) { + memheader_t *header; + int i; + + for( i = 0, header = VM_STRINGS_MEMPOOL->chain ; header ; header = header->next, i++ ) + Con_DPrintf( "Leaked string %i (size: %i): %.*s\n", i, header->size, header->size, ((char*)header) + sizeof( memheader_t ) ); + } + Mem_FreePool(&VM_STRINGS_MEMPOOL); + CL_PurgeOwner( MENUOWNER ); VM_Search_Reset(); VM_Files_CloseAll(); } @@ -2884,7 +3123,7 @@ void VM_CL_Cmd_Reset(void) // Menu char *vm_m_extensions = -""; +"DP_CINEMATIC_DPV"; /* ========= @@ -3205,7 +3444,7 @@ void VM_M_gethostcachevalue( void ) else switch(type) { case 0: - PRVM_G_FLOAT ( OFS_RETURN ) = hostCacheCount; + PRVM_G_FLOAT ( OFS_RETURN ) = hostcache_viewcount; return; case 1: PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount; @@ -3253,18 +3492,18 @@ void VM_M_gethostcachestring(void) hostnr = PRVM_G_FLOAT(OFS_PARM1); - if(hostnr < 0 || hostnr >= hostCacheCount) + if(hostnr < 0 || hostnr >= hostcache_viewcount) { Con_Print("VM_M_gethostcachestring: bad hostnr passed!\n"); return; } if( type == 0 ) - PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( hostcache[hostnr].cname ); + PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( hostcache_viewset[hostnr]->info.cname ); else if( type == 1 ) - PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( hostcache[hostnr].line1 ); + PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( hostcache_viewset[hostnr]->line1 ); else - PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( hostcache[hostnr].line2 ); + PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( hostcache_viewset[hostnr]->line2 ); } prvm_builtin_t vm_m_builtins[] = { @@ -3349,8 +3588,12 @@ prvm_builtin_t vm_m_builtins[] = { VM_search_getfilename, // 77 VM_chr, VM_itof, - VM_ftoi,// 80 - e10, // 90 + VM_ftoi, // 80 + VM_itof, // isString + VM_altstr_count, + VM_altstr_prepare, + VM_altstr_get, // 84 + 0,0,0,0,0,0, // 90 e10, // 100 e100, // 200 e100, // 300 @@ -3381,7 +3624,12 @@ prvm_builtin_t vm_m_builtins[] = { VM_drawsetcliparea, VM_drawresetcliparea, VM_getimagesize,// 460 - e10, // 470 + VM_cin_open, + VM_cin_close, + VM_cin_setstate, + VM_cin_getstate, + VM_cin_restart, // 465 + 0,0,0,0,0, // 470 e10, // 480 e10, // 490 e10, // 500