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.20 by root, Thu Feb 23 01:35:35 2006 UTC vs.
Revision 1.25 by root, Thu Feb 23 03:14:26 2006 UTC

12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
15use Carp (); 15use Carp ();
16use Storable; 16use Storable;
17use File::Spec;
17use List::Util qw(min max); 18use List::Util qw(min max);
18 19
19#XXX: The map_* procedures scream for a map-object 20#XXX: The map_* procedures scream for a map-object
20 21
21our @EXPORT = 22our @EXPORT =
24our $LIB = $ENV{CROSSFIRE_LIBDIR} 25our $LIB = $ENV{CROSSFIRE_LIBDIR}
25 or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n"; 26 or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n";
26 27
27sub TILESIZE (){ 32 } 28sub TILESIZE (){ 32 }
28 29
29our $CACHEDIR; 30our $VARDIR;
30our %ARCH; 31our %ARCH;
31our %FACE; 32our %FACE;
32our $TILE; 33our $TILE;
33 34
34our %FIELD_MULTILINE = ( 35our %FIELD_MULTILINE = (
112sub read_pak($;$) { 113sub read_pak($;$) {
113 my ($path, $cache) = @_; 114 my ($path, $cache) = @_;
114 115
115 eval { 116 eval {
116 defined $cache 117 defined $cache
118 && -e $cache
117 && -M $cache < -M $path 119 && -M $cache < -M $path
118 && Storable::retrieve $cache 120 && Storable::retrieve ($cache)
119 } or do { 121 } or do {
120 my %pak; 122 my %pak;
121 123
122 open my $fh, "<:raw", $path 124 open my $fh, "<:raw", $path
123 or Carp::croak "$_[0]: $!"; 125 or Carp::croak "$_[0]: $!";
125 my ($type, $id, $len, $path) = split; 127 my ($type, $id, $len, $path) = split;
126 $path =~ s/.*\///; 128 $path =~ s/.*\///;
127 read $fh, $pak{$path}, $len; 129 read $fh, $pak{$path}, $len;
128 } 130 }
129 131
130 Storable::nstore \%pak, $cache 132 Storable::nstore (\%pak, $cache)
131 if defined $cache; 133 if defined $cache;
132 134
133 \%pak 135 \%pak
134 } 136 }
135} 137}
137sub read_arch($;$) { 139sub read_arch($;$) {
138 my ($path, $cache) = @_; 140 my ($path, $cache) = @_;
139 141
140 eval { 142 eval {
141 defined $cache 143 defined $cache
144 && -e $cache
142 && -M $cache < -M $path 145 && -M $cache < -M $path
143 && Storable::retrieve $cache 146 && Storable::retrieve ($cache)
144 } or do { 147 } or do {
145 my %arc; 148 my %arc;
146 my ($more, $prev); 149 my ($more, $prev);
147 150
148 open my $fh, "<:raw", $path 151 open my $fh, "<:raw", $path
203 } 206 }
204 } 207 }
205 208
206 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.
207 210
208 Storable::nstore \%arc, $cache 211 Storable::nstore (\%arc, $cache)
209 if defined $cache; 212 if defined $cache;
210 213
211 \%arc 214 \%arc
212 } 215 }
213} 216}
262 265
263 } else { 266 } else {
264 # single face 267 # single face
265 return (0, 0, 0, 0); 268 return (0, 0, 0, 0);
266 } 269 }
267}
268
269sub init($) {
270 my ($cachedir) = @_;
271
272 return if %ARCH;
273
274 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
275} 270}
276 271
277=item $type = arch_attr $arch 272=item $type = arch_attr $arch
278 273
279Returns a hashref describing the object and its attributes. It can contain 274Returns a hashref describing the object and its attributes. It can contain
377# return(edit_type); 372# return(edit_type);
378# 373#
379# 374#
380} 375}
381 376
382$CACHEDIR ||= "$ENV{HOME}/.crossfire"; 377sub init($) {
378 my ($cachedir) = @_;
383 379
380 return if %ARCH;
381
382 mkdir $cachedir, 0777;
383 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
384}
385
386$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir;
387
384init $CACHEDIR; 388init $VARDIR;
385 389
386=head1 AUTHOR 390=head1 AUTHOR
387 391
388 Marc Lehmann <schmorp@schmorp.de> 392 Marc Lehmann <schmorp@schmorp.de>
389 http://home.schmorp.de/ 393 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines