Introduction to game engine layering

Game engine layered architecture (top-down)

Tool Layer
In a modern game engine, the first thing we see may not be complex codes, but various editors. Using these editors, we can create and design levels, characters, animations, etc. Game content, this series of editors constitute the top layer of the engine - the tool layer.
Insert image description here
Function Layer

  • The process of converting a three-dimensional virtual world into a frame-by-frame two-dimensional image requires the use of a rendering system (Rendering);
  • To make the stationary models move and make lifelike movements to form a continuous picture, we need to use the animation system (Animation);
  • Physical collisions and the action of various forces make the movement of objects closer to the real world. We need to use the physical system (Physics);
  • Each game world has its own rules, and there are also NPCs to enrich the game playability, which requires the use of scripts (Script), state machines (FSM) and AI;

The operation of any game is inseparable from human-computer interaction, which involves a series of functions. The above functions combined together form the functional layer of the game engine.
Insert image description here
The Resource Layer
game contains not only lines of source code, but also multimedia files in various formats, such as PhotoShop's PSD files and 3DSMAX's MAX files, which load and manage this series of graphics, images, audio, Video files and other data are the tasks of the resource layer. The resource layer is located below the functional layer and continuously provides data to the functional layer. It is like a painter painting above, and the resource layer continuously provides paint for it below.
Insert image description here
Core Layer
The most core and most important layer in the game engine is the core layer. The core layer is responsible for responding to frequent calls from the upper layers and providing various basic functions, such as memory management, container allocation, data calculation, multi-thread creation, etc.
Insert image description here
Platform Layer
The platform layer is the most easily overlooked layer. A game or engine may be released on different platforms and have different graphical interfaces; and different users may use different hardware devices, such as Keyboard, mouse and controller. Adapting to different platforms is the task of the platform layer. Insert image description here
Third Party Libraries
middleware and third-party libraries are converted in the form of SDK (Software Development Kit) or file format.
Insert image description here
Why layered architecture?

Insert image description here
In order to decouple the game engine and reduce complexity, each layer will complete its own tasks independently. The bottom layer provides basic services to the upper layer, and the upper layer calls the underlying tools. Such a layered architecture makes the upper layer flexible and the bottom layer stable, which is more conducive to function updates and development.

Resource layer

PSD files in Photohop, MAX files in 3DSMAX, etc. generally contain the tool's own information, a large amount of data that has nothing to do with the engine, and the data format is relatively complex. Direct use will greatly reduce efficiency. In order to improve the efficiency of scheduling resources, the engine needs to convert different resources into asset files when importing. For example, when using texture files in the engine, we may import files in JPG and PNG formats. However, the compression algorithms of these two files are not efficient for the GPU. Using them directly in the GPU will waste performance, so they are usually converted into dds. The format is then stored in the video memory.
Insert image description here
For any game character, such as the small robot in the picture above, you may need to bind corresponding materials, textures, grids, animations and other resources, define a Composite asset file to associate these resources, such as XML files, and use GUID (Globally Unique Identifier) symbol) for identification management.
Insert image description here
When actually running, the game also needs to use the Asset Manager (Runtime Asset Manager), which manages assets according to the asset life cycle (Asset Life Cycle), real-time loading and unloading of assets, allocation of resources, and garbage collection (GC). , delayed loading, etc. are included.

Functional layer

Insert image description here
The use of the functional layer makes the virtual world in the game move forward every time a tick passes. Within a tick, the tickLogic() and tickRender() functions are executed respectively. The logical tickLogic() is generally executed first and is mainly used to simulate the game world, including input and output processing, camera perspective position transformation, collision detection, etc. Operation; the tickRender() used to draw the world renders based on the position of each asset calculated by tickLogic().
Insert image description here
The functional layer is very complex and large, especially when it comes to network programming, so multi-threaded computing is usually required. The current mainstream multi-threading is to split tasks that can be calculated in parallel and put them into multiple threads for calculation. However, if there are tasks that are not suitable for parallel computing, its flaws will be exposed. In the future, the engine will divide each task into very small executable units, and allocate each atomic task to multiple threads for execution, making more efficient use of resources.
Insert image description here

core layer

The core layer provides a foundation for all logic in the upper layer. It provides mathematical libraries (such as matrix operations), data structures and containers (such as binary trees), memory management and other tools. Because everything in the engine is centered on efficiency, when performing mathematical operations, you can use approximate operations or SIMD (single instruction multiple data streams, executing the same instruction at the same time in a synchronous manner) to improve computing efficiency; as for Data structures and containers. The data structures that come with programming languages ​​may cause some problems. For example, the storage space opened by Vector in C++ will increase exponentially when adding objects. After adding a large number of objects, we will not be able to use the storage space. It is known that memory holes may occur, and the data structure in the engine is more convenient for memory management and improves access efficiency. The memory management of the engine is very similar to that of the operating system. The core principle can be summarized as: store data together as much as possible and access it easily. Access in sequence, process in batches
Insert image description here

platform layer

The platform layer enables the game to be compatible with different platforms such as Xbox, Mac, and Windows, as well as different devices such as controllers and keyboards and mice. The platform layer uses Render Hardware Interface (RHI) to remove the differences between different Graphics APIs (such as DirectX11, DirectX12, OpenGL), so that the upper layer does not need to care about the problems that may be caused by using different APIs.
Insert image description here

tool layer

Insert image description here
The tool layer is generally presented in the form of an editor (blueprint editor, material editor, etc.) and can be developed using different programming languages ​​(C++, C#, Html5, etc.). Development efficiency is prioritized. It needs to enable different users to create game content. . Because many game digital assets are created in different DCCs (Blender, MAYA, etc.), the tool layer generally contains import and export tools for importing and exporting game resources.

Guess you like

Origin blog.csdn.net/gghhb12/article/details/136437631