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.89 by root, Fri Feb 16 22:16:16 2007 UTC vs.
Revision 1.98 by root, Sat Mar 17 22:11:22 2007 UTC

404 coroapi::cede_every (1000); // cede once in a while 404 coroapi::cede_every (1000); // cede once in a while
405 405
406 switch (f.kw) 406 switch (f.kw)
407 { 407 {
408 case KW_arch: 408 case KW_arch:
409 if (object *op = object::read (f)) 409 if (object *op = object::read (f, this))
410 { 410 {
411 if (op->inv) 411 if (op->inv)
412 sum_weight (op); 412 sum_weight (op);
413 413
414 insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 414 insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD);
454} 454}
455 455
456bool 456bool
457maptile::_save_objects (object_freezer &f, int flags) 457maptile::_save_objects (object_freezer &f, int flags)
458{ 458{
459 static int cede_count = 0; 459 coroapi::cede ();
460 460
461 if (flags & IO_HEADER) 461 if (flags & IO_HEADER)
462 _save_header (f); 462 _save_header (f);
463 463
464 if (!spaces) 464 if (!spaces)
465 return false; 465 return false;
466 466
467 for (int i = 0; i < size (); ++i) 467 for (int i = 0; i < size (); ++i)
468 { 468 {
469#if 0 // temporarily disabled for improved(?) stability, schmorp #TODO#d#//D 469#if 0 // disabled, there still seem to be races somewhere
470 static int cede_count = 0;
471
470 if (cede_count >= 500) 472 if (cede_count >= 500)
471 { 473 {
472 cede_count = 0; 474 cede_count = 0;
473 coroapi::cede (); 475 coroapi::cede ();
474 } 476 }
475#endif 477#endif
476 478
477 int unique = 0; 479 int unique = 0;
478 for (object *op = spaces [i].bot; op; op = op->above) 480 for (object *op = spaces [i].bot; op; op = op->above)
479 { 481 {
482#if 0
480 // count per-object, but cede only when modification-safe 483 // count per-object, but cede only when modification-safe
481 cede_count++; 484 cede_count++;
485#endif
482 486
483 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) 487 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
484 unique = 1; 488 unique = 1;
485 489
486 if (!op->can_map_save ()) 490 if (!op->can_map_save ())
493 } 497 }
494 else if (flags & IO_OBJECTS) 498 else if (flags & IO_OBJECTS)
495 op->write (f); 499 op->write (f);
496 } 500 }
497 } 501 }
502
503 coroapi::cede ();
498 504
499 return true; 505 return true;
500} 506}
501 507
502bool 508bool
1075void 1081void
1076mapspace::update_ () 1082mapspace::update_ ()
1077{ 1083{
1078 object *tmp, *last = 0; 1084 object *tmp, *last = 0;
1079 uint8 flags = P_UPTODATE, light = 0, anywhere = 0; 1085 uint8 flags = P_UPTODATE, light = 0, anywhere = 0;
1080 facetile *top, *floor, *middle;
1081 object *top_obj, *floor_obj, *middle_obj;
1082 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; 1086 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1083 1087
1084 middle = blank_face; 1088 //object *middle = 0;
1085 top = blank_face; 1089 //object *top = 0;
1086 floor = blank_face; 1090 //object *floor = 0;
1087 1091 // this seems to generate better code than using locals, above
1088 middle_obj = 0; 1092 object *&top = faces_obj[0] = 0;
1089 top_obj = 0; 1093 object *&middle = faces_obj[1] = 0;
1090 floor_obj = 0; 1094 object *&floor = faces_obj[2] = 0;
1091 1095
1092 for (tmp = bot; tmp; last = tmp, tmp = tmp->above) 1096 for (tmp = bot; tmp; last = tmp, tmp = tmp->above)
1093 { 1097 {
1094 /* This could be made additive I guess (two lights better than 1098 /* This could be made additive I guess (two lights better than
1095 * one). But if so, it shouldn't be a simple additive - 2 1099 * one). But if so, it shouldn't be a simple additive - 2
1108 * Always put the player down for drawing. 1112 * Always put the player down for drawing.
1109 */ 1113 */
1110 if (!tmp->invisible) 1114 if (!tmp->invisible)
1111 { 1115 {
1112 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) 1116 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER)))
1113 {
1114 top = tmp->face;
1115 top_obj = tmp; 1117 top = tmp;
1116 }
1117 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1118 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1118 { 1119 {
1119 /* If we got a floor, that means middle and top were below it, 1120 /* If we got a floor, that means middle and top were below it,
1120 * so should not be visible, so we clear them. 1121 * so should not be visible, so we clear them.
1121 */ 1122 */
1122 middle = blank_face; 1123 middle = 0;
1123 top = blank_face; 1124 top = 0;
1124 floor = tmp->face;
1125 floor_obj = tmp; 1125 floor = tmp;
1126 } 1126 }
1127 /* Flag anywhere have high priority */ 1127 /* Flag anywhere have high priority */
1128 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) 1128 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE))
1129 { 1129 {
1130 middle = tmp->face;
1131
1132 middle_obj = tmp; 1130 middle = tmp;
1133 anywhere = 1; 1131 anywhere = 1;
1134 } 1132 }
1135 /* Find the highest visible face around. If equal 1133 /* Find the highest visible face around. If equal
1136 * visibilities, we still want the one nearer to the 1134 * visibilities, we still want the one nearer to the
1137 * top 1135 * top
1138 */ 1136 */
1139 else if (middle == blank_face || (tmp->face->visibility > middle->visibility && !anywhere)) 1137 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere))
1140 {
1141 middle = tmp->face;
1142 middle_obj = tmp; 1138 middle = tmp;
1143 }
1144 } 1139 }
1145 1140
1146 if (tmp == tmp->above) 1141 if (tmp == tmp->above)
1147 { 1142 {
1148 LOG (llevError, "Error in structure of map\n"); 1143 LOG (llevError, "Error in structure of map\n");
1183 * middle face. This should not happen, as we already have the 1178 * middle face. This should not happen, as we already have the
1184 * else statement above so middle should not get set. OTOH, it 1179 * else statement above so middle should not get set. OTOH, it
1185 * may be possible for the faces to match but be different objects. 1180 * may be possible for the faces to match but be different objects.
1186 */ 1181 */
1187 if (top == middle) 1182 if (top == middle)
1188 middle = blank_face; 1183 middle = 0;
1189 1184
1190 /* There are three posibilities at this point: 1185 /* There are three posibilities at this point:
1191 * 1) top face is set, need middle to be set. 1186 * 1) top face is set, need middle to be set.
1192 * 2) middle is set, need to set top. 1187 * 2) middle is set, need to set top.
1193 * 3) neither middle or top is set - need to set both. 1188 * 3) neither middle or top is set - need to set both.
1198 /* Once we get to a floor, stop, since we already have a floor object */ 1193 /* Once we get to a floor, stop, since we already have a floor object */
1199 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1194 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1200 break; 1195 break;
1201 1196
1202 /* If two top faces are already set, quit processing */ 1197 /* If two top faces are already set, quit processing */
1203 if ((top != blank_face) && (middle != blank_face)) 1198 if (top && middle)
1204 break; 1199 break;
1205 1200
1206 /* Only show visible faces */ 1201 /* Only show visible faces */
1207 if (!tmp->invisible) 1202 if (!tmp->invisible)
1208 { 1203 {
1209 /* Fill in top if needed */ 1204 /* Fill in top if needed */
1210 if (top == blank_face) 1205 if (!top)
1211 { 1206 {
1212 top = tmp->face;
1213 top_obj = tmp; 1207 top = tmp;
1214 if (top == middle) 1208 if (top == middle)
1215 middle = blank_face; 1209 middle = 0;
1216 } 1210 }
1217 else 1211 else
1218 { 1212 {
1219 /* top is already set - we should only get here if 1213 /* top is already set - we should only get here if
1220 * middle is not set 1214 * middle is not set
1221 * 1215 *
1222 * Set the middle face and break out, since there is nothing 1216 * Set the middle face and break out, since there is nothing
1223 * more to fill in. We don't check visiblity here, since 1217 * more to fill in. We don't check visiblity here, since
1224 * 1218 *
1225 */ 1219 */
1226 if (tmp->face != top) 1220 if (tmp != top)
1227 { 1221 {
1228 middle = tmp->face;
1229 middle_obj = tmp; 1222 middle = tmp;
1230 break; 1223 break;
1231 } 1224 }
1232 } 1225 }
1233 } 1226 }
1234 } 1227 }
1235 1228
1236 if (middle == floor) 1229 if (middle == floor)
1237 middle = blank_face; 1230 middle = 0;
1238 1231
1239 if (top == middle) 1232 if (top == middle)
1240 middle = blank_face; 1233 middle = 0;
1241 1234
1242 faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; 1235#if 0
1243 faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; 1236 faces_obj [0] = top;
1244 faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; 1237 faces_obj [1] = middle;
1238 faces_obj [2] = floor;
1239#endif
1245} 1240}
1246 1241
1247uint64 1242uint64
1248mapspace::volume () const 1243mapspace::volume () const
1249{ 1244{
1669 return default_region; 1664 return default_region;
1670 1665
1671 return ::region::default_region (); 1666 return ::region::default_region ();
1672} 1667}
1673 1668
1669/* picks a random object from a style map.
1670 * Redone by MSW so it should be faster and not use static
1671 * variables to generate tables.
1672 */
1673object *
1674maptile::pick_random_object () const
1675{
1676 /* while returning a null object will result in a crash, that
1677 * is actually preferable to an infinite loop. That is because
1678 * most servers will automatically restart in case of crash.
1679 * Change the logic on getting the random space - shouldn't make
1680 * any difference, but this seems clearer to me.
1681 */
1682 for (int i = 1000; --i;)
1683 {
1684 object *pick = at (rndm (width), rndm (height)).bot;
1674 1685
1686 // do not prefer big monsters just because they are big.
1687 if (pick && pick->head_ () == pick)
1688 return pick->head_ ();
1689 }
1690
1691 // instead of crashing in the unlikely(?) case, try to return *something*
1692 return get_archetype ("blocked");
1693}
1694

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines