Rework of player's Firing function

 Author: Daniel Jackson


The players fire function was exceeding 1,000 lines and causing a drop in frames anytime the player was firing any weapon. Each time any weapon was fired the weapon checked its current type against every weapon type and its current magazine to see if it could be fired. These repeated checks were causing frames drops and made the function more difficult to read.

To fix this I shifted our player's current weapon to be a pointer to a particular weapon in its arsenal so we could skip going through the entire arsenal every fire. Then I shifted our fire into a switch case using its weapon type and was able to remove most of the code checking each weapon's magazine and instead only check our current weapon and then go through the appropriate checks. This drastically shortened the fire function and decreased the average amount of checks per fire, and I plan to shorten it even further using this new system.


(Lines from fire commented out just prior to deletion)

(Entire block could not fit on screen even when zoomed out)



(New fire function)




Comments

Popular posts from this blog

Adding assets to every enemy -- Owen Meyers

Sphere to AABB collision