From: divverent Date: Sat, 21 Mar 2009 22:09:45 +0000 (+0000) Subject: DP_QC_GETTIME X-Git-Tag: xonotic-v0.1.0preview~1789 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bedd1875d4decdd4fbb226052d12d2e6e347d18a;p=xonotic%2Fdarkplaces.git DP_QC_GETTIME git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8818 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/clvm_cmds.c b/clvm_cmds.c index eeaa92e4..e1969f6e 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -3606,7 +3606,7 @@ VM_argv_start_index, // #515 float(float idx) argv_start_index = #515; (DP_Q VM_argv_end_index, // #516 float(float idx) argv_end_index = #516; (DP_QC_TOKENIZE_CONSOLE) VM_buf_cvarlist, // #517 void(float buf, string prefix, string antiprefix) buf_cvarlist = #517; (DP_QC_STRINGBUFFERS_CVARLIST) VM_cvar_description, // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION) -NULL, // #519 +VM_gettime, // #519 float(float timer) gettime = #519; (DP_QC_GETTIME) VM_keynumtostring, // #520 string keynumtostring(float keynum) VM_findkeysforcommand, // #521 string findkeysforcommand(string command) NULL, // #522 diff --git a/host.c b/host.c index b8209a67..95db9771 100644 --- a/host.c +++ b/host.c @@ -54,6 +54,7 @@ double realtime; client_t *host_client; jmp_buf host_abortframe; +double host_starttime = 0; // pretend frames take this amount of time (in seconds), 0 = realtime cvar_t host_framerate = {0, "host_framerate","0", "locks frame timing to this value in seconds, 0.05 is 20fps for example, note that this can easily run too fast, use cl_maxfps if you want to limit your framerate instead, or sys_ticrate to limit server speed"}; @@ -612,7 +613,7 @@ void Host_Main(void) cl_timer = 0; sv_timer = 0; - realtime = Sys_DoubleTime(); + realtime = host_starttime = Sys_DoubleTime(); for (;;) { if (setjmp(host_abortframe)) diff --git a/prvm_cmds.c b/prvm_cmds.c index 38a97a85..f47f5f68 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -2593,11 +2593,40 @@ VM_gettime float gettime(void) ========= */ +extern double host_starttime; void VM_gettime(void) { - VM_SAFEPARMCOUNT(0,VM_gettime); + int timer_index; - PRVM_G_FLOAT(OFS_RETURN) = (float) realtime; + VM_SAFEPARMCOUNTRANGE(0,1,VM_gettime); + + if(prog->argc == 0) + { + PRVM_G_FLOAT(OFS_RETURN) = (float) realtime; + } + else + { + timer_index = (int) PRVM_G_FLOAT(OFS_PARM0); + switch(timer_index) + { + case 0: // GETTIME_FRAMESTART + PRVM_G_FLOAT(OFS_RETURN) = (float) realtime; + break; + case 1: // GETTIME_REALTIME + PRVM_G_FLOAT(OFS_RETURN) = (float) Sys_DoubleTime(); + break; + case 2: // GETTIME_HIRES + PRVM_G_FLOAT(OFS_RETURN) = (float) (Sys_DoubleTime() - realtime); + break; + case 3: // GETTIME_UPTIME + PRVM_G_FLOAT(OFS_RETURN) = (float) Sys_DoubleTime() - host_starttime; + break; + default: + VM_Warning("VM_gettime: %s: unsupported timer specified, returning realtime\n", PRVM_NAME); + PRVM_G_FLOAT(OFS_RETURN) = (float) realtime; + break; + } + } } /* diff --git a/svvm_cmds.c b/svvm_cmds.c index 201413c1..ab3a1ea2 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -81,6 +81,7 @@ char *vm_sv_extensions = "DP_QC_GETSURFACEPOINTATTRIBUTE " "DP_QC_GETTAGINFO " "DP_QC_GETTAGINFO_BONEPROPERTIES " +"DP_QC_GETTIME " "DP_QC_MINMAXBOUND " "DP_QC_MULTIPLETEMPSTRINGS " "DP_QC_NUM_FOR_EDICT " @@ -3597,7 +3598,7 @@ VM_argv_start_index, // #515 float(float idx) argv_start_index = #515; (DP_Q VM_argv_end_index, // #516 float(float idx) argv_end_index = #516; (DP_QC_TOKENIZE_CONSOLE) VM_buf_cvarlist, // #517 void(float buf, string prefix, string antiprefix) buf_cvarlist = #517; (DP_QC_STRINGBUFFERS_CVARLIST) VM_cvar_description, // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION) -NULL, // #519 +VM_gettime, // #519 float(float timer) gettime = #519; (DP_QC_GETTIME) NULL, // #520 NULL, // #521 NULL, // #522