Jump to content
  • Advertisement
Sign in to follow this  
derek7

look my global.h

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


#ifndef __global__
#define __global__

#include <dinput.h>
#include "CCamera.h"
#include "CMesh.h"
#include "CSkinnedmesh.h"
#include "CD3DText.h"
#include "CVertex.h"
#include "CLight.h"
#include "CVBIB.h"
#include "CTerrain.h"
#include "CTiny.h"

class CD3D
{
public:
	CD3D(IDirect3DDevice9* device = NULL,
		HWND hwnd = NULL,
		int width = 800,
		int height = 600,
		bool switch1 = true,
		Camera::CameraType cameraType = Camera::LANDOBJECT)
		:
	      _device(device),	
		_hwnd(hwnd),
		_width(width),	_height(height),
	      _switch(switch1),	_camera(cameraType),
		_xbias(0),		_ybias(0)
	{ }

IDirect3DDevice9 * getDevice(){return _device;}
 HWND &CD3D::getHwnd()  {return _hwnd;}
 int &CD3D::getWidth() {return _width;}
 int &CD3D::getHeight(){return _height;}
 bool &CD3D::getSwitch(){return _switch;}
 Camera &CD3D::getCamera(){return _camera;}
 float &CD3D::getXbias() {return _xbias;}
 float &CD3D::getYbias() {return _ybias;}

void setDevice(IDirect3DDevice9 * device)
							  { _device = device;}
void setHwnd(HWND	hwnd)     { _hwnd = hwnd;}
void setWidth(int	width)    { _width = width;}
void setHeight(int height)    { _height = height;}
void setSwitch(bool  switch1) { _switch = switch1;}
void setCamera(Camera camera) { _camera = camera;}
void setXbias(float xbias)    { _xbias = xbias;}
void setYbias(float ybias)    { _ybias = ybias;}

private:
	IDirect3DDevice9 *	_device;
	HWND			_hwnd;
	int				_width;
	int     		_height;
	bool    		_switch;
	Camera  		_camera;
	float			_xbias ,_ybias;
};

extern CD3D g_D3D;
extern int numFaces ;
extern float timeElapsed;
extern CTiny *tiny;
extern D3DXVECTOR3 dir ;
extern D3DXCOLOR col;
extern CLight myLight;
extern D3DLIGHT9 light;
extern CMesh *pObject[6];
extern CD3DText *fps;
extern IDirect3DTexture9 *tex;
extern CSkinnedMesh *skinMesh;
extern CSkinnedMesh *skinMesh1;
extern CVBIB floor1;
extern CTerrain* Terrain;
#endif


if I add a new global here,and almost all cpp file will be recompiled.because global.h is included almost all cpp. so how to improve it?

Share this post


Link to post
Share on other sites
Advertisement
1. Remove all includes that are not needed, obviously. If you only use a type name and not its internal structure, you only need the type name. As an example:

/* Forward class declaration */
class CSkinnedMesh;

CSkinnedMesh* pMesh;

This is perfectly valid and does not require the header file to be included. Then, in the implementing file (CPP) you can include the header file.

2. Remove code from the header file. For example, the CD3D constructor can be turned over to your CPP file instead. Then turn to rule 1.

3. Read up on pre-compiled headers, if you like the idea of that.

4. There was a link pointing to information about organizing your project. Anyone?

Greetz,

Illco

Share this post


Link to post
Share on other sites
Quote:
Original post by Illco
4. There was a link pointing to information about organizing your project. Anyone?


That link has already been provided to him. Apparently, he hasn't clicked on it. I don't know, since he tends to abandon a thread as soon as his question is answered without any form of acknowledgement.

Share this post


Link to post
Share on other sites
Quote:
Original post by derek7
*** Source Snippet Removed ***

if I add a new global here,and almost all cpp file will be recompiled.because global.h is included almost all cpp.
so how to improve it?
Now you know why the idea of a global.h is bad. Don't do such a thing! Include only the .h files in each .cpp file that the .cpp file needs.

There are other reasons why it is bad too, but I feel that I'd be wasting my time explaining them.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Jan-Lieuwe
A quick option to speed this up: turn it into a precompiled header.
That's like micro-optimizing bubble sort instead of switching to quicksort.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave Hunt
Quote:
Original post by Illco
4. There was a link pointing to information about organizing your project. Anyone?


That link has already been provided to him. Apparently, he hasn't clicked on it. I don't know, since he tends to abandon a thread as soon as his question is answered without any form of acknowledgement.


which link is provided? you mean this :http://www.gamedev.net/reference/articles/article1798.asp

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
Quote:
Original post by derek7
*** Source Snippet Removed ***

if I add a new global here,and almost all cpp file will be recompiled.because global.h is included almost all cpp.
so how to improve it?
Now you know why the idea of a global.h is bad. Don't do such a thing! Include only the .h files in each .cpp file that the .cpp file needs.

There are other reasons why it is bad too, but I feel that I'd be wasting my time explaining them.


but I don't want global.h but I must use it.otherwise how to handle global variable?

I see many code ,they use global variable too. no solution is provided.

maybe singleton is a solution .but it not sovle this problem completely.

Share this post


Link to post
Share on other sites
Quote:
Original post by derek7
but I don't want global.h but I must use it.otherwise how to handle global variable?


In my project I have one (and maybe a second one, but less important) .cpp file, that uses global variables. Other use variables, that have to be passed as parameters to functions or class methods.
It's something like a connection-point, functions in which all redirections take place.

So I also have file "global_resources.h", where I declare global variables (with extern, implementation is in each class source file), but it's there rather for clarity.

Quote:

I see many code ,they use global variable too. no solution is provided.

maybe singleton is a solution .but it not sovle this problem completely.


If you think you need to have those global variables visible from multiple .cpp files, then it's you who's building the rules for your project. Then it is truly inevitable, and the problem cannot be fully solved.

Cheers.
/def

Share this post


Link to post
Share on other sites
Quote:
In my project I have one (and maybe a second one, but less important) .cpp file, that uses global variables. Other use variables, that have to be passed as parameters to functions or class methods.
/def


you mean you use several .h to handle global variable instead of put all global variable in a .h file?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!