Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game Design, Development, and Technology

Similar presentations


Presentation on theme: "Game Design, Development, and Technology"— Presentation transcript:

1 Game Design, Development, and Technology
CS 382 Game Design, Development, and Technology Programming Fundamentals Data Structures Bit Packing Objects-Oriented vs. Component-Based Part 3.3

2 Programming Fundamentals
Several standard data structures figure prominently in game programming… Vectors & Matrices Facilitate the implementation of linear algebra formulas in graphics and animation Dictionaries & Hash Tables Facilitate the implementation of massive look-up tables for audio and visual associations Stacks & Queues Manage the application of affine transformations (translations, rotations, scaling) and entity interactions (collisions, multiplayer commands, etc.) Part 3.3 Programming Fundamentals Page 88

3 Programming Fundamentals
Data Structure: Layered Isometric Grid One common game data structure is the map, which is based on an array of cells, each of which has an associated terrain type, structure type, and pointers to mobile game units (troops, creatures, etc.). Direction Adjacency Location North (x, y-1) Northeast (x, y-1) if y is even (x+1, y – 1) if y is odd East (x+1, y) Southeast (x, y+1) if y is even (x+1, y+1) if y is odd South (x, y+2) Southwest (x-1, y+1) if y is even (x, y+1) if y is odd West (x-1, y) Northwest (x-1, y-1) if y is even (x, y-1) if y is odd Part 3.3 Programming Fundamentals Page 89

4 Programming Fundamentals
Data Structure: Particle System To model certain non-polygonal objects (e.g., splashing water, explosions, smoke), a system of hundreds or thousands of small particles may be used, with each particle having its own attributes. FIELD TYPE Position Vector Velocity Color Energy Integer Size Float Transparency TimeToLive Part 3.3 Programming Fundamentals Page 90

5 Programming Fundamentals
Data Structure: Subdivision Surface When 3D objects are distant from the viewer, their level of detail can be low, while when they’re near the viewer, the level of detail must be high. Subdivision surfaces are used to expand a 3D model lacking details into a more elaborate model. DATA STRUCTURE DESCRIPTION Vertex (x,y,z) coordinate info Triangle Three vertex objects Triangular Mesh Array of triangles Adjacency Matrix 2D table of vertex adjacencies Triangle Subdivider Drives triangular mesh subdivision Part 3.3 Programming Fundamentals Page 91

6 Programming Fundamentals
Data Structure: Interactive Music Sequencer An interactive music sequencer provides the interaction of computer games with the immersive qualities of music. // Note: The red fields are the // interactive features. typedef list< Sequence * > SequencePtrList_t; typedef list< Track * >    TrackPtrList_t; typedef list< Voice * >    VoicePtrList_t; class MusicSequencer_t {    MusicSequencerState_t State;    SequencePtrList_t     ActiveSequencePtrList;    SequencePtrList_t     FreeSequencePtrList;    TrackPtrList_t        ActiveTrackPtrList;    TrackPtrList_t        FreeTrackPtrList;    VoicePtrList_t        ActiveVoicePtrList;    VoicePtrList_t        FreeVoicePtrList; }; class SequenceState_t {    Tempo_t  Tempo;    Volume_t Volume; }; class Sequence_t {    SequenceState_t State;    SequenceState_t BeginState;    SequenceState_t EndState;    SequenceInterpolator_t Interpolator;    TimeUnit_t         TimeElapsed;    TimeUnit_t          TimeStep;    CallbackFunc_t *pCallback;    TrackPtrList_t     TrackPtrList; }; class TrackState_t {    Volume_t    Volume;    PitchBend_t PitchBend;    Pan_t       Pan;    Effect_t    Effect; }; class Track_t {    TrackState_t       State;    TrackState_t       BeginState;    TrackState_t     EndState;    TrackInterpolator_t Interpolator;    Sequence          *pOwner;    char                *pEvent;    Instrument_t    *pInstrument;    VoicePtrList_t    VoicePtrList; }; class VoiceState_t {    SynthVolume_t Volume;    SynthPitch_t  Pitch;    SynthPan_t    Pan;    SynthEffect_t Effect; }; class Voice_t {    VoiceState_t        CurrentState;    VoiceState_t        BeginState;    VoiceState_t        EndState;    VoiceInterpolator_t Interpolator;    Track_t             *pOwner;    char                nKey; }; Part 3.3 Programming Fundamentals Page 92

7 Programming Fundamentals
Data Structure: Spring Node One method for implementing animated cloth is to place invisible spring nodes at vertex locations within the cloth. FIELD TYPE Position Vector Velocity Force Mass Float Neighbor List Linked list of other spring nodes Distance List Parallel list of neighbor distances Neighbor Count Integer One reasonable model has each node connected to… its nearest neighbors (vertical and horizontal) by strong stretch springs its diagonal neighbors by weaker shear springs all of its neighbors by weak bend springs Part 3.3 Programming Fundamentals Page 93

8 Programming Fundamentals
Data Structure: BSP Tree To efficiently determine the order in which polygons should be rendered, binary space partitioning trees are used. The layout surfaces are used to perform a binary space partitioning (up to a certain depth). In this Doom-like layout, the game developer wants the player to see into adjacent rooms (and sometimes through those rooms into additional rooms), but the 80-room layout makes determining what’s visible somewhat problematic. In addition, the optical connectivity is determined between the various rooms and corridors, using doors and windows to determine viable adjacencies. This information is then combined to quickly determine overall visibility between rooms. Programming Fundamentals Page 94

9 Programming Fundamentals
Bit Packing for Network Compression Network games need to send game state information such as position, velocity, acceleration, and status flags, but storage bytes are often padded with bits containing no real information. struct NetData { unsigned char MsgType; // byte unsigned long Time; // 0 - 0xFFFFFFFF bytes unsigned short Element; // bytes int XPosition; // -100,000 – 100, bytes int YPosition; // -100,000 – 100, bytes }; Basic structure without bit packing: 136 bits struct NetData : public BitPackCodec<5> { PkUint<unsigned char, 5> MsgType; // 5 bits PkUint<unsigned long> Time; // 32 bits PkUint<unsigned short, 148, 1153> Element; // 10 bits PkUint<int, , > XPosition; // 18 bits PkUint<int, , > YPosition; // 18 bits }; Basic structure with bit packing: 83 bits While the use of bit packing greatly reduces the bandwidth requirements for network gaming, it complicates debugging and slows down performance (due to the linear time complexity of the packing and unpacking operations). Programming Fundamentals Page 95

10 Programming Fundamentals
Object-Oriented Vs. Component-Based How can Weapons be made animatable? How can Doors and Gems be made Destructible, but not Actors and Weapons? Traditional object orientation uses an inheritance hierarchy to define the characteristics of game elements. Object Renderable Object Logical Object Spawn Point Trigger Box Particle System Physics Object Animatable Object Collectable Object Weapon Healthpack Actor Door Gem Component-based programming relies on aggregate behavior, i.e., assigning each game entity a set of behaviors and functionalities. The flexibility of components and their reliance on run-time message passing complicates debugging and performance. Entity: Weapon Rendering Component Animating Component Collecting Component Entity: Door Rendering Component Animating Component Destroying Component Part 3.3 Programming Fundamentals Page 96


Download ppt "Game Design, Development, and Technology"

Similar presentations


Ads by Google