Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions iCadeTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "iCadeTest/iCadeTest-Prefix.pch";
INFOPLIST_FILE = "iCadeTest/iCadeTest-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.2;
PRODUCT_NAME = "$(TARGET_NAME)";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -308,11 +311,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "iCadeTest/iCadeTest-Prefix.pch";
INFOPLIST_FILE = "iCadeTest/iCadeTest-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.2;
PRODUCT_NAME = "$(TARGET_NAME)";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
VALIDATE_PRODUCT = YES;
WRAPPER_EXTENSION = app;
};
Expand All @@ -337,6 +343,7 @@
05059CA213AB035F00A09408 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
2 changes: 2 additions & 0 deletions iCadeTest/iCade/iCadeReaderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
UIView *inputView;
iCadeState _iCadeState;
id<iCadeEventDelegate> _delegate;
NSTimer *_actionLoop;

struct {
bool stateChanged:1;
Expand All @@ -62,5 +63,6 @@
@property (nonatomic, assign) iCadeState iCadeState;
@property (nonatomic, assign) id<iCadeEventDelegate> delegate;
@property (nonatomic, assign) BOOL active;
@property (nonatomic, retain) NSTimer *actionLoop;

@end
35 changes: 34 additions & 1 deletion iCadeTest/iCade/iCadeReaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ of this software and associated documentation files (the "Software"), to deal

static const char *ON_STATES = "wdxayhujikol";
static const char *OFF_STATES = "eczqtrfnmpgv";
static const iCadeState ICADE_STATES[] = {iCadeJoystickDownLeft, iCadeJoystickDownRight, iCadeJoystickUpLeft,iCadeJoystickUpRight,
iCadeJoystickUp, iCadeJoystickDown, iCadeJoystickLeft, iCadeJoystickRight,
iCadeButtonA, iCadeButtonB, iCadeButtonC, iCadeButtonD,
iCadeButtonE, iCadeButtonF, iCadeButtonG, iCadeButtonH};

@interface iCadeReaderView()

Expand All @@ -34,14 +38,15 @@ - (void)didBecomeActive;

@implementation iCadeReaderView

@synthesize iCadeState=_iCadeState, delegate=_delegate, active;
@synthesize iCadeState=_iCadeState, delegate=_delegate, active, actionLoop = _actionLoop;

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
self.actionLoop = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(checkCurrentState:) userInfo:nil repeats:YES];

return self;
}
Expand Down Expand Up @@ -134,6 +139,34 @@ - (void)insertText:(NSString *)text {
}
}

//We check if the current state contains a specific state.
//In this case, we remove the State and we notify the delegate
- (void)compareState:(iCadeState *)currentState withState:(iCadeState)testState {
if ((testState & *currentState) == testState) {
NSLog(@"This is the currentState: %i and the testState: %i", *currentState, testState);
*currentState &= ~testState;
if (_delegateFlags.stateChanged) {
[_delegate stateChanged:testState];
} else {
if (_delegateFlags.buttonDown) {
[_delegate buttonDown:testState];
}
}
}
}

- (void)checkCurrentState:(NSTimer*)theTimer {
iCadeState currentState = _iCadeState;
NSLog(@" \n\n\n\n\n\nThis is the currentState: %i", currentState);

//We begin with the composition (UpRight).
//Else, we would have sent 2 separate actions instead of the composition
for (int i = 0; i<16; i++) {
[self compareState:&currentState withState:ICADE_STATES[i]];
}

}

- (void)deleteBackward {
// This space intentionally left blank to complete protocol
}
Expand Down
37 changes: 36 additions & 1 deletion iCadeTest/iCadeTestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,42 @@ - (void)setState:(BOOL)state forButton:(iCadeState)button {
center.x += offset;
}
break;

case iCadeJoystickDownLeft:
if (state) {
center.x -= offset;
center.y += offset;
} else {
center.x += offset;
center.y -= offset;
}
break;
case iCadeJoystickDownRight:
if (state) {
center.x += offset;
center.y += offset;
} else {
center.x -= offset;
center.y -= offset;
}
break;
case iCadeJoystickUpLeft:
if (state) {
center.x -= offset;
center.y -= offset;
} else {
center.x += offset;
center.y += offset;
}
break;
case iCadeJoystickUpRight:
if (state) {
center.x += offset;
center.y -= offset;
} else {
center.x -= offset;
center.y += offset;
}
break;
default:
break;
}
Expand Down