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.35 by root, Sun Mar 12 16:23:56 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>) {
317 type: 323 type:
318 for (@Crossfire::Data::ATTR0) { 324 for (@Crossfire::Data::ATTR0) {
319 my $req = $_->{required} 325 my $req = $_->{required}
320 or die "internal error: ATTR0 without 'required'"; 326 or die "internal error: ATTR0 without 'required'";
321 327
328 keys %$req;
322 while (my ($k, $v) = each %$req) { 329 while (my ($k, $v) = each %$req) {
323 next type 330 next type
324 unless $arch->{$k} == $v; 331 unless $arch->{$k} == $v;
325 } 332 }
326 333
399 406
400 mkdir $cachedir, 0777; 407 mkdir $cachedir, 0777;
401 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 408 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
402} 409}
403 410
404$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir; 411$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire";
405 412
406init $VARDIR; 413init $VARDIR;
407 414
408=head1 AUTHOR 415=head1 AUTHOR
409 416

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines