CO1301 Games Concepts Week 24 Efficiency, Numbers - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

CO1301 Games Concepts Week 24 Efficiency, Numbers

Description:

3.2: C , Java, and Scripting Languages, Noel Llopis. 3.4: Programming Fundamentals, Noel Llopis ... Alternative degrees: Multimedia, Games Design. ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 33
Provided by: gjbel
Category:

less

Transcript and Presenter's Notes

Title: CO1301 Games Concepts Week 24 Efficiency, Numbers


1
CO1301 - Games ConceptsWeek 24Efficiency,
NumbersPreparation for next year
  • Gareth Bellaby

2
  • Efficiency

3
Efficiency
  • Last week I talked about the need for efficiency.
    The time available to perform operations within a
    computer game is small (0.017 to 0.033 seconds
    per frame) and so efficiency is a dominant
    concern within games programming.
  • If you have 10,000 trees. You need to perform
    collision detection for all of the trees. That's
    a lot of processing.

4
Tree collision
  • Collision is currently being implemented as
  • What could be done in order to reduce the
    computational cost?

5
Improving efficiency
  • Firstly, can the collision detection be made more
    efficient?
  • Examine the calculation. Collision detection
    depends upon a distance check. The most expensive
    element of the calculation is the square root.
    But it can be dispensed with

6
Improving efficiency
  • Rewrite the check so that the square is no longer
    used.
  • Square both sides of the equation.
  • Perform the check against the square of the tree
    radius.

7
Improving efficiency
  • The square of the radius can be pre-calculated so
    it costs nothing.
  • A simple rewriting of the calculation has
    improved matters.
  • The use of squares is common within graphics,
    e.g. for distance tests.

8
Efficiency
  • Could anything else be done to improve
    efficiency?
  • Does the program have to check all of the trees?
  • Most of the trees are so far away that we can
    ignore them. It is possible to devise a method so
    that only likely candidates are checked.

9
Partitioning the world
  • Grid out the world.
  • Record the trees according to which grid they are
    in.
  • Only check those trees which are in the same grid
    as the player.
  • 10 by 10 grid.
  • Each grid has 100 trees within it.

10
Partitioning the world
  • This example will use clear coordinates and
    scaling, but note that the principle holds true
    for all contexts. Each cell of the grid willl be
    100 units by 100 units.
  • Need an efficient way to derive the current grid
    of the player. Remember that integer devision
    within C produces an integer result and that
    the result is always rounded down. Divide the
    player coordinates (x and z) by 100. The result
    is the grid reference.

11
Deriviving the grid cell
  • player location ( 40, 30 )
  • gt ( 40/100, 30/100 )
  • gt ( 0, 0 )
  • player location ( 140, 130 )
  • gt ( 140/100, 130/100 )
  • gt ( 1, 1 )
  • player location ( 450, 70 )
  • gt ( 450/100, 70/100 )
  • gt ( 4, 0 )

12
Spatial Partitioning
  • In programming terms you could create a 2D array
    which corresponds exactly to the grid
    coordinates. Each cell could then have the
    locations of its own trees stored.
  • This is an simple example of a technique called
    "spatial partitioning", i.e. partitioning or
    sub-dividing space into chunks. Spatial
    partitioning is used extensively within computer
    games, e.g. in a game level so that only nearby
    models or visible models are rendered.

13
Spatial Partitioning
  • For example, it is possible to extend the grid
    approach to include a check to see whether the
    trees get rendered.
  • There's a nice version of this later on in Frank
    Luna, Introduction to DirectX, in Chapter 18 when
    he uses a grid to filter out geometry that is not
    in view of the camera.
  • More sophisticated techniques include Binary
    Space Partioning (BSP) trees and Oct-trees.

14
  • Numbers

15
Numbers
  • Mathematics distinguishes between several types
    of number
  • Whole numbers (or natural numbers)
  • 0,1,2, only positive numbers
  • Integers
  • 0,1,-1,2,-2,3,-3, ve or -ve whole numbers
  • Real numbers
  • 0.02, -3.455, 124.0, 0.33333, any number written
    with a decimal point (possibly infinitely long)
  • As well as others
  • A number (in any form) is called a scalar

.
16
Numbers in C
  • Equivalent types of number in C
  • int - integers (ve or ve)
  • unsigned int - whole numbers (ve only)
  • float - real numbers
  • Each type has finite storage
  • Exact amount depends on compiler
  • They have limitations not present in maths
  • Maximum and minimum values
  • e.g. typical int (4-bytes) has max/min of 2
    billion
  • So large values may be out of range for an int

17
Floating point concerns
  • Floating point numbers cannot all be accurately
    represented.
  • The float and double data types rarely hold
    exactly the numbers you assign or would expect
    them to.
  • Calculations can cause difference to magnify,
    i.e. error propagation.
  • Difference will be greater for larger values.
  • Never use , except for small integers.
  • Always assume a margin of error, e.g. test
    against a range
  • -epsilon lt x lt epsilon, where epsilon is a
    small number.
  • For example, the code on the following slide
    implements a test against zero.

18
Test against zero
  • // For 32-bit floats
  • const float kfEpsilon 0.5e-6f
  • bool IsZero( const float x )
  • return fabs( x ) lt kfEpsilon

