Skip to content

Commit

Permalink
Updated the Joypad SDK to the latest post-0.1.5.1 version.
Browse files Browse the repository at this point in the history
  • Loading branch information
alinebee committed Jan 9, 2012
1 parent 955de0b commit 11d1faf
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 137 deletions.
4 changes: 2 additions & 2 deletions Boxer/BXInputController+BXJoypadInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
//The BXJoypadInput category handles JoyPad iOS app input passed on from BXJoypadController.

#import "BXInputController.h"
#import "JoypadSDK.h"

@class JoypadControllerLayout;
@interface BXInputController (BXJoypadInput)
@interface BXInputController (BXJoypadInput) <JoypadDeviceDelegate, JoypadManagerDelegate>

//Returns a custom Joypad layout appropriate for the currently-selected joystick type.
@property (readonly, nonatomic) JoypadControllerLayout *currentJoypadLayout;
Expand Down
4 changes: 2 additions & 2 deletions Boxer/BXInputController+BXJoypadInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#define BXJoypadRotationDeadzone 0.15f

//The maximum scale of movement for the analog stick.
//TODO: figure out what lies behind this constant.
#define BXJoypadAnalogStickMaxDistance 55.0f
//(used to be 55.0 in previous versions of the Joypad SDK, now normalised to 1.0.)
#define BXJoypadAnalogStickMaxDistance 1.0f

//What fraction of the accelerometer input to mix with the previous input,
//to derive a smoothed value. Used by joypadDevice:didAccelerate:.
Expand Down
8 changes: 3 additions & 5 deletions Boxer/BXJoypadController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
//q.v. http://getjoypad.com/ and https://github.com/lzell/JoypadSDK#readme

#import <Foundation/Foundation.h>
#import "JoypadSDK.h"

@class JoypadManager;
@class JoypadControllerLayout;

@interface BXJoypadController : NSObject
@interface BXJoypadController : NSObject <JoypadManagerDelegate>
{
JoypadManager *joypadManager;
BOOL suppressReconnectionNotifications;
BOOL isReconnectingDevices;
JoypadControllerLayout *currentLayout;
BOOL hasJoypadDevices;
}
Expand Down
73 changes: 38 additions & 35 deletions Boxer/BXJoypadController.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@ - (void) setCurrentLayout: (JoypadControllerLayout *)layout

if (layout)
{
[joypadManager useCustomLayout: layout];
[joypadManager setControllerLayout: layout];

//Disconnect and reconnect each device to make it notice the new layout
//(Remove this once Joypad SDK can handle on-the-fly layout changes)
suppressReconnectionNotifications = YES;
for (JoypadDevice *device in [joypadManager connectedDevices])
isReconnectingDevices = YES;
for (JoypadDevice *device in [self joypadDevices])
{
NSUInteger playerNum = [device playerNumber];
[device disconnect];
[joypadManager connectToDevice: device asPlayer: playerNum];
}
suppressReconnectionNotifications = NO;
isReconnectingDevices = NO;
}
}
}
Expand All @@ -63,6 +61,8 @@ - (void) awakeFromNib
{
joypadManager = [[JoypadManager alloc] init];
[joypadManager setDelegate: self];
[joypadManager setMaxPlayerCount: 1];

//Default to a 4-button layout (this may be overridden by any game the user starts)
[self setCurrentLayout: [BX4ButtonJoystickLayout layout]];
[joypadManager startFindingDevices];
Expand Down Expand Up @@ -120,65 +120,68 @@ - (void) observeValueForKeyPath: (NSString *)keyPath
else if ([keyPath isEqualToString: @"currentSession.DOSWindowController.inputController"])
{
//Rebind all connected devices to send their messages to the currently active session
for (JoypadDevice *device in [joypadManager connectedDevices])
for (JoypadDevice *device in [self joypadDevices])
{
[device setDelegate: [self activeWindowController]];
}
}
}

