www.pudn.com > RCApp-src.zip > Engine.h


/* 
	RedEye Project (http://members.ozemail.com.au/~ndmcevoy/) 
	Copyright (C) 2003  Nick McEvoy 
 
	This library is free software; you can redistribute it and/or 
	modify it under the terms of the GNU Library General Public 
	License as published by the Free Software Foundation; either 
	version 2 of the License, or (at your option) any later version. 
 
	This library is distributed in the hope that it will be useful, 
	but WITHOUT ANY WARRANTY; without even the implied warranty of 
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
	Library General Public License for more details. 
 
	You should have received a copy of the GNU Library General Public 
	License along with this library; if not, write to the Free 
	Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 
	----------------------------------------------------------------- 
 
		Commented for use with Doxygen (http://www.doxygen.org) 
 
	----------------------------------------------------------------- 
*/ 
 
/*! \file Engine.h 
 *	\brief Game engine. 
 * 
 *		This file contains the game engine. 
 */ 
 
#ifndef _RE_GAME_ENGINE_H_ 
#define _RE_GAME_ENGINE_H_ 
 
// PLIB includes 
#include  
 
// ODE includes 
#include "ode/common.h" 
 
// RedEye includes 
#include "RCDefs.h" 
#include "RCXML.h" 
#include "Camera.h" 
 
class reGameEngine 
{ 
public: 
	//! Get instance 
	static reGameEngine* GetInstance(); 
 
	//! Initialise 
	void Init(); 
 
	//! GLUT callback handlers 
	void Update(); 
	void Display(); 
	void Reshape(int w, int h); 
	void Keyboard(unsigned char key, int x, int y, bool bKeyDown); 
	void KeyboardSpecial(int key, int x, int y, bool bKeyDown); 
	void MouseFunc(int button, int state, int x, int y); 
	void MotionFunc(int x, int y); 
	void PassiveMotionFunc(int x, int y); 
 
	//! ODE collision callback handler 
	void CollisionEventHandler(dGeomID o1, dGeomID o2); 
 
	ssgRoot* GetWorld() {return &mWorld;}; 
	dWorldID GetODEWorldId() {return mODEWorldId;}; 
	dSpaceID GetODESpaceId() {return mODESpaceId;}; 
	dJointGroupID GetODEJointGroupId() {return mODEJointGroupId;}; 
 
	//! Load level 
	void LoadLevel(const char* sLevelDir); 
	char* GetLevelFile() {return msLevelFile;}; 
 
	//! Pause game 
	void SetGamePaused(bool bPaused); 
 
	//! Set fullscreen 
	void SetFullscreen(bool bFull); 
 
	bool IsTextureOn() {return mbTextureOn;}; 
	bool IsWireFrameOn() {return mbWireFrameOn;}; 
	bool IsGravityOnOn() {return mbGravityOn;}; 
 
	reGameCamera* GetCamera() {return &mCamera;}; 
 
	TiXmlDocument* GetXMLConfig() {return &mXMLConfig;}; 
	TiXmlNode* GetXMLConfigNode() {return mXMLConfig.FirstChild("Config");} 
 
	TiXmlDocument* GetXMLLevel() {return &mXMLLevel;}; 
	TiXmlNode* GetXMLLevelNode() {return mXMLLevel.FirstChild("Level");} 
 
	const char* GetLevelPath() { 
		return reGetXMLAttribute(GetXMLLevelNode(), "path", ""); 
	} 
 
	//! Destructor 
	~reGameEngine(); 
 
protected: 
	//! Constructor is protected as this class is a singleton 
	reGameEngine(); 
 
private: 
	enum eGameMode 
	{ 
		eGameInit, 
		eGameLoading, 
		eGameRunning, 
		eGameStopped, 
		eGamePaused 
	}; 
 
	//! Change game mode 
	bool ChangeGameMode(eGameMode eMode); 
 
	//! Current level directory 
	char msLevelFile[RE_STRING_MAX]; 
 
	//! Current game mode 
	eGameMode meGameMode; 
 
	//! PLIB scene graph & its drawing modes 
	ssgRoot mWorld; 
	bool mbTextureOn; 
	bool mbWireFrameOn; 
	//GLenum meShadingMode; 
	bool mbGravityOn; 
	float mfGravityValue; 
 
	//! ODE physics engine 
	dWorldID mODEWorldId; 
	dSpaceID mODESpaceId; 
	dJointGroupID mODEJointGroupId; 
 
	//! Last update time 
	int miLastUpdateTimeMs; 
 
	//! Camera 
	reGameCamera mCamera; 
 
	//! Config 
	TiXmlDocument mXMLConfig; 
 
	//! Level 
	TiXmlDocument mXMLLevel; 
 
	//! The one and only instance 
	static reGameEngine* mpInstance; 
}; 
 
//! Get the one and only instance 
inline reGameEngine* reGetGameEngine() {return reGameEngine::GetInstance();}; 
 
//! Quick methods 
inline ssgRoot* reGetWorld() {return reGetGameEngine()->GetWorld();}; 
inline dWorldID reGetODEWorldId() {return reGetGameEngine()->GetODEWorldId();}; 
inline dSpaceID reGetODESpaceId() {return reGetGameEngine()->GetODESpaceId();}; 
inline dJointGroupID reGetODEJointGroupId() {return reGetGameEngine()->GetODEJointGroupId();}; 
 
#endif // _RE_GAME_ENGINE_H_