--- deliantra/server/common/map.C 2006/12/30 18:45:27 1.58 +++ deliantra/server/common/map.C 2006/12/31 22:23:11 1.62 @@ -38,78 +38,9 @@ const char * create_pathname (const char *name) { - static char buf[MAX_BUF]; - - /* Why? having extra / doesn't confuse unix anyplace? Dependancies - * someplace else in the code? msw 2-17-97 - */ - if (*name == '/') - sprintf (buf, "%s/%s%s", settings.datadir, settings.mapdir, name); - else - sprintf (buf, "%s/%s/%s", settings.datadir, settings.mapdir, name); - return (buf); -} - -/* - * same as create_pathname, but for the overlay maps. - */ -const char * -create_overlay_pathname (const char *name) -{ - static char buf[MAX_BUF]; - - /* Why? having extra / doesn't confuse unix anyplace? Dependancies - * someplace else in the code? msw 2-17-97 - */ - if (*name == '/') - sprintf (buf, "%s/%s%s", settings.localdir, settings.mapdir, name); - else - sprintf (buf, "%s/%s/%s", settings.localdir, settings.mapdir, name); - return (buf); -} - -/* - * same as create_pathname, but for the template maps. - */ -const char * -create_template_pathname (const char *name) -{ - static char buf[MAX_BUF]; - - /* Why? having extra / doesn't confuse unix anyplace? Dependancies - * someplace else in the code? msw 2-17-97 - */ - if (*name == '/') - sprintf (buf, "%s/%s%s", settings.localdir, settings.templatedir, name); - else - sprintf (buf, "%s/%s/%s", settings.localdir, settings.templatedir, name); - return (buf); -} - -/* - * This makes absolute path to the itemfile where unique objects - * will be saved. Converts '/' to '@'. I think it's essier maintain - * files than full directory structure, but if this is problem it can - * be changed. - */ -static const char * -create_items_path (const char *s) -{ - static char buf[MAX_BUF]; - char *t; - - if (*s == '/') - s++; - - sprintf (buf, "%s/%s/", settings.localdir, settings.uniquedir); - - for (t = buf + strlen (buf); *s; s++, t++) - if (*s == '/') - *t = '@'; - else - *t = *s; - *t = 0; - return (buf); + static char buf[8192]; + snprintf (buf, sizeof (buf), "%s/%s/%s", settings.datadir, settings.mapdir, name); + return buf; } /* @@ -333,7 +264,7 @@ maptile *m1; sint16 sx, sy; - if (ob == NULL) + if (!ob) { flag = get_map_flags (m, &m1, x, y, &sx, &sy); if (flag & P_OUT_OF_MAP) @@ -530,7 +461,7 @@ for (mapspace *ms = spaces + size (); ms-- > spaces; ) for (object *op = ms->bot; op; op = op->above) - op->activate (1); + op->activate_recursive (); } void @@ -541,7 +472,7 @@ for (mapspace *ms = spaces + size (); ms-- > spaces; ) for (object *op = ms->bot; op; op = op->above) - op->deactivate (1); + op->deactivate_recursive (); } bool @@ -791,7 +722,7 @@ switch (kw) { case KW_EOF: - LOG (llevError, "%s: end of file while reading map header, aborting header load.", &path); + LOG (llevError, "%s: end of file while reading map header, aborting header load.\n", &path); return false; case KW_end: @@ -959,7 +890,7 @@ if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); - MAP_OUT2 (end, 0); + freezer.put (KW_end); return true; } @@ -1335,15 +1266,25 @@ static maptile * load_and_link_tiled_map (maptile *orig_map, int tile_num) { - maptile *mp = orig_map->find_map (orig_map->tile_path[tile_num]); - mp->load (); + maptile *mp = orig_map->load_map_sync (orig_map->tile_path [tile_num], orig_map); + + if (!mp || mp->in_memory != MAP_IN_MEMORY) + { + // emergency mode, manufacture a dummy map, this creates a memleak, but thats fine + LOG (llevError, "FATAL: cannot load tiled map %s from %s, leaking memory and worse!\n", + &orig_map->tile_path[tile_num], &orig_map->path); + mp = new maptile (1, 1); + mp->alloc (); + mp->in_memory = MAP_IN_MEMORY; + } int dest_tile = (tile_num + 2) % 4; orig_map->tile_map[tile_num] = mp; - /* need to do a strcmp here as the orig_map->path is not a shared string */ - if (orig_map->tile_map[tile_num]->tile_path[dest_tile] && orig_map->tile_map[tile_num]->tile_path[dest_tile] == orig_map->path) + // optimisation: back-link map to origin map if euclidean + //TODO: non-euclidean maps MUST GO + if (orig_map->tile_map[tile_num]->tile_path[dest_tile] == orig_map->path) orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map; return mp;