Measuring time May 17, 2010 02:20PM | Registered: 15 years ago Posts: 34 |
void IntroState::update(GameManager* game, UserController* userController) { // Function updates the current screen that has to be diaplyed by either // keeping track of time and changing the screen when enough time has // passed, or by listening to user input. clock_t currentTime = (clock_t)((double)(clock() / CLOCKS_PER_SEC) * 1000); // Variable currentScreenBeginTime_ is 0 only if this is the first time // IntroState singleton class has been updated. if (currentScreenBeginTime_ == 0) currentScreenBeginTime_ = currentTime; userController->scanButtons(); bool shouldChangeScreen = userController->isButtonPressed(UserController::SELECT) || (currentTime >= currentScreenBeginTime_ + durationScreen_); bool shouldEndApplication = userController->isButtonPressed(UserController::EXIT); if (shouldChangeScreen) { currentScreenBeginTime_ = currentTime; if (++currentScreen_ == screens_.size()) game->changeState(EndState::Instance()); } else if (shouldEndApplication) { game->changeState(EndState::Instance()); } }
unsigned int currentScreen_ = 0; clock_t currentScreenBeginTime_ = 0; clock_t durationScreen_ = 2000;
Re: Measuring time May 17, 2010 02:29PM | Registered: 15 years ago Posts: 379 |
Re: Measuring time May 17, 2010 03:23PM | Registered: 15 years ago Posts: 34 |
Re: Measuring time May 17, 2010 04:10PM | Registered: 15 years ago Posts: 379 |
Re: Measuring time May 17, 2010 04:35PM | Registered: 15 years ago Posts: 34 |
Re: Measuring time May 17, 2010 04:55PM | Registered: 15 years ago Posts: 379 |
Re: Measuring time May 17, 2010 05:25PM | Registered: 15 years ago Posts: 34 |
bool shouldChangeScreen = userController->isButtonPressed(UserController::SELECT) || (currentTime >= currentScreenBeginTime_ + durationScreen_);... is to keep code lines under 80 columns.
void IntroState::update(GameManager* game, UserController* userController) { // Function updates the current screen that has to be diaplyed by either // keeping track of time and changing the screen when enough time has // passed, or by listening to user input. long currentTime = (long)(gettime() / TB_TIMER_CLOCK); // Variable currentScreenBeginTime_ is 0 only if this is the first time // IntroState singleton class has been updated after calling onOpen(). if (currentScreenBeginTime_ == 0) currentScreenBeginTime_ = currentTime; userController->scanButtons(); bool shouldChangeScreen = userController->isButtonPressed(UserController::SELECT) || (currentTime >= currentScreenBeginTime_ + durationScreen_); if (shouldChangeScreen) { currentScreenBeginTime_ = currentTime; if (++currentScreen_ == screens_.size()) game->changeState(MenuState::Instance()); } }