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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.235 by root, Tue May 6 20:00:12 2008 UTC vs.
Revision 1.238 by root, Wed May 7 11:02:50 2008 UTC

904 * drop on that space. 904 * drop on that space.
905 */ 905 */
906 if (!drop_to_ground 906 if (!drop_to_ground
907 || !map 907 || !map
908 || map->in_memory != MAP_ACTIVE 908 || map->in_memory != MAP_ACTIVE
909 || map->nodrop 909 || map->no_drop
910 || ms ().move_block == MOVE_ALL) 910 || ms ().move_block == MOVE_ALL)
911 { 911 {
912 while (inv) 912 while (inv)
913 { 913 {
914 inv->destroy_inv (false); 914 inv->destroy_inv (false);
943 943
944static struct freed_map : maptile 944static struct freed_map : maptile
945{ 945{
946 freed_map () 946 freed_map ()
947 { 947 {
948 path = "<freed objects map>"; 948 path = "<freed objects map>";
949 name = "/internal/freed_objects_map"; 949 name = "/internal/freed_objects_map";
950 width = 3; 950 width = 3;
951 height = 3; 951 height = 3;
952 nodrop = 1; 952 no_drop = 1;
953 no_reset = 1;
953 954
954 alloc (); 955 alloc ();
955 in_memory = MAP_ACTIVE; 956 in_memory = MAP_ACTIVE;
956 } 957 }
957 958
1056 if (object *pl = visible_to ()) 1057 if (object *pl = visible_to ())
1057 esrv_del_item (pl->contr, count); 1058 esrv_del_item (pl->contr, count);
1058 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed 1059 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1059 1060
1060 adjust_weight (env, -total_weight ()); 1061 adjust_weight (env, -total_weight ());
1061
1062 *(above ? &above->below : &env->inv) = below;
1063
1064 if (below)
1065 below->above = above;
1066 1062
1067 /* we set up values so that it could be inserted into 1063 /* we set up values so that it could be inserted into
1068 * the map, but we don't actually do that - it is up 1064 * the map, but we don't actually do that - it is up
1069 * to the caller to decide what we want to do. 1065 * to the caller to decide what we want to do.
1070 */ 1066 */
1071 map = env->map; 1067 map = env->map;
1072 x = env->x; 1068 x = env->x;
1073 y = env->y; 1069 y = env->y;
1070
1071 // make sure cmov optimisation is applicable
1072 *(above ? &above->below : &env->inv) = below;
1073 *(below ? &below->above : &above ) = above; // &above is just a dummy
1074
1074 above = 0; 1075 above = 0;
1075 below = 0; 1076 below = 0;
1076 env = 0; 1077 env = 0;
1077 1078
1078 /* NO_FIX_PLAYER is set when a great many changes are being 1079 /* NO_FIX_PLAYER is set when a great many changes are being
1108 1109
1109 esrv_del_item (pl->contr, count); 1110 esrv_del_item (pl->contr, count);
1110 } 1111 }
1111 1112
1112 /* link the object above us */ 1113 /* link the object above us */
1113 if (above) 1114 // re-link, make sure compiler can easily use cmove
1114 above->below = below; 1115 *(above ? &above->below : &ms.top) = below;
1115 else 1116 *(below ? &below->above : &ms.bot) = above;
1116 ms.top = below; /* we were top, set new top */
1117
1118 /* Relink the object below us, if there is one */
1119 if (below)
1120 below->above = above;
1121 else
1122 ms.bot = above;
1123 1117
1124 above = 0; 1118 above = 0;
1125 below = 0; 1119 below = 0;
1126 1120
1127 if (map->in_memory == MAP_SAVING) 1121 if (map->in_memory == MAP_SAVING)
1274 * just 'op' otherwise 1268 * just 'op' otherwise
1275 */ 1269 */
1276object * 1270object *
1277insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1271insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1278{ 1272{
1279 assert (!op->flag [FLAG_FREED]);
1280
1281 op->remove (); 1273 op->remove ();
1282 1274
1283 /* Ideally, the caller figures this out. However, it complicates a lot 1275 /* Ideally, the caller figures this out. However, it complicates a lot
1284 * of areas of callers (eg, anything that uses find_free_spot would now 1276 * of areas of callers (eg, anything that uses find_free_spot would now
1285 * need extra work 1277 * need extra work
1303 */ 1295 */
1304 if (op->nrof && !(flag & INS_NO_MERGE)) 1296 if (op->nrof && !(flag & INS_NO_MERGE))
1305 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 1297 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1306 if (object::can_merge (op, tmp)) 1298 if (object::can_merge (op, tmp))
1307 { 1299 {
1308 // TODO: we atcually want to update tmp, not op, 1300 // TODO: we actually want to update tmp, not op,
1309 // but some caller surely breaks when we return tmp 1301 // but some caller surely breaks when we return tmp
1310 // from here :/ 1302 // from here :/
1311 op->nrof += tmp->nrof; 1303 op->nrof += tmp->nrof;
1312 tmp->destroy (1); 1304 tmp->destroy (1);
1313 } 1305 }
1318 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1310 if (!QUERY_FLAG (op, FLAG_ALIVE))
1319 CLEAR_FLAG (op, FLAG_NO_STEAL); 1311 CLEAR_FLAG (op, FLAG_NO_STEAL);
1320 1312
1321 if (flag & INS_BELOW_ORIGINATOR) 1313 if (flag & INS_BELOW_ORIGINATOR)
1322 { 1314 {
1323 if (originator->map != op->map || originator->x != op->x || originator->y != op->y) 1315 if (originator->map != op->map || originator->x != op->x || originator->y != op->y || !originator->is_on_map ())
1324 { 1316 {
1325 LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); 1317 LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n");
1326 abort (); 1318 abort ();
1327 } 1319 }
1328 1320
1329 op->above = originator; 1321 op->above = originator;
1330 op->below = originator->below; 1322 op->below = originator->below;
1331
1332 if (op->below)
1333 op->below->above = op;
1334 else
1335 ms.bot = op;
1336
1337 /* since *below* originator, no need to update top */
1338 originator->below = op; 1323 originator->below = op;
1324
1325 *(op->below ? &op->below->above : &ms.bot) = op;
1339 } 1326 }
1340 else 1327 else
1341 { 1328 {
1342 object *top, *floor = NULL; 1329 object *floor = 0;
1343 1330 object *top = ms.top;
1344 top = ms.bot;
1345 1331
1346 /* If there are other objects, then */ 1332 /* If there are other objects, then */
1347 if (top) 1333 if (top)
1348 { 1334 {
1349 object *last = 0;
1350
1351 /* 1335 /*
1352 * If there are multiple objects on this space, we do some trickier handling. 1336 * If there are multiple objects on this space, we do some trickier handling.
1353 * We've already dealt with merging if appropriate. 1337 * We've already dealt with merging if appropriate.
1354 * Generally, we want to put the new object on top. But if 1338 * Generally, we want to put the new object on top. But if
1355 * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last 1339 * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last
1358 * once we get to them. This reduces the need to traverse over all of 1342 * once we get to them. This reduces the need to traverse over all of
1359 * them when adding another one - this saves quite a bit of cpu time 1343 * them when adding another one - this saves quite a bit of cpu time
1360 * when lots of spells are cast in one area. Currently, it is presumed 1344 * when lots of spells are cast in one area. Currently, it is presumed
1361 * that flying non pickable objects are spell objects. 1345 * that flying non pickable objects are spell objects.
1362 */ 1346 */
1363 for (top = ms.bot; top; top = top->above) 1347 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1364 { 1348 {
1365 if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) 1349 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) || QUERY_FLAG (tmp, FLAG_OVERLAY_FLOOR))
1366 floor = top; 1350 floor = tmp;
1367 1351
1368 if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) 1352 if (QUERY_FLAG (tmp, FLAG_NO_PICK) && (tmp->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1369 { 1353 {
1370 /* We insert above top, so we want this object below this */ 1354 /* We insert above top, so we want this object below this */
1371 top = top->below; 1355 top = tmp->below;
1372 break; 1356 break;
1373 } 1357 }
1374 1358
1375 last = top; 1359 top = tmp;
1376 } 1360 }
1377
1378 /* Don't want top to be NULL, so set it to the last valid object */
1379 top = last;
1380 1361
1381 /* We let update_position deal with figuring out what the space 1362 /* We let update_position deal with figuring out what the space
1382 * looks like instead of lots of conditions here. 1363 * looks like instead of lots of conditions here.
1383 * makes things faster, and effectively the same result. 1364 * makes things faster, and effectively the same result.
1384 */ 1365 */
1391 */ 1372 */
1392 if (!(flag & INS_ON_TOP) 1373 if (!(flag & INS_ON_TOP)
1393 && ms.flags () & P_BLOCKSVIEW 1374 && ms.flags () & P_BLOCKSVIEW
1394 && (op->face && !faces [op->face].visibility)) 1375 && (op->face && !faces [op->face].visibility))
1395 { 1376 {
1377 object *last;
1378
1396 for (last = top; last != floor; last = last->below) 1379 for (last = top; last != floor; last = last->below)
1397 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) 1380 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT))
1398 break; 1381 break;
1399 1382
1400 /* Check to see if we found the object that blocks view, 1383 /* Check to see if we found the object that blocks view,
1411 top = floor; 1394 top = floor;
1412 1395
1413 /* Top is the object that our object (op) is going to get inserted above. 1396 /* Top is the object that our object (op) is going to get inserted above.
1414 */ 1397 */
1415 1398
1416 /* First object on this space */ 1399 /* no top found, insert on top */
1417 if (!top) 1400 if (!top)
1418 { 1401 {
1419 op->above = ms.bot;
1420
1421 if (op->above)
1422 op->above->below = op;
1423
1424 op->below = 0; 1402 op->above = 0;
1403 op->below = ms.top;
1425 ms.bot = op; 1404 ms.top = op;
1405
1406 *(op->below ? &op->below->above : &ms.bot) = op;
1426 } 1407 }
1427 else 1408 else
1428 { /* get inserted into the stack above top */ 1409 { /* get inserted into the stack above top */
1429 op->above = top->above; 1410 op->above = top->above;
1430
1431 if (op->above)
1432 op->above->below = op; 1411 top->above = op;
1433 1412
1434 op->below = top; 1413 op->below = top;
1435 top->above = op; 1414 *(op->above ? &op->above->below : &ms.top) = op;
1436 } 1415 }
1437
1438 if (!op->above)
1439 ms.top = op;
1440 } /* else not INS_BELOW_ORIGINATOR */ 1416 } /* else not INS_BELOW_ORIGINATOR */
1441 1417
1442 if (op->type == PLAYER) 1418 if (op->type == PLAYER)
1443 { 1419 {
1444 op->contr->do_los = 1; 1420 op->contr->do_los = 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines