X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=prvm_cmds.c;h=b6c6b16c89628d4f16cfc637183eb41d1c65fcb9;hb=783c61300adf71a38a5c9edb323d6f5ff90ac51d;hp=67cd6f9af97bbfe018e211cd9168c2708cf1a9c6;hpb=c1d9e759b83908c5398daf43a94f8585b9c7356a;p=xonotic%2Fdarkplaces.git diff --git a/prvm_cmds.c b/prvm_cmds.c index 67cd6f9a..b6c6b16c 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -96,6 +96,9 @@ float search_getsize(float handle) string search_getfilename(float handle, float num) string chr(float ascii) + +float itof(intt ent) +intt ftoi(float num) perhaps only : Menu : WriteMsg =============================== @@ -142,11 +145,12 @@ string findkeysforcommand(string command) float gethostcachevalue(float type) string gethostcachestring(float type, float hostnr) - + parseentitydata(entity ent, string data) */ #include "quakedef.h" #include "progdefs.h" +#include "progsvm.h" #include "clprogdefs.h" #include "mprogdefs.h" @@ -180,11 +184,6 @@ mempool_t *vm_strings_mempool[PRVM_MAXPROGS]; static char vm_string_temp[VM_STRINGTEMP_BUFFERS][VM_STRINGTEMP_LENGTH]; static int vm_string_tempindex = 0; -// qc cvar -#define MAX_QC_CVARS 128 * PRVM_MAXPROGS -cvar_t vm_qc_cvar[MAX_QC_CVARS]; -int vm_currentqc_cvar; - // qc file handling #define MAX_VMFILES 256 #define MAX_PRVMFILES MAX_VMFILES * PRVM_MAXPROGS @@ -393,8 +392,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); @@ -562,13 +559,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); } /* @@ -629,14 +622,13 @@ void VM_localsound(void) s = PRVM_G_STRING(OFS_PARM0); - if(!S_GetCached(s, true)) + if(!S_LocalSound (s)) { - Con_Printf("VM_localsound: %s : %s not cached !\n", PRVM_NAME, s); + Con_Printf("VM_localsound: Failed to play %s for %s !\n", s, PRVM_NAME); PRVM_G_FLOAT(OFS_RETURN) = -4; return; } - S_LocalSound(s, true); PRVM_G_FLOAT(OFS_RETURN) = 1; } @@ -711,7 +703,7 @@ void VM_str_cvar(void) strcpy(out, cvar_string); - PRVM_G_INT(OFS_PARM0) = PRVM_SetString(out); + PRVM_G_INT(OFS_RETURN) = PRVM_SetString(out); } /* @@ -840,6 +832,38 @@ void VM_stof(void) PRVM_G_FLOAT(OFS_RETURN) = atof(string); } +/* +======================== +VM_itof + +float itof(intt ent) +======================== +*/ +void VM_itof(void) +{ + VM_SAFEPARMCOUNT(1, VM_itof); + PRVM_G_FLOAT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0); +} + +/* +======================== +VM_itoe + +intt ftoi(float num) +======================== +*/ +void VM_ftoi(void) +{ + int ent; + VM_SAFEPARMCOUNT(1, VM_ftoi); + + ent = PRVM_G_FLOAT(OFS_PARM0); + if(PRVM_PROG_TO_EDICT(ent)->p.e->free) + PRVM_ERROR ("VM_ftoe: %s tried to access a freed entity (entity %i)!\n", PRVM_NAME, ent); + + PRVM_G_INT(OFS_RETURN) = ent; +} + /* ========= VM_spawn @@ -911,7 +935,7 @@ void VM_find (void) { prog->xfunction->builtinsprofile++; ed = PRVM_EDICT_NUM(e); - if (ed->e->free) + if (ed->p.e->free) continue; t = PRVM_E_STRING(ed,f); if (!t) @@ -952,7 +976,7 @@ void VM_findfloat (void) { prog->xfunction->builtinsprofile++; ed = PRVM_EDICT_NUM(e); - if (ed->e->free) + if (ed->p.e->free) continue; if (PRVM_E_FLOAT(ed,f) == s) { @@ -1004,7 +1028,7 @@ void VM_findchain (void) for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent)) { prog->xfunction->builtinsprofile++; - if (ent->e->free) + if (ent->p.e->free) continue; t = PRVM_E_STRING(ent,f); if (!t) @@ -1012,7 +1036,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; } @@ -1053,12 +1077,12 @@ void VM_findchainfloat (void) for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent)) { prog->xfunction->builtinsprofile++; - if (ent->e->free) + 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; } @@ -1108,14 +1132,8 @@ 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_GetCached(s, true)) - { - Con_Printf("VM_precache_sound: %s already cached (%s)\n", s, PRVM_NAME); - return; - } - - if(!S_PrecacheSound(s,true, true)) + + if(!S_PrecacheSound (s,true, true)) Con_Printf("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME); } @@ -1279,7 +1297,7 @@ void VM_nextent (void) return; } ent = PRVM_EDICT_NUM(i); - if (!ent->e->free) + if (!ent->p.e->free) { VM_RETURN_EDICT(ent); return; @@ -1361,12 +1379,12 @@ void VM_WriteLong (void) void VM_WriteAngle (void) { - MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0)); + MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol); } void VM_WriteCoord (void) { - MSG_WriteDPCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0)); + MSG_WriteCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol); } void VM_WriteString (void) @@ -1496,8 +1514,7 @@ float registercvar (string name, string value, float flags) void VM_registercvar (void) { char *name, *value; - cvar_t *variable; - int flags; + int flags; VM_SAFEPARMCOUNT(3,VM_registercvar); @@ -1520,19 +1537,8 @@ void VM_registercvar (void) return; } - if (vm_currentqc_cvar >= MAX_QC_CVARS) - PRVM_ERROR ("VM_registercvar: ran out of cvar slots (%i)\n", MAX_QC_CVARS); - -// copy the name and value - variable = &vm_qc_cvar[vm_currentqc_cvar++]; - variable->flags = flags; - variable->name = Z_Malloc (strlen(name)+1); - strcpy (variable->name, name); - variable->string = Z_Malloc (strlen(value)+1); - strcpy (variable->string, value); - variable->value = atof (value); + Cvar_Get(name, value, flags); - Cvar_RegisterVariable(variable); PRVM_G_FLOAT(OFS_RETURN) = 1; // success } @@ -1584,7 +1590,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); @@ -1826,7 +1832,7 @@ void VM_fgets(void) c = FS_Getc(VM_FILES[filenum]); if (developer.integer) Con_Printf("fgets: %s: %s\n", PRVM_NAME, string); - if (c >= 0) + if (c >= 0 || end) PRVM_G_INT(OFS_RETURN) = PRVM_SetString(string); else PRVM_G_INT(OFS_RETURN) = 0; @@ -1901,8 +1907,8 @@ void VM_strcat(void) { char *s; - if(prog->argc < 2) - PRVM_ERROR("VM_strcat wrong parameter count (min. 2 expected ) !\n"); + if(prog->argc < 1) + PRVM_ERROR("VM_strcat wrong parameter count (min. 1 expected ) !\n"); s = VM_GetTempString(); VM_VarString(0, s, VM_STRINGTEMP_LENGTH); @@ -1986,9 +1992,14 @@ strunzone(string s) //void(string s) strunzone = #119; // removes a copy of a string from the string zone (you can not use that string again or it may crash!!!) void VM_strunzone(void) { + char *str; VM_SAFEPARMCOUNT(1,VM_strunzone); - Mem_Free(PRVM_G_STRING(OFS_PARM0)); + str = PRVM_G_STRING(OFS_PARM0); + if( developer.integer && !Mem_IsAllocated( VM_STRINGS_MEMPOOL, str ) ) + PRVM_ERROR( "VM_strunzone: Zone string already freed in %s!", PRVM_NAME ); + else + Mem_Free( str ); } /* @@ -2243,6 +2254,34 @@ void VM_loadfromdata(void) PRVM_ED_LoadFromFile(PRVM_G_STRING(OFS_PARM0)); } +/* +======================== +VM_M_parseentitydata + +parseentitydata(entity ent, string data) +======================== +*/ +void VM_M_parseentitydata(void) +{ + prvm_edict_t *ent; + const char *data; + + VM_SAFEPARMCOUNT(2, VM_parseentitydata); + + // get edict and test it + ent = PRVM_G_EDICT(OFS_PARM0); + if (ent->p.e->free) + PRVM_ERROR ("VM_parseentitydata: %s: Can only set already spawned entities (entity %i is free)!\n", PRVM_NAME, PRVM_NUM_FOR_EDICT(ent)); + + data = PRVM_G_STRING(OFS_PARM1); + + // parse the opening brace + if (!COM_ParseToken(&data, false) || com_token[0] != '{' ) + PRVM_ERROR ("VM_parseentitydata: %s: Couldn't parse entity data:\n%s\n", PRVM_NAME, data ); + + PRVM_ED_ParseEdict (data, ent); +} + /* ========= VM_loadfromfile @@ -2790,6 +2829,14 @@ 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); VM_Search_Reset(); VM_Files_CloseAll(); @@ -2948,6 +2995,7 @@ void VM_M_getkeydest(void) VM_M_callfunction callfunction(...,string function_name) +Extension: pass ========= */ mfunction_t *PRVM_ED_FindFunction (const char *name); @@ -3045,7 +3093,7 @@ void VM_M_writetofile(void) } ent = PRVM_G_EDICT(OFS_PARM1); - if(ent->e->free) + if(ent->p.e->free) { Con_Printf("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1)); return; @@ -3301,8 +3349,9 @@ prvm_builtin_t vm_m_builtins[] = { VM_search_end, VM_search_getsize, VM_search_getfilename, // 77 - VM_chr, //78 - 0,0,// 80 + VM_chr, + VM_itof, + VM_ftoi,// 80 e10, // 90 e10, // 100 e100, // 200 @@ -3351,7 +3400,8 @@ prvm_builtin_t vm_m_builtins[] = { VM_M_keynumtostring, VM_M_findkeysforcommand,// 610 VM_M_gethostcachevalue, - VM_M_gethostcachestring // 612 + VM_M_gethostcachestring, + VM_M_parseentitydata // 613 }; const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);