Game engine with C + +
- Reference Cppcon 2016:jason Jurecka "Game engine using STD C + + 11"
- This presentation focuses on the use of c++11 in the game engine
Features of the game engine
Do not use too many STD
- The game's history is very long, and the memory, CPU use is very harsh
- For example, for std::string, the operation is slow, so more use of CString
- For example, templates in Std can cause code to swell
The game engine does not use too many exceptions
- Turns off the exception of third-party libraries.
The game engine will not be too formal fix, more casual
Use of c++11 in the game engine
- constexpr do compile-time resource version management
- Static_assert do compile-time type validation
- Unique_ptr do Raii, replace auto_ptr
- Auto_ptr has copy semantics, the source object becomes invalid after copying, while Unique_ptr has no copy semantics, but provides the moving semantics
- Auto_ptr is not a container element, unique_ptr can be used as a container element
- Move semantics accelerates data copy of standard containers
- The algorithm library is also suitable for raw arrays
- Ref Cppcon 2016:jason Jurecka "Game engine using STD C + + 11"
- The speaker likened himself to a Swiss army knife, capable of doing everything but not proficient, shape rendering, data loading and parsing, game AI
- Std::async
- Pure: Used to declare purely virtual functions
Smart pointers for reference c++11
- Four smart pointers: Auto_ptr, shared_ptr, weak_ptr, unique_ptr the latter three are c++11 support, and the first one has been deprecated by c++11
Auto_ptr
- Implemented in c++98
- When the value
p1 = p2
is assigned, the P2 becomes a null pointer, and the assignment is actually assigning the P2 member variable pointer to P1 and calling release () on P2
- Release () is the function of releasing the original pointer, the member variable pointer is set to 0, and returns the source pointer, does not release the resource
- The function of Reset () is to set the member variable pointer to 0 and release the resource
- Judge Null to use
p.get() == NULL
- cannot be placed in a container because the assignment of the container will cause the element in the container to be placed empty, refer to:
- unique_ptr
- to replace auto_ptr, add move semantics, and support custom deleter
- compared to auto_ptr, Assignment and replication are not supported, but assignment and replication with move can be supported using
p = = NULL
to determine whether it is empty
shared_ptr
Weak_ptr
- Used to monitor shared_ptr and resolve deadlock issues when shared_ptr mutual references
Author FOCUSTC, from CSDN
Game engine with C + +