⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chmaze.h

📁 Windows上的MUD客户端程序
💻 H
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	Declaration for the ChMazeWnd class, which is used to display
	3d graphics.

----------------------------------------------------------------------------*/

// $Header: /home/cvs/chaco/modules/client/msw/ChGraphx/ChMaze.h,v 2.99 1996/07/21 00:04:10 pritham Exp $

#if !defined( _CHMAZE_H )
#define _CHMAZE_H

#if defined( CH_MSW )
	#pragma warning( disable:4091 )
#endif	// defined( CH_MSW )

#include <math.h>

#if !defined(CH_VRML_PLUGIN )
#include <ChHook.h>
#endif

#include <ChKeyMap.h>

#include "ChGrType.h"
#include <ChGraphx.h>
#include "ChGrVw.h"
#include <ChDibImage.h>

#include <ChHTTP.h>


// The Renderer to use is selected at compile-time only
#include "ChGrRend.h"

#include <QvDB.h>
#include <QvInput.h>
#include <QvNode.h>
#include <QvState.h>
#include <QvNodes.h>
#include <QvInput.h>

#include "ChRender.h"

class ChGrTextureHandler;

class QvNode;
class QvShapeHints;
class ChMazeMainInfo;
class ChRenderContext;
class ChQvState;
class ChMazeCameraControl;
class ChQvAnchorSensor;
class ChQvBounds;
class ChParseInfo;
class ChGraphicStreamManager;


class ChVrmlStateTransition;

typedef ChQvAnchorSensor *pChQvAnchorSensor;
typedef ChParseInfo *pChParseInfo;

// Change this to use the non-stub version
#if defined(CH_VRML_EVENTS)	 && !defined( CH_VRML_PLUGIN )
class ChStubBrowser;
#define ChVrmlBrowser	ChStubBrowser
#endif

/*----------------------------------------------------------------------------
	Constants
----------------------------------------------------------------------------*/

/* Progress message IDs */

#define PROGRESS_MSG_0   	0		// ""
#define PROGRESS_MSG_1   	1		// "Geometry computation complete"
#define PROGRESS_MSG_2   	2		// "Computing scene geometry"
#define PROGRESS_MSG_3		3		// "Decoding texture"


#define ACCEL_FACTOR		1.6


// Error code generated by maze

#define 	CH_MAZE_PARSE_ERROR_BASE			0x10000000
#define 	CH_MAZE_PARSE_ERROR_SYNTAX			( CH_MAZE_PARSE_ERROR_BASE + 1 )

#define 	CH_MAZE_ROUTE_ERROR_BASE			0x20000000
#define 	CH_MAZE_ROUTE_ERROR_NODE_NOTFOUND		( CH_MAZE_ROUTE_ERROR_BASE + 1 )
#define 	CH_MAZE_ROUTE_ERROR_INVALID_ADD			( CH_MAZE_ROUTE_ERROR_BASE + 2 )
#define 	CH_MAZE_ROUTE_ERROR_INVALID_REMOVE		( CH_MAZE_ROUTE_ERROR_BASE + 3 )
#define 	CH_MAZE_ROUTE_ERROR_FIELD_MISMATCH		( CH_MAZE_ROUTE_ERROR_BASE + 4 )
#define 	CH_MAZE_ROUTE_ERROR_EVENT_NOTFOUND		( CH_MAZE_ROUTE_ERROR_BASE + 5 )

#define 	CH_MAZE_HTTP_ERROR_BASE				0x30000000
// All http error are 	CH_VRML_HTTP_ERROR_BASE + http error code


/*----------------------------------------------------------------------------
	Typedefs and helper classes
----------------------------------------------------------------------------*/
class ChRegistry;

class ChVrmlSettings
{
	public:
	
	enum whichPreference {	
		moveVector = 0x01, 
		scaleTextures = 0x02,
		renderQuality= 0x04,            
		moveRenderQuality = 0x08,        
		headlightBrightness = 0x10,
		viewerMode = 0x20,
		asciiTextQuality = 0x80,
		headlightOn = 0x100,                
		collisionMode = 0x200,
		collisionAlarm = 0x400,
		headlightSwitch = 0x1000,
		renderOptimization = 0x2000
	};
	
	
	 
	public:

		ChVrmlSettings() :
			m_boolMoveVector(GR_PREFS_DRAW_MOVE_VECTOR_DEF),              
			m_boolScaleTextures(GR_PREFS_DRAW_SCALE_PAT_DEF),           
			m_renderQuality(smoothShading),
			m_moveRenderQuality(smoothShading),
			m_fHeadlightBrightness(GR_PREFS_HEADLIGHT_BRIGHTNESS_DEF),        
		 	m_viewerMode(Ch3DViewerMode(GR_PREFS_VIEWER_MODE_DEF)),
			m_iAsciiTextQuality(GR_PREFS_ASCII_TEXT_QUALITY_DEF),
			m_boolHeadlightOn( false ),
			m_collisionMode(GR_PREFS_COLLISION_MODE_DEF),              
			m_boolCollisionAlarm(GR_PREFS_COLLISION_ALARM_DEF),         
			m_optimization(GR_PREFS_RENDER_OPTIMIZATION_DEF)  
			{};
		
	 
		inline float GetHeadlightBrightness() { return m_fHeadlightBrightness;};
		inline ChShadingLevel GetRenderQuality() { return m_renderQuality; }
		inline ChShadingLevel GetMoveRenderQuality()
						{
							return m_moveRenderQuality;
						}
		inline bool GetMoveVector() { return m_boolMoveVector; }
		inline bool GetScaleTextures() { return m_boolScaleTextures; }
 		inline Ch3DViewerMode GetViewerMode()
						{
							return (Ch3DViewerMode)m_viewerMode;
						}
 		inline int GetAsciiTextQuality()
						{
							return m_iAsciiTextQuality;
						}
 		inline bool GetHeadlightSwitch()
 			{ 
 				return m_boolHeadlightOn; 
 			};

 		 inline Ch3DCollisionMode GetCollisionMode( ) { return m_collisionMode;};
 		 inline bool GetCollisionAlarm() { return m_boolCollisionAlarm;};

		inline ChRenderOptimization GetRenderOptimization() { return m_optimization; }

		void ReadPreferences(const string& strCompanyName, const string& strProduct,
						const string& strGroup);
		//void ReadPreferences(ChRegistry *pReg);
		bool UpdatePreferences( bool boolMoveVector,
										bool boolScaleTextures,
										ChShadingLevel renderQuality,
										ChShadingLevel moveRenderQuality,
										float fHeadlight,
										int iAsciiTextQuality );

		bool UpdatePreferences( bool boolMoveVector,
										bool boolScaleTextures,
										ChShadingLevel renderQuality,
										ChShadingLevel moveRenderQuality,
										float fHeadlight,
										int iAsciiTextQuality,
										bool boolCollisionAlarm  );

		 ChVrmlSettings* SetHeadlightBrightness(ChRegistry &reg, float fHeadlightBrightness);
		 ChVrmlSettings* SetRenderQuality(ChRegistry &reg, ChShadingLevel renderQuality);
		 ChVrmlSettings* SetMoveRenderQuality(ChRegistry &reg, ChShadingLevel moveRenderQuality);
		 ChVrmlSettings* SetMoveVector(ChRegistry &reg, bool boolMoveVector);
		 ChVrmlSettings* SetScaleTextures(ChRegistry &reg, bool boolScaleTextures);
 		 ChVrmlSettings* SetViewerMode(ChRegistry &reg, Ch3DViewerMode viewerMode);
 		 ChVrmlSettings* SetAsciiTextQuality(ChRegistry &reg, int iAsciiTextQuality);
		 ChVrmlSettings* SetHeadlightSwitch(ChRegistry &reg, bool headlightOn);

 		 ChVrmlSettings* SetCollisionMode(ChRegistry &reg, Ch3DCollisionMode collisionMode);
 		 ChVrmlSettings* SetCollisionAlarm(ChRegistry &reg, bool boolCollisionAlarm);

		 ChVrmlSettings* SetHeadlightBrightness( float fHeadlightBrightness);
		 ChVrmlSettings* SetRenderQuality( ChShadingLevel renderQuality);
		 ChVrmlSettings* SetMoveRenderQuality( ChShadingLevel moveRenderQuality);
		 ChVrmlSettings* SetMoveVector( bool boolMoveVector);
		 ChVrmlSettings* SetScaleTextures( bool boolScaleTextures);
 		 ChVrmlSettings* SetViewerMode( Ch3DViewerMode viewerMode);
 		 ChVrmlSettings* SetAsciiTextQuality( int iAsciiTextQuality);
		 ChVrmlSettings* SetHeadlightSwitch( bool headlightOn);

 		 ChVrmlSettings* SetCollisionMode(Ch3DCollisionMode collisionMode);
 		 ChVrmlSettings* SetCollisionAlarm(bool boolCollisionAlarm);

