The Video Gamester
Member
in the game I'm working on I load in my weapon stats from an external .csv file that is loaded into a global variable, global.lootTable, at the start of the game. Each gun has up to two special traits from a pool of 36 which may grow or shrink as I further develop the game. I am trying to decide how to handle the traits as each influences the game in different ways. Some influence the bullets fired directly like causing the bullet to bounce or give a status effect. Others create extra instances of the bullet, exp. shotgun, or influence enemy death to cause aoe damage or turn to stone. I have two ideas on how to do this.
The game is a roguelike so at the start of every run it checks the 5 gun slots and pulls the stats from the global.lootTable using an accessor [# somenumb, yOffset]. yOffset is the gun and the somenumb is pulled sequentially to load the data into an array for each slot. At this point I have a choice. I can leave the data for the traits as a string or I can interpret them with a string comparison script that returns an enum.
1. If I leave it as a string every shot fired will run the trait strings through a switch comparison. This has little effect if it has no traits as it is the first case. However if its traits are near the bottom it will need to run a comparison through all 30+ traits above it. Once the trait is found it runs the code to influence the game.
2. If I make each trait an enum it increases both memory usage and load times. This caused build time to go up 2ish seconds which isn't too bad. But as I can give each trait a numerical value I can run a if-else statement that splits all the traits into groups of ten or so. Then a switch statement finds the exact value and runs the code to influence the game. This caps the most amount of checks to 12 before the code fires. each new set of ten adds one to the max checks.
The problem I have is that I am not too familiar with the strain enums cause. Could this many enums make the additional checks caused by a string comparison a better choice? Is there a much simpler option that I am missing?
edit: I would like to add that the fastest firing weapon with traits fires 12 per second meaning the checks ran per second for 1 is 360 vs 144 for the 2
The game is a roguelike so at the start of every run it checks the 5 gun slots and pulls the stats from the global.lootTable using an accessor [# somenumb, yOffset]. yOffset is the gun and the somenumb is pulled sequentially to load the data into an array for each slot. At this point I have a choice. I can leave the data for the traits as a string or I can interpret them with a string comparison script that returns an enum.
1. If I leave it as a string every shot fired will run the trait strings through a switch comparison. This has little effect if it has no traits as it is the first case. However if its traits are near the bottom it will need to run a comparison through all 30+ traits above it. Once the trait is found it runs the code to influence the game.
2. If I make each trait an enum it increases both memory usage and load times. This caused build time to go up 2ish seconds which isn't too bad. But as I can give each trait a numerical value I can run a if-else statement that splits all the traits into groups of ten or so. Then a switch statement finds the exact value and runs the code to influence the game. This caps the most amount of checks to 12 before the code fires. each new set of ten adds one to the max checks.
The problem I have is that I am not too familiar with the strain enums cause. Could this many enums make the additional checks caused by a string comparison a better choice? Is there a much simpler option that I am missing?
edit: I would like to add that the fastest firing weapon with traits fires 12 per second meaning the checks ran per second for 1 is 360 vs 144 for the 2
Last edited: