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.22 by root, Thu Feb 23 01:55:54 2006 UTC vs.
Revision 1.29 by root, Thu Feb 23 13:22:10 2006 UTC

25our $LIB = $ENV{CROSSFIRE_LIBDIR} 25our $LIB = $ENV{CROSSFIRE_LIBDIR}
26 or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n"; 26 or Carp::croak "\$CROSSFIRE_LIBDIR must be set\n";
27 27
28sub TILESIZE (){ 32 } 28sub TILESIZE (){ 32 }
29 29
30our $CACHEDIR; 30our $VARDIR;
31our %ARCH; 31our %ARCH;
32our %FACE; 32our %FACE;
33our $TILE; 33our $TILE;
34 34
35our %FIELD_MULTILINE = ( 35our %FIELD_MULTILINE = (
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, "<:raw", "$path~"
54 or die "$path~: $!";
55 local $/;
56 Storable::thaw <$fh>
57}
58
59sub save_ref($$) {
60 my ($ref, $path) = @_;
61
62 open my $fh, ">:raw", "$path~"
63 or die "$path~: $!";
64 print $fh Storable::nfreeze $ref;
65 close $fh;
66 rename "$path~", $path
67 or die "$path: $!";
68}
49 69
50sub normalize_arch($) { 70sub normalize_arch($) {
51 my ($ob) = @_; 71 my ($ob) = @_;
52 72
53 my $arch = $ARCH{$ob->{_name}} 73 my $arch = $ARCH{$ob->{_name}}
114 my ($path, $cache) = @_; 134 my ($path, $cache) = @_;
115 135
116 eval { 136 eval {
117 defined $cache 137 defined $cache
118 && -M $cache < -M $path 138 && -M $cache < -M $path
119 && Storable::retrieve $cache 139 && load_ref $cache
120 } or do { 140 } or do {
121 my %pak; 141 my %pak;
122 142
123 open my $fh, "<:raw", $path 143 open my $fh, "<:raw", $path
124 or Carp::croak "$_[0]: $!"; 144 or Carp::croak "$_[0]: $!";
126 my ($type, $id, $len, $path) = split; 146 my ($type, $id, $len, $path) = split;
127 $path =~ s/.*\///; 147 $path =~ s/.*\///;
128 read $fh, $pak{$path}, $len; 148 read $fh, $pak{$path}, $len;
129 } 149 }
130 150
131 Storable::nstore \%pak, $cache 151 save_ref \%pak, $cache
132 if defined $cache; 152 if defined $cache;
133 153
134 \%pak 154 \%pak
135 } 155 }
136} 156}
139 my ($path, $cache) = @_; 159 my ($path, $cache) = @_;
140 160
141 eval { 161 eval {
142 defined $cache 162 defined $cache
143 && -M $cache < -M $path 163 && -M $cache < -M $path
144 && Storable::retrieve $cache 164 && load_ref $cache
145 } or do { 165 } or do {
146 my %arc; 166 my %arc;
147 my ($more, $prev); 167 my ($more, $prev);
148 168
149 open my $fh, "<:raw", $path 169 open my $fh, "<:raw", $path
204 } 224 }
205 } 225 }
206 226
207 undef $parse_block; # work around bug in perl not freeing $fh etc. 227 undef $parse_block; # work around bug in perl not freeing $fh etc.
208 228
209 Storable::nstore \%arc, $cache 229 save_ref \%arc, $cache
210 if defined $cache; 230 if defined $cache;
211 231
212 \%arc 232 \%arc
213 } 233 }
214} 234}
263 283
264 } else { 284 } else {
265 # single face 285 # single face
266 return (0, 0, 0, 0); 286 return (0, 0, 0, 0);
267 } 287 }
268}
269
270sub init($) {
271 my ($cachedir) = @_;
272
273 return if %ARCH;
274
275 mkdir 0777, $cachedir;
276 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
277} 288}
278 289
279=item $type = arch_attr $arch 290=item $type = arch_attr $arch
280 291
281Returns a hashref describing the object and its attributes. It can contain 292Returns a hashref describing the object and its attributes. It can contain
379# return(edit_type); 390# return(edit_type);
380# 391#
381# 392#
382} 393}
383 394
395sub init($) {
396 my ($cachedir) = @_;
397
398 return if %ARCH;
399
400 mkdir $cachedir, 0777;
401 *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst";
402}
403
384$CACHEDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir; 404$VARDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir . "/crossfire";
385 405
386init $CACHEDIR; 406init $VARDIR;
387 407
388=head1 AUTHOR 408=head1 AUTHOR
389 409
390 Marc Lehmann <schmorp@schmorp.de> 410 Marc Lehmann <schmorp@schmorp.de>
391 http://home.schmorp.de/ 411 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines