void Engine::RunFrame() { assert(initialized_); // If not headless, and the graphics subsystem no longer has a window open, assume we should exit if (!headless_ && !GetSubsystem<Graphics>()->IsInitialized()) exiting_ = true; if (exiting_) return; // Note: there is a minimal performance cost to looking up subsystems (uses a hashmap); if they would be looked up several // times per frame it would be better to cache the pointers Time* time = GetSubsystem<Time>(); Input* input = GetSubsystem<Input>(); Audio* audio = GetSubsystem<Audio>(); time->BeginFrame(timeStep_); // If pause when minimized -mode is in use, stop updates and audio as necessary if (pauseMinimized_ && input->IsMinimized()) { if (audio->IsPlaying()) { audio->Stop(); audioPaused_ = true; } } else { // Only unpause when it was paused by the engine if (audioPaused_) { audio->Play(); audioPaused_ = false; } Update(); } Render(); ApplyFrameLimit(); time->EndFrame(); }
LRESULT Audio::AudioProcStatic(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { #pragma warning(disable: 4312) Audio* audio = reinterpret_cast<Audio*>(GetWindowLong(hWnd, GWL_USERDATA)); #pragma warning(default: 4312) switch (msg) { case MM_MCINOTIFY: // message received when an audio file has finished playing - used for repeat function if (wParam == MCI_NOTIFY_SUCCESSFUL && audio->IsPlaying()) { audio->SwitchPlayingOff(); if (audio->GetRepeat()) audio->Play(); // repeat the audio else audio->CallListeners(); // notify listeners that the audio file has come to an end } } return 0; }