Commit 2ab71571 by James R.

Merge branch 'high-resolution-timer-2' into next

parents d004515d c0dbc562
......@@ -4847,14 +4847,14 @@ void TryRunTics(tic_t realtics)
{
DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic));
ps_tictime = I_GetTimeMicros();
ps_tictime = I_GetPreciseTime();
G_Ticker((gametic % NEWTICRATERATIO) == 0);
ExtraDataTicker();
gametic++;
consistancy[gametic%BACKUPTICS] = Consistancy();
ps_tictime = I_GetTimeMicros() - ps_tictime;
ps_tictime = I_GetPreciseTime() - ps_tictime;
// Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame.
if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value)
......
......@@ -413,7 +413,7 @@ static void D_Display(void)
if (!automapactive && !dedicated && cv_renderview.value)
{
ps_rendercalltime = I_GetTimeMicros();
ps_rendercalltime = I_GetPreciseTime();
if (players[displayplayer].mo || players[displayplayer].playerstate == PST_DEAD)
{
topleft = screens[0] + viewwindowy*vid.width + viewwindowx;
......@@ -460,7 +460,7 @@ static void D_Display(void)
if (postimgtype2)
V_DoPostProcessor(1, postimgtype2, postimgparam2);
}
ps_rendercalltime = I_GetTimeMicros() - ps_rendercalltime;
ps_rendercalltime = I_GetPreciseTime() - ps_rendercalltime;
}
if (lastdraw)
......@@ -474,7 +474,7 @@ static void D_Display(void)
lastdraw = false;
}
ps_uitime = I_GetTimeMicros();
ps_uitime = I_GetPreciseTime();
if (gamestate == GS_LEVEL)
{
......@@ -487,7 +487,7 @@ static void D_Display(void)
}
else
{
ps_uitime = I_GetTimeMicros();
ps_uitime = I_GetPreciseTime();
}
}
......@@ -529,7 +529,7 @@ static void D_Display(void)
CON_Drawer();
ps_uitime = I_GetTimeMicros() - ps_uitime;
ps_uitime = I_GetPreciseTime() - ps_uitime;
//
// wipe update
......@@ -615,9 +615,9 @@ static void D_Display(void)
M_DrawPerfStats();
}
ps_swaptime = I_GetTimeMicros();
ps_swaptime = I_GetPreciseTime();
I_FinishUpdate(); // page flip or blit buffer
ps_swaptime = I_GetTimeMicros() - ps_swaptime;
ps_swaptime = I_GetPreciseTime() - ps_swaptime;
}
}
......
......@@ -379,4 +379,8 @@ Needed for some lua shenanigans.
#define FIELDFROM( type, field, have, want ) \
(void *)((intptr_t)(field) - offsetof (type, have) + offsetof (type, want))
#ifdef HAVE_SDL
typedef UINT64 precise_t;
#endif
#endif //__DOOMTYPE__
......@@ -248,12 +248,12 @@ void HWR_RenderBatches(void)
}
// sort polygons
ps_hw_batchsorttime = I_GetTimeMicros();
ps_hw_batchsorttime = I_GetPreciseTime();
if (cv_glshaders.value && gl_shadersavailable)
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons);
else
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders);
ps_hw_batchsorttime = I_GetTimeMicros() - ps_hw_batchsorttime;
ps_hw_batchsorttime = I_GetPreciseTime() - ps_hw_batchsorttime;
// sort order
// 1. shader
// 2. texture
......@@ -261,7 +261,7 @@ void HWR_RenderBatches(void)
// 4. colors + light level
// not sure about what order of the last 2 should be, or if it even matters
ps_hw_batchdrawtime = I_GetTimeMicros();
ps_hw_batchdrawtime = I_GetPreciseTime();
currentShader = polygonArray[polygonIndexArray[0]].shader;
currentTexture = polygonArray[polygonIndexArray[0]].texture;
......@@ -446,7 +446,7 @@ void HWR_RenderBatches(void)
polygonArraySize = 0;
unsortedVertexArraySize = 0;
ps_hw_batchdrawtime = I_GetTimeMicros() - ps_hw_batchdrawtime;
ps_hw_batchdrawtime = I_GetPreciseTime() - ps_hw_batchdrawtime;
}
......
......@@ -147,11 +147,11 @@ static angle_t gl_aimingangle;
static void HWR_SetTransformAiming(FTransform *trans, player_t *player, boolean skybox);
// Render stats
int ps_hw_skyboxtime = 0;
int ps_hw_nodesorttime = 0;
int ps_hw_nodedrawtime = 0;
int ps_hw_spritesorttime = 0;
int ps_hw_spritedrawtime = 0;
precise_t ps_hw_skyboxtime = 0;
precise_t ps_hw_nodesorttime = 0;
precise_t ps_hw_nodedrawtime = 0;
precise_t ps_hw_spritesorttime = 0;
precise_t ps_hw_spritedrawtime = 0;
// Render stats for batching
int ps_hw_numpolys = 0;
......@@ -161,8 +161,8 @@ int ps_hw_numshaders = 0;
int ps_hw_numtextures = 0;
int ps_hw_numpolyflags = 0;
int ps_hw_numcolors = 0;
int ps_hw_batchsorttime = 0;
int ps_hw_batchdrawtime = 0;
precise_t ps_hw_batchsorttime = 0;
precise_t ps_hw_batchdrawtime = 0;
boolean gl_init = false;
boolean gl_maploaded = false;
......@@ -4654,7 +4654,7 @@ static void HWR_CreateDrawNodes(void)
// that is already lying around. This should all be in some sort of linked list or lists.
sortindex = Z_Calloc(sizeof(size_t) * (numplanes + numpolyplanes + numwalls), PU_STATIC, NULL);
ps_hw_nodesorttime = I_GetTimeMicros();
ps_hw_nodesorttime = I_GetPreciseTime();
for (i = 0; i < numplanes; i++, p++)
{
......@@ -4709,9 +4709,9 @@ static void HWR_CreateDrawNodes(void)
}
}
ps_hw_nodesorttime = I_GetTimeMicros() - ps_hw_nodesorttime;
ps_hw_nodesorttime = I_GetPreciseTime() - ps_hw_nodesorttime;
ps_hw_nodedrawtime = I_GetTimeMicros();
ps_hw_nodedrawtime = I_GetPreciseTime();
// Okay! Let's draw it all! Woo!
HWD.pfnSetTransform(&atransform);
......@@ -4748,7 +4748,7 @@ static void HWR_CreateDrawNodes(void)
}
}
ps_hw_nodedrawtime = I_GetTimeMicros() - ps_hw_nodedrawtime;
ps_hw_nodedrawtime = I_GetPreciseTime() - ps_hw_nodedrawtime;
numwalls = 0;
numplanes = 0;
......@@ -6017,10 +6017,10 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
if (viewnumber == 0) // Only do it if it's the first screen being rendered
HWD.pfnClearBuffer(true, false, &ClearColor); // Clear the Color Buffer, stops HOMs. Also seems to fix the skybox issue on Intel GPUs.
ps_hw_skyboxtime = I_GetTimeMicros();
ps_hw_skyboxtime = I_GetPreciseTime();
if (skybox && drawsky) // If there's a skybox and we should be drawing the sky, draw the skybox
HWR_RenderSkyboxView(viewnumber, player); // This is drawn before everything else so it is placed behind
ps_hw_skyboxtime = I_GetTimeMicros() - ps_hw_skyboxtime;
ps_hw_skyboxtime = I_GetPreciseTime() - ps_hw_skyboxtime;
{
// do we really need to save player (is it not the same)?
......@@ -6132,7 +6132,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
ps_numbspcalls = 0;
ps_numpolyobjects = 0;
ps_bsptime = I_GetTimeMicros();
ps_bsptime = I_GetPreciseTime();
validcount++;
......@@ -6170,7 +6170,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
}
#endif
ps_bsptime = I_GetTimeMicros() - ps_bsptime;
ps_bsptime = I_GetPreciseTime() - ps_bsptime;
if (cv_glbatching.value)
HWR_RenderBatches();
......@@ -6186,12 +6186,12 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
// Draw MD2 and sprites
ps_numsprites = gl_visspritecount;
ps_hw_spritesorttime = I_GetTimeMicros();
ps_hw_spritesorttime = I_GetPreciseTime();
HWR_SortVisSprites();
ps_hw_spritesorttime = I_GetTimeMicros() - ps_hw_spritesorttime;
ps_hw_spritedrawtime = I_GetTimeMicros();
ps_hw_spritesorttime = I_GetPreciseTime() - ps_hw_spritesorttime;
ps_hw_spritedrawtime = I_GetPreciseTime();
HWR_DrawSprites();
ps_hw_spritedrawtime = I_GetTimeMicros() - ps_hw_spritedrawtime;
ps_hw_spritedrawtime = I_GetPreciseTime() - ps_hw_spritedrawtime;
#ifdef NEWCORONAS
//Hurdler: they must be drawn before translucent planes, what about gl fog?
......
......@@ -116,11 +116,11 @@ extern FTransform atransform;
// Render stats
extern int ps_hw_skyboxtime;
extern int ps_hw_nodesorttime;
extern int ps_hw_nodedrawtime;
extern int ps_hw_spritesorttime;
extern int ps_hw_spritedrawtime;
extern precise_t ps_hw_skyboxtime;
extern precise_t ps_hw_nodesorttime;
extern precise_t ps_hw_nodedrawtime;
extern precise_t ps_hw_spritesorttime;
extern precise_t ps_hw_spritedrawtime;
// Render stats for batching
extern int ps_hw_numpolys;
......@@ -130,8 +130,8 @@ extern int ps_hw_numshaders;
extern int ps_hw_numtextures;
extern int ps_hw_numpolyflags;
extern int ps_hw_numcolors;
extern int ps_hw_batchsorttime;
extern int ps_hw_batchdrawtime;
extern precise_t ps_hw_batchsorttime;
extern precise_t ps_hw_batchdrawtime;
extern boolean gl_init;
extern boolean gl_maploaded;
......
......@@ -46,7 +46,13 @@ UINT32 I_GetFreeMem(UINT32 *total);
*/
tic_t I_GetTime(void);
int I_GetTimeMicros(void);// provides microsecond counter for render stats
/** \brief Returns precise time value for performance measurement.
*/
precise_t I_GetPreciseTime(void);
/** \brief Returns the difference between precise times as microseconds.
*/
int I_PreciseToMicros(precise_t);
/** \brief The I_Sleep function
......
......@@ -25,7 +25,7 @@
#include "m_perfstats.h"
#include "d_netcmd.h" // for cv_perfstats
#include "i_system.h" // I_GetTimeMicros
#include "i_system.h" // I_GetPreciseTime
static UINT8 hooksAvailable[(hook_MAX/8)+1];
......@@ -481,7 +481,7 @@ void LUAh_ThinkFrame(void)
continue;
if (cv_perfstats.value == 3)
time_taken = I_GetTimeMicros();
time_taken = I_GetPreciseTime();
PushHook(gL, hookp);
if (lua_pcall(gL, 0, 0, 1)) {
if (!hookp->error || cv_debug & DBG_LUA)
......@@ -492,7 +492,7 @@ void LUAh_ThinkFrame(void)
if (cv_perfstats.value == 3)
{
lua_Debug ar;
time_taken = I_GetTimeMicros() - time_taken;
time_taken = I_GetPreciseTime() - time_taken;
// we need the function, let's just retrieve it again
PushHook(gL, hookp);
lua_getinfo(gL, ">S", &ar);
......
......@@ -18,7 +18,7 @@
#include "z_zone.h"
#include "v_video.h"
#include "i_video.h"
#include "i_system.h" // I_GetTimeMicros
#include "i_system.h" // I_GetPreciseTime
#include "m_misc.h"
#include "st_stuff.h" // st_palette
......@@ -53,8 +53,8 @@ static RGBA_t *gif_framepalette = NULL;
static FILE *gif_out = NULL;
static INT32 gif_frames = 0;
static UINT32 gif_prevframeus = 0; // "us" is microseconds
static UINT32 gif_delayus = 0;
static precise_t gif_prevframetime = 0;
static UINT32 gif_delayus = 0; // "us" is microseconds
static UINT8 gif_writeover = 0;
......@@ -608,7 +608,7 @@ static void GIF_framewrite(void)
{
// golden's attempt at creating a "dynamic delay"
UINT16 mingifdelay = 10; // minimum gif delay in milliseconds (keep at 10 because gifs can't get more precise).
gif_delayus += (I_GetTimeMicros() - gif_prevframeus); // increase delay by how much time was spent between last measurement
gif_delayus += I_PreciseToMicros(I_GetPreciseTime() - gif_prevframetime); // increase delay by how much time was spent between last measurement
if (gif_delayus/1000 >= mingifdelay) // delay is big enough to be able to effect gif frame delay?
{
......@@ -711,7 +711,7 @@ static void GIF_framewrite(void)
}
fwrite(gifframe_data, 1, (p - gifframe_data), gif_out);
++gif_frames;
gif_prevframeus = I_GetTimeMicros();
gif_prevframetime = I_GetPreciseTime();
}
......@@ -739,7 +739,7 @@ INT32 GIF_open(const char *filename)
GIF_headwrite();
gif_frames = 0;
gif_prevframeus = I_GetTimeMicros();
gif_prevframetime = I_GetPreciseTime();
gif_delayus = 0;
return 1;
}
......
......@@ -16,17 +16,17 @@
#include "lua_script.h"
#include "p_local.h"
extern int ps_tictime;
extern precise_t ps_tictime;
extern int ps_playerthink_time;
extern int ps_thinkertime;
extern precise_t ps_playerthink_time;
extern precise_t ps_thinkertime;
extern int ps_thlist_times[];
extern precise_t ps_thlist_times[];
extern int ps_checkposition_calls;
extern int ps_checkposition_calls;
extern int ps_lua_thinkframe_time;
extern int ps_lua_mobjhooks;
extern precise_t ps_lua_thinkframe_time;
extern int ps_lua_mobjhooks;
typedef struct
{
......
......@@ -22,7 +22,7 @@
#include "lua_script.h"
#include "lua_hook.h"
#include "m_perfstats.h"
#include "i_system.h" // I_GetTimeMicros
#include "i_system.h" // I_GetPreciseTime
// Object place
#include "m_cheat.h"
......@@ -323,7 +323,7 @@ static inline void P_RunThinkers(void)
size_t i;
for (i = 0; i < NUM_THINKERLISTS; i++)
{
ps_thlist_times[i] = I_GetTimeMicros();
ps_thlist_times[i] = I_GetPreciseTime();
for (currentthinker = thlist[i].next; currentthinker != &thlist[i]; currentthinker = currentthinker->next)
{
#ifdef PARANOIA
......@@ -331,7 +331,7 @@ static inline void P_RunThinkers(void)
#endif
currentthinker->function.acp1(currentthinker);
}
ps_thlist_times[i] = I_GetTimeMicros() - ps_thlist_times[i];
ps_thlist_times[i] = I_GetPreciseTime() - ps_thlist_times[i];
}
}
......@@ -658,11 +658,11 @@ void P_Ticker(boolean run)
LUAh_PreThinkFrame();
ps_playerthink_time = I_GetTimeMicros();
ps_playerthink_time = I_GetPreciseTime();
for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
P_PlayerThink(&players[i]);
ps_playerthink_time = I_GetTimeMicros() - ps_playerthink_time;
ps_playerthink_time = I_GetPreciseTime() - ps_playerthink_time;
}
// Keep track of how long they've been playing!
......@@ -677,18 +677,18 @@ void P_Ticker(boolean run)
if (run)
{
ps_thinkertime = I_GetTimeMicros();
ps_thinkertime = I_GetPreciseTime();
P_RunThinkers();
ps_thinkertime = I_GetTimeMicros() - ps_thinkertime;
ps_thinkertime = I_GetPreciseTime() - ps_thinkertime;
// Run any "after all the other thinkers" stuff
for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
P_PlayerAfterThink(&players[i]);
ps_lua_thinkframe_time = I_GetTimeMicros();
ps_lua_thinkframe_time = I_GetPreciseTime();
LUAh_ThinkFrame();
ps_lua_thinkframe_time = I_GetTimeMicros() - ps_lua_thinkframe_time;
ps_lua_thinkframe_time = I_GetPreciseTime() - ps_lua_thinkframe_time;
}
// Run shield positioning
......
......@@ -34,7 +34,7 @@
#include "m_random.h" // quake camera shake
#include "r_portal.h"
#include "r_main.h"
#include "i_system.h" // I_GetTimeMicros
#include "i_system.h" // I_GetPreciseTime
#ifdef HWRENDER
#include "hardware/hw_main.h"
......@@ -100,17 +100,17 @@ lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
extracolormap_t *extra_colormaps = NULL;
// Render stats
int ps_prevframetime = 0;
int ps_rendercalltime = 0;
int ps_uitime = 0;
int ps_swaptime = 0;
precise_t ps_prevframetime = 0;
precise_t ps_rendercalltime = 0;
precise_t ps_uitime = 0;
precise_t ps_swaptime = 0;
int ps_bsptime = 0;
precise_t ps_bsptime = 0;
int ps_sw_spritecliptime = 0;
int ps_sw_portaltime = 0;
int ps_sw_planetime = 0;
int ps_sw_maskedtime = 0;
precise_t ps_sw_spritecliptime = 0;
precise_t ps_sw_portaltime = 0;
precise_t ps_sw_planetime = 0;
precise_t ps_sw_maskedtime = 0;
int ps_numbspcalls = 0;
int ps_numsprites = 0;
......@@ -1498,9 +1498,9 @@ void R_RenderPlayerView(player_t *player)
ProfZeroTimer();
#endif
ps_numbspcalls = ps_numpolyobjects = ps_numdrawnodes = 0;
ps_bsptime = I_GetTimeMicros();
ps_bsptime = I_GetPreciseTime();
R_RenderBSPNode((INT32)numnodes - 1);
ps_bsptime = I_GetTimeMicros() - ps_bsptime;
ps_bsptime = I_GetPreciseTime() - ps_bsptime;
ps_numsprites = visspritecount;
#ifdef TIMING
RDMSR(0x10, &mycount);
......@@ -1511,9 +1511,9 @@ void R_RenderPlayerView(player_t *player)
//profile stuff ---------------------------------------------------------
Mask_Post(&masks[nummasks - 1]);
ps_sw_spritecliptime = I_GetTimeMicros();
ps_sw_spritecliptime = I_GetPreciseTime();
R_ClipSprites(drawsegs, NULL);
ps_sw_spritecliptime = I_GetTimeMicros() - ps_sw_spritecliptime;
ps_sw_spritecliptime = I_GetPreciseTime() - ps_sw_spritecliptime;
// Add skybox portals caused by sky visplanes.
......@@ -1521,7 +1521,7 @@ void R_RenderPlayerView(player_t *player)
Portal_AddSkyboxPortals();
// Portal rendering. Hijacks the BSP traversal.
ps_sw_portaltime = I_GetTimeMicros();
ps_sw_portaltime = I_GetPreciseTime();
if (portal_base)
{
portal_t *portal;
......@@ -1561,17 +1561,17 @@ void R_RenderPlayerView(player_t *player)
Portal_Remove(portal);
}
}
ps_sw_portaltime = I_GetTimeMicros() - ps_sw_portaltime;
ps_sw_portaltime = I_GetPreciseTime() - ps_sw_portaltime;
ps_sw_planetime = I_GetTimeMicros();
ps_sw_planetime = I_GetPreciseTime();
R_DrawPlanes();
ps_sw_planetime = I_GetTimeMicros() - ps_sw_planetime;
ps_sw_planetime = I_GetPreciseTime() - ps_sw_planetime;
// draw mid texture and sprite
// And now 3D floors/sides!
ps_sw_maskedtime = I_GetTimeMicros();
ps_sw_maskedtime = I_GetPreciseTime();
R_DrawMasked(masks, nummasks);
ps_sw_maskedtime = I_GetTimeMicros() - ps_sw_maskedtime;
ps_sw_maskedtime = I_GetPreciseTime() - ps_sw_maskedtime;
free(masks);
}
......
......@@ -78,17 +78,17 @@ boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixe
// Render stats
extern int ps_prevframetime;// time when previous frame was rendered
extern int ps_rendercalltime;
extern int ps_uitime;
extern int ps_swaptime;
extern precise_t ps_prevframetime;// time when previous frame was rendered
extern precise_t ps_rendercalltime;
extern precise_t ps_uitime;
extern precise_t ps_swaptime;
extern int ps_bsptime;
extern precise_t ps_bsptime;
extern int ps_sw_spritecliptime;
extern int ps_sw_portaltime;
extern int ps_sw_planetime;
extern int ps_sw_maskedtime;
extern precise_t ps_sw_spritecliptime;
extern precise_t ps_sw_portaltime;
extern precise_t ps_sw_planetime;
extern precise_t ps_sw_maskedtime;
extern int ps_numbspcalls;
extern int ps_numsprites;
......
......@@ -54,12 +54,6 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
#include <fcntl.h>
#endif
#if defined (_WIN32)
DWORD TimeFunction(int requested_frequency);
#else
int TimeFunction(int requested_frequency);
#endif
#include <stdio.h>
#ifdef _WIN32
#include <conio.h>
......@@ -2044,112 +2038,36 @@ ticcmd_t *I_BaseTiccmd2(void)
return &emptycmd2;
}
#if defined (_WIN32)
static HMODULE winmm = NULL;
static DWORD starttickcount = 0; // hack for win2k time bug
static p_timeGetTime pfntimeGetTime = NULL;
// ---------
// I_GetTime
// Use the High Resolution Timer if available,
// else use the multimedia timer which has 1 millisecond precision on Windowz 95,
// but lower precision on Windows NT
// ---------
DWORD TimeFunction(int requested_frequency)
{
DWORD newtics = 0;
// this var acts as a multiplier if sub-millisecond precision is asked but is not available
int excess_frequency = requested_frequency / 1000;
if (!starttickcount) // high precision timer
{
LARGE_INTEGER currtime; // use only LowPart if high resolution counter is not available
static LARGE_INTEGER basetime = {{0, 0}};
// use this if High Resolution timer is found
static LARGE_INTEGER frequency;
if (!basetime.LowPart)
{
if (!QueryPerformanceFrequency(&frequency))
frequency.QuadPart = 0;
else
QueryPerformanceCounter(&basetime);
}
if (frequency.LowPart && QueryPerformanceCounter(&currtime))
{
newtics = (INT32)((currtime.QuadPart - basetime.QuadPart) * requested_frequency
/ frequency.QuadPart);
}
else if (pfntimeGetTime)
{
currtime.LowPart = pfntimeGetTime();
if (!basetime.LowPart)
basetime.LowPart = currtime.LowPart;
if (requested_frequency > 1000)
newtics = currtime.LowPart - basetime.LowPart * excess_frequency;
else
newtics = (currtime.LowPart - basetime.LowPart)/(1000/requested_frequency);
}
}
else
{
if (requested_frequency > 1000)
newtics = (GetTickCount() - starttickcount) * excess_frequency;
else
newtics = (GetTickCount() - starttickcount)/(1000/requested_frequency);
}
return newtics;
}
static void I_ShutdownTimer(void)
{
pfntimeGetTime = NULL;
if (winmm)
{
p_timeEndPeriod pfntimeEndPeriod = (p_timeEndPeriod)(LPVOID)GetProcAddress(winmm, "timeEndPeriod");
if (pfntimeEndPeriod)
pfntimeEndPeriod(1);
FreeLibrary(winmm);
winmm = NULL;
}
}
#else
//
// I_GetTime
// returns time in 1/TICRATE second tics
//
// millisecond precision only
int TimeFunction(int requested_frequency)
{
static Uint64 basetime = 0;
Uint64 ticks = SDL_GetTicks();
static Uint64 timer_frequency;
if (!basetime)
basetime = ticks;
static double tic_frequency;
static Uint64 tic_epoch;
ticks -= basetime;
tic_t I_GetTime(void)
{
static double elapsed;
ticks = (ticks*requested_frequency);
const Uint64 now = SDL_GetPerformanceCounter();
ticks = (ticks/1000);
elapsed += (now - tic_epoch) / tic_frequency;
tic_epoch = now; // moving epoch
return ticks;
return (tic_t)elapsed;
}
#endif
tic_t I_GetTime(void)
precise_t I_GetPreciseTime(void)
{
return TimeFunction(NEWTICRATE);
return SDL_GetPerformanceCounter();
}
int I_GetTimeMicros(void)
int I_PreciseToMicros(precise_t d)
{
return TimeFunction(1000000);
return (int)(d / (timer_frequency / 1000000.0));
}
//
......@@ -2157,26 +2075,11 @@ int I_GetTimeMicros(void)
//
void I_StartupTimer(void)
{
#ifdef _WIN32
// for win2k time bug
if (M_CheckParm("-gettickcount"))
{
starttickcount = GetTickCount();
CONS_Printf("%s", M_GetText("Using GetTickCount()\n"));
}
winmm = LoadLibraryA("winmm.dll");
if (winmm)
{
p_timeEndPeriod pfntimeBeginPeriod = (p_timeEndPeriod)(LPVOID)GetProcAddress(winmm, "timeBeginPeriod");
if (pfntimeBeginPeriod)
pfntimeBeginPeriod(1);
pfntimeGetTime = (p_timeGetTime)(LPVOID)GetProcAddress(winmm, "timeGetTime");
}
I_AddExitFunc(I_ShutdownTimer);
#endif
}
timer_frequency = SDL_GetPerformanceFrequency();
tic_epoch = SDL_GetPerformanceCounter();
tic_frequency = timer_frequency / (double)NEWTICRATE;
}
void I_Sleep(void)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment