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

📄 chmazmod.cpp

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

    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.

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

	Implementation for the ChGraphic class, which is used to display
	graphics, & accept selection of hot spots and sprites.

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

// $Header: /home/cvs/chaco/modules/client/msw/ChGraphx/ChMazMod.cpp,v 2.82 1996/09/12 19:09:43 pritham Exp $

#include "grheader.h"

#include <ctype.h>

#include <ChCore.h>
#include <ChHtmWnd.h>
#include <ChPane.h>

#if defined( CH_MSW ) && defined( CH_ARCH_16 )

	#include <ChUtil.h>

#endif	// defined( CH_MSW ) && defined( CH_ARCH_16 )

#include "ChGrMod.h"
#include "ChVrmlWnd.h"
#include "ChMazDep.h"

#if !defined( CH_PUEBLO_PLUGIN )
#include "ChMazePr.h"
#endif

#include "ChRlabPr.h"
#include "ChRenderData.h"

#if defined( CH_VRML_EVENTS )

#include "ChStubBrowser.h"
#include "ChVrmlEvent.h"

#endif	// defined( CH_VRML_EVENTS )

#include "ChMazCam.h"


#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))

#include "ChRLImg.h"

#endif	// defined( CH_USE_RLAB )

#ifdef _DEBUG
	#undef THIS_FILE
	static char THIS_FILE[] = __FILE__;
#endif


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

#define GRAPHICS_PANE		1

									// Graphics img command modifiers for VRML

#define CH_GRAPH_VRML				"xch_graph_vrml"
#define CH_GRAPH_CMD_MINTIME   		"xch_minTime"
#define CH_GRAPH_CMD_MAXTIME   		"xch_maxTime"
#define CH_GRAPH_CMD_MAXMOVE   		"xch_maxMove"
#define CH_GRAPH_CMD_MAXROTATION   	"xch_maxRotation"
#define CH_GRAPH_CMD_STARTTIME   	"xch_startTime"
#define CH_GRAPH_CMD_PARAMS   		"params"
#define CH_CMD_NAME			   		"xch_cmd"

// IHTML magic name for the the current viewpoint node
#define theCurrentViewpoint			"current_viewpoint"

/*----------------------------------------------------------------------------
	Handler declarations
----------------------------------------------------------------------------*/

CH_DECLARE_MESSAGE_HANDLER( mazeInitHandler )
CH_DECLARE_MESSAGE_HANDLER( mazeLoadCompleteHandler )
CH_DECLARE_MESSAGE_HANDLER( mazeLoadErrorHandler )
#if !defined( CH_PUEBLO_PLUGIN )
CH_DECLARE_MESSAGE_HANDLER( mazeGetPageCountHandler )
CH_DECLARE_MESSAGE_HANDLER( mazeGetPagesHandler )
CH_DECLARE_MESSAGE_HANDLER( mazeGetPageDataHandler )
CH_DECLARE_MESSAGE_HANDLER( mazeReleasePagesHandler )
#endif

CH_DECLARE_MESSAGE_HANDLER( mazeLoadSceneHandler )
CH_DECLARE_MESSAGE_HANDLER( mazeImageHookHandler )
#if !defined( CH_PUEBLO_PLUGIN )
CH_DECLARE_MESSAGE_HANDLER( mazePlayGraphicHandler )
#endif


static ChMsgHandlerDesc	mazeHandlers[] =
						{	{CH_MSG_INIT, 			mazeInitHandler},
							{CH_MSG_LOAD_COMPLETE,	mazeLoadCompleteHandler},
							{CH_MSG_LOAD_ERROR,		mazeLoadErrorHandler},
#if !defined( CH_PUEBLO_PLUGIN )
						{CH_MSG_GET_PAGE_COUNT,	mazeGetPageCountHandler},
							{CH_MSG_GET_PAGES,		mazeGetPagesHandler},
							{CH_MSG_GET_PAGE_DATA,	mazeGetPageDataHandler},
							{CH_MSG_RELEASE_PAGES,	mazeReleasePagesHandler},
#endif
							{CH_MSG_INLINE,			mazeImageHookHandler},
#if !defined( CH_PUEBLO_PLUGIN )
							{CH_MSG_PLAY_GRAPHIC,	mazePlayGraphicHandler},
#endif
							{CH_MSG_LOAD_SCENE,		mazeLoadSceneHandler}
						};
/*----------------------------------------------------------------------------
	Chaco menu handlers
----------------------------------------------------------------------------*/

CH_DECLARE_MESSAGE_HANDLER( graphicsViewMenuHandler )


/*----------------------------------------------------------------------------
	ChMazeMainInfo class
----------------------------------------------------------------------------*/

ChMazeMainInfo::ChMazeMainInfo( ChModuleID idModule,
								ChCore* pCore ) :
					ChGraphicMainInfo( idModule, pCore ),
					m_reg( GR_PREFS_GROUP ),
					m_pInProgressReqs(0),
					m_minNotifyTime(-1),
					m_maxNotifyTime(-1),
					m_lastTick(0),
					m_boolNotificationEnabled(false)
{
	ChPane*		pPane = GetPaneMgr()->FindPane( ChPaneMgr::strGraphicName );
	CRect		rtChild( -100, -100, -1, -1 );
	bool		boolCreated;


	m_pSettings	 = new ChVrmlSettings;
	ReadPreferences();
	m_pWnd = new ChPuebloVrmlWnd( this, m_pSettings );
	boolCreated = GetView()->Create( rtChild, pPane->GetFrameWnd() );

	ASSERT( boolCreated );

	GetView()->SetCmdHookMgr( &m_hookMgr );
	m_pStartReq = new ChMazeStartHTTPReq( GetView(), "" );
}

void ChMazeMainInfo::Initialize()
{	
	ChGraphicMainInfo::Initialize();

	// GetView()->SetHeadlight(false);	Why on earth did we do this????
}

ChMazeMainInfo::~ChMazeMainInfo()
{											/* ChGraphicMainInfo class does
												most all the work */

	ChPane*		pPane = GetPaneMgr()->FindPane( ChPaneMgr::strGraphicName );

	ASSERT( 0 != pPane );

	if ((GetView() == pPane->GetWindow()) &&
		(pPane->GetModuleID() == GetModuleID()))
	{
											// Remove the window from the pane
		pPane->SetOwner( 0, 0, 0 );
	}
											// Destroy the window
	if (GetView())
	{
		GetView()->DestroyWindow();
		delete m_pWnd;
		m_pWnd = 0;
	}

	ChMazeWnd::TermMazeWnd();

	delete m_pSettings;
}


void ChMazeMainInfo::RegisterDispatchers()
{
	chint16		sHandlerCount = sizeof( mazeHandlers ) /
								sizeof( ChMsgHandlerDesc );

	ChGraphicMainInfo::RegisterDispatchers();	  // inherit handlers
	m_graphicDispatcher.AddHandler( mazeHandlers, sHandlerCount );
}


void ChMazeMainInfo::ShowModule( bool boolShow )
{
	ChGraphicMainInfo::ShowModule( boolShow );
	GetView()->SendMessage( WM_QUERYNEWPALETTE );	// ???? fake out 3dr
	if(!boolShow) m_boolNotificationEnabled = false;

	#if 0
	if(!boolShow) 
	{
		// to track down leaks just temporary!!!!!!!!!!!
		ChPane*		pPane = GetPaneMgr()->FindPane( ChPaneMgr::strGraphicName );

		ASSERT( 0 != pPane );

		if ((GetView() == pPane->GetWindow()) &&
			(pPane->GetModuleID() == GetModuleID()))
		{
												// Remove the window from the pane
			pPane->SetOwner( 0, 0, 0 );
		}
												// Destroy the window
		if (GetView())
		{
			GetView()->DestroyWindow();
			delete m_pWnd;
			m_pWnd = 0;
		}

		ChMazeWnd::TermMazeWnd();
	
		CRect		rtChild( -100, -100, -1, -1 );
		m_pWnd = new ChPuebloVrmlWnd( this, m_pSettings );
		bool boolCreated = GetView()->Create( rtChild, pPane->GetFrameWnd() );

		ASSERT( boolCreated );

		GetView()->SetCmdHookMgr( &m_hookMgr );
		delete m_pStartReq;
		m_pStartReq = new ChMazeStartHTTPReq( GetView(), "" );
	}
	#endif
}


void ChMazeMainInfo::EndFrameTime()
{
	DWORD	luNow = GetTickCount();
	DWORD	luElapsed = luNow - m_luTime;
	string	strStatus;
	double	frameRate = luElapsed ? 1.0 / (float)luElapsed : 1.0;

	frameRate *= 1000.0;

	strStatus.Format( "Frames per second: %.2f", frameRate );
	WriteStatus( strStatus );
}

void ChMazeMainInfo::WriteStatus(const string &strMessage)
{
	ChStatusMsg		StatusMsg( (string&)strMessage );
	GetCore()->DispatchMsg( CH_CORE_MODULE_ID, StatusMsg );
}

void ChMazeMainInfo::DoCommand(string& strArgs)
{
	string strValue;
	//TRACE1("DoCommand: %s\n", strArgs);
	//  respond to hooked img messages
	if (ChHtmlWnd::GetHTMLAttribute( strArgs, CH_GRAPH_CMD, strValue ))
	{      
		#if defined( CH_ARCH_16 )    
		TrimLeft( strValue );
		#else
		strValue.TrimLeft();
		#endif
		char cmd[100];   
		#if defined( CH_ARCH_16 ) 
		    
		for ( int i = 0; i < 99 && !isspace( strValue[i] );  i++ )
		{
			cmd[i] = strValue[i];
		}  
		cmd[i] = 0;
		#else
		::sscanf(LPCTSTR(strValue), "%s", cmd);
		#endif
		string strCmd(cmd);

		#if defined( CH_ARCH_16 )   
		TrimLeft( strCmd );
		TrimRight( strCmd ); 
		#else
		strCmd.TrimLeft();
		strCmd.TrimRight();
		#endif            
		
		if(!strCmd.CompareNoCase("light"))
		{
			int	iLight;
			float fLevel; 
			#if defined( CH_ARCH_16 ) 
			const char* pstrStart = strValue;
			pstrStart += i;
			char * pstrEnd;
			iLight =  (int)strtol( pstrStart, &pstrEnd, 10 );
			pstrStart = pstrEnd;
			fLevel =  (int)strtod( pstrStart, &pstrEnd );
			#else
			::sscanf(LPCTSTR(strValue), "%s %d %f", cmd, &iLight, &fLevel);
			#endif
			//GetView()->AdjustLight(string(cmd), iLight, fLevel);
			GetView()->AdjustLight( strCmd, iLight, fLevel);
			return;
		}
		else if(!strCmd.CompareNoCase("draw"))
		{
									// <img xch_graph="draw">
			GetView()->UpdateWindow();
			#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
			GetView()->GetRenderContext()->Draw();
			#endif
			return;
		}
		else if(!strCmd.CompareNoCase("event"))
		{
									// <img xch_graph="event {type} {name} [count] {arg[s]}">
			ProcessEvent(strArgs);
			return;
		}
		else if (!strCmd.CompareNoCase( "load" ))
		{
			// Forwarded by pane as notification of what will happen
			OnLoadInitiated(string(""));
			return;
		}

		else
		{
			// handle all others tbd
		}
	}
	//else
	{
		string strVRML;
		if(ChHtmlWnd::GetHTMLAttribute( strArgs, CH_GRAPH_CMD_NODE, strVRML ))
		{
			string strCmd("node");
			GetView()->DoNodeCommand(strCmd, strVRML);
			return;
		}
	}
	
	{
		string strCmd;
		if(ChHtmlWnd::GetHTMLAttribute( strArgs, CH_EVENT_NOTIFY, strCmd ))
		{
			strCmd.TrimLeft();
			strCmd.TrimRight();
			if(!strCmd.CompareNoCase("move"))
			{
				SetupPositionNotification(strArgs);
			}
		 	return;
		}
	}
}

#if 0
// oughta do it this way someday
template <class eType> 
bool readMFEvent(string &in, const string &fmt, eType *&pEvent)
{
}
#endif

void ChMazeMainInfo::ProcessEvent(string& strArgs)
{
	#if defined(CH_VRML_EVENTS)
	string strValue;

//	TRACE1("ProcessEvent: %s\n", strArgs);
	//  respond to hooked img messages
									// <img xch_graph="event {node} {type} {eventName} [count] {arg[s]}">
									// example:
									// <img xch_graph="event MyCubeRotation SFRotation setRotation 0. 1. 0. .2">

	if (ChHtmlWnd::GetHTMLAttribute( strArgs, CH_GRAPH_CMD, strValue ))
	{      

		strValue.TrimLeft();
		char cmd[100];
		char name[200];
		char nodeName[200];
		char eventTypeName[200];
		int numBytes = 0;	

		ChVRMLEvent::type	eventType;
	   
		int numRead = ::sscanf(LPCTSTR(strValue), "%s %s %s %s%n", cmd, nodeName, eventTypeName, name, &numBytes);

		if(numRead >= 4)
		{
			ChVrmlBrowser * pBrowser = GetView()->GetBrowser();

			// Find the subject node
			
			string strNode(nodeName);

			ChNode * pNode = (pBrowser->Resolve(0, strNode));
			if(pNode == 0 && !strNode.CompareNoCase(theCurrentViewpoint))
			{
				pNode = pBrowser->GetViewpoint();
			}
			ChNode *pSFNode = 0;

			if(pNode)
			{
				// Got a node to work on
				string strEvent(eventTypeName);
				eventType = pBrowser->GetType(strEvent);
				ChIVrmlEvent *pEvent = 0;
			
				switch(eventType)
				{
					case ChVRMLEvent::SFRotation :
					{
						float x, y, z, angle;
						int numRead = ::sscanf(LPCTSTR(strValue) + numBytes, "%f %f %f %f", &x, &y, &z, &angle);
						pEvent = new ChRotationEvent(name, x, y, z, angle);
						break;
					}
					case ChVRMLEvent::SFVec3f :
					{
						float x, y, z;
						int numRead = ::sscanf(LPCTSTR(strValue) + numBytes, "%f %f %f", &x, &y, &z);
						pEvent = new ChVec3fEvent(name, x, y, z);
						break;
					}
					case ChVRMLEvent::MFVec3f :
					{
						int count;
						int nBytes = numBytes;
						int n;
						int numRead = ::sscanf(LPCTSTR(strValue) + nBytes, "%d%n", &count, &n);
						if(numRead)
						{
							float *val = new float [count*3];
							for(int i = 0; i < count * 3; i++)
							{
								nBytes += n;
								numRead = ::sscanf(LPCTSTR(strValue) + nBytes, "%f%n", val+i, &n);
								if(!numRead) break;
							}
							if(numRead) pEvent = new ChVec3fEvent(name, count, val);
							delete []val;
						}
						break;
					}
					case ChVRMLEvent::SFLong :
					{
						long value;
						int numRead = ::sscanf(LPCTSTR(strValue) + numBytes, "%d", &value);
						pEvent = new ChLongEvent(name, value);
						break;
					}
					case ChVRMLEvent::SFFloat :
					{

⌨️ 快捷键说明

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