Skip to content

Commit

Permalink
Remove unnecessary delegate callback from OrbitalRect
Browse files Browse the repository at this point in the history
  • Loading branch information
jdetloff committed May 26, 2013
1 parent d28f5b9 commit f07da16
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 75 deletions.
4 changes: 2 additions & 2 deletions GraceWorld.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,8 @@
children = (
0FA0C8BF1751BE3500CDC8B8 /* OrbitalElement.h */,
0FA0C8C01751BE3500CDC8B8 /* OrbitalElement.m */,
0FCD44401733815800F7BED4 /* PlayerPhysicsWrapper.h */,
0FCD44411733815800F7BED4 /* PlayerPhysicsWrapper.m */,
0F7C4B68172C475E00037EAC /* OrbitalSurface.h */,
0F7C4B69172C475E00037EAC /* OrbitalSurface.m */,
0F4CE359172FC57E00637555 /* OrbitalRect.h */,
Expand All @@ -1242,8 +1244,6 @@
0F7C4B6D172C62B000037EAC /* OneWayEdgeCollisionDetector.cpp */,
0F4CE35C1730D1BA00637555 /* OrbitController.h */,
0F4CE35D1730D1BA00637555 /* OrbitController.m */,
0FCD44401733815800F7BED4 /* PlayerPhysicsWrapper.h */,
0FCD44411733815800F7BED4 /* PlayerPhysicsWrapper.m */,
);
name = Physics;
sourceTree = "<group>";
Expand Down
10 changes: 2 additions & 8 deletions GraceWorld/OrbitalRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
#import "OrbitalElement.h"
#import <Foundation/Foundation.h>

@class OrbitalRect;
@protocol OrbitalRectSensorDelegate <NSObject>
- (void)orbitalRectContactedByBoy:(OrbitalRect *)rect;
- (void)orbitalRectEndedContactWithBoy:(OrbitalRect *)rect;
@end

@interface OrbitalRect : OrbitalElement

@interface OrbitalRect : OrbitalElement <NSCopying>
@property (nonatomic, strong, readonly) NSArray *vertices;
@property (nonatomic, weak) id<OrbitalRectSensorDelegate> delegate;
@property (nonatomic, strong) void (^sensorAction)(BOOL contact);

- (id)initWithVertices:(NSArray *)vertices;
- (void)boyBeganContact;
Expand Down
25 changes: 2 additions & 23 deletions GraceWorld/OrbitalRect.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,13 @@ - (id)initWithVertices:(NSArray *)vertices {


- (void)boyBeganContact {
[self.delegate orbitalRectContactedByBoy:self];
_sensorAction(YES);
}


- (void)boyEndedContact {
[self.delegate orbitalRectEndedContactWithBoy:self];
_sensorAction(NO);
}


#pragma mark -

- (id)copyWithZone:(NSZone *)zone {
OrbitalRect *rect = [[OrbitalRect allocWithZone:zone] initWithVertices:_vertices];
return rect;
}


- (BOOL)isEqual:(id)object {
if ([object isKindOfClass:[OrbitalRect class]]) {
OrbitalRect *rect = object;
return rect.vertices == _vertices;
}
return NO;
}


- (NSUInteger)hash {
return [_vertices[0] height] + [_vertices[0] angle]*5 + [_vertices[1] height]*25 + [_vertices[1] angle]*125 + [_vertices[2] height]*625 + [_vertices[2] angle]*3125 + [_vertices[3] height]*15625 + [_vertices[3] angle]*78125;
}

@end
2 changes: 1 addition & 1 deletion GraceWorld/OrbitalStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

- (void)addOrbitalSurfaces:(NSArray *)orbitalSurfaces;
- (void)addSensorSurface:(OrbitalSurface *)surface;
- (void)addOrbitalRect:(OrbitalRect *)rect withContactBlock:(void (^)(BOOL contact))contactBlock;
- (void)addOrbitalRect:(OrbitalRect *)rect;

@end
34 changes: 1 addition & 33 deletions GraceWorld/OrbitalStructure.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@
#import "OrbitalRect.h"


@interface OrbitalStructure () <OrbitalRectSensorDelegate>
@end


@implementation OrbitalStructure {
NSMutableDictionary *_rectContactBlocks;
NSMutableArray *_orbitalSurfaces;
NSMutableArray *_sensorSurfaces;
NSMutableArray *_orbitalRects;
}

@synthesize orbitalSurfaces = _orbitalSurfaces;

- (id)init {
self = [super init];
if (self) {
_activated = YES;
_rectContactBlocks = [[NSMutableDictionary alloc] init];
_orbitalSurfaces = [[NSMutableArray alloc] init];
_orbitalRects = [[NSMutableArray alloc] init];
_sensorSurfaces = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -63,33 +56,8 @@ - (void)addSensorSurface:(OrbitalSurface *)surface {
}


- (void)addOrbitalRect:(OrbitalRect *)rect withContactBlock:(void (^)(BOOL contact))contactBlock {
rect.delegate = self;
- (void)addOrbitalRect:(OrbitalRect *)rect {
[_orbitalRects addObject:rect];

void (^blockCopy)(BOOL) = [contactBlock copy];
if (blockCopy) {
[_rectContactBlocks setObject:blockCopy forKey:rect];
}
}


#pragma mark -


- (void)orbitalRectContactedByBoy:(OrbitalRect *)rect {
void (^contactBlock)(BOOL) = [_rectContactBlocks objectForKey:rect];
if (contactBlock) {
contactBlock(YES);
}
}


- (void)orbitalRectEndedContactWithBoy:(OrbitalRect *)rect {
void (^contactBlock)(BOOL) = [_rectContactBlocks objectForKey:rect];
if (contactBlock) {
contactBlock(NO);
}
}


Expand Down
25 changes: 17 additions & 8 deletions GraceWorld/WorldDataStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ - (OrbitalStructure *)cityInterior {
OrbitalRect *ladder7 = [[OrbitalRect alloc] initWithVertices:ladder7Vertices];
OrbitalRect *ladder8 = [[OrbitalRect alloc] initWithVertices:ladder8Vertices];

ladder1.sensorAction = ladderBlock;
ladder2.sensorAction = ladderBlock;
ladder3.sensorAction = ladderBlock;
ladder4.sensorAction = ladderBlock;
ladder5.sensorAction = ladderBlock;
ladder6.sensorAction = ladderBlock;
ladder7.sensorAction = ladderBlock;
ladder8.sensorAction = ladderBlock;

_cityInterior = [[OrbitalStructure alloc] init];
[_cityInterior addSensorSurface:entranceSensor];
[_cityInterior addOrbitalSurfaces:surfaces];
Expand All @@ -398,14 +407,14 @@ - (OrbitalStructure *)cityInterior {
[_cityInterior addOrbitalSurfaces:platform7];
[_cityInterior addOrbitalSurfaces:platform8];
[_cityInterior addOrbitalSurfaces:platform9];
[_cityInterior addOrbitalRect:ladder1 withContactBlock:ladderBlock];
[_cityInterior addOrbitalRect:ladder2 withContactBlock:ladderBlock];
[_cityInterior addOrbitalRect:ladder3 withContactBlock:ladderBlock];
[_cityInterior addOrbitalRect:ladder4 withContactBlock:ladderBlock];
[_cityInterior addOrbitalRect:ladder5 withContactBlock:ladderBlock];
[_cityInterior addOrbitalRect:ladder6 withContactBlock:ladderBlock];
[_cityInterior addOrbitalRect:ladder7 withContactBlock:ladderBlock];
[_cityInterior addOrbitalRect:ladder8 withContactBlock:ladderBlock];
[_cityInterior addOrbitalRect:ladder1];
[_cityInterior addOrbitalRect:ladder2];
[_cityInterior addOrbitalRect:ladder3];
[_cityInterior addOrbitalRect:ladder4];
[_cityInterior addOrbitalRect:ladder5];
[_cityInterior addOrbitalRect:ladder6];
[_cityInterior addOrbitalRect:ladder7];
[_cityInterior addOrbitalRect:ladder8];
}
return _cityInterior;
}
Expand Down

0 comments on commit f07da16

Please sign in to comment.