@@ -38,8 +38,16 @@ void ListAccelerators (CDocument * pDoc, const int iType);
38
38
39
39
static TCHAR BASED_CODE szCtrlBars[] = _T(" CtrlBars" );
40
40
41
- LARGE_INTEGER hp_timeLastTimerFired;
42
- CTime timeLastTimerFired;
41
+ // we need two timers, because processing a tick shouldn't reset timer processing
42
+ // nor vice-versa
43
+
44
+ // for normal timers
45
+ LARGE_INTEGER hp_timeLastTimerFired; // if we have high-resolution timer
46
+ CTime timeLastTimerFired; // otherwise
47
+
48
+ // for OnPluginTick
49
+ LARGE_INTEGER hp_timeLastTickFired; // if we have high-resolution timer
50
+ CTime timeLastTickFired; // otherwise
43
51
44
52
int ActivityToolBarResourceNames [6 ] = {
45
53
IDB_ACTIVITY_TOOLBAR_0,
@@ -407,9 +415,15 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
407
415
408
416
// initialize timer fallback
409
417
if (App.m_iCounterFrequency )
418
+ {
410
419
QueryPerformanceCounter (&hp_timeLastTimerFired);
420
+ QueryPerformanceCounter (&hp_timeLastTickFired);
421
+ }
411
422
else
423
+ {
412
424
timeLastTimerFired = CTime::GetCurrentTime ();
425
+ timeLastTickFired = CTime::GetCurrentTime ();
426
+ }
413
427
414
428
return 0 ;
415
429
} // CMainFrame::OnCreate
@@ -2256,36 +2270,50 @@ void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
2256
2270
2257
2271
void CMainFrame::CheckTimerFallback ()
2258
2272
{
2259
- double fElapsedTime ;
2273
+ double fElapsedTime ; // normal timers
2274
+ double fElapsedTick ; // OnPluginTick timer
2260
2275
2261
2276
if (App.m_iCounterFrequency )
2262
2277
{
2263
2278
LARGE_INTEGER timeNow;
2264
2279
2265
2280
QueryPerformanceCounter (&timeNow);
2266
2281
2267
- LONGLONG iTimeTaken = iTimeTaken = timeNow.QuadPart - hp_timeLastTimerFired.QuadPart ;
2282
+ LONGLONG iTimeTaken;
2283
+
2284
+ // normal timers
2285
+ iTimeTaken = timeNow.QuadPart - hp_timeLastTimerFired.QuadPart ;
2286
+ fElapsedTime = ((double ) iTimeTaken) / ((double ) App.m_iCounterFrequency );
2268
2287
2269
- fElapsedTime = ((double ) iTimeTaken) /
2270
- ((double ) App.m_iCounterFrequency );
2288
+ // OnPluginTick timer
2289
+ iTimeTaken = timeNow.QuadPart - hp_timeLastTickFired.QuadPart ;
2290
+ fElapsedTick = ((double ) iTimeTaken) / ((double ) App.m_iCounterFrequency );
2271
2291
}
2272
- else
2292
+ else // 1-second resolution if no high-resolution timer available
2273
2293
{
2274
- fElapsedTime = (double ) timeLastTimerFired.GetTime () - (double ) CTime::GetCurrentTime ().GetTime ();
2294
+ fElapsedTime = (double ) CTime::GetCurrentTime ().GetTime () - (double ) timeLastTimerFired.GetTime ();
2295
+ fElapsedTick = (double ) CTime::GetCurrentTime ().GetTime () - (double ) timeLastTickFired.GetTime ();
2275
2296
}
2276
2297
2277
2298
// first do tick timers
2278
2299
2279
- if (fElapsedTime > 0.040 ) // more than 40 milliseconds has elapsed
2300
+ if (fElapsedTick > 0.040 ) // more than 40 milliseconds has elapsed
2280
2301
{
2281
2302
for (POSITION pos = App.m_pWorldDocTemplate ->GetFirstDocPosition (); pos;)
2282
2303
{
2283
2304
CMUSHclientDoc * pDoc = (CMUSHclientDoc*) App.m_pWorldDocTemplate ->GetNextDoc (pos);
2284
2305
pDoc->CheckTickTimers ();
2285
- }
2286
- }
2306
+ } // end for
2307
+
2308
+ // so we know when we prccessed this tick
2309
+ if (App.m_iCounterFrequency )
2310
+ QueryPerformanceCounter (&hp_timeLastTickFired);
2311
+ else
2312
+ timeLastTickFired = CTime::GetCurrentTime ();
2313
+
2314
+ } // if time for OnPluginTick
2287
2315
2288
- double fInterval = 0.10 ; // 10th of a second
2316
+ double fInterval = 0.10 ; // 10th of a second (if m_nTimerInterval is zero)
2289
2317
2290
2318
// if non-zero interval is seconds
2291
2319
if (App.m_nTimerInterval )
0 commit comments