Yes, G is a structure full of global variables that can be accessed from any file in the program. It''s declared in a header file, and uses a little trick to make it truly global without writing externs all over the place.
There''s a reason why all of the variables are in a single structure. Here''s the code:
//----------------------------------------------------------------------------// Global Variables//---------------------------------------------------------------------------- #ifndef GLOBALS_OWNERSHIPextern#endif struct{ HWND hWnd; // Handle to the main window HINSTANCE hInstance; // Application instance BOOL bActive; // Are we in the foreground? BOOL bQuitting; // Set when the program is terminating // DirectDraw Variables LPDIRECTDRAW7 lpDD; LPDIRECTDRAWSURFACE7 lpDDSPrimary; LPDIRECTDRAWSURFACE7 lpDDSBack; LPDIRECTDRAWSURFACE7 lpDDSRes; LPDIRECTDRAWPALETTE lpDDPalette; // DirectInput Variables LPDIRECTINPUT7 lpDI; LPDIRECTINPUTDEVICE7 lpDIKeyboard; UCHAR KeyState[256]; // DirectSound Variables LPDIRECTSOUND lpDS; LPDIRECTSOUNDBUFFER lpDSB_Sample; } G;
One of the source files needs to declare GLOBALS_OWNERSHIP. This file becomes the ''owner'' of the structure G. All other files that include this header get the structure with the word extern slapped onto the beginning of it, which in effect makes the structure available to all source files that include it. If I didn''t do things this way, I''d have to manually type extern before every variable I wanted global, which I consider a pain. Here, I''ve got all of my globals in a convenient structure, thereby enhancing the readability of the code overall.
Don''t get too worried about the code -- it''s all part of the Ladder series. And if you''re one of those people who remembers the code from the last time around, there may be some changes.
Teej