From Valve Developer Community
Revision as of 22:46, 5 August 2009 by TomEdwards (talk | contribs) (Notable functions)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 );
	void InitViewport()
		m_pViewport = new CBaseViewport;
		m_pViewport->Start( gameuifuncs, gameeventmanager );
		m_pViewport->SetName( "Skeleton viewport" );
		m_pViewport->SetBounds( 0, 0, ScreenWidth(), ScreenHeight() );

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

Notable members

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:If your screen has a grey wash over it, you've probably not called m_pViewport->SetPaintBackgroundEnabled(false).
See CHudChat.
See CBaseHudWeaponSelection.

Notable functions

Called before the main Init() function. Must create and set up m_pViewport (see minimum implementation).
This is the first stop for a usercmd. Always pass through to the player entity somewhere here!
See events.
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!
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.
Intercepts mouse movement. Created to accommodate a pair of binoculars..?
Allows the client to change the position of the camera. Handles third-person mode, but otherwise passes through to the player entity.

See also