scrub no-longer designated tiles
| 173 | |
| 174 | // scrub no-longer designated tiles |
| 175 | static void do_cycle(color_ostream &out) { |
| 176 | cycle_timestamp = world->frame_counter; |
| 177 | |
| 178 | std::unordered_map<df::coord, df::job *> dig_jobs; |
| 179 | fill_dig_jobs(dig_jobs); |
| 180 | |
| 181 | bool has_assignment = false; |
| 182 | uint32_t scrubbed = 0; |
| 183 | for (auto & block : world->map.map_blocks) { |
| 184 | auto warm_mask = World::getPersistentTilemask(warm_config, block); |
| 185 | auto damp_mask = World::getPersistentTilemask(damp_config, block); |
| 186 | if (!warm_mask && !damp_mask) |
| 187 | continue; |
| 188 | |
| 189 | bool used = false; |
| 190 | const auto & block_pos = block->map_pos; |
| 191 | for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++) { |
| 192 | if ((!warm_mask || !warm_mask->getassignment(x, y)) && |
| 193 | (!damp_mask || !damp_mask->getassignment(x, y))) |
| 194 | { |
| 195 | continue; |
| 196 | } |
| 197 | |
| 198 | if (!block->designation[x][y].bits.dig && |
| 199 | !dig_jobs.contains(block_pos + df::coord(x, y, 0))) |
| 200 | { |
| 201 | if (warm_mask) warm_mask->setassignment(x, y, false); |
| 202 | if (damp_mask) damp_mask->setassignment(x, y, false); |
| 203 | ++scrubbed; |
| 204 | } else { |
| 205 | has_assignment = true; |
| 206 | used = true; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if (!used) { |
| 211 | // delete the tile masks so we can skip over this block in the future |
| 212 | World::deletePersistentTilemask(warm_config, block); |
| 213 | World::deletePersistentTilemask(damp_config, block); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | DEBUG(log,out).print("scrubbed {} tagged tiles\n", scrubbed); |
| 218 | |
| 219 | if (!has_assignment){ |
| 220 | DEBUG(log,out).print("no more active tagged tiles; disabling\n"); |
| 221 | do_enable(false); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | DFhackCExport command_result plugin_onupdate(color_ostream &out) { |
| 226 | if (world->frame_counter - cycle_timestamp >= CYCLE_TICKS) |
no test coverage detected