ID:149989
 
I've been designing an MORPG and trying to decide how to store stats. Instead of declaring each stat, I have tried using a stat container in each mob/obj/whatever. I have stat defaults that can be used if the mob/obj/whatever does not have a certain stat in its stat container.

Part of the idea has been that I can avoid multiple copies of stats. However, I can do that just by using the default if a stat is null.

What I am mainly concerned with is trying not to store too many null variables so I don't have the overhead for each mob/obj/whatever. However, there is an amount of speed loss (and code to write) which might be too much to justify the stat container if using a small amount of things with stats. (I would like to use a large amount.) If I can never reach the point where the memory taken by null variables affects performance, then a stat container won't be worth it.

Has the memory taken by null variables affected anyone? How many things with stats do people tend to allow on servers at once without "too much" memory consumption (within the range of a low budget for server money)? In practice, will the number of mobs/objs/whatever be too small to take advantage of a stat container?

I realize that these things vary, but I'm trying to get a rough idea so this thing doesn't blow up in my face when (/if) I get it on a server.

Thank you.
ACWraith wrote:
Has the memory taken by null variables affected anyone?

If a variable is the default value, it takes up no memory, no matter how many extra objects there are. A variable only takes up memory if it equals a non-default value.
In response to Deadron
Deadron wrote:
[snip]
If a variable is the default value, it takes up no memory, no matter how many extra objects there are. A variable only takes up memory if it equals a non-default value.

Cool. That helps a lot.

Everything will be initialized to null in my design and then I'll return whatever I decide if the value is null. (I'm going to have different defaults in different situations.)

Thank you. :)

(I'm used to working in C/C++ too much, huh?)
In response to ACWraith
Talk about your basic stalking, strangling, and dismembering Peter to sell his vital organs to pay Paul... you're certainly dedicated to making your code monumentally inefficient in the name of efficiency.

Take a look at this:

mob/var/strength = 8

mob
troll
strength = 23
ork
strength = 7
thief
strength = 4
warrior
strength = 15
xyclani
male
gender = "male"
strength = 3
female
gender = "female"
strength = 6

You realize that every single variable here is simply set to a default value? Default is whatever the variable is initialized to for a given object... it doesn't matter if there's a different default higher or lower on the object tree... it's still a default. The only time you're likely to have so many different "situations" that you can't handle different defaults with different branches of the object tree is with players themselves (i.e., if you have random attributes, or player-chosen ones)... and if you have so many players that you need to "optimize" your code for player variable handling, then you've got problems we'd all love to have.
In response to Lesbian Assassin
Heh, dedicated to making my effort inefficient anyway.

I plan on being able to edit every race/class/whatever online. Hardcode won't cut it in my little dreamland. (I plan on being able to charge a bit to take care of server costs. I'm not going to want to reboot constantly with paying customers to get upset.)