Upload
christina-sparks
View
231
Download
4
Tags:
Embed Size (px)
Citation preview
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
242-515 AGD: 5. Game Arch.
2
1. Simple Game Architecture2. More Detailed Game Architecture3. Graphics/Rendering4. Game Programming
Overview
1. Simple Game Architecture
Rendering EngineGame Logic
AI
Audio
Game WorldData
Input
Network
3
• 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
242-515 AGD: 5. Game Arch.
5
2. More Detailed Game Architecture
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
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
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
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?
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)
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)
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)
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/
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
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
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
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
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:
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
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
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
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
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
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.