Exemplo n.º 1
0
bool Tick()
{
	bool DoNextTick = true;

	DoNextTick = TickSim();

	TickRender();

	SwitchToThread();

	return DoNextTick;
}
Exemplo n.º 2
0
/*virtual*/ bool Framework3D::Tick()
{
	XTRACE_FUNCTION;
	PROFILE_FUNCTION;

	bool DoNextTick = true;

	if( HasRequestedExit() )
	{
		DoNextTick = false;
	}

	m_HasFocus = m_Window->HasFocus();

	StringManager::FlushStrings( StringManager::ESL_Transient );

	m_Clock->Tick( m_UIManager->GetUIStack()->PausesGame(), false );

	m_EventManager->Tick();

	if( m_DoVideoCapture )
	{
		// One sim tick, one render tick
		DoNextTick &= TickSim( m_VideoCaptureFixedFrameTime );
		TickRender();
	}
	else if( m_UseFixedFrameTime )
	{
		m_FrameTimeAccumulator += m_Clock->GetMachineDeltaTime();

		if( m_FrameTimeAccumulator > m_FrameTimeLimit )
		{
			// We've hit a very long frame, maybe we were sitting in the debugger.
			// Don't bother simming for this duration, it will just cause more hitches.
			m_FrameTimeAccumulator = 0.0f;
		}

		const int NumSimTicks = static_cast<int>( m_FrameTimeAccumulator / m_FixedFrameTime );
		const int LastSimTick = NumSimTicks - 1;
		for( int SimTickIndex = 0; SimTickIndex <= LastSimTick && DoNextTick; ++SimTickIndex )
		{
			ASSERT( m_FrameTimeAccumulator >= m_FixedFrameTime );
			m_FrameTimeAccumulator -= m_FixedFrameTime;

			DoNextTick &= TickSim( m_FixedFrameTime );

			if( SimTickIndex == LastSimTick )
			{
				TickRender();
			}
			else
			{
				DropRender();
			}
		}
	}
	else
	{
		// One sim tick, one render tick
		DoNextTick &= TickSim( m_Clock->GetMachineDeltaTime() );
		TickRender();
	}

#if BUILD_WINDOWS_NO_SDL
	{
		XTRACE_NAMED( SwitchToThread );	// Crashing within this trace name would typically indicate a crash in another thread.
		const BOOL SwitchedToThread = SwitchToThread();
		if( 0 == SwitchedToThread )
		{
			// Prevent hogging the CPU, maybe?
			Sleep( 0 );
		}
	}
#endif
#if BUILD_SDL
	{
		SDL_Delay( 0 );
	}
#endif

	return DoNextTick;
}