c# - Is it better to parse an XML at program startup, or as needed by method calls? -
i'm creating game right in c# uses xml build skills of different characters. (this file contains attributes, such damage, have been stripped in example brevity's sake.)
<classes> <class name="mage"> <skill name="fireball"> </skill> </class> <class name="knight"> <skill name="slash"> </skill> </class> . . . </classes>
i'm creating xmlparser class grab skills each character based on name ('xmlparser.getskillsbyname("mage")' returns list of skills).
should xml file parsed @ startup of game , each set of skills assigned corresponding class type (mage, knight, etc.); or should parser called on need-to-know-basis? i.e. once player chooses class type, constructor class choice parse xml file skills associated it.
currently, i've started implementing latter choice. each class type has base type of 'player'. player has method skills class type based on name--so in constructor of each character, there line similar to
list<skill> myskills = base.getskillsbyname("mage");
i'm asking because place work doing similar, parse xml @ start , call list of objects based on need it.
both techniques viable in case choose parse @ load time. way game have better performance during play time, , eliminate risk of running data validation errors in middle of game.
Comments
Post a Comment