… | |
… | |
11 | use strict; |
11 | use strict; |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
15 | use Carp (); |
15 | use Carp (); |
16 | use Storable; |
|
|
17 | use File::Spec; |
16 | use File::Spec; |
18 | use List::Util qw(min max); |
17 | use List::Util qw(min max); |
19 | |
18 | |
20 | #XXX: The map_* procedures scream for a map-object |
19 | #XXX: The map_* procedures scream for a map-object |
21 | |
20 | |
… | |
… | |
45 | sub MOVE_FLY_HIGH (){ 0x4 } |
44 | sub MOVE_FLY_HIGH (){ 0x4 } |
46 | sub MOVE_FLYING (){ 0x6 } |
45 | sub MOVE_FLYING (){ 0x6 } |
47 | sub MOVE_SWIM (){ 0x8 } |
46 | sub MOVE_SWIM (){ 0x8 } |
48 | sub MOVE_ALL (){ 0xf } |
47 | sub MOVE_ALL (){ 0xf } |
49 | |
48 | |
|
|
49 | BEGIN { |
|
|
50 | if ($^O eq "MSWin32") { |
|
|
51 | eval "use FreezeThaw qw(freeze thaw)"; |
|
|
52 | } else { |
|
|
53 | eval "use Storable qw(freeze thaw)"; |
|
|
54 | } |
|
|
55 | } |
|
|
56 | |
50 | sub load_ref($) { |
57 | sub load_ref($) { |
51 | my ($path) = @_; |
58 | my ($path) = @_; |
52 | |
59 | |
53 | open my $fh, ">:raw", "$path~" |
60 | open my $fh, "<", $path |
54 | or die "$path~: $!"; |
61 | or die "$path: $!"; |
|
|
62 | binmode $fh; |
55 | local $/; |
63 | local $/; |
56 | Storable::thaw <$fh> |
64 | thaw <$fh> |
57 | } |
65 | } |
58 | |
66 | |
59 | sub save_ref($$) { |
67 | sub save_ref($$) { |
60 | my ($ref, $path) = @_; |
68 | my ($ref, $path) = @_; |
61 | |
69 | |
62 | open my $fh, ">:raw", "$path~" |
70 | open my $fh, ">", "$path~" |
63 | or die "$path~: $!"; |
71 | or die "$path~: $!"; |
|
|
72 | binmode $fh; |
64 | print $fh Storable::nfreeze $ref; |
73 | print $fh freeze $ref; |
65 | close $fh; |
74 | close $fh; |
66 | rename "$path~", $path |
75 | rename "$path~", $path |
67 | or die "$path: $!"; |
76 | or die "$path: $!"; |
68 | } |
77 | } |
69 | |
78 | |
… | |
… | |
138 | && -M $cache < -M $path |
147 | && -M $cache < -M $path |
139 | && load_ref $cache |
148 | && load_ref $cache |
140 | } or do { |
149 | } or do { |
141 | my %pak; |
150 | my %pak; |
142 | |
151 | |
143 | open my $fh, "<:raw", $path |
152 | open my $fh, "<", $path |
144 | or Carp::croak "$_[0]: $!"; |
153 | or Carp::croak "$_[0]: $!"; |
|
|
154 | binmode $fh; |
145 | while (<$fh>) { |
155 | while (<$fh>) { |
146 | my ($type, $id, $len, $path) = split; |
156 | my ($type, $id, $len, $path) = split; |
147 | $path =~ s/.*\///; |
157 | $path =~ s/.*\///; |
148 | read $fh, $pak{$path}, $len; |
158 | read $fh, $pak{$path}, $len; |
149 | } |
159 | } |
… | |
… | |
164 | && load_ref $cache |
174 | && load_ref $cache |
165 | } or do { |
175 | } or do { |
166 | my %arc; |
176 | my %arc; |
167 | my ($more, $prev); |
177 | my ($more, $prev); |
168 | |
178 | |
169 | open my $fh, "<:raw", $path |
179 | open my $fh, "<", $path |
170 | or Carp::croak "$path: $!"; |
180 | or Carp::croak "$path: $!"; |
|
|
181 | |
|
|
182 | binmode $fh; |
171 | |
183 | |
172 | my $parse_block; $parse_block = sub { |
184 | my $parse_block; $parse_block = sub { |
173 | my %arc = @_; |
185 | my %arc = @_; |
174 | |
186 | |
175 | while (<$fh>) { |
187 | while (<$fh>) { |
… | |
… | |
399 | |
411 | |
400 | mkdir $cachedir, 0777; |
412 | mkdir $cachedir, 0777; |
401 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
413 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
402 | } |
414 | } |
403 | |
415 | |
404 | $VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir; |
416 | $VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire"; |
405 | |
417 | |
406 | init $VARDIR; |
418 | init $VARDIR; |
407 | |
419 | |
408 | =head1 AUTHOR |
420 | =head1 AUTHOR |
409 | |
421 | |