ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.115 by root, Wed Aug 1 01:53:13 2007 UTC vs.
Revision 1.122 by root, Thu Aug 30 05:24:14 2007 UTC

355} 355}
356 356
357void 357void
358maptile::activate () 358maptile::activate ()
359{ 359{
360 active = true;
361
362 if (spaces) 360 if (spaces)
363 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 361 for (mapspace *ms = spaces + size (); ms-- > spaces; )
364 for (object *op = ms->bot; op; op = op->above) 362 for (object *op = ms->bot; op; op = op->above)
365 op->activate_recursive (); 363 op->activate_recursive ();
366} 364}
367 365
368void 366void
369maptile::deactivate () 367maptile::deactivate ()
370{ 368{
371 active = false;
372
373 if (spaces) 369 if (spaces)
374 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 370 for (mapspace *ms = spaces + size (); ms-- > spaces; )
375 for (object *op = ms->bot; op; op = op->above) 371 for (object *op = ms->bot; op; op = op->above)
376 op->deactivate_recursive (); 372 op->deactivate_recursive ();
377} 373}
387 if (!spaces) 383 if (!spaces)
388 return false; 384 return false;
389 385
390 for (int i = 0; i < size (); ++i) 386 for (int i = 0; i < size (); ++i)
391 { 387 {
392 int unique = 0; 388 bool unique = 0;
389
393 for (object *op = spaces [i].bot; op; op = op->above) 390 for (object *op = spaces [i].bot; op; op = op->above)
394 { 391 {
395 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) 392 unique |= op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR];
396 unique = 1;
397 393
398 if (!op->can_map_save ()) 394 if (expect_false (!op->can_map_save ()))
399 continue; 395 continue;
400 396
401 if (unique || op->flag [FLAG_UNIQUE]) 397 if (expect_false (unique || op->flag [FLAG_UNIQUE]))
402 { 398 {
403 if (flags & IO_UNIQUES) 399 if (flags & IO_UNIQUES)
404 op->write (f); 400 op->write (f);
405 } 401 }
406 else if (flags & IO_OBJECTS) 402 else if (expect_true (flags & IO_OBJECTS))
407 op->write (f); 403 op->write (f);
408 } 404 }
409 } 405 }
410 406
411 coroapi::cede_to_tick (); 407 coroapi::cede_to_tick ();
893 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 889 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
894 break; 890 break;
895 891
896 if (QUERY_FLAG (op, FLAG_IS_FLOOR) 892 if (QUERY_FLAG (op, FLAG_IS_FLOOR)
897 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) 893 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL)
898 || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL)
899 || QUERY_FLAG (op, FLAG_UNIQUE) 894 || QUERY_FLAG (op, FLAG_UNIQUE)
900 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) 895 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)
901 || QUERY_FLAG (op, FLAG_UNPAID) 896 || QUERY_FLAG (op, FLAG_UNPAID)
902 || op->is_alive ()) 897 || op->is_alive ())
903 ; // do not decay 898 ; // do not decay
1228 vol += op->volume (); 1223 vol += op->volume ();
1229 1224
1230 return vol; 1225 return vol;
1231} 1226}
1232 1227
1233/* this updates the orig_map->tile_map[tile_num] value after finding 1228bool
1234 * the map. It also takes care of linking back the freshly found 1229maptile::tile_available (int dir, bool load)
1235 * maps tile_map values if it tiles back to this one. It returns
1236 * the value of orig_map->tile_map[tile_num].
1237 */
1238static inline maptile *
1239find_and_link (maptile *orig_map, int tile_num)
1240{ 1230{
1241 maptile *mp = orig_map->tile_map [tile_num]; 1231 if (!tile_path[dir])
1232 return 0;
1242 1233
1243 if (!mp) 1234 if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_IN_MEMORY))
1244 { 1235 return 1;
1245 mp = orig_map->find_sync (orig_map->tile_path [tile_num], orig_map);
1246 1236
1247 if (!mp) 1237 if ((tile_map[dir] = find_async (tile_path[dir], this, load)))
1248 { 1238 return 1;
1249 // emergency mode, manufacture a dummy map, this creates a memleak, but thats fine
1250 LOG (llevError, "FATAL: cannot load tiled map %s from %s, leaking memory and worse!\n",
1251 &orig_map->tile_path[tile_num], &orig_map->path);
1252 mp = new maptile (1, 1);
1253 mp->alloc ();
1254 mp->in_memory = MAP_IN_MEMORY;
1255 }
1256 }
1257 1239
1258 int dest_tile = (tile_num + 2) % 4;
1259
1260 orig_map->tile_map [tile_num] = mp;
1261
1262 // optimisation: back-link map to origin map if euclidean
1263 //TODO: non-euclidean maps MUST GO
1264 if (orig_map->tile_map[tile_num]->tile_path[dest_tile] == orig_map->path)
1265 orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map;
1266
1267 return mp; 1240 return 0;
1268}
1269
1270static inline void
1271load_and_link (maptile *orig_map, int tile_num)
1272{
1273 find_and_link (orig_map, tile_num)->load_sync ();
1274} 1241}
1275 1242
1276/* this returns TRUE if the coordinates (x,y) are out of 1243/* this returns TRUE if the coordinates (x,y) are out of
1277 * map m. This function also takes into account any 1244 * map m. This function also takes into account any
1278 * tiling considerations, loading adjacant maps as needed. 1245 * tiling considerations, loading adjacant maps as needed.
1291 if (!m) 1258 if (!m)
1292 return 0; 1259 return 0;
1293 1260
1294 if (x < 0) 1261 if (x < 0)
1295 { 1262 {
1296 if (!m->tile_path[3]) 1263 if (!m->tile_available (3))
1297 return 1; 1264 return 1;
1298 1265
1299 if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY)
1300 find_and_link (m, 3);
1301
1302 return out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y); 1266 return out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y);
1303 } 1267 }
1304 1268
1305 if (x >= m->width) 1269 if (x >= m->width)
1306 { 1270 {
1307 if (!m->tile_path[1]) 1271 if (!m->tile_available (1))
1308 return 1; 1272 return 1;
1309 1273
1310 if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY)
1311 find_and_link (m, 1);
1312
1313 return out_of_map (m->tile_map[1], x - m->width, y); 1274 return out_of_map (m->tile_map[1], x - m->width, y);
1314 } 1275 }
1315 1276
1316 if (y < 0) 1277 if (y < 0)
1317 { 1278 {
1318 if (!m->tile_path[0]) 1279 if (!m->tile_available (0))
1319 return 1; 1280 return 1;
1320 1281
1321 if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY)
1322 find_and_link (m, 0);
1323
1324 return out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height); 1282 return out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height);
1325 } 1283 }
1326 1284
1327 if (y >= m->height) 1285 if (y >= m->height)
1328 { 1286 {
1329 if (!m->tile_path[2]) 1287 if (!m->tile_available (2))
1330 return 1; 1288 return 1;
1331
1332 if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY)
1333 find_and_link (m, 2);
1334 1289
1335 return out_of_map (m->tile_map[2], x, y - m->height); 1290 return out_of_map (m->tile_map[2], x, y - m->height);
1336 } 1291 }
1337 1292
1338 /* Simple case - coordinates are within this local 1293 /* Simple case - coordinates are within this local
1352maptile * 1307maptile *
1353maptile::xy_find (sint16 &x, sint16 &y) 1308maptile::xy_find (sint16 &x, sint16 &y)
1354{ 1309{
1355 if (x < 0) 1310 if (x < 0)
1356 { 1311 {
1357 if (!tile_path[3]) 1312 if (!tile_available (3))
1358 return 0; 1313 return 0;
1359 1314
1360 find_and_link (this, 3);
1361 x += tile_map[3]->width; 1315 x += tile_map[3]->width;
1362 return tile_map[3]->xy_find (x, y); 1316 return tile_map[3]->xy_find (x, y);
1363 } 1317 }
1364 1318
1365 if (x >= width) 1319 if (x >= width)
1366 { 1320 {
1367 if (!tile_path[1]) 1321 if (!tile_available (1))
1368 return 0; 1322 return 0;
1369 1323
1370 find_and_link (this, 1);
1371 x -= width; 1324 x -= width;
1372 return tile_map[1]->xy_find (x, y); 1325 return tile_map[1]->xy_find (x, y);
1373 } 1326 }
1374 1327
1375 if (y < 0) 1328 if (y < 0)
1376 { 1329 {
1377 if (!tile_path[0]) 1330 if (!tile_available (0))
1378 return 0; 1331 return 0;
1379 1332
1380 find_and_link (this, 0);
1381 y += tile_map[0]->height; 1333 y += tile_map[0]->height;
1382 return tile_map[0]->xy_find (x, y); 1334 return tile_map[0]->xy_find (x, y);
1383 } 1335 }
1384 1336
1385 if (y >= height) 1337 if (y >= height)
1386 { 1338 {
1387 if (!tile_path[2]) 1339 if (!tile_available (2))
1388 return 0; 1340 return 0;
1389 1341
1390 find_and_link (this, 2);
1391 y -= height; 1342 y -= height;
1392 return tile_map[2]->xy_find (x, y); 1343 return tile_map[2]->xy_find (x, y);
1393 } 1344 }
1394 1345
1395 /* Simple case - coordinates are within this local 1346 /* Simple case - coordinates are within this local
1406adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) 1357adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy)
1407{ 1358{
1408 if (!map1 || !map2) 1359 if (!map1 || !map2)
1409 return 0; 1360 return 0;
1410 1361
1411 //TODO: this doesn't actually check corretcly when intermediate maps are not loaded 1362 //TODO: this doesn't actually check correctly when intermediate maps are not loaded
1412 //fix: compare paths instead (this is likely faster, too!) 1363 //fix: compare paths instead (this is likely faster, too!)
1413 if (map1 == map2) 1364 if (map1 == map2)
1414 { 1365 {
1415 *dx = 0; 1366 *dx = 0;
1416 *dy = 0; 1367 *dy = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines