242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements,...
-
Upload
christina-sparks -
Category
Documents
-
view
229 -
download
4
Transcript of 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements,...
![Page 1: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/1.jpg)
242-515 AGD: 5. Game Arch.
1
• Objectiveo to discuss some of the main
game architecture elements, rendering, and the game loop
Animation and Games
Development242-515, Semester 1, 2014-2015
5. Game Architecture
![Page 2: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/2.jpg)
242-515 AGD: 5. Game Arch.
2
1. Simple Game Architecture2. More Detailed Game Architecture3. Graphics/Rendering4. Game Programming
Overview
![Page 3: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/3.jpg)
1. Simple Game Architecture
Rendering EngineGame Logic
AI
Audio
Game WorldData
Input
Network
3
![Page 4: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/4.jpg)
• I will focus on the graphics and maths techniques used inside the "Rendering Engine" box.
• These include:o basic 3D graphics theoryo 3D graphics programming with the JMonkeyEngine game
engineo 3D rendering algorithms underlying 3D game engineso shader programming (maybe)
4
![Page 5: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/5.jpg)
242-515 AGD: 5. Game Arch.
5
2. More Detailed Game Architecture
![Page 6: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/6.jpg)
242-515 AGD: 5. Game Arch.
6
• Elements used in most games:o startup and shutdowno file IO (loaders, writers, datafile parsers)o input controls (keyboard, mouse, touch)o window management
• minimize, maximize, full-screen, resolutiono maths (e.g. vectors, matrices)o data structures (e.g. linked lists)
• In JMonkeyEngine, many of these come from the standard Java libraries
2.1. Core Systems
![Page 7: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/7.jpg)
242-515 AGD: 5. Game Arch.
7
• These can be separated into game media (stuff visible to the player) and data resources (data used internally by the game).
2.2. Resources (Assets)
• Data Resources:o user settings
• player items• high score table
o game settings• fonts• physics map
o platform settings• graphics and audio
capabilities
• Media Resources:o images / textureso audioo videoo shaderso 3D models
![Page 8: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/8.jpg)
242-515 AGD: 5. Game Arch.
8
• The game engine will often reuse existing libraries:o GUI (in JMonkeyEngine (JME): Nifty GUI)o Physics (in JME: jBullet, a Java port of the Bullet Physics
library)o skeletons (in JME: support for Blender joints)o AIo visual effects( in JME: OpenGL shaders, particle system)o terrain (in JME: the Ogre3D dotScene format)
o scene graph (so important, that it's a part of the core in JME)
2.3. Third-Party Libraries
![Page 9: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/9.jpg)
242-515 AGD: 5. Game Arch.
9
• A scene graph stores all the entities or objects in the scene, and the spatial relationship between them.
2.4. What is a Scene Graph?
![Page 10: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/10.jpg)
242-515 AGD: 5. Game Arch.
10
• The scene graph data structure simplifies the creation of a scene by the user, and also:o makes it easier to transform groups of objects
• e.g. translate, rotate them
o makes it easier to determine when objects are colliding and are visible to each other
o makes it easier to display a scene with different Levels of Detail (LOD)
![Page 11: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/11.jpg)
242-515 AGD: 5. Game Arch.
11
• Particleso smoke, fire, explosions, etc.
• Post processing / filter effectso reflective water, light scattering, fogo shadow mappingo High Dynamic Range (HDR) rendering
• increased contrast for greater detailo ambient occlusion (blocking)o depth of field bluro etc.
2.5. Visual Effects (in JME)
![Page 12: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/12.jpg)
242-515 AGD: 5. Game Arch.
12
• Java binding to the Bullet physics libraryo a collision detection and rigid body dynamics library
• http://bulletphysics.org/wordpress/
• Features include:o collisions, gravity, forceso mesh-accurate collision shapeso rigid body dynamics for vehicles and characters o physical joints and hingeso Blender integrationo Ragdoll physicso Multi-threaded physics
2.6. Physics (in JME)
![Page 13: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/13.jpg)
3. Graphics/Rendering
• Almost every game engine utilizes either OpenGL or DirectX for its graphics processing and rendering.
• JMonkeyEngine uses OpenGL.
http://msdn.microsoft.com/en-US/directxhttp://www.opengl.org/
![Page 14: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/14.jpg)
3.1. OpenGL• A hardware-independent API, implemented on
many different platforms.
• Several hundred functions, with many language bindings.
• An accepted industry standard:• evolves slowly• currently at version 4.2
• Widely used for:• games, modeling, scientific visualization, etc.
14
![Page 15: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/15.jpg)
3.2. DirectX• DirectX is a Microsoft API providing direct access
to hardware.• Only for Windows, currently at version 11.1• DirectX components:
o Direct Graphics – 2D and 3D graphicso DirectInput – interface to input deviceso DirectAudio – play sound and musico DirectPlay – communication across networkso DirectShow – multimedia support
15
![Page 16: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/16.jpg)
3.3. OpenGL vs. DirectX
• OpenGL is aimed at 3D graphics only; DirectX is a more complete game development API.
• OpenGL is portable across platforms; DirectX is only for Windows.
16
![Page 17: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/17.jpg)
3.4. What is Rendering?
• Rendering is the process of converting a 3D scene into a 2D picture (raster image) on the computer screen: o The 3D scene is composed of 3D models (geometries).o A model is composed of 3D graphics primitiveso e.g. triangles, quadrilaterals
17
render
![Page 18: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/18.jpg)
242-515 AGD: 5. Game Arch.
18
4. Game Programming• Most games consist of an startup phase,
a game loop, and a shutdown phase:
• A game loop consists of three stages:
![Page 19: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/19.jpg)
4.1. A Detailed Game Flowchart
Read player input
Update game state,using:Collision Detection,Game AI, Physics,
etc
Shutdown: store scores close files game over?
Initialization: Load assets Load levels …
Start
Display Startup GUI
Render (draw)game frameEnd
![Page 20: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/20.jpg)
242-515 AGD: 5. Game Arch.
20
• An important element missing from the basic game loop is the need to keep the rate of frame drawing constant.
• A frame rate is the average number of frames drawn by the game loop each second.
• Typical frame rates:o 30 fps (i.e. 30 frames drawn in 1 second)o 50 fps
• The frame rate should stay constant so that the user sees the game updating at a fixed rate.
4.2. Frame Rates
![Page 21: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/21.jpg)
242-515 AGD: 5. Game Arch.
21
• The frame rate should be the same on fast and slow computers.
• The problem is that a fast machine will carry out "updating" and "rendering" faster than a slow machine, and so the frame rate will be faster.
• We must change the game loop so that the frame rate isn't affected by a computer's speed.
4.3. Frame Rate Problem
![Page 22: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/22.jpg)
242-515 AGD: 5. Game Arch.
22
• One way to fix this speed problem is to add a "wait" stage in the loop:
delays the loopso the frame rateis not too fast
UpdateStartup Input
RenderWait
Shutdown
stoprun
game loop
![Page 23: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/23.jpg)
242-515 AGD: 5. Game Arch.
23
• Waiting deals with a loop that is too fast, but what about a loop that is too slow?o e.g. because the computer is slow
• One solution is to skip the rendering (drawing) stage, making the loop faster:
UpdateStartup Input
RenderWait
Shutdown
stoprun
game loop
Do we haveextra time?
yes
no
![Page 24: 242-515 AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649d935503460f94a7a0ac/html5/thumbnails/24.jpg)
242-515 AGD: 5. Game Arch.
24
• The good news is that JMonkeyEngine deals with maintaining a constant frame rate.
• We only have to write the "update" code for the loop, not the "rendering" or timing parts, which are dealt with by the engine.