2.3 engine Planning
Compared with today's commercial game engines, this game engine built on the game in this book is insignificant. The engine of the game stranded is small enough to be contained in a single library. Since the game engine depends on the needs of developers, there are more than one correct way to develop or split the game engine. Generally, it is better to split unrelated systems into different dynamic link libraries (DLL), so that you can easily update, modify, and re-release the changed software to users. If there is any new version, it is very economical to re-release the full .exe file to users who have already purchased the game. As long as developers re-release a dynamic link library (DLL) (only a small part of the entire language family), the efficiency will be improved a lot. Although the current broadband Internet allows you to download and update information much faster than in the past, these games are far more complex than they were in the past. Currently, some games only need to use four or more CDs to install them on users' machines. This makes it inefficient to re-release the entire game on the Internet. This is used to fix serious problems on users' machines.ProgramThe major update information of defects is terrible.
Stranded's game engine is divided into five main parts. They are rendering systems, input systems, sound systems, artificial intelligence systems, and mathematical libraries. Each part is very small, so a separate static library can meet the needs of game development in this book. Of course, if the game engine is extended beyond the scope of this book's discussion, the reader may think of using multiple Dynamic Link Libraries (DLL) instead of static libraries. Each part of the engine has its own header file and source file. For convenience, all header files are included in a header file named engine. h. You only need to include all header files in one file and modify them. You do not need to consider complicated operations in multiple files in the game engine.
2.3.1 Rendering System
The rendering system contains a program for rendering a large number of geometric figures at a time.Code. For example, to display a role model, you need to use the cache to send all data to the rendering system at the same time, that is, not to send only one triangle data at a time. You can use a texture image to gradient the ry to add the details of the scene. There is no difference between role model data and level data. They are processed in the same way. The model and other objects to be animated must be animated before being sent to the rendering system. When talking about level ry, this book will use a variety of different technologies, which will make the Data Rendering rate higher. The rendering system only cares about the data sent to itself and displays it, regardless of whether you want to draw a ry or render the displayed text on the screen. The rendering system is not responsible for what needs to be rendered, but for what does not need to be rendered.
The rendering system initializes the rendering API, creates and draws text, draws texture ry, implements hardware illumination, and sorts out the system work after completing the work. Since texture creation and destruction depend on the rendering API being used, the rendering system will have to deal with these tasks. Processing textures directly in the rendering system will make the system as independent as possible. Porting the rendering API to OpenGL or another rendering API does not affect the code outside the rendering system. This is the key to writing API-independent code.
2.3.2 Input System
The input system supports the keyboard, mouse, handle, and game pad. Because directinput considers all input devices such as non-keyboard and mouse, the same code is used for basic processing on devices such as game controllers, controllers, and game cushions. The game engine contains an input system. The only purpose of this input system is to create an input device and initialize and disable the API when necessary. Each device is derived from a base class. This is also used in the input system class. Each device contains a common function that determines whether a button is in a specific State (Up, down, or down.
2.3.3 sound system
The sound system is very similar to the input system because it contains a sound system class derived from the base class, because it sets the sound API, creates and destroys sound objects, and clean up the system when the work is completed. The sound object is derived from the base class of the sound object, so that the sound system remains independent from other systems. Because audio resources occupy some memory, many objects use the same sound file. The sound system saves the sound file list by itself. The sound list contains audio files that have been loaded and will be played. The sound object has its own sound ID, which is used to tell the sound system the sound it references. Although hundreds of objects use a certain sound file, only one sound file is loaded in the memory. The sound object in the Game Engine saves the sound file name and saves the array index to the sound list of the corresponding file. In essence, a sound object is very simple. It is just a method to reference a sound file loaded by a sound system.
2.3.4 artificial intelligence
In terms of perception, artificial intelligence systems can be compared with mathematical systems. It consists of several functions used to determine the actions to be taken during code calls. AI will maintain a simple style in this game, so there is not much code here.
2.3.5 Math Library
A mathematical library is a set of mathematical classes, functions, and constants that are widely used by engines and their games. The main mathematical library classes include vector, matrix, Quaternary, Ray, plane, boundary body, basic physics functions, and polygon. Mathematics is mathematics, and it is not simple. The game engine and other games developed on this engine will all use each item in the math library. The code added to the math library is simple and clear, and can be expanded with the expansion of the game engine/game.
the physics content in the math library is very simple. It is only responsible for dealing with simple collision and reaction between gravity and objects. An object must be capable of fast processing and collision between other objects, as well as fast processing and environment collision. Using this processing method will result from problems related to program performance, but there are many ways to accelerate computing, so as to ensure that game players can accept program performance. Physics is a huge topic. Appendix A has a lot of resources for this topic to help readers expand beyond the scope of this book.