Tricks of the Windows Game Programming Gurus:Windows GDI, Controls, and Last-Minute Gift Ideas

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

Take a moment or two and review the `WinMain()`. It should look very generic because it’s the one we have been using all along! The only differences, of course, are the calls to `Game_Init()`, `Game_Main()`, and `Game_Shutdown()`, which follow:

    ///////////////////////////////////////////////////////////

    int Game_Main(void *parms = NULL)

    {

    // this is the main loop of the game, do all your processing

    // here

    // for now test if user is hitting ESC and send WM_CLOSE

    if (KEYDOWN(VK_ESCAPE))

       SendMessage(main_window_handle,WM_CLOSE,0,0);

    // return success or failure or your own return code here

    return(1);

    } // end Game_Main

    ////////////////////////////////////////////////////////////

    int Game_Init(void *parms = NULL)

    {

    // this is called once after the initial window is created and

    // before the main event loop is entered; do all your initialization

    // here

    // return success or failure or your own return code here

    return(1);

    } // end Game_Init

    /////////////////////////////////////////////////////////////

    int Game_Shutdown(void *parms = NULL)

    {

    // this is called after the game is exited and the main event

    // loop while is exited; do all you cleanup and shutdown here

    // return success or failure or your own return code here

    return(1);

    } // end Game_Shutdown

The console functions don’t do much! That’s right—you’re the one that’s going to fill them in with code each time. However, I did put a little something in `Game_Main()` to test for the Esc key and send a `WM_CLOSE` message to kill the window. This way you don’t always have to close the window with the mouse or Alt+F4 key combination. Also, I’m sure that you’ve noticed the parameter list of each function looks like the following:

    Game_*(void *parms = NULL, int num_parms=0);

The `num_parms` is just a convenience for you if you want to send parameters to any of the functions along with the number of parameters sent. The type is `void`, so it’s flexible. Again, this isn’t in stone and you can surely change it, but it’s something to start with.

Finally, you might think that I should have forced the window to be full screen without any controls by using the `WS_POPUP` style. I could have done this, but I’m thinking of making them windowed for a number of demos so that they’re easier to debug. We can also change to full screen on a demo-by-demo basis, so let’s leave it windowed for now.

C++ If you’re a C programmer, the syntax `Game_Main(void *parms = NULL, int num_parms=0)` might look a little alien. The assignment on-the-fly is called default parameters. All it does is assign the parameters the listed default values so you don’t have to type in parameters if you know that they are the same as the default values. For example, if you don’t want to use the parameter list and don’t care if `*parms == NULL and num_parms == 0`, you can call `Game_Main()` just like that—without parameters. On the other hand, if you want to send parameters, you would have to use `Game_Main(&list, 12)`, or something similar. Take a look at Appendix D for a short tutorial on C++ if it still seems fuzzy.

If you run `T3DCONSOLE.EXE` on the CD, you won’t see much other than a blank window. The cool thing is that all you have to do is fill in `Game_Init()`, `Game_Main()`, and `Game_Shutdown()` with your 3D game code and you have a million dollars! Of course, we have a little ways to go, but we’re getting there <BG>.

As a final demo of using the T3D Game Console, I have created an application based on it called `DEMO4_9.CPP`. It’s a 3D star field demo—not bad for GDI. Check it out and see if you can make it speed up and slow down. The program once again illustrates the erase, move, draw animation cycle. It also locks the frame rate to 30 fps with our timing code.

### Summary

Well, my young Jedi, you are now a master of Windows—at least enough to take on the evil empire of game programming. In this chapter, you saw a number of topics, including GDI, controls, timing, getting information. In the end, you saw a real template application—the T3D Game Console. With it, you can get started on some serious Windows applications. Beginning with the next chapter, you’re going to embark on the wonderful world of DirectX. It’s cooler than cool—definitely a NexTGeN topic!

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.