From c8fe8e8eb84825e8e61de39f1518b29ac56e49ec Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Tue, 26 Nov 2013 15:49:34 +0000
Subject: [PATCH] [Fix?] Continue in switch case doesn't behave as I thought it
 did.....

---
 src/weapon.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/weapon.c b/src/weapon.c
index 598bd33..ba81d83 100644
--- a/src/weapon.c
+++ b/src/weapon.c
@@ -310,6 +310,7 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
   Weapon* w;
   int i;
 
+  /* Choose layer. */
   switch(layer) {
   case WEAPON_LAYER_BG:
     wlayer = wbackLayer;
@@ -341,7 +342,7 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
       wlayer[i]->timer -= dt;
       if(wlayer[i]->timer < 0.) {
         weapon_destroy(wlayer[i], layer);
-        continue;
+        break;
       }
       break;
     /* Beam weapons handled apart. */
@@ -350,7 +351,7 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
       wlayer[i]->timer -= dt;
       if(wlayer[i]->timer < 0.) {
         weapon_destroy(wlayer[i],layer);
-        continue;
+        break;
       }
       wlayer[i]->lockon -= dt;
       if(wlayer[i]->lockon < 0.) {
@@ -365,11 +366,12 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
           w->outfit->name);
       break;
     }
-    weapon_update(wlayer[i], dt, layer);
 
     /* Only increment if weapon wasn't deleted. */
-    if(w == wlayer[i])
+    if(w == wlayer[i]) {
+      weapon_update(wlayer[i], dt, layer);
       i++;
+    }
   }
 }
 
@@ -505,6 +507,12 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
   glTexture* gfx;
   Vec2 crash[2];
 
+  /* Get the sprite direction to speed up calculations. */
+  if(!outfit_isBeam(w->outfit)) {
+    gfx = outfit_gfx(w->outfit);
+    gl_getSpriteFromDir(&wsx, &wsy, gfx, w->solid->dir);
+  }
+
   for(i = 0; i < pilot_nstack; i++) {
     /* Check for player to exist. */
     if((i == 0) && (player == NULL)) continue;
@@ -531,8 +539,6 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
 
     /* Smart weapons only collide with  their target. */
     else if(weapon_isSmart(w)) {
-      gfx = outfit_gfx(w->outfit);
-      gl_getSpriteFromDir(&wsx, &wsy, gfx, w->solid->dir);
       if((pilot_stack[i]->id == w->target) &&
           CollideSprite(gfx, wsx, wsy, &w->solid->pos,
             pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos,
@@ -542,11 +548,8 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
         return; /* Weapon is destroyed. */
       }
     }
-    /* Dumb weapons hit anything not of the same faction. */
-    else if(!weapon_isSmart(w)) {
-      gfx = outfit_gfx(w->outfit);
-      gl_getSpriteFromDir(&wsx, &wsy, gfx, w->solid->dir);
-
+    /* Dump weapons hit anything not of the same faction. */
+    else {
         if(!areAllies(w->faction, pilot_stack[i]->faction) &&
             CollideSprite(gfx, wsx, wsy, &w->solid->pos,
               pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos,
@@ -557,7 +560,8 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
       }
     }
   /* Smart weapons also get to think their next move. */
-  if(weapon_isSmart(w)) (*w->think)(w,dt);
+  if(weapon_isSmart(w))
+    (*w->think)(w,dt);
 
   /* Update the solid position. */
   (*w->solid->update)(w->solid, dt);