Time Profile on game -- objc_object::sideTable_release/retain?

Discussion in 'iOS Programming' started by MythicFrost, Mar 25, 2014.

  1. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #1
    I'm analysing my TD game (which is made in Spritekit.) I'm focusing on my 'getTargetsForTower' method right now. The method is called in my update loop.

    As you will see below 'objc_object::sideTable_retain()' and 'objc_object::sideTable_release(bool)' are consuming half of the CPU time for this method. (The statistics are after running for roughly six minutes.)

    [​IMG]

    I'm really not sure what they are, but I'm wondering if it is a coding mistake on my part or if this is normal?

    I can post the code for the methods if wanted.

    Would appreciate any info about this. I didn't have any success Googling.
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
  3. MythicFrost, Mar 29, 2014
    Last edited: Mar 29, 2014

    MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #3
    I did also find that one, but I didn't understand all of it. Other than that, there really aren't any posts about this topic. I have ARC enabled, and all my global variables are declared with nonatomic and retain.

    The method loops through the enemies on the map. Gets the tile(s) their on, loops through the towers that cover that tile (or a part of that tile) and then checks if the enemy is within the radius of the tower, and finally updates the target if it's in range. Usually an enemy is only on one tile, but as it transitions from one to another it'll be on two for a little bit.

    When stress testing I might have 500 enemies and 446 towers on screen, and this method will be running as many times it can up to 60 every second. It also runs on a background thread.

    Code:
    - (void)getTargetsForTowers {
        NSArray *enemiesCopy = [enemiesOnMap copy];
        CCUnit *enemy;
        for (int i = 0; i < enemiesCopy.count; i++) {
            if (i < enemiesOnMap.count) {
                enemy = [enemiesOnMap objectAtIndex:i];
                [self calculateTravelDistanceForEnemy:enemy];
                
                if (enemy.actualHealth > 0) {
                    NSArray *tiles = [self getTilesForEnemy:enemy];
                    for (CCTileInfo *tile in tiles) {
                        CCSKTower *tower = nil;
                        for (int k = 0; k < tile.towers.count; k++) {
                            tower = [tile.towers objectAtIndex:k];
                            BOOL passes = tower.target == nil;
                            if (!passes) {
                                passes = enemy.distanceToEnd < tower.target.distanceToEnd;
                            }
                            if (passes) {
                                BOOL inRange = [self circle:tower.position withRadius:tower.attackRange collisionWithCircle:enemy.position collisionCircleRadius:1];
                                if (inRange) {
                                    tower.target = enemy;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    Thanks for your reply. I'd like to be able to get some kind of solution to this. (I can post any other methods if you'd like as well.)
     

Share This Page