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

📄 chmaze.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			case walkMode:
			{
				OnWalk();
				break;
			}
			case flyMode:
			{
				OnFly();
				break;
			}
			case examineMode:
			{
				OnExamine();
				break;
			}
			case beBrighter:
			{
				OnBrighten();
				break;
			}
			case beDimmer:
			{
				OnDimmer();
				break;
			}
			case goPrevCamera:
			{
				OnCameraPrev();
				break;
			}

			case goNextCamera:
			{
				OnCameraNext();
				break;
			}


			case resetCamera:
			{
				ResetCamera()->InvalidateRect( NULL, false );
				break;
			}
			
			default:
			{
				boolProcessed = false;
				break;
			}
		}
	}
	else
	{
		boolProcessed = false;
	}

	if(!boolProcessed)
	{
		boolProcessed = m_pNavigators[GetSettings()->GetViewerMode()]->ProcessKeyEvent(WM_KEYDOWN, nChar, 0);
	}

	if (!boolProcessed)
	{
		ChGraphicView::OnKeyDown( nChar, nRepCnt, nFlags );
	}
}


void ChMazeWnd::OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags )
{
	// TODO: Add your message handler code here and/or call default

	bool			boolProcessed = false;

	boolProcessed = m_pNavigators[GetSettings()->GetViewerMode()]->ProcessKeyEvent(WM_KEYUP, nChar, 0);

	if (!boolProcessed)
	{
		ChGraphicView::OnKeyUp( nChar, nRepCnt, nFlags );
	}
}


void ChMazeWnd::OnRButtonDblClk( UINT nFlags, CPoint point )
{
	// TODO: Add your message handler code here and/or call default

	ChGraphicView::OnRButtonDblClk( nFlags, point );
}


void ChMazeWnd::OnRButtonUp( UINT nFlags, CPoint point )
{
	// TODO: Add your message handler code here and/or call default

	if(!GetScene()) return;	
	if(! m_pNavigators[GetSettings()->GetViewerMode()]->
		ProcessMouseEvent(WM_RBUTTONUP, point.x, point.y, nFlags))
	{
		ChGraphicView::OnRButtonUp( nFlags, point );
	}
	if(!(nFlags & (MK_MBUTTON | MK_RBUTTON | MK_LBUTTON)))ReleaseCapture();
}


void ChMazeWnd::OnRButtonDown( UINT nFlags, CPoint point )
{
	// TODO: Add your message handler code here and/or call default

	if(!GetScene()) return;	
	SetCapture();
	if(! m_pNavigators[GetSettings()->GetViewerMode()]->
		ProcessMouseEvent(WM_RBUTTONDOWN, point.x, point.y, nFlags))
	{
		ChGraphicView::OnRButtonDown( nFlags, point );
	}
}


BOOL ChMazeWnd::PreCreateWindow( CREATESTRUCT& cs )
{
		HCURSOR		hCursor;

	if (!ChGraphicView::PreCreateWindow( cs ))
	{
		return false;
	}

	hCursor = AfxGetApp()->LoadStandardCursor( IDC_ARROW );
	cs.lpszClass = AfxRegisterWndClass( CS_DBLCLKS | CS_OWNDC, hCursor,
									//	(HBRUSH)(COLOR_WINDOW + 1) );
										(HBRUSH)(COLOR_BTNFACE + 1) );
	return true;

	//return ChGraphicView::PreCreateWindow(cs);
}

void ChMazeWnd::OnDestroy()
{
	m_currentPage = GetNewPage(); // bump the page number so that any pending request 
								  // will fail gracefully

	#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )
	GetMainInfo()->GetCore()->AbortRequests( false, 
								GetMainInfo()->GetStream() );
	#else
	GetHTTPConn()->AbortRequests( false, GetHTTPConn()->GetStreamMgr() );
	#endif


	// cancel all parse threads if any
	AbortParsing();

	m_RC.AbortConstruction();

	if(m_uiTickTimer)
	{
		KillTimer( m_uiTickTimer );
		m_uiTickTimer = 0;
	}
	ChGraphicView::OnDestroy();

	if(m_pRoot)
	{
	#if 0
		ChQvDeleteState	state(this);
		m_pRoot->traverse(&state);
		delete m_pRoot;
	#endif
		m_pRoot->Release();	
	}

	m_RC.Term();
}


void ChMazeWnd::OnTimer( UINT nIDEvent )
{
	if (m_uiMoveTimer == nIDEvent)
	{
		POINT	ptCursor;

		GetCursorPos( &ptCursor );
		ScreenToClient( &ptCursor );
		IsAnchor(ptCursor.x, ptCursor.y);		// update the status line
		m_pNavigators[GetSettings()->GetViewerMode()]->ProcessEvent(WM_TIMER, 0);
		//UpdateMouseMove( ptCursor.x, ptCursor.y );
	}
	#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
	else if(m_uiTickTimer == nIDEvent)
	{
		POINT	ptCursor;
		KillTimer( moveTimerID+1);
		chuint32 luLastFrame = m_luTime;
		GetCursorPos( &ptCursor );
		ScreenToClient( &ptCursor );

		m_pNavigators[GetSettings()->GetViewerMode()]->ProcessEvent(WM_TIMER, 0);

		m_RC.LowerConstructionThreads(m_pNavigators[GetSettings()->GetViewerMode()]->IsMoving());

		//TRACE("Calling draw...");
		if( ContinueDraw() && m_RC.Draw())
		{
			//TRACE("rendered");	TRACE("\n");
			IsAnchor(ptCursor.x, ptCursor.y);		// update the status line
			m_boolMouseMove = false;
		}
		//TRACE("\n");
		
		CDC* pDC = GetDC();
		DrawMouseMoveCrosshair( pDC );
		DrawMouseMoveVector( pDC );
		ReleaseDC(pDC);

		if(m_boolMouseMove)
		{
			IsAnchor(ptCursor.x, ptCursor.y);		// update the status line
			m_boolMouseMove = false;
		}

		chuint32 luTimeElapsed, luTime = GetTickCount();
		
		luTimeElapsed = (luTime > luLastFrame) ? luTime - luLastFrame : 0; // one jitter every 23 days
 
 		int iTicks = moveTimerDuration - UINT(luTimeElapsed);
		//iTicks = max(iTicks, 1);
		int iSlackTime = 8;
		if(m_pNavigators[GetSettings()->GetViewerMode()]->IsMoving())
		{
			iSlackTime = 4;
		}
		iTicks = max(iTicks, iSlackTime);	 // Give other threads time to work, too
		m_uiTickTimer = SetTimer( moveTimerID+1, UINT(iTicks), 0 );

	}
	#else
	else if(m_uiTickTimer == nIDEvent)
	{
		POINT	ptCursor;

		GetCursorPos( &ptCursor );
		ScreenToClient( &ptCursor );
		IsAnchor(ptCursor.x, ptCursor.y);		// update the status line
		m_pNavigators[GetSettings()->GetViewerMode()]->ProcessEvent(WM_TIMER, 0);
		//UpdateMouseMove( ptCursor.x, ptCursor.y );
		m_boolMouseMove = false;
	}
	#endif
	else
	{
		ChGraphicView::OnTimer( nIDEvent );
	}
}


BOOL ChMazeWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// TODO: Add your message handler code here and/or call default
	if(nHitTest == HTCLIENT)
	{
		SetCursor(m_hCursor);
		return true;
	}
	else
		return ChGraphicView::OnSetCursor(pWnd, nHitTest, message);
}

void ChMazeWnd::OnVRMLActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
	#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
	//if(GetRC())	RLWinHandleActivate(GetRC(), MAKEWORD( nState, bMinimized) );
	if(GetRenderContext())	GetRenderContext()->OnWindowActivate( nState, bMinimized );

	#endif
}

void ChMazeWnd::OnPaint() 
{
	#if defined(CH_USE_3DR)
	// class wizard says: Do not call ChGraphicView::OnPaint() for painting messages  ????????
	GetRenderContext()->SetDirty();
	ChGraphicView::OnPaint();
	#elif (defined(CH_USE_RLAB) || defined(CH_USE_D3D))

	//CPaintDC dc(this); // device context for painting
	GetRenderContext()->SetDirty();

	// TODO: Add your message handler code here
  	RECT r;
    PAINTSTRUCT ps;

    if (GetUpdateRect(&r, FALSE))
    {
    	BeginPaint(&ps);
		if(GetRC())
		{
			//RLWinHandlePaint(GetRC(), ps.hdc);
			GetRenderContext()->OnWindowPaint(ps.hdc);
		}
		EndPaint(&ps);
    }
	#endif
}

LONG ChMazeWnd::OnPrefChange( UINT wParam, LONG lParam )
{
	#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))

	m_RC.AdjustHeadlight();
	#endif
	if(wParam & ChVrmlSettings::viewerMode)
	{
		m_pNavigators[GetSettings()->GetViewerMode()]->SetState(ChVrmlStateTransition::s_start);
	}
	else if(wParam & ChVrmlSettings::renderOptimization)
	{
		GetRenderContext()->OptimizationChanged();
		GetRenderContext()->SetDirty();
	}
	else
	{
		GetRenderContext()->SetDirty();
	}
	return 1;	
}

LONG ChMazeWnd::OnVrmlEvent( UINT wParam, LONG lParam )
{
	LONG lValue = 1;
#if defined(CH_VRML_EVENTS)
	ChEventMsg *pEventMsg = (ChEventMsg *)lParam;
	lValue = m_RC.ProcessEvent(pEventMsg);
#endif
	return lValue;	
}


LONG ChMazeWnd::OnProgressMsg( UINT wParam, LONG lParam )
{
	// Override this member function to get notification of progress
	OnUpdateProgress( wParam );
	return 1;	
}

LONG ChMazeWnd::OnMazeError( UINT wParam, LONG lParam )
{
	// Override this member function to get notification of progress
	string* pstrBuf = (string*)lParam;

	OnError( wParam, *pstrBuf, traceError);

	delete pstrBuf;
	return 1;	
}


LONG ChMazeWnd::OnParseError( UINT wParam, LONG lParam )
{
	// Override this member function to get notification of progress
	char* pBuf = (char*)lParam;

	OnError( CH_MAZE_PARSE_ERROR_SYNTAX, string(pBuf) + "\n", traceError);

	#if !defined(CH_VRML_PLUGIN )
	if ( pBuf )
	{
		AfxMessageBox( pBuf,  MB_OK | MB_ICONEXCLAMATION );
	}
	#endif

	delete [] pBuf;

	// Resume animation - this one blew up so no need to wait
	GetRenderContext()->Animate();
	return 1;	
}



LONG ChMazeWnd::OnParseComplete( UINT wParam, LONG lParam )
{

	ChParseInfo* pParseInfo = (ChParseInfo*)lParam;
	ASSERT( pParseInfo );

	bool		boolSuccess = false;
	bool		boolFound   = RemoveParseInfo( pParseInfo );


	if ( boolFound && pParseInfo->GetType() == ChParseInfo::typeScene )
	{
		QvNode *rootToDelete = 0;

	    if ( pParseInfo->GetParseResult() )
		{
			#if 0 && I_HOPE
			if(m_pRoot)
			{
				ChQvDeleteState	state(this);
				m_pRoot->traverse(&state);
				delete m_pRoot;
			}
			#endif

			rootToDelete = m_pRoot;

			#if defined(CH_USE_3DR)
			ClearAnchors();
			delete m_pAnchor;
			m_pAnchor = 0;
			#elif (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
			// no need to
			#else
			#pragma message("Not clearing anchor")
			#endif

			m_pRoot = pParseInfo->GetQVNode();
			boolSuccess = true;
			CheckForTrailingJunk( *pParseInfo->GetStream() );

		}
	    else
	    {
			TRACE("Read was bad.\n");
			// Clean up on bad read
			if(pParseInfo->GetQVNode())
			{
				#if 0
				SetupContexts();
				ChQvDeleteState	state(this);
				pParseInfo->GetQVNode()->traverse(&state);
				delete pParseInfo->GetQVNode();
				#endif
				pParseInfo->GetQVNode()->Release();	
			}
	    }

		// save tree, and do traversal
		if(boolSuccess)
		{
			// We are going to mess with the scene, we better lock befor any body
			// uses

			GetRenderContext()->LockScene();
			m_strURL = pParseInfo->GetURL();
			m_currentPage = GetNewPage();
			GetRenderContext()->UnlockScene(); // done, can be used now

			#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )
			// Always visible if we're a standalone viewer
			GetMainInfo()->ShowModule();
			#endif			
						// pop up if not visible
			SetScene(m_pRoot)->InvalidateRect(0, false);


			
								  // Zap the old scene; we are guaranteed
							  // all its construction threads are now
							  // ended
			if(rootToDelete)
			{
				rootToDelete->Release();

				#if 0
				ChQvDeleteState	state(this);
				rootToDelete->traverse(&state);
				delete rootToDelete;
				#endif
			}

			Spawn( pParseInfo->GetURL() );	 // Spawn new requests based on embedded URLs

			#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )
			ChGraphicDocumentHTTPReq * pReq = (ChGraphicDocumentHTTPReq *)(pParseInfo->GetUserData2());
			if(pReq)
			{
				GetMainInfo()->OnParseComplete(pParseInfo->GetURL(), chparam(pReq));  
				delete pReq;
				
			}
			#endif
		}

	}
	else if ( boolFound && pParseInfo->GetType() == ChParseInfo::typeWWWInline )
	{
		QvWWWInline *pInlineNode = (QvWWWInline*)pParseInfo->GetUserData();

	    if ( pParseInfo->GetParseResult() )
		{
			if(pInlineNode)
			{
				ChQvWWWInlineRenderData *pRenderData =  ((ChQvWWWInlineRenderData*)(pInlineNode->GetRenderData()));
				pRenderData->SetParseInfo(0);
				if(pRenderData->GetCurrentURL().IsEmpty())
				{
					// Attach to tree, and instantiate the new subtree
					pInlineNode->children->append(pParseInfo->GetQVNode());
					pRenderData->Instantiate( this, pParseInfo->GetQVNode());
					pRenderData->SetURL(pParseInfo->GetURL());

					// Spawn for new requests
					ChQvSpawnState state( this, pParseInfo->GetURL() );
			    	pParseInfo->GetQVNode()->traverse(&state);

					// Set it dirty, for redraw, etc.
					GetRenderContext()->SetDirty();
					InvalidateRect(0, false);
				}
			}
			else
			{
				TRACE("WWWInline parse complete, but node is gone, so deleting result.\n");
				pParseInfo->GetQVNode()->Release();	// oughta be non-null cuz parse result was good
			}
		}
	    else
	    {
			TRACE("WWWInline Read was bad.\n");
			// Clean up on bad read
			if(pParseInfo->GetQVNode())
			{
				pParseInfo->GetQVNode()->Release();
			}
	    }


	}
	else
	{
		if(pParseInfo->GetQVNode())
		{
			pParseInfo->GetQVNode()->Release();

		}
	}
	// done with this file, cleanup 
	delete pParseInfo;
	return 1;	
}

LONG ChMazeWnd::OnLoadTexture( UINT wParam, LONG lParam )
{
	GetRenderContext()->AddToTextureQueue( (ChMazeTextureHTTPReq*)lParam );
	return 0;
}

LONG ChMazeWnd::OnActivateWnd( UINT wParam, LONG lParam ) 
{

	#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
		#if 0
		if (WA_INACTIVE != nState)
		{
			SetFocus();
		}
		#endif
		OnVRMLActivate( LOWORD(wParam), CWnd::FromHandle( (HWND)lParam ), HIWORD(wParam));
	#endif

	return 0;
}


void ChMazeWnd::OnSysKeyDown(  UINT nChar, UINT nRepCnt, UINT nFlags )
{
	bool boolProcessed = m_pNavigators[GetSettings()->GetViewerMode()]->ProcessKeyEvent(WM_KEYDOWN, nChar, 0);
	if(!boolProcessed /*|| nChar == VK_MENU*/)
	{
		ChGraphicView::OnSysKeyDown( nChar, nRepCnt, nFlags );
	}
}

void ChMazeWnd::OnSysKeyUp(  UINT nChar, UINT nRepCnt, UINT nFlags )
{
	bool boolProcessed = m_pNavigators[GetSettings()->GetViewerMode()]->ProcessKeyEvent(WM_KEYUP, nChar, 0);
	if(!boolProcessed /*|| nChar == VK_MENU*/)
	{
		ChGraphicView::OnSysKeyUp( nChar, nRepCnt, nFlags );
	}
}

bool ChMazeWnd::OnLeftClick(int x, int y, chuint32 uFlags)
{
	EndAnchor(x, y);
	return true;
}

bool ChMazeWnd::OnRightClick(int x, int y, chuint32 uFlags)
{
	DisplayMenu(  x, y, uFlags );
	return true;
}



/*----------------------------------------------------------------------------
	Override this virtual member function to display trace messages generated
	by VRML parser, HTTP load errors, plugin errors etc.
----------------------------------------------------------------------------*/
void ChMazeWnd::OnError( chuint32 luErrorCode, const string& strMsg, int iType  )
{

}

⌨️ 快捷键说明

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