… | |
… | |
72 | |
72 | |
73 | @safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; |
73 | @safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; |
74 | |
74 | |
75 | # we bless all objects into (empty) derived classes to force a method lookup |
75 | # we bless all objects into (empty) derived classes to force a method lookup |
76 | # within the Safe compartment. |
76 | # within the Safe compartment. |
77 | for my $pkg (qw(cf::object cf::object::player cf::player cf::map cf::party cf::region cf::arch)) { |
77 | for my $pkg (qw(cf::object cf::object::player cf::player cf::map cf::party cf::region cf::arch cf::living)) { |
78 | no strict 'refs'; |
78 | no strict 'refs'; |
79 | @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
79 | @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
80 | } |
80 | } |
81 | |
81 | |
82 | $Event::DIED = sub { |
82 | $Event::DIED = sub { |
… | |
… | |
262 | $obj->{$name} = \%arg; |
262 | $obj->{$name} = \%arg; |
263 | } else { |
263 | } else { |
264 | warn "object uses attachment '$name' that is not available, postponing.\n"; |
264 | warn "object uses attachment '$name' that is not available, postponing.\n"; |
265 | } |
265 | } |
266 | |
266 | |
267 | push @{$obj->{_attachment}}, $name; |
267 | $obj->{_attachment}{$name} = undef; |
268 | |
268 | |
269 | $res->{attachment} = $name; |
269 | $res->{attachment} = $name; |
270 | $res |
270 | $res |
271 | } |
271 | } |
272 | |
272 | |
… | |
… | |
368 | my ($obj) = @_; |
368 | my ($obj) = @_; |
369 | my $registry = $obj->registry; |
369 | my $registry = $obj->registry; |
370 | |
370 | |
371 | @$registry = (); |
371 | @$registry = (); |
372 | |
372 | |
373 | delete $obj->{_attachment} unless @{ $obj->{_attachment} || [] }; |
373 | delete $obj->{_attachment} unless scalar keys %{ $obj->{_attachment} || {} }; |
374 | |
374 | |
375 | for my $name (@{ $obj->{_attachment} || [] }) { |
375 | for my $name (keys %{ $obj->{_attachment} || {} }) { |
376 | if (my $attach = $attachment{$name}) { |
376 | if (my $attach = $attachment{$name}) { |
377 | for (@$attach) { |
377 | for (@$attach) { |
378 | my ($klass, @attach) = @$_; |
378 | my ($klass, @attach) = @$_; |
379 | _attach @$registry, $klass, @attach; |
379 | _attach @$registry, $klass, @attach; |
380 | } |
380 | } |
… | |
… | |
385 | } |
385 | } |
386 | |
386 | |
387 | sub object_freezer_save { |
387 | sub object_freezer_save { |
388 | my ($filename, $objs) = @_; |
388 | my ($filename, $objs) = @_; |
389 | |
389 | |
390 | $filename .= ".pst"; |
|
|
391 | |
|
|
392 | if (@$objs) { |
390 | if (@$objs) { |
393 | open my $fh, ">:raw", "$filename~"; |
391 | open my $fh, ">:raw", "$filename.pst~"; |
394 | chmod $fh, SAVE_MODE; |
|
|
395 | syswrite $fh, Storable::nfreeze { version => 1, objs => $objs }; |
392 | syswrite $fh, Storable::nfreeze { version => 1, objs => $objs }; |
396 | close $fh; |
393 | close $fh; |
|
|
394 | chmod SAVE_MODE, "$filename.pst~"; |
397 | rename "$filename~", $filename; |
395 | rename "$filename.pst~", "$filename.pst"; |
398 | } else { |
396 | } else { |
399 | unlink $filename; |
397 | unlink "$filename.pst"; |
400 | } |
398 | } |
|
|
399 | |
|
|
400 | chmod SAVE_MODE, "$filename~"; |
|
|
401 | rename "$filename~", $filename; |
401 | } |
402 | } |
402 | |
403 | |
403 | sub object_thawer_load { |
404 | sub object_thawer_load { |
404 | my ($filename) = @_; |
405 | my ($filename) = @_; |
405 | |
406 | |
… | |
… | |
416 | |
417 | |
417 | @{$dst->registry} = @{$src->registry}; |
418 | @{$dst->registry} = @{$src->registry}; |
418 | |
419 | |
419 | %$dst = %$src; |
420 | %$dst = %$src; |
420 | |
421 | |
421 | $dst->{_attachment} = [@{ $src->{_attachment} }] |
422 | %{$dst->{_attachment}} = %{$src->{_attachment}} |
422 | if exists $src->{_attachment}; |
423 | if exists $src->{_attachment}; |
423 | }, |
424 | }, |
424 | ; |
425 | ; |
425 | |
426 | |
426 | ############################################################################# |
427 | ############################################################################# |
… | |
… | |
667 | my ($map) = @_; |
668 | my ($map) = @_; |
668 | |
669 | |
669 | my $path = $map->tmpname; |
670 | my $path = $map->tmpname; |
670 | defined $path or return; |
671 | defined $path or return; |
671 | |
672 | |
672 | unlink "$path.cfperl"; |
|
|
673 | unlink "$path.pst"; |
673 | unlink "$path.pst"; |
674 | }; |
674 | }; |
675 | |
675 | |
|
|
676 | # old style persistent data, TODO: remove #d# |
676 | *cf::mapsupport::on_swapin = |
677 | *cf::mapsupport::on_swapin = |
677 | *cf::mapsupport::on_load = sub { |
678 | *cf::mapsupport::on_load = sub { |
678 | my ($map) = @_; |
679 | my ($map) = @_; |
679 | |
680 | |
680 | my $path = $map->tmpname; |
681 | my $path = $map->tmpname; |
… | |
… | |
687 | |
688 | |
688 | $data->{version} <= 1 |
689 | $data->{version} <= 1 |
689 | or return; # too new |
690 | or return; # too new |
690 | |
691 | |
691 | $map->_set_obs ($data->{obs}); |
692 | $map->_set_obs ($data->{obs}); |
|
|
693 | $map->invoke (EVENT_MAP_UPGRADE); |
692 | }; |
694 | }; |
693 | |
695 | |
694 | attach_to_maps prio => -10000, package => cf::mapsupport::; |
696 | attach_to_maps prio => -10000, package => cf::mapsupport::; |
695 | |
697 | |
696 | ############################################################################# |
698 | ############################################################################# |