		ChVrmlSettings*  SetRenderOptimization(ChRegistry &reg, ChRenderOptimization	optimization);
		ChVrmlSettings*  SetRenderOptimization(ChRenderOptimization	optimization) ;

	protected:
		bool					m_boolMoveVector;
		bool					m_boolScaleTextures;
		ChShadingLevel			m_renderQuality;
		ChShadingLevel			m_moveRenderQuality;

 		float					m_fHeadlightBrightness;
		Ch3DViewerMode			m_viewerMode;
		BOOL					m_boolHeadlightOn;

		Ch3DCollisionMode		m_collisionMode;
		BOOL					m_boolCollisionAlarm;

		int						m_iAsciiTextQuality;

		string					m_strCompanyName;
		string					m_strProduct;
		string					m_strGroup;
		ChRenderOptimization	m_optimization;
		// override this method to get notification when preferences change
		virtual void Notify(chuint32 which);	  // which is what changed
		ChVrmlSettings* SetRegistry(const string& strCompanyName, const string& strProduct,
						const string& strGroup);

};

/*----------------------------------------------------------------------------
	ChMazeWnd class
----------------------------------------------------------------------------*/

class ChMazeWnd : public ChGraphicView
{
	public:
		enum constants { minMoveAmount = 1, maxMoveAmount = 20,
							moveTimerID = 8650657, moveTimerDuration = 33 };

		enum ChCameraChange { cameraMoved = 0x01, cameraTurned = 0x02, cameraSelected = 0x04 };

		enum traceType { traceError = 0x08, traceWarning = 0x10 };

		#if defined(CH_VRML_VIEWER)	 || defined(CH_VRML_PLUGIN )
		ChMazeWnd( );
		#else
		ChMazeWnd( ChMazeMainInfo *pInfo, ChVrmlSettings *pSettings );
		#endif

		#if defined(CH_VRML_VIEWER)	 
		DECLARE_DYNCREATE( ChMazeWnd )
		#endif
		
		static int GetNumMazeObjects()		{ return m_iObjectCount; }

		#if defined(CH_VRML_VIEWER)	|| defined(CH_VRML_PLUGIN )
		virtual void InitMazeView( ChHTTPConn *httpConn, ChVrmlSettings *pSettings  );
		#endif

										// Create a wnd

		bool Create( const CRect& rtView, CWnd* pParent,
						DWORD dwStyle = WS_VISIBLE | WS_BORDER, // | WS_VSCROLL,
						UINT uiID = 0 );

											/* ClassWizard generated virtual
												function overrides */
		//{{AFX_VIRTUAL(ChMazeWnd)
	protected:
		virtual void OnInitialUpdate();     // first time after construct
		virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//}}AFX_VIRTUAL


	protected:
		virtual ~ChMazeWnd();

		#if defined( _DEBUG )

			virtual void AssertValid() const;
			virtual void Dump( CDumpContext& dc ) const;

		#endif	// defined( _DEBUG )

 	public:
		virtual void OnError( chuint32 luErrorCode, const string& strMsg, int iType  );
		void OnVRMLActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
		inline ChMazeCameraControl* GetCameraControl()
					{
						return m_pCameraControl;
					}
		#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )
		inline ChHookManager* GetCmdHookMgr() { return m_pHookMgr; }
		#endif

		inline ChGraphicPageID GetCurrentPage() { return m_currentPage; }
		#if defined(CH_USE_3DR)
		inline G3dHandle_t GetGC() { return m_RC.GetGC(); }
		#endif
		inline ChNativeContext GetRC() { return m_RC.GetRC(); }
		inline ChRenderContext* GetRenderContext() { return &m_RC; }
		inline QvNode* GetScene() { return m_pRoot; }

		#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )
		inline ChMazeMainInfo* GetMainInfo() { return (ChMazeMainInfo*)ChGraphicView::GetMainInfo(); }
//		ChHTTPConn* GetHTTPConn();
		#else
		inline ChHTTPConn* GetHTTPConn() { return m_pHttpConn; }
		#endif

		float GetUserSpeedFactor();
		void  SetUserSpeedFactor(float fSpeed);
		void  ResetUserSpeedFactor();

		float GetMoveAmountAngle();
		float GetMoveAmountDistance();
		ChMazeWnd * GoFaster(bool boolFaster = true );
		inline ChQvBounds *GetBounds() { return m_pBounds; };
		inline bool IsInMouseAnchor() { return m_boolInMouseAnchor; }
		inline bool IsInMouseMove() { return m_boolInMouseMove; }

