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.190 by root, Mon Jan 22 03:44:41 2007 UTC vs.
Revision 1.194 by root, Wed Jan 24 22:42:49 2007 UTC

8use Storable; 8use Storable;
9use Opcode; 9use Opcode;
10use Safe; 10use Safe;
11use Safe::Hole; 11use Safe::Hole;
12 12
13use Coro 3.4 (); 13use Coro 3.5 ();
14use Coro::Event; 14use Coro::Event;
15use Coro::Timer; 15use Coro::Timer;
16use Coro::Signal; 16use Coro::Signal;
17use Coro::Semaphore; 17use Coro::Semaphore;
18use Coro::AIO; 18use Coro::AIO;
1176} 1176}
1177 1177
1178sub normalise { 1178sub normalise {
1179 my ($path, $base) = @_; 1179 my ($path, $base) = @_;
1180 1180
1181 $path = "$path"; # make sure its a string
1182
1181 # map plan: 1183 # map plan:
1182 # 1184 #
1183 # /! non-realised random map exit (special hack!) 1185 # /! non-realised random map exit (special hack!)
1184 # {... are special paths that are not being touched 1186 # {... are special paths that are not being touched
1185 # ?xxx/... are special absolute paths 1187 # ?xxx/... are special absolute paths
1221 $self->init; # pass $1 etc. 1223 $self->init; # pass $1 etc.
1222 return $self; 1224 return $self;
1223 } 1225 }
1224 } 1226 }
1225 1227
1226 Carp::carp "unable to resolve path '$path'."; 1228 Carp::carp "unable to resolve path '$path' (base '$base').";
1227 () 1229 ()
1228} 1230}
1229 1231
1230sub init { 1232sub init {
1231 my ($self) = @_; 1233 my ($self) = @_;
1365 if ($map->should_reset) { 1367 if ($map->should_reset) {
1366 # doing this can freeze the server in a sync job, obviously 1368 # doing this can freeze the server in a sync job, obviously
1367 #$cf::WAIT_FOR_TICK->wait; 1369 #$cf::WAIT_FOR_TICK->wait;
1368 $map->reset; 1370 $map->reset;
1369 undef $guard; 1371 undef $guard;
1370 $map = find $path 1372 return find $path;
1371 or return;
1372 } 1373 }
1373 1374
1374 $cf::MAP{$path} = $map 1375 $cf::MAP{$path} = $map
1375 } 1376 }
1376} 1377}
1747 return if UNIVERSAL::isa $self->map, "ext::map_link"; 1748 return if UNIVERSAL::isa $self->map, "ext::map_link";
1748 1749
1749 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] 1750 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y]
1750 if $self->map; 1751 if $self->map;
1751 1752
1752 $self->enter_map ($LINK_MAP || link_map, 20, 20); 1753 $self->enter_map ($LINK_MAP || link_map, 10, 10);
1753} 1754}
1754 1755
1755sub cf::object::player::leave_link { 1756sub cf::object::player::leave_link {
1756 my ($self, $map, $x, $y) = @_; 1757 my ($self, $map, $x, $y) = @_;
1757 1758
2294 for my $signal (qw(INT HUP TERM)) { 2295 for my $signal (qw(INT HUP TERM)) {
2295 Event->signal ( 2296 Event->signal (
2296 reentrant => 0, 2297 reentrant => 0,
2297 data => WF_AUTOCANCEL, 2298 data => WF_AUTOCANCEL,
2298 signal => $signal, 2299 signal => $signal,
2300 prio => 0,
2299 cb => sub { 2301 cb => sub {
2300 cf::cleanup "SIG$signal"; 2302 cf::cleanup "SIG$signal";
2301 }, 2303 },
2302 ); 2304 );
2303 } 2305 }
2478my $bug_warning = 0; 2480my $bug_warning = 0;
2479 2481
2480$TICK_WATCHER = Event->timer ( 2482$TICK_WATCHER = Event->timer (
2481 reentrant => 0, 2483 reentrant => 0,
2482 parked => 1, 2484 parked => 1,
2483 prio => -1, 2485 prio => 0,
2484 at => $NEXT_TICK || $TICK, 2486 at => $NEXT_TICK || $TICK,
2485 data => WF_AUTOCANCEL, 2487 data => WF_AUTOCANCEL,
2486 cb => sub { 2488 cb => sub {
2487 if ($Coro::current != $Coro::main) { 2489 if ($Coro::current != $Coro::main) {
2488 Carp::cluck "major BUG: server tick called outside of main coro, skipping it" 2490 Carp::cluck "major BUG: server tick called outside of main coro, skipping it"
2497 $NEXT_TICK += $TICK; 2499 $NEXT_TICK += $TICK;
2498 2500
2499 $WAIT_FOR_TICK->broadcast; 2501 $WAIT_FOR_TICK->broadcast;
2500 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; 2502 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited;
2501 2503
2504 Event::sweep;
2505 Coro::cede_notself;
2506
2502 my $AFTER = Event::time; 2507# my $AFTER = Event::time;
2503 warn $AFTER - $NOW;#d# 2508# warn $AFTER - $NOW;#d#
2504 2509
2505 # if we are delayed by four ticks or more, skip them all 2510 # if we are delayed by four ticks or more, skip them all
2506 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4; 2511 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4;
2507 2512
2508 $TICK_WATCHER->at ($NEXT_TICK); 2513 $TICK_WATCHER->at ($NEXT_TICK);
2509 $TICK_WATCHER->start; 2514 $TICK_WATCHER->start;
2510 }, 2515 },
2511); 2516);
2512 2517
2513IO::AIO::max_poll_time $TICK * 0.2; 2518IO::AIO::max_poll_time $TICK * 0.1;
2514 2519
2515undef $Coro::AIO::WATCHER; 2520undef $Coro::AIO::WATCHER;
2516$AIO_POLL_WATCHER = Event->io ( 2521$AIO_POLL_WATCHER = Event->io (
2517 reentrant => 0, 2522 reentrant => 0,
2518 fd => IO::AIO::poll_fileno, 2523 fd => IO::AIO::poll_fileno,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines