… | |
… | |
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); |
|
|
18 | use Storable; |
19 | |
19 | |
20 | #XXX: The map_* procedures scream for a map-object |
20 | #XXX: The map_* procedures scream for a map-object |
21 | |
21 | |
22 | our @EXPORT = |
22 | our @EXPORT = |
23 | qw(read_pak read_arch %ARCH TILESIZE $TILE %FACE editor_archs arch_extents); |
23 | qw(read_pak read_arch %ARCH TILESIZE $TILE %FACE editor_archs arch_extents); |
… | |
… | |
48 | sub MOVE_ALL (){ 0xf } |
48 | sub MOVE_ALL (){ 0xf } |
49 | |
49 | |
50 | sub load_ref($) { |
50 | sub load_ref($) { |
51 | my ($path) = @_; |
51 | my ($path) = @_; |
52 | |
52 | |
53 | open my $fh, "<:raw", "$path~" |
53 | open my $fh, "<", $path |
54 | or die "$path~: $!"; |
54 | or die "$path: $!"; |
|
|
55 | binmode $fh; |
55 | local $/; |
56 | local $/; |
|
|
57 | |
56 | Storable::thaw <$fh> |
58 | Storable::thaw <$fh> |
57 | } |
59 | } |
58 | |
60 | |
59 | sub save_ref($$) { |
61 | sub save_ref($$) { |
60 | my ($ref, $path) = @_; |
62 | my ($ref, $path) = @_; |
61 | |
63 | |
62 | open my $fh, ">:raw", "$path~" |
64 | open my $fh, ">", "$path~" |
63 | or die "$path~: $!"; |
65 | or die "$path~: $!"; |
|
|
66 | binmode $fh; |
64 | print $fh Storable::nfreeze $ref; |
67 | print $fh Storable::freeze $ref; |
65 | close $fh; |
68 | close $fh; |
66 | rename "$path~", $path |
69 | rename "$path~", $path |
67 | or die "$path: $!"; |
70 | or die "$path: $!"; |
68 | } |
71 | } |
69 | |
72 | |
… | |
… | |
138 | && -M $cache < -M $path |
141 | && -M $cache < -M $path |
139 | && load_ref $cache |
142 | && load_ref $cache |
140 | } or do { |
143 | } or do { |
141 | my %pak; |
144 | my %pak; |
142 | |
145 | |
143 | open my $fh, "<:raw", $path |
146 | open my $fh, "<", $path |
144 | or Carp::croak "$_[0]: $!"; |
147 | or Carp::croak "$_[0]: $!"; |
|
|
148 | binmode $fh; |
145 | while (<$fh>) { |
149 | while (<$fh>) { |
146 | my ($type, $id, $len, $path) = split; |
150 | my ($type, $id, $len, $path) = split; |
147 | $path =~ s/.*\///; |
151 | $path =~ s/.*\///; |
148 | read $fh, $pak{$path}, $len; |
152 | read $fh, $pak{$path}, $len; |
149 | } |
153 | } |
… | |
… | |
164 | && load_ref $cache |
168 | && load_ref $cache |
165 | } or do { |
169 | } or do { |
166 | my %arc; |
170 | my %arc; |
167 | my ($more, $prev); |
171 | my ($more, $prev); |
168 | |
172 | |
169 | open my $fh, "<:raw", $path |
173 | open my $fh, "<", $path |
170 | or Carp::croak "$path: $!"; |
174 | or Carp::croak "$path: $!"; |
|
|
175 | |
|
|
176 | binmode $fh; |
171 | |
177 | |
172 | my $parse_block; $parse_block = sub { |
178 | my $parse_block; $parse_block = sub { |
173 | my %arc = @_; |
179 | my %arc = @_; |
174 | |
180 | |
175 | while (<$fh>) { |
181 | while (<$fh>) { |