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.32 by root, Tue Aug 15 18:07:25 2006 UTC vs.
Revision 1.35 by root, Thu Aug 24 13:35:48 2006 UTC

16our %COMMAND; 16our %COMMAND;
17our @EVENT; 17our @EVENT;
18our %PROP_TYPE; 18our %PROP_TYPE;
19our %PROP_IDX; 19our %PROP_IDX;
20our $LIBDIR = maps_directory "perl"; 20our $LIBDIR = maps_directory "perl";
21
22our $TICK = MAX_TIME * 1e-6;
23our $TICK_WATCHER;
24our $NEXT_TICK;
21 25
22BEGIN { 26BEGIN {
23 @EVENT = map lc, @EVENT; 27 @EVENT = map lc, @EVENT;
24 28
25 *CORE::GLOBAL::warn = sub { 29 *CORE::GLOBAL::warn = sub {
385}; 389};
386 390
387############################################################################# 391#############################################################################
388# load/save perl data associated with player->ob objects 392# load/save perl data associated with player->ob objects
389 393
394sub all_objects(@) {
395 @_, map all_objects ($_->inv), @_
396}
397
390*on_player_load = sub { 398*on_player_load = sub {
391 my ($ob, $path) = @_; 399 my ($ob, $path) = @_;
392 400
393 for my $o ($ob, $ob->inv) { 401 for my $o (all_objects $ob) {
394 if (my $value = $o->get_ob_key_value ("_perl_data")) { 402 if (my $value = $o->get_ob_key_value ("_perl_data")) {
395 $o->set_ob_key_value ("_perl_data"); 403 $o->set_ob_key_value ("_perl_data");
396 404
397 %$o = %{ Storable::thaw pack "H*", $value }; 405 %$o = %{ Storable::thaw pack "H*", $value };
398 } 406 }
401 409
402*on_player_save = sub { 410*on_player_save = sub {
403 my ($ob, $path) = @_; 411 my ($ob, $path) = @_;
404 412
405 $_->set_ob_key_value (_perl_data => unpack "H*", Storable::nfreeze $_) 413 $_->set_ob_key_value (_perl_data => unpack "H*", Storable::nfreeze $_)
406 for grep %$_, $ob, $ob->inv; 414 for grep %$_, all_objects $ob;
407}; 415};
408 416
409############################################################################# 417#############################################################################
410# core extensions - in perl 418# core extensions - in perl
411
412my $delta_timer = Event->timer (
413 parked => 1,
414 prio => Event::PRIO_HIGH,
415 cb => sub { Event::unloop (undef) },
416);
417
418sub sleep_delta($) {
419 $delta_timer->at (Event::time + $_[0]);
420 $delta_timer->start;
421 Event::loop;
422}
423 419
424=item cf::player::exists $login 420=item cf::player::exists $login
425 421
426Returns true when the given account exists. 422Returns true when the given account exists.
427 423
523 no strict 'refs'; 519 no strict 'refs';
524 *{"ext::$fun"} = $safe_hole->wrap ($cb); 520 *{"ext::$fun"} = $safe_hole->wrap ($cb);
525} 521}
526 522
527############################################################################# 523#############################################################################
524# the server's main()
525
526sub run {
527 Event::loop;
528}
529
530#############################################################################
528# initialisation 531# initialisation
529 532
530register "<global>", __PACKAGE__; 533register "<global>", __PACKAGE__;
531 534
532unshift @INC, $LIBDIR; 535unshift @INC, $LIBDIR;
533 536
534load_extensions; 537load_extensions;
535 538
539$TICK_WATCHER = Event->timer (
540 prio => 1,
541 at => $NEXT_TICK || 1,
542 cb => sub {
543 cf::server_tick; # one server iteration
544
545 my $NOW = Event::time;
546 $NEXT_TICK += $TICK;
547
548 # if we are delayed by > 0.25 second, skip ticks
549 $NEXT_TICK = $NOW if $NOW >= $NEXT_TICK + .25;
550
551 $TICK_WATCHER->at ($NEXT_TICK);
552 $TICK_WATCHER->start;
553 },
554);
555
5361 5561
537 557

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines