Introduction Main Elements
Total Page:16
File Type:pdf, Size:1020Kb
Game Engines Introduction Game Engines are software platforms used to create and run video games. One of the reasons that Game Engines exist is because creating computer games requires a lot of different kinds of complex software. Computer games include video elements, user interface elements, a variety of resources that must be loaded and used, and other complex systems. If each game developer had to create these various software systems for each game, the development time required to create a new game would be too long. One thing that most software developers do is save old code. If a developer can just plug in software elements that have been previously used and have been tested, then this makes the development cycle shorter. Why write the same code again when a developer can just plug-in already written code. This same idea is behind game engines. In the early days, game developers saved their old code and systems and just reused them on new games. At some point, the idea was to create modular systems that are more self-contained and easier to reused. This was one of the driving elements for Game Engines. The other reason for modern Game Engines was that games were being developed for multiple platforms. These include computers, consoles, hand-held devices, and the Internet. Game developers wanted to sell their games on multiple platforms so they added a game run-time element to game engines. The run-time element was a layer where the game hardware was virtualized. This means that when the game engine code sends a draw command to the hardware, the draw command first goes through a layer that translates it to the appropriate hardware commands. This hardware layer is called a Game Runtime. This means that Game Engine included a runtime element that runs on top of the hardware and through with the game code executes. Main Elements The main elements of modern Game Engines include: • Game Development Tools – this includes tools for assembling game elements in a graphical environment and game scripting tools • Game Internal Elements – this includes various elements used by game developers to draw graphics, simulate physics, use artificial intelligence elements, etc. These are blocks of code that can be attached to game elements. Some of these are third party Software Development Kits (SDK’s) that can be plugged into the Game Engine. • Game Runtime Element – this is the runtime code that support multiple hardware for the game. When the game is compiled a target platform is selected and the Game Engine adds the appropriate runtime layer to the game. The internal elements to a typical game engine are indicated in the following diagram. As you can see, Game Engines are complex and difficult to create. For this reason, many game companies either create and reuse their own game engines or purchase commercial game engines. Many commercial game engines, when used, include the underlying code in which the game engines was created so game developers can modify the parts of the engine they need for their own games. The rise of easy-to-use commercial and open source game engines is a boon for independent game developers. These developers can take advantage of the game engine to create playable and sometimes successful games. There are a lot of game engines (https://en.wikipedia.org/wiki/List_of_game_engines). Popular game engines include: Unity UnReal Engine GameMaker Godot CryEngine Marmalade SDK AppGameKit Cocos2d-x MonoGame Amazon Lumberyard ShiVa Engine HeroEngine Construct Common Features Many Game Engines have some common features. These include: • Graphics editor for game components • Representing game elements as Objects and Properties • Layout tools for Game Levels • Physics elements to simulate physical movement • Scripting elements The graphical editor allows the developer to edit various graphical features. While Game Engine graphical editors are not as full-featured as dedicated graphical software, they do include enough features to allow some level of graphical editing. Another important feature that most game engines share is how game elements are represented in the game development environment. Most game engines use the Object/Property model to represent game elements. This means that the developer can treat game elements in a simplified manner and use ideas such as inheritance to good effect. This object/property model also works with most game scripting languages since almost all modern programming and scripting languages use the Object/Property model to represent software components. Many game engines include some kind of layout tools for building sections of the game. This could include tools for arranging game objects and other game elements, create movement paths for objects, and other level design tools. Since most games include movable objects, one way to ensure that such objects move and react to the environment in a realistic manner is to include various physics elements. This consists of software modules that simulate realistic movement of objects such as gravity, momentum, force, and other physical forces. Since these can be simulated by standard calculations, building in a physics component simplified the game development. Few Game Engines include a purely graphical development environment. This means that, at some point, the developer will have to use a programming or scripting language to control the game. Most Game Engines have their own built-in scripting language (often based on a mainstream language such as C/C++, Java, Python, etc). The Game Engine will used the developer created scripts to build the game code along with the various graphic, physics, resources, etc. Basic Game Programming Concepts There are some basic concepts that game developers should be familiar with when developing games. These include: 1. The Game Loop 2. Event structures and callback Methods 3. Sprites and 3D Objects 4. The Game Coordinate System 5. Vectors 6. Game Cameras Game Loop The Game Loop refers to how the game software runs when the game is running. Basically, game software is written to run in a loop. Inside this loop the game software performs a number of things, such as displaying graphics on the screen. Games display animated objects by drawing and redrawing images on the screen. Each time through the game loop the screen is redrawn, which gives the impression of 2D and 3D objects moving across the screen. The speed of the game loop is typically measured in Frames Per Second (FPS) which is how fast the screen is redrawn. Many games now include FPS rates of 60 or above, which means that the game loop is running at 60 times a second. Inside the game loop the game software displays graphics on the screen as well as performing other tasks. For most games, the Game Loop includes: 1. Get Input from player and evaluate game state 2. Update game state 3. Redraw the screen 4. Go back to step 1 If the game is running at 60 FPS then these steps are done 60 times a second. Notice that there is more than just redrawing the screen that is happing in the game loop. This includes: • Getting input from the player such as from the keyboard, mouse, controller, etc. • Evaluating the current state of the game. This would include tracking game elements, positions, sound, etc. • Updating the game state. This would include adding or removing game objects, moving game objects, playing sounds and videos, etc. To use a simple example, suppose your game has a graphical object displayed on the screen. When the player presses the left arrow key the game should move the object to the left a certain number of pixels. When the player stops pressing the left arrow key the game should stop moving the graphical object. The game loop performing this action might look like: 1. Read the keyboard and get the current position of the object. 2. If the keyboard is the left arrow key then set the position of the object some number of pixels to the left. 3. Redraw the object using its current position on the screen. 4. Go back to 1 There are a number of things happening inside the game loop, not only moving graphical objects. These could include things like, for example, adding 100 pieces of gold if your character sells equipment, sets a new quest based on a dialog with a non-player character, changing the game camera so the player can look in a new direction. All of these will be happening inside the game loop (but not necessarily 60 times a second). Non-game programmers sometimes have a hard time dealing with the game loop environment. Regular programmers deal with a single process through the code and they typically don’t have to consider running their code inside a loop. The regular code progress is under the control of the programmer. With game programming the game operation and progress is under the control of the game loop. For example, if code is designed to call a method it will be called 60 times a second inside the game loop. Because game code is running inside a game loop, calling methods inside the loop is not reliable. For this reason, many Game Engines use an Event-based Callback system to link the game code to what happens inside the loop. With a regular non-game program the code for checking a condition and performing an action would look like: A. Check condition R B. If R is true then do X C. Else continue with the program Inside a game loop this does not work as well. The checking for a condition and the performance of X is taking place 60 times a second. This is why gaming code normally uses and Event/Callback system.