… | |
… | |
1140 | $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used}, |
1140 | $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used}, |
1141 | (cf::region::find $rmp->{region}), $rmp->{custom} |
1141 | (cf::region::find $rmp->{region}), $rmp->{custom} |
1142 | ) |
1142 | ) |
1143 | } |
1143 | } |
1144 | |
1144 | |
|
|
1145 | =item cf::map->register ($regex, $prio) |
|
|
1146 | |
|
|
1147 | Register a handler for the map path matching the given regex at the |
|
|
1148 | givne priority (higher is better, built-in handlers have priority 0, the |
|
|
1149 | default). |
|
|
1150 | |
|
|
1151 | =cut |
|
|
1152 | |
1145 | sub register { |
1153 | sub register { |
1146 | my (undef, $regex) = @_; |
1154 | my (undef, $regex, $prio) = @_; |
1147 | my $pkg = caller; |
1155 | my $pkg = caller; |
1148 | |
1156 | |
1149 | no strict; |
1157 | no strict; |
1150 | push @{"$pkg\::ISA"}, __PACKAGE__; |
1158 | push @{"$pkg\::ISA"}, __PACKAGE__; |
1151 | |
1159 | |
1152 | $EXT_MAP{$pkg} = qr<$regex>; |
1160 | $EXT_MAP{$pkg} = [$prio, qr<$regex>]; |
1153 | } |
1161 | } |
1154 | |
1162 | |
1155 | # also paths starting with '/' |
1163 | # also paths starting with '/' |
1156 | $EXT_MAP{"cf::map"} = qr{^(?=/)}; |
1164 | $EXT_MAP{"cf::map"} = [0, qr{^(?=/)}]; |
1157 | |
1165 | |
1158 | sub thawer_merge { |
1166 | sub thawer_merge { |
1159 | my ($self, $merge) = @_; |
1167 | my ($self, $merge) = @_; |
1160 | |
1168 | |
1161 | # we have to keep some variables in memory intact |
1169 | # we have to keep some variables in memory intact |
… | |
… | |
1204 | |
1212 | |
1205 | return $path if UNIVERSAL::isa $path, "cf::map"; # already a map object |
1213 | return $path if UNIVERSAL::isa $path, "cf::map"; # already a map object |
1206 | |
1214 | |
1207 | $path = normalise $path, $base; |
1215 | $path = normalise $path, $base; |
1208 | |
1216 | |
1209 | for my $pkg (keys %EXT_MAP) { |
1217 | for my $pkg (sort { $EXT_MAP{$b}[0] <=> $EXT_MAP{$a}[0] } keys %EXT_MAP) { |
1210 | if ($path =~ $EXT_MAP{$pkg}) { |
1218 | if ($path =~ $EXT_MAP{$pkg}[1]) { |
1211 | my $self = bless cf::map::new, $pkg; |
1219 | my $self = bless cf::map::new, $pkg; |
1212 | $self->{path} = $path; $self->path ($path); |
1220 | $self->{path} = $path; $self->path ($path); |
1213 | $self->init; # pass $1 etc. |
1221 | $self->init; # pass $1 etc. |
1214 | return $self; |
1222 | return $self; |
1215 | } |
1223 | } |
… | |
… | |
1289 | $self->{load_path} = $path; |
1297 | $self->{load_path} = $path; |
1290 | |
1298 | |
1291 | 1 |
1299 | 1 |
1292 | } |
1300 | } |
1293 | |
1301 | |
1294 | sub load_orig { |
1302 | sub load_header_orig { |
1295 | my ($self) = @_; |
1303 | my ($self) = @_; |
1296 | |
1304 | |
1297 | $self->load_header_from ($self->load_path) |
1305 | $self->load_header_from ($self->load_path) |
1298 | } |
1306 | } |
1299 | |
1307 | |
1300 | sub load_temp { |
1308 | sub load_header_temp { |
1301 | my ($self) = @_; |
1309 | my ($self) = @_; |
1302 | |
1310 | |
1303 | $self->load_header_from ($self->save_path) |
1311 | $self->load_header_from ($self->save_path) |
|
|
1312 | } |
|
|
1313 | |
|
|
1314 | sub prepare_temp { |
|
|
1315 | my ($self) = @_; |
|
|
1316 | |
|
|
1317 | $self->last_access ((delete $self->{last_access}) |
|
|
1318 | || $cf::RUNTIME); #d# |
|
|
1319 | # safety |
|
|
1320 | $self->{instantiate_time} = $cf::RUNTIME |
|
|
1321 | if $self->{instantiate_time} > $cf::RUNTIME; |
|
|
1322 | } |
|
|
1323 | |
|
|
1324 | sub prepare_orig { |
|
|
1325 | my ($self) = @_; |
|
|
1326 | |
|
|
1327 | $self->{load_original} = 1; |
|
|
1328 | $self->{instantiate_time} = $cf::RUNTIME; |
|
|
1329 | $self->last_access ($cf::RUNTIME); |
|
|
1330 | $self->instantiate; |
1304 | } |
1331 | } |
1305 | |
1332 | |
1306 | sub load_header { |
1333 | sub load_header { |
1307 | my ($self) = @_; |
1334 | my ($self) = @_; |
1308 | |
1335 | |
1309 | if ($self->load_temp) { |
1336 | if ($self->load_header_temp) { |
1310 | $self->last_access ((delete $self->{last_access}) |
1337 | $self->prepare_temp; |
1311 | || $cf::RUNTIME); #d# |
|
|
1312 | # safety |
|
|
1313 | $self->{instantiate_time} = $cf::RUNTIME |
|
|
1314 | if $self->{instantiate_time} > $cf::RUNTIME; |
|
|
1315 | } else { |
1338 | } else { |
1316 | $self->load_orig |
1339 | $self->load_header_orig |
1317 | or return; |
1340 | or return; |
1318 | |
1341 | $self->prepare_orig; |
1319 | $self->{load_original} = 1; |
|
|
1320 | $self->{instantiate_time} = $cf::RUNTIME; |
|
|
1321 | $self->last_access ($cf::RUNTIME); |
|
|
1322 | $self->instantiate; |
|
|
1323 | } |
1342 | } |
1324 | |
1343 | |
1325 | 1 |
1344 | 1 |
1326 | } |
1345 | } |
1327 | |
1346 | |
… | |
… | |
1354 | |
1373 | |
1355 | $cf::MAP{$path} = $map |
1374 | $cf::MAP{$path} = $map |
1356 | } |
1375 | } |
1357 | } |
1376 | } |
1358 | |
1377 | |
|
|
1378 | sub pre_load { } |
|
|
1379 | sub post_load { } |
|
|
1380 | |
1359 | sub load { |
1381 | sub load { |
1360 | my ($self) = @_; |
1382 | my ($self) = @_; |
1361 | |
1383 | |
1362 | my $path = $self->{path}; |
1384 | my $path = $self->{path}; |
1363 | my $guard = cf::lock_acquire "map_load:$path"; |
1385 | my $guard = cf::lock_acquire "map_load:$path"; |
… | |
… | |
1365 | return if $self->in_memory != cf::MAP_SWAPPED; |
1387 | return if $self->in_memory != cf::MAP_SWAPPED; |
1366 | |
1388 | |
1367 | $self->in_memory (cf::MAP_LOADING); |
1389 | $self->in_memory (cf::MAP_LOADING); |
1368 | |
1390 | |
1369 | $self->alloc; |
1391 | $self->alloc; |
|
|
1392 | |
|
|
1393 | $self->pre_load; |
|
|
1394 | |
1370 | $self->_load_objects ($self->{load_path}, 1) |
1395 | $self->_load_objects ($self->{load_path}, 1) |
1371 | or return; |
1396 | or return; |
1372 | |
1397 | |
1373 | $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) |
1398 | $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) |
1374 | if delete $self->{load_original}; |
1399 | if delete $self->{load_original}; |
… | |
… | |
1395 | $self->difficulty ($self->estimate_difficulty) |
1420 | $self->difficulty ($self->estimate_difficulty) |
1396 | unless $self->difficulty; |
1421 | unless $self->difficulty; |
1397 | Coro::cede; |
1422 | Coro::cede; |
1398 | $self->activate; |
1423 | $self->activate; |
1399 | } |
1424 | } |
|
|
1425 | |
|
|
1426 | $self->post_load; |
1400 | |
1427 | |
1401 | $self->in_memory (cf::MAP_IN_MEMORY); |
1428 | $self->in_memory (cf::MAP_IN_MEMORY); |
1402 | } |
1429 | } |
1403 | |
1430 | |
1404 | sub customise_for { |
1431 | sub customise_for { |