aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/sixense/in_sixense.h
blob: eb56a8a37af92ef127b36732259ec45ef8f63b27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
//========= Copyright Valve Corporation, All rights reserved. ============//
#ifndef IN_SIXENSE_H
#define IN_SIXENSE_H

#include "mathlib/vector.h"
#include "vgui_controls/Frame.h"
#include "vgui_controls/Label.h"
#include "vgui_video.h"
#include "convar.h"
#include "usercmd.h"
#include "tier1/utlstring.h"
#include "GameEventListener.h"
#include "in_sixense_gesture_bindings.h"


#if defined( CLIENT_DLL )
class C_Portal_Player;
#define CPortal_Player C_Portal_Player
#else
class CPortal_Player;
#endif

// forward declarations
namespace sixenseUtils {
	class IFPSViewAngles;
	class IFPSPlayerMovement;
	class IFPSEvents;
	class IFPSMeleeWeapon;

	class IDerivatives;
	class IButtonStates;
	class ILaserPointer;

	class IControllerManager;
};

class SixenseInput : public CGameEventListener
{

public:
	bool LoadModules();
	bool UnloadModules();

	SixenseInput();
	~SixenseInput();


	void Init();
	void PostInit();
	void Shutdown();
#ifdef PORTAL2
	bool IsBaseWarningUp();
	void PlayerPortalled( const VMatrix &PortalMatrix );
	void SetOneToOneMode( bool bOnOrOff );

	inline QAngle GetAnglesToRightHand() { return m_AnglesToRightHand; }
	inline QAngle GetAnglesToLeftHand() { return m_AnglesToLeftHand; }

	// If the right trigger is held and a melee weapon is selected, go to 1-to-1 melee mode
	bool IsInOneToOneMode();
	bool IsInAlwaysOneToOneMode();

	void FixPortalView();
	void SetPortalTweakingParameters( bool bIsTweaking );

	bool IsHoldingObject();

	C_BaseEntity *GetHeldObject();
#endif

	bool IsEnabled();
	bool IsLeftHanded();

	// SixenseFrame computes the view parameters from the controllers. Should be called once per frame
	bool SixenseFrame( float flFrametime, CUserCmd *pCmd );
	void SixenseUpdateKeys( float flFrametime, CUserCmd *pCmd );

	bool SendKeyToActiveWindow(ButtonCode_t key);
	void SixenseUpdateMouseCursor();
	void SixenseUpdateControllerManager();
	void controllerManagerCallback( int );
	inline void ResetFrameTime( float flTime ) { m_fRemainingFrameTime = flTime; }

	// Set the engine's view angles
	void SetView( float flInputSampleFrametime, CUserCmd *pCmd );
	void SetMode( int nMode );
	void ResetView( QAngle SpawnAngles );
	void SetEnabled( bool bEnabled );
	void LoadDefaultSettings( int nLevel );
	bool InMenuMode();


	QAngle GetViewAngles();
	QAngle GetViewAngleOffset();

	void ForceViewAngles( QAngle angles );
	bool IsSixenseMap();
	void CreateGUI( vgui::VPANEL parent );
	void SwitchViewModes( CUserCmd *pCmd );

	// playerIndex = (0 to 3), handIndex = (left = 0 or right = 1)
	void Rumble( unsigned char nIndex, unsigned char nRumbleData, unsigned char nRumbleFlags );
	void Rumble( unsigned char nPlayerIndex, unsigned char nHandIndex, unsigned char nRumbleData, unsigned char nRumbleFlags );

	void SetFilter( float f );
	void GetFOV( float *pHfov, float *pVfov );

#ifdef SIXENSE_PLAYER_DATA
	void SetPlayerHandPositions( CUserCmd *pCmd, float flFrametime );
#endif

	void SetBaseOffset();
	void SetFilterLevel( float flNearRange, float flNearVal, float flFarRange, float flFarVal );

	static class SixenseGUIFrame *m_SixenseFrame;

	bool IsAimingForwards();



	virtual void FireGameEvent( IGameEvent *pEvent );

	void BlendView();

	void DisableFreeAimSpin( int nDisable );
	void DisableGestures( int nDisable );
	void PlayerSpawn();
	bool AreBindingsDisabled();

	void LeftPointGesture( bool start );
	void RightPointGesture( bool start );

	void StartRatchet();
	void StopRatchet();

	void CheckWeaponForScope();

	SixenseGestureBindings *GetGestureBindings();

	void InstallConvarCallbacks();
	void UpdateValuesFromConvars();
	void ConvarChanged();

private:

	bool m_bIsEnabled; // sixense.dll loaded
	bool m_bIsActive; // controllers not docked

	bool m_bModulesLoaded;

	bool m_bWasInMenuMode;

#ifdef PORTAL2
	bool m_bJustPortalled;

	bool m_bIsLeftTriggerDown;
	bool m_bIsRightTriggerDown;

	bool m_bIsIn1to1Mode;
	bool m_bIs1to1ModeLocked;
	bool m_bIs1to1ModeScaling;
	bool m_bIs1to1ModeRatcheting;

	bool m_bExitOneWhenAimingForwards;
	bool m_bScalingLockedOneToOne;

	bool m_bIsTweaking;

	float m_fDisableJumpUntil;

	int m_nGlowIndex;

	float m_fLastHorizSpeedMult;
	float m_fLastVertSpeedMult;

	QAngle m_AnglesToRightHand, m_AnglesToLeftHand;

	float m_fTweakSixenseAimFreeaimAccelBandExponent;
	float m_fTweakSixenseAimFreeaimAutoLevelRate;
	float m_fTweakSixenseAimFreeaimAccelBandSize;
	float m_fTweakSixenseAimFreeaimMaxSpeed;
	float m_fTweakSixenseAimFreeaimDeadZoneRadius;
	float m_fTweakSixenseAimFreeaimHeadingMultiplier;
	float m_fTweakSixenseAimFreeaimPitchMultiplier;
	float m_fTweakSixenseAim1to1HeadingMultiplier;
	float m_fTweakSixenseAim1to1PitchMultiplier;

	Vector3 m_GrabPos;
#endif

	bool m_bConvarChanged;

	bool m_bPlayerValid;
	
	float m_fRemainingFrameTime;

	bool m_bScopeSwitchedMode;
	sixenseUtils::IFPSViewAngles::fps_mode m_nScopeSwitchedPrevMode;
	int m_nScopeSwitchedPrevSpringViewEnabled;

	float m_fTeleportWaitToBlendTime;

	class ISixenseAPI *m_pSixenseAPI;

	struct _sixenseAllControllerData *m_pACD;

	class sixenseUtils::IFPSViewAngles *m_pFPSViewAngles;
	class sixenseUtils::IFPSPlayerMovement *m_pFPSPlayerMovement;
	class sixenseUtils::IFPSEvents *m_pFPSEvents;

	class sixenseUtils::IDerivatives *m_pLeftDeriv, *m_pRightDeriv;
	class sixenseUtils::IButtonStates *m_pLeftButtonStates, *m_pRightButtonStates;
	class sixenseUtils::ILaserPointer *m_pLaserPointer;

	class sixenseUtils::IControllerManager *m_pControllerManager;

	int m_LastViewMode;
	int m_nLeftIndex, m_nRightIndex;

	void PlayerDroppedEntity( int entityID );
	void PlayerUsedEntity( int entityID );

	bool m_bMoveMouseToCenter;
	int m_nFilterLevel;
	unsigned char m_nLastLeftSequence, m_nLastRightSequence;
	bool m_bShouldSetBaseOffset;
	bool m_bJustSpawned;

#ifdef WATERMARK
	class SixenseWatermarkFrame *m_WatermarkFrame;
#endif

	int m_nFreeaimSpinDisabled;
	int m_nGesturesDisabled;

	bool m_nShouldUnduck;

	SixenseGestureBindings *m_pGestureBindings;
};

extern SixenseInput *g_pSixenseInput;


class SixenseGUIFrame : public vgui::Frame
{
	DECLARE_CLASS_SIMPLE( SixenseGUIFrame, vgui::Frame );

public:

	// Construction
	SixenseGUIFrame( vgui::VPANEL parent, char const *pPanelName );
	virtual ~SixenseGUIFrame();

	void setImage( CUtlString img_name );

	virtual void SetVisible( bool bState );

private:

	vgui::ImagePanel *m_ImagePanel;

};

#ifdef PORTAL2
class SixenseBaseWarning : public vgui::Frame
{
	DECLARE_CLASS_SIMPLE( SixenseBaseWarning, vgui::Frame );
public:
	SixenseBaseWarning( vgui::Panel *parent, char const *name );
	//virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
protected:
	//virtual void PaintBackground();
	virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
	vgui::Label *_label;
};
#endif

#endif