Oolite
Loading...
Searching...
No Matches
OOSDLJoystickManager Class Reference

#include <OOSDLJoystickManager.h>

+ Inheritance diagram for OOSDLJoystickManager:
+ Collaboration diagram for OOSDLJoystickManager:

Instance Methods

(id) - init
 
(void) - dealloc
 
(BOOL) - handleSDLEvent:
 
(NSString *) - nameOfJoystick:
 
(int16_t) - getAxisWithStick:axis:
 
(JoyAxisEvent- makeJoyAxisEvent:
 
(JoyButtonEvent- makeJoyButtonEvent:
 
(JoyHatEvent- makeJoyHatEvent:
 
(NSInteger) - getJoystickIndexFromId:
 
(NSUInteger) - joystickCount [implementation]
 
- Instance Methods inherited from OOJoystickManager
(NSPoint) - rollPitchAxis
 
(NSPoint) - viewAxis
 
(void) - setFunction:withDict:
 
(void) - unsetAxisFunction:
 
(void) - unsetButtonFunction:
 
(BOOL) - isButtonDown:stick:
 
(BOOL) - getButtonState:
 
(double) - getAxisState:
 
(double) - getSensitivity
 
(void) - setProfile:forAxis:
 
(OOJoystickAxisProfile *) - getProfileForAxis:
 
(void) - saveProfileForAxis:
 
(void) - loadProfileForAxis:
 
(const BOOL *) - getAllButtonStates
 
(NSArray *) - listSticks
 
(NSDictionary *) - axisFunctions
 
(NSDictionary *) - buttonFunctions
 
(void) - setCallback:object:hardware:
 
(void) - clearCallback
 
(void) - setDefaultMapping
 
(void) - clearMappings
 
(void) - clearStickStates
 
(void) - clearStickButtonState:
 
(void) - decodeAxisEvent:
 
(void) - decodeButtonEvent:
 
(void) - decodeHatEvent:
 
(void) - saveStickSettings
 
(void) - loadStickSettings
 
(void) - setFunctionForAxis:function:stick: [implementation]
 
(void) - setFunctionForButton:function:stick: [implementation]
 

Private Attributes

NSDictionary * joystickIdMap
 
SDL_Joystick * stick [MAX_STICKS]
 
int stickCount
 

Additional Inherited Members

- Class Methods inherited from OOJoystickManager
(id) + sharedStickHandler
 
(BOOL) + setStickHandlerClass:
 

Detailed Description

Definition at line 45 of file OOSDLJoystickManager.h.

Method Documentation

◆ dealloc

- (void) dealloc

Definition at line 1 of file OOSDLJoystickManager.m.

76{
77 [joystickIdMap release];
78 [super dealloc];
79}

◆ getAxisWithStick:axis:

- (int16_t) getAxisWithStick: (NSUInteger)  stickNum
axis: (NSUInteger)  axisNum 

Reimplemented from OOJoystickManager.

Definition at line 1 of file OOSDLJoystickManager.m.

189 :(NSUInteger) stickNum axis:(NSUInteger) axisNum
190{
191 return SDL_GetJoystickAxis(stick[stickNum], axisNum);
192}
SDL_Joystick * stick[MAX_STICKS]

◆ getJoystickIndexFromId:

- (NSInteger) getJoystickIndexFromId: (SDL_JoystickID)  joystickId

Definition at line 1 of file OOSDLJoystickManager.m.

82 : (SDL_JoystickID) joystickId
83{
84 NSNumber *index = [joystickIdMap valueForKey: [NSString stringWithFormat: @"%d", joystickId]];
85 if (index)
86 {
87 return [index integerValue];
88 }
89 return -1;
90}

◆ handleSDLEvent:

- (BOOL) handleSDLEvent: (SDL_Event *)  evt

Definition at line 1 of file OOSDLJoystickManager.m.

125 : (SDL_Event *)evt
126{
127 BOOL rc=NO;
128 switch(evt->type)
129 {
130 case SDL_EVENT_GAMEPAD_AXIS_MOTION:
131 case SDL_EVENT_JOYSTICK_AXIS_MOTION:
132 {
133 JoyAxisEvent joyEvt = [self makeJoyAxisEvent: (SDL_JoyAxisEvent*)evt];
134 if (joyEvt.which >= 0)
135 {
136 [self decodeAxisEvent: &joyEvt];
137 rc=YES;
138 }
139 break;
140 }
141
142 case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
143 case SDL_EVENT_GAMEPAD_BUTTON_UP:
144 case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
145 case SDL_EVENT_JOYSTICK_BUTTON_UP:
146 {
147 JoyButtonEvent joyEvt = [self makeJoyButtonEvent: (SDL_JoyButtonEvent*)evt];
148 if (joyEvt.which >= 0)
149 {
150 [self decodeButtonEvent: &joyEvt];
151 rc=YES;
152 }
153 break;
154 }
155
156 case SDL_EVENT_JOYSTICK_HAT_MOTION:
157 {
158 JoyHatEvent joyEvt = [self makeJoyHatEvent: (SDL_JoyHatEvent*)evt];
159 if (joyEvt.which >= 0)
160 {
161 [self decodeHatEvent: &joyEvt];
162 rc=YES;
163 }
164 break;
165 }
166
167 default:
168 OOLog(@"handleSDLEvent.unknownEvent", @"%@", @"JoystickHandler was sent an event it doesn't know");
169 }
170 return rc;
171}
#define OOLog(class, format,...)
Definition OOLogging.h:88

◆ init

- (id) init

Reimplemented from OOJoystickManager.

Definition at line 1 of file OOSDLJoystickManager.m.

35{
36 int i;
37
38 NSMutableDictionary *idMap = [[[NSMutableDictionary alloc] init] autorelease];
39
40 // Find and open the sticks. Make sure that we don't fail if more joysticks than MAX_STICKS are detected.
41 SDL_JoystickID *joystickIds = SDL_GetJoysticks(&stickCount);
42 OOLog(@"joystick.init", @"Number of joysticks detected: %d", stickCount);
44 {
46 OOLog(@"joystick.init", @"Number of joysticks detected exceeds maximum number of joysticks allowed. Setting number of active joysticks to %d.", MAX_STICKS);
47 }
48 if(stickCount)
49 {
50 for(i = 0; i < stickCount; i++)
51 {
52 // it's doubtful MAX_STICKS will ever get exceeded, but
53 // we need to be defensive.
54 if(i > MAX_STICKS)
55 break;
56
57 stick[i]=SDL_OpenJoystick(joystickIds[i]);
58 if(stick[i])
59 {
60 [idMap setObject: [NSNumber numberWithInt: i] forKey: [NSString stringWithFormat: @"%d", joystickIds[i]]];
61 }
62 else
63 {
64 OOLog(@"joystick.init", @"Failed to open joystick #%d", i);
65 }
66 }
67 SDL_SetJoystickEventsEnabled(true);
68 }
69 SDL_free(joystickIds);
70 joystickIdMap = [idMap copy];
71 return [super init];
72}
#define MAX_STICKS

◆ joystickCount

- (NSUInteger) joystickCount
implementation

Reimplemented from OOJoystickManager.

Definition at line 1 of file OOSDLJoystickManager.m.

177{
178 return stickCount;
179}

◆ makeJoyAxisEvent:

- (JoyAxisEvent) makeJoyAxisEvent: (SDL_JoyAxisEvent*)  sdlevt

Definition at line 1 of file OOSDLJoystickManager.m.

93 : (SDL_JoyAxisEvent*) sdlevt
94{
95 JoyAxisEvent evt;
96 evt.type = sdlevt->type;
97 evt.which = [self getJoystickIndexFromId: sdlevt->which];
98 evt.axis = sdlevt->axis;
99 evt.value = sdlevt->value;
100 return evt;
101}

◆ makeJoyButtonEvent:

- (JoyButtonEvent) makeJoyButtonEvent: (SDL_JoyButtonEvent*)  sdlevt

Definition at line 1 of file OOSDLJoystickManager.m.

103 : (SDL_JoyButtonEvent*) sdlevt
104{
105 JoyButtonEvent evt;
106 evt.type = sdlevt->type;
107 evt.which = [self getJoystickIndexFromId: sdlevt->which];
108 evt.button = sdlevt->button;
109 evt.down = sdlevt->down;
110 return evt;
111}

◆ makeJoyHatEvent:

- (JoyHatEvent) makeJoyHatEvent: (SDL_JoyHatEvent*)  sdlevt

Definition at line 1 of file OOSDLJoystickManager.m.

114 : (SDL_JoyHatEvent*) sdlevt
115{
116 JoyHatEvent evt;
117 evt.type = sdlevt->type;
118 evt.which = [self getJoystickIndexFromId: sdlevt->which];
119 evt.hat = sdlevt->hat;
120 evt.value = sdlevt->value;
121 return evt;
122}

◆ nameOfJoystick:

- (NSString *) nameOfJoystick: (NSUInteger)  stickNumber

Reimplemented from OOJoystickManager.

Definition at line 1 of file OOSDLJoystickManager.m.

182 :(NSUInteger)stickNumber
183{
184 if (stickNumber >= stickCount) return @"(unknown joystick)";
185 return [NSString stringWithUTF8String:SDL_GetJoystickName(stick[stickNumber])];
186}

Member Data Documentation

◆ joystickIdMap

- (NSDictionary*) joystickIdMap
private

Definition at line 48 of file OOSDLJoystickManager.h.

◆ stick

- (SDL_Joystick* stick[MAX_STICKS])
private

Definition at line 49 of file OOSDLJoystickManager.h.

◆ stickCount

- (int) stickCount
private

Definition at line 50 of file OOSDLJoystickManager.h.


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