Advertisement

Getting rid of globals

Started by August 02, 2002 09:59 PM
0 comments, last by pizza box 22 years, 3 months ago
I''ve been programming in DirectX using Andre LaMothe''s style from TOTWGPG, and in his code he uses global variables extensively. I want to move away from using so many globals, as I''ve heard they get to be a hassle as programs grow in size. How would I go about replacing all the globals for DirectX and Windows? I tried placing all the variables in a class, but I didn''t know where to declare the class (WinMain?) If anyone can share as to how they deal with all these variables, I''d be very thankful. Thank you
As u said when ur codes grow up it becomes hard to handle TONES of variables. But because global variables are needed for Dx stuffs, this what i do. I create 2 files a *.h and a *.cpp that handle the Dx stuffs.This is the declaration of my Dx class:


  class GDEVICE{	LPDIRECTDRAW7		lpDD;	LPDIRECTDRAWSURFACE7 lpddsPrimary,lpddsBack;	LPDIRECTDRAWCLIPPER lpddcClipper;	DDSURFACEDESC2 desc;	int Width,Height,Depth;	BOOL				FullScreen;	public:	HINSTANCE	hInstance;	HWND		hWnd;	GDEVICE();	//~GDEVICE();	int	Initialize(int iWidth,int iHeight,int iDepth,BOOL bFullScreen,HWND hWnd);	int	Initialize(int iWidth,int iHeight,int iDepth);	int	Flip(DWORD dwFlag=DDFLIP_WAIT);	int	Restore();	int 	SetScreenMode(BOOL bFullSreen,HWND hWnd) ;	BOOL	GetScreenMode();	BOOL	CreatePrimarySurface(int iBufferCount=1);	BOOL	CreateBackSurface();	LPDIRECTDRAWSURFACE7 CreateOffScreenSurface(int iWidth,int iHeight,		DWORD dwFlag=DDSCAPS_VIDEOMEMORY);	LPDIRECTDRAWSURFACE7 LoadBitmapToSurface(char* filename);	int Release();};  


That''s what i did myself bt u can modiy it as u want.
Hope it helps
"...and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces."----------Scott Meyers, "Effective C++"

This topic is closed to new replies.

Advertisement