]> git.mxchange.org Git - quix0rs-blobwars.git/commitdiff
Do not fill in comboString when we are not using it.
authorGuus Sliepen <guus@debian.org>
Wed, 7 Jul 2010 14:22:26 +0000 (16:22 +0200)
committerGuus Sliepen <guus@debian.org>
Wed, 7 Jul 2010 14:22:26 +0000 (16:22 +0200)
According to callgrind, blobwars was spending 4% of its time in
enemyBulletCollisions(), calling snprintf() to fill in comboString. However,
this string was only used when an enemy was killed to check against objectives.
So now snprintf() has been moved to where it actually is being used, dropping
time spent in that function by 3.8%.

src/enemies.cpp

index 1e59f832cc118919568ce386c2a37696611272a2..9c998c3e8532f4c67defbb4a4b9360a68e5c3c3a 100644 (file)
@@ -377,8 +377,6 @@ void enemyBulletCollisions(Entity *bullet)
 
                if ((bullet->owner == &player) || (bullet->owner == &engine.world) || (bullet->flags & ENT_BOSS))
                {
-                       snprintf(comboString, sizeof comboString, "Combo-%s", bullet->name);
-
                        if (Collision::collision(enemy, bullet))
                        {
                                if (bullet->id != WP_LASER)
@@ -458,6 +456,7 @@ void enemyBulletCollisions(Entity *bullet)
                                                                checkCombo();
                                                        }
                                                        
+                                                       snprintf(comboString, sizeof comboString, "Combo-%s", bullet->name);
                                                        checkObjectives(comboString, false);
                                                        checkObjectives("Enemy", false);
                                                        checkObjectives(enemy->name, false);
@@ -505,6 +504,7 @@ void enemyBulletCollisions(Entity *bullet)
                                        {
                                                if (player.currentWeapon != &weapon[WP_LASER])
                                                {
+                                                       snprintf(comboString, sizeof comboString, "Combo-%s", bullet->name);
                                                        checkCombo();
                                                        checkObjectives(comboString, false);
                                                }