We need a robust engine in the game. How can we ensure the robustness of the engine? There are two main aspects: one is to minimize bugs, and the other is to discover and solve bugs as soon as possible after they occur. Like most engines, the GB engine has its own set of protection mechanisms. Includes assertions, log modules, and debug modules.
I. Assertions
The use of assertions allows developers to see the problem in the shortest time. Generally, assertions are only useful in debug mode. In release mode, we can record the error information in log. At this time, we need to redefine assert. The simplest thing is to define a macro. In GB, assert-related macros are defined in asserts. h. Ee_disable_asserts macro is used to control whether to enable assertions. ee_enable_release_assert is used to control whether to enable assertions in release mode. In general, it is not recommended to enable assertions in release mode. Three assertions are provided in GB: ee_assert_xxx, ee_verify_xxx and ee_fail_xxx. the first is used in debug mode, the second is used in release mode, and the last is used in case of detection failure.
2. Log
The log system is an essential part of a game engine. The most important purpose of building a log module is to understand the running status of the entire engine. First, we must know what should be recorded in the log. In general, the information recorded in the log can be divided by three levels: High, Medium, and low. Advanced information includes engine error information. For example, the crash information obtained through try catch is usually fatal errors, such as array out-of-bounds, memory access failure, and memory leakage. Medium refers to some non-fatal errors, such as data loading failure, network connection failure, and file opening failure. Low-level information includes some running prompts. Of course, we can also refine the level score as needed. In GB, the log level is divided into eight levels. We can perform different processing based on different levels. Generally, we store different types of log information in different files, it is recommended that the log information that causes the engine to crash be sent to a database over the network, which is advantageous for us to find the game errors.