void new_frame(void) { DWORD CurrentFPSTime; static DWORD LastFPSTime; static DWORD CounterTime; static int Fps_Counter=0; //if (!Config.showFPS) return; Fps_Counter++; Timers.frameDrawn = 1; CurrentFPSTime = ticks_to_microsecs(gettick()); if (CounterTime > CurrentFPSTime) { CounterTime = ticks_to_microsecs(gettick()); Fps_Counter = 0; } else if (CurrentFPSTime - CounterTime >= 500000.0 ) { Timers.fps = (float) (Fps_Counter * 1000000.0 / (CurrentFPSTime - CounterTime)); CounterTime = ticks_to_microsecs(gettick()); Fps_Counter = 0; } LastFPSTime = CurrentFPSTime; Timers.lastFrameTime = CurrentFPSTime; }
void new_vi(void) { DWORD Dif; DWORD CurrentFPSTime; static DWORD LastFPSTime = 0; static DWORD CounterTime = 0; static DWORD CalculatedTime; static int VI_Counter = 0; static int VI_WaitCounter = 0; long time; start_section(IDLE_SECTION); // if ( (!Config.showVIS) && (!Config.limitFps) ) return; VI_Counter++; CurrentFPSTime = ticks_to_microsecs(gettick()); Dif = CurrentFPSTime - LastFPSTime; if (Timers.limitVIs) { if (Timers.limitVIs == 2 && Timers.frameDrawn == 0) VI_WaitCounter++; else { if (Dif < (double) VILimitMicroseconds * (VI_WaitCounter + 1) ) { CalculatedTime = CounterTime + (double)VILimitMicroseconds * (double)VI_Counter; time = (int)(CalculatedTime - CurrentFPSTime); if (time>0&&time<1000000) { usleep(time); } CurrentFPSTime = CurrentFPSTime + time; } Timers.frameDrawn = 0; VI_WaitCounter = 0; } } // DWORD diff_millisecs = ticks_to_millisecs(diff_ticks(CounterTime,CurrentFPSTime)); if (CounterTime > CurrentFPSTime) { CounterTime = ticks_to_microsecs(gettick()); VI_Counter = 0 ; } else if (CurrentFPSTime - CounterTime >= 500000.0 ) { Timers.vis = (float) (VI_Counter * 1000000.0 / (CurrentFPSTime - CounterTime)); // sprintf(txtbuffer,"Timer.VIs: Current = %dus; Last = %dus; diff_ms = %d; FPS_count = %d", CurrentFPSTime, CounterTime, diff_millisecs, VI_Counter); // DEBUG_print(txtbuffer,0); CounterTime = ticks_to_microsecs(gettick()); VI_Counter = 0 ; } LastFPSTime = CurrentFPSTime ; Timers.lastViTime = CurrentFPSTime; end_section(IDLE_SECTION); }
void TimerUpdate(void) { DWORD CurrentTime = ticks_to_microsecs(gettick()); if (CurrentTime - Timers.lastFrameTime > 1000000) Timers.fps = 0.0f; if (CurrentTime - Timers.lastViTime > 1000000) Timers.vis = 0.0f; }
u32 diff_usec(long long start,long long end) { u64 diff; diff = diff_ticks(start,end); return ticks_to_microsecs(diff); }
static void tod_hack_reset (void) { struct timeval tv; uae_u32 rate = currprefs.ntscmode ? 60 : 50; #ifdef GEKKO //gettimeofday is buggy in libogc tod_hack = (uae_u32) ((ticks_to_microsecs(gettick())/(1000000 / rate))); #else gettimeofday (&tv, NULL); tod_hack = (uae_u32)(((uae_u64)tv.tv_sec) * rate + tv.tv_usec / (1000000 / rate)); #endif tod_hack -= ciaatod; tod_hack_delay = 10 * 50; }
virtual uint32 getMillis(bool skipRecord = false) { #if defined(GEKKO) return (ticks_to_microsecs(gettime()) / 1000.0) - _startTime; #elif defined(__CELLOS_LV2__) return (sys_time_get_system_time() / 1000.0) - _startTime; #else struct timeval t; gettimeofday(&t, 0); return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - _startTime; #endif }
static int gettimeofday2(struct timeval *val, void *dummy) { (void)dummy; #if defined(_MSC_VER) && !defined(_XBOX360) DWORD msec = timeGetTime(); #elif defined(_XBOX360) DWORD msec = GetTickCount(); #endif #if defined(__CELLOS_LV2__) uint64_t usec = sys_time_get_system_time(); #elif defined(GEKKO) uint64_t usec = ticks_to_microsecs(gettime()); #else uint64_t usec = msec * 1000; #endif val->tv_sec = usec / 1000000; val->tv_usec = usec % 1000000; return 0; }
double Sys_DoubleTime(void) { #if defined(GEKKO) return ticks_to_microsecs(gettime()) / 1000000.0; #elif defined(__CELLOS_LV2__) return sys_time_get_system_time() / 1000000.0; #elif defined(_WIN32) static double pfreq; static __int64 startcount; __int64 pcount; if (!pfreq) { __int64 freq; if (QueryPerformanceFrequency((LARGE_INTEGER*)&freq) && freq > 0) { //hardware timer available pfreq = (double)freq; QueryPerformanceCounter((LARGE_INTEGER*)&startcount); } } QueryPerformanceCounter((LARGE_INTEGER*)&pcount); /* TODO -check for wrapping - is it necessary? */ return (pcount - startcount) / pfreq; #else struct timeval tp; struct timezone tzp; static int secbase; gettimeofday(&tp, &tzp); if (!secbase) { secbase = tp.tv_sec; return tp.tv_usec / 1000000.0; } return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0; #endif }
void CIA_vsync_handler () { #ifdef TOD_HACK if (currprefs.tod_hack && ciaatodon) { struct timeval tv; uae_u32 t, nt, rate = currprefs.ntscmode ? 60 : 50; if (tod_hack_delay > 0) { tod_hack_delay--; if (tod_hack_delay == 0) { tod_hack_reset (); tod_hack_delay = 0; write_log ("TOD_HACK re-initialized CIATOD=%#6.6lX\n", ciaatod); } } if (tod_hack_delay == 0) { #ifdef GEKKO //gettimeofday is buggy in libogc t = (uae_u32) ((ticks_to_microsecs(gettick())/(1000000 / rate))); #else gettimeofday (&tv, NULL); t = (uae_u32)(((uae_u64)tv.tv_sec) * rate + tv.tv_usec / (1000000 / rate)); #endif nt = t - tod_hack; if ((nt < ciaatod && ciaatod - nt < 10) || nt == ciaatod) return; /* try not to count backwards */ ciaatod = nt; ciaatod &= 0xffffff; ciaa_checkalarm (0); return; } } #endif if (ciaatodon) { ciaatod++; ciaatod &= 0xFFFFFF; ciaa_checkalarm (1); } }
void Button::drawComponent(Graphics& gfx) { // printf("Button drawComponent\n"); gfx.setColor(inactiveColor); //activate relevant texture if(active) { //draw normalImage with/without gray mask and with alpha test on //printf("Button Active\n"); gfx.setColor(activeColor); } if(getFocus()) { //draw focus indicator (extra border for button?) //printf("Button in Focus\n"); gfx.setColor(focusColor); } //draw buttonLabel? gfx.enableBlending(true); // gfx.setTEV(GX_PASSCLR); gfx.setTEV(GX_MODULATE); // gfx.setColor(focusColor); gfx.setDepth(-10.0f); gfx.newModelView(); gfx.loadModelView(); gfx.loadOrthographic(); switch (buttonStyle) { case BUTTON_DEFAULT: // gfx.fillRect(x, y, width, height); normalImage->activateImage(GX_TEXMAP0); gfx.drawImage(0, x, y, width/2, height/2, 0.0, width/16.0, 0.0, height/16.0); gfx.drawImage(0, x+width/2, y, width/2, height/2, width/16.0, 0.0, 0.0, height/16.0); gfx.drawImage(0, x, y+height/2, width/2, height/2, 0.0, width/16.0, height/16.0, 0.0); gfx.drawImage(0, x+width/2, y+height/2, width/2, height/2, width/16.0, 0.0, height/16.0, 0.0); // gfx.drawImage(0, x, y, width, height, 0.0, 1.0, 0.0, 1.0); if (selected) { gfx.setColor(selectedColor); if(selectedImage) selectedImage->activateImage(GX_TEXMAP0); gfx.drawImage(0, x, y, width/2, height/2, 0.0, width/16.0, 0.0, height/16.0); gfx.drawImage(0, x+width/2, y, width/2, height/2, width/16.0, 0.0, 0.0, height/16.0); gfx.drawImage(0, x, y+height/2, width/2, height/2, 0.0, width/16.0, height/16.0, 0.0); gfx.drawImage(0, x+width/2, y+height/2, width/2, height/2, width/16.0, 0.0, height/16.0, 0.0); } break; case BUTTON_STYLEA_NORMAL: if (getFocus()) focusImage->activateImage(GX_TEXMAP0); else normalImage->activateImage(GX_TEXMAP0); gfx.drawImage(0, x, y, width/2, height, 0.0, width/8.0, 0.0, 1.0); gfx.drawImage(0, x+width/2, y, width/2, height, width/8.0, 0.0, 0.0, 1.0); break; case BUTTON_STYLEA_SELECT: if (selected) { if (getFocus()) selectedFocusImage->activateImage(GX_TEXMAP0); else selectedImage->activateImage(GX_TEXMAP0); } else { if (getFocus()) focusImage->activateImage(GX_TEXMAP0); else normalImage->activateImage(GX_TEXMAP0); } gfx.drawImage(0, x, y, width/2, height, 0.0, width/8.0, 0.0, 1.0); gfx.drawImage(0, x+width/2, y, width/2, height, width/8.0, 0.0, 0.0, 1.0); break; } if (buttonText) { int strWidth, strHeight; unsigned long CurrentTime; float scrollWidth, time_sec, scrollOffset; gfx.enableScissor(x + labelScissor, y, width - 2*labelScissor, height); if(active) IplFont::getInstance().drawInit(labelColor); else IplFont::getInstance().drawInit(inactiveColor); switch (labelMode) { case LABEL_CENTER: IplFont::getInstance().drawString((int) (x+width/2), (int) (y+height/2), *buttonText, fontSize, true); break; case LABEL_LEFT: strWidth = IplFont::getInstance().getStringWidth(*buttonText, fontSize); strHeight = IplFont::getInstance().getStringHeight(*buttonText, fontSize); IplFont::getInstance().drawString((int) (x+labelScissor), (int) (y+(height-strHeight)/2), *buttonText, fontSize, false); break; case LABEL_SCROLL: strHeight = IplFont::getInstance().getStringHeight(*buttonText, fontSize); scrollWidth = IplFont::getInstance().getStringWidth(*buttonText, fontSize)-width+2*labelScissor; scrollWidth = scrollWidth < 0.0f ? 0.0 : scrollWidth; CurrentTime = ticks_to_microsecs(gettick()); time_sec = (float)(CurrentTime - StartTime)/1000000.0f; if (time_sec > SCROLL_PERIOD) StartTime = ticks_to_microsecs(gettick()); scrollOffset = fabsf(fmodf(time_sec,SCROLL_PERIOD)-SCROLL_PERIOD/2)/(SCROLL_PERIOD/2); IplFont::getInstance().drawString((int) (x+labelScissor-(int)(scrollOffset*scrollWidth)), (int) (y+(height-strHeight)/2), *buttonText, fontSize, false); break; case LABEL_SCROLLONFOCUS: if(getFocus()) { strHeight = IplFont::getInstance().getStringHeight(*buttonText, fontSize); scrollWidth = IplFont::getInstance().getStringWidth(*buttonText, fontSize)-width+2*labelScissor; scrollWidth = scrollWidth < 0.0f ? 0.0 : scrollWidth; CurrentTime = ticks_to_microsecs(gettick()); time_sec = (float)(CurrentTime - StartTime)/1000000.0f; if (time_sec > SCROLL_PERIOD) StartTime = ticks_to_microsecs(gettick()); scrollOffset = fabsf(fmodf(time_sec,SCROLL_PERIOD)-SCROLL_PERIOD/2)/(SCROLL_PERIOD/2); IplFont::getInstance().drawString((int) (x+labelScissor-(int)(scrollOffset*scrollWidth)), (int) (y+(height-strHeight)/2), *buttonText, fontSize, false); } else { strWidth = IplFont::getInstance().getStringWidth(*buttonText, fontSize); strHeight = IplFont::getInstance().getStringHeight(*buttonText, fontSize); IplFont::getInstance().drawString((int) (x+labelScissor), (int) (y+(height-strHeight)/2), *buttonText, fontSize, false); } break; } gfx.disableScissor(); } }
void Button::setLabelMode(int mode) { labelMode = mode; if(labelMode >= LABEL_SCROLL) StartTime = ticks_to_microsecs(gettick()); }
u64 Timer::GetTimerMicrosecs() { return ticks_to_microsecs(m_Timer - Util::timer_gettime()); }