void MapReduceProgress::timerEvent(QTimerEvent* event) { updateTimeElapsed(); }
void Game::run() { if (!initialized) { return; } instance = newInstance; newInstance = nullptr; Assets::clean(); Thread updateThread([]() { lastUpdate = Time::get(); while (!metallicar::quit && instance) { bool updated = false; updateTimeElapsed(); while (timeElapsedGreaterThanStep()) { updated = true; renderingBackBuffer->clear(); Input::pollEvents(); instance->update(); instance->render(); if (newInstance) { // change instance delete instance; instance = newInstance; newInstance = nullptr; Assets::clean(); } } if (updated) { // swap rendering buffers renderingBuffersLock.mutexlock(); map<double, list<function<void()>>>* tmp = renderingFrontBuffer; renderingFrontBuffer = renderingBackBuffer; renderingBackBuffer = tmp; renderingBuffersLock.unlock(); } Thread::sleep(1); } }); updateThread.start(); Thread audioCleanupThread([]() { while (!metallicar::quit && instance) { Audio::clean(); Thread::sleep(500); } }); audioCleanupThread.start(); // main thread (I/O) while (!metallicar::quit && instance) { updateFPS(); Input::pollWindowEvents(); // copy front buffer renderingBuffersLock.mutexlock(); map<double, list<function<void()>>> renderers(*renderingFrontBuffer); renderingBuffersLock.unlock(); // render Graphics::prepareFrame(); for (auto& kv : renderers) { for (auto& renderer : kv.second) { renderer(); } } Graphics::finalizeFrame(); Window::update(); } updateThread.join(); audioCleanupThread.join(); }
void MapReduceProgress::showEvent(QShowEvent* event) { m_timeElapsed.start(); m_timerId = startTimer(1000); updateTimeElapsed(); }