--- deliantra/server/common/object.C 2007/01/03 20:08:04 1.106 +++ deliantra/server/common/object.C 2007/01/07 02:39:13 1.108 @@ -1,6 +1,7 @@ /* CrossFire, A Multiplayer game for X-windows + Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team Copyright (C) 2001 Mark Wedel & Crossfire Development Team Copyright (C) 1992 Frank Tore Johansen @@ -38,7 +39,8 @@ static UUID uuid; const uint64 UUID_SKIP = 1<<19; -object *active_objects; /* List of active objects that need to be processed */ +objectvec objects; +activevec actives; short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 @@ -392,15 +394,12 @@ /* * Returns the object which has the count-variable equal to the argument. */ - object * find_object (tag_t i) { - for (object *op = object::first; op; op = op->next) - if (op->count == i) - return op; - - return 0; + return ((unsigned int)i) < objects.size () + ? objects [i] + : 0; } /* @@ -408,14 +407,13 @@ * Used only by the patch command, but not all that useful. * Enables features like "patch food 999" */ - object * find_object_name (const char *str) { shstr_cmp str_ (str); object *op; - for (op = object::first; op != NULL; op = op->next) + for_all_objects (op) if (op->name == str_) break; @@ -679,55 +677,25 @@ void object::link () { - count = ++ob_count; uuid = gen_uuid (); - prev = 0; - next = object::first; - - if (object::first) - object::first->prev = this; - - object::first = this; + objects.insert (this); } void object::unlink () { - if (this == object::first) - object::first = next; - - /* Remove this object from the list of used objects */ - if (prev) prev->next = next; - if (next) next->prev = prev; - - prev = 0; - next = 0; -} - -bool -object::active () const -{ - return active_next || active_prev || this == active_objects; + objects.erase (this); } void object::activate () { /* If already on active list, don't do anything */ - if (active ()) + if (active) return; if (has_active_speed ()) - { - /* process_events() expects us to insert the object at the beginning - * of the list. */ - active_next = active_objects; - - if (active_next) - active_next->active_prev = this; - - active_objects = this; - } + actives.insert (this); } void @@ -751,24 +719,10 @@ object::deactivate () { /* If not on the active list, nothing needs to be done */ - if (!active ()) + if (!active) return; - if (active_prev == 0) - { - active_objects = active_next; - if (active_next) - active_next->active_prev = 0; - } - else - { - active_prev->active_next = active_next; - if (active_next) - active_next->active_prev = active_prev; - } - - active_next = 0; - active_prev = 0; + actives.erase (this); } void @@ -902,9 +856,6 @@ owner = 0; enemy = 0; attacked_by = 0; - - // only relevant for players(?), but make sure of it anyways - contr = 0; } void