Tricks of the Windows Game Programming Gurus:Vector Rasterization and 2D Transformations

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

#### The Engine Architecture

Thus far you have a fairly simple 2D engine going, as shown in Figure 8.54. Basically, it’s a 2D 8-bit/256-color back buffered DirectX engine that has support for any resolution, along with clipping to the primary display surface.

Figure 8.54 The architecture of the graphics engine.

However, the engine is full-screen only as is, but oh well—it’s free! To build an application using the library, you’ll need to include `T3DLIB1.CPP|H` (from the CD) along with `DDRAW.LIB` (DirectDraw Library), `WINMM.LIB` (Win32 Multimedia Library), and a main game program based on `T3DCONSOLE.CPP` (you made this earlier in the book). Then you’re ready to go.

Of course, you wrote a lot of code, and you’re free to modify, use, abuse all this stuff, or even burn it if you like. I just thought you might like it all explained and put together in a couple of easy-to-use files. And of course, you’ll probably end up making a lot of 16-bit conversions to it, but I’ll leave this to you because I’ve covered 16- and 24-bit modes in depth and it’s not that hard to make the conversions.

#### Basic Definitions

The engine has one header file, `T3DLIB1.H`, and within it are a number of `#defines` that the engine uses. Here they are for your reference:

    // DEFINES ////////////////////////////////////////////////

    // default screen size

    #define SCREEN_WIDTH        640  // size of screen

    #define SCREEN_HEIGHT       480

    #define SCREEN_BPP          8    // bits per pixel

    #define MAX_COLORS_PALETTE  256

    // bitmap defines

    #define BITMAP_ID            0x4D42 // universal id for a bitmap

    #define BITMAP_STATE_DEAD    0

    #define BITMAP_STATE_ALIVE   1

    #define BITMAP_STATE_DYING   2

    #define BITMAP_ATTR_LOADED   128

    #define BITMAP_EXTRACT_MODE_CELL  0

    #define BITMAP_EXTRACT_MODE_ABS   1

    // defines for BOBs

    #define BOB_STATE_DEAD         0    // this is a dead bob

    #define BOB_STATE_ALIVE        1    // this is a live bob

    #define BOB_STATE_DYING        2    // this bob is dying

    #define BOB_STATE_ANIM_DONE    1    // done animation state

    #define MAX_BOB_FRAMES         64   // maximum number of bob frames

    #define MAX_BOB_ANIMATIONS     16   // maximum number of

                                        // animation sequeces

    #define BOB_ATTR_SINGLE_FRAME   1   // bob has single frame

    #define BOB_ATTR_MULTI_FRAME    2   // bob has multiple frames

    #define BOB_ATTR_MULTI_ANIM     4   // bob has multiple animations

    #define BOB_ATTR_ANIM_ONE_SHOT  8   // bob will perform

                                        // the animation once

    #define BOB_ATTR_VISIBLE        16  // bob is visible

    #define BOB_ATTR_BOUNCE         32  // bob bounces off edges

    #define BOB_ATTR_WRAPAROUND     64  // bob wraps around edges

    #define BOB_ATTR_LOADED         128 // the bob has been loaded

    #define BOB_ATTR_CLONE          256 // the bob is a clone

    // screen transition commands

    #define SCREEN_DARKNESS  0         // fade to black

    #define SCREEN_WHITENESS 1         // fade to white

    #define SCREEN_SWIPE_X   2         // do a horizontal swipe

    #define SCREEN_SWIPE_Y   3         // do a vertical swipe

    #define SCREEN_DISOLVE   4         // a pixel disolve

    #define SCREEN_SCRUNCH   5         // a square compression

    #define SCREEN_BLUENESS  6         // fade to blue

    #define SCREEN_REDNESS   7         // fade to red

    #define SCREEN_GREENNESS 8         // fade to green

    // defines for Blink_Colors

    #define BLINKER_ADD           0    // add a light to database

    #define BLINKER_DELETE        1    // delete a light from database

    #define BLINKER_UPDATE        2    // update a light

    #define BLINKER_RUN           3    // run normal

    // fixed point mathematics constants

    #define FIXP16_SHIFT     16

    #define FIXP16_MAG       65536

    #define FIXP16_DP_MASK   0x0000ffff

    #define FIXP16_WP_MASK   0xffff0000

    #define FIXP16_ROUND_UP  0x00008000

You’ve seen all of these in one place or another.

#### Working Macros

Next are all the macros you’ve written thus far. Again, you’ve seen them all in one place or another, but here they are all at once:

    // MACROS /////////////////////////////////////////////////

    // these read the keyboard asynchronously

    #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

    #define KEY_UP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

    // this builds a 16 bit color value in 5.5.5 format (1-bit alpha mode)

    #define _RGB16BIT555(r,g,b) ((b%32) + ((g%32) << 5) + ((r%32) << 10))

    // this builds a 16 bit color value in 5.6.5 format (green dominate mode)

    #define _RGB16BIT565(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))

    // bit manipulation macros

    #define SET_BIT(word,bit_flag)   ((word)=((word) | (bit_flag)))

    #define RESET_BIT(word,bit_flag) ((word)=((word) & (∼bit_flag)))

    // initializes a direct draw struct, basically zeros

    // it and sets the dwSize field

    #define DDRAW_INIT_STRUCT(ddstruct)

    { memset(&ddstruct,0,sizeof(ddstruct));

    ddstruct.dwSize=sizeof(ddstruct); }

    // used to compute the min and max of two expressions

    #define MIN(a, b)  (( <) ?  :)

    #define MAX(a, b)  (( >) ?  :)

    // used for swapping algorithm

    #define SWAP(a,b,t) {t=a; a=b; b=t;}

    // some math macros

    #define DEG_TO_RAD(ang) ((ang)*PI/180)

    #define RAD_TO_DEG(rads) ((rads)*180/PI)

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.