TEST_F( TimeTests, TimeUtils_Convert_Seconds_To_GameTicks ) { STickTime game_time( 5000 ); ASSERT_TRUE( NTimeUtils::Convert_Seconds_To_Game_Ticks( 5.0 ) == game_time ); ASSERT_TRUE( NTimeUtils::Convert_Seconds_To_Ticks( TT_GAME_TIME, 5.0 ) == game_time ); }
static void Boat_update_angles(Boat *boat, const Uint8 *key_state) { Uint32 cur_time = game_time(), last_rot_time = Boat_GET(last_rot_time, boat); float angle = Ent_GET(rotation, boat); vec2 move_direction = {0, 0}; if(!key_state[SDLK_RIGHT] && !key_state[SDLK_LEFT]) { Boat_SET(last_rot_time, boat, 0); return; } if(last_rot_time != 0 && (cur_time - last_rot_time) < BOAT_ROTATION_DELAY) return; if(key_state[SDLK_LEFT]) angle += BOAT_SPRITE_ANGLE_INTERVAL; else angle -= BOAT_SPRITE_ANGLE_INTERVAL; Boat_SET(last_rot_time, boat, cur_time); angle = angle_normalize(angle_round(angle, BOAT_SPRITE_ANGLE_INTERVAL)); Ent_SET(rotation, boat, angle); vec2_from_angle(&move_direction, angle); Ent_SET(move_direction, boat, &move_direction); }
void update_entities(Uint32 last_frame_time) { const list_t *ent_iter = NULL; /* Ent updating follows, in 3 stages: * -First stage: update position, angles and bounds for all entities * -Second stage: call the think functions on any entities necessary * -Third stage: call frame callbacks, which check collisions and draw to surface */ if(!is_paused()) { while((ent_iter = ent_table_next(ent_iter)) != NULL) { Ent *ent = ent_iter->item; if(game_time() >= Ent_GET(next_think, ent)) Ent_CALL(think, ent); } while((ent_iter = ent_table_next(ent_iter)) != NULL) { Ent *ent = ent_iter->item; Ent_update(ent, last_frame_time); } } while((ent_iter = ent_table_next(ent_iter)) != NULL) { Ent *ent = ent_iter->item; Ent_CALL(on_frame, ent); } }
LiveHousePage::LiveHousePage() : mLastActionTime( game_time( NULL ) ), mCheckoutStale( false ), mOutOfTime( false ), mStartTestFailed( false ), mCurrentRequestForStartTest( false ) { // assume ping sent at startup, because no house checked out at startup, // and checking out a house automatically pings it if( sLastPingTime == 0 ) { // we're the first to set it // other LiveHousePage's will find it already set at their construction sLastPingTime = game_time( NULL ); } }
void LiveHousePage::makeActive( char inFresh ) { if( !inFresh ) { return; } // this page becoming active is an action mLastActionTime = game_time( NULL ); mCheckoutStale = false; mOutOfTime = false; mStartTestFailed = false; mCurrentRequestForStartTest = false; }
void Game::update() { unsigned int now = SDL_GetTicks(); GameTime game_time(now - total_time_, now); input_->update(); if(input_->escape()) { stop(); } screen_manager_.update(*input_, game_time); total_time_ = SDL_GetTicks(); }
void finish_frame(Uint32 *frame_start, Uint32 *frame_end, Uint32 *game_frame_end) { Uint32 delay = 1000 / FRAME_RATE_MAX, elapsed; *frame_end = SDL_GetTicks(); elapsed = *frame_end - *frame_start; if(elapsed < delay) delay -= elapsed; *frame_end = SDL_GetTicks(); if(!is_paused()) { game_time_update(elapsed); *game_frame_end = game_time(); } SDL_Delay(delay); }
TEST_F( TimeTests, TimeUtils_Convert_GameTicks_To_Seconds ) { STickTime game_time( 5000 ); ASSERT_TRUE( NTimeUtils::Convert_Game_Ticks_To_Seconds( game_time ) == 5.0 ); ASSERT_TRUE( NTimeUtils::Convert_Ticks_To_Seconds( TT_GAME_TIME, game_time ) == 5.0 ); }
void LiveHousePage::step() { if( sWebRequest != -1 ) { int result = stepWebRequestSerial( sWebRequest ); if( result != 0 ) { // send is over, not matter what response we get back // same response possibilies for all requests types here switch( result ) { case -1: mCheckoutStale = true; if( mCurrentRequestForStartTest ) { mStartTestFailed = true; } printf( "Web request FAILED!\n" ); break; case 1: { char *response = getWebResultSerial( sWebRequest ); printf( "Server response: %s\n", response ); // same OK result expected whether we // have sent a ping or a self-test start/end if( strstr( response, "OK" ) == NULL ) { mCheckoutStale = true; if( mCurrentRequestForStartTest ) { mStartTestFailed = true; } if( strstr( response, "OUT_OF_TIME" ) != NULL ) { mOutOfTime = true; } } delete [] response; } } clearWebRequestSerial( sWebRequest ); sWebRequest = -1; } } else if( sPendingTestRequests.size() > 0 ) { const char *command = *( sPendingTestRequests.getElement( 0 ) ); sPendingTestRequests.deleteElement( 0 ); if( strcmp( command, "start_self_test" ) == 0 ) { mCurrentRequestForStartTest = true; } else { mCurrentRequestForStartTest = false; } char *ticketHash = getTicketHash(); char *fullRequestURL = autoSprintf( "%s?action=%s&user_id=%d" "&%s", serverURL, command, userID, ticketHash ); delete [] ticketHash; sWebRequest = startWebRequestSerial( "GET", fullRequestURL, NULL ); delete [] fullRequestURL; // counts as a ping sLastPingTime = game_time( NULL ); } else if( ! mCheckoutStale ) { int currentTime = game_time( NULL ); if( currentTime > sLastPingTime + 60 * 4 ) { // getting close to five minute timeout mark if( currentTime - mLastActionTime < 60 * 5 ) { // there's been activity in the last five minutes // send ping char *ticketHash = getTicketHash(); char *fullRequestURL = autoSprintf( "%s?action=ping_house&user_id=%d" "&%s", serverURL, userID, ticketHash ); delete [] ticketHash; sWebRequest = startWebRequestSerial( "GET", fullRequestURL, NULL ); mCurrentRequestForStartTest = false; delete [] fullRequestURL; sLastPingTime = currentTime; } } } }
void LiveHousePage::actionHappened() { mLastActionTime = game_time( NULL ); }