コード例 #1
0
ファイル: Application.cpp プロジェクト: LawrenceWeng/ember
void Application::mainLoop()
{
	DesiredFpsListener desiredFpsListener;
	Eris::EventService& eventService = mSession->getEventService();
	Input& input(Input::getSingleton());

	do {
		try {
			Log::sCurrentFrameStartMilliseconds = microsec_clock::local_time();

			unsigned int frameActionMask = 0;
			TimeFrame timeFrame = TimeFrame(boost::posix_time::microseconds(desiredFpsListener.getMicrosecondsPerFrame()));
			bool updatedRendering = mOgreView->renderOneFrame(timeFrame);
			if (updatedRendering) {
				frameActionMask |= MainLoopController::FA_GRAPHICS;
				frameActionMask |= MainLoopController::FA_INPUT;
			} else {
				input.processInput();
				frameActionMask |= MainLoopController::FA_INPUT;
			}

			if (mWorldView) {
				mWorldView->update();
			}

			mServices->getSoundService().cycle();
			frameActionMask |= MainLoopController::FA_SOUND;

			//Keep on running IO and handlers until we need to render again
			eventService.processEvents(timeFrame.getRemainingTime(), mShouldQuit);

			mMainLoopController.EventFrameProcessed(timeFrame, frameActionMask);

		} catch (const std::exception& ex) {
			S_LOG_CRITICAL("Got exception, shutting down." << ex);
			throw;
		} catch (...) {
			S_LOG_CRITICAL("Got unknown exception, shutting down.");
			throw;
		}

	} while (!mShouldQuit);
}
コード例 #2
0
ファイル: Application.cpp プロジェクト: angkorcn/ember
void Application::mainLoopStep(long minMicrosecondsPerFrame)
{
	TimeFrame timeFrame = TimeFrame(boost::posix_time::microseconds(minMicrosecondsPerFrame));
	Input& input(Input::getSingleton());
	ptime currentTime;
	unsigned int frameActionMask = 0;
	try {

		if (mPollEris) {
			currentTime = microsec_clock::local_time();
			mMainLoopController.EventStartErisPoll.emit((currentTime - mLastTimeErisPollStart).total_microseconds() / 1000000.0f);
			mLastTimeErisPollStart = currentTime;
			Eris::PollDefault::poll(0);
			if (mWorldView) {
				mWorldView->update();
			}
			currentTime = microsec_clock::local_time();
			mMainLoopController.EventEndErisPoll.emit((currentTime - mLastTimeErisPollEnd).total_microseconds() / 1000000.0f);
			mLastTimeErisPollEnd = currentTime;
			frameActionMask |= MainLoopController::FA_ERIS;
		}

		currentTime = microsec_clock::local_time();
		mMainLoopController.EventBeforeInputProcessing.emit((currentTime - mLastTimeInputProcessingStart).total_microseconds() / 1000000.0f);
		mLastTimeInputProcessingStart = currentTime;
		input.processInput();
		frameActionMask |= MainLoopController::FA_INPUT;

		currentTime = microsec_clock::local_time();
		mMainLoopController.EventAfterInputProcessing.emit((currentTime - mLastTimeInputProcessingEnd).total_microseconds() / 1000000.0f);
		mLastTimeInputProcessingEnd = currentTime;

		bool updatedRendering = mOgreView->renderOneFrame(timeFrame);
		if (updatedRendering) {
			frameActionMask |= MainLoopController::FA_GRAPHICS;
		}
		mServices->getSoundService().cycle();
		frameActionMask |= MainLoopController::FA_SOUND;

		mMainLoopController.EventFrameProcessed(timeFrame, frameActionMask);

		//If we should cap the fps so that each frame should take a minimum amount of time,
		//we need to see if we should sleep a little.
		if (minMicrosecondsPerFrame > 0) {
			if (timeFrame.isTimeLeft()) {
				try {
					boost::this_thread::sleep(timeFrame.getRemainingTime());
				} catch (const boost::thread_interrupted& ex) {
				}
			}
		}
		mLastTimeMainLoopStepEnded = microsec_clock::local_time();
	} catch (const std::exception& ex) {
		S_LOG_CRITICAL("Got exception, shutting down." << ex);
		throw;
	} catch (const std::string& ex) {
		S_LOG_CRITICAL("Got exception, shutting down. " << ex);
		throw;
	} catch (...) {
		S_LOG_CRITICAL("Got unknown exception.");
		throw;
	}
}