--- deliantra/server/common/map.C 2007/08/01 01:53:13 1.115 +++ deliantra/server/common/map.C 2007/08/24 00:40:31 1.118 @@ -357,8 +357,6 @@ void maptile::activate () { - active = true; - if (spaces) for (mapspace *ms = spaces + size (); ms-- > spaces; ) for (object *op = ms->bot; op; op = op->above) @@ -368,8 +366,6 @@ void maptile::deactivate () { - active = false; - if (spaces) for (mapspace *ms = spaces + size (); ms-- > spaces; ) for (object *op = ms->bot; op; op = op->above) @@ -1230,47 +1226,19 @@ return vol; } -/* this updates the orig_map->tile_map[tile_num] value after finding - * the map. It also takes care of linking back the freshly found - * maps tile_map values if it tiles back to this one. It returns - * the value of orig_map->tile_map[tile_num]. - */ -static inline maptile * -find_and_link (maptile *orig_map, int tile_num) +bool +maptile::tile_available (int dir, bool load) { - maptile *mp = orig_map->tile_map [tile_num]; - - if (!mp) - { - mp = orig_map->find_sync (orig_map->tile_path [tile_num], orig_map); - - if (!mp) - { - // 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; + if (!tile_path[dir]) + return 0; - orig_map->tile_map [tile_num] = mp; + if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_IN_MEMORY)) + return 1; - // 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; + if ((tile_map[dir] = find_async (tile_path[dir], this, load))) + return 1; - return mp; -} - -static inline void -load_and_link (maptile *orig_map, int tile_num) -{ - find_and_link (orig_map, tile_num)->load_sync (); + return 0; } /* this returns TRUE if the coordinates (x,y) are out of @@ -1293,45 +1261,33 @@ if (x < 0) { - if (!m->tile_path[3]) + if (!m->tile_available (3, 0)) return 1; - if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) - find_and_link (m, 3); - return out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y); } if (x >= m->width) { - if (!m->tile_path[1]) + if (!m->tile_available (1, 0)) return 1; - if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) - find_and_link (m, 1); - return out_of_map (m->tile_map[1], x - m->width, y); } if (y < 0) { - if (!m->tile_path[0]) + if (!m->tile_available (0, 0)) return 1; - if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) - find_and_link (m, 0); - return out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height); } if (y >= m->height) { - if (!m->tile_path[2]) + if (!m->tile_available (2, 0)) return 1; - if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) - find_and_link (m, 2); - return out_of_map (m->tile_map[2], x, y - m->height); } @@ -1354,40 +1310,36 @@ { if (x < 0) { - if (!tile_path[3]) + if (!tile_available (3, 1)) return 0; - find_and_link (this, 3); x += tile_map[3]->width; return tile_map[3]->xy_find (x, y); } if (x >= width) { - if (!tile_path[1]) + if (!tile_available (1, 1)) return 0; - find_and_link (this, 1); x -= width; return tile_map[1]->xy_find (x, y); } if (y < 0) { - if (!tile_path[0]) + if (!tile_available (0, 1)) return 0; - find_and_link (this, 0); y += tile_map[0]->height; return tile_map[0]->xy_find (x, y); } if (y >= height) { - if (!tile_path[2]) + if (!tile_available (2, 1)) return 0; - find_and_link (this, 2); y -= height; return tile_map[2]->xy_find (x, y); }