--- deliantra/server/common/object.C 2006/09/14 01:12:28 1.41 +++ deliantra/server/common/object.C 2006/09/14 22:33:59 1.47 @@ -1,4 +1,3 @@ - /* CrossFire, A Multiplayer game for X-windows @@ -19,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - The authors can be reached via e-mail at crossfire-devel@real-time.com + The authors can be reached via e-mail at */ /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. @@ -37,7 +36,6 @@ static UUID uuid; const uint64 UUID_SKIP = 1<<19; -object *objects; /* Pointer to the list of used objects */ object *active_objects; /* List of active objects that need to be processed */ 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, @@ -449,7 +447,7 @@ { object *op; - for (op = objects; op != NULL; op = op->next) + for (op = object::first; op != NULL; op = op->next) { dump_object (op); fprintf (logfile, "Object %d\n:%s\n", op->count, errmsg); @@ -485,7 +483,7 @@ { object *op; - for (op = objects; op != NULL; op = op->next) + for (op = object::first; op != NULL; op = op->next) if (op->count == i) break; return op; @@ -503,7 +501,7 @@ shstr_cmp str_ (str); object *op; - for (op = objects; op != NULL; op = op->next) + for (op = object::first; op != NULL; op = op->next) if (op->name == str_) break; @@ -517,27 +515,6 @@ } /* - * Returns the object which this object marks as being the owner. - * A id-scheme is used to avoid pointing to objects which have been - * freed and are now reused. If this is detected, the owner is - * set to NULL, and NULL is returned. - * Changed 2004-02-12 - if the player is setting at the play again - * prompt, he is removed, and we don't want to treat him as an owner of - * anything, so check removed flag. I don't expect that this should break - * anything - once an object is removed, it is basically dead anyways. - */ -object * -object::get_owner () -{ - if (!owner - || QUERY_FLAG (owner, FLAG_FREED) - || QUERY_FLAG (owner, FLAG_REMOVED)) - owner = 0; - - return owner; -} - -/* * Sets the owner and sets the skill and exp pointers to owner's current * skill and experience objects. */ @@ -614,7 +591,6 @@ expmul = 1.0; face = blank_face; - attacked_by_count = -1; if (settings.casting_time) casting_time = -1; @@ -919,24 +895,28 @@ update_object (op->more, action); } -static unordered_vector mortals; -static std::vector > freed; +object::vector object::mortals; +object::vector object::objects; // not yet used +object *object::first; void object::free_mortals () { - for (unordered_vector::iterator i = mortals.begin (); i != mortals.end ();) + for (AUTODECL (i, mortals.begin ()); i != mortals.end ();) if ((*i)->refcnt) ++i; // further delay freeing else { - //printf ("free_mortal(%p,%ld,%ld)\n", *i, pticks, (*i)->count);//D - //freed.push_back (*i);//D delete *i; mortals.erase (i); } - if (mortals.size() && 0)//D - LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D + static int lastmortals = 0;//D + + if (mortals.size() != lastmortals)//D + { + lastmortals = mortals.size ();//D + LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D + } } object::object () @@ -945,7 +925,6 @@ expmul = 1.0; face = blank_face; - attacked_by_count = -1; } object::~object () @@ -959,12 +938,12 @@ uuid = gen_uuid (); prev = 0; - next = objects; + next = object::first; - if (objects) - objects->prev = this; + if (object::first) + object::first->prev = this; - objects = this; + object::first = this; } void object::unlink () @@ -972,8 +951,8 @@ //count = 0;//D if (!prev && !next) return;//D - if (this == objects) - objects = next; + if (this == object::first) + object::first = next; /* Remove this object from the list of used objects */ if (prev) prev->next = next; @@ -985,19 +964,7 @@ object *object::create () { - object *op; - - if (freed.empty ()) - op = new object; - else - { - // highly annoying, but the only way to get it stable right now - op = freed.back (); - freed.pop_back (); - op->~object (); - new ((void *) op) object; - } - + object *op = new object; op->link (); return op; } @@ -1025,8 +992,6 @@ SET_FLAG (this, FLAG_FREED); - //printf ("free(%p,%ld,%ld)\n", this, pticks, count);//D - if (more) { more->free (free_inventory); @@ -1075,7 +1040,10 @@ } } - owner = 0; + // clear those pointers that likely might have circular references to us + owner = 0; + enemy = 0; + attacked_by = 0; /* Remove object from the active list */ speed = 0; @@ -1097,9 +1065,8 @@ while (op != NULL) { if (op->type == CONTAINER) - { - weight = (signed long) (weight * (100 - op->stats.Str) / 100); - } + weight = (signed long) (weight * (100 - op->stats.Str) / 100); + op->carrying -= weight; op = op->env; } @@ -1117,22 +1084,14 @@ void remove_ob (object *op) { - object * - tmp, * - last = NULL; - object * - otmp; + object *tmp, *last = 0; + object *otmp; + + tag_t tag; + int check_walk_off; + mapstruct *m; - tag_t - tag; - int - check_walk_off; - mapstruct * - m; - - sint16 - x, - y; + sint16 x, y; if (QUERY_FLAG (op, FLAG_REMOVED)) return; @@ -1330,7 +1289,7 @@ } } - return NULL; + return 0; } /* @@ -1667,7 +1626,7 @@ } } - tmp1 = arch_to_object (find_archetype (arch_string)); + tmp1 = arch_to_object (archetype::find (arch_string)); tmp1->x = op->x; tmp1->y = op->y;