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.237 by root, Tue May 6 21:04:37 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines