ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.562 by root, Sat Apr 23 04:46:26 2011 UTC vs.
Revision 1.566 by root, Sun May 1 16:58:16 2011 UTC

1# 1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG. 2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3# 3#
4# Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4# Copyright (©) 2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 5#
6# Deliantra is free software: you can redistribute it and/or modify it under 6# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the 7# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your 8# Free Software Foundation, either version 3 of the License, or (at your
9# option) any later version. 9# option) any later version.
1954 # {... are special paths that are not being touched 1954 # {... are special paths that are not being touched
1955 # ?xxx/... are special absolute paths 1955 # ?xxx/... are special absolute paths
1956 # ?random/... random maps 1956 # ?random/... random maps
1957 # /... normal maps 1957 # /... normal maps
1958 # ~user/... per-player map of a specific user 1958 # ~user/... per-player map of a specific user
1959 # !up !down for quad maps, or other maps with up/down layers
1959 1960
1960 $path =~ s/$PATH_SEP/\//go; 1961 $path =~ s/$PATH_SEP/\//go;
1961 1962
1962 # treat it as relative path if it starts with 1963 # treat it as relative path if it starts with
1963 # something that looks reasonable 1964 # something that looks reasonable
1964 if ($path =~ m{^(?:\./|\.\./|\w)}) { 1965 if ($path =~ m{^(?:\./|\.\./|\w)}) {
1965 $base or Carp::carp "normalise called with relative path and no base: '$path'"; 1966 $base or Carp::carp "normalise called with relative path and no base: '$path'";
1966 1967
1967 $base =~ s{[^/]+/?$}{}; 1968 $base =~ s{[^/]+/?$}{};
1968 $path = "$base/$path"; 1969 $path = "$base/$path";
1970
1971 } elsif ($path eq '!up') {
1972 $base && ref $base
1973 or Carp::carp "normalise called with relative tile path and no base: '$path'";
1974
1975 my $uppth = $base->tile_path (cf::TILE_UP);
1976 $path = $uppth if $uppth;
1977
1978 } elsif ($path eq '!down') {
1979 $base && ref $base
1980 or Carp::carp "normalise called with relative tile path and no base: '$path'";
1981
1982 my $dpth = $base->tile_path (cf::TILE_DOWN);
1983 $path = $dpth if $dpth;
1969 } 1984 }
1970 1985
1971 for ($path) { 1986 for ($path) {
1972 redo if s{/\.?/}{/}; 1987 redo if s{/\.?/}{/};
1973 redo if s{/[^/]+/\.\./}{/}; 1988 redo if s{/[^/]+/\.\./}{/};
2069 $self->{load_path} = $path; 2084 $self->{load_path} = $path;
2070 2085
2071 1 2086 1
2072} 2087}
2073 2088
2089# used to laod the header of an original map
2074sub load_header_orig { 2090sub load_header_orig {
2075 my ($self) = @_; 2091 my ($self) = @_;
2076 2092
2077 $self->load_header_from ($self->load_path) 2093 $self->load_header_from ($self->load_path)
2078} 2094}
2079 2095
2096# used to laod the header of an instantiated map
2080sub load_header_temp { 2097sub load_header_temp {
2081 my ($self) = @_; 2098 my ($self) = @_;
2082 2099
2083 $self->load_header_from ($self->save_path) 2100 $self->load_header_from ($self->save_path)
2084} 2101}
2085 2102
2103# called after loading the header from an instantiated map
2086sub prepare_temp { 2104sub prepare_temp {
2087 my ($self) = @_; 2105 my ($self) = @_;
2088 2106
2089 $self->last_access ((delete $self->{last_access}) 2107 $self->last_access ((delete $self->{last_access})
2090 || $cf::RUNTIME); #d# 2108 || $cf::RUNTIME); #d#
2091 # safety 2109 # safety
2092 $self->{instantiate_time} = $cf::RUNTIME 2110 $self->{instantiate_time} = $cf::RUNTIME
2093 if $self->{instantiate_time} > $cf::RUNTIME; 2111 if $self->{instantiate_time} > $cf::RUNTIME;
2094} 2112}
2095 2113
2114# called after loading the header from an original map
2096sub prepare_orig { 2115sub prepare_orig {
2097 my ($self) = @_; 2116 my ($self) = @_;
2098 2117
2099 $self->{load_original} = 1; 2118 $self->{load_original} = 1;
2100 $self->{instantiate_time} = $cf::RUNTIME; 2119 $self->{instantiate_time} = $cf::RUNTIME;
2126sub find { 2145sub find {
2127 my ($path, $origin) = @_; 2146 my ($path, $origin) = @_;
2128 2147
2129 cf::cede_to_tick; 2148 cf::cede_to_tick;
2130 2149
2131 $path = normalise $path, $origin && $origin->path; 2150 $path = normalise $path, $origin;
2132 2151
2133 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove 2152 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove
2134 my $guard2 = cf::lock_acquire "map_find:$path"; 2153 my $guard2 = cf::lock_acquire "map_find:$path";
2135 2154
2136 $cf::MAP{$path} || do { 2155 $cf::MAP{$path} || do {
2197 } 2216 }
2198 } 2217 }
2199 } 2218 }
2200 2219
2201 $f->resolve_delayed_derefs; 2220 $f->resolve_delayed_derefs;
2221 } else {
2222 $self->post_load_original
2223 if delete $self->{load_original};
2202 } 2224 }
2203 2225
2204 cf::cede_to_tick; 2226 cf::cede_to_tick;
2205 # now do the right thing for maps 2227 # now do the right thing for maps
2206 $self->link_multipart_objects; 2228 $self->link_multipart_objects;
2291our $MAP_PREFETCHER = undef; 2313our $MAP_PREFETCHER = undef;
2292 2314
2293sub find_async { 2315sub find_async {
2294 my ($path, $origin, $load) = @_; 2316 my ($path, $origin, $load) = @_;
2295 2317
2296 $path = normalise $path, $origin && $origin->{path}; 2318 $path = normalise $path, $origin;
2297 2319
2298 if (my $map = $cf::MAP{$path}) { 2320 if (my $map = $cf::MAP{$path}) {
2299 return $map if !$load || $map->in_memory == cf::MAP_ACTIVE; 2321 return $map if !$load || $map->in_memory == cf::MAP_ACTIVE;
2300 } 2322 }
2301 2323
2812 ($path, $x, $y) = (undef, undef, undef); 2834 ($path, $x, $y) = (undef, undef, undef);
2813 } 2835 }
2814 } 2836 }
2815 2837
2816 my $map = eval { 2838 my $map = eval {
2817 my $map = defined $path ? cf::map::find $path : undef; 2839 my $map = defined $path ? cf::map::find $path, $self->map : undef;
2818 2840
2819 if ($map) { 2841 if ($map) {
2820 $map = $map->customise_for ($self); 2842 $map = $map->customise_for ($self);
2821 $map = $check->($map, $x, $y, $self) if $check && $map; 2843 $map = $check->($map, $x, $y, $self) if $check && $map;
2822 } else { 2844 } else {
2920 2942
2921 prepare_random_map $exit 2943 prepare_random_map $exit
2922 if $exit->slaying eq "/!"; 2944 if $exit->slaying eq "/!";
2923 } 2945 }
2924 2946
2925 my $map = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; 2947 my $map = cf::map::normalise $exit->slaying, $exit->map;
2926 my $x = $exit->stats->hp; 2948 my $x = $exit->stats->hp;
2927 my $y = $exit->stats->sp; 2949 my $y = $exit->stats->sp;
2928 2950
2929 $self->goto ($map, $x, $y); 2951 $self->goto ($map, $x, $y);
2930 2952

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines