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.25 by root, Thu Feb 23 03:14:26 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);
44sub MOVE_FLY_LOW (){ 0x2 } 44sub MOVE_FLY_LOW (){ 0x2 }
45sub MOVE_FLY_HIGH (){ 0x4 } 45sub MOVE_FLY_HIGH (){ 0x4 }
46sub MOVE_FLYING (){ 0x6 } 46sub MOVE_FLYING (){ 0x6 }
47sub MOVE_SWIM (){ 0x8 } 47sub MOVE_SWIM (){ 0x8 }
48sub MOVE_ALL (){ 0xf } 48sub MOVE_ALL (){ 0xf }
49
50sub load_ref($) {
51 my ($path) = @_;
52
53 open my $fh, "<", $path
54 or die "$path: $!";
55 binmode $fh;
56 local $/;
57
58 Storable::thaw <$fh>
59}
60
61sub save_ref($$) {
62 my ($ref, $path) = @_;
63
64 open my $fh, ">", "$path~"
65 or die "$path~: $!";
66 binmode $fh;
67 print $fh Storable::freeze $ref;
68 close $fh;
69 rename "$path~", $path
70 or die "$path: $!";
71}
49 72
50sub normalize_arch($) { 73sub normalize_arch($) {
51 my ($ob) = @_; 74 my ($ob) = @_;
52 75
53 my $arch = $ARCH{$ob->{_name}} 76 my $arch = $ARCH{$ob->{_name}}
113sub read_pak($;$) { 136sub read_pak($;$) {
114 my ($path, $cache) = @_; 137 my ($path, $cache) = @_;
115 138
116 eval { 139 eval {
117 defined $cache 140 defined $cache
118 && -e $cache
119 && -M $cache < -M $path 141 && -M $cache < -M $path
120 && Storable::retrieve ($cache) 142 && load_ref $cache
121 } or do { 143 } or do {
122 my %pak; 144 my %pak;
123 145
124 open my $fh, "<:raw", $path 146 open my $fh, "<", $path
125 or Carp::croak "$_[0]: $!"; 147 or Carp::croak "$_[0]: $!";
148 binmode $fh;
126 while (<$fh>) { 149 while (<$fh>) {
127 my ($type, $id, $len, $path) = split; 150 my ($type, $id, $len, $path) = split;
128 $path =~ s/.*\///; 151 $path =~ s/.*\///;
129 read $fh, $pak{$path}, $len; 152 read $fh, $pak{$path}, $len;
130 } 153 }
131 154
132 Storable::nstore (\%pak, $cache) 155 save_ref \%pak, $cache
133 if defined $cache; 156 if defined $cache;
134 157
135 \%pak 158 \%pak
136 } 159 }
137} 160}
139sub read_arch($;$) { 162sub read_arch($;$) {
140 my ($path, $cache) = @_; 163 my ($path, $cache) = @_;
141 164
142 eval { 165 eval {
143 defined $cache 166 defined $cache
144 && -e $cache
145 && -M $cache < -M $path 167 && -M $cache < -M $path
146 && Storable::retrieve ($cache) 168 && load_ref $cache
147 } or do { 169 } or do {
148 my %arc; 170 my %arc;
149 my ($more, $prev); 171 my ($more, $prev);
150 172
151 open my $fh, "<:raw", $path 173 open my $fh, "<", $path
152 or Carp::croak "$path: $!"; 174 or Carp::croak "$path: $!";
175
176 binmode $fh;
153 177
154 my $parse_block; $parse_block = sub { 178 my $parse_block; $parse_block = sub {
155 my %arc = @_; 179 my %arc = @_;
156 180
157 while (<$fh>) { 181 while (<$fh>) {
206 } 230 }
207 } 231 }
208 232
209 undef $parse_block; # work around bug in perl not freeing $fh etc. 233 undef $parse_block; # work around bug in perl not freeing $fh etc.
210 234
211 Storable::nstore (\%arc, $cache) 235 save_ref \%arc, $cache
212 if defined $cache; 236 if defined $cache;
213 237
214 \%arc 238 \%arc
215 } 239 }
216} 240}
299 type: 323 type:
300 for (@Crossfire::Data::ATTR0) { 324 for (@Crossfire::Data::ATTR0) {
301 my $req = $_->{required} 325 my $req = $_->{required}
302 or die "internal error: ATTR0 without 'required'"; 326 or die "internal error: ATTR0 without 'required'";
303 327
328 keys %$req;
304 while (my ($k, $v) = each %$req) { 329 while (my ($k, $v) = each %$req) {
305 next type 330 next type
306 unless $arch->{$k} == $v; 331 unless $arch->{$k} == $v;
307 } 332 }
308 333
381 406
382 mkdir $cachedir, 0777; 407 mkdir $cachedir, 0777;
383 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; 408 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
384} 409}
385 410
386$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir; 411$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire";
387 412
388init $VARDIR; 413init $VARDIR;
389 414
390=head1 AUTHOR 415=head1 AUTHOR
391 416

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines