Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 17 Creating an Interactive 3D Environment © 2008 Cengage Learning EMEA.

Similar presentations


Presentation on theme: "CHAPTER 17 Creating an Interactive 3D Environment © 2008 Cengage Learning EMEA."— Presentation transcript:

1 CHAPTER 17 Creating an Interactive 3D Environment © 2008 Cengage Learning EMEA

2 LEARNING OBJECTIVES In this chapter you will learn about: – –Game engine architecture – –Game initialization and shutdown – –The game loop – –Creating an interactive DirectX 10 3D environment – –Creating an interactive OpenGL 3D environment

3 GAME ENGINE ARCHITECTURE A game engine is the central unit of any computer game and it can be described as a collection of technologies such as a sound engine, AI subsystem, physics engine, networking subsystem, 3D renderer, and input control system. The number of subsystems provided is highly dependent on the developer’s requirements and the implementation platform of choice.

4 GAME ENGINE ARCHITECTURE Game engines, built upon various APIs such as DirectX and OpenGL, are normally designed with software componentry in mind. – –This allows for decomposition of the engine, resulting in numerous functional units. By designing component-based engines, we are able to replace provided technologies with other third-party or in-house developed units as needed. – –For example, a game engine’s renderer, physics engine or sound system can easily be replaced by an improved or alternate version in a plug-and-play fashion.

5 GAME ENGINE ARCHITECTURE The term ‘game engine’ existed for some time, but only became truly common in the mid-1990s when developers started licensing the core code of other games for their own titles. This reuse led to the development of high-end commercial game engines and middleware providing game developers with a number of game creation tools and technical components – i.e. accelerating the game development process.

6 GAME ENGINE ARCHITECTURE We can divide the source code of a game into two units, namely, the game-engine code and the game-specific code. – –The game-specific code deals exclusively with in-game play elements, for instance, the behaviour of non- player characters, mission-based events and logic, and the main menu. – –Game-specific code is not intended for future reuse and thus excluded from the game engine code. – –Game-engine code forms the core of the entire game implementation with the game-specific code being executed on top of it. – –The game engine is separate from the game being developed in the sense that it provides all the technological components without any hard coded information about the actual gameplay.

7 GAME ENGINE ARCHITECTURE Game-engine code and game-specific code can be designed and integrated using one of the following architectures: ad-hoc, modular, or the directed acyclic graph architecture (DAG).

8 GAME ENGINE ARCHITECTURE Once we have chosen the preferred overall architecture, we have to summarize all possible states our game will go through from initialization to shutdown. Possible states (with associated events) are listed here: – –Initialization. – –Enter the main game loop:   Additional initialization and memory allocation.   Load intro video.   Initialize and display in-game menu: – –Event monitoring. – –Process user input.   Start game.   In-game loop: – –Input monitoring. – –Execution of artificial intelligence (AI) – –Execution of physics routines. – –Sound and music output. – –Execution of game logic. – –Rendering of the scene based on the input from the user and other subsystems. – –Display synchronization. – –Update game state.   Exit the game and return to the in-game menu. – –Shutdown of the game if the user wishes to terminate the program.

9 Initialization and Shutdown The first step invoked whenever a game is executed, is initialization. This step deals with resource and device acquisition, memory allocation, initialization of the game’s GUI, and loading of art assets such as an intro video from file. The first initialization phase is commonly referred to as the ‘front-end initialization step’ to distinguish it from the level and actual game play initialization phases. – –Front-end initialization occurs prior to the game loop and is required for setting up the environment by assigning resources and loading game data and assets

10 Initialization and Shutdown void FrontEndInit() {AcquireResources();AllocMem();LoadAssets();InitGUI();LoadPlayerPreferences();} All devices and resources are released and final program cleanup is done during the exit state. The exit state has to release all resources and devices acquired, memory allocated and data loaded in the reverse order of the initial front-end acquisition.

11 Initialization and Shutdown void Cleanup() {SavePlayerPreferences();ShutdownGUI();ShutdownAssetAccess();FreeMem();ReleaseResources();}

12 The Game Loop The game loop allows uninterrupted execution of the game. It enables us to execute a series of tasks such as input monitoring, execution of artificial intelligence and physics routines, sound and music processing, execution of game logic, display synchronization and so forth for every frame rendered. All these tasks are processed on a per-frame basis, thus resulting in a living world where everything happens in a seemingly concurrent manner, especially so where the computer game runs at 40 frames per second or more.

13 The Game Loop Timing allows a game to execute at a speed independent of the frame rate or processor’s clock speed. Most games released today make use of variable frame timing. Another key element of any game is the processing of player input. Other tasks performed during the game loop include the execution of AI code so that NPCs can decide where to go next or what action to take, object updates, the execution of game code and scripts, the execution of physics code to ensure correct inter-object and object- entity interaction, updating the camera according to player input, animating objects and updating particle effects, etc.

14 The Game Loop while(!ExitGame()){UpdateTiming();InputHandling();UpdateNetworking();ExecuteScripts();UpdateAI();UpdatePhysics();UpdateSound();UpdateEntities();UpdateCamera();CollisionDetection();CollisionResponse();RenderFrame();UpdateGameState();}

15 The following code sample illustrates the possible structure of a decoupled game loop: while(!ExitGame()) { UpdateTiming(); InputHandling(); if(UpdateWorld()) { UpdateNetworking(); ExecuteScripts(); UpdateAI(); UpdatePhysics(); UpdateSound(); UpdateEntities(); UpdateCamera(); CollisionDetection(); CollisionResponse();] } InterpolateObjectStates(); RenderFrame(); UpdateGameState(); }

16 CREATING AN INTERACTIVE DIRECTX 10 3D ENVIRONMENT [see the textbook and book website for the source code example and detailed discussion].

17 CREATING AN INTERACTIVE OPENGL 3D ENVIRONMENT [see the textbook and book website for the source code example and detailed discussion].


Download ppt "CHAPTER 17 Creating an Interactive 3D Environment © 2008 Cengage Learning EMEA."

Similar presentations


Ads by Google