19
Number conversion
  • C can automatically convert number types
  • But doesnt always 5 / 10 0, Correct 5.0 /
    10.0
  • The compiler usually issues a warning when it
    does perform a conversion
  • e.g. int i 9.0/10.0 // Warning likely (i 0)
  • Dont ignore warnings ensure it is what you
    want
  • float / double are rounded down to int
  • To round to the nearest int
  • int NearInt MyFloat 0.5f
  • N.B. 0.5 is a double, 0.5f is a float
  • In order to convert number types you use casting.
    The modern C casting style is
  • float f static_castltfloatgt(MyInteger)

20
  • Preparation for next year

21
Summer break
  • You are expected to work over the summer break.
  • I have prepared summer work for you. This work
    goes through various programming concepts using
    both the console window and the TL-Engine.
  • At the top of the Games Concepts module page.
  • "Summer2008.zip"
  • It will be updated over the summer so be prepared
    to check it again.

22
Programming
  • Ensure that you have a copy of Visual Studio
    (preferably Visual Studio 2005). DO NOT USE
    Visual Studio Express!
  • Ensure that you have the TL-Engine.
  • Ensure that you have the DirectX SDK.

23
Preparation
  • You do not have an exam for this module.
  • It is a fact that those people who do work over
    the summer period in preparation for the second
    year will do better.
  • You need to keep C and programming fresh in
    your mind.
  • The more preparation you do the better your
    learning experience.
  • You should be seeking to extend your
    understanding of games development.

24
Graphics
  • Prepare for the graphics module.
  • The graphics you are doing is
  • DirectX 9
  • Using the "programmable graphics pipeline", i.e.
    using shaders.
  • Programming the graphics card using vertex
    shaders and pixel shaders.
  • Work through Frank Luna, Introduction to 3D Game
    Programming with DirectX 9.0c A Shader Approach
  • Use Laurent's notes for CO2408 Computer Graphics.

25
You must buy
  • Rabin, Steve, (ed.), (2005), Game Development,
    Charles River Media. ISBN 1584503777
  • van Verth, James, (2004), Essential Mathematics
    For Games Interactive Applications A
    Programmer's Guide Book, Morgan Kaufmann. ISBN
    155860863X
  • Luna, Frank D., Introduction to 3D Game
    Programming with DirectX 9.0c A Shader Approach,
    Wordware Publishing Inc. ISBN-10 1598220160.
    ISBN-13 978-1598220162

26
Some other books
  • Be careful, there any many books which are out of
    date or irrelevant.
  • Brownlow, Martin, Game Programming Golden Rules
    (2004), Charles River Media, ISBN-10 1584503068,
    ISBN-13 978-1584503064.
  • Llopis, Noel, C for Game Programmers, (2003),
    (Charles River Media, ISBN-10 1584502274,
    ISBN-13 978-1584502272
  • Also have a look at the Game Programming Gems
    series. These can be found in the library.

27
Preparation
  • Steve Rabin, Introduction to Game Development.
  • It is a big book. Not all of the chapters are
    directly relevant to you as game developers. Some
    of the material we've already covered. You need
    to read the following chapters.

28
Preparation
  • 3.1 Teams and Processes, Noel Llopis
  • 3.2 C, Java, and Scripting Languages, Noel
    Llopis
  • 3.4 Programming Fundamentals, Noel Llopis
  • 3.5 Debugging Games, Steve Rabin
  • 3.6 Game Architecture, Noel Llopis
  • 3.7 Memory and I/O Systems, Noel Llopis
  • 4.1 Mathematical Concepts, Eric Lengyel
  • 4.2 Collision Detection and Resolution, Steve
    Rabin

29
Preparation
  • 5.1 Graphics, Tom Forsyth
  • 5.3 Artificial Intelligence Agents,
    Architecture, and Techniques, Steve Rabin
  • 5.4 Artificial Intelligence Pathfinding, Syrus
    Mesdaghi
  • 6.5 Surface Effects, David Johnson
  • 6.6 Lighting, Peter Lewis

30
Preparation
  • You do not need to read everything in detail.
  • Skip over sections that you find complicated on
    first reading.
  • The course will expand, enhance and clarify the
    material introduced in these chapters.
  • The scope of the book means that much material is
    dealt with quickly or only in a surface.
  • However, reading the sections I have indicated
    is excellent preparation for the second year.

31
Preparation
  • For example, 3.7 Memory and I/O Systems. There's
    a bunch of code on page 304. You are not expected
    to learn the code. You are not even expected
    particularly to understand it in depth (although
    you should by the end of the course). However,
    you should pick up the main points that
  • programs use memory
  • every line of code that uses memory management
    involves quite a few things happening
  • it may be a good idea for a game to build a
    memory manager

32
Advice
  • Jobs are available.
  • Industry recruits the best.
  • The course meets the requirements of industry.
  • The course is a good indication of your
    suitability as a programmer for the games
    industry.
  • If you have less than 50 in this final
    assignment I would strongly suggest moving onto
    another degree.
  • Alternative degrees Multimedia, Games Design.
Write a Comment
User Comments (0)
About PowerShow.com