Add high-resolution timers C API for profiling. The functions are called

uint64_t gethiticks() and gethitickspersec().  For SDL 1.2, the timer
has the same resolution as getticks (1000 Hz). For Windows and SDL 1.3,
the resolution of the underlying perf-timers is used.  The only user of
these functions right now is some TROR on-screen debugging code.

Revert an earlier change regarding r_preview_mouseaim.  We can't do the
check because editstatus is set later.

git-svn-id: https://svn.eduke32.com/eduke32@2026 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-09-15 17:05:00 +00:00
parent cc7110c18f
commit 7582b86237
5 changed files with 61 additions and 11 deletions

View file

@ -141,6 +141,8 @@ void uninittimer(void);
void sampletimer(void); void sampletimer(void);
uint32_t getticks(void); uint32_t getticks(void);
int32_t gettimerfreq(void); int32_t gettimerfreq(void);
uint64_t gethiticks(void);
uint64_t gethitickspersec(void);
void (*installusertimercallback(void (*callback)(void)))(void); void (*installusertimercallback(void (*callback)(void)))(void);
int32_t checkvideomode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced); int32_t checkvideomode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced);

View file

@ -194,6 +194,9 @@ uint8_t graysectbitmap[MAXSECTORS>>3];
uint8_t graywallbitmap[MAXWALLS>>3]; uint8_t graywallbitmap[MAXWALLS>>3];
int32_t autogray = 0, showinnergray = 1; int32_t autogray = 0, showinnergray = 1;
#ifdef YAX_DEBUG
double hitickspersec;
#endif
#ifdef ENGINE_SCREENSHOT_DEBUG #ifdef ENGINE_SCREENSHOT_DEBUG
int32_t engine_screenshot = 0; int32_t engine_screenshot = 0;
#endif #endif
@ -766,7 +769,7 @@ void yax_drawrooms(void (*ExtAnalyzeSprites)(void), int32_t horiz, int16_t sectn
// original (1st-draw) and accumulated ('per-level') gotsector bitmaps // original (1st-draw) and accumulated ('per-level') gotsector bitmaps
static uint8_t ogotsector[MAXSECTORS>>3], lgotsector[MAXSECTORS>>3]; static uint8_t ogotsector[MAXSECTORS>>3], lgotsector[MAXSECTORS>>3];
#ifdef YAX_DEBUG #ifdef YAX_DEBUG
int32_t t; uint64_t t;
#endif #endif
if (getrendermode()==4 || numyaxbunches==0) if (getrendermode()==4 || numyaxbunches==0)
@ -846,7 +849,7 @@ void yax_drawrooms(void (*ExtAnalyzeSprites)(void), int32_t horiz, int16_t sectn
j = bunches[cf][bnchcnt]; // the actual bunchnum... j = bunches[cf][bnchcnt]; // the actual bunchnum...
yax_globalbunch = j; yax_globalbunch = j;
#ifdef YAX_DEBUG #ifdef YAX_DEBUG
t=getticks(); t=gethiticks();
#endif #endif
k = bunchsec[j]; k = bunchsec[j];
@ -864,9 +867,10 @@ void yax_drawrooms(void (*ExtAnalyzeSprites)(void), int32_t horiz, int16_t sectn
for (i=0; i<(numsectors+7)>>3; i++) for (i=0; i<(numsectors+7)>>3; i++)
lgotsector[i] |= gotsector[i]; lgotsector[i] |= gotsector[i];
yaxdebug("l%d: faked sec %3d (bunch %2d),%3d dspr, ob=[%2d,%2d], sn=%3d,%3d ms", yaxdebug("l%d: faked sec %3d (bunch %2d),%3d dspr, ob=[%2d,%2d], sn=%3d, %.3f ms",
yax_globallev-YAX_MAXDRAWS, k, j, yax_spritesortcnt[yax_globallev], yax_globallev-YAX_MAXDRAWS, k, j, yax_spritesortcnt[yax_globallev],
ourbunch[0],ourbunch[1],sectnum,getticks()-t); ourbunch[0],ourbunch[1],sectnum,
(double)(1000*(gethiticks()-t))/hitickspersec);
} }
if (ourbunch[cf]==j) if (ourbunch[cf]==j)
@ -934,7 +938,7 @@ void yax_drawrooms(void (*ExtAnalyzeSprites)(void), int32_t horiz, int16_t sectn
k = bunchsec[j]; // best start-drawing sector k = bunchsec[j]; // best start-drawing sector
yax_globalbunch = j; yax_globalbunch = j;
#ifdef YAX_DEBUG #ifdef YAX_DEBUG
t=getticks(); t=gethiticks();
#endif #endif
yax_tweakpicnums(j, cf, 0); yax_tweakpicnums(j, cf, 0);
if (k < 0) if (k < 0)
@ -946,8 +950,9 @@ void yax_drawrooms(void (*ExtAnalyzeSprites)(void), int32_t horiz, int16_t sectn
yax_nomaskpass = nmp; yax_nomaskpass = nmp;
drawrooms(globalposx,globalposy,globalposz,globalang,horiz,k+MAXSECTORS); // +MAXSECTORS: force drawrooms(globalposx,globalposy,globalposz,globalang,horiz,k+MAXSECTORS); // +MAXSECTORS: force
yaxdebug("l%d nm%d: DRAWN sec %3d (bn %2d),%3d tspr,%3d ms", yaxdebug("l%d nm%d: DRAWN sec %3d (bn %2d),%3d tspr, %.3f ms",
yax_globallev-YAX_MAXDRAWS, nmp, k, j, spritesortcnt, getticks()-t); yax_globallev-YAX_MAXDRAWS, nmp, k, j, spritesortcnt,
(double)(1000*(gethiticks()-t))/hitickspersec);
if (nmp==1) if (nmp==1)
{ {
@ -973,7 +978,7 @@ void yax_drawrooms(void (*ExtAnalyzeSprites)(void), int32_t horiz, int16_t sectn
} }
#ifdef YAX_DEBUG #ifdef YAX_DEBUG
t=getticks(); t=gethiticks();
#endif #endif
yax_globalcf = -1; yax_globalcf = -1;
yax_globalbunch = -1; yax_globalbunch = -1;
@ -982,7 +987,8 @@ void yax_drawrooms(void (*ExtAnalyzeSprites)(void), int32_t horiz, int16_t sectn
// draw base level // draw base level
drawrooms(globalposx,globalposy,globalposz,globalang,horiz,osectnum); drawrooms(globalposx,globalposy,globalposz,globalang,horiz,osectnum);
yaxdebug("DRAWN base level sec %d, %2d ms", osectnum, getticks()-t); yaxdebug("DRAWN base level sec %d, %.3f ms", osectnum,
(double)(1000*(gethiticks()-t))/hitickspersec);
yax_copytsprite(-1, scansector_collectsprites); yax_copytsprite(-1, scansector_collectsprites);
scansector_collectsprites = 1; scansector_collectsprites = 1;
@ -7674,6 +7680,12 @@ int32_t initengine(void)
if (i) return i; if (i) return i;
} }
#ifdef YAX_DEBUG
hitickspersec = (double)gethitickspersec();
if (hitickspersec==0.0)
hitickspersec = 1.0;
#endif
if (loadtables()) return 1; if (loadtables()) return 1;
xyaspect = -1; xyaspect = -1;

View file

@ -6398,8 +6398,9 @@ void polymost_initosdfuncs(void)
for (i=0; i<sizeof(cvars_polymost)/sizeof(cvars_polymost[0]); i++) for (i=0; i<sizeof(cvars_polymost)/sizeof(cvars_polymost[0]); i++)
{ {
if (editstatus==0 && !Bstrcmp(cvars_polymost[i].name, "r_preview_mouseaim")) // can't do this: editstatus is set after this function
continue; // if (editstatus==0 && !Bstrcmp(cvars_polymost[i].name, "r_preview_mouseaim"))
// continue;
if (OSD_RegisterCvar(&cvars_polymost[i])) if (OSD_RegisterCvar(&cvars_polymost[i]))
continue; continue;

View file

@ -712,6 +712,28 @@ uint32_t getticks(void)
return (uint32_t)SDL_GetTicks(); return (uint32_t)SDL_GetTicks();
} }
// high-resolution timers for profiling
#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2
uint64_t gethiticks(void)
{
return SDL_GetTicks();
}
uint64_t gethitickspersec(void)
{
return 1000;
}
#else // SDL 1.3
uint64_t gethiticks(void)
{
return SDL_GetPerformanceCounter();
}
uint64_t gethitickspersec(void)
{
return SDL_GetPerformanceFrequency();
}
#endif
// //
// gettimerfreq() -- returns the number of ticks per second the timer is configured to generate // gettimerfreq() -- returns the number of ticks per second the timer is configured to generate

View file

@ -1574,6 +1574,19 @@ uint32_t getticks(void)
return (uint32_t)(i*longlong(1000)/timerfreq); return (uint32_t)(i*longlong(1000)/timerfreq);
} }
// high-resolution timers for profiling
uint64_t gethiticks(void)
{
uint64_t i;
if (timerfreq == 0) return 0;
QueryPerformanceCounter((LARGE_INTEGER *)&i);
return i;
}
uint64_t gethitickspersec(void)
{
return timerfreq;
}
// //
// gettimerfreq() -- returns the number of ticks per second the timer is configured to generate // gettimerfreq() -- returns the number of ticks per second the timer is configured to generate