Presentation is loading. Please wait.

Presentation is loading. Please wait.

09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Course intro Project management –Group size limit increased to 5 –Lecture notes had.

Similar presentations


Presentation on theme: "09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Course intro Project management –Group size limit increased to 5 –Lecture notes had."— Presentation transcript:

1 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Course intro Project management –Group size limit increased to 5 –Lecture notes had wrong deadline for Stage 1 Goals – now Sept 15 A useful tool was left off the list: CVS –“Concurrent Version Management” –You should be using it, or something similar, to manage your code among several users –See the CSL documentation for details on using it –Similar products exist in the real world, and are an essential part of game development

2 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Today Designing interactive software

3 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Interactive Programs Games are interactive programs Moreover, they are typically immersive in some way What are the important features of an interactive program? Which features are particularly important for immersive software like games?

4 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Important Features User controls the action –Control is “direct” and “immediate” Program provides constant feedback about its state –The user must know and understand what is happening –The user must receive acknowledgment that their input was received

5 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Immersive Software Software engages the attention of the user Response is really immediate Software provides a consistent alternate reality –The program should do reasonable things, for some definition of reasonable (game designer defines reasonable)

6 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Interactive Program Structure Event driven programming –Everything happens in response to an event Events come from two sources: –The user –The system Events are also called messages –An event causes a message to be sent… Initialize User Does Something And/or System does Something System Updates

7 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin User Events The OS manages user input –Interrupts at the hardware level … –Get converted into events in queues at the windowing level … –Are made available to your program It is generally up to the application to make use of the event stream User interface toolkits have a variety of methods for managing events There are two ways to get events: You can ask, or you can be told. What are the computer science terms?

8 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Polling for Events Most windowing systems provide a non-blocking event query –Does not wait for an event, returns immediately if no events are ready –In FLTK, it’s wait(0) What type of games might use this structure? Why wouldn’t you always use it? while ( not done ) if ( e = checkEvent() ) process event … draw frame

9 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Waiting for Events Most windowing systems provide a blocking event function –Waits (blocks) until an event is available On what systems is this better than the previous method? What types of games is it most useful for? while ( not done ) e = nextEvent(); process event … draw frame

10 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Background Work Stuff often must happen even if the user isn’t doing anything –What stuff? Why is this a problem with the “wait” technique? How is it solved? –2 answers

11 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin System Events Windowing systems provide timer events –The application requests an event at a future time –The system will provide an event sometime around the requested time. Semantics vary: Guaranteed to come before the requested time As soon as possible after Almost never right on (real-time OS?) Application is not interrupted - it has to look for the event –Exception: alarm signals in UNIX ( setitimer )

12 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Work Procedures A function to be called if no event is available The blocking event query checks for an event; if none found, call this procedure Typically hard to use – they must do bounded computation and there’s no guarantee they will ever be called

13 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin The Callback Abstraction A common event abstraction is the callback mechanism Applications register functions they wish to have called in response to particular events –Translation table says which callbacks go with which events Generally found in GUI (graphical user interface) toolkits –“When the button is pressed, invoke the callback” –Many systems mix methods, or have a catch-all callback for unclaimed events (FLTK works this way) Why are callbacks good? Why are they bad?

14 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Upon Receiving an Event … Event responses fall into two classes: –Task events: The event sparks a specific task or results in some change of state within the current mode eg Load, Save, Pick up a weapon, turn on the lights, … Call a function to do the job –Mode switches: The event causes the game to shift to some other mode of operation eg Start game, quit, go to menu, … Switch event loops, or change callbacks, because events now have different meanings Software structure reflects this - menu system is separate from run-time game system, for example

15 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Real-Time Loop At the core of games with animation is a real-time loop: What else might you need to do? The number of times this loop executes per second is the frame rate –# frames per second (fps) while ( true ) process events update animation render

16 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Lag Lag is the time between when a user does something and when they see the result - also called latency –Too much lag and causality is distorted –With tight visual/motion coupling, too much lag makes people motion sick –Too much lag makes it hard to target objects (and track them, and do all sorts of other perceptual tasks) High variance in lag also makes interaction difficult –Users can adjust to constant lag, but not variable lag From a psychological perspective, lag is the important variable

17 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Computing Lag Lag is NOT the time it takes to compute 1 frame! What is the formula for maximum lag as a function of frame rate, fr? What is the formula for average lag? Process input Update state Render Process input Update state Render Process input Frame time Lag Event time

18 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Frame Rate Questions What is an acceptable frame rate for twitch games? Why? What is the maximum useful frame rate? Why? What is the frame rate for NTSC television? What is the minimum frame rate required for a sense of presence? How do we know? How can we manipulate the frame rate?

