C# parameter passing philosophy question

Started by
2 comments, last by TheTroll 16 years, 10 months ago
I am working on a game where various units can be build. Transports, Militia, etc. There are a variety of unit templates, which contain information such as the texture used to display the unit, the base statistics, and so forth. Then there is a List of the actual units, which contains things like modifiers on the current unit (attack value down, etc), the unit's position, the unit's hit points, and a reference back to the template that was used to "build" it, etc. Here's what I'm looking for input into: I'm in a position where the unit itself doesn't know what it's base attack value (for instance) is. The template has that information. So I have a couple of options that I can think of, and probably better ones that I have not thought of! I use attack value as an example, but the thought process is the same for all the stuff I am looking at. (1) I can have the routines that need to use the total attack value get the base value from the templates and the modifiers from the unit itself. (2) I can pass the template structure (or more likely just the single template of the unit itself) into the routine that returns the total attack value. (3) I can put the base attack value into the unit itself as a field. This repeats data and uses memory, but removes the complication. Any thoughts? Thanks in advance, Bradley Eng-Kohn
Advertisement
Having the unit recalculate it's attack value and other values from the template very time it needs them, really seems likes a waste of processor time to me. So I would suggest making fields for these values. It is not really that much of a use of memory but would be a big waste of the processor.

theTroll
Yes, normally I'd agree. I forgot to mention it is turn based, so I've got a bit more leeway in this regard.
Even turned based games should have decent performance. Since most of the values you would have would be shorts then all and all the memory is not so bad. Also it would be a lot easier to debug if the units had all the values as part of the class. If you really wanted to worry about memory. What you could do is split your class up like this.

Static Unit Information; Name, model, textures, attack values, defense value ect.
Individual Unit Information; Location, current action, current health, ect.

Each unit class would have the individual data and a static class for the static unit information. That would keep you from repeating static data for each individual class.

theTroll

This topic is closed to new replies.

Advertisement