… | |
… | |
15 | |
15 | |
16 | _reload_1; |
16 | _reload_1; |
17 | |
17 | |
18 | our %COMMAND = (); |
18 | our %COMMAND = (); |
19 | our @EVENT; |
19 | our @EVENT; |
20 | our %PROP_TYPE; |
|
|
21 | our %PROP_IDX; |
|
|
22 | our $LIBDIR = maps_directory "perl"; |
20 | our $LIBDIR = maps_directory "perl"; |
23 | |
21 | |
24 | our $TICK = MAX_TIME * 1e-6; |
22 | our $TICK = MAX_TIME * 1e-6; |
25 | our $TICK_WATCHER; |
23 | our $TICK_WATCHER; |
26 | our $NEXT_TICK; |
24 | our $NEXT_TICK; |
… | |
… | |
33 | |
31 | |
34 | print STDERR "cfperl: $msg"; |
32 | print STDERR "cfperl: $msg"; |
35 | LOG llevError, "cfperl: $msg"; |
33 | LOG llevError, "cfperl: $msg"; |
36 | }; |
34 | }; |
37 | } |
35 | } |
38 | |
|
|
39 | my %ignore_set = (MAP_PROP_PATH => 1); # I hate the plug-in api. Deeply! |
|
|
40 | |
|
|
41 | # generate property mutators |
|
|
42 | sub prop_gen { |
|
|
43 | my ($prefix, $class) = @_; |
|
|
44 | |
|
|
45 | no strict 'refs'; |
|
|
46 | |
|
|
47 | for my $prop (keys %PROP_TYPE) { |
|
|
48 | $prop =~ /^\Q$prefix\E_(.*$)/ or next; |
|
|
49 | my $sub = lc $1; |
|
|
50 | |
|
|
51 | my $type = $PROP_TYPE{$prop}; |
|
|
52 | my $idx = $PROP_IDX {$prop}; |
|
|
53 | |
|
|
54 | *{"$class\::get_$sub"} = *{"$class\::$sub"} = sub { |
|
|
55 | $_[0]->get_property ($type, $idx) |
|
|
56 | }; |
|
|
57 | |
|
|
58 | *{"$class\::set_$sub"} = sub { |
|
|
59 | $_[0]->set_property ($type, $idx, $_[1]); |
|
|
60 | } unless $ignore_set{$prop}; |
|
|
61 | } |
|
|
62 | } |
|
|
63 | |
|
|
64 | # auto-generate most of the API |
|
|
65 | |
|
|
66 | prop_gen OBJECT_PROP => "cf::object"; |
|
|
67 | # CFAPI_OBJECT_ANIMATION? |
|
|
68 | prop_gen PLAYER_PROP => "cf::object::player"; |
|
|
69 | |
|
|
70 | prop_gen MAP_PROP => "cf::map"; |
|
|
71 | prop_gen ARCH_PROP => "cf::arch"; |
|
|
72 | |
36 | |
73 | @safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; |
37 | @safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; |
74 | |
38 | |
75 | # we bless all objects into (empty) derived classes to force a method lookup |
39 | # we bless all objects into (empty) derived classes to force a method lookup |
76 | # within the Safe compartment. |
40 | # within the Safe compartment. |
… | |
… | |
509 | } |
473 | } |
510 | |
474 | |
511 | sub object_thawer_load { |
475 | sub object_thawer_load { |
512 | my ($filename) = @_; |
476 | my ($filename) = @_; |
513 | |
477 | |
|
|
478 | local $/; |
|
|
479 | |
|
|
480 | my $av; |
|
|
481 | |
|
|
482 | #TODO: use sysread etc. |
|
|
483 | if (open my $data, "<:raw:perlio", $filename) { |
|
|
484 | $data = <$data>; |
514 | open my $fh, "<:raw:perlio", "$filename.pst" |
485 | if (open my $pst, "<:raw:perlio", "$filename.pst") { |
515 | or return; |
486 | $av = eval { (Storable::thaw <$pst>)->{objs} }; |
|
|
487 | } |
|
|
488 | return ($data, $av); |
|
|
489 | } |
516 | |
490 | |
517 | eval { local $/; (Storable::thaw <$fh>)->{objs} } |
491 | () |
518 | } |
492 | } |
519 | |
493 | |
520 | attach_to_objects |
494 | attach_to_objects |
521 | prio => -1000000, |
495 | prio => -1000000, |
522 | on_clone => sub { |
496 | on_clone => sub { |
… | |
… | |
718 | #Symbol::delete_package __PACKAGE__; |
692 | #Symbol::delete_package __PACKAGE__; |
719 | |
693 | |
720 | # 7. reload cf.pm |
694 | # 7. reload cf.pm |
721 | $msg->("reloading cf.pm"); |
695 | $msg->("reloading cf.pm"); |
722 | require cf; |
696 | require cf; |
|
|
697 | |
|
|
698 | $msg->("load extensions"); |
|
|
699 | cf::load_extensions; |
723 | }; |
700 | }; |
724 | $msg->($@) if $@; |
701 | $msg->($@) if $@; |
725 | |
702 | |
726 | $msg->("reloaded"); |
703 | $msg->("reloaded"); |
727 | }; |
704 | }; |
… | |
… | |
918 | |
895 | |
919 | ############################################################################# |
896 | ############################################################################# |
920 | # the server's main() |
897 | # the server's main() |
921 | |
898 | |
922 | sub main { |
899 | sub main { |
|
|
900 | load_extensions; |
923 | Event::loop; |
901 | Event::loop; |
924 | } |
902 | } |
925 | |
903 | |
926 | ############################################################################# |
904 | ############################################################################# |
927 | # initialisation |
905 | # initialisation |
928 | |
906 | |
929 | register "<global>", __PACKAGE__; |
907 | register "<global>", __PACKAGE__; |
930 | |
908 | |
931 | unshift @INC, $LIBDIR; |
909 | unshift @INC, $LIBDIR; |
932 | |
|
|
933 | load_extensions; |
|
|
934 | |
910 | |
935 | $TICK_WATCHER = Event->timer ( |
911 | $TICK_WATCHER = Event->timer ( |
936 | prio => 1, |
912 | prio => 1, |
937 | at => $NEXT_TICK || 1, |
913 | at => $NEXT_TICK || 1, |
938 | cb => sub { |
914 | cb => sub { |