Sign in to follow this  
BEngKohn

C# parameter passing philosophy question

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this