]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Simplify the code
authorterencehill <piuntn@gmail.com>
Mon, 25 Apr 2011 22:52:51 +0000 (00:52 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 25 Apr 2011 22:52:51 +0000 (00:52 +0200)
qcsrc/client/Main.qc
qcsrc/client/hud.qc

index f2311200e3cddcfbaba68061fe1e727866f9d127..21ccb217ce6c04858f4914de03d278fb8935e25a 100644 (file)
@@ -840,9 +840,9 @@ void Ent_ClientData()
                if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
                  || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
                )
                if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
                  || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
                )
-                       last_p_health = -1;
+                       prev_p_health = -1;
                else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
                else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
-                       health_time = -1;
+                       prev_health = -1;
        }
        spectatee_status = newspectatee_status;
 }
        }
        spectatee_status = newspectatee_status;
 }
index 9d997e0eb33c13482a6c3611874d8ebecb301277..dec1b7ff1176e4e01581fda429bd4f6265735810 100644 (file)
@@ -1302,20 +1302,13 @@ void HUD_Powerups(void)
 //
 
 // prev_* vars contain the health/armor at the previous FRAME
 //
 
 // prev_* vars contain the health/armor at the previous FRAME
-float prev_health, prev_armor;
-
-// *_damagetime vars contain time at which damage happened
 // set to -1 when player is dead or was not playing
 // set to -1 when player is dead or was not playing
+float prev_health, prev_armor;
 float health_damagetime, armor_damagetime;
 float health_damagetime, armor_damagetime;
-
-// *_beforedamage vars contain the old health/armor value (before the damage happened)
-// set to -1 when load or damage effect are ended normally
 float health_beforedamage, armor_beforedamage;
 float health_beforedamage, armor_beforedamage;
-
 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
 float old_p_health, old_p_armor;
 float old_p_healthtime, old_p_armortime;
 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
 float old_p_health, old_p_armor;
 float old_p_healthtime, old_p_armortime;
-
 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
 float prev_p_health, prev_p_armor;
 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
 float prev_p_health, prev_p_armor;
@@ -1331,13 +1324,13 @@ void HUD_HealthArmor(void)
                health = getstati(STAT_HEALTH);
                if(health <= 0)
                {
                health = getstati(STAT_HEALTH);
                if(health <= 0)
                {
-                       health_damagetime = -1;
+                       prev_health = -1;
                        return;
                }
                armor = getstati(STAT_ARMOR);
 
                // code to check for spectatee_status changes is in Ent_ClientData()
                        return;
                }
                armor = getstati(STAT_ARMOR);
 
                // code to check for spectatee_status changes is in Ent_ClientData()
-               // prev_p_health and health_damagetime can be set to -1 there
+               // prev_p_health and prev_health can be set to -1 there
 
                if (prev_p_health == -1)
                {
 
                if (prev_p_health == -1)
                {
@@ -1353,11 +1346,11 @@ void HUD_HealthArmor(void)
                        prev_p_health = health;
                        prev_p_armor = armor;
                }
                        prev_p_health = health;
                        prev_p_armor = armor;
                }
-               else if (health_damagetime == -1)
+               else if (prev_health == -1)
                {
                        //start the load effect
                {
                        //start the load effect
-                       health_damagetime = time;
-                       armor_damagetime = time;
+                       health_damagetime = 0;
+                       armor_damagetime = 0;
                        prev_health = 0;
                        prev_armor = 0;
                }
                        prev_health = 0;
                        prev_armor = 0;
                }
@@ -1496,25 +1489,19 @@ void HUD_HealthArmor(void)
                                                p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
                                                prev_p_health = p_health;
                                        }
                                                p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
                                                prev_p_health = p_health;
                                        }
-                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0 && health_beforedamage == -1)
+                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
                                        {
                                        {
-                                               if (prev_health == 0 || prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
+                                               if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
                                                {
                                                {
+                                                       if (time - health_damagetime >= 1)
+                                                               health_beforedamage = prev_health;
                                                        health_damagetime = time;
                                                        health_damagetime = time;
-                                                       health_beforedamage = prev_health;
                                                }
                                                }
-                                       }
-                                       if (health_beforedamage != -1)
-                                       {
-                                               float d = time - health_damagetime;
-                                               if (d < 1)
+                                               if (time - health_damagetime < 1)
                                                {
                                                {
-                                                       HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
-                                                       if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage) //refresh the effect if repeatedly damaged
-                                                               health_damagetime = time;
+                                                       float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
+                                                       HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
                                                }
                                                }
-                                               else
-                                                       health_beforedamage = -1; //damage effect ended
                                        }
                                        prev_health = health;
 
                                        }
                                        prev_health = health;
 
@@ -1554,25 +1541,19 @@ void HUD_HealthArmor(void)
                                                p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
                                                prev_p_armor = p_armor;
                                        }
                                                p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
                                                prev_p_armor = p_armor;
                                        }
-                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0 && armor_beforedamage == -1)
+                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
                                        {
                                        {
-                                               if (prev_armor == 0 || prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
+                                               if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
                                                {
                                                {
+                                                       if (time - armor_damagetime >= 1)
+                                                               armor_beforedamage = prev_armor;
                                                        armor_damagetime = time;
                                                        armor_damagetime = time;
-                                                       armor_beforedamage = prev_armor;
                                                }
                                                }
-                                       }
-                                       if (armor_beforedamage != -1)
-                                       {
-                                               float d = time - armor_damagetime;
-                                               if (d < 1)
+                                               if (time - armor_damagetime < 1)
                                                {
                                                {
-                                                       HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
-                                                       if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage) //refresh the effect if repeatedly damaged
-                                                               armor_damagetime = time;
+                                                       float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
+                                                       HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
                                                }
                                                }
-                                               else
-                                                       armor_beforedamage = -1; //damage effect ended
                                        }
                                        prev_armor = armor;
                                }
                                        }
                                        prev_armor = armor;
                                }