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.92 by root, Sun Feb 18 17:24:16 2007 UTC vs.
Revision 1.100 by root, Tue Apr 17 10:06:32 2007 UTC

344} 344}
345 345
346/* link_multipart_objects go through all the objects on the map looking 346/* link_multipart_objects go through all the objects on the map looking
347 * for objects whose arch says they are multipart yet according to the 347 * for objects whose arch says they are multipart yet according to the
348 * info we have, they only have the head (as would be expected when 348 * info we have, they only have the head (as would be expected when
349 * they are saved). We do have to look for the old maps that did save 349 * they are saved).
350 * the more sections and not re-add sections for them.
351 */ 350 */
352void 351void
353maptile::link_multipart_objects () 352maptile::link_multipart_objects ()
354{ 353{
355 if (!spaces) 354 if (!spaces)
399bool 398bool
400maptile::_load_objects (object_thawer &f) 399maptile::_load_objects (object_thawer &f)
401{ 400{
402 for (;;) 401 for (;;)
403 { 402 {
404 coroapi::cede_every (1000); // cede once in a while 403 coroapi::cede_to_tick_every (100); // cede once in a while
405 404
406 switch (f.kw) 405 switch (f.kw)
407 { 406 {
408 case KW_arch: 407 case KW_arch:
409 if (object *op = object::read (f, this)) 408 if (object *op = object::read (f, this))
454} 453}
455 454
456bool 455bool
457maptile::_save_objects (object_freezer &f, int flags) 456maptile::_save_objects (object_freezer &f, int flags)
458{ 457{
459 static int cede_count = 0; 458 coroapi::cede_to_tick ();
460 459
461 if (flags & IO_HEADER) 460 if (flags & IO_HEADER)
462 _save_header (f); 461 _save_header (f);
463 462
464 if (!spaces) 463 if (!spaces)
465 return false; 464 return false;
466 465
467 for (int i = 0; i < size (); ++i) 466 for (int i = 0; i < size (); ++i)
468 { 467 {
469#if 0 // temporarily disabled for improved(?) stability, schmorp #TODO#d#//D
470 if (cede_count >= 500)
471 {
472 cede_count = 0;
473 coroapi::cede ();
474 }
475#endif
476
477 int unique = 0; 468 int unique = 0;
478 for (object *op = spaces [i].bot; op; op = op->above) 469 for (object *op = spaces [i].bot; op; op = op->above)
479 { 470 {
480 // count per-object, but cede only when modification-safe
481 cede_count++;
482
483 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) 471 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
484 unique = 1; 472 unique = 1;
485 473
486 if (!op->can_map_save ()) 474 if (!op->can_map_save ())
487 continue; 475 continue;
493 } 481 }
494 else if (flags & IO_OBJECTS) 482 else if (flags & IO_OBJECTS)
495 op->write (f); 483 op->write (f);
496 } 484 }
497 } 485 }
486
487 coroapi::cede_to_tick ();
498 488
499 return true; 489 return true;
500} 490}
501 491
502bool 492bool
1075void 1065void
1076mapspace::update_ () 1066mapspace::update_ ()
1077{ 1067{
1078 object *tmp, *last = 0; 1068 object *tmp, *last = 0;
1079 uint8 flags = P_UPTODATE, light = 0, anywhere = 0; 1069 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; 1070 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1083 1071
1084 middle = blank_face; 1072 //object *middle = 0;
1085 top = blank_face; 1073 //object *top = 0;
1086 floor = blank_face; 1074 //object *floor = 0;
1087 1075 // this seems to generate better code than using locals, above
1088 middle_obj = 0; 1076 object *&top = faces_obj[0] = 0;
1089 top_obj = 0; 1077 object *&middle = faces_obj[1] = 0;
1090 floor_obj = 0; 1078 object *&floor = faces_obj[2] = 0;
1091 1079
1092 for (tmp = bot; tmp; last = tmp, tmp = tmp->above) 1080 for (tmp = bot; tmp; last = tmp, tmp = tmp->above)
1093 { 1081 {
1094 /* This could be made additive I guess (two lights better than 1082 /* This could be made additive I guess (two lights better than
1095 * one). But if so, it shouldn't be a simple additive - 2 1083 * one). But if so, it shouldn't be a simple additive - 2
1108 * Always put the player down for drawing. 1096 * Always put the player down for drawing.
1109 */ 1097 */
1110 if (!tmp->invisible) 1098 if (!tmp->invisible)
1111 { 1099 {
1112 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) 1100 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER)))
1113 {
1114 top = tmp->face;
1115 top_obj = tmp; 1101 top = tmp;
1116 }
1117 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1102 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1118 { 1103 {
1119 /* If we got a floor, that means middle and top were below it, 1104 /* If we got a floor, that means middle and top were below it,
1120 * so should not be visible, so we clear them. 1105 * so should not be visible, so we clear them.
1121 */ 1106 */
1122 middle = blank_face; 1107 middle = 0;
1123 top = blank_face; 1108 top = 0;
1124 floor = tmp->face;
1125 floor_obj = tmp; 1109 floor = tmp;
1126 } 1110 }
1127 /* Flag anywhere have high priority */ 1111 /* Flag anywhere have high priority */
1128 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) 1112 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE))
1129 { 1113 {
1130 middle = tmp->face;
1131
1132 middle_obj = tmp; 1114 middle = tmp;
1133 anywhere = 1; 1115 anywhere = 1;
1134 } 1116 }
1135 /* Find the highest visible face around. If equal 1117 /* Find the highest visible face around. If equal
1136 * visibilities, we still want the one nearer to the 1118 * visibilities, we still want the one nearer to the
1137 * top 1119 * top
1138 */ 1120 */
1139 else if (middle == blank_face || (tmp->face->visibility > middle->visibility && !anywhere)) 1121 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere))
1140 {
1141 middle = tmp->face;
1142 middle_obj = tmp; 1122 middle = tmp;
1143 }
1144 } 1123 }
1145 1124
1146 if (tmp == tmp->above) 1125 if (tmp == tmp->above)
1147 { 1126 {
1148 LOG (llevError, "Error in structure of map\n"); 1127 LOG (llevError, "Error in structure of map\n");
1183 * middle face. This should not happen, as we already have the 1162 * middle face. This should not happen, as we already have the
1184 * else statement above so middle should not get set. OTOH, it 1163 * else statement above so middle should not get set. OTOH, it
1185 * may be possible for the faces to match but be different objects. 1164 * may be possible for the faces to match but be different objects.
1186 */ 1165 */
1187 if (top == middle) 1166 if (top == middle)
1188 middle = blank_face; 1167 middle = 0;
1189 1168
1190 /* There are three posibilities at this point: 1169 /* There are three posibilities at this point:
1191 * 1) top face is set, need middle to be set. 1170 * 1) top face is set, need middle to be set.
1192 * 2) middle is set, need to set top. 1171 * 2) middle is set, need to set top.
1193 * 3) neither middle or top is set - need to set both. 1172 * 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 */ 1177 /* Once we get to a floor, stop, since we already have a floor object */
1199 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1178 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1200 break; 1179 break;
1201 1180
1202 /* If two top faces are already set, quit processing */ 1181 /* If two top faces are already set, quit processing */
1203 if ((top != blank_face) && (middle != blank_face)) 1182 if (top && middle)
1204 break; 1183 break;
1205 1184
1206 /* Only show visible faces */ 1185 /* Only show visible faces */
1207 if (!tmp->invisible) 1186 if (!tmp->invisible)
1208 { 1187 {
1209 /* Fill in top if needed */ 1188 /* Fill in top if needed */
1210 if (top == blank_face) 1189 if (!top)
1211 { 1190 {
1212 top = tmp->face;
1213 top_obj = tmp; 1191 top = tmp;
1214 if (top == middle) 1192 if (top == middle)
1215 middle = blank_face; 1193 middle = 0;
1216 } 1194 }
1217 else 1195 else
1218 { 1196 {
1219 /* top is already set - we should only get here if 1197 /* top is already set - we should only get here if
1220 * middle is not set 1198 * middle is not set
1221 * 1199 *
1222 * Set the middle face and break out, since there is nothing 1200 * Set the middle face and break out, since there is nothing
1223 * more to fill in. We don't check visiblity here, since 1201 * more to fill in. We don't check visiblity here, since
1224 * 1202 *
1225 */ 1203 */
1226 if (tmp->face != top) 1204 if (tmp != top)
1227 { 1205 {
1228 middle = tmp->face;
1229 middle_obj = tmp; 1206 middle = tmp;
1230 break; 1207 break;
1231 } 1208 }
1232 } 1209 }
1233 } 1210 }
1234 } 1211 }
1235 1212
1236 if (middle == floor) 1213 if (middle == floor)
1237 middle = blank_face; 1214 middle = 0;
1238 1215
1239 if (top == middle) 1216 if (top == middle)
1240 middle = blank_face; 1217 middle = 0;
1241 1218
1242 faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; 1219#if 0
1243 faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; 1220 faces_obj [0] = top;
1244 faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; 1221 faces_obj [1] = middle;
1222 faces_obj [2] = floor;
1223#endif
1245} 1224}
1246 1225
1247uint64 1226uint64
1248mapspace::volume () const 1227mapspace::volume () const
1249{ 1228{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines