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.28 by root, Thu Feb 23 13:15:22 2006 UTC vs.
Revision 1.34 by root, Fri Feb 24 11:50:36 2006 UTC

11use strict; 11use strict;
12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
15use Carp (); 15use Carp ();
16use Storable;
17use File::Spec; 16use File::Spec;
18use List::Util qw(min max); 17use List::Util qw(min max);
18use 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
22our @EXPORT = 22our @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);
48sub MOVE_ALL (){ 0xf } 48sub MOVE_ALL (){ 0xf }
49 49
50sub load_ref($) { 50sub 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
59sub save_ref($$) { 61sub 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>) {
399 405
400 mkdir $cachedir, 0777; 406 mkdir $cachedir, 0777;
401 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 407 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
402} 408}
403 409
404$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir; 410$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire";
405 411
406init $VARDIR; 412init $VARDIR;
407 413
408=head1 AUTHOR 414=head1 AUTHOR
409 415

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines