# HG changeset patch # User Jens Alfke # Date 1215547921 25200 # Node ID db7bb080c3d5d6d7ece5e37cf32917e4fde17c8d # Parent 4e567e11f45f01cae5749585cc631dd9c25262a6 Fixed some memory leaks, and took the address-related properties out of Player. diff -r 4e567e11f45f -r db7bb080c3d5 GeekGameBoard.xcodeproj/project.pbxproj --- a/GeekGameBoard.xcodeproj/project.pbxproj Mon Jul 07 15:47:42 2008 -0700 +++ b/GeekGameBoard.xcodeproj/project.pbxproj Tue Jul 08 13:12:01 2008 -0700 @@ -19,6 +19,8 @@ 2734B2620CC7F25A0070C008 /* HexchequerGame.m in Sources */ = {isa = PBXBuildFile; fileRef = 2734B2610CC7F25A0070C008 /* HexchequerGame.m */; }; 2734B4F00CCA5BDB0070C008 /* CheckersGame.m in Sources */ = {isa = PBXBuildFile; fileRef = 2734B4EF0CCA5BDB0070C008 /* CheckersGame.m */; }; 274124060CFCCF9D00842A9B /* DemoBoardView.m in Sources */ = {isa = PBXBuildFile; fileRef = 274124050CFCCF9D00842A9B /* DemoBoardView.m */; }; + 274B35B80E22D55E0052BAB4 /* Player.m in Sources */ = {isa = PBXBuildFile; fileRef = 274B35B50E22D55E0052BAB4 /* Player.m */; }; + 274B35B90E22D55E0052BAB4 /* Turn.m in Sources */ = {isa = PBXBuildFile; fileRef = 274B35B70E22D55E0052BAB4 /* Turn.m */; }; 275167D90DEE2AB000247375 /* Blue.png in Resources */ = {isa = PBXBuildFile; fileRef = 275167D40DEE2AB000247375 /* Blue.png */; }; 275167DA0DEE2AB000247375 /* Gold.png in Resources */ = {isa = PBXBuildFile; fileRef = 275167D50DEE2AB000247375 /* Gold.png */; }; 275167DB0DEE2AB000247375 /* Green.png in Resources */ = {isa = PBXBuildFile; fileRef = 275167D60DEE2AB000247375 /* Green.png */; }; @@ -77,6 +79,11 @@ 2734B4EF0CCA5BDB0070C008 /* CheckersGame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CheckersGame.m; sourceTree = ""; }; 274124040CFCCF9D00842A9B /* DemoBoardView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoBoardView.h; sourceTree = ""; }; 274124050CFCCF9D00842A9B /* DemoBoardView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoBoardView.m; sourceTree = ""; }; + 274B35B30E22D55E0052BAB4 /* Game+Protected.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Game+Protected.h"; sourceTree = ""; }; + 274B35B40E22D55E0052BAB4 /* Player.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Player.h; sourceTree = ""; }; + 274B35B50E22D55E0052BAB4 /* Player.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Player.m; sourceTree = ""; }; + 274B35B60E22D55E0052BAB4 /* Turn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Turn.h; sourceTree = ""; }; + 274B35B70E22D55E0052BAB4 /* Turn.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Turn.m; sourceTree = ""; }; 275167D40DEE2AB000247375 /* Blue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Blue.png; sourceTree = ""; }; 275167D50DEE2AB000247375 /* Gold.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Gold.png; sourceTree = ""; }; 275167D60DEE2AB000247375 /* Green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Green.png; sourceTree = ""; }; @@ -226,6 +233,11 @@ children = ( 27275C490CC700F2009C4C6C /* Game.h */, 27275C4A0CC700F2009C4C6C /* Game.m */, + 274B35B30E22D55E0052BAB4 /* Game+Protected.h */, + 274B35B40E22D55E0052BAB4 /* Player.h */, + 274B35B50E22D55E0052BAB4 /* Player.m */, + 274B35B60E22D55E0052BAB4 /* Turn.h */, + 274B35B70E22D55E0052BAB4 /* Turn.m */, 27275C900CC7C578009C4C6C /* TicTacToeGame.h */, 27275C910CC7C578009C4C6C /* TicTacToeGame.m */, 2734B4EE0CCA5BDB0070C008 /* CheckersGame.h */, @@ -397,6 +409,8 @@ 27C999C30D81185E005AFD4F /* GGBUtils.m in Sources */, 279F4D870D8606C200B32DBF /* GGBLayer.m in Sources */, 279F4D880D8606C200B32DBF /* GGBTextLayer.m in Sources */, + 274B35B80E22D55E0052BAB4 /* Player.m in Sources */, + 274B35B90E22D55E0052BAB4 /* Turn.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff -r 4e567e11f45f -r db7bb080c3d5 Source/Bit.m --- a/Source/Bit.m Mon Jul 07 15:47:42 2008 -0700 +++ b/Source/Bit.m Tue Jul 08 13:12:01 2008 -0700 @@ -123,8 +123,8 @@ z = _restingZ; } - //self.zPosition = z; #if !TARGET_OS_IPHONE + self.zPosition = z; self.shadowOpacity = shadow; self.shadowOffset = offset; self.shadowRadius = radius; diff -r 4e567e11f45f -r db7bb080c3d5 Source/DiscPiece.m --- a/Source/DiscPiece.m Mon Jul 07 15:47:42 2008 -0700 +++ b/Source/DiscPiece.m Tue Jul 08 13:12:01 2008 -0700 @@ -38,7 +38,7 @@ _imageLayer.contentsGravity = @"resizeAspect"; _imageLayer.masksToBounds = YES; [self addSublayer: _imageLayer]; - [_imageLayer release]; + [_imageLayer release]; // superlayer is holding onto it } _imageLayer.frame = CGRectInset(self.bounds, outerDiameter-diameter, outerDiameter-diameter); _imageLayer.cornerRadius = diameter/2; diff -r 4e567e11f45f -r db7bb080c3d5 Source/KlondikeGame.m --- a/Source/KlondikeGame.m Mon Jul 07 15:47:42 2008 -0700 +++ b/Source/KlondikeGame.m Tue Jul 08 13:12:01 2008 -0700 @@ -59,25 +59,22 @@ [Card setCardSize: kCardSize]; CGPoint pos = {floor(gap/2)+kCardSize.width/2, floor(boardSize.height-kCardSize.height/2)}; - [_deck release]; - _deck = [[Deck alloc] initWithCardsOfClass: [PlayingCard class]]; + _deck = [[[Deck alloc] initWithCardsOfClass: [PlayingCard class]] autorelease]; [_deck shuffle]; _deck.position = pos; [_board addSublayer: _deck]; pos.x += xSpacing; - [_sink release]; - _sink = [[Deck alloc] init]; + _sink = [[[Deck alloc] init] autorelease]; _sink.position = pos; [_board addSublayer: _sink]; pos.x += xSpacing; for( CardSuit suit=kSuitClubs; suit<=kSuitSpades; suit++ ) { pos.x += xSpacing; - Deck *aces = [[Deck alloc] init]; + Deck *aces = [[[Deck alloc] init] autorelease]; aces.position = pos; [_board addSublayer: aces]; - [_aces[suit] release]; _aces[suit] = aces; } diff -r 4e567e11f45f -r db7bb080c3d5 Source/Player.h --- a/Source/Player.h Mon Jul 07 15:47:42 2008 -0700 +++ b/Source/Player.h Tue Jul 08 13:12:01 2008 -0700 @@ -14,8 +14,9 @@ @interface Player : NSObject { Game *_game; - NSString *_name, *_uuid, *_address, *_addressType; + NSString *_name; BOOL _local; + NSMutableDictionary *_extraValues; } - (id) initWithGame: (Game*)game; @@ -24,18 +25,16 @@ - (id) initWithCoder: (NSCoder*)decoder; - (void) encodeWithCoder: (NSCoder*)coder; +@property (copy) NSString *name; // Display name +@property (readonly) CGImageRef icon; // An icon to display (calls game.iconForPlayer:) + @property (readonly) Game *game; -@property (copy) NSString *name, // Display name - *UUID, // Address Book UUID - *address, // Contact address - *addressType; // Contact address type (an AB property type) @property (readonly) int index; // Player's index in the Game's -players array -@property (readwrite,getter=isLocal) BOOL local; // Is the player on this computer? (Defaults to YES) +@property (readwrite,getter=isLocal) BOOL local; // Is player a human at this computer? (Defaults to YES) @property (readonly, getter=isCurrent) BOOL current; // Is it this player's turn? @property (readonly, getter=isFriendly) BOOL friendly; // Is this player the current player or an ally? @property (readonly, getter=isUnfriendly) BOOL unfriendly; // Is this player an opponent of the current player? @property (readonly) Player *nextPlayer, *previousPlayer; // The next/previous player in sequence -@property (readonly) CGImageRef icon; @end diff -r 4e567e11f45f -r db7bb080c3d5 Source/Player.m --- a/Source/Player.m Mon Jul 07 15:47:42 2008 -0700 +++ b/Source/Player.m Tue Jul 08 13:12:01 2008 -0700 @@ -40,10 +40,8 @@ if( self ) { _game = [decoder decodeObjectForKey: @"game"]; _name = [[decoder decodeObjectForKey: @"name"] copy]; - _uuid = [[decoder decodeObjectForKey: @"UUID"] copy]; - _address = [[decoder decodeObjectForKey: @"address"] copy]; - _addressType = [[decoder decodeObjectForKey: @"addressType"] copy]; _local= [decoder decodeBoolForKey: @"local"]; + _extraValues = [[decoder decodeObjectForKey: @"extraValues"] mutableCopy]; } return self; } @@ -52,23 +50,35 @@ { [coder encodeObject: _game forKey: @"game"]; [coder encodeObject: _name forKey: @"name"]; - [coder encodeObject: _uuid forKey: @"UUID"]; - [coder encodeObject: _address forKey: @"address"]; - [coder encodeObject: _addressType forKey: @"addressType"]; [coder encodeBool: _local forKey: @"local"]; + [coder encodeObject: _extraValues forKey: @"extraValues"]; } - (void) dealloc { [_name release]; - [_uuid release]; - [_address release]; - [_addressType release]; + [_extraValues release]; [super dealloc]; } -@synthesize game=_game, name=_name, UUID=_uuid, address=_address, addressType=_addressType, local=_local; +- (id)valueForUndefinedKey:(NSString *)key +{ + return [_extraValues objectForKey: key]; +} + +- (void)setValue:(id)value forUndefinedKey:(NSString *)key +{ + if( ! _extraValues ) + _extraValues = [[NSMutableDictionary alloc] init]; + if( value ) + [_extraValues setObject: value forKey: key]; + else + [_extraValues removeObjectForKey: key]; +} + + +@synthesize game=_game, name=_name, local=_local; - (BOOL) isCurrent {return self == _game.currentPlayer;} - (BOOL) isFriendly {return self == _game.currentPlayer;} // could be overridden for games with partners