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.569 by root, Wed May 4 07:36:40 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.
2069 $self->{load_path} = $path; 2069 $self->{load_path} = $path;
2070 2070
2071 1 2071 1
2072} 2072}
2073 2073
2074# used to laod the header of an original map
2074sub load_header_orig { 2075sub load_header_orig {
2075 my ($self) = @_; 2076 my ($self) = @_;
2076 2077
2077 $self->load_header_from ($self->load_path) 2078 $self->load_header_from ($self->load_path)
2078} 2079}
2079 2080
2081# used to laod the header of an instantiated map
2080sub load_header_temp { 2082sub load_header_temp {
2081 my ($self) = @_; 2083 my ($self) = @_;
2082 2084
2083 $self->load_header_from ($self->save_path) 2085 $self->load_header_from ($self->save_path)
2084} 2086}
2085 2087
2088# called after loading the header from an instantiated map
2086sub prepare_temp { 2089sub prepare_temp {
2087 my ($self) = @_; 2090 my ($self) = @_;
2088 2091
2089 $self->last_access ((delete $self->{last_access}) 2092 $self->last_access ((delete $self->{last_access})
2090 || $cf::RUNTIME); #d# 2093 || $cf::RUNTIME); #d#
2091 # safety 2094 # safety
2092 $self->{instantiate_time} = $cf::RUNTIME 2095 $self->{instantiate_time} = $cf::RUNTIME
2093 if $self->{instantiate_time} > $cf::RUNTIME; 2096 if $self->{instantiate_time} > $cf::RUNTIME;
2094} 2097}
2095 2098
2099# called after loading the header from an original map
2096sub prepare_orig { 2100sub prepare_orig {
2097 my ($self) = @_; 2101 my ($self) = @_;
2098 2102
2099 $self->{load_original} = 1; 2103 $self->{load_original} = 1;
2100 $self->{instantiate_time} = $cf::RUNTIME; 2104 $self->{instantiate_time} = $cf::RUNTIME;
2126sub find { 2130sub find {
2127 my ($path, $origin) = @_; 2131 my ($path, $origin) = @_;
2128 2132
2129 cf::cede_to_tick; 2133 cf::cede_to_tick;
2130 2134
2131 $path = normalise $path, $origin && $origin->path; 2135 $path = normalise $path, $origin;
2132 2136
2133 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove 2137 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove
2134 my $guard2 = cf::lock_acquire "map_find:$path"; 2138 my $guard2 = cf::lock_acquire "map_find:$path";
2135 2139
2136 $cf::MAP{$path} || do { 2140 $cf::MAP{$path} || do {
2168 { 2172 {
2169 my $guard = cf::lock_acquire "map_data:$path"; 2173 my $guard = cf::lock_acquire "map_data:$path";
2170 2174
2171 return unless $self->valid; 2175 return unless $self->valid;
2172 return unless $self->in_memory == cf::MAP_SWAPPED; 2176 return unless $self->in_memory == cf::MAP_SWAPPED;
2173
2174 $self->in_memory (cf::MAP_LOADING);
2175 2177
2176 $self->alloc; 2178 $self->alloc;
2177 2179
2178 $self->pre_load; 2180 $self->pre_load;
2179 cf::cede_to_tick; 2181 cf::cede_to_tick;
2197 } 2199 }
2198 } 2200 }
2199 } 2201 }
2200 2202
2201 $f->resolve_delayed_derefs; 2203 $f->resolve_delayed_derefs;
2204 } else {
2205 $self->post_load_original
2206 if delete $self->{load_original};
2202 } 2207 }
2208
2209 $self->in_memory (cf::MAP_INACTIVE);
2203 2210
2204 cf::cede_to_tick; 2211 cf::cede_to_tick;
2205 # now do the right thing for maps 2212 # now do the right thing for maps
2206 $self->link_multipart_objects; 2213 $self->link_multipart_objects;
2207 $self->difficulty ($self->estimate_difficulty) 2214 $self->difficulty ($self->estimate_difficulty)
2211 unless ($self->{deny_activate}) { 2218 unless ($self->{deny_activate}) {
2212 $self->decay_objects; 2219 $self->decay_objects;
2213 $self->fix_auto_apply; 2220 $self->fix_auto_apply;
2214 $self->update_buttons; 2221 $self->update_buttons;
2215 cf::cede_to_tick; 2222 cf::cede_to_tick;
2216 $self->activate; 2223 #$self->activate; # no longer activate maps automatically
2217 } 2224 }
2218 2225
2219 $self->{last_save} = $cf::RUNTIME; 2226 $self->{last_save} = $cf::RUNTIME;
2220 $self->last_access ($cf::RUNTIME); 2227 $self->last_access ($cf::RUNTIME);
2221
2222 $self->in_memory (cf::MAP_ACTIVE);
2223 } 2228 }
2224 2229
2225 $self->post_load; 2230 $self->post_load;
2226 2231
2227 1 2232 1
2270} 2275}
2271 2276
2272sub find_sync { 2277sub find_sync {
2273 my ($path, $origin) = @_; 2278 my ($path, $origin) = @_;
2274 2279
2280 # it's a bug to call this from the main context
2275 return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync" 2281 return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync"
2276 if $Coro::current == $Coro::main; 2282 if $Coro::current == $Coro::main;
2277 2283
2278 find $path, $origin 2284 find $path, $origin
2279} 2285}
2280 2286
2281sub do_load_sync { 2287sub do_load_sync {
2282 my ($map) = @_; 2288 my ($map) = @_;
2283 2289
2290 # it's a bug to call this from the main context
2284 return cf::LOG cf::llevError | cf::logBacktrace, "do_load_sync" 2291 return cf::LOG cf::llevError | cf::logBacktrace, "do_load_sync"
2285 if $Coro::current == $Coro::main; 2292 if $Coro::current == $Coro::main;
2286 2293
2287 $map->load; 2294 $map->load;
2288} 2295}
2291our $MAP_PREFETCHER = undef; 2298our $MAP_PREFETCHER = undef;
2292 2299
2293sub find_async { 2300sub find_async {
2294 my ($path, $origin, $load) = @_; 2301 my ($path, $origin, $load) = @_;
2295 2302
2296 $path = normalise $path, $origin && $origin->{path}; 2303 $path = normalise $path, $origin;
2297 2304
2298 if (my $map = $cf::MAP{$path}) { 2305 if (my $map = $cf::MAP{$path}) {
2299 return $map if !$load || $map->in_memory == cf::MAP_ACTIVE; 2306 return $map if !$load || $map->linkable;
2300 } 2307 }
2301 2308
2302 $MAP_PREFETCH{$path} |= $load; 2309 $MAP_PREFETCH{$path} |= $load;
2303 2310
2304 $MAP_PREFETCHER ||= cf::async { 2311 $MAP_PREFETCHER ||= cf::async {
2363sub swap_out { 2370sub swap_out {
2364 my ($self) = @_; 2371 my ($self) = @_;
2365 2372
2366 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2373 my $lock = cf::lock_acquire "map_data:$self->{path}";
2367 2374
2368 return if $self->in_memory != cf::MAP_ACTIVE; 2375 return if !$self->linkable;
2369 return if $self->{deny_save}; 2376 return if $self->{deny_save};
2370 return if $self->players; 2377 return if $self->players;
2371 2378
2372 # first deactivate the map and "unlink" it from the core 2379 # first deactivate the map and "unlink" it from the core
2373 $self->deactivate; 2380 $self->deactivate;
2812 ($path, $x, $y) = (undef, undef, undef); 2819 ($path, $x, $y) = (undef, undef, undef);
2813 } 2820 }
2814 } 2821 }
2815 2822
2816 my $map = eval { 2823 my $map = eval {
2817 my $map = defined $path ? cf::map::find $path : undef; 2824 my $map = defined $path ? cf::map::find $path, $self->map : undef;
2818 2825
2819 if ($map) { 2826 if ($map) {
2820 $map = $map->customise_for ($self); 2827 $map = $map->customise_for ($self);
2821 $map = $check->($map, $x, $y, $self) if $check && $map; 2828 $map = $check->($map, $x, $y, $self) if $check && $map;
2822 } else { 2829 } else {
2912 $Coro::current->{desc} = "enter_exit"; 2919 $Coro::current->{desc} = "enter_exit";
2913 2920
2914 unless (eval { 2921 unless (eval {
2915 $self->deactivate_recursive; # just to be sure 2922 $self->deactivate_recursive; # just to be sure
2916 2923
2917 # random map handling
2918 {
2919 my $guard = cf::lock_acquire "exit_prepare:$exit";
2920
2921 prepare_random_map $exit
2922 if $exit->slaying eq "/!";
2923 }
2924
2925 my $map = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; 2924 my $map = cf::map::normalise $exit->slaying, $exit->map;
2926 my $x = $exit->stats->hp; 2925 my $x = $exit->stats->hp;
2927 my $y = $exit->stats->sp; 2926 my $y = $exit->stats->sp;
2927
2928 # special map handling
2929 my $slaying = $exit->slaying;
2930
2931 # special map handling
2932 if ($slaying eq "/!") {
2933 my $guard = cf::lock_acquire "exit_prepare:$exit";
2934
2935 prepare_random_map $exit
2936 if $exit->slaying eq "/!"; # need to re-check after getting the lock
2937
2938 $map = $exit->slaying;
2939
2940 } elsif ($slaying eq '!up') {
2941 $map = $exit->map->tile_path (cf::TILE_UP);
2942 $x = $exit->x;
2943 $y = $exit->y;
2944
2945 } elsif ($slaying eq '!down') {
2946 $map = $exit->map->tile_path (cf::TILE_DOWN);
2947 $x = $exit->x;
2948 $y = $exit->y;
2949 }
2928 2950
2929 $self->goto ($map, $x, $y); 2951 $self->goto ($map, $x, $y);
2930 2952
2931 # if exit is damned, update players death & WoR home-position 2953 # if exit is damned, update players death & WoR home-position
2932 $self->contr->savebed ($map, $x, $y) 2954 $self->contr->savebed ($map, $x, $y)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines