ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.50 by root, Mon Aug 28 07:07:42 2006 UTC vs.
Revision 1.52 by root, Mon Aug 28 16:52:51 2006 UTC

174 174
175Attach handlers to all maps. 175Attach handlers to all maps.
176 176
177=item cf:register_attachment $name, ... 177=item cf:register_attachment $name, ...
178 178
179Register an attachment by name through which objects can refer to this
180attachment.
181
182=item cf:register_map_attachment $name, ...
183
184Register an attachment by name through which maps can refer to this
185attachment.
186
179=cut 187=cut
180 188
181# the following variables are defined in .xs and must not be re-created 189# the following variables are defined in .xs and must not be re-created
182our @CB_GLOBAL = (); # registry for all global events 190our @CB_GLOBAL = (); # registry for all global events
183our @CB_OBJECT = (); # all objects (should not be used except in emergency) 191our @CB_OBJECT = (); # all objects (should not be used except in emergency)
277} 285}
278 286
279sub cf::player::attach { 287sub cf::player::attach {
280 my ($obj, $name, %arg) = @_; 288 my ($obj, $name, %arg) = @_;
281 289
282 _attach_attachment KLASS_PLAYER, $obj, $name, %arg; 290 _attach_attachment $obj, $name, %arg;
283} 291}
284 292
285sub cf::map::attach { 293sub cf::map::attach {
286 my ($obj, $name, %arg) = @_; 294 my ($obj, $name, %arg) = @_;
287 295
288 _attach_attachment KLASS_MAP, $obj, $name, %arg; 296 _attach_attachment $obj, $name, %arg;
289} 297}
290 298
291sub attach_global { 299sub attach_global {
292 _attach @CB_GLOBAL, KLASS_GLOBAL, @_ 300 _attach @CB_GLOBAL, KLASS_GLOBAL, @_
293} 301}
313 321
314sub register_attachment { 322sub register_attachment {
315 my $name = shift; 323 my $name = shift;
316 324
317 $attachment{$name} = [[KLASS_OBJECT, @_]]; 325 $attachment{$name} = [[KLASS_OBJECT, @_]];
326}
327
328sub register_map_attachment {
329 my $name = shift;
330
331 $attachment{$name} = [[KLASS_MAP, @_]];
318} 332}
319 333
320our $override; 334our $override;
321our @invoke_results = (); # referenced from .xs code. TODO: play tricks with reify and mortals? 335our @invoke_results = (); # referenced from .xs code. TODO: play tricks with reify and mortals?
322 336
385} 399}
386 400
387sub object_freezer_save { 401sub object_freezer_save {
388 my ($filename, $objs) = @_; 402 my ($filename, $objs) = @_;
389 403
390 $filename .= ".pst";
391
392 if (@$objs) { 404 if (@$objs) {
393 open my $fh, ">:raw", "$filename~"; 405 open my $fh, ">:raw", "$filename.pst~";
394 chmod $fh, SAVE_MODE;
395 syswrite $fh, Storable::nfreeze { version => 1, objs => $objs }; 406 syswrite $fh, Storable::nfreeze { version => 1, objs => $objs };
396 close $fh; 407 close $fh;
408 chmod SAVE_MODE, "$filename.pst~";
397 rename "$filename~", $filename; 409 rename "$filename.pst~", "$filename.pst";
398 } else { 410 } else {
399 unlink $filename; 411 unlink "$filename.pst";
400 } 412 }
413
414 chmod SAVE_MODE, "$filename~";
415 rename "$filename~", $filename;
401} 416}
402 417
403sub object_thawer_load { 418sub object_thawer_load {
404 my ($filename) = @_; 419 my ($filename) = @_;
405 420
667 my ($map) = @_; 682 my ($map) = @_;
668 683
669 my $path = $map->tmpname; 684 my $path = $map->tmpname;
670 defined $path or return; 685 defined $path or return;
671 686
672 unlink "$path.cfperl";
673 unlink "$path.pst"; 687 unlink "$path.pst";
674}; 688};
675 689
690# old style persistent data, TODO: remove #d#
676*cf::mapsupport::on_swapin = 691*cf::mapsupport::on_swapin =
677*cf::mapsupport::on_load = sub { 692*cf::mapsupport::on_load = sub {
678 my ($map) = @_; 693 my ($map) = @_;
679 694
680 my $path = $map->tmpname; 695 my $path = $map->tmpname;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines