Remember the “5+1” layer model and the two driving beasts.
| Layer | English | Keywords | Typical responsibilities | Example code Xiaoming would write for “making the character move” |
|---|---|---|---|---|
| ⑤ | Tool Layer | Editor, productivity | Level/Material/Blueprint/Particle/Sound… all DCC import and visual editing | Use Level Editor to drag the robot into the scene, adjust the camera and animation State Machine |
| ④ | Function Layer | Visible, animatable, playable | Rendering (Render), Animation, Physics, AI/Scripting, UI (HUD) | TickLogic: read input → update Skeletal Animation; TickRender: submit DrawCall |
| ③ | Resource Layer | Assets = efficient data + relationships | Convert different asset types into efficient required formats 1. .max/.psd → engine Asset (DDS textures, compressed Mesh); 2. Manage GUID, Handle, lifecycle, lazy loading, GC | Write Composite Asset: make “Robot.asset” point to Mesh/Texture/Anim |
| ② | Core Layer | Swiss Army knife | Math library (SIMD), containers (fragmentation-free), memory pool, thread/task system, RTTI/Reflection | Provide Vec3/Quat math, efficient Queue, memory allocator for upper layers to call |
| ① | Platform Layer | Write once, run everywhere | Encapsulate OS, file paths, CPU/GPU differences, RHI (DX/Metal/Vulkan abstraction), input devices | Implement RHI::CreateBuffer(): PC uses DX12, Mac uses Metal |
Avoid logic where lower layers call upward into upper layers in reverse, which would cause a messy structure.
The two “mythical beasts” — the game main loop One Tick every 16.67ms (60 FPS):
- TickLogic:
- Read input → AI decision → Skeletal Animation update → physics collision → memory GC → …
- (Whether you can see it or not, the world state has advanced)
- TickRender:
- Cull based on latest state → generate CommandBuffer → GPU execution → present frame
- (Presentation only; does not affect real physics/logic) → Logic and rendering are strictly separated, facilitating multithreading, replay recording, and network synchronization.
Resource → Asset lifecycle (key)
Raw files (Resource)
↓ Import/Convert (offline)
Engine assets (Asset):
- Compact data, GPU-friendly (e.g., DDS textures)
- Carry GUIDs; renaming/moving does not lose references
- Composite Asset describes associations (Mesh+Mat+Anim)
↓
Runtime Handle system + Asset Manager: - Lazy loading, Reference Counting, asynchronous unloading
- Avoid “stutter” and “memory blow-up” during Level switching
Evolution of multithreading and the Job system
Single-threaded → Logic/Render two threads → function-module threads (Physics/Animation) → fully Job-based (Task Graph)
Key: identify dependencies (Dependency), build a DAG, and split tasks into atomic Jobs to keep all cores fed.
Three golden rules of memory (Core Layer design mantra)
- Keep data together (Array-of-Struct → Struct-of-Array)
- Sequential access (Cache-line friendly)
- Batch reads/writes/frees (reduce malloc/free; use a Pool)
Easily overlooked pitfalls in the Platform Layer
- File path separators, case sensitivity, encoding
- Different CPU architectures (x86/ARM, big.LITTLE cores, SPU)
- Graphics API differences → RHI abstraction
- Input devices (keyboard/mouse, gamepad, steering wheel, Kinect…)
Tool Layer = productivity
- In-house: Level Editor, Material Editor, Blueprint…
- DCC chain: Max/Maya/PS/Houdini → Export Plugin → Asset Conditioning Pipeline → engine
- There is still no absolute standard for a unified data format (FBX→USD?); most engines build their own.
Engine = ⑤ Tool ④ Function ③ Resource ② Core ① Platform; Tick drives the layered stack, the lower, the steadier; the higher, the livelier.
Video link: Engine Architecture Layers | GAMES104 - Modern Game Engine: From Beginner to Practice