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.31 by root, Thu Feb 23 15:01:43 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);
19 18
20#XXX: The map_* procedures scream for a map-object 19#XXX: The map_* procedures scream for a map-object
21 20
45sub MOVE_FLY_HIGH (){ 0x4 } 44sub MOVE_FLY_HIGH (){ 0x4 }
46sub MOVE_FLYING (){ 0x6 } 45sub MOVE_FLYING (){ 0x6 }
47sub MOVE_SWIM (){ 0x8 } 46sub MOVE_SWIM (){ 0x8 }
48sub MOVE_ALL (){ 0xf } 47sub MOVE_ALL (){ 0xf }
49 48
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
50sub load_ref($) { 57sub 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
59sub save_ref($$) { 67sub 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
406init $VARDIR; 418init $VARDIR;
407 419
408=head1 AUTHOR 420=head1 AUTHOR
409 421

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines