ClientMode

From Valve Developer Community
Jump to navigation Jump to search
Help.png
This article contains speculation that needs to be confirmed.

The ClientMode is literally the mode of operation in which the client is running. Your mod might have different ClientModes for the player walking around on foot, driving a vehicle in third person, and issuing commands from an overhead camera.

The system was created to accommodate the original TF2's RTS commander mode, but after that project changed direction it stopped serving any useful purpose to Valve. Although it is still in place, code elsewhere (such as the HUD, which is a single global object) might be written in the assumption that there is only one mode.

Minimum implementation

At least one ClientMode is required for a mod to compile. (A ModeManager is also required, even if there is only one ClientMode for it to manage!)

#include "clientmode_shared.h"

class ClientModeSkeleton : public ClientModeShared
{
	DECLARE_CLASS( ClientModeSkeleton, ClientModeShared );
public:
	void InitViewport()
	{
		m_pViewport = new CBaseViewport;
		m_pViewport->Start( gameuifuncs, gameeventmanager );
		m_pViewport->SetPaintBackgroundEnabled(false);
		m_pViewport->SetName( "Skeleton viewport" );
		m_pViewport->SetBounds( 0, 0, ScreenWidth(), ScreenHeight() );
	}
};

IClientMode* g_pClientMode = new ClientModeSkeleton;
IClientMode* GetClientModeNormal() { return g_pClientMode; }

Notable members

m_pViewport
The ultimate parent of all game-level VGUI controls created while this ClientMode is active (see VGUI Documentation#Panels and hierarchy). Disconnected from the rendering hierarchy when the ClientMode is deactivated.
Tip.pngTip:If your screen has a grey wash over it, you've probably not called m_pViewport->SetPaintBackgroundEnabled(false).
m_pChatElement
See CHudChat.
m_pWeaponSelection
See CBaseHudWeaponSelection.

Notable functions

InitViewport()
Called before the main Init() function. Must create and set up m_pViewport (see minimum implementation).
CreateMove()
This is the first stop for a usercmd. Always pass through to the player entity somewhere here!
FireGameEvent()
See events.
ShouldDrawCrosshair()
ShouldDrawDetailObjects()
ShouldDrawEntity(C_BaseEntity*)
ShouldDrawFog()
ShouldDrawLocalPlayer(C_BasePlayer*)
ShouldDrawParticles()
ShouldDrawViewModel()
A collection of functions that filter what the client renders each frame. ShouldDrawEntity() is particularly powerful - but remember that it is called every time any entity is up for drawing!
KeyInput()
This doesn't collect input for a usercmd as you might expect from the name, but instead intercepts each keypress beforehand and decides if it should proceed to the usercmd (and from there the server) or be "swallowed" by a HUD element like the chat window or console.
OverrideMouseInput()
Intercepts mouse movement. Created to accommodate a pair of binoculars..?
OverrideView()
Allows the client to change the position of the camera. Handles third-person mode, but otherwise passes through to the player entity.

See also