ID:154154
 
I'm fairly new in BYOND ( about 2/3's done with my first game ), and I'm wonder what is really more efficient. When I talk efficient I mean like the best speed:size ratio possible.

I have a few cases I was wondering about:
Firstly:
Is it more efficient to have lesser variables in /mob and more inside of like /mob/pc and /mob/monster even if they would be duplicate? I use a lot of variables such as ExpHitWorth and HitPoints inside of /mob/var instead of inside of /mob/monster. Would having things like shopkeepers and other NPC's who never engage in combat with these variables really be that much of an extra tax?

Secondly:
Is it better to reference procs within verbs to carry out actions? I don't know about this, but which do you think would work better?
verb
MyVerb()
MyProc()
Some ending action based on return
proc
MyProc()
Meat of the verb's action

Thirdly:
Are lists more efficient than regular variables? Like, would it be more efficient for me to use a var for each stat, or a list holding all of them?

Fourthly:
Does anyone know how difficult it is to execute if() statements? I use a TON of them in some of my procs & verbs, and I'm wondering how much damage they do ( I might be able to get rid of them if I were to use lists ), so I guess the question is: if() statements or lists?

Thanks in advance, and you can reply here with questions/comments or e-mail me @ [email protected] and replace nospam with shadowwolf :)
ShadowWolf wrote:
Is it more efficient to have lesser variables in /mob and more inside of like /mob/pc and /mob/monster even if they would be duplicate? I use a lot of variables such as ExpHitWorth and HitPoints inside of /mob/var instead of inside of /mob/monster. Would having things like shopkeepers and other NPC's who never engage in combat with these variables really be that much of an extra tax?

Whenever it makes sense to do so, you want to have the variables as high up the tree as possible (that is, at the mob/var level instead of the shopkeeper level). It is proper object-oriented technique that will save you a lot of hassle.

Also, in DM there is no additional space taken up for unused variables. If a mob doesn't have a value for a variable, no space is taken up. This means there is a different consideration: You will considerably impact your game if, for example, you set a value for every turf that you don't need to. That means thousands of cases of unnecessary space being taken up.


Secondly:
Is it better to reference procs within verbs to carry out actions? I don't know about this, but which do you think would work better?
verb
MyVerb()
MyProc()
Some ending action based on return
proc
MyProc()
Meat of the verb's action

There is no absolute right or wrong here. My personal opinion is that in most cases the verb should be nothing but a wrapper around a proc. Sometimes, though, I do query the player for more information in the verb before I call the proc -- that keeps the "view" and the "model" separate. (Hmm another BYONDscape article that would be useful...Model/View/Controller technique).


Does anyone know how difficult it is to execute if() statements? I use a TON of them in some of my procs & verbs, and I'm wondering how much damage they do ( I might be able to get rid of them if I were to use lists ), so I guess the question is: if() statements or lists?

I don't understand this question, and would have to see what you are doing.

Does anyone know how difficult it is to execute if() statements? I use a TON of them in some of my procs & verbs, and I'm wondering how much damage they do ( I might be able to get rid of them if I were to use lists ), so I guess the question is: if() statements or lists?

If I recall Deadron's earlier responce to my version of the same question:

80 if()'s wouldn't even be noticable.
800 if()'s might cause the game to "miss a beat" so to speak.

That's about all you need to know.
In response to Foomer
Foomer wrote:
If I recall Deadron's earlier responce to my version of the same question:

80 if()'s wouldn't even be noticable.
800 if()'s might cause the game to "miss a beat" so to speak.

That's about all you need to know.

This is true if the content of the if() statement is simple (I think you were doing simple comparison statements, which are very fast). However an if() statement could also be calling procs and doing who knows what all in there...so it's harder to say in this case, since I am not clear on when one would be choosing between if statements and lists.
In response to Deadron
Thanks for the answers ( both of you :) )

With the If() statements I mean in C++, an If() comparison takes up 4 clock cycles + objectives ( what it actually does ). I Figure there's probably a 1 clock cycle penalty because of the nature of DM and BYOND. That means 5 clock cycles per if() statement, which is very minor considering only about 20 - 40 if() statements would be occuring simultaniously.

Most of my if() statements do little else but call a proc or set a couple variabels, never both or more than 1 proc or 5 vars.

I try to avoid doing any extra comparisons because they're a waste of processor time ( efficiency-wise ) but are an evil necessity for logical operations.
In response to ShadowWolf
ShadowWolf wrote:
Thanks for the answers ( both of you :) )

With the If() statements I mean in C++, an If() comparison takes up 4 clock cycles + objectives ( what it actually does ). I Figure there's probably a 1 clock cycle penalty because of the nature of DM and BYOND. That means 5 clock cycles per if() statement, which is very minor considering only about 20 - 40 if() statements would be occuring simultaniously.

I can't say for sure but an if() in DM shouldn't be more expensive than in other languages.
In response to Deadron
What about comparing variables that require a lot of referencing (probably not correct terminoloy...) like this:

if(player.target.armor.strength < owner.weapon.puncture)
//do something

Those are completely made up and could be done a better way but I'm just wondering about that type of situation.

One more question. You said that variables that aren't given a value aren't actually assigned memory. Do you mean variables that are assigned their initial value and aren't changed don't take up extra memory or even giving it an initial value will give each datum it's own copy of it in memory?
In response to English
English wrote:
What about comparing variables that require a lot of referencing (probably not correct terminoloy...) like this:

if(player.target.armor.strength < owner.weapon.puncture)
//do something

Dan would have to say for sure...but it would be very unusual in the scheme of things for this sort of thing to make any difference. Almost always there are much bigger inefficiencies in the architecture of a game that are really slowing things down.


One more question. You said that variables that aren't given a value aren't actually assigned memory. Do you mean variables that are assigned their initial value and aren't changed don't take up extra memory or even giving it an initial value will give each datum it's own copy of it in memory?

Giving it an initial value does not take up memory.