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.238 by root, Sat Apr 14 07:23:00 2007 UTC vs.
Revision 1.242 by root, Mon Apr 16 12:37:08 2007 UTC

76our %MAP; # all maps 76our %MAP; # all maps
77our $LINK_MAP; # the special {link} map, which is always available 77our $LINK_MAP; # the special {link} map, which is always available
78our $RANDOM_MAPS = cf::localdir . "/random"; 78our $RANDOM_MAPS = cf::localdir . "/random";
79our $BDB_ENV_DIR = cf::localdir . "/db"; 79our $BDB_ENV_DIR = cf::localdir . "/db";
80 80
81our $WAIT_FOR_TICK; $WAIT_FOR_TICK ||= new Coro::Signal;
82our $WAIT_FOR_TICK_ONE; $WAIT_FOR_TICK_ONE ||= new Coro::Signal;
83
84# used to convert map paths into valid unix filenames by replacing / by ∕ 81# used to convert map paths into valid unix filenames by replacing / by ∕
85our $PATH_SEP = "∕"; # U+2215, chosen purely for visual reasons 82our $PATH_SEP = "∕"; # U+2215, chosen purely for visual reasons
86 83
87binmode STDOUT; 84binmode STDOUT;
88binmode STDERR; 85binmode STDERR;
136=item %cf::CFG 133=item %cf::CFG
137 134
138Configuration for the server, loaded from C</etc/crossfire/config>, or 135Configuration for the server, loaded from C</etc/crossfire/config>, or
139from wherever your confdir points to. 136from wherever your confdir points to.
140 137
141=item $cf::WAIT_FOR_TICK, $cf::WAIT_FOR_TICK_ONE 138=item cf::wait_for_tick, cf::wait_for_tick_begin
142 139
143These are Coro::Signal objects that are C<< ->broadcast >> (WAIT_FOR_TICK) 140These are functions that inhibit the current coroutine one tick. cf::wait_for_tick_begin only
144or C<< ->send >> (WAIT_FOR_TICK_ONE) on after normal server tick 141returns directly I<after> the tick processing (and consequently, can only wake one process
145processing has been done. Call C<< ->wait >> on them to maximise the 142per tick), while cf::wait_for_tick wakes up all waiters after tick processing.
146window of cpu time available, or simply to synchronise to the server tick.
147 143
148=back 144=back
149 145
150=cut 146=cut
151 147
1483 $self->in_memory (cf::MAP_LOADING); 1479 $self->in_memory (cf::MAP_LOADING);
1484 1480
1485 $self->alloc; 1481 $self->alloc;
1486 1482
1487 $self->pre_load; 1483 $self->pre_load;
1484 Coro::cede;
1488 1485
1489 $self->_load_objects ($self->{load_path}, 1) 1486 $self->_load_objects ($self->{load_path}, 1)
1490 or return; 1487 or return;
1491 1488
1492 $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) 1489 $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1)
1499 $self->_load_objects ($uniq, 0); 1496 $self->_load_objects ($uniq, 0);
1500 } 1497 }
1501 } 1498 }
1502 1499
1503 Coro::cede; 1500 Coro::cede;
1504
1505 # now do the right thing for maps 1501 # now do the right thing for maps
1506 $self->link_multipart_objects; 1502 $self->link_multipart_objects;
1503 Coro::cede;
1507 1504
1508 unless ($self->{deny_activate}) { 1505 unless ($self->{deny_activate}) {
1509 $self->decay_objects; 1506 $self->decay_objects;
1510 $self->fix_auto_apply; 1507 $self->fix_auto_apply;
1511 $self->update_buttons; 1508 $self->update_buttons;
1513 $self->set_darkness_map; 1510 $self->set_darkness_map;
1514 $self->difficulty ($self->estimate_difficulty) 1511 $self->difficulty ($self->estimate_difficulty)
1515 unless $self->difficulty; 1512 unless $self->difficulty;
1516 Coro::cede; 1513 Coro::cede;
1517 $self->activate; 1514 $self->activate;
1515 Coro::cede;
1518 } 1516 }
1519 1517
1520 $self->post_load; 1518 $self->post_load;
1519 Coro::cede;
1521 1520
1522 $self->in_memory (cf::MAP_IN_MEMORY); 1521 $self->in_memory (cf::MAP_IN_MEMORY);
1523} 1522}
1524 1523
1525sub customise_for { 1524sub customise_for {
2385 } 2384 }
2386 2385
2387 1 2386 1
2388} 2387}
2389 2388
2389our $archetypes_loaded;
2390
2391sub load_archetypes {
2392 return 1 if $archetypes_loaded++; # current can only load them once
2393# load_archetype_file sprintf "%s/archetypes", cf::datadir;
2394 load_archetype_file sprintf "%s/archetypes", cf::datadir
2395}
2396
2397sub load_treasures {
2398 load_treasure_file sprintf "%s/treasures", cf::datadir
2399}
2400
2390sub reload_resources { 2401sub reload_resources {
2391 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir 2402 load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir
2392 or die "unable to load regions file\n";#d# 2403 or die "unable to load regions file\n";
2393 load_facedata 2404 load_facedata
2394 or die "unable to load facedata\n";#d# 2405 or die "unable to load facedata\n";
2406 load_archetypes
2407 or die "unable to load archetypes\n";
2408 load_treasures
2409 or die "unable to load treasurelists\n";
2395} 2410}
2396 2411
2397sub init { 2412sub init {
2398 reload_resources; 2413 reload_resources;
2399} 2414}
2643 2658
2644unshift @INC, $LIBDIR; 2659unshift @INC, $LIBDIR;
2645 2660
2646my $bug_warning = 0; 2661my $bug_warning = 0;
2647 2662
2663our @WAIT_FOR_TICK;
2664our @WAIT_FOR_TICK_BEGIN;
2665
2666sub wait_for_tick {
2667 return unless $TICK_WATCHER->is_active;
2668 return if $Coro::current == $Coro::main;
2669
2670 my $signal = new Coro::Signal;
2671 push @WAIT_FOR_TICK, $signal;
2672 $signal->wait;
2673}
2674
2675sub wait_for_tick_begin {
2676 return unless $TICK_WATCHER->is_active;
2677 return if $Coro::current == $Coro::main;
2678
2679 my $signal = new Coro::Signal;
2680 push @WAIT_FOR_TICK_BEGIN, $signal;
2681 $signal->wait;
2682}
2683
2648$TICK_WATCHER = Event->timer ( 2684$TICK_WATCHER = Event->timer (
2649 reentrant => 0, 2685 reentrant => 0,
2650 parked => 1, 2686 parked => 1,
2651 prio => 0, 2687 prio => 0,
2652 at => $NEXT_TICK || $TICK, 2688 at => $NEXT_TICK || $TICK,
2670 write_runtime 2706 write_runtime
2671 or warn "ERROR: unable to write runtime file: $!"; 2707 or warn "ERROR: unable to write runtime file: $!";
2672 }; 2708 };
2673 } 2709 }
2674 2710
2675 $WAIT_FOR_TICK->broadcast; 2711 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) {
2676 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; 2712 $sig->send;
2713 }
2714 while (my $sig = shift @WAIT_FOR_TICK) {
2715 $sig->send;
2716 }
2677 2717
2678# my $AFTER = Event::time; 2718# my $AFTER = Event::time;
2679# warn $AFTER - $NOW;#d# 2719# warn $AFTER - $NOW;#d#
2680 2720
2681 # if we are delayed by four ticks or more, skip them all 2721 # if we are delayed by four ticks or more, skip them all

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines