void PlatformDesktop::SingleLoop() { if( mEventRecorder ) mEventRecorder->StartOfFrame( GetTime() ); HandleEvents(); poro_assert( GetApplication() ); poro_assert( mGraphics ); types::Double32 dt = mOneFrameShouldLast; if( mFixedTimeStep == false ) { static types::Double32 last_time_update_called = 0; dt = (types::Double32)( GetUpTime() - last_time_update_called ); last_time_update_called = GetUpTime(); } GetApplication()->Update( (types::Float32)(dt) ); mGraphics->BeginRendering(); GetApplication()->Draw(mGraphics); mGraphics->EndRendering(); if( mEventRecorder ) mEventRecorder->EndOfFrame( GetTime() ); }
void Keyboard::AddKeyboardListener( IKeyboardListener* listener ) { poro_assert( listener ); poro_logger << "Added keyboard listener" << std::endl; mListeners.push_back(listener); }
void Keyboard::FireKeyUpEvent( int button, types::charset unicode ) { for( std::size_t i = 0; i < mListeners.size(); ++i ) { poro_assert( mListeners[ i ] ); mListeners[ i ]->OnKeyUp( button, unicode ); } SetKeyDown( button, false ); }
void Keyboard::RemoveKeyboardListener( IKeyboardListener* listener ) { poro_logger << "Remove keyboard listener" << std::endl; std::vector< IKeyboardListener* >::iterator i = std::find( mListeners.begin(), mListeners.end(), listener ); poro_assert( i != mListeners.end() ); if( i != mListeners.end() ) mListeners.erase( i ); }
IPlatform * IPlatform::Instance() { poro_assert(gInstance!=NULL); return gInstance; }
Joystick* PlatformDesktop::GetJoystick( int n ) { poro_assert( n >= 0 && n < (int)mJoysticks.size() ); poro_assert( mJoysticks[ n ] ); return mJoysticks[ n ]; }
void PlatformDesktop::HandleEvents() { // Reset mouse state mMouse->OnFrameStart(); mKeyboard->OnFrameStart(); // -- event recorder might fire or simulate events of the SDL_EventPoll poro_assert( mEventRecorder ); if( mEventRecorder ) mEventRecorder->DoPlaybacksForFrame(); //---------- for( std::size_t i = 0; i < mJoysticks.size(); ++i ) { HandleJoystickImpl( mJoysticks[ i ] ); } //--------- // Handle events SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: { mEventRecorder->FireKeyDownEvent( static_cast< int >( event.key.keysym.sym ), static_cast< types::charset >( event.key.keysym.unicode ) ); } break; case SDL_KEYUP: { mEventRecorder->FireKeyUpEvent( static_cast< int >( event.key.keysym.sym ), static_cast< types::charset >( event.key.keysym.unicode ) ); } break; case SDL_QUIT: mRunning = 0; break; case SDL_MOUSEBUTTONDOWN: if( event.button.button == SDL_BUTTON_LEFT ) { mEventRecorder->FireMouseDownEvent( mMousePos, Mouse::MOUSE_BUTTON_LEFT ); mEventRecorder->FireTouchDownEvent( mMousePos, 0 ); } else if( event.button.button == SDL_BUTTON_RIGHT ) { mEventRecorder->FireMouseDownEvent( mMousePos, Mouse::MOUSE_BUTTON_RIGHT ); } else if( event.button.button == SDL_BUTTON_MIDDLE ) { mEventRecorder->FireMouseDownEvent( mMousePos, Mouse::MOUSE_BUTTON_MIDDLE ); } else if( event.button.button == SDL_BUTTON_WHEELUP ) { mEventRecorder->FireMouseDownEvent( mMousePos, Mouse::MOUSE_BUTTON_WHEEL_UP ); } else if( event.button.button == SDL_BUTTON_WHEELDOWN ) { mEventRecorder->FireMouseDownEvent( mMousePos, Mouse::MOUSE_BUTTON_WHEEL_DOWN ); } break; case SDL_MOUSEBUTTONUP: if( event.button.button == SDL_BUTTON_LEFT ) { mEventRecorder->FireMouseUpEvent( mMousePos, Mouse::MOUSE_BUTTON_LEFT ); mEventRecorder->FireTouchUpEvent( mMousePos, 0 ); } else if( event.button.button == SDL_BUTTON_RIGHT ) { mEventRecorder->FireMouseUpEvent( mMousePos, Mouse::MOUSE_BUTTON_RIGHT ); } else if( event.button.button == SDL_BUTTON_MIDDLE ) { mEventRecorder->FireMouseUpEvent( mMousePos, Mouse::MOUSE_BUTTON_MIDDLE ); } break; case SDL_MOUSEMOTION: { mMousePos = mGraphics->ConvertToInternalPos( event.motion.x, event.motion.y ); mEventRecorder->FireMouseMoveEvent( mMousePos ); if( mTouch && mTouch->IsTouchIdDown( 0 ) ) mEventRecorder->FireTouchMoveEvent( mMousePos, 0 ); } break; } } }