コード例 #1
0
ファイル: RWGame.cpp プロジェクト: SamStudio8/openrw
int RWGame::run()
{
	clock.restart();
	
	// Loop until the window is closed or we run out of state.
	while (window.isOpen() && StateManager::get().states.size()) {
		State* state = StateManager::get().states.back();

		RW_PROFILE_FRAME_BOUNDARY();
		
		RW_PROFILE_BEGIN("Input");
		sf::Event event;
		while (window.pollEvent(event)) {
			switch (event.type) {
			case sf::Event::GainedFocus:
				inFocus = true;
				break;
			case sf::Event::LostFocus:
				inFocus = false;
				break;
			case sf::Event::KeyPressed:
				globalKeyEvent(event);
				break;
			case sf::Event::Closed:
				return 0;
			default: break;
			}

			RW_PROFILE_BEGIN("State");
			state->handleEvent(event);
			RW_PROFILE_END()
		}
		RW_PROFILE_END();
		
		if(! window.isOpen() )
		{
			break;
		}

		float timer = clock.restart().asSeconds();
		accum += timer * timescale;

		RW_PROFILE_BEGIN("Update");
		if ( accum >= GAME_TIMESTEP ) {
			RW_PROFILE_BEGIN("state");
			StateManager::get().tick(GAME_TIMESTEP);
			RW_PROFILE_END();

			if (StateManager::get().states.size() == 0) {
				break;
			}

			RW_PROFILE_BEGIN("engine");
			tick(GAME_TIMESTEP);
			RW_PROFILE_END();
			
			accum -= GAME_TIMESTEP;
			
			// Throw away time if the accumulator reaches too high.
			if ( accum > GAME_TIMESTEP * 5.f )
			{
				accum = 0.f;
			}
		}
		RW_PROFILE_END();

		float alpha = fmod(accum, GAME_TIMESTEP) / GAME_TIMESTEP;
		if( ! state->shouldWorldUpdate() )
		{
			alpha = 1.f;
		}

		RW_PROFILE_BEGIN("Render");
		RW_PROFILE_BEGIN("engine");
		render(alpha, timer);
		RW_PROFILE_END();

		RW_PROFILE_BEGIN("state");
		if (StateManager::get().states.size() > 0) {
			StateManager::get().draw(renderer);
		}
		RW_PROFILE_END();
		RW_PROFILE_END();

		renderProfile();

		window.display();
	}

    if( httpserver_thread )
    {
        httpserver_thread->join();
    }

	return 0;
}
コード例 #2
0
ファイル: RWGame.cpp プロジェクト: haphzd/openrw
int RWGame::run()
{
	last_clock_time = clock.now();

	// Loop until the window is closed or we run out of state.
	while (window.isOpen() && StateManager::get().states.size()) {
		State* state = StateManager::get().states.back();

		RW_PROFILE_FRAME_BOUNDARY();
		
		RW_PROFILE_BEGIN("Input");
		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			switch (event.type) {
			case SDL_QUIT:
				window.close();
				break;

			case SDL_WINDOWEVENT:
				switch (event.window.event) {
				case SDL_WINDOWEVENT_FOCUS_GAINED:
					inFocus = true;
					break;

				case SDL_WINDOWEVENT_FOCUS_LOST:
					inFocus = false;
					break;
				}
				break;

			case SDL_KEYDOWN:
				globalKeyEvent(event);
				break;

			case SDL_MOUSEMOTION:
				event.motion.xrel *= MOUSE_SENSITIVITY_SCALE;
				event.motion.yrel *= MOUSE_SENSITIVITY_SCALE;
				break;
			}

			RW_PROFILE_BEGIN("State");
			state->handleEvent(event);
			RW_PROFILE_END()
		}
		RW_PROFILE_END();

		auto now = clock.now();
		float timer = std::chrono::duration<float>(now - last_clock_time).count();
		last_clock_time = now;
		accum += timer * timescale;

		RW_PROFILE_BEGIN("Update");
		if ( accum >= GAME_TIMESTEP ) {
			RW_PROFILE_BEGIN("state");
			StateManager::get().tick(GAME_TIMESTEP);
			RW_PROFILE_END();

			if (StateManager::get().states.size() == 0) {
				break;
			}

			RW_PROFILE_BEGIN("engine");
			tick(GAME_TIMESTEP);
			RW_PROFILE_END();
			
			accum -= GAME_TIMESTEP;
			
			// Throw away time if the accumulator reaches too high.
			if ( accum > GAME_TIMESTEP * 5.f )
			{
				accum = 0.f;
			}
		}
		RW_PROFILE_END();

		float alpha = fmod(accum, GAME_TIMESTEP) / GAME_TIMESTEP;
		if( ! state->shouldWorldUpdate() )
		{
			alpha = 1.f;
		}

		RW_PROFILE_BEGIN("Render");
		RW_PROFILE_BEGIN("engine");
		render(alpha, timer);
		RW_PROFILE_END();

		RW_PROFILE_BEGIN("state");
		if (StateManager::get().states.size() > 0) {
			StateManager::get().draw(renderer);
		}
		RW_PROFILE_END();
		RW_PROFILE_END();

		renderProfile();

		window.swap();
	}

    if( httpserver_thread )
    {
        httpserver_thread->join();
    }

	return 0;
}