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.236 by root, Tue May 6 20:08:37 2008 UTC vs.
Revision 1.241 by root, Wed May 7 19:19:09 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 // make sure cmov optimisation is applicable
1063 *(above ? &above->below : &env->inv) = below;
1064 *(below ? &below->above : &above ) = above; // &above is just a dummy
1065
1066 above = 0;
1067 below = 0;
1068 env = 0;
1069 1062
1070 /* we set up values so that it could be inserted into 1063 /* we set up values so that it could be inserted into
1071 * 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
1072 * to the caller to decide what we want to do. 1065 * to the caller to decide what we want to do.
1073 */ 1066 */
1074 map = env->map; 1067 map = env->map;
1075 x = env->x; 1068 x = env->x;
1076 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
1075 above = 0;
1076 below = 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
1079 * made to players inventory. If set, avoiding the call 1080 * made to players inventory. If set, avoiding the call
1080 * to save cpu time. 1081 * to save cpu time.
1081 */ 1082 */
1267 * just 'op' otherwise 1268 * just 'op' otherwise
1268 */ 1269 */
1269object * 1270object *
1270insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1271insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1271{ 1272{
1272 assert (!op->flag [FLAG_FREED]);
1273
1274 op->remove (); 1273 op->remove ();
1275 1274
1276 /* Ideally, the caller figures this out. However, it complicates a lot 1275 /* Ideally, the caller figures this out. However, it complicates a lot
1277 * 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
1278 * need extra work 1277 * need extra work
1296 */ 1295 */
1297 if (op->nrof && !(flag & INS_NO_MERGE)) 1296 if (op->nrof && !(flag & INS_NO_MERGE))
1298 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 1297 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1299 if (object::can_merge (op, tmp)) 1298 if (object::can_merge (op, tmp))
1300 { 1299 {
1301 // TODO: we atcually want to update tmp, not op, 1300 // TODO: we actually want to update tmp, not op,
1302 // but some caller surely breaks when we return tmp 1301 // but some caller surely breaks when we return tmp
1303 // from here :/ 1302 // from here :/
1304 op->nrof += tmp->nrof; 1303 op->nrof += tmp->nrof;
1305 tmp->destroy (1); 1304 tmp->destroy (1);
1306 } 1305 }
1317 { 1316 {
1318 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");
1319 abort (); 1318 abort ();
1320 } 1319 }
1321 1320
1321 if (!originator->is_on_map ())
1322 LOG (llevDebug | logBacktrace, "insert_ob_in_map(%s) called with INS_BELOW_ORIGINATOR when originator '%s' not on map",
1323 op->debug_desc (), originator->debug_desc ());
1324
1322 op->above = originator; 1325 op->above = originator;
1323 op->below = originator->below; 1326 op->below = originator->below;
1324
1325 if (op->below)
1326 op->below->above = op;
1327 else
1328 ms.bot = op;
1329
1330 /* since *below* originator, no need to update top */
1331 originator->below = op; 1327 originator->below = op;
1328
1329 *(op->below ? &op->below->above : &ms.bot) = op;
1332 } 1330 }
1333 else 1331 else
1334 { 1332 {
1335 object *top, *floor = NULL; 1333 object *floor = 0;
1336 1334 object *top = ms.top;
1337 top = ms.bot;
1338 1335
1339 /* If there are other objects, then */ 1336 /* If there are other objects, then */
1340 if (top) 1337 if (top)
1341 { 1338 {
1342 object *last = 0;
1343
1344 /* 1339 /*
1345 * If there are multiple objects on this space, we do some trickier handling. 1340 * If there are multiple objects on this space, we do some trickier handling.
1346 * We've already dealt with merging if appropriate. 1341 * We've already dealt with merging if appropriate.
1347 * Generally, we want to put the new object on top. But if 1342 * Generally, we want to put the new object on top. But if
1348 * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last 1343 * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last
1351 * once we get to them. This reduces the need to traverse over all of 1346 * once we get to them. This reduces the need to traverse over all of
1352 * them when adding another one - this saves quite a bit of cpu time 1347 * them when adding another one - this saves quite a bit of cpu time
1353 * when lots of spells are cast in one area. Currently, it is presumed 1348 * when lots of spells are cast in one area. Currently, it is presumed
1354 * that flying non pickable objects are spell objects. 1349 * that flying non pickable objects are spell objects.
1355 */ 1350 */
1356 for (top = ms.bot; top; top = top->above) 1351 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1357 { 1352 {
1358 if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) 1353 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) || QUERY_FLAG (tmp, FLAG_OVERLAY_FLOOR))
1359 floor = top; 1354 floor = tmp;
1360 1355
1361 if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) 1356 if (QUERY_FLAG (tmp, FLAG_NO_PICK) && (tmp->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1362 { 1357 {
1363 /* We insert above top, so we want this object below this */ 1358 /* We insert above top, so we want this object below this */
1364 top = top->below; 1359 top = tmp->below;
1365 break; 1360 break;
1366 } 1361 }
1367 1362
1368 last = top; 1363 top = tmp;
1369 } 1364 }
1370
1371 /* Don't want top to be NULL, so set it to the last valid object */
1372 top = last;
1373 1365
1374 /* We let update_position deal with figuring out what the space 1366 /* We let update_position deal with figuring out what the space
1375 * looks like instead of lots of conditions here. 1367 * looks like instead of lots of conditions here.
1376 * makes things faster, and effectively the same result. 1368 * makes things faster, and effectively the same result.
1377 */ 1369 */
1384 */ 1376 */
1385 if (!(flag & INS_ON_TOP) 1377 if (!(flag & INS_ON_TOP)
1386 && ms.flags () & P_BLOCKSVIEW 1378 && ms.flags () & P_BLOCKSVIEW
1387 && (op->face && !faces [op->face].visibility)) 1379 && (op->face && !faces [op->face].visibility))
1388 { 1380 {
1381 object *last;
1382
1389 for (last = top; last != floor; last = last->below) 1383 for (last = top; last != floor; last = last->below)
1390 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) 1384 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT))
1391 break; 1385 break;
1392 1386
1393 /* Check to see if we found the object that blocks view, 1387 /* Check to see if we found the object that blocks view,
1401 } /* If objects on this space */ 1395 } /* If objects on this space */
1402 1396
1403 if (flag & INS_ABOVE_FLOOR_ONLY) 1397 if (flag & INS_ABOVE_FLOOR_ONLY)
1404 top = floor; 1398 top = floor;
1405 1399
1406 /* Top is the object that our object (op) is going to get inserted above. 1400 // insert object above top, or bottom-most if top = 0
1407 */
1408
1409 /* First object on this space */
1410 if (!top) 1401 if (!top)
1411 { 1402 {
1403 op->below = 0;
1412 op->above = ms.bot; 1404 op->above = ms.bot;
1413
1414 if (op->above)
1415 op->above->below = op;
1416
1417 op->below = 0;
1418 ms.bot = op; 1405 ms.bot = op;
1406
1407 *(op->above ? &op->above->below : &ms.top) = op;
1419 } 1408 }
1420 else 1409 else
1421 { /* get inserted into the stack above top */ 1410 {
1422 op->above = top->above; 1411 op->above = top->above;
1423
1424 if (op->above)
1425 op->above->below = op; 1412 top->above = op;
1426 1413
1427 op->below = top; 1414 op->below = top;
1428 top->above = op; 1415 *(op->above ? &op->above->below : &ms.top) = op;
1429 } 1416 }
1430 1417 }
1431 if (!op->above)
1432 ms.top = op;
1433 } /* else not INS_BELOW_ORIGINATOR */
1434 1418
1435 if (op->type == PLAYER) 1419 if (op->type == PLAYER)
1436 { 1420 {
1437 op->contr->do_los = 1; 1421 op->contr->do_los = 1;
1438 ++op->map->players; 1422 ++op->map->players;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines