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

📄 clientmode_commander.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	if ( !in )
		return 0.0;

	sign = in > 0.0 ? 1.0 : -1.0;
	
	move = GetScaledSlueSpeed();

	return move * sign;
}

//-----------------------------------------------------------------------------
// Purpose: Zero out any movement in the command
// Input  : *cmd - 
//-----------------------------------------------------------------------------
void CClientModeCommander::ResetCommand( CUserCmd *cmd )
{
	cmd->buttons = 0;
	cmd->forwardmove = 0;
	cmd->sidemove = 0;
	cmd->upmove = 0;
	cmd->viewangles.Init();
}	

//-----------------------------------------------------------------------------
// Purpose: TF2 commander mode movement logic
//-----------------------------------------------------------------------------
void CClientModeCommander::IsometricMove( CUserCmd *cmd )
{
	int i;
	Vector wishvel;
	float fmove, smove;
	Vector forward, right, up;

	AngleVectors ( cmd->viewangles, &forward, &right, &up);  // Determine movement angles
	
	// Copy movement amounts
	fmove = cmd->forwardmove;
	smove = cmd->sidemove;
	
	// No up / down movement
	forward.Init(1, 0, 0);
	right.Init(0, -1, 0);

	wishvel.Init();
	
	// Determine x and y parts of velocity
	for (i=0; i < 3; i++)       
	{
		wishvel[i] = forward[i]*fmove + right[i]*smove;
	}

	m_pViewport->GetCommanderOverlayPanel()->TacticalOrigin() += cmd->frametime * wishvel;
	m_pViewport->GetCommanderOverlayPanel()->BoundOrigin( m_pViewport->GetCommanderOverlayPanel()->TacticalOrigin() );
}

#define WINDOWED_KEEPMOVING_PIXELS 300
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : frametime - 
//			*cmd - 
//-----------------------------------------------------------------------------
void CClientModeCommander::CreateMove( float flFrameTime, float flInputSampleTime, CUserCmd *cmd )
{
	int mx, my;
	int realx, realy;
	//int sidex, sidey;

	cmd->upmove = 0;

	// Figure out the speed scale so their perceptual movement speed stays the same.
	m_ScaledSlueSpeed  = Commander_SlueSpeed.GetFloat() * m_pViewport->GetCommanderOverlayPanel()->WorldUnitsPerPixel();
	m_ScaledMouseSpeed = Commander_MouseSpeed.GetFloat() * m_pViewport->GetCommanderOverlayPanel()->WorldUnitsPerPixel();

	// Translate WASD while in commander mode...
	float temp = cmd->forwardmove;
	// Swap forward/right
	cmd->forwardmove = cmd->sidemove;
	// Invert right/left
	cmd->sidemove = -temp;

	// Normalize nonzero inputs to scaled speed
	if ( cmd->forwardmove )
	{
		cmd->forwardmove = ( cmd->forwardmove > 0 ) ? GetScaledSlueSpeed() : -GetScaledSlueSpeed();
	}
	if ( cmd->sidemove )
	{
		cmd->sidemove = ( cmd->sidemove > 0 ) ? GetScaledSlueSpeed() : -GetScaledSlueSpeed();
	}

	// Sample mouse
	input->GetFullscreenMousePos( &mx, &my, &realx, &realy );

	if( m_pViewport->GetCommanderOverlayPanel()->IsRightMouseMapMoving() || ( in_commandermousemove.state & 1 ) )
	{
		cmd->forwardmove = m_ScaledMouseSpeed * (mx - m_LastMouseX);
		cmd->sidemove = m_ScaledMouseSpeed * (my - m_LastMouseY);

		if ( Commander_InvertMouse.GetInt() )
		{
			cmd->forwardmove *= -1.0f;
			cmd->sidemove *= -1.0f;
		}

		//input->SetFullscreenMousePos( m_LastMouseX, m_LastMouseY );
		mx = m_LastMouseX;
		my = m_LastMouseY;
	}
	/*
	else if ( input->IsFullscreenMouse() )
	{
		if ( abs( realx - mx ) < WINDOWED_KEEPMOVING_PIXELS && 
			 abs( realy - my ) < WINDOWED_KEEPMOVING_PIXELS )
		{
			sidex = 2;
			sidey = 2;

			// Check Size of viewport
			if ( mx < sidex )
			{
				cmd->forwardmove = -GetScaledSlueSpeed();
			}
			else if ( mx > ( ScreenWidth() - sidex ))
			{
				cmd->forwardmove = GetScaledSlueSpeed();
			}
			
			if ( my < sidey )
			{
				cmd->sidemove = -GetScaledSlueSpeed();
			}
			else if ( my > ( ScreenHeight() - sidey ) )
			{
				cmd->sidemove = GetScaledSlueSpeed();
			}
		}
	}
	*/

	m_LastMouseX = mx;
	m_LastMouseY = my;

	// Look straight down
	cmd->viewangles.x = 90; // 45;
	cmd->viewangles.y = 90; //45fmod( 3.0* 360 * (gpGlobals->curtime * 0.01), 360 );
	cmd->viewangles.z = 0;

	m_pViewport->GetCommanderOverlayPanel()->TacticalAngles() = cmd->viewangles;

	IsometricMove( cmd );

	// Reset command
	ResetCommand( cmd );
}

//-----------------------------------------------------------------------------
// Purpose: Makes sure the mouse is over the same world position as it started
//-----------------------------------------------------------------------------

void CClientModeCommander::MoveMouse( Vector& worldPos )
{
	Vector worldCenter;
	float wworld, hworld;
	m_pViewport->GetCommanderOverlayPanel()->GetOrthoRenderBox(worldCenter, wworld, hworld);
	wworld *= 2; hworld *= 2;

	Vector worldDelta;
	VectorSubtract( worldPos, worldCenter, worldDelta );

	int w, h;
	m_pViewport->GetSize( w, h );

	int mx, my;
	mx = (worldDelta.x / wworld + 0.5f) * w;
	my = (0.5f - worldDelta.y / hworld) * h;

	// Clamp
	if (mx < 0)	mx = 0; else if (mx > w) mx = w;
	if (my < 0)	my = 0; else if (my > h) my = h;

	//input->SetFullscreenMousePos( mx, my );

	m_LastMouseX = mx;
	m_LastMouseY = my;
}


//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *newmap - 
//-----------------------------------------------------------------------------
void CClientModeCommander::LevelInit( const char *newmap )
{
	BaseClass::LevelInit( newmap );

	HudCommanderOverlayMgr()->LevelShutdown();
	MapData().LevelInit( newmap );
	m_pViewport->GetCommanderOverlayPanel()->LevelInit( newmap );
	HudCommanderOverlayMgr()->LevelInit( );

	m_pViewport->Enable();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CClientModeCommander::LevelShutdown( void )
{
	m_pViewport->Disable();

	MapData().LevelShutdown();

	HudCommanderOverlayMgr()->LevelShutdown();

	m_pViewport->GetCommanderOverlayPanel()->LevelShutdown();

	BaseClass::LevelShutdown();
}

//-----------------------------------------------------------------------------
// returns the viewport panel
//-----------------------------------------------------------------------------
vgui::Panel *CClientModeCommander::GetViewport()
{
	return m_pViewport;
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CClientModeCommander::ShouldDrawEntity(C_BaseEntity *pEnt)
{
	return MapData().IsEntityVisibleToTactical(pEnt);
}

bool CClientModeCommander::ShouldDrawDetailObjects( )
{
	return false;
}

//-----------------------------------------------------------------------------
// Purpose: Always draw the local player while in commander mode
//-----------------------------------------------------------------------------
bool CClientModeCommander::ShouldDrawLocalPlayer( C_BasePlayer *pPlayer )
{
	return true;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CClientModeCommander::ShouldDrawViewModel( void )
{
	return false;
}

//-----------------------------------------------------------------------------
// Purpose: Return false to disable crosshair
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CClientModeCommander::ShouldDrawCrosshair( void )
{
	return false;
}

//-----------------------------------------------------------------------------
// Purpose: Adjust engine rendering viewport rectangle if needed
// Input  : x - 
//			y - 
//			width - 
//			height - 
//-----------------------------------------------------------------------------
void CClientModeCommander::AdjustEngineViewport( int& x, int& y, int& width, int& height )
{
}


//-----------------------------------------------------------------------------
// Should I draw particles
//-----------------------------------------------------------------------------

bool CClientModeCommander::ShouldDrawParticles( )
{
	Vector vCenter;
	float xSize, ySize;
	m_pViewport->GetCommanderOverlayPanel()->GetOrthoRenderBox(vCenter, xSize, ySize);

	// Activate/deactivate particles rendering based on zoom level
	float maxSize = max( xSize, ySize );
	return (maxSize < VISIBLE_STATIC_PROP_HEIGHT);
}


//-----------------------------------------------------------------------------
// Purpose: When in commander mode, force gl_clear and don't draw the skybox
//-----------------------------------------------------------------------------

void CClientModeCommander::PreRender( CViewSetup *pSetup )
{
	if ( !m_pClear || !m_pSkyBox )
		return;

	m_fOldClear = m_pClear->GetFloat();
	m_pClear->SetValue( 1.0f );
	pSetup->clearColor = !!m_pClear->GetInt();

	m_fOldSkybox = m_pSkyBox->GetFloat();
	m_pSkyBox->SetValue( 0.0f );

	GetOrthoParameters(pSetup);
	render->DrawTopView( true );
	Vector2D mins = pSetup->origin.AsVector2D();
	Vector2D maxs = pSetup->origin.AsVector2D();
	mins.x += pSetup->m_OrthoLeft;
	maxs.x += pSetup->m_OrthoRight;
	mins.y += pSetup->m_OrthoTop;
	maxs.y += pSetup->m_OrthoBottom;
	render->TopViewBounds( mins, maxs );

	// Activate/deactivate static prop + particles rendering based on zoom level
	Vector2D size;
	Vector2DSubtract( maxs, mins, size );
	float maxSize = max( size.x, size.y );
	bool showStaticProps = (maxSize < VISIBLE_STATIC_PROP_HEIGHT);
	ClientLeafSystem()->DrawStaticProps(showStaticProps);
	ClientLeafSystem()->DrawSmallEntities(showStaticProps);

	BaseClass::PreRender(pSetup);
}

void CClientModeCommander::PostRenderWorld()
{
	render->DrawTopView( false );
	ClientLeafSystem()->DrawStaticProps(true);
	ClientLeafSystem()->DrawSmallEntities(true);
}

//-----------------------------------------------------------------------------
// Purpose: Restore cvar values
//-----------------------------------------------------------------------------
void CClientModeCommander::PostRender( void )
{
	if ( !m_pClear || !m_pSkyBox )
		return;

	m_pClear->SetValue( m_fOldClear );
	m_pSkyBox->SetValue( m_fOldSkybox );

	BaseClass::PostRender();
}

//-----------------------------------------------------------------------------
// Purpose: Swallow mouse wheel when in this view
// Input  : down - 
//			keynum - 
//			*pszCurrentBinding - 
// Output : int
//-----------------------------------------------------------------------------
int CClientModeCommander::KeyInput( int down, int keynum, const char *pszCurrentBinding )
{
	switch ( keynum )
	{
	case K_MWHEELUP:
	case K_MWHEELDOWN:
		// Swallow
		return 0;
	}

	// Allow engine to process
	return BaseClass::KeyInput( down, keynum, pszCurrentBinding );
}

⌨️ 快捷键说明

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