19 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Frame Rate Answers (I) Twitch games demand at least 30fs, but the higher the better (lower lag) –Users see enemy’s motions sooner –Higher frame rates make targeting easier The maximum useful frame rate is the monitor refresh rate –Time taken for the monitor to draw one screen –But wait, there’s more…

20 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Frame Rate Restrictions There are synchronization issues (RTR, Sect 2.1) –Buffer swap in graphics hardware is timed with vertical sweep, so ideal frame rate is monitor refresh rate –Can turn of synchronization, but get tearing artifacts on screen Top half of screen is one image, bottom half is another Synchronization limits available frame rates –Say your monitor refreshes at 60Hz –Available frame rates are 60, 30, 20, 15, 12, 10, … Operating system clock limits timer resolution –Linux OS clock is 100Hz, Windows 2000 clock is 1000Hz (defined in CLK_TCK )

21 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Frame Rate Answers (II) NTSC television draws all the odd lines of the screen, then all the even ones (interlace format) –Full screen takes 1/30th of a second –Use 60fps to improve visuals, but only half of each frame actually gets drawn by the screen –Do consoles only render 1/2 screen each time? It was once argued that 10fps was required for a sense of presence (being there) –Head mounted displays require 20fps or higher to avoid illness –Many factors influence the sense of presence –Perceptual studies indicate what frame rates are acceptable

22 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin NTSC vs. PAL Two major differences: –Vertical resolution: 625 vs. 525 (not all useable) –Frame rate: 50 Hz vs. 60 Hz (approx) Issues: –Artwork appearance, particularly for menus and other 2D art –Animation timing: Detach animation clock from frame rate clock, which is good practice anyway

23 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Reducing Lag Faster algorithms and hardware is the obvious answer Designers choose a frame rate and put as much into the game as they can without going below the threshold –Part of design documents presented to the publisher –Threshold assumes fastest hardware and all game features turned on –Options given to players to reduce game features and improve their frame rate There’s a resource budget: How much time is dedicated to each aspect of the game (graphics, AI, sound, …) Some other techniques allow for more features and less lag

24 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Decoupling Computation It is most important to minimize lag between the user actions and their direct consequences –So the input/rendering loop must have low latency Lag between actions and other consequences may be less severe –Time between input and the reaction of enemy can be greater –Time to switch animations can be greater Technique: Update different parts of the game at different rates, which requires decoupling them –For example, run graphics at 60fps, AI at 10fps –Very common in real games

25 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Animation and Sound Animation and sound need not be changed at high frequency, but they must be updated at high frequency –For example, switching from walk to run can happen at low frequency, but joint angles for walking must be updated at every frame Solution is to package multiple frames of animation and submit them all at once to the renderer –Good idea anyway, makes animation independent of frame rate Sound is offloaded to the sound card

26 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Texture Mapping The problem: Colors, normals, etc. are only specified at vertices. How do we add detail between vertices? Solution: Specify the details in an image (the texture) and specify how to apply the image to the geometry (the map) Works for shading parameters other than color, as we shall see –The basic underlying idea is the mapping

27 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Basic Mapping The texture lives in a 2D space –Parameterize points in the texture with 2 coordinates: (s,t) –These are just what we would call (x,y) if we were talking about an image, but we wish to avoid confusion with the world (x,y,z) Define the mapping from (x,y,z) in world space to (s,t) in texture space With polygons: –Specify (s,t) coordinates at vertices –Interpolate (s,t) for other points based on given vertices

28 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Basic Mapping

29 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin I assume you recall… Texture sampling (aliasing) is a big problem –Mipmaps and other filtering techniques are the solution The texture value for points that map outside the texture image can be generated in various ways –Repeat, Clamp, … Texture coordinates are specified at vertices and interpolated across triangles Width and height of texture images is constrained (powers of two, sometimes must be square)

30 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Textures in Games The game engine provides some amount of texture support Artists are supplied with tools to exploit this support –They design the texture images –They specify how to apply the image to the object Commonly, textures are supplied at varying resolutions to support different hardware performance –Note that the texture mapping code does not need to be changed - just load different sized maps at run time Textures are, without doubt, the most important part of a game’s look

31 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Example Texture Tool

32 09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Todo By Monday, Sept 7: Formulate groups, on the whiteboard in room 1346 By Monday, Sept 7: Read booklet on group work –http://www-honors.ucdavis.edu/vohs/index.htmlhttp://www-honors.ucdavis.edu/vohs/index.html By Monday, Sept 15: Goals for stage 1 By Monday, Sept 22: Lock in Stage 1


Download ppt "09/04/03CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time Course intro Project management –Group size limit increased to 5 –Lecture notes had."

Similar presentations


Ads by Google