简介:目前已经捋完了 UE 启动过程中的第一个 PreInit 阶段,很多类在看源码时,一遍又一遍的遇到,慢慢的就熟悉了
回顾
下面来回顾一下前面的过程, PreInit 正如其命名,就是预先初始化,主要就是相关配置类的初始化、线程的初始化,运行模式的确定,最基础关联库和插件的加载,还有很多检查,中间遇到问题基本都会直接退出
在阅读完这段后,发现代码那么长,又是第一阅读,很容易往细节里看,看着看着就忘了整体流程。不过读后还是一个心得的
-
UE 有一个 延迟注册功能,用于将函数注册到指定阶段,然后到达那个阶段后调用 RunAndClearDelayedAutoRegisterDelegates 来执行,这里的阶段有对应的 enum,正好对应启动流程的阶段
enum class EDelayedRegisterRunPhase : uint8 { StartOfEnginePreInit, FileSystemReady, TaskGraphSystemReady, StatSystemReady, IniSystemReady, EarliestPossiblePluginsLoaded, ShaderTypesReady, PreObjectSystemReady, ObjectSystemReady, DeviceProfileManagerReady, EndOfEngineInit, NumPhases, };
-
模块加载方面,在启动 UE 时是做了分阶段的,而且使用 enum 来区分,这个就比较方便了。根据字面意思就能知道,引擎在启动的时候都有哪些模块加载阶段了,enum 在 ELoadingPhase 命名空间下,保存在 ModuleDescriptor.h 文件内。每一个阶段都有详细的注释,下面列出具体阶段
enum Type { /** As soon as possible - in other words, uplugin files are loadable from a pak file (as well as right after PlatformFile is set up in case pak files aren't used) Used for plugins needed to read files (compression formats, etc) */ EarliestPossible, /** Loaded before the engine is fully initialized, immediately after the config system has been initialized. Necessary only for very low-level hooks */ PostConfigInit, /** The first screen to be rendered after system splash screen */ PostSplashScreen, /** Loaded before coreUObject for setting up manual loading screens, used for our chunk patching system */ PreEarlyLoadingScreen, /** Loaded before the engine is fully initialized for modules that need to hook into the loading screen before it triggers */ PreLoadingScreen, /** Right before the default phase */ PreDefault, /** Loaded at the default loading point during startup (during engine init, after game modules are loaded.) */ Default, /** Right after the default phase */ PostDefault, /** After the engine has been initialized */ PostEngineInit, /** Do not automatically load this module */ None, // NOTE: If you add a new value, make sure to update the ToString() method below! Max };
在刚开始看的时候基本对所有的东西都是一无所知的,对 C++ 了解的也不是很多,这时候科技的力量就体现出来了,DeepSeek, 遇到看不明白的代码或类或方法,直接复制粘贴问它,我发现他在这种已有数据的说明解释方面还是可以的,非常好用。