]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
DP_QC_GETTIME
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 21 Mar 2009 22:09:45 +0000 (22:09 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 21 Mar 2009 22:09:45 +0000 (22:09 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8818 d7cf8633-e32d-0410-b094-e92efae38249

clvm_cmds.c
host.c
prvm_cmds.c
svvm_cmds.c

index eeaa92e4ae81b8a7fe378f6077a3b06ac0d9798e..e1969f6e4089da54e8bcbc2cefd8454bf17c9b41 100644 (file)
@@ -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 b8209a6718a0f934a0a20dab43bac05806efc574..95db9771a0cede904439d9270f685fdf46abe3fa 100644 (file)
--- 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))
index 38a97a852caf2b66a49421784d1f6fc9ff90f893..f47f5f6852ee68958b3653f073843a17e88871d2 100644 (file)
@@ -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;
+               }
+       }
 }
 
 /*
index 201413c1dc9cf6ca178c7fa509f336039598d8d5..ab3a1ea27580b07265fa58916e9a03062cc3f363 100644 (file)
@@ -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