Fixed some memory leaks, and took the address-related properties out of Player.
authorJens Alfke <jens@mooseyard.com>
Tue Jul 08 13:12:01 2008 -0700 (2008-07-08)
changeset 13db7bb080c3d5
parent 12 4e567e11f45f
child 14 4585c74d809c
Fixed some memory leaks, and took the address-related properties out of Player.
GeekGameBoard.xcodeproj/project.pbxproj
Source/Bit.m
Source/DiscPiece.m
Source/KlondikeGame.m
Source/Player.h
Source/Player.m
     1.1 --- a/GeekGameBoard.xcodeproj/project.pbxproj	Mon Jul 07 15:47:42 2008 -0700
     1.2 +++ b/GeekGameBoard.xcodeproj/project.pbxproj	Tue Jul 08 13:12:01 2008 -0700
     1.3 @@ -19,6 +19,8 @@
     1.4  		2734B2620CC7F25A0070C008 /* HexchequerGame.m in Sources */ = {isa = PBXBuildFile; fileRef = 2734B2610CC7F25A0070C008 /* HexchequerGame.m */; };
     1.5  		2734B4F00CCA5BDB0070C008 /* CheckersGame.m in Sources */ = {isa = PBXBuildFile; fileRef = 2734B4EF0CCA5BDB0070C008 /* CheckersGame.m */; };
     1.6  		274124060CFCCF9D00842A9B /* DemoBoardView.m in Sources */ = {isa = PBXBuildFile; fileRef = 274124050CFCCF9D00842A9B /* DemoBoardView.m */; };
     1.7 +		274B35B80E22D55E0052BAB4 /* Player.m in Sources */ = {isa = PBXBuildFile; fileRef = 274B35B50E22D55E0052BAB4 /* Player.m */; };
     1.8 +		274B35B90E22D55E0052BAB4 /* Turn.m in Sources */ = {isa = PBXBuildFile; fileRef = 274B35B70E22D55E0052BAB4 /* Turn.m */; };
     1.9  		275167D90DEE2AB000247375 /* Blue.png in Resources */ = {isa = PBXBuildFile; fileRef = 275167D40DEE2AB000247375 /* Blue.png */; };
    1.10  		275167DA0DEE2AB000247375 /* Gold.png in Resources */ = {isa = PBXBuildFile; fileRef = 275167D50DEE2AB000247375 /* Gold.png */; };
    1.11  		275167DB0DEE2AB000247375 /* Green.png in Resources */ = {isa = PBXBuildFile; fileRef = 275167D60DEE2AB000247375 /* Green.png */; };
    1.12 @@ -77,6 +79,11 @@
    1.13  		2734B4EF0CCA5BDB0070C008 /* CheckersGame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CheckersGame.m; sourceTree = "<group>"; };
    1.14  		274124040CFCCF9D00842A9B /* DemoBoardView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoBoardView.h; sourceTree = "<group>"; };
    1.15  		274124050CFCCF9D00842A9B /* DemoBoardView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoBoardView.m; sourceTree = "<group>"; };
    1.16 +		274B35B30E22D55E0052BAB4 /* Game+Protected.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Game+Protected.h"; sourceTree = "<group>"; };
    1.17 +		274B35B40E22D55E0052BAB4 /* Player.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Player.h; sourceTree = "<group>"; };
    1.18 +		274B35B50E22D55E0052BAB4 /* Player.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Player.m; sourceTree = "<group>"; };
    1.19 +		274B35B60E22D55E0052BAB4 /* Turn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Turn.h; sourceTree = "<group>"; };
    1.20 +		274B35B70E22D55E0052BAB4 /* Turn.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Turn.m; sourceTree = "<group>"; };
    1.21  		275167D40DEE2AB000247375 /* Blue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Blue.png; sourceTree = "<group>"; };
    1.22  		275167D50DEE2AB000247375 /* Gold.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Gold.png; sourceTree = "<group>"; };
    1.23  		275167D60DEE2AB000247375 /* Green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Green.png; sourceTree = "<group>"; };
    1.24 @@ -226,6 +233,11 @@
    1.25  			children = (
    1.26  				27275C490CC700F2009C4C6C /* Game.h */,
    1.27  				27275C4A0CC700F2009C4C6C /* Game.m */,
    1.28 +				274B35B30E22D55E0052BAB4 /* Game+Protected.h */,
    1.29 +				274B35B40E22D55E0052BAB4 /* Player.h */,
    1.30 +				274B35B50E22D55E0052BAB4 /* Player.m */,
    1.31 +				274B35B60E22D55E0052BAB4 /* Turn.h */,
    1.32 +				274B35B70E22D55E0052BAB4 /* Turn.m */,
    1.33  				27275C900CC7C578009C4C6C /* TicTacToeGame.h */,
    1.34  				27275C910CC7C578009C4C6C /* TicTacToeGame.m */,
    1.35  				2734B4EE0CCA5BDB0070C008 /* CheckersGame.h */,
    1.36 @@ -397,6 +409,8 @@
    1.37  				27C999C30D81185E005AFD4F /* GGBUtils.m in Sources */,
    1.38  				279F4D870D8606C200B32DBF /* GGBLayer.m in Sources */,
    1.39  				279F4D880D8606C200B32DBF /* GGBTextLayer.m in Sources */,
    1.40 +				274B35B80E22D55E0052BAB4 /* Player.m in Sources */,
    1.41 +				274B35B90E22D55E0052BAB4 /* Turn.m in Sources */,
    1.42  			);
    1.43  			runOnlyForDeploymentPostprocessing = 0;
    1.44  		};
     2.1 --- a/Source/Bit.m	Mon Jul 07 15:47:42 2008 -0700
     2.2 +++ b/Source/Bit.m	Tue Jul 08 13:12:01 2008 -0700
     2.3 @@ -123,8 +123,8 @@
     2.4              z = _restingZ;
     2.5          }
     2.6  
     2.7 -        //self.zPosition = z;
     2.8  #if !TARGET_OS_IPHONE
     2.9 +        self.zPosition = z;
    2.10          self.shadowOpacity = shadow;
    2.11          self.shadowOffset = offset;
    2.12          self.shadowRadius = radius;
     3.1 --- a/Source/DiscPiece.m	Mon Jul 07 15:47:42 2008 -0700
     3.2 +++ b/Source/DiscPiece.m	Tue Jul 08 13:12:01 2008 -0700
     3.3 @@ -38,7 +38,7 @@
     3.4          _imageLayer.contentsGravity = @"resizeAspect";
     3.5          _imageLayer.masksToBounds = YES;
     3.6          [self addSublayer: _imageLayer];
     3.7 -        [_imageLayer release];
     3.8 +        [_imageLayer release]; // superlayer is holding onto it
     3.9      }
    3.10      _imageLayer.frame = CGRectInset(self.bounds, outerDiameter-diameter, outerDiameter-diameter);
    3.11      _imageLayer.cornerRadius = diameter/2;
     4.1 --- a/Source/KlondikeGame.m	Mon Jul 07 15:47:42 2008 -0700
     4.2 +++ b/Source/KlondikeGame.m	Tue Jul 08 13:12:01 2008 -0700
     4.3 @@ -59,25 +59,22 @@
     4.4      [Card setCardSize: kCardSize];
     4.5      
     4.6      CGPoint pos = {floor(gap/2)+kCardSize.width/2, floor(boardSize.height-kCardSize.height/2)};
     4.7 -    [_deck release];
     4.8 -    _deck = [[Deck alloc] initWithCardsOfClass: [PlayingCard class]];
     4.9 +    _deck = [[[Deck alloc] initWithCardsOfClass: [PlayingCard class]] autorelease];
    4.10      [_deck shuffle];
    4.11      _deck.position = pos;
    4.12      [_board addSublayer: _deck];
    4.13      
    4.14      pos.x += xSpacing;
    4.15 -    [_sink release];
    4.16 -    _sink = [[Deck alloc] init];
    4.17 +    _sink = [[[Deck alloc] init] autorelease];
    4.18      _sink.position = pos;
    4.19      [_board addSublayer: _sink];
    4.20      
    4.21      pos.x += xSpacing;
    4.22      for( CardSuit suit=kSuitClubs; suit<=kSuitSpades; suit++ ) {
    4.23          pos.x += xSpacing;
    4.24 -        Deck *aces = [[Deck alloc] init];
    4.25 +        Deck *aces = [[[Deck alloc] init] autorelease];
    4.26          aces.position = pos;
    4.27          [_board addSublayer: aces];
    4.28 -        [_aces[suit] release];
    4.29          _aces[suit] = aces;
    4.30      }
    4.31      
     5.1 --- a/Source/Player.h	Mon Jul 07 15:47:42 2008 -0700
     5.2 +++ b/Source/Player.h	Tue Jul 08 13:12:01 2008 -0700
     5.3 @@ -14,8 +14,9 @@
     5.4  @interface Player : NSObject <NSCoding>
     5.5  {
     5.6      Game *_game;
     5.7 -    NSString *_name, *_uuid, *_address, *_addressType;
     5.8 +    NSString *_name;
     5.9      BOOL _local;
    5.10 +    NSMutableDictionary *_extraValues;
    5.11  }
    5.12  
    5.13  - (id) initWithGame: (Game*)game;
    5.14 @@ -24,18 +25,16 @@
    5.15  - (id) initWithCoder: (NSCoder*)decoder;
    5.16  - (void) encodeWithCoder: (NSCoder*)coder;
    5.17  
    5.18 +@property (copy) NSString *name;                            // Display name
    5.19 +@property (readonly) CGImageRef icon;                       // An icon to display (calls game.iconForPlayer:)
    5.20 +
    5.21  @property (readonly) Game *game;
    5.22 -@property (copy) NSString *name,                            // Display name
    5.23 -                          *UUID,                            // Address Book UUID
    5.24 -                          *address,                         // Contact address
    5.25 -                          *addressType;                     // Contact address type (an AB property type)
    5.26  @property (readonly) int index;                             // Player's index in the Game's -players array
    5.27 -@property (readwrite,getter=isLocal) BOOL local;            // Is the player on this computer? (Defaults to YES)
    5.28 +@property (readwrite,getter=isLocal) BOOL local;            // Is player a human at this computer? (Defaults to YES)
    5.29  @property (readonly, getter=isCurrent) BOOL current;        // Is it this player's turn?
    5.30  @property (readonly, getter=isFriendly) BOOL friendly;      // Is this player the current player or an ally?
    5.31  @property (readonly, getter=isUnfriendly) BOOL unfriendly;  // Is this player an opponent of the current player?
    5.32  @property (readonly) Player *nextPlayer, *previousPlayer;   // The next/previous player in sequence
    5.33 -@property (readonly) CGImageRef icon;
    5.34  @end
    5.35  
    5.36  
     6.1 --- a/Source/Player.m	Mon Jul 07 15:47:42 2008 -0700
     6.2 +++ b/Source/Player.m	Tue Jul 08 13:12:01 2008 -0700
     6.3 @@ -40,10 +40,8 @@
     6.4      if( self ) {
     6.5          _game =  [decoder decodeObjectForKey: @"game"];
     6.6          _name = [[decoder decodeObjectForKey: @"name"] copy];
     6.7 -        _uuid = [[decoder decodeObjectForKey: @"UUID"] copy];
     6.8 -        _address = [[decoder decodeObjectForKey: @"address"] copy];
     6.9 -        _addressType = [[decoder decodeObjectForKey: @"addressType"] copy];
    6.10          _local=  [decoder decodeBoolForKey:   @"local"];
    6.11 +        _extraValues = [[decoder decodeObjectForKey: @"extraValues"] mutableCopy];
    6.12      }
    6.13      return self;
    6.14  }
    6.15 @@ -52,23 +50,35 @@
    6.16  {
    6.17      [coder encodeObject: _game  forKey: @"game"];
    6.18      [coder encodeObject: _name  forKey: @"name"];
    6.19 -    [coder encodeObject: _uuid  forKey: @"UUID"];
    6.20 -    [coder encodeObject: _address forKey: @"address"];
    6.21 -    [coder encodeObject: _addressType forKey: @"addressType"];
    6.22      [coder encodeBool:   _local forKey: @"local"];
    6.23 +    [coder encodeObject: _extraValues forKey: @"extraValues"];
    6.24  }
    6.25  
    6.26  - (void) dealloc
    6.27  {
    6.28      [_name release];
    6.29 -    [_uuid release];
    6.30 -    [_address release];
    6.31 -    [_addressType release];
    6.32 +    [_extraValues release];
    6.33      [super dealloc];
    6.34  }
    6.35  
    6.36  
    6.37 -@synthesize game=_game, name=_name, UUID=_uuid, address=_address, addressType=_addressType, local=_local;
    6.38 +- (id)valueForUndefinedKey:(NSString *)key
    6.39 +{
    6.40 +    return [_extraValues objectForKey: key];
    6.41 +}
    6.42 +
    6.43 +- (void)setValue:(id)value forUndefinedKey:(NSString *)key
    6.44 +{
    6.45 +    if( ! _extraValues )
    6.46 +        _extraValues = [[NSMutableDictionary alloc] init];
    6.47 +    if( value )
    6.48 +        [_extraValues setObject: value forKey: key];
    6.49 +    else
    6.50 +        [_extraValues removeObjectForKey: key];
    6.51 +}
    6.52 +
    6.53 +
    6.54 +@synthesize game=_game, name=_name, local=_local;
    6.55  
    6.56  - (BOOL) isCurrent      {return self == _game.currentPlayer;}
    6.57  - (BOOL) isFriendly     {return self == _game.currentPlayer;}   // could be overridden for games with partners