Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
added project files
- Loading branch information
1 parent
669bd2f
commit f166687
Showing
257 changed files
with
155,632 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// ControlPadConnectViewController.h | ||
// SNES4iPad | ||
// | ||
// Created by Yusef Napora on 5/10/10. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
typedef enum { | ||
ControlPadConnectionStateConnected, | ||
ControlPadConnectionStateAvailable, | ||
ControlPadConnectionStateSearching | ||
} ControlPadConnectionState; | ||
|
||
@interface ControlPadConnectViewController : UIViewController { | ||
|
||
UILabel *controllerLabel; | ||
UILabel *statusLabel; | ||
|
||
UIActivityIndicatorView *spinner; | ||
UIButton *acceptButton; | ||
UIButton *denyButton; | ||
UIButton *disconnectButton; | ||
|
||
NSUInteger currentPadNumber; | ||
NSArray *numberStrings; | ||
|
||
ControlPadConnectionState state; | ||
} | ||
|
||
@property (nonatomic, retain) IBOutlet UILabel *controllerLabel; | ||
@property (nonatomic, retain) IBOutlet UILabel *statusLabel; | ||
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *spinner; | ||
@property (nonatomic, retain) IBOutlet UIButton *acceptButton; | ||
@property (nonatomic, retain) IBOutlet UIButton *denyButton; | ||
@property (nonatomic, retain) IBOutlet UIButton *disconnectButton; | ||
@property (nonatomic, assign) NSUInteger currentPadNumber; | ||
@property (nonatomic, assign) ControlPadConnectionState state; | ||
|
||
- (IBAction) buttonPressed:(id)sender; | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// | ||
// ControlPadConnectViewController.m | ||
// SNES4iPad | ||
// | ||
// Created by Yusef Napora on 5/10/10. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "SNES4iPadAppDelegate.h" | ||
#import "ControlPadConnectViewController.h" | ||
#import "ControlPadManager.h" | ||
|
||
|
||
@implementation ControlPadConnectViewController | ||
|
||
@synthesize state, controllerLabel, statusLabel, spinner, acceptButton, denyButton, disconnectButton, currentPadNumber; | ||
|
||
|
||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
self.contentSizeForViewInPopover = CGSizeMake(424, 128); | ||
|
||
numberStrings = [[NSArray alloc] initWithObjects:@"One", @"Two", @"Three", @"Four", nil]; | ||
|
||
[self.acceptButton setBackgroundImage:[[UIImage imageNamed:@"greenButton.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0] | ||
forState:UIControlStateNormal]; | ||
[self.denyButton setBackgroundImage:[[UIImage imageNamed:@"redButton.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0] | ||
forState:UIControlStateNormal]; | ||
[self.disconnectButton setBackgroundImage:[[UIImage imageNamed:@"redButton.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0] | ||
forState:UIControlStateNormal]; | ||
} | ||
|
||
|
||
|
||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | ||
// Overriden to allow any orientation. | ||
return YES; | ||
} | ||
|
||
- (void) viewWillAppear:(BOOL)animated | ||
{ | ||
controllerLabel.text = [NSString stringWithFormat:@"Player %@", [numberStrings objectAtIndex:currentPadNumber]]; | ||
|
||
NSString *deviceName = [AppDelegate().controlPadManager deviceNameForPadNumber:currentPadNumber]; | ||
if (deviceName == nil) | ||
{ | ||
self.state = ControlPadConnectionStateSearching; | ||
} | ||
} | ||
|
||
- (void) viewWillDisappear:(BOOL)animated | ||
{ | ||
[AppDelegate().controlPadManager stopSearchingForConnection]; | ||
} | ||
|
||
- (void) setState:(ControlPadConnectionState)s | ||
{ | ||
if (state != s) | ||
{ | ||
state = s; | ||
switch (state) | ||
{ | ||
case ControlPadConnectionStateSearching: | ||
acceptButton.hidden = YES; | ||
denyButton.hidden = YES; | ||
disconnectButton.hidden = YES; | ||
[spinner startAnimating]; | ||
statusLabel.text = @"Waiting For Connection..."; | ||
[AppDelegate().controlPadManager searchForConnectionToPadNumber:currentPadNumber]; | ||
break; | ||
case ControlPadConnectionStateAvailable: | ||
acceptButton.hidden = NO; | ||
denyButton.hidden = NO; | ||
disconnectButton.hidden = YES; | ||
[spinner stopAnimating]; | ||
statusLabel.text = [NSString stringWithFormat:@"Found: %@", | ||
[AppDelegate().controlPadManager deviceNameForPendingConnection]]; | ||
break; | ||
case ControlPadConnectionStateConnected: | ||
acceptButton.hidden = YES; | ||
denyButton.hidden = YES; | ||
disconnectButton.hidden = NO; | ||
[spinner stopAnimating]; | ||
statusLabel.text = [NSString stringWithFormat:@"Connected to %@", | ||
[AppDelegate().controlPadManager deviceNameForPadNumber:currentPadNumber]]; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
- (IBAction) buttonPressed:(id)sender | ||
{ | ||
NSLog(@"button pressed: %@", [sender description]); | ||
if (sender == acceptButton) | ||
{ | ||
[AppDelegate().controlPadManager acceptPendingConnection]; | ||
} else if (sender == denyButton) | ||
{ | ||
[AppDelegate().controlPadManager denyPendingConnection]; | ||
self.state = ControlPadConnectionStateSearching; | ||
} else if (sender == disconnectButton) { | ||
[AppDelegate().controlPadManager disconnectPadNumber:currentPadNumber]; | ||
self.state = ControlPadConnectionStateSearching; | ||
} | ||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
// Releases the view if it doesn't have a superview. | ||
[super didReceiveMemoryWarning]; | ||
|
||
// Release any cached data, images, etc that aren't in use. | ||
} | ||
|
||
|
||
- (void)viewDidUnload { | ||
[super viewDidUnload]; | ||
// Release any retained subviews of the main view. | ||
// e.g. self.myOutlet = nil; | ||
} | ||
|
||
|
||
- (void)dealloc { | ||
[super dealloc]; | ||
[numberStrings release]; | ||
[controllerLabel release]; | ||
[statusLabel release]; | ||
[spinner release]; | ||
[acceptButton release]; | ||
[denyButton release]; | ||
|
||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// ControlPadManager.h | ||
// SNES4iPad | ||
// | ||
// Created by Yusef Napora on 5/10/10. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <GameKit/GameKit.h> | ||
|
||
#define MAX_CONTROL_PADS 4 | ||
|
||
extern unsigned long padStatusForPadNumber(int which); | ||
|
||
@interface ControlPadManager : NSObject <GKSessionDelegate> { | ||
GKSession *gkSession; | ||
|
||
NSMutableArray *controlPadPeerIDs; | ||
|
||
NSUInteger padAwaitingConnection; | ||
NSString *pendingConnectionPeerID; | ||
|
||
// these longs hold the current status of all the control pads. | ||
// status == a mask of which buttons are currently pressed | ||
// this is the value returned by statusForPadNumber: | ||
unsigned long padStatus[MAX_CONTROL_PADS]; | ||
} | ||
|
||
@property (nonatomic, assign) NSUInteger padAwaitingConnection; | ||
@property (nonatomic, retain) NSString *pendingConnectionPeerID; | ||
|
||
- (void) searchForConnectionToPadNumber:(NSUInteger)padNumber; | ||
- (void) stopSearchingForConnection; | ||
|
||
- (void) acceptPendingConnection; | ||
- (void) denyPendingConnection; | ||
- (void) disconnectPadNumber:(NSUInteger)padNumber; | ||
- (void) disconnectPeer:(NSString *)peerID; | ||
- (unsigned long) statusForPadNumber:(NSUInteger)padNumber; | ||
- (NSString *) deviceNameForPadNumber:(NSUInteger)padNumber; | ||
- (NSString *) deviceNameForPendingConnection; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// | ||
// ControlPadManager.m | ||
// SNES4iPad | ||
// | ||
// Created by Yusef Napora on 5/10/10. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "SNES4iPadAppDelegate.h" | ||
#import "ControlPadManager.h" | ||
#import "ControlPadConnectViewController.h" | ||
|
||
#define MAX_CONNECTIONS 4 | ||
#define SESSION_ID @"com.snes-hd.controller" | ||
|
||
unsigned long padStatusForPadNumber(int which) | ||
{ | ||
if (which < MAX_CONTROL_PADS) | ||
return [AppDelegate().controlPadManager statusForPadNumber:which]; | ||
|
||
return 0; | ||
} | ||
|
||
@implementation ControlPadManager | ||
@synthesize padAwaitingConnection, pendingConnectionPeerID; | ||
|
||
|
||
- (id) init | ||
{ | ||
if (self = [super init]) | ||
{ | ||
gkSession = [[GKSession alloc] initWithSessionID:SESSION_ID | ||
displayName:nil | ||
sessionMode:GKSessionModeServer]; | ||
gkSession.delegate = self; | ||
[gkSession setDataReceiveHandler:self withContext:NULL]; | ||
controlPadPeerIDs = [[NSMutableArray alloc] initWithObjects: | ||
[NSMutableString string], | ||
[NSMutableString string], | ||
[NSMutableString string], | ||
[NSMutableString string], | ||
nil]; | ||
|
||
} | ||
return self; | ||
} | ||
|
||
- (void) searchForConnectionToPadNumber:(NSUInteger)padNumber | ||
{ | ||
if (padNumber >= MAX_CONTROL_PADS) | ||
return; | ||
|
||
padAwaitingConnection = padNumber; | ||
gkSession.available = YES; | ||
} | ||
|
||
- (void) stopSearchingForConnection | ||
{ | ||
gkSession.available = NO; | ||
} | ||
|
||
- (NSString *) deviceNameForPendingConnection | ||
{ | ||
return [gkSession displayNameForPeer:pendingConnectionPeerID]; | ||
} | ||
|
||
- (NSString *) deviceNameForPadNumber:(NSUInteger)padNumber | ||
{ | ||
if (padNumber >= MAX_CONTROL_PADS) | ||
return nil; | ||
|
||
return [gkSession displayNameForPeer: [controlPadPeerIDs objectAtIndex:padNumber]]; | ||
} | ||
|
||
- (unsigned long) statusForPadNumber:(NSUInteger)padNumber | ||
{ | ||
if (padNumber < MAX_CONTROL_PADS) { | ||
return padStatus[padNumber]; | ||
} | ||
return 0; | ||
} | ||
|
||
- (void) disconnectPadNumber:(NSUInteger)padNumber | ||
{ | ||
if (padNumber >= MAX_CONTROL_PADS) | ||
return; | ||
|
||
NSString *peerID = [controlPadPeerIDs objectAtIndex:padNumber]; | ||
[gkSession disconnectPeerFromAllPeers:peerID]; | ||
[[controlPadPeerIDs objectAtIndex:padNumber] setString:@""]; | ||
} | ||
|
||
- (void) disconnectPeer:(NSString *)peerID | ||
{ | ||
if ([controlPadPeerIDs containsObject:peerID]) | ||
{ | ||
[self disconnectPadNumber:[controlPadPeerIDs indexOfObject:peerID]]; | ||
} | ||
} | ||
|
||
- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context | ||
{ | ||
if (![controlPadPeerIDs containsObject:peer]) | ||
return; | ||
|
||
NSUInteger padNumber = [controlPadPeerIDs indexOfObject:peer]; | ||
[data getBytes:&padStatus[padNumber]]; | ||
//NSLog(@"recieved pad status for player %d: %X", padNumber + 1, padStatus[padNumber]); | ||
} | ||
|
||
- (void) acceptPendingConnection | ||
{ | ||
[gkSession acceptConnectionFromPeer:self.pendingConnectionPeerID error:nil]; | ||
[[controlPadPeerIDs objectAtIndex:padAwaitingConnection] setString:self.pendingConnectionPeerID]; | ||
self.pendingConnectionPeerID = nil; | ||
|
||
[AppDelegate().romDetailViewController updateConnectionButtons]; | ||
} | ||
|
||
- (void) denyPendingConnection | ||
{ | ||
[gkSession denyConnectionFromPeer:self.pendingConnectionPeerID]; | ||
self.pendingConnectionPeerID = nil; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark GKSession Delegate methods | ||
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state { | ||
NSLog(@"Session state changed"); | ||
|
||
switch (state) { | ||
case GKPeerStateConnected: | ||
NSLog(@"New Peer connected: %@", peerID); | ||
[[controlPadPeerIDs objectAtIndex:padAwaitingConnection] setString:peerID]; | ||
self.pendingConnectionPeerID = nil; | ||
AppDelegate().controlPadConnectViewController.state = ControlPadConnectionStateConnected; | ||
|
||
break; | ||
case GKPeerStateAvailable: | ||
case GKPeerStateConnecting: | ||
NSLog(@"Peer connecting/available: %@", peerID); | ||
self.pendingConnectionPeerID = peerID; | ||
AppDelegate().controlPadConnectViewController.state = ControlPadConnectionStateAvailable; | ||
break; | ||
case GKPeerStateUnavailable: | ||
NSLog(@"Peer unavailable: %@", peerID); | ||
self.pendingConnectionPeerID = nil; | ||
AppDelegate().controlPadConnectViewController.state = ControlPadConnectionStateSearching; | ||
break; | ||
case GKPeerStateDisconnected: | ||
NSLog(@"Peer disconnected: %@", peerID); | ||
[self disconnectPeer:peerID]; | ||
AppDelegate().controlPadConnectViewController.state = ControlPadConnectionStateSearching; | ||
[AppDelegate().romDetailViewController updateConnectionButtons]; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
- (void)session:(GKSession *)session didReceiveConnectionRequestFromPeer:(NSString *)peerID { | ||
NSLog(@"Recieved connection request from %@", peerID); | ||
self.pendingConnectionPeerID = peerID; | ||
AppDelegate().controlPadConnectViewController.state = ControlPadConnectionStateAvailable; | ||
} | ||
- (void)session:(GKSession *)session connectionWithPeerFailed:(NSString *)peerID withError:(NSError *)error { | ||
NSLog(@"Connection with %@ failed", peerID); | ||
} | ||
@end |
Oops, something went wrong.