Jump to content

Game engine: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m →‎Implementation: Rephrased graphics library argument
m →‎Implementation: Fixed grammer, made graphics libraries singular
Line 13: Line 13:
The line between a game and its engine is often blurry, Jason Gregory in his book Game engine architecture argues game engines are [[Data-driven_programming|data-driven]], while software with hard-coded logic, or specialized code for each game object may still be a game, but is not a game engine.<ref>{{cite book|last1=Gregory|first1=Jason|title=Game engine architecture|date=2014|isbn=9781466560017|page=11|edition=2.|location=What is an Engine|url=http://www.gameenginebook.com/}}</ref> [[Video game developers]] will create [[data (computing)|data]], often called assets or media, the [[build system]] will invoke the game engine's Asset Conditioning Pipeline, compile an [[executable]], and bundle the massaged assets together to create a [[computer application]].<ref>{{cite web|last1=Dongen|first1=Joost van|title=The Game Asset Pipeline|url=http://www.proun-game.com/Oogst3D/ARTICLES/TheGameAssetPipeline.pdf|website=Proun Game|accessdate=22 September 2015}}</ref> The types of data can often be categorized as [[Computer_graphics|graphics]], [[Sound_recording_and_reproduction|audio]], [[Level (video gaming)|world data]], and with the advent of scripting languages being incorporated into game engines, even [[Source_code|game logic]] can be data.
The line between a game and its engine is often blurry, Jason Gregory in his book Game engine architecture argues game engines are [[Data-driven_programming|data-driven]], while software with hard-coded logic, or specialized code for each game object may still be a game, but is not a game engine.<ref>{{cite book|last1=Gregory|first1=Jason|title=Game engine architecture|date=2014|isbn=9781466560017|page=11|edition=2.|location=What is an Engine|url=http://www.gameenginebook.com/}}</ref> [[Video game developers]] will create [[data (computing)|data]], often called assets or media, the [[build system]] will invoke the game engine's Asset Conditioning Pipeline, compile an [[executable]], and bundle the massaged assets together to create a [[computer application]].<ref>{{cite web|last1=Dongen|first1=Joost van|title=The Game Asset Pipeline|url=http://www.proun-game.com/Oogst3D/ARTICLES/TheGameAssetPipeline.pdf|website=Proun Game|accessdate=22 September 2015}}</ref> The types of data can often be categorized as [[Computer_graphics|graphics]], [[Sound_recording_and_reproduction|audio]], [[Level (video gaming)|world data]], and with the advent of scripting languages being incorporated into game engines, even [[Source_code|game logic]] can be data.


Game engines consist of many [[Software_component|components]], called [[Library_(computing)|libraries]]. A library is suite of versatile functions and/or classes. Some of these libraries have vendor specific implementations, for example, on the UNIX-like and Windows-family of operating systems the hardware accelerated [[Graphics library|graphics libraries]] must be linked into the application as a [[Library (computing)|shared library]]. Some game engines allow these [[Library_(computing)|libraries]] to be swapped out, these are called modular engines.<ref>{{cite web|last1=Aaron|first1=Boudreaux|title=Modular Game Engine Design|url=http://www.irma-international.org/viewtitle/66327/|website=irma-international.org|publisher=University of Louisiana at Lafayette, USA|accessdate=22 September 2015}}</ref>
Game engines consist of many [[Software_component|components]], called [[Library_(computing)|libraries]]. A library is suite of versatile functions and/or classes. Some of these libraries have vendor specific implementations, for example, on the UNIX-like and Windows-family of operating systems the hardware accelerated [[ library]] must be linked into the application as a [[Library (computing)|shared library]]. Some game engines allow these [[Library_(computing)|libraries]] to be swapped out, these are called modular engines.<ref>{{cite web|last1=Aaron|first1=Boudreaux|title=Modular Game Engine Design|url=http://www.irma-international.org/viewtitle/66327/|website=irma-international.org|publisher=University of Louisiana at Lafayette, USA|accessdate=22 September 2015}}</ref>


Many modern game engine [[Software_framework|frameworks]], have easy to use API-s which allow a wide variety of [[software]] to be created.<ref>{{cite web|title=Unreal 4 Programming Guide|url=https://docs.unrealengine.com/latest/INT/Programming/index.html|website=docs.unrealengine.com|accessdate=22 September 2015}}</ref> Often game engines are specialized for the game in production.<ref>{{cite book|last1=Gregory|first1=Jason|title=Game engine architecture|date=2014|isbn=9781466560017|page=13|edition=2.|url=http://www.gameenginebook.com/}}</ref>
Many modern game engine [[Software_framework|frameworks]], have easy to use API-s which allow a wide variety of [[software]] to be created.<ref>{{cite web|title=Unreal 4 Programming Guide|url=https://docs.unrealengine.com/latest/INT/Programming/index.html|website=docs.unrealengine.com|accessdate=22 September 2015}}</ref> Often game engines are specialized for the game in production.<ref>{{cite book|last1=Gregory|first1=Jason|title=Game engine architecture|date=2014|isbn=9781466560017|page=13|edition=2.|url=http://www.gameenginebook.com/}}</ref>

Revision as of 01:27, 24 September 2015

Creating a racing game in Blender Game Engine.

A game engine is software which make up a video game.[1] There are many software frameworks available to aid in game development. A framework is software which has been partially constructed and can be completed by adding the missing functionality. Many frameworks are marketed as game engines, they make game development a lot easier, and have become synonymous with the term game engine. Some of the most sought after features are sound playback, scripting, artificial intelligence, networking, multi-threading libraries, localization tools, advanced computer graphics, collision detection and response system, and the ability to make games for multiple platforms, ideally enabling the possibility to develop and test the game on a PC and then quickly deploy it on a console, tablet or mobile phone.

History

The term game engine was popularized in the mid-90s with the advent of the Doom series of games by id Software. Doom had a reasonably clear distinction between assets and core simulation components, which made it easy to reuse the code and simply change the data (assets) to create sequels and brand new titles based on the same technology.[2]

As time went on, software components were designed to became more generalized and reusable across many games. Game studios, such as Epic Games and id Software, could create new titles cheaply, and licensing out the game engine became a viable second-stream of revenue.[3]

Today, there are companies that focus specifically on creating commercial game engines and game development tools, such as Unity Technologies.

Implementation

The line between a game and its engine is often blurry, Jason Gregory in his book Game engine architecture argues game engines are data-driven, while software with hard-coded logic, or specialized code for each game object may still be a game, but is not a game engine.[4] Video game developers will create data, often called assets or media, the build system will invoke the game engine's Asset Conditioning Pipeline, compile an executable, and bundle the massaged assets together to create a computer application.[5] The types of data can often be categorized as graphics, audio, world data, and with the advent of scripting languages being incorporated into game engines, even game logic can be data.

Game engines consist of many components, called libraries. A library is suite of versatile functions and/or classes. Some of these libraries have vendor specific implementations, for example, on the UNIX-like and Windows-family of operating systems the hardware accelerated graphics library must be linked into the application as a shared library. Some game engines allow these libraries to be swapped out, these are called modular engines.[6]

Many modern game engine frameworks, have easy to use API-s which allow a wide variety of software to be created.[7] Often game engines are specialized for the game in production.[8]

Agents

Most game engines are written in object oriented programming languages, and the entities in the game world are naturally objects. Very often, there is a base class all objects derive from, in Unreal this is the AActor class, in Unity3D, this is the GameObject class.

Composition and Aggregation

A big problem in object oriented programming is whether or not an object "has-a" object (composition), uses-a object (aggregation), or "is-a" object (inheritance).[9] Historically, class hierarchies have quickly gone out of hand, and inheritance can result in the Diamond of Death problem.

In modern engines, components are quickly becoming the norm, the trend has moved towards composition and aggregation.[10] In Unity3D, a GameObject is composed of objects called components which alter the behavior of GameObject.[11]

Main Game Loop

Game engines try to solve simulations which are constantly being changed by input from a user. A loop runs repeatedly, and during it, various subsystems are updated at differing rates. In games, this is called the main game loop.[12] Frameworks will implement the main game loop for the developers.

Fixed delta time

The simplest way is to step forward a fixed delta time, usually running the main game loop as often as the user's computer monitor refresh rate.[13]

The problem with this approach is that if a frame (delta time/timestep) consistently takes longer to generate than the fixed delta time, the simulation will appear to run in slow-motion.

The simulation will run too fast if a bug prevents it from waiting the reminder of the fixed delta time, after an update iteration.

These effects often become apparent when a user's computer hardware differs from the developer's hardware.

Variable delta time

The simplest solution to the problems found in a fixed timestep is to deploy a variable timestep. By measuring the time spent between the last frame and the current frame, one can move all the agents in increments multiplied by the delta time. This rewards video game enthusiasts with high frame-rates.

The problem with this approach is that certain game subsystems must be run at a fixed timestep, such as rigid body dynamics; agents not detecting collisions will result in a lack of collision response, which could result in inaccurate simulation.

The simplest solution is to find a timestep the simulation is stable under, and locking the simulation to that timestep.

Semi-fixed timestep

Another solution is to update rigid body dynamics and game logic relying on it at a fixed timestep, and the rest of the game as often of possible.[14][15]

Multithreaded Main Game Loop

Hardware manufacturers find it difficult to increase single-core performance, so they add multiple cores onto a CPU instead.[16] To take advantage of this, many games use different models to use all the cores on a system.

Some engines have utilities to make "jobs", sending specific code over to one of the cores and then reciving the data later, asynchroniously. [17]

Another common solution is to put every game engine subsystem on its own core. The results of one system could be fed into the next system, body dynamics data is fed into game logic which is fed to both graphics rendering and audio rendering. Other approaches are also possible, this solution often results in data lagging one frame behind inside a subsystem.[18]

Optimization

Game developers care greatly about getting the most out of their computer systems, optimization is a massive part of engine development. Computers have finite resources. Memory, processing power, storage devices and networking have intrinsic quirks which require optimization for peak performance.

You have been lied to all your life. RAM is not random access memory, it hasn't been for many years, CPU-s retrieve coalesced memory faster than randomly accessing memory.[19] Special care must be taken when processing data, a game engine will try to access data which is not far apart, as randomly accessing data is slow.[20] Ideally, the data should be retrieved in continuous chunks, it should be accessed by consistently reading upwards in memory, while additionally avoiding memory gaps.[21]

In C++, the memory allocation constructs new and delete are often overridden to track exactly how much memory has been spent and to reckon how much memory is left on the system.[22] There are a plethora of data structures used to manage memory.[23][24]

A common optimization for storage space is data compression, often all the data is compressed.[25] Some engines will store all the data into one package, other engines will have one package for each world. Creating a local filesystem in this way also solves data locality problems which speed up load times.[26][27][28]

When writing online games, there usually are two types of data to be sent, data which needs to arrive no matter what and data which is in constant flux. TCP/IP can be used for data which must arrive, such as player names and chat messages, and data which is changing, such as player positions, might be sent using the fast but lossy UDP protocol. However, having two sockets, TCP/IP and UDP; at once, is not recommended.[29]

Build System

The build system will take all the source code, libraries, and assets, compile them individually and link them together to create platform-specific data files and an executable.[30] Often, the build system will invoke a few tools to get the final touches done, such as the resource database, to find what data is being used in the game, the asset conditioning pipeline, to get the data compiled and linked together for the target platform, and the translation preprocessor, to get the correct languages included with the data.[31]

Continuous Integration systems are, in most serious development environments, used to automate builds, and revision control to manage a build's source code.[32][33][34] It is common to have builds for debug, release and production.[35][36] Various features will be switched on or off on the different builds, debug has debug symbols intact, release will run fast enough to run in real-time but with debugging and assertions still turned on, and production will be compiled with all possible optimization flags and have all debug tracing, asserts, debug menus, command-line-interface and debug graphics deactivated.[37]

Tools

Tools are used to create assets, to translate the game and to get assets into the game.

To create content (assets), Digital Content Creation tools are used.[38] These include 3D modelling software, graphics editors and audio editing and recording tools.

Resource Database

Tools are made to keep track of what content (assets) are used.[39] Some engines make quite complex resource databases making the tracking of the content visual, and enabling the ability to select resources in the game and adding them to levels through IDE-s, such as Unity3D's IDE and Unreal Engine 4's UnrealEd, at Naughty Dog they go for a much more minimalist approach to keep track of what assets are in use, they have MySQL database with a simple web front-end called Builder, which can invoke the Asset Conditioning Pipeline and manipulate two kinds of resource files, actors, which is Naughty Dog's jargon for agents, and level data.[40]

Asset Conditioning Pipeline

Game data, assets or media, often go through a similar pipeline as source core.[41]

Exporters

Special tools are often designed for the Digital Content Creation tools to export the data so that it can be processed by the application.

Resource compilers

A resource compiler is a tool which prepares, or massages, the assets for use in the application. This may include converting the assets, or invoking an exporter.

Resource linkers

Resource linkers package all the files together for use by the application.

Localization

Many games are localized.

UTF

To support characters for other languages than English, Unicode was invented. Most computer applications will use Unicode to represent text.[42]

Preprocessor tool

Often, all the text strings are processed by a preprocessor to create a file for translators to fill in, and during runtime the strings are looked up in a lookup table and swapped out with the correct Unicode characters for the user's language of choice.

Modules

Modular engines designed in an object oriented fashion, might use abstract classes to provide a standardized interface for each module. This enables modules to have many different implementations which a developer may choose from, or easily extend by adding new modules. Some modules only work on the hardware its designed for, so being able to swap them out can help make a game engine cross-platform.

Even non-modular engines take advantage of a vast array of libraries, often marketed as engines. They can be categorized as the following.

Audio renderer

Audio in games is complex and the module is often implemented similarly to the graphics rendering module, as sound moves a lot like light does, across the world.

Rigid body dynamics

Often called physics.

Filesystem

Often overlooked. Sometimes, the standard template library might be good enough, other times a cross-platform optimized filesystem module is designed for faster load times and data compression.

Graphics renderer

Graphics rendering is probably the most impressive part of game engines.

Animation

Animation is a complex topic which is still in its infancy.

Artificial Intelligence

Artificial intelligence in video games is weak AI. The goal is to make the computer fun to play with.

In competitive games, computer controlled agents in the game world will not play expertly. Instead an attempt is made to make them behave like human beings.

Scripting

Exposing the framework to scripting languages allow rapid prototyping.

See also

References

  1. ^ "Oxford Dictionary". Oxford Dictionary. Retrieved 22 September 2015.
  2. ^ Gregory, Jason (2014). Game engine architecture (2. ed.). p. 14. ISBN 9781466560017.
  3. ^ Gregory, Jason (2014). Game engine architecture (2. ed.). p. 11. ISBN 9781466560017.
  4. ^ Gregory, Jason (2014). Game engine architecture (2. ed.). What is an Engine. p. 11. ISBN 9781466560017.{{cite book}}: CS1 maint: location missing publisher (link)
  5. ^ Dongen, Joost van. "The Game Asset Pipeline" (PDF). Proun Game. Retrieved 22 September 2015.
  6. ^ Aaron, Boudreaux. "Modular Game Engine Design". irma-international.org. University of Louisiana at Lafayette, USA. Retrieved 22 September 2015.
  7. ^ "Unreal 4 Programming Guide". docs.unrealengine.com. Retrieved 22 September 2015.
  8. ^ Gregory, Jason (2014). Game engine architecture (2. ed.). p. 13. ISBN 9781466560017.
  9. ^ "Aggregation vs Composition". Stack Exchange. Retrieved 23 September 2015.
  10. ^ Gregory, Jason (2014). Game engine architecture (2. ed.). p. 103. ISBN 9781466560017.
  11. ^ "Game Architecture Best Practices". answers.unity3d.com. Retrieved 22 September 2015.
  12. ^ Nystrom, Bob. "Game Programming Patterns - Game Loop". Retrieved 22 September 2015.
  13. ^ "Fix Your Timestep". Gafferon Games. Retrieved 22 September 2015.
  14. ^ "Unity3D - Fixed Update". Retrieved 22 September 2015.
  15. ^ "Update and Fixed Update". Retrieved 22 September 2015.
  16. ^ "The Manycore Shift White Paper". Retrieved 22 September 2015.
  17. ^ "Parallelizing the Naughty Dog Engine". Retrieved 22 September 2015.
  18. ^ Gregory, Jason. "Multiprocessor Game Loops". Game Engine Architecture (PDF).
  19. ^ "Pitfalls of Object Oriented Programming" (PDF). harmful.cat-v.org. Retrieved 22 September 2015.
  20. ^ Nystrom, Bob. "Update Method". Retrieved 22 September 2015.
  21. ^ Nystrom, Bob. "Data Locality". Retrieved 23 September 2015.
  22. ^ Gyrling, Christian. "Are we out of memory?". Retrieved 22 September 2015.
  23. ^ Nystrom, Bob. "Optimization Patterns". Retrieved 22 September 2015.
  24. ^ Gregory, Jason. "Memory Management". Game Engine Architecture (2. ed.). p. 239.
  25. ^ McShaffry, Mike (2012). Game Coding Complete (4. ed.). p. 195. ISBN 1133776574.
  26. ^ McShaffry, Mike (2012). Game Coding Complete (4. ed.). Packaging Resources into a Single File. p. 211. ISBN 1133776574.{{cite book}}: CS1 maint: location missing publisher (link)
  27. ^ McShaffry, Mike (2012). Game Coding Complete (4. ed.). Resource File and Directory Organization. p. 320. ISBN 1133776574.{{cite book}}: CS1 maint: location missing publisher (link)
  28. ^ McShaffry, Mike (2012). Game Coding Complete (4. ed.). Other Benefits of Packaging Resources. p. 211. ISBN 1133776574.{{cite book}}: CS1 maint: location missing publisher (link)
  29. ^ "Networking for Game Programmers".
  30. ^ Gregory, Jason. "Build Configurations". Game Engine Architecture (2. ed.). p. 76.
  31. ^ McShaffry, Mike (2012). Game Coding Complete (4. ed.). p. 118. ISBN 1133776574.
  32. ^ McShaffry, Mike (2012). "Automate Your Builds". Game Coding Complete (4. ed.). p. 118. ISBN 1133776574.
  33. ^ "Making Developers More Productive Dolphin Development Infrastructure". Retrieved 22 September 2015.
  34. ^ McShaffry, Mike (2012). Game Coding Complete (4. ed.). Source Code Repositories and Version Control. p. 120. ISBN 1133776574.{{cite book}}: CS1 maint: location missing publisher (link)
  35. ^ McShaffry, Mike (2012). Game Coding Complete (4. ed.). Build Configurations. p. 99. ISBN 1133776574.{{cite book}}: CS1 maint: location missing publisher (link)
  36. ^ Gregory, Jason. "Typical Build Configurations". Game Engine Architecture (2. ed.). p. 78.
  37. ^ McShaffry, Mike (2012). Game Coding Complete (4. ed.). Assertions. p. 149. ISBN 1133776574.{{cite book}}: CS1 maint: location missing publisher (link)
  38. ^ Dongen, Joost van. "The Game Asset Pipeline" (PDF). p. 3.
  39. ^ Gregory, Jason (2014). Game engine architecture (2. ed.). p. 69. ISBN 9781466560017.
  40. ^ Gregory, Jason (2014). "Some Successful Resource Database Designs". Game engine architecture (2. ed.). p. 312. ISBN 9781466560017.
  41. ^ "Book Excerpt: The Game Asset Pipeline : Managing Asset Processing". www.gamasutra.com. Retrieved 2015-09-22.
  42. ^ Spolsky, Joel. "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)". Retrieved 22 September 2015.