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

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.30 by root, Thu Feb 23 14:54:44 2006 UTC vs.
Revision 1.34 by root, Fri Feb 24 11:50:36 2006 UTC

13use base 'Exporter'; 13use base 'Exporter';
14 14
15use Carp (); 15use Carp ();
16use File::Spec; 16use File::Spec;
17use List::Util qw(min max); 17use List::Util qw(min max);
18use Storable;
18 19
19#XXX: The map_* procedures scream for a map-object 20#XXX: The map_* procedures scream for a map-object
20 21
21our @EXPORT = 22our @EXPORT =
22 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);
44sub MOVE_FLY_HIGH (){ 0x4 } 45sub MOVE_FLY_HIGH (){ 0x4 }
45sub MOVE_FLYING (){ 0x6 } 46sub MOVE_FLYING (){ 0x6 }
46sub MOVE_SWIM (){ 0x8 } 47sub MOVE_SWIM (){ 0x8 }
47sub MOVE_ALL (){ 0xf } 48sub MOVE_ALL (){ 0xf }
48 49
49BEGIN {
50 if ($^O eq "MSWin32") {
51 eval "use FreezeThaw qw(freeze thaw)";
52 } else {
53 eval "use Storable qw(freeze thaw)";
54 }
55}
56
57sub load_ref($) { 50sub load_ref($) {
58 my ($path) = @_; 51 my ($path) = @_;
59 52
60 open my $fh, "<:raw", "$path~" 53 open my $fh, "<", $path
61 or die "$path~: $!"; 54 or die "$path: $!";
55 binmode $fh;
62 local $/; 56 local $/;
63 thaw <$fh> 57
58 Storable::thaw <$fh>
64} 59}
65 60
66sub save_ref($$) { 61sub save_ref($$) {
67 my ($ref, $path) = @_; 62 my ($ref, $path) = @_;
68 63
69 open my $fh, ">:raw", "$path~" 64 open my $fh, ">", "$path~"
70 or die "$path~: $!"; 65 or die "$path~: $!";
71 my $ref = freeze $ref; 66 binmode $fh;
72 print $fh $ref; 67 print $fh Storable::freeze $ref;
73 close $fh; 68 close $fh;
74 rename "$path~", $path 69 rename "$path~", $path
75 or die "$path: $!"; 70 or die "$path: $!";
76} 71}
77 72
146 && -M $cache < -M $path 141 && -M $cache < -M $path
147 && load_ref $cache 142 && load_ref $cache
148 } or do { 143 } or do {
149 my %pak; 144 my %pak;
150 145
151 open my $fh, "<:raw", $path 146 open my $fh, "<", $path
152 or Carp::croak "$_[0]: $!"; 147 or Carp::croak "$_[0]: $!";
148 binmode $fh;
153 while (<$fh>) { 149 while (<$fh>) {
154 my ($type, $id, $len, $path) = split; 150 my ($type, $id, $len, $path) = split;
155 $path =~ s/.*\///; 151 $path =~ s/.*\///;
156 read $fh, $pak{$path}, $len; 152 read $fh, $pak{$path}, $len;
157 } 153 }
172 && load_ref $cache 168 && load_ref $cache
173 } or do { 169 } or do {
174 my %arc; 170 my %arc;
175 my ($more, $prev); 171 my ($more, $prev);
176 172
177 open my $fh, "<:raw", $path 173 open my $fh, "<", $path
178 or Carp::croak "$path: $!"; 174 or Carp::croak "$path: $!";
175
176 binmode $fh;
179 177
180 my $parse_block; $parse_block = sub { 178 my $parse_block; $parse_block = sub {
181 my %arc = @_; 179 my %arc = @_;
182 180
183 while (<$fh>) { 181 while (<$fh>) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines