OpenBarnyard
 
Loading...
Searching...
No Matches
TInputInterface.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TInputInterface.h"
4#include "TInputDeviceMouse.h"
5
6//-----------------------------------------------------------------------------
7// Enables memory debugging.
8// Note: Should be the last include!
9//-----------------------------------------------------------------------------
10#include "Core/TMemoryDebugOn.h"
11
13
15
16// $Barnyard: FUNCTION 006c3fd0
18{
19 if ( m_DeviceList.Count() == 0 )
20 {
21 return TNULL;
22 }
23
24 for ( auto it = m_DeviceList.Begin(); it != m_DeviceList.End(); ++it )
25 {
26 if ( it->GetClass()->IsA( a_pClass ) )
27 {
28 if ( a_uiIndex == 0 )
29 {
30 return it;
31 }
32 else
33 {
34 a_uiIndex -= 1;
35 }
36 }
37 }
38
39 return TNULL;
40}
41
42// $Barnyard: FUNCTION 006c3f80
44{
45 if ( device != TNULL )
46 {
47 m_DeviceList.InsertTail( device );
48 device->SetInputInterface( this );
49 }
50}
51
52// $Barnyard: FUNCTION 006c3d50
54{
55 if ( device != TNULL )
56 {
57 m_DeviceList.Remove( device );
58 device->SetInputInterface( TNULL );
59 }
60}
61
62// $Barnyard: FUNCTION 006c3e10
64{
65 TBOOL bResult = TTRUE;
66
67 for ( auto it = m_DeviceList.Begin(); it != m_DeviceList.End(); ++it )
68 {
69 bResult &= it->Acquire();
70 }
71
72 return bResult;
73}
74
75// $Barnyard: FUNCTION 006c3e50
77{
78 TBOOL bResult = TTRUE;
79
80 for ( auto it = m_DeviceList.Begin(); it != m_DeviceList.End(); ++it )
81 {
82 bResult &= it->Unacquire();
83 }
84
85 return bResult;
86}
87
88// $Barnyard: FUNCTION 006c3e90
90{
91 TBOOL bResult = TTRUE;
92
93 for ( auto it = m_DeviceList.Begin(); it != m_DeviceList.End(); ++it )
94 {
95 bResult &= it->Flush();
96 }
97
98 return bResult;
99}
100
101// $Barnyard: FUNCTION 006c3cb0
103{
104 m_bIsExclusiveMode = a_bIsExclusive;
105}
106
107// $Barnyard: FUNCTION 006c3cc0
109{
110 return m_bIsExclusiveMode;
111}
112
113// $Barnyard: FUNCTION 006c3ed0
115{
116 TINT iNumProcessed = 0;
117
118 for ( auto it = m_DeviceList.Begin(); it != m_DeviceList.End(); ++it )
119 {
120 if ( it->IsAcquired() )
121 {
122 it->Update( a_fDeltaTime );
123 }
124 }
125
126 for ( auto it = m_DeviceList.Begin(); it != m_DeviceList.End(); ++it )
127 {
128 if ( it->IsAcquired() )
129 {
130 iNumProcessed += it->ProcessEvents( m_InputEventEmitter, a_fDeltaTime );
131 }
132 }
133
134 return iNumProcessed;
135}
136
137// $Barnyard: FUNCTION 006c3f50
139{
140 for ( auto it = m_DeviceList.Begin(); it != m_DeviceList.End(); ++it )
141 {
142 it->StopAllRepeats();
143 }
144}
145
146// $Barnyard: FUNCTION 006c3d90
148{
149 for ( auto it = m_DeviceList.Begin(); it != m_DeviceList.End(); ++it )
150 {
151 it->Unacquire();
152 it->Release();
153 it->Remove();
154 delete it.Get();
155 }
156}
157
158// $Barnyard: FUNCTION 006c4030
160 : m_InputEventEmitter( this )
161{
162 m_bIsExclusiveMode = TFALSE;
163}
164
165// $Barnyard: FUNCTION 006c4080
169
170// $Barnyard: FUNCTION 006c3ba0
172{
173 m_pSource = a_pDevice;
174 m_iDoodad = a_iDoodad;
175 m_eEventType = a_eEventType;
177 m_iAxisCount = 0;
178 m_wszString[ 0 ] = L'\0';
179}
180
181TInputInterface::InputEvent::InputEvent( TInputDevice* a_pDevice, TINT a_iDoodad, EVENT_TYPE a_eEventType, TWCHAR* a_wszString )
182{
183 m_pSource = a_pDevice;
184 m_iDoodad = a_iDoodad;
185 m_eEventType = a_eEventType;
187 m_iAxisCount = 0;
188 TStringManager::String16Copy( m_wszString, a_wszString, 3 );
189 m_Magnitude.Ints[ 0 ] = 0;
190}
191
192TInputInterface::InputEvent::InputEvent( TInputDevice* a_pDevice, TINT a_iDoodad, EVENT_TYPE a_eEventType, TINT a_iMagnitude1 )
193{
194 m_pSource = a_pDevice;
195 m_iDoodad = a_iDoodad;
196 m_eEventType = a_eEventType;
197 m_Magnitude.Ints[ 0 ] = a_iMagnitude1;
199 m_iAxisCount = 1;
200 m_wszString[ 0 ] = L'\0';
201}
202
203// $Barnyard: FUNCTION 006c3c50
204TInputInterface::InputEvent::InputEvent( TInputDevice* a_pDevice, TINT a_iDoodad, EVENT_TYPE a_eEventType, TINT a_iMagnitude1, TINT a_iMagnitude2 )
205{
206 m_pSource = a_pDevice;
207 m_iDoodad = a_iDoodad;
208 m_eEventType = a_eEventType;
209 m_Magnitude.Ints[ 0 ] = a_iMagnitude1;
210 m_Magnitude.Ints[ 1 ] = a_iMagnitude2;
212 m_iAxisCount = 2;
213 m_wszString[ 0 ] = L'\0';
214}
215
216TInputInterface::InputEvent::InputEvent( TInputDevice* a_pDevice, TINT a_iDoodad, EVENT_TYPE a_eEventType, TFLOAT a_fMagnitude1 )
217{
218 m_pSource = a_pDevice;
219 m_iDoodad = a_iDoodad;
220 m_eEventType = a_eEventType;
221 m_Magnitude.Floats[ 0 ] = a_fMagnitude1;
223 m_iAxisCount = 1;
224 m_wszString[ 0 ] = L'\0';
225}
226
227// $Barnyard: FUNCTION 006c3c10
228TInputInterface::InputEvent::InputEvent( TInputDevice* a_pDevice, TINT a_iDoodad, EVENT_TYPE a_eEventType, TFLOAT a_fMagnitude1, TFLOAT a_fMagnitude2 )
229{
230 m_pSource = a_pDevice;
231 m_iDoodad = a_iDoodad;
232 m_eEventType = a_eEventType;
233 m_Magnitude.Floats[ 0 ] = a_fMagnitude1;
234 m_Magnitude.Floats[ 1 ] = a_fMagnitude2;
236 m_iAxisCount = 2;
237 m_wszString[ 0 ] = L'\0';
238}
239
241{
242 TASSERT( a_iAxis >= 0 && a_iAxis < GetAxisCount() );
243
244 if ( IsMagnitudeInt() )
245 {
246 return m_Magnitude.Ints[ a_iAxis ];
247 }
248 else
249 {
250 if ( m_Magnitude.Floats[ a_iAxis ] < -0.5f )
251 {
252 return -1;
253 }
254
255 return 0.5f < m_Magnitude.Floats[ a_iAxis ];
256 }
257}
258
259// $Barnyard: FUNCTION 006c3c90
261{
262 TASSERT( a_iAxis >= 0 && a_iAxis < GetAxisCount() );
263
264 if ( IsMagnitudeFloat() )
265 {
266 return m_Magnitude.Floats[ a_iAxis ];
267 }
268
269 return (TFLOAT)m_Magnitude.Ints[ a_iAxis ];
270}
271
272// $Barnyard: FUNCTION 006c3cd0
273TBOOL TInputInterface::InputEvent::StartRepeat( TFLOAT a_fFirstRepeatTime, TFLOAT a_fRepeatTime ) const
274{
275 return m_pSource->StartRepeat( m_iDoodad, a_fFirstRepeatTime, a_fRepeatTime );
276}
277
Keyboard input device for the Toshi engine.
Mouse input device for the Toshi engine.
Input system interface for the Toshi engine.
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TDEFINE_CLASS_NORUNTIME(...)
Definition TObject.h:138
wchar_t TWCHAR
Definition Typedefs.h:21
unsigned int TUINT
Definition Typedefs.h:8
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TInputDevice * GetDeviceByIndex(TClass *a_pClass, TUINT a_uiIndex)
virtual TBOOL GetExclusiveMode() const
virtual TINT ProcessEvents(TFLOAT a_fDeltaTime)
virtual void SetExclusiveMode(TBOOL a_bIsExclusive)
void RemoveDevice(TInputDevice *device)
virtual TBOOL AcquireAll()
virtual TBOOL FlushAll()
void AddDevice(TInputDevice *device)
virtual TBOOL UnacquireAll()
virtual void StopAllRepeats()
union TInputInterface::InputEvent::@331074113164076150144143322340042066145372056013 m_Magnitude
TBOOL StartRepeat(TFLOAT a_fFirstRepeatTime=0.5f, TFLOAT a_fRepeatTime=0.1f) const
InputEvent(TInputDevice *a_pDevice, TINT a_iDoodad, EVENT_TYPE a_eEventType)
TFLOAT GetMagnitudeFloat(TINT a_iAxis) const
TINT GetMagnitudeInt(TINT a_iAxis) const
void SetInputInterface(TInputInterface *a_pInterface)
Definition TClass.h:8
static TWCHAR * String16Copy(TWCHAR *dst, const TWCHAR *src, TSIZE size=-1)