… | |
… | |
454 | } |
454 | } |
455 | |
455 | |
456 | bool |
456 | bool |
457 | maptile::_save_objects (object_freezer &f, int flags) |
457 | maptile::_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 | } |
… | |
… | |
493 | } |
495 | } |
494 | else if (flags & IO_OBJECTS) |
496 | else if (flags & IO_OBJECTS) |
495 | op->write (f); |
497 | op->write (f); |
496 | } |
498 | } |
497 | } |
499 | } |
|
|
500 | |
|
|
501 | coroapi::cede (); |
498 | |
502 | |
499 | return true; |
503 | return true; |
500 | } |
504 | } |
501 | |
505 | |
502 | bool |
506 | bool |
… | |
… | |
1075 | void |
1079 | void |
1076 | mapspace::update_ () |
1080 | mapspace::update_ () |
1077 | { |
1081 | { |
1078 | object *tmp, *last = 0; |
1082 | object *tmp, *last = 0; |
1079 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1083 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1080 | faceidx 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; |
1084 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1083 | |
1085 | |
1084 | middle = blank_face; |
1086 | //object *middle = 0; |
1085 | top = blank_face; |
1087 | //object *top = 0; |
1086 | floor = blank_face; |
1088 | //object *floor = 0; |
1087 | |
1089 | // this seems to generate better code than using locals, above |
1088 | middle_obj = 0; |
1090 | object *&top = faces_obj[0] = 0; |
1089 | top_obj = 0; |
1091 | object *&middle = faces_obj[1] = 0; |
1090 | floor_obj = 0; |
1092 | object *&floor = faces_obj[2] = 0; |
1091 | |
1093 | |
1092 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1094 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1093 | { |
1095 | { |
1094 | /* This could be made additive I guess (two lights better than |
1096 | /* This could be made additive I guess (two lights better than |
1095 | * one). But if so, it shouldn't be a simple additive - 2 |
1097 | * one). But if so, it shouldn't be a simple additive - 2 |
… | |
… | |
1108 | * Always put the player down for drawing. |
1110 | * Always put the player down for drawing. |
1109 | */ |
1111 | */ |
1110 | if (!tmp->invisible) |
1112 | if (!tmp->invisible) |
1111 | { |
1113 | { |
1112 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1114 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1113 | { |
|
|
1114 | top = tmp->face; |
|
|
1115 | top_obj = tmp; |
1115 | top = tmp; |
1116 | } |
|
|
1117 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1116 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1118 | { |
1117 | { |
1119 | /* If we got a floor, that means middle and top were below it, |
1118 | /* If we got a floor, that means middle and top were below it, |
1120 | * so should not be visible, so we clear them. |
1119 | * so should not be visible, so we clear them. |
1121 | */ |
1120 | */ |
1122 | middle = blank_face; |
1121 | middle = 0; |
1123 | top = blank_face; |
1122 | top = 0; |
1124 | floor = tmp->face; |
|
|
1125 | floor_obj = tmp; |
1123 | floor = tmp; |
1126 | } |
1124 | } |
1127 | /* Flag anywhere have high priority */ |
1125 | /* Flag anywhere have high priority */ |
1128 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
1126 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
1129 | { |
1127 | { |
1130 | middle = tmp->face; |
|
|
1131 | |
|
|
1132 | middle_obj = tmp; |
1128 | middle = tmp; |
1133 | anywhere = 1; |
1129 | anywhere = 1; |
1134 | } |
1130 | } |
1135 | /* Find the highest visible face around. If equal |
1131 | /* Find the highest visible face around. If equal |
1136 | * visibilities, we still want the one nearer to the |
1132 | * visibilities, we still want the one nearer to the |
1137 | * top |
1133 | * top |
1138 | */ |
1134 | */ |
1139 | else if (middle == blank_face || (::faces [tmp->face].visibility > ::faces [middle].visibility && !anywhere)) |
1135 | else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) |
1140 | { |
|
|
1141 | middle = tmp->face; |
|
|
1142 | middle_obj = tmp; |
1136 | middle = tmp; |
1143 | } |
|
|
1144 | } |
1137 | } |
1145 | |
1138 | |
1146 | if (tmp == tmp->above) |
1139 | if (tmp == tmp->above) |
1147 | { |
1140 | { |
1148 | LOG (llevError, "Error in structure of map\n"); |
1141 | LOG (llevError, "Error in structure of map\n"); |
… | |
… | |
1183 | * middle face. This should not happen, as we already have the |
1176 | * middle face. This should not happen, as we already have the |
1184 | * else statement above so middle should not get set. OTOH, it |
1177 | * else statement above so middle should not get set. OTOH, it |
1185 | * may be possible for the faces to match but be different objects. |
1178 | * may be possible for the faces to match but be different objects. |
1186 | */ |
1179 | */ |
1187 | if (top == middle) |
1180 | if (top == middle) |
1188 | middle = blank_face; |
1181 | middle = 0; |
1189 | |
1182 | |
1190 | /* There are three posibilities at this point: |
1183 | /* There are three posibilities at this point: |
1191 | * 1) top face is set, need middle to be set. |
1184 | * 1) top face is set, need middle to be set. |
1192 | * 2) middle is set, need to set top. |
1185 | * 2) middle is set, need to set top. |
1193 | * 3) neither middle or top is set - need to set both. |
1186 | * 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 */ |
1191 | /* Once we get to a floor, stop, since we already have a floor object */ |
1199 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1192 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1200 | break; |
1193 | break; |
1201 | |
1194 | |
1202 | /* If two top faces are already set, quit processing */ |
1195 | /* If two top faces are already set, quit processing */ |
1203 | if ((top != blank_face) && (middle != blank_face)) |
1196 | if (top && middle) |
1204 | break; |
1197 | break; |
1205 | |
1198 | |
1206 | /* Only show visible faces */ |
1199 | /* Only show visible faces */ |
1207 | if (!tmp->invisible) |
1200 | if (!tmp->invisible) |
1208 | { |
1201 | { |
1209 | /* Fill in top if needed */ |
1202 | /* Fill in top if needed */ |
1210 | if (top == blank_face) |
1203 | if (!top) |
1211 | { |
1204 | { |
1212 | top = tmp->face; |
|
|
1213 | top_obj = tmp; |
1205 | top = tmp; |
1214 | if (top == middle) |
1206 | if (top == middle) |
1215 | middle = blank_face; |
1207 | middle = 0; |
1216 | } |
1208 | } |
1217 | else |
1209 | else |
1218 | { |
1210 | { |
1219 | /* top is already set - we should only get here if |
1211 | /* top is already set - we should only get here if |
1220 | * middle is not set |
1212 | * middle is not set |
1221 | * |
1213 | * |
1222 | * Set the middle face and break out, since there is nothing |
1214 | * Set the middle face and break out, since there is nothing |
1223 | * more to fill in. We don't check visiblity here, since |
1215 | * more to fill in. We don't check visiblity here, since |
1224 | * |
1216 | * |
1225 | */ |
1217 | */ |
1226 | if (tmp->face != top) |
1218 | if (tmp != top) |
1227 | { |
1219 | { |
1228 | middle = tmp->face; |
|
|
1229 | middle_obj = tmp; |
1220 | middle = tmp; |
1230 | break; |
1221 | break; |
1231 | } |
1222 | } |
1232 | } |
1223 | } |
1233 | } |
1224 | } |
1234 | } |
1225 | } |
1235 | |
1226 | |
1236 | if (middle == floor) |
1227 | if (middle == floor) |
1237 | middle = blank_face; |
1228 | middle = 0; |
1238 | |
1229 | |
1239 | if (top == middle) |
1230 | if (top == middle) |
1240 | middle = blank_face; |
1231 | middle = 0; |
1241 | |
1232 | |
1242 | faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; |
1233 | #if 0 |
1243 | faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; |
1234 | faces_obj [0] = top; |
1244 | faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; |
1235 | faces_obj [1] = middle; |
|
|
1236 | faces_obj [2] = floor; |
|
|
1237 | #endif |
1245 | } |
1238 | } |
1246 | |
1239 | |
1247 | uint64 |
1240 | uint64 |
1248 | mapspace::volume () const |
1241 | mapspace::volume () const |
1249 | { |
1242 | { |