OpenBarnyard
 
Loading...
Searching...
No Matches
AInputMapManager Class Reference

#include <AInputMapManager.h>

Inheritance diagram for AInputMapManager:

Classes

struct  Command
 

Public Types

enum  InputEvent : TUINT32 {
  InputEvent_None = 0 , InputEvent_GoneDown = ( 1U << ( Toshi::TInputInterface::EVENT_TYPE_GONE_DOWN ) ) , InputEvent_GoneUp = ( 1U << ( Toshi::TInputInterface::EVENT_TYPE_GONE_UP ) ) , InputEvent_Repeat = ( 1U << ( Toshi::TInputInterface::EVENT_TYPE_REPEAT ) ) ,
  InputEvent_Virtual = ( 1U << ( Toshi::TInputInterface::EVENT_TYPE_VIRTUAL ) ) , InputEvent_Moved = ( 1U << ( Toshi::TInputInterface::EVENT_TYPE_MOVED ) )
}
 
using ThisClass = AInputMapManager
 
using BaseClass = Toshi::TObject
 
using ActionId = TUINT32
 

Public Member Functions

virtual Toshi::TClass * GetClass () override
 
 AInputMapManager ()
 
TBOOL ReadControlsData ()
 
void PushInputMap (AInputMap *a_pInputMap)
 
AInputMapPopInputMap ()
 
AInputMapFindMap (const Toshi::TPString8 &a_rMapName)
 
TBOOL SetMap (const Toshi::TPString8 &a_rMapName)
 
void GetEventCommands (const Toshi::TInputInterface::InputEvent *a_pEvent, AInputCommandArray &a_rCommandArray)
 
AInputCommand GetCommandCode (const Toshi::TPString8 &a_rCommandName)
 
Toshi::TInputDevice::Doodad GetDoodadFromKey (const Toshi::TPString8 &a_rKey)
 

Static Public Member Functions

static Toshi::TObject * CreateTObject ()
 
static Toshi::TObject * CreateTObjectInPlace (void *a_pPtr)
 
static void InitialiseClass ()
 
static void DeinitialiseClass ()
 
static __forceinline Toshi::TClass * GetClassStatic ()
 

Static Public Attributes

static constexpr Toshi::TClass * PARENTCLASS = & Toshi::TObject::ms_oClass
 
static Toshi::TClass ms_oClass = Toshi::TClass( "AInputMapManager", AInputMapManager::PARENTCLASS, AInputMapManager::CreateTObject, AInputMapManager::CreateTObjectInPlace, AInputMapManager::InitialiseClass, AInputMapManager::DeinitialiseClass, 0, 1, sizeof( AInputMapManager ), alignof( AInputMapManager ) )
 
static constexpr TUINT MAX_NUM_INPUT_MAPS = 32
 

Detailed Description

Definition at line 35 of file AInputMapManager.h.

Member Typedef Documentation

◆ ActionId

Definition at line 41 of file AInputMapManager.h.

◆ BaseClass

using AInputMapManager::BaseClass = Toshi::TObject

Definition at line 39 of file AInputMapManager.h.

◆ ThisClass

Member Enumeration Documentation

◆ InputEvent

Enumerator
InputEvent_None 
InputEvent_GoneDown 
InputEvent_GoneUp 
InputEvent_Repeat 
InputEvent_Virtual 
InputEvent_Moved 

Definition at line 43 of file AInputMapManager.h.

44 {
46 InputEvent_GoneDown = BITFLAG( Toshi::TInputInterface::EVENT_TYPE_GONE_DOWN ),
47 InputEvent_GoneUp = BITFLAG( Toshi::TInputInterface::EVENT_TYPE_GONE_UP ),
48 InputEvent_Repeat = BITFLAG( Toshi::TInputInterface::EVENT_TYPE_REPEAT ),
49 InputEvent_Virtual = BITFLAG( Toshi::TInputInterface::EVENT_TYPE_VIRTUAL ),
50 InputEvent_Moved = BITFLAG( Toshi::TInputInterface::EVENT_TYPE_MOVED ),
51 };
#define BITFLAG(x)
Definition Defines.h:10

Constructor & Destructor Documentation

◆ AInputMapManager()

AInputMapManager::AInputMapManager ( )

Definition at line 15 of file AInputMapManager.cpp.

16 : m_pActiveInputMap( TNULL ), m_iNumPushedInputMaps( 0 ), m_oDoodadToNameMap( AMemory::GetAllocator( AMemory::POOL_Misc ) ), m_oKeyMap( AMemory::GetAllocator( AMemory::POOL_Misc ) ), m_oCommandMap( AMemory::GetAllocator( AMemory::POOL_Misc ) ), m_UnkMap( AMemory::GetAllocator( AMemory::POOL_Misc ) )
17{
18 InitMouseDoodads();
19 InitKeyboardDoodads();
20 InitGamepadDoodads();
21 InitCommandMap();
22}
#define TNULL
Definition Typedefs.h:23
@ POOL_Misc
Definition AMemory.h:35
static Toshi::T2Allocator * GetAllocator(POOL a_ePool)
Definition AMemory.cpp:31

Member Function Documentation

◆ CreateTObject()

Toshi::TObject * AInputMapManager::CreateTObject ( )
static

Definition at line 13 of file AInputMapManager.cpp.

◆ CreateTObjectInPlace()

Toshi::TObject * AInputMapManager::CreateTObjectInPlace ( void * a_pPtr)
static

Definition at line 13 of file AInputMapManager.cpp.

◆ DeinitialiseClass()

void AInputMapManager::DeinitialiseClass ( )
static

Definition at line 13 of file AInputMapManager.cpp.

◆ FindMap()

AInputMap * AInputMapManager::FindMap ( const Toshi::TPString8 & a_rMapName)

Definition at line 83 of file AInputMapManager.cpp.

84{
85 for ( auto it = m_InputMaps.Begin(); it != m_InputMaps.End(); it++ )
86 {
87 if ( ( *it )->GetName() == a_rMapName )
88 {
89 return *it;
90 }
91 }
92
93 return TNULL;
94}

◆ GetClass()

Toshi::TClass * AInputMapManager::GetClass ( )
overridevirtual

Definition at line 13 of file AInputMapManager.cpp.

◆ GetClassStatic()

static __forceinline Toshi::TClass * AInputMapManager::GetClassStatic ( )
inlinestatic

Definition at line 39 of file AInputMapManager.h.

◆ GetCommandCode()

AInputCommand AInputMapManager::GetCommandCode ( const Toshi::TPString8 & a_rCommandName)

Definition at line 145 of file AInputMapManager.cpp.

146{
147 for ( auto it = m_oCommandMap.Begin(); it != m_oCommandMap.End(); it++ )
148 {
149 if ( it->GetSecond().Name == a_rCommandName )
150 {
151 return it->GetFirst();
152 }
153 }
154
156}
@ AInputCommand_Unknown
Definition AInputMap.h:13

◆ GetDoodadFromKey()

Toshi::TInputDevice::Doodad AInputMapManager::GetDoodadFromKey ( const Toshi::TPString8 & a_rKey)

Definition at line 158 of file AInputMapManager.cpp.

159{
160 for ( auto it = m_oDoodadToNameMap.Begin(); it != m_oDoodadToNameMap.End(); it++ )
161 {
162 if ( it->GetSecond() == a_rKey )
163 {
164 return it->GetFirst();
165 }
166 }
167
168 return -1;
169}

◆ GetEventCommands()

void AInputMapManager::GetEventCommands ( const Toshi::TInputInterface::InputEvent * a_pEvent,
AInputCommandArray & a_rCommandArray )

Definition at line 105 of file AInputMapManager.cpp.

106{
107 a_rCommandArray.Clear();
108
109 if ( m_pActiveInputMap )
110 {
111 auto pCommandMap = &m_pActiveInputMap->GetCommandMap();
112 auto pCommandIndexRes = pCommandMap->Find( a_pEvent->GetDoodad() );
113
114 while ( pCommandMap->IsValid( pCommandIndexRes ) )
115 {
116 auto pCommandRes = m_oCommandMap.Find( pCommandIndexRes->GetSecond() );
117 TBOOL bCommandValid;
118
119 if ( m_oCommandMap.IsValid( pCommandRes ) )
120 {
121 bCommandValid = TTRUE;
122 auto command = pCommandRes->GetSecond();
123
124 if ( !command.IsEventTypeAllowed( a_pEvent->GetEventType() ) )
125 {
126 bCommandValid = TFALSE;
127 }
128 }
129 else
130 {
131 bCommandValid = TFALSE;
132 }
133
134 if ( bCommandValid )
135 {
136 a_rCommandArray.AddCommand( pCommandIndexRes->GetSecond() );
137 }
138
139 // Look if there are any other commands binded to this doodad
140 pCommandIndexRes = pCommandMap->FindNext( pCommandIndexRes, a_pEvent->GetDoodad() );
141 }
142 }
143}
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
void AddCommand(AInputCommand a_eCommand)

◆ InitialiseClass()

void AInputMapManager::InitialiseClass ( )
static

Definition at line 13 of file AInputMapManager.cpp.

◆ PopInputMap()

AInputMap * AInputMapManager::PopInputMap ( )

Definition at line 74 of file AInputMapManager.cpp.

75{
76 TASSERT( m_iNumPushedInputMaps > 0 );
77 m_iNumPushedInputMaps = Toshi::TMath::Max( m_iNumPushedInputMaps - 1, 0 );
78
79 m_pActiveInputMap = ( m_iNumPushedInputMaps != 0 ) ? m_apPushedInputMaps[ m_iNumPushedInputMaps - 1 ] : TNULL;
80 return m_apPushedInputMaps[ m_iNumPushedInputMaps - 1 ];
81}
#define TASSERT(X,...)
Definition Defines.h:138

◆ PushInputMap()

void AInputMapManager::PushInputMap ( AInputMap * a_pInputMap)

Definition at line 61 of file AInputMapManager.cpp.

62{
63 TASSERT( m_iNumPushedInputMaps < MAX_NUM_INPUT_MAPS );
64 m_iNumPushedInputMaps++;
65
66 if ( m_iNumPushedInputMaps < 32 )
67 {
68 m_apPushedInputMaps[ m_iNumPushedInputMaps - 1 ] = a_pInputMap;
69 }
70
71 m_pActiveInputMap = a_pInputMap;
72}
static constexpr TUINT MAX_NUM_INPUT_MAPS

◆ ReadControlsData()

TBOOL AInputMapManager::ReadControlsData ( )

Definition at line 24 of file AInputMapManager.cpp.

25{
26 TString8 controlsFilePath;
27 controlsFilePath.Format( "Data/Options/%s.trb", "Controls_Win" );
28
29 TTRB trb;
30 auto eLoadResult = trb.Load( controlsFilePath );
31
32 if ( eLoadResult != TTRB::ERROR_OK )
33 {
34 return TFALSE;
35 }
36
37 auto properties = PBProperties::LoadFromTRB( trb );
38
39 while ( m_InputMaps.Size() != 0 )
40 {
41 auto pInputMap = m_InputMaps.Back();
42 m_InputMaps.PopBack();
43
44 if ( pInputMap )
45 {
46 delete pInputMap;
47 }
48 }
49
50 for ( auto it = properties->Begin(); it != properties->End(); it++ )
51 {
52 auto pInputMap = new AInputMap( TPString8( it->GetName().GetString() ) );
53
54 pInputMap->LoadFromProperties( *it->GetValue()->GetProperties() );
55 m_InputMaps.PushBack( pInputMap );
56 }
57
58 return TTRUE;
59}
ERROR Load(const TCHAR *a_szFilePath, TUINT32 a_uiUnknown=0)
Definition TTRB.cpp:38
@ ERROR_OK
Definition TTRB.h:258
TString8 & Format(const TCHAR *a_pcFormat,...)
Definition TString8.cpp:176

◆ SetMap()

TBOOL AInputMapManager::SetMap ( const Toshi::TPString8 & a_rMapName)

Definition at line 96 of file AInputMapManager.cpp.

97{
98 auto pMap = FindMap( a_rMapName );
99 if ( !pMap ) return TFALSE;
100
101 m_pActiveInputMap = pMap;
102 return TTRUE;
103}
AInputMap * FindMap(const Toshi::TPString8 &a_rMapName)

Member Data Documentation

◆ MAX_NUM_INPUT_MAPS

TUINT AInputMapManager::MAX_NUM_INPUT_MAPS = 32
staticconstexpr

Definition at line 65 of file AInputMapManager.h.

◆ ms_oClass

Definition at line 39 of file AInputMapManager.h.

◆ PARENTCLASS

Toshi::TClass* AInputMapManager::PARENTCLASS = & Toshi::TObject::ms_oClass
staticconstexpr

Definition at line 39 of file AInputMapManager.h.


The documentation for this class was generated from the following files: