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.139 by root, Fri Jan 5 19:12:03 2007 UTC vs.
Revision 1.140 by root, Fri Jan 5 20:04:02 2007 UTC

229 my $guard = Coro::guard { $TICK_WATCHER->start }; 229 my $guard = Coro::guard { $TICK_WATCHER->start };
230 $TICK_WATCHER->stop; 230 $TICK_WATCHER->stop;
231 $guard 231 $guard
232} 232}
233 233
234=item cf::async { BLOCK }
235
236Currently the same as Coro::async_pool, meaning you cannot use
237C<on_destroy>, C<join> or other gimmicks on these coroutines. The only
238thing you are allowed to do is call C<prio> on it.
239
240=cut
241
242BEGIN { *async = \&Coro::async_pool }
243
234=item cf::sync_job { BLOCK } 244=item cf::sync_job { BLOCK }
235 245
236The design of crossfire+ requires that the main coro ($Coro::main) is 246The design of crossfire+ requires that the main coro ($Coro::main) is
237always able to handle events or runnable, as crossfire+ is only partly 247always able to handle events or runnable, as crossfire+ is only partly
238reentrant. Thus "blocking" it by e.g. waiting for I/O is not acceptable. 248reentrant. Thus "blocking" it by e.g. waiting for I/O is not acceptable.
256 my $freeze_guard = freeze_mainloop; 266 my $freeze_guard = freeze_mainloop;
257 267
258 my $busy = 1; 268 my $busy = 1;
259 my @res; 269 my @res;
260 270
261 (Coro::async_pool { 271 (async {
262 @res = eval { $job->() }; 272 @res = eval { $job->() };
263 warn $@ if $@; 273 warn $@ if $@;
264 undef $busy; 274 undef $busy;
265 })->prio (Coro::PRIO_MAX); 275 })->prio (Coro::PRIO_MAX);
266 276
277 287
278 $job->() 288 $job->()
279 } 289 }
280} 290}
281 291
282=item $coro = cf::coro { BLOCK } 292=item $coro = cf::async_ext { BLOCK }
283 293
284Creates (and readies) and returns a new coro. This coro is automcatially 294Like async, but this coro is automcatially being canceled when the
285being canceled when the extension calling this is being unloaded. 295extension calling this is being unloaded.
286 296
287=cut 297=cut
288 298
289sub coro(&) { 299sub async_ext(&) {
290 my $cb = shift; 300 my $cb = shift;
291 301
292 my $coro = &Coro::async_pool ($cb); 302 my $coro = &Coro::async ($cb);
293 303
294 $coro->on_destroy (sub { 304 $coro->on_destroy (sub {
295 delete $EXT_CORO{$coro+0}; 305 delete $EXT_CORO{$coro+0};
296 }); 306 });
297 $EXT_CORO{$coro+0} = $coro; 307 $EXT_CORO{$coro+0} = $coro;
1270} 1280}
1271 1281
1272sub find_sync { 1282sub find_sync {
1273 my ($path, $origin) = @_; 1283 my ($path, $origin) = @_;
1274 1284
1275 cf::sync_job { 1285 cf::sync_job { cf::map::find $path, $origin }
1276 my $map = cf::map::find $path, $origin;
1277 $map
1278 }
1279} 1286}
1280 1287
1281sub do_load_sync { 1288sub do_load_sync {
1282 my ($map) = @_; 1289 my ($map) = @_;
1283 1290
1545 # try to abort aborted map switching on player login :) 1552 # try to abort aborted map switching on player login :)
1546 # should happen only on crashes 1553 # should happen only on crashes
1547 if ($pl->ob->{_link_pos}) { 1554 if ($pl->ob->{_link_pos}) {
1548 1555
1549 $pl->ob->enter_link; 1556 $pl->ob->enter_link;
1550 (Coro::async_pool { 1557 (async {
1551 # we need this sleep as the login has a concurrent enter_exit running 1558 # we need this sleep as the login has a concurrent enter_exit running
1552 # and this sleep increases chances of the player not ending up in scorn 1559 # and this sleep increases chances of the player not ending up in scorn
1560 $pl->ob->reply (undef,
1561 "There was an internal problem at your last logout, "
1562 . "the server will try to bring you to your intended destination in a second.",
1563 cf::NDI_RED);
1553 Coro::Timer::sleep 1; 1564 Coro::Timer::sleep 1;
1554 $pl->ob->leave_link; 1565 $pl->ob->leave_link;
1555 })->prio (2); 1566 })->prio (2);
1556 } 1567 }
1557 }, 1568 },
1564sub cf::object::player::goto { 1575sub cf::object::player::goto {
1565 my ($self, $path, $x, $y) = @_; 1576 my ($self, $path, $x, $y) = @_;
1566 1577
1567 $self->enter_link; 1578 $self->enter_link;
1568 1579
1569 (Coro::async_pool { 1580 (async {
1570 $path = new cf::path $path; 1581 $path = new cf::path $path;
1571 1582
1572 my $map = cf::map::find $path->as_string; 1583 my $map = cf::map::find $path->as_string;
1573 $map = $map->customise_for ($self) if $map; 1584 $map = $map->customise_for ($self) if $map;
1574 1585
1636 1647
1637 return unless $self->type == cf::PLAYER; 1648 return unless $self->type == cf::PLAYER;
1638 1649
1639 $self->enter_link; 1650 $self->enter_link;
1640 1651
1641 (Coro::async_pool { 1652 (async {
1642 $self->deactivate_recursive; # just to be sure 1653 $self->deactivate_recursive; # just to be sure
1643 unless (eval { 1654 unless (eval {
1644 prepare_random_map $exit 1655 prepare_random_map $exit
1645 if $exit->slaying eq "/!"; 1656 if $exit->slaying eq "/!";
1646 1657
1727 } 1738 }
1728 } 1739 }
1729 }, 1740 },
1730); 1741);
1731 1742
1732=item $client->coro (\&cb) 1743=item $client->async (\&cb)
1733 1744
1734Create a new coroutine, running the specified callback. The coroutine will 1745Create a new coroutine, running the specified callback. The coroutine will
1735be automatically cancelled when the client gets destroyed (e.g. on logout, 1746be automatically cancelled when the client gets destroyed (e.g. on logout,
1736or loss of connection). 1747or loss of connection).
1737 1748
1738=cut 1749=cut
1739 1750
1740sub cf::client::coro { 1751sub cf::client::async {
1741 my ($self, $cb) = @_; 1752 my ($self, $cb) = @_;
1742 1753
1743 my $coro = &Coro::async_pool ($cb); 1754 my $coro = &Coro::async ($cb);
1744 1755
1745 $coro->on_destroy (sub { 1756 $coro->on_destroy (sub {
1746 delete $self->{_coro}{$coro+0}; 1757 delete $self->{_coro}{$coro+0};
1747 }); 1758 });
1748 1759
2002 2013
2003sub main { 2014sub main {
2004 # we must not ever block the main coroutine 2015 # we must not ever block the main coroutine
2005 local $Coro::idle = sub { 2016 local $Coro::idle = sub {
2006 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 2017 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
2007 Coro::async_pool { Event::one_event }; 2018 async { Event::one_event };
2008 }; 2019 };
2009 2020
2010 cfg_load; 2021 cfg_load;
2011 db_load; 2022 db_load;
2012 load_extensions; 2023 load_extensions;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines