Contents

UE4 tick

Contents

在GuardedMain中,如果没有退出命令的话,我们会移植在EngineTick中。

1
2
3
4
5
6
7
FMemMark MemStackMark(FMemStack::Get());

FThreadHeartBeat::Get().HeartBeat(true);

FGameThreadHitchHeartBeat::Get().FrameStart();

FPlatformMisc::TickHotfixables();
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//如果没有多线程的话,我们通过游戏线程进行渲染线程心跳检测

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);