--- deliantra/server/common/arch.C 2006/09/08 17:14:07 1.14 +++ deliantra/server/common/arch.C 2006/09/10 13:20:12 1.15 @@ -1,6 +1,7 @@ + /* * static char *rcsid_arch_c = - * "$Id: arch.C,v 1.14 2006/09/08 17:14:07 root Exp $"; + * "$Id: arch.C,v 1.15 2006/09/10 13:20:12 root Exp $"; */ /* @@ -38,7 +39,7 @@ /* IF set, does a little timing on the archetype load. */ #define TIME_ARCH_LOAD 0 -static void add_arch (archetype * at); +static void add_arch (archetype *at); static archetype *arch_table[ARCHTABLE]; int arch_cmp = 0; /* How many strcmp's */ @@ -55,9 +56,13 @@ #if USE_UNORDERED_MAP // the hashtable -typedef std::tr1::unordered_map HT; +typedef + std::tr1::unordered_map < +size_t, archetype *> + HT; -static HT ht; +static HT + ht; #endif /** @@ -74,7 +79,8 @@ archetype * find_archetype_by_object_name (const char *name) { - archetype *at; + archetype * + at; if (name == NULL) return (archetype *) NULL; @@ -95,7 +101,8 @@ archetype * find_archetype_by_object_type_name (int type, const char *name) { - archetype *at; + archetype * + at; if (name == NULL) return NULL; @@ -206,7 +213,7 @@ * Last, make a check on the full name. */ int -item_matched_string (object * pl, object * op, const char *name) +item_matched_string (object *pl, object *op, const char *name) { char * cp, @@ -214,6 +221,7 @@ int count, retval = 0; + strcpy (local_name, name); /* strtok is destructive to name */ for (cp = strtok (local_name, ","); cp; cp = strtok (NULL, ",")) @@ -328,6 +336,7 @@ load_archetypes (); arch_init = 0; empty_archetype = find_archetype ("empty_archetype"); + /* init_blocksview();*/ } @@ -337,7 +346,7 @@ */ void -arch_info (object * op) +arch_info (object *op) { sprintf (errmsg, "%d searches and %d strcmp()'s", arch_search, arch_cmp); new_draw_info (NDI_BLACK, 0, op, errmsg); @@ -360,7 +369,8 @@ void init_archetable (void) { - archetype *at; + archetype * + at; LOG (llevDebug, " Setting up archetable...\n"); @@ -375,7 +385,7 @@ */ void -dump_arch (archetype * at) +dump_arch (archetype *at) { dump_object (&at->clone); } @@ -391,6 +401,7 @@ { archetype * at; + for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) { dump_arch (at); @@ -414,8 +425,7 @@ else next = at->next; - delete - at; + delete at; i++; } LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); @@ -423,9 +433,9 @@ archetype::archetype () { - clear_object (&clone); /* to initial state other also */ - CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_object() */ - SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */ + clear_object (&clone); /* to initial state other also */ + CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_object() */ + SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */ } archetype::~archetype () @@ -439,7 +449,9 @@ void first_arch_pass (object_thawer & fp) { - archetype *at, *head = NULL, *last_more = NULL; + archetype * + at, * + head = NULL, *last_more = NULL; at->clone.arch = first_archetype = at = new archetype; @@ -456,57 +468,59 @@ switch (i) { - case LL_NORMAL: /* A new archetype, just link it with the previous */ - if (last_more != NULL) - last_more->next = at; - if (head != NULL) - head->next = at; - head = last_more = at; + case LL_NORMAL: /* A new archetype, just link it with the previous */ + if (last_more != NULL) + last_more->next = at; + if (head != NULL) + head->next = at; + head = last_more = at; #if 0 - if (!op->type) - LOG (llevDebug, " WARNING: Archetype %s has no type info!\n", op->arch->name); + if (!op->type) + LOG (llevDebug, " WARNING: Archetype %s has no type info!\n", op->arch->name); #endif - at->tail_x = 0; - at->tail_y = 0; - break; - - case LL_MORE: /* Another part of the previous archetype, link it correctly */ - - at->head = head; - at->clone.head = &head->clone; - if (last_more != NULL) - { - last_more->more = at; - last_more->clone.more = &at->clone; - } - last_more = at; - - /* If this multipart image is still composed of individual small - * images, don't set the tail_.. values. We can't use them anyways, - * and setting these to zero makes the map sending to the client much - * easier as just looking at the head, we know what to do. - */ - if (at->clone.face != head->clone.face) - { - head->tail_x = 0; - head->tail_y = 0; - } - else - { - if (at->clone.x > head->tail_x) - head->tail_x = at->clone.x; - if (at->clone.y > head->tail_y) - head->tail_y = at->clone.y; - } - break; + at->tail_x = 0; + at->tail_y = 0; + break; + + case LL_MORE: /* Another part of the previous archetype, link it correctly */ + + at->head = head; + at->clone.head = &head->clone; + if (last_more != NULL) + { + last_more->more = at; + last_more->clone.more = &at->clone; + } + last_more = at; + + /* If this multipart image is still composed of individual small + * images, don't set the tail_.. values. We can't use them anyways, + * and setting these to zero makes the map sending to the client much + * easier as just looking at the head, we know what to do. + */ + if (at->clone.face != head->clone.face) + { + head->tail_x = 0; + head->tail_y = 0; + } + else + { + if (at->clone.x > head->tail_x) + head->tail_x = at->clone.x; + if (at->clone.y > head->tail_y) + head->tail_y = at->clone.y; + } + break; } at = new archetype; + at->clone.arch = at; } - delete at; + delete + at; } /* @@ -517,8 +531,11 @@ void second_arch_pass (object_thawer & thawer) { - char buf[MAX_BUF], *variable = buf, *argument, *cp; - archetype *at = NULL, *other; + char + buf[MAX_BUF], * + variable = buf, *argument, *cp; + archetype * + at = NULL, *other; while (fgets (buf, MAX_BUF, thawer) != NULL) { @@ -555,6 +572,7 @@ { treasurelist * tl = find_treasurelist (argument); + if (tl == NULL) LOG (llevError, "Failed to link treasure to arch (%s): %s\n", &at->name, argument); else @@ -570,6 +588,7 @@ { archetype * at; + for (at = first_archetype; at != NULL; at = at->next) if (QUERY_FLAG (&at->clone, FLAG_GENERATOR) && at->clone.other_arch == NULL) LOG (llevError, "Warning: %s is generator but lacks other_arch.\n", &at->name); @@ -588,6 +607,7 @@ { char filename[MAX_BUF]; + #if TIME_ARCH_LOAD struct timeval tv1, @@ -598,8 +618,7 @@ LOG (llevDebug, "Reading archetypes from %s:\n", filename); { - object_thawer - thawer (filename); + object_thawer thawer (filename); clear_archetable (); LOG (llevDebug, " arch-pass 1...\n"); @@ -611,8 +630,7 @@ warn_archetypes = 1; { - object_thawer - thawer (filename); + object_thawer thawer (filename); LOG (llevDebug, " loading treasure...\n"); load_treasures (); @@ -632,20 +650,23 @@ */ object * -arch_to_object (archetype * at) +arch_to_object (archetype *at) { object * op; + if (at == NULL) { if (warn_archetypes) LOG (llevError, "Couldn't find archetype.\n"); + return NULL; } + op = get_object (); copy_object (&at->clone, op); - op->instantiate (); op->arch = at; + op->instantiate (); return op; } @@ -659,8 +680,11 @@ object * create_singularity (const char *name) { - object *op; - char buf[MAX_BUF]; + object * + op; + char + buf[MAX_BUF]; + sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); op = get_object (); op->name = op->name_pl = buf; @@ -676,10 +700,13 @@ object * get_archetype (const char *name) { - archetype *at; + archetype * + at; + at = find_archetype (name); if (at == NULL) return create_singularity (name); + return arch_to_object (at); } @@ -690,9 +717,12 @@ unsigned long hasharch (const char *str, int tablesize) { - unsigned long hash = 0; - unsigned int i = 0; - const char *p; + unsigned long + hash = 0; + unsigned int + i = 0; + const char * + p; /* use the one-at-a-time hash function, which supposedly is * better than the djb2-like one used by perl5.005, but @@ -727,7 +757,7 @@ if (!name) return 0; - HT::const_iterator i = ht.find ((size_t)name); + HT::const_iterator i = ht.find ((size_t) name); if (i == ht.end ()) return 0; @@ -735,8 +765,10 @@ return i->second; #endif - archetype *at; - unsigned long index; + archetype * + at; + unsigned long + index; if (name == NULL) return (archetype *) NULL; @@ -768,10 +800,11 @@ add_arch (archetype *at) { #if USE_UNORDERED_MAP - ht.insert (std::make_pair ((size_t)(const char *)at->name, at)); + ht.insert (std::make_pair ((size_t) (const char *) at->name, at)); #endif - int index = hasharch ((const char *) at->name, ARCHTABLE), org_index = index; + int + index = hasharch ((const char *) at->name, ARCHTABLE), org_index = index; for (;;) { @@ -836,7 +869,7 @@ */ object * -object_create_arch (archetype * at) +object_create_arch (archetype *at) { object * op, *