wait and time code March 07, 2009 03:23PM | Registered: 15 years ago Posts: 18 |
if (cursorx >= 260 && cursorx <=420 && cursory >= 300 && cursory <=400){ // landingpad bottom VIDEO_ClearFrameBuffer(rmode,xfb,COLOR_BLACK); errorcountlv4 ++; printf("you touched the edge"); usleep(5000000); }I hate the Usleep, It makes it much too hard to Position the cursor after a mess up.
Re: wait and time code March 07, 2009 07:09PM | Registered: 16 years ago Posts: 152 |
Re: wait and time code March 08, 2009 05:16PM | Registered: 15 years ago Posts: 25 |
... f32 current_time = 0.0f; f32 delta_t = 1.0f/60.0f; //or 1/50 depending on the video mode ... while(running) { .... // Wait for the next frame VIDEO_WaitVSync(); current_time += delta_t; }
Re: wait and time code March 08, 2009 07:54PM | Registered: 16 years ago Posts: 265 |
Re: wait and time code March 08, 2009 08:00PM | Registered: 16 years ago Posts: 114 |
/**************************************************************************** * tmbinc msec timer ****************************************************************************/ #ifdef HW_RVL #define TB_CLOCK 60750000 /* WII */ #else #define TB_CLOCK 40500000 #endif struct MillisecondTimer { MillisecondTimer() { Update(); } void Update() { {u32 u; do { asm volatile ("mftbu %0" : "=r" (u)); asm volatile ("mftb %0" : "=r" (tm.l)); asm volatile ("mftbu %0" : "=r" (tm.u)); } while (u != (tm.u)); } } u32 operator -(MillisecondTimer& timer) { tb_t* end = &tm; tb_t* start = &timer.tm; u32 upper; u32 lower; upper = end->u - start->u; if (start->l > end->l) upper--; lower = end->l - start->l; return ((upper * ((unsigned long) 0x80000000 / (TB_CLOCK / 2000))) + (lower / (TB_CLOCK / 1000))); } protected: struct tb_t { u32 l; u32 u; }; tb_t tm; }; ... // Usage before a main loop... MillisecondTimer start; MillisecondTimer current; while (true) { current.Update(); u32 ticks = current - start; // ticks now holds the number of milliseconds since the start of your app/loop. // Draw stuff like normal, etc... }
Hah, is there any Gamecube homebrew that runs really fast on the Wii because of that? :PQuote
henke37
And you really need to have an upper limit on the framerate, as old games exampliefies what happens otherwise, they are unplayable!
Re: wait and time code March 09, 2009 10:40AM | Registered: 16 years ago Posts: 276 |
framerate is the same on all consoles, it's (approximately) 1/60s for NTSC and PAL60 (480i/480p) and 1/50s for PAL50 (576i)Quote
Hah, is there any Gamecube homebrew that runs really fast on the Wii because of that
Re: wait and time code March 09, 2009 03:01PM | Registered: 16 years ago Posts: 265 |
Re: wait and time code March 09, 2009 04:58PM | Registered: 16 years ago Posts: 114 |
Last time I tried gettime() it returned the time in ticks, but the value was only updated once a second >.>Quote
ekeeke
I think the thing above is already implemented in libogc: just use gettime() to get the elapsed ticks since boot (in microsecond) , diff_usec() to calculate the difference between 2 values (this take timer overflow in account) and usleep() to wait a specific amount of microseconds.
I meant if there was any homebrew that didn't wait for a VSync and runs faster as a result.Quote
ekeeke
framerate is the same on all consoles, it's (approximately) 1/60s for NTSC and PAL60 (480i/480p) and 1/50s for PAL50 (576i)
Re: wait and time code March 09, 2009 06:16PM | Registered: 16 years ago Posts: 276 |
Re: wait and time code March 10, 2009 02:37AM | Registered: 15 years ago Posts: 18 |
Re: wait and time code March 14, 2009 03:11AM | Registered: 15 years ago Posts: 32 |
Re: wait and time code March 15, 2009 03:55AM | Registered: 16 years ago Posts: 68 |
#include ogc/lwp_watchdog.h> class Timer{ double Then; Timer::Timer() { Then = ticks_to_millisecs(gettime()) / 1000.0; } double Timer::TimePassed() { double diff = ticks_to_millisecs(gettime())/ 1000.0 - Then; Then = ticks_to_millisecs(gettime())/ 1000.0; return diff; } };
Re: wait and time code March 30, 2009 03:54AM | Registered: 16 years ago Posts: 1,012 |