ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/00_map_handling.ext
(Generate patch)

Comparing deliantra/server/ext/00_map_handling.ext (file contents):
Revision 1.2 by root, Sat Dec 30 12:38:18 2006 UTC vs.
Revision 1.3 by root, Sat Dec 30 15:07:59 2006 UTC

192 while (!$done) { 192 while (!$done) {
193 Coro::cede_notself; 193 Coro::cede_notself;
194 Event::one_event unless Coro::nready; 194 Event::one_event unless Coro::nready;
195 } 195 }
196 196
197 warn "job done<@res>\n";#d#
198
199 wantarray ? @res : $res[0] 197 wantarray ? @res : $res[0]
200} 198}
201 199
202# and all this just because we cannot iterate over 200# and all this just because we cannot iterate over
203# all maps in C++... 201# all maps in C++...
222 220
223 $map->reset_time (0) if $map->reset_time > $cf::RUNTIME; 221 $map->reset_time (0) if $map->reset_time > $cf::RUNTIME;
224 $map->reset_timeout (10);#d# 222 $map->reset_timeout (10);#d#
225 223
226 $map->{load_path} = $path; 224 $map->{load_path} = $path;
227 warn "load header from $path\n";#d#
228 225
229 $map 226 $map
230} 227}
231 228
232sub cf::map::find_map_nb { 229sub cf::map::find_map_nb {
233 my ($path, $origin) = @_; 230 my ($path, $origin) = @_;
234 231
232 warn "find_map_nb<$path,$origin>\n";#d#
233
235 $path = ref $path ? $path : new cf::path $path, $origin && $origin->path; 234 $path = ref $path ? $path : new cf::path $path, $origin && $origin->path;
236 my $key = $path->as_string; 235 my $key = $path->as_string;
237
238 warn "find_map_nb<$path,$origin>\n";#d#
239 236
240 $cf::MAP{$key} || do { 237 $cf::MAP{$key} || do {
241 # do it the slow way 238 # do it the slow way
242 my $map = try_load_header $path->save_path; 239 my $map = try_load_header $path->save_path;
243 240
249 $map or return; 246 $map or return;
250 247
251 $map->instantiate; 248 $map->instantiate;
252 $map->path ($key); 249 $map->path ($key);
253 $map->{path} = $path; 250 $map->{path} = $path;
251
252 $map->per_player (0) if $path->{user_rel};
254 253
255 $map->reset if $map->should_reset; 254 $map->reset if $map->should_reset;
256 255
257 $cf::MAP{$key} = $map 256 $cf::MAP{$key} = $map
258 } 257 }
334} 333}
335 334
336sub cf::map::swap_out { 335sub cf::map::swap_out {
337 my ($self) = @_; 336 my ($self) = @_;
338 337
339 $self->save; 338 $self->save if $self->in_memory == cf::MAP_IN_MEMORY;
340 $self->clear; 339 $self->clear;
341 $self->in_memory (cf::MAP_SWAPPED); 340 $self->in_memory (cf::MAP_SWAPPED);
342} 341}
343 342
344sub cf::map::should_reset { 343sub cf::map::should_reset {
356 355
357sub cf::map::reset { 356sub cf::map::reset {
358 my ($self) = @_; 357 my ($self) = @_;
359 358
360 return if $self->players; 359 return if $self->players;
360 return if $self->{path}{user_rel};#d#
361 361
362 warn "resetting map ", $self->path;#d# 362 warn "resetting map ", $self->path;#d#
363 return;#d# 363
364 utf8::encode (my $save = $self->{path}->save_path);
365 aioreq_pri 3; IO::AIO::aio_unlink $save;
366 aioreq_pri 3; IO::AIO::aio_unlink "$save.pst";
364 367
365 $self->clear; 368 $self->clear;
366 $self->in_memory (cf::MAP_SWAPPED); 369 $self->in_memory (cf::MAP_SWAPPED);
367 $self->{load_path} = $self->{path}->load_path; 370 utf8::encode ($self->{load_path} = $self->{path}->load_path);
368 utf8::encode $self->{load_path};
369} 371}
370 372
371sub cf::object::player::enter_exit { 373sub cf::object::player::enter_exit {
372 my ($ob, $exit) = @_; 374 my ($ob, $exit) = @_;
373 375
374 warn "enter_exit\n";#d#
375 sync_job { 376 sync_job {
376 warn "enter_exit<$ob,$exit>\n";#d# 377 my ($map, $x, $y);
377 378
378 if ($exit) { 379 if ($exit) {
379 my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path; 380 my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path;
380 381
381 my $map = cf::map::find_map_nb $path->as_string; 382 $map = cf::map::find_map_nb $path->as_string;
382 $map = $map->customise_for ($ob) if $map; 383 $map = $map->customise_for ($ob) if $map;
383
384 if ($map) {
385 $map->do_load_nb;
386 $ob->enter_map ($map, $exit->stats->hp, $exit->stats->sp); 384 ($x, $y) = ($exit->stats->hp, $exit->stats->sp);
387 } else {
388 $ob->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED);
389 }
390 } else { 385 } else {
391 # used on login only(?) 386 # used on login only(?)
392 my $map = cf::map::find_map_nb $ob->contr->maplevel; 387 $map = cf::map::find_map_nb $ob->contr->maplevel;
393 my ($x, $y) = ($ob->x, $ob->y); 388 ($x, $y) = ($ob->x, $ob->y);
394 389
395 unless ($map) { 390 unless ($map) {
396 $map = cf::map::find_map_nb $emergency_position->[0] 391 $map = cf::map::find_map_nb $emergency_position->[0]
397 or die "FATAL: cannot load emergency map\n"; 392 or die "FATAL: cannot load emergency map\n";
398 $x = $emergency_position->[1]; 393 $x = $emergency_position->[1];
399 $y = $emergency_position->[2]; 394 $y = $emergency_position->[2];
400 } 395 }
396 }
401 397
398 if ($map) {
399 warn "entering ", $map->path, " at ($x, $y)\n";#d#
402 $map->do_load_nb; 400 $map->do_load_nb;
403 $ob->enter_map ($map, $x, $y); 401 $ob->enter_map ($map, $x, $y);
402 } else {
403 $ob->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED);
404 } 404 }
405 } 405 }
406} 406}
407 407
408sub cf::map::customise_for { 408sub cf::map::customise_for {
409 my ($map, $ob) = @_; 409 my ($map, $ob) = @_;
410
411 warn "customise_for<$map,$ob>\n";#d#
412 410
413 if ($map->per_player) { 411 if ($map->per_player) {
414 return cf::map::find_map_nb "~" . $ob->name . "/" . $map->{path}{path}; 412 return cf::map::find_map_nb "~" . $ob->name . "/" . $map->{path}{path};
415 } 413 }
416 414

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines