在GuardedMain中,如果没有退出命令的话,我们会移植在EngineTick中。
FMemMark MemStackMark(FMemStack::Get());
FThreadHeartBeat::Get().HeartBeat(true);
FGameThreadHitchHeartBeat::Get().FrameStart();
FPlatformMisc::TickHotfixables();
//如果没有多线程的话,我们通过游戏线程进行渲染线程心跳检测
TickRenderingTickables();
//发生在第一帧,主线程等待渲染线程完成所有的renderingcommands
FlushRenderingCommands();
GEngine-\>UpdateTimeAndHandleMaxTickRate();
//通知渲染线程的scene及逆行所有的primitivescene的更新
for (const FWorldContext& Context : GEngine-\>GetWorldContexts())
{
UWorld\* CurrentWorld = Context.World();
if (CurrentWorld)
{
FSceneInterface\* Scene = CurrentWorld-\>Scene;
ENQUEUE_RENDER_COMMAND(UpdateScenePrimitives)(
[Scene](FRHICommandListImmediate& RHICmdList)
{
Scene-\>UpdateAllPrimitiveSceneInfos(RHICmdList);
});
}
}
// BeginFrameRenderThread(RHICmdList, CurrentFrameCounter);
//Scene-\>StartFrame();
//当不是editor的时候
GEngine-\>EmitDynamicResolutionEvent(EDynamicResolutionStateEvent::BeginFrame);
GMalloc-\>UpdateStats();
//计算FPS
CalculateFPSTimings();
FlushPendingDeleteRHIResources_RenderThread();
FPlatformApplicationMisc::PumpMessages(true);
bIdleMode = ShouldUseIdleMode();
FPlatformProcess::Sleep(.1f);
SlateApp.PollGameDeviceState();
SlateApp.FinishedInputThisFrame();
//tick media framework
MediaModule-\>TickPreEngine();
//主的game tick
GEngine-\>Tick(FApp::GetDeltaTime(), bIdleMode);
//异步的shader编译
GShaderCompilingManager-\>ProcessAsyncResults(true, false);
//
GDistanceFieldAsyncQueue-\>ProcessAsyncTasks();
//
MediaModule-\>TickPreSlate();
//
ProcessLocalPlayerSlateOperations();
//处理slate的逻辑
//……
FSlateApplication::Get().Tick();
FModuleManager::GetModuleChecked\<IAutomationControllerModule\>(AutomationController).Tick();
FModuleManager::GetModuleChecked\<IAutomationWorkerModule\>(AutomationWorkerModuleName).Tick();
//tick RHI
RHITick( FApp::GetDeltaTime() ); // Update RHI.
GFrameCounter++;
//得到所有需要cleaned up 的object
PendingCleanupObjects = GetPendingCleanupObjects();
//同步主线程和渲染线程
{
SCOPE_CYCLE_COUNTER(STAT_FrameSyncTime);
// this could be perhaps moved down to get greater parallelism
// Sync game and render thread. Either total sync or allowing one frame lag.
static FFrameEndSync FrameEndSync;
static auto CVarAllowOneFrameThreadLag =
IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.OneFrameThreadLag"));
FrameEndSync.Sync( CVarAllowOneFrameThreadLag-\>GetValueOnGameThread() != 0 );
}
//删除之前的object
delete PreviousPendingCleanupObjects;
//deferred commands
GEngine-\>TickDeferredCommands();
//MediaModule-\>TickPostRender();
// end of RHI frame
EndFrameRenderThread(RHICmdList);