"Game engine Architecture" reading experience (ii)

Source: Internet
Author: User

I. Debugging techniques and tools

(1) Basic commissioning

A) logging and tracking, some bugs are difficult to use vs own debugging for single-step debugging, the best solution is the printf debugging method, print a set of data, observe the situation. What I did was build a console alone, but vs comes with a outputdebugstring () method to print debug information. But this only supports char* content, and we can process this function so that it supports different types of data and even allows it to accept variable parameters.

b) Verbose level: we sometimes want to print, sometimes do not want to print, so you can set the level of print content, each information set a level, and then set a global level, greater than this level of printing, and then you can adjust the global level, control the scope of the printed content.

c) Channel: Re-expansion of thinking, there are a lot of content to print, will be more chaotic, then, the different modules of the printing information into different channels can solve the problem, and then add a channel parameters, you can control the printing of which channel information.

d) LOG: Sometimes the program will be inexplicable collapse, this time is not only to see the printing information, we need to write the program's execution process to the log file for running after the view results. Here is a tangled place, if every time the printing is entered into the log file, will guarantee the integrity of the log, but will lose performance, if the buffer is full to output to the log, there is a possibility that the program will not be able to collapse the contents of the buffer output, so this is a choice of issue.

e) Crash report: Crash Report is also a log, but the program crashes only the log, most operating systems have a top-level exception handler, you can print a variety of exception information in this function, or even send e-mail to the program team (this is a bit 6 AH), the exception information including player status, level, Running scripts, stack information, and so on help us to find information about bugs.

(2) Special debugging function in the game

The above general program can also be used, but the following should be unique in the game, drawing debugging.

The game is almost entirely mathematical content-driven, we use mathematics to locate objects, such as collision detection, projection of light, detection of sight, and so on, if we all print out, on the one hand, particularly troublesome, on the other hand is not good observation, a better solution is to use the plot to draw information, such as a bounding box, then draw it out , is the so-called picture top thousand words, the picture is the best expression way.

Debug Drawing API: should be easy to use, the graphics package expands straight lines, spheres, points, axes (x red, y green, z Blue), bounding box, text. It is best to add the ability to control color, line width, sphere radius, axis length, and so on.

We can adjust the position of these elements by parameters, size, etc., the degree of freedom is very high. And the content can be managed using a Debugdrawmanager class that adds the debug drawing content to the debug content queue and renders it together during rendering.

(3) The game built-in menu, or the main console is also a good choice, we can control the game through the menu or console in the game, if the strong scripting language support, and even the entire game can be manipulated. such as an AI, you can remove its AI, instead of manually control AI to achieve the purpose of debugging.

(4) When we are debugging the game, we can add a bit buff to the character manually, such as removing collision detection and moving to any scene.

(5) Camera movement: Sometimes when debugging the game, from a certain angle we can not see the game very well, so we could design a game can also be moved during the pause operation of the camera to help us Debug.

(6) Screenshot is also a very important debugging method, sometimes we can not reproduce the bug very well, in this case or screen recording can be very good to help us locate the bug.

(7) Performance testing: The game is real-time system, to ensure that FPS is very important, we have to grasp the performance, one way is to see the function of the call time, on the other hand is the function of the execution time, on the other hand is the number of calls to the function.

(8) If a resource fails to load, a clear log hint should be given, or it should appear directly in the game.

(9) Memory and memory leak detection are also important.

Two. Rendering engine

The rendering engine is a top priority in the game engine and the hardest part. As a graphics, DX has not learned how little white, said the chapter and do not understand how much, just know some concepts, you have to continue the evil complement.

(1) The first is to introduce the elements of the 3D world: vertices, triangular meshes, lighting, texture textures, lighting models, cameras, rasterization, Z-cache, anti-aliasing and so on.

(2) Render pipeline: The rendering of the architecture is based on the pipeline (pipeline), the biggest advantage of the pipeline is parallelism, the calculation of each phase at the same time, greatly increasing the throughput of the rendering system.

(3) The division of the rendering pipeline in a generalized manner:

A) tool stage (offline): Defining geometry and materials

b) Asset adjustment phase (offline): Adjusts geometry and material data to become the format available to the engine

c) Application phase (CPU): Identify potentially visible instances of the mesh and send them and their materials to the graphics hardware for rendering.

d) geometric phase (GPU): Vertex transformation, illumination, projection to homogeneous clipping space

e) rasterization phase (GPU): Triangles are converted to fragments, and the fragments are shaded. After multiple tests (depth test, alpha test, template test, etc.) finally and frame buffer fusion.

(4) Set the world matrix before rendering, light direction vector, texture binding, texture addressing and filtering modes, time-based texture scrolling or animation effects, depth testing (disabled or enabled), alpha blending options. Before committing the entity to be set, drawing only sometimes needs to restore the settings. If we forget, it causes a rendering state to leak, that is, the rendering state of the previous entity affects the rendering state of the next entity.

(5) Setting the rendering state is global, effective for the entire GPU, when changing the rendering state, the entire GPU pipeline must complete the work to replace the new settings, so for the order of rendering must be well grasped, otherwise there will be performance loss. It is best to render according to the material sort, but if you press the material, there will be overdraw to render the same pixel repeatedly. The solution is to use the GPU's deep pre-render step (Z-prepass), which is the first time to quickly produce deep buffer content, and the second time to fill in the frame buffer with a full color.

(6) Scene graph: The so-called scene graph is not a diagram, but the data structure of the object in the management scene, before the flat-cut truncated object is removed before the display objects, usually four fork tree, eight fork tree, BSP tree, KD tree, space hashing technology. Quadtree and octal trees use recursive thinking to subdivide the scene and keep the query overhead to a minimum. The BSP tree uses a plane to divide the space equally, the legendary two-dollar space partition tree.

BSP Tree or portal system: for indoor environments

Quad Tree: Outdoor flat terrain, God view

Additional culling mechanism: outdoor large scene, first person or third person game

(7) Well, the rest of me basically can't read ... such as: normal map, high dynamic range illumination (HDR), global Illumination (GI), gamma correction, full-screen post-processing (dynamic blur, depth blur, vignette, coloring, etc.)


The game engine is really profound, even if 10 years time, also not necessarily can understand all. The game is simple, the premise is that there are engines. It's too hard to be an engine!


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Game engine Architecture" reading experience (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.