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)
ID:265670
Dec 2 2006, 7:46 am
|
|
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 |
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] 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. |
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.