#22268 - expos1994 - Wed Jun 16, 2004 3:52 pm
Hello,
I needed a wait() function in my game, so the player can have a moment to take in some info. Well I am using ThePernProject's Wait(seconds) function since it seemed to be somewhat simple.
Well I added in a for.. loop so it would wait(1) second each time through. Well a one-second wait doesn't happen. It just zips through the loop. I am wondering if I'm doing something dumb, but it seems that the Wait() function resets the timer. And everything should be ok. Plus, I added this to the end of my main game loop (just on a whim really). And my game pauses for a second each time through the loop. So why won't it pause in this for() loop? Does anyone have any ideas?
Here's how I define the registers:
Here's the Wait() function:
Here's where I call it and it doesn't work:
Is there something I'm doing wrong? I like to think that I can call Wait() how ever many times I need to in this simulate_days() function, but I could be wrong...
Thanks for any help you can provide.
--Chris
I needed a wait() function in my game, so the player can have a moment to take in some info. Well I am using ThePernProject's Wait(seconds) function since it seemed to be somewhat simple.
Well I added in a for.. loop so it would wait(1) second each time through. Well a one-second wait doesn't happen. It just zips through the loop. I am wondering if I'm doing something dumb, but it seems that the Wait() function resets the timer. And everything should be ok. Plus, I added this to the end of my main game loop (just on a whim really). And my game pauses for a second each time through the loop. So why won't it pause in this for() loop? Does anyone have any ideas?
Here's how I define the registers:
Code: |
#define REG_TM3D (*(volatile u16*)0x400010C) #define REG_TM3CNT (*(volatile u16*)0x400010E) |
Here's the Wait() function:
Code: |
void Wait(int seconds) { //Start the timer REG_TM3CNT = TIME_FREQUENCY_1024 | TIME_ENABLE; //zero the timer REG_TM3D = 0; while(seconds--) { while(REG_TM3D <= 16386){} //wait REG_TM3D = 0; //reset the timmer } } |
Here's where I call it and it doesn't work:
Code: |
void simulate_days(u16 numofdays) { u16 loop; u16 loop2; char day_string[6]; for (loop = 0; loop < numofdays; loop++) { update_date(); if (selecteditem == 6) { PlotTextBG3((char *)month[monthno],5,1); //Prints the date sprintf(day_string,"%d",day); if (day < 10) //moves ", 1848" based on the day { PlotTextBG3(day_string,8,1); PlotTextBG3((", 1948"),9,1); }else { PlotTextBG3(day_string,8,1); PlotTextBG3((", 1948"),11,1); } } update_food(); WaitForVsync(); Wait(1); } } |
Is there something I'm doing wrong? I like to think that I can call Wait() how ever many times I need to in this simulate_days() function, but I could be wrong...
Thanks for any help you can provide.
--Chris