- (void) joypadManager: (JoypadManager *)manager
didFindDevice: (JoypadDevice *)device
previouslyConnected: (BOOL)wasConnected
//Called when JoypadManager discovers a device, but before any connection attempts are made:
//we flag at this point that we have joypad devices available, so that joystick emulation
//will be enabled as early as possible.
- (BOOL) joypadManager: (JoypadManager *)manager deviceShouldConnect: (JoypadDevice *)device
{
//Don't connect more than one device
if (![self hasJoypadDevices])
{
[joypadManager connectToDevice: device asPlayer: 1];
[self setHasJoypadDevices: YES];
}
//NOTE: this method is getting called erroneously after disconnection
//in Joypad SDK 0.15.2 preview.
//We can't detect this though, which means that Boxer won't recognise
//that the Joypad device has disappeared and that there is no longer
//any input controller present. Big deal.
[self setHasJoypadDevices: YES];
return YES;
}

- (void) joypadManager: (JoypadManager *)manager
didLoseDevice: (JoypadDevice *)device
{
if (![[self joypadDevices] count])
{
[self setHasJoypadDevices: NO];
}
}
- (void) joypadManager: (JoypadManager *)manager
deviceDidConnect: (JoypadDevice *)device
player: (unsigned int)player
{
[device setDelegate: [self activeWindowController]];
BXInputController *delegate = [self activeWindowController];
[device setDelegate: delegate];

//Avoid spamming observers whenever we disconnect and immediately reconnect a device
if (!suppressReconnectionNotifications)
if (!isReconnectingDevices)
{
[self setHasJoypadDevices: YES];

[self willChangeValueForKey: @"joypadDevices"];
[self didChangeValueForKey: @"joypadDevices"];
}

//Let the delegate know that the device has been connected
[[device delegate] joypadManager: manager
deviceDidConnect: device
player: player];
[delegate joypadManager: manager
deviceDidConnect: device
player: player];
}

- (void) joypadManager: (JoypadManager *)manager
deviceDidDisconnect: (JoypadDevice *)device
player: (unsigned int)player
{
{
//Avoid spamming observers whenever we disconnect and immediately reconnect a device
if (!suppressReconnectionNotifications)
if (!isReconnectingDevices)
{
BOOL devicesRemaining = [manager connectedDeviceCount] > 0;
[self setHasJoypadDevices: devicesRemaining];

[self willChangeValueForKey: @"joypadDevices"];
[self didChangeValueForKey: @"joypadDevices"];
}
//Let the device's delegate know that the device has been connected
[[device delegate] joypadManager: manager
deviceDidDisconnect: device
player: player];

BXInputController *delegate = (BXInputController *)[device delegate];

//Let the device's delegate know that the device has been disconnected
[delegate joypadManager: manager deviceDidDisconnect: device player: player];

[device setDelegate: nil];
}
@end
9 changes: 4 additions & 5 deletions Other Sources/JoypadCocoaSDK/JoypadConstants.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//
// JoypadConstants.h
// Joypad SDK
//
// Created by Lou Zell on 6/1/11.
// Copyright 2011 Hazelmade. All rights reserved.
// Copyright 2011 Joypad Inc. All rights reserved.
//
// Please email questions to me, Lou, at [email protected]
// Please email questions to [email protected]
// __________________________________________________________________________
//

typedef struct
Expand All @@ -26,8 +26,7 @@ typedef enum
kJoyInputTypeDpad,
kJoyInputTypeButton,
kJoyInputTypeAnalogStick,
kJoyInputTypeAccelerometer,
kJoyInputTypeWheel
kJoyInputTypeAccelerometer
}JoyInputType;

typedef enum
Expand Down
33 changes: 23 additions & 10 deletions Other Sources/JoypadCocoaSDK/JoypadControllerLayout.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
//
// JoypadControllerLayout.h
// Joypad SDK
//
// Created by Lou Zell on 3/14/11.
// Copyright 2011 Hazelmade. All rights reserved.
// Copyright 2011 Joypad Inc. All rights reserved.
//
// Please email questions to me, Lou, at [email protected]
// -----------------------------------------------------------------
// Please email questions to [email protected]
// __________________________________________________________________________
//
// Examples of several custom controllers can be found in MyJoypadLayout.m in
// the JoypadiOSSample project that comes with the SDK download.
//
// This is the class that you will use to create a custom layout for your
// application. Each method listed in the Public API section below adds
// one component to your controller. Currently, you can add:
//
// * Analog sticks
// * Re-centering analog sticks
// * Dpads
// * Buttons
// * Accelerometer Data (this components doesn't add a view)
//
// See the comments at the top of each method for instructions on using it.
//
// An example of building a custom controller from start to finish is in
// the README that comes with the SDK download, which is also at:
// http://getjoypad.com/sdk_doc.html
//

#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
Expand All @@ -39,6 +37,12 @@

#pragma mark Public API

/**
* Returns a new autoreleased layout:
* JoypadControllerLayout *myLayout = [JoypadControllerLayout layout];
*/
+(JoypadControllerLayout *)layout;

/**
* Set the name of this layout. This name will be displayed in the Connection Modal on Joypad
* when a connection occurs.
Expand Down Expand Up @@ -102,10 +106,19 @@
-(void)addAccelerometer;

/**
* Adds an analog stick with origin at the center of the frame.
* Adds an analog stick with origin at the center of the frame. This stick does not
* recenter around the initial touch point. See the next method for more flexibility.
*/
-(void)addAnalogStickWithFrame:(CGRect)rect identifier:(JoyInputIdentifier)inputId;

/**
* Same as above with an extra parameter to specify if the analog stick should recenter at the
* initial touch down point. This gives it a hybrid feel between an analog stick and trackpad.
* Recentering analog sticks are ideal for camera movement in a FPS. For player movement,
* it is best to stick with a stationary analog stick (i.e. pass NO as the last argument).
*/
-(void)addAnalogStickWithFrame:(CGRect)rect identifier:(JoyInputIdentifier)inputId recentering:(BOOL)recentering;

/**
* Equal if controller layouts have the same input components (buttons, labels, dpads, name, etc.)
*/
Expand Down
26 changes: 14 additions & 12 deletions Other Sources/JoypadCocoaSDK/JoypadDevice.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
//
// JoypadDevice.h
// Joypad SDK
//
// Created by Lou Zell on 2/25/11.
// Copyright 2011 Hazelmade. All rights reserved.
// Copyright 2011 Joypad Inc. All rights reserved.
//
// Please email questions to me, Lou, at [email protected]
// Please email questions to [email protected]
// __________________________________________________________________________
//

#import <Foundation/Foundation.h>
#import "JoypadConstants.h"

// Forward declarations.
@protocol JoypadDeviceDelegate;

@interface JoypadDevice : NSObject

/**
* Sets the object that will receive input from a JoypadDevice.
* See the JoypadDeviceDelegate Category at the bottom of this header.
*/
-(void)setDelegate:(id)aDelegate;
-(void)setDelegate:(id<JoypadDeviceDelegate>)aDelegate;

/**
* Gets the object that will receive input from a JoypadDevice.
* See the JoypadDeviceDelegate Category at the bottom of this header.
*/
-(id)delegate;
-(id<JoypadDeviceDelegate>)delegate;

/**
* The name of this device. This is the name that is displayed
Expand All @@ -32,11 +35,10 @@
-(NSString *)name;

/**
* The player number of this device. You set the player number when
* you initiate a connection. For example:
*
* -[JoypadManager connectToDevice:aDevice asPlayer:2];
*
* The player number of this device. This will be set automatically
* by the sdk based on the order of connections. As players drop out
* in a multiplayer game, new players will fill their old spots in
* ascending order.
*/
-(unsigned int)playerNumber;

Expand All @@ -54,8 +56,8 @@



@interface NSObject (JoypadDeviceDelegate)

@protocol JoypadDeviceDelegate <NSObject>
@optional
/**
Implement the following methods in the class that will receive input from Joypad.
Expand Down
Loading

0 comments on commit 11d1faf

Please sign in to comment.