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.21 by root, Thu Feb 23 01:55:29 2006 UTC vs.
Revision 1.24 by root, Thu Feb 23 03:13:33 2006 UTC

113sub read_pak($;$) { 113sub read_pak($;$) {
114 my ($path, $cache) = @_; 114 my ($path, $cache) = @_;
115 115
116 eval { 116 eval {
117 defined $cache 117 defined $cache
118 && -e $cache
118 && -M $cache < -M $path 119 && -M $cache < -M $path
119 && Storable::retrieve $cache 120 && Storable::retrieve ($cache)
120 } or do { 121 } or do {
121 my %pak; 122 my %pak;
122 123
123 open my $fh, "<:raw", $path 124 open my $fh, "<:raw", $path
124 or Carp::croak "$_[0]: $!"; 125 or Carp::croak "$_[0]: $!";
126 my ($type, $id, $len, $path) = split; 127 my ($type, $id, $len, $path) = split;
127 $path =~ s/.*\///; 128 $path =~ s/.*\///;
128 read $fh, $pak{$path}, $len; 129 read $fh, $pak{$path}, $len;
129 } 130 }
130 131
131 Storable::nstore \%pak, $cache 132 Storable::nstore (\%pak, $cache)
132 if defined $cache; 133 if defined $cache;
133 134
134 \%pak 135 \%pak
135 } 136 }
136} 137}
138sub read_arch($;$) { 139sub read_arch($;$) {
139 my ($path, $cache) = @_; 140 my ($path, $cache) = @_;
140 141
141 eval { 142 eval {
142 defined $cache 143 defined $cache
144 && -e $cache
143 && -M $cache < -M $path 145 && -M $cache < -M $path
144 && Storable::retrieve $cache 146 && Storable::retrieve ($cache)
145 } or do { 147 } or do {
146 my %arc; 148 my %arc;
147 my ($more, $prev); 149 my ($more, $prev);
148 150
149 open my $fh, "<:raw", $path 151 open my $fh, "<:raw", $path
204 } 206 }
205 } 207 }
206 208
207 undef $parse_block; # work around bug in perl not freeing $fh etc. 209 undef $parse_block; # work around bug in perl not freeing $fh etc.
208 210
209 Storable::nstore \%arc, $cache 211 Storable::nstore (\%arc, $cache)
210 if defined $cache; 212 if defined $cache;
211 213
212 \%arc 214 \%arc
213 } 215 }
214} 216}
263 265
264 } else { 266 } else {
265 # single face 267 # single face
266 return (0, 0, 0, 0); 268 return (0, 0, 0, 0);
267 } 269 }
268}
269
270sub init($) {
271 my ($cachedir) = @_;
272
273 return if %ARCH;
274
275 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
276} 270}
277 271
278=item $type = arch_attr $arch 272=item $type = arch_attr $arch
279 273
280Returns a hashref describing the object and its attributes. It can contain 274Returns a hashref describing the object and its attributes. It can contain
378# return(edit_type); 372# return(edit_type);
379# 373#
380# 374#
381} 375}
382 376
377sub init($) {
378 my ($cachedir) = @_;
379
380 return if %ARCH;
381
382 mkdir $cachedir, 0777;
383 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
384}
385
383$CACHEDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir; 386$CACHEDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir;
384 387
385init $CACHEDIR; 388init $CACHEDIR;
386 389
387=head1 AUTHOR 390=head1 AUTHOR
388 391

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines