X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=prvm_cmds.c;h=fc0396a0eda7cb706940c6cd107b21fb53fffcfb;hb=3ff18334a572ae2c544598e05194675207c613df;hp=a9ce8ac9f6dcf27d9af7c0b87ec8a86f8b5840d9;hpb=449b12475e1848290002970f45fd4bdcd0a4d462;p=xonotic%2Fdarkplaces.git diff --git a/prvm_cmds.c b/prvm_cmds.c index a9ce8ac9..fc0396a0 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -86,6 +86,9 @@ float gettime() loadfromdata(string data) loadfromfile(string file) float mod(float val, float m) +const string str_cvar (string) + crash() + stackdump() perhaps only : Menu : WriteMsg =============================== @@ -125,6 +128,8 @@ float getmousetarget(void) callfunction(...,string function_name) writetofile(float fhandle, entity ent) +float isfunction(string function_name) +vector getresolution(float number) */ #include "quakedef.h" @@ -660,6 +665,35 @@ void VM_cvar (void) PRVM_G_FLOAT(OFS_RETURN) = Cvar_VariableValue(PRVM_G_STRING(OFS_PARM0)); } +/* +================= +VM_str_cvar + +const string str_cvar (string) +================= +*/ +void VM_str_cvar(void) +{ + char *out, *name; + const char *cvar_string; + VM_SAFEPARMCOUNT(1,VM_str_cvar); + + name = PRVM_G_STRING(OFS_PARM0); + + if(!name) + PRVM_ERROR("VM_str_cvar: %s: null string\n", PRVM_NAME); + + VM_CheckEmptyString(name); + + out = VM_GetTempString(); + + cvar_string = Cvar_VariableString(name); + + strcpy(out, cvar_string); + + PRVM_G_INT(OFS_PARM0) = PRVM_SetString(out); +} + /* ================= VM_cvar_set @@ -1081,6 +1115,36 @@ void VM_coredump (void) Cbuf_AddText("\n"); } +/* +========= +VM_stackdump + +stackdump() +========= +*/ +void PRVM_StackTrace(void); +void VM_stackdump (void) +{ + VM_SAFEPARMCOUNT(0, VM_stackdump); + + PRVM_StackTrace(); +} + +/* +========= +VM_crash + +crash() +========= +*/ + +void VM_crash(void) +{ + VM_SAFEPARMCOUNT(0, VM_crash); + + PRVM_ERROR("Crash called by %s\n",PRVM_NAME); +} + /* ========= VM_traceon @@ -2077,6 +2141,32 @@ void VM_clientstate(void) PRVM_G_FLOAT(OFS_RETURN) = cls.state; } +/* +========= +VM_getostype + +float getostype(void) +========= +*/ // not used at the moment -> not included in the common list +void VM_getostype(void) +{ + VM_SAFEPARMCOUNT(0,VM_getostype); + + /* + OS_WINDOWS + OS_LINUX + OS_MAC - not supported + */ + +#ifdef _WIN32 + PRVM_G_FLOAT(OFS_RETURN) = 0; +#elif defined _MAC + PRVM_G_FLOAT(OFS_RETURN) = 2; +#else + PRVM_G_FLOAT(OFS_RETURN) = 1; +#endif +} + /* ========= VM_getmousepos @@ -2660,25 +2750,73 @@ VM_M_callfunction ========= */ mfunction_t *PRVM_ED_FindFunction (const char *name); -int PRVM_EnterFunction (mfunction_t *f); void VM_M_callfunction(void) { mfunction_t *func; char *s; + if(prog->argc == 0) + PRVM_ERROR("VM_M_callfunction: 1 parameter is required !\n"); + s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1)); if(!s) - PRVM_ERROR("VM_M_getfunction: null string !\n"); + PRVM_ERROR("VM_M_callfunction: null string !\n"); VM_CheckEmptyString(s); func = PRVM_ED_FindFunction(s); - if(func) - PRVM_EnterFunction(func); + if(!func) + PRVM_ERROR("VM_M_callfunciton: function %s not found !\n", s); + else if (func->first_statement < 0) + { + // negative statements are built in functions + int builtinnumber = -func->first_statement; + prog->xfunction->builtinsprofile++; + if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber]) + prog->builtins[builtinnumber](); + else + PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME); + } + else if(func > 0) + { + prog->argc--; + PRVM_ExecuteProgram(func - prog->functions,""); + prog->argc++; + } } +/* +========= +VM_M_isfunction + +float isfunction(string function_name) +========= +*/ +mfunction_t *PRVM_ED_FindFunction (const char *name); +void VM_M_isfunction(void) +{ + mfunction_t *func; + char *s; + + VM_SAFEPARMCOUNT(1, VM_M_isfunction); + + s = PRVM_G_STRING(OFS_PARM0); + + if(!s) + PRVM_ERROR("VM_M_isfunction: null string !\n"); + + VM_CheckEmptyString(s); + + func = PRVM_ED_FindFunction(s); + + if(!func) + PRVM_G_FLOAT(OFS_RETURN) = false; + else + PRVM_G_FLOAT(OFS_RETURN) = true; +} + /* ========= VM_M_writetofile @@ -2715,6 +2853,27 @@ void VM_M_writetofile(void) PRVM_ED_Write (VM_FILES[filenum], ent); } +/* +========= +VM_M_getresolution + +vector getresolution(float number) +========= +*/ +extern unsigned short video_resolutions[][2]; +void VM_M_getresolution(void) +{ + int nr; + VM_SAFEPARMCOUNT(1, VM_getresolution); + + nr = PRVM_G_FLOAT(OFS_PARM0); + + + PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0]; + PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1]; + PRVM_G_VECTOR(OFS_RETURN)[2] = 0; +} + prvm_builtin_t vm_m_builtins[] = { 0, // to be consistent with the old vm // common builtings (mostly) @@ -2788,7 +2947,10 @@ prvm_builtin_t vm_m_builtins[] = { VM_loadfromdata, VM_loadfromfile, VM_modulo, // 70 - e10, // 80 + VM_str_cvar, + VM_crash, + VM_stackdump, // 73 + 0,0,0,0,0,0,0,// 80 e10, // 90 e10, // 100 e100, // 200 @@ -2831,7 +2993,9 @@ prvm_builtin_t vm_m_builtins[] = { VM_M_setmousetarget, VM_M_getmousetarget, VM_M_callfunction, - VM_M_writetofile // 606 + VM_M_writetofile, + VM_M_isfunction, + VM_M_getresolution // 608 }; const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);