ID:265670
 
I was wondering, how much will it affect speed/CPU if I used the 'in' operator and lists instead of bit flags and the '&' operator in lists used merely for toggles?

e.g.
var/list/quests = new
if("Finding Anna" in quests)
// insead of
var/const/FINDING_ANNA = FLAG1|FLAG2
var/quests = (FINDING_ANNA|DEFEATING_KIDNAPPER)
if(FINDING_ANNA & quests)
Efficiency should be the last thing on your list to what you should be worrying about, so do the thing that is more logical to you, and if you experience slowdowns, *then* do optimization work.

For your question, bit flags would obviously be faster, but you are severely limited on how many things you can check (since bit flags in DM are limited to 16 bits in width) while lists can expand indefinitely. Even so, using a list rather than an integer won't slow your game down.

Generally, you should use bit flags when you have boolean-valued settings.

With a quest list, you're better off sticking with an actual list as it's the most extensible and makes the most design sense. Bit flags are limited to 16 bits in BYOND, which is inadequate for the purposes of keeping track of many quests. Not to mention, there could be sub-quests and such as well. Datums may also be a good way to go.

In any case, this sort of thing is never going to impact "tight code" that needs serious optimization.

Lummox JR
if you keep the quests list in alphabetical order you can find a given string in the list very quickly. if adding a quest to the list is a somewhat rare thing then you can keep the list in order as you add items to it.

you could also use an associated list, but that would require a unique field to identify each quest. indexing into an associated list should be much faster than using 'in' to find a quest.
Thanks everybody for your replies!

If anybody has any other method, I'll be glad to look through that, too. =)
I've always used a list matrix for quests, one column doesn't get too cluttered.
mob/var/list/Events[50][10]
//number of quests optional ,
//the second number is how many quest
//points one has to finish. (From 1-10, respectivly, yes?)
if(Events[1][1] && Events[1][2]) //blah blah

That way you can have multiple things needed to do in the quest, and have it mostly organized :D

I haven't figured out how to do like Events["quest 1"] ["block fixed"]. Haha wait, that might do it.

I'm not sure if this would be quite efficient, but it works quite well.