		#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )
		inline void SetCmdHookMgr( ChHookManager *pHookMgr )
					{
						m_pHookMgr = pHookMgr;
					}
		#endif


		ChMazeWnd* SetScene( QvNode *root );

		inline unsigned long GetBackgroundColorL()
			{

				unsigned long val;
				#if defined(CH_USE_3DR)
				unsigned long r, g, b;
				
				r = long( m_backGroundColor.r() * 255.0 );
				g = long( m_backGroundColor.g() * 255.0 );
				b = long( m_backGroundColor.b() * 255.0 );
				val = r | (g << 8) | (b << 16) | 0xff000000;
				#elif defined( CH_USE_RLAB )  || defined(CH_USE_D3D) 
				val = long(*(m_backGroundColor.GetNative()));
				#else
				#endif


				return val;
			}

		virtual void Render( CRect* pClipRect = 0 );
		//bool LoadBackground( const string & strURL );
		bool LoadScene( const string & strURL, const string &strFilename, chparam data );
		bool LoadWWWInline( const string & strURL, const string &strFilename, 
												QvWWWInline *pInlineNode );
		void Spawn( const string &strFilename );

		virtual bool ContinueDraw() {return true;};	 // override to get notification before draw
	    virtual void Draw( CDC* pDC = 0, RECT* pClipRect = 0 );  // Draw to screen

		virtual bool NotifyPaletteChange( UINT uMsg, CWnd* pFocusWnd );

		void AdjustLight( string strCmd, int iLight, float fLevel );
		void DoNodeCommand( string& strCmd, string &strNodeVRML );
		void SetupContexts();
		void SetGlobalHints();
		void SetupTreeDefaults();

		static string EncapsulateVRML( string strNodeVRML );

		void DoAnchor( chint32 lX, chint32 lY );

		void AddAnchor(ChQvAnchorSensor *pAnchor);

		ChMazeWnd* SetHeadlight( bool boolOn );
		inline bool IsHeadlightOn()	{ return GetSettings()->GetHeadlightSwitch();;};
		inline float GetHeadlightBrightness()	{ return GetSettings()->GetHeadlightBrightness();};
		inline Ch3DViewerMode GetSceneViewerMode() {return GetSettings()->GetViewerMode();};
		inline ChVrmlSettings *GetSettings( ) {return m_pSettings; };
 		inline bool IsMoving() { return m_boolMoving; }
		inline void SetMoving( bool boolMoving ) { m_boolMoving = boolMoving; }
  		inline ChGraphicPageID GetNewPage() { return ++m_pageCount; }
		bool GetURL( const string& strURL, chparam userData,
						const char* pstrDefURL = 0);
		string&		GetCurrentURL()			 { return m_strURL; }
		ChMazeWnd *ResetCamera();
 		Ch3DCollisionMode GetCollisionMode( );


		virtual  void OnHotSpot( chparam userData,
								const string& strDocURL  );
		virtual  void  OnUpdateProgress( UINT uMsgID ) {}


		static void TermMazeWnd();
  		void WriteStatus( UINT uMsgID );
		bool CheckForTrailingJunk(QvInput &in );
		int	 GetShapeCount()				{ return m_RC.GetShapeCount(); }

		HANDLE GetEndParseEvent()			{ return m_hParseThreadEvent; }
		// Virtual override function to be called for UI update for new file
		virtual bool OnLoadComplete() {return true;};
	
		#if defined(CH_VRML_EVENTS)	 && !defined( CH_VRML_PLUGIN )
		ChVrmlBrowser * GetBrowser();
		#endif

 		inline ChVrmlStateTransition* GetSceneNavigator()
 		{
 			return ((GetSceneViewerMode() >= 0) ? m_pNavigators[GetSceneViewerMode()] : 0);
		};

		float CalcAccel( float fVal );
		virtual bool OnLeftClick(int x, int y, chuint32 uFlags);
		virtual bool OnRightClick(int x, int y, chuint32 uFlags);

		virtual bool OnCameraChange(ChCameraChange efChanged) {return false;};	 // override to get camera motion updates
		bool GetVelocity(GxVec3f &velocity);	// in world units/sec (usually m/s)
		bool GetAngularVelocity(GxVec3f &axis, float &slewRate); // in rads/sec

		void DisplayMenu( int x, int y, chuint32 uFlags );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -