int main() { RtosTimer MyTimer(OnTimeout, osTimerPeriodic, NULL); MyTimer.start(3000); while(1) { myled = 1; osDelay(500); myled = 0; osDelay(500); } }
void GamePlay::Loop(sf::RenderWindow* target,TextureManager* textureManager) { sf::Event MyEvent; MyTimer fps = MyTimer(1000/resource::consts::FPS); int frame = 0; fps.StartTimer(); int key_down = 0; while(_running) { if(frame % resource::consts::FPS == 0) { while(target->GetEvent(MyEvent)) { _player->UpdateKey(MyEvent,_offSet,_map); switch(MyEvent.Type) { case sf::Event::KeyPressed: key_down = 1; switch(MyEvent.Key.Code) { case sf::Key::Escape: _running = false; break; } break; case sf::Event::KeyReleased: key_down = false; break; } } if(!key_down) { _player->UpdateVelocity(_map); } target->Clear(); _player->UpdatePosition(); _player->CollosionLogic(_map); Render(target,textureManager); } target->Display(); frame++; if( fps.GetTicks() < 1000 / resource::consts::FPS ) { //Sleep the remaining frame time // SDL_Delay( ( 1000 / resource::consts::FPS ) - fps.GetTicks() ); } } }
ut_Timer* ut_Timer_new(void* userdata, ut_TimerCallback* cb, GError** error) { ut_Timer* self = g_try_new0(ut_Timer, 1); if (G_UNLIKELY(!self)) { if (error) *error = gx_error_no_memory; return NULL; } self->timer = new_nothrow MyTimer(userdata, cb); if (G_UNLIKELY(!(self->timer))) { g_free(self); if (error) *error = gx_error_no_memory; return NULL; } return self; }