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.581 by root, Fri Feb 3 02:04:11 2012 UTC vs.
Revision 1.597 by root, Sun Nov 11 02:14:37 2012 UTC

1# 1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG. 2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3# 3#
4# Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4# Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 5#
6# Deliantra is free software: you can redistribute it and/or modify it under 6# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the 7# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your 8# Free Software Foundation, either version 3 of the License, or (at your
9# option) any later version. 9# option) any later version.
10# 10#
11# This program is distributed in the hope that it will be useful, 11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details. 14# GNU General Public License for more details.
15# 15#
16# You should have received a copy of the Affero GNU General Public License 16# You should have received a copy of the Affero GNU General Public License
17# and the GNU General Public License along with this program. If not, see 17# and the GNU General Public License along with this program. If not, see
18# <http://www.gnu.org/licenses/>. 18# <http://www.gnu.org/licenses/>.
19# 19#
20# The authors can be reached via e-mail to <support@deliantra.net> 20# The authors can be reached via e-mail to <support@deliantra.net>
21# 21#
22 22
23package cf; 23package cf;
24 24
32use Safe; 32use Safe;
33use Safe::Hole; 33use Safe::Hole;
34use Storable (); 34use Storable ();
35use Carp (); 35use Carp ();
36 36
37use Guard (); 37use AnyEvent ();
38use AnyEvent::IO ();
39use AnyEvent::DNS ();
40
38use Coro (); 41use Coro ();
39use Coro::State; 42use Coro::State;
40use Coro::Handle; 43use Coro::Handle;
41use Coro::EV; 44use Coro::EV;
42use Coro::AnyEvent; 45use Coro::AnyEvent;
48use Coro::AIO; 51use Coro::AIO;
49use Coro::BDB 1.6; 52use Coro::BDB 1.6;
50use Coro::Storable; 53use Coro::Storable;
51use Coro::Util (); 54use Coro::Util ();
52 55
56use Guard ();
53use JSON::XS 2.01 (); 57use JSON::XS 2.01 ();
54use BDB (); 58use BDB ();
55use Data::Dumper; 59use Data::Dumper;
56use Fcntl; 60use Fcntl;
57use YAML::XS (); 61use YAML::XS ();
83our %COMMAND = (); 87our %COMMAND = ();
84our %COMMAND_TIME = (); 88our %COMMAND_TIME = ();
85 89
86our @EXTS = (); # list of extension package names 90our @EXTS = (); # list of extension package names
87our %EXTCMD = (); 91our %EXTCMD = ();
92our %EXTACMD = ();
88our %EXTICMD = (); 93our %EXTICMD = ();
94our %EXTIACMD = ();
89our %EXT_CORO = (); # coroutines bound to extensions 95our %EXT_CORO = (); # coroutines bound to extensions
90our %EXT_MAP = (); # pluggable maps 96our %EXT_MAP = (); # pluggable maps
91 97
92our $RELOAD; # number of reloads so far, non-zero while in reload 98our $RELOAD; # number of reloads so far, non-zero while in reload
93our @EVENT; 99our @EVENT;
129our $DB_ENV; 135our $DB_ENV;
130 136
131our @EXTRA_MODULES = qw(pod match mapscript incloader); 137our @EXTRA_MODULES = qw(pod match mapscript incloader);
132 138
133our %CFG; 139our %CFG;
140our %EXT_CFG; # cfgkeyname => [var-ref, defaultvalue]
134 141
135our $UPTIME; $UPTIME ||= time; 142our $UPTIME; $UPTIME ||= time;
136our $RUNTIME = 0; 143our $RUNTIME = 0;
137our $SERVER_TICK = 0; 144our $SERVER_TICK = 0;
138our $NOW; 145our $NOW;
219=item $cf::RUNTIME 226=item $cf::RUNTIME
220 227
221The time this server has run, starts at 0 and is increased by $cf::TICK on 228The time this server has run, starts at 0 and is increased by $cf::TICK on
222every server tick. 229every server tick.
223 230
224=item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR 231=item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR
225$cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR 232$cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR
226$cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR 233$cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR
227 234
228Various directories - "/etc", read-only install directory, perl-library 235Various directories - "/etc", read-only install directory, perl-library
229directory, pod-directory, read-only maps directory, "/var", "/var/tmp", 236directory, pod-directory, read-only maps directory, "/var", "/var/tmp",
230unique-items directory, player file directory, random maps directory and 237unique-items directory, player file directory, random maps directory and
231database environment. 238database environment.
335)) { 342)) {
336 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 343 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
337} 344}
338 345
339$EV::DIED = sub { 346$EV::DIED = sub {
340 Carp::cluck "error in event callback: @_"; 347 warn "error in event callback: $@";
341}; 348};
342 349
343############################################################################# 350#############################################################################
344 351
345sub fork_call(&@); 352sub fork_call(&@);
1426=cut 1433=cut
1427 1434
1428############################################################################# 1435#############################################################################
1429# command handling &c 1436# command handling &c
1430 1437
1431=item cf::register_command $name => \&callback($ob,$args); 1438=item cf::register_command $name => \&callback($ob,$args)
1432 1439
1433Register a callback for execution when the client sends the user command 1440Register a callback for execution when the client sends the user command
1434$name. 1441$name.
1435 1442
1436=cut 1443=cut
1442 #warn "registering command '$name/$time' to '$caller'"; 1449 #warn "registering command '$name/$time' to '$caller'";
1443 1450
1444 push @{ $COMMAND{$name} }, [$caller, $cb]; 1451 push @{ $COMMAND{$name} }, [$caller, $cb];
1445} 1452}
1446 1453
1447=item cf::register_extcmd $name => \&callback($pl,$packet); 1454=item cf::register_extcmd $name => \&callback($pl,@args)
1448 1455
1449Register a callback for execution when the client sends an (synchronous) 1456Register a callback for execution when the client sends an (synchronous)
1450extcmd packet. Ext commands will be processed in the order they are 1457extcmd packet. Ext commands will be processed in the order they are
1451received by the server, like other user commands. The first argument is 1458received by the server, like other user commands. The first argument is
1452the logged-in player. Ext commands can only be processed after a player 1459the logged-in player. Ext commands can only be processed after a player
1453has logged in successfully. 1460has logged in successfully.
1454 1461
1455If the callback returns something, it is sent back as if reply was being 1462The values will be sent back to the client.
1456called.
1457 1463
1464=item cf::register_async_extcmd $name => \&callback($pl,$reply->(...),@args)
1465
1466Same as C<cf::register_extcmd>, but instead of returning values, the
1467callback needs to clal the C<$reply> function.
1468
1458=item cf::register_exticmd $name => \&callback($ns,$packet); 1469=item cf::register_exticmd $name => \&callback($ns,@args)
1459 1470
1460Register a callback for execution when the client sends an (asynchronous) 1471Register a callback for execution when the client sends an (asynchronous)
1461exticmd packet. Exti commands are processed by the server as soon as they 1472exticmd packet. Exti commands are processed by the server as soon as they
1462are received, i.e. out of order w.r.t. other commands. The first argument 1473are received, i.e. out of order w.r.t. other commands. The first argument
1463is a client socket. Exti commands can be received anytime, even before 1474is a client socket. Exti commands can be received anytime, even before
1464log-in. 1475log-in.
1465 1476
1466If the callback returns something, it is sent back as if reply was being 1477The values will be sent back to the client.
1467called.
1468 1478
1469=cut 1479=item cf::register_async_exticmd $name => \&callback($ns,$reply->(...),@args)
1470 1480
1481Same as C<cf::register_extcmd>, but instead of returning values, the
1482callback needs to clal the C<$reply> function.
1483
1484=cut
1485
1471sub register_extcmd { 1486sub register_extcmd($$) {
1472 my ($name, $cb) = @_; 1487 my ($name, $cb) = @_;
1473 1488
1474 $EXTCMD{$name} = $cb; 1489 $EXTCMD{$name} = $cb;
1475} 1490}
1476 1491
1477sub register_exticmd { 1492sub register_async_extcmd($$) {
1478 my ($name, $cb) = @_; 1493 my ($name, $cb) = @_;
1479 1494
1495 $EXTACMD{$name} = $cb;
1496}
1497
1498sub register_exticmd($$) {
1499 my ($name, $cb) = @_;
1500
1480 $EXTICMD{$name} = $cb; 1501 $EXTICMD{$name} = $cb;
1502}
1503
1504sub register_async_exticmd($$) {
1505 my ($name, $cb) = @_;
1506
1507 $EXTIACMD{$name} = $cb;
1481} 1508}
1482 1509
1483use File::Glob (); 1510use File::Glob ();
1484 1511
1485cf::player->attach ( 1512cf::player->attach (
1501 my $msg = eval { $pl->ns->{json_coder}->decode ($buf) }; 1528 my $msg = eval { $pl->ns->{json_coder}->decode ($buf) };
1502 1529
1503 if (ref $msg) { 1530 if (ref $msg) {
1504 my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash 1531 my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash
1505 1532
1506 my @reply;
1507
1508 if (my $cb = $EXTCMD{$type}) { 1533 if (my $cb = $EXTACMD{$type}) {
1534 $cb->(
1535 $pl,
1536 sub {
1537 $pl->ext_msg ("reply-$reply", @_)
1538 if $reply;
1539 },
1540 @payload
1541 );
1542 } else {
1543 my @reply;
1544
1545 if (my $cb = $EXTCMD{$type}) {
1509 @reply = $cb->($pl, @payload); 1546 @reply = $cb->($pl, @payload);
1547 }
1548
1549 $pl->ext_msg ("reply-$reply", @reply)
1550 if $reply;
1510 } 1551 }
1511
1512 $pl->ext_reply ($reply, @reply)
1513 if $reply;
1514 1552
1515 } else { 1553 } else {
1516 error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; 1554 error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n";
1517 } 1555 }
1518 1556
1531 }; 1569 };
1532 1570
1533 $grp 1571 $grp
1534} 1572}
1535 1573
1574sub _ext_cfg_reg($$$$) {
1575 my ($rvar, $varname, $cfgname, $default) = @_;
1576
1577 $cfgname = lc $varname
1578 unless length $cfgname;
1579
1580 $EXT_CFG{$cfgname} = [$rvar, $default];
1581
1582 $$rvar = exists $CFG{$cfgname} ? $CFG{$cfgname} : $default;
1583}
1584
1536sub load_extensions { 1585sub load_extensions {
1537 info "loading extensions..."; 1586 info "loading extensions...";
1587
1588 %EXT_CFG = ();
1538 1589
1539 cf::sync_job { 1590 cf::sync_job {
1540 my %todo; 1591 my %todo;
1541 1592
1542 for my $path (<$LIBDIR/*.ext>) { 1593 for my $path (<$LIBDIR/*.ext>) {
1585 unless exists $done{$_}; 1636 unless exists $done{$_};
1586 } 1637 }
1587 1638
1588 trace "... pass $pass, loading '$k' into '$v->{pkg}'\n"; 1639 trace "... pass $pass, loading '$k' into '$v->{pkg}'\n";
1589 1640
1641 my $source = $v->{source};
1642
1643 # support "CONF varname :confname = default" pseudo-statements
1644 $source =~ s{
1645 ^ CONF \s+ ([^\s:=]+) \s* (?:: \s* ([^\s:=]+) \s* )? = ([^\n#]+)
1646 }{
1647 "our \$$1; BEGIN { cf::_ext_cfg_reg \\\$$1, q\x00$1\x00, q\x00$2\x00, $3 }";
1648 }gmxe;
1649
1590 my $active = eval $v->{source}; 1650 my $active = eval $source;
1591 1651
1592 if (length $@) { 1652 if (length $@) {
1593 error "$v->{path}: $@\n"; 1653 error "$v->{path}: $@\n";
1594 1654
1595 cf::cleanup "mandatory extension '$k' failed to load, exiting." 1655 cf::cleanup "mandatory extension '$k' failed to load, exiting."
1882} 1942}
1883 1943
1884=item $protocol_xml = $player->expand_cfpod ($cfpod) 1944=item $protocol_xml = $player->expand_cfpod ($cfpod)
1885 1945
1886Expand deliantra pod fragments into protocol xml. 1946Expand deliantra pod fragments into protocol xml.
1887
1888=item $player->ext_reply ($msgid, @msg)
1889
1890Sends an ext reply to the player.
1891
1892=cut
1893
1894sub ext_reply($$@) {
1895 my ($self, $id, @msg) = @_;
1896
1897 $self->ns->ext_reply ($id, @msg)
1898}
1899 1947
1900=item $player->ext_msg ($type, @msg) 1948=item $player->ext_msg ($type, @msg)
1901 1949
1902Sends an ext event to the client. 1950Sends an ext event to the client.
1903 1951
3208=cut 3256=cut
3209 3257
3210sub cf::client::ext_msg($$@) { 3258sub cf::client::ext_msg($$@) {
3211 my ($self, $type, @msg) = @_; 3259 my ($self, $type, @msg) = @_;
3212 3260
3213 if ($self->extcmd == 2) {
3214 $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); 3261 $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg]));
3215 } elsif ($self->extcmd == 1) { # TODO: remove
3216 push @msg, msgtype => "event_$type";
3217 $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg}));
3218 }
3219}
3220
3221=item $client->ext_reply ($msgid, @msg)
3222
3223Sends an ext reply to the client.
3224
3225=cut
3226
3227sub cf::client::ext_reply($$@) {
3228 my ($self, $id, @msg) = @_;
3229
3230 return unless $self->extcmd == 2;
3231
3232 $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg]));
3233} 3262}
3234 3263
3235=item $success = $client->query ($flags, "text", \&cb) 3264=item $success = $client->query ($flags, "text", \&cb)
3236 3265
3237Queues a query to the client, calling the given callback with 3266Queues a query to the client, calling the given callback with
3294 my $msg = eval { $ns->{json_coder}->decode ($buf) }; 3323 my $msg = eval { $ns->{json_coder}->decode ($buf) };
3295 3324
3296 if (ref $msg) { 3325 if (ref $msg) {
3297 my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash 3326 my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash
3298 3327
3299 my @reply;
3300
3301 if (my $cb = $EXTICMD{$type}) { 3328 if (my $cb = $EXTIACMD{$type}) {
3329 $cb->(
3330 $ns,
3331 sub {
3332 $ns->ext_msg ("reply-$reply", @_)
3333 if $reply;
3334 },
3335 @payload
3336 );
3337 } else {
3338 my @reply;
3339
3340 if (my $cb = $EXTICMD{$type}) {
3302 @reply = $cb->($ns, @payload); 3341 @reply = $cb->($ns, @payload);
3342 }
3343
3344 $ns->ext_msg ("reply-$reply", @reply)
3345 if $reply;
3303 } 3346 }
3304
3305 $ns->ext_reply ($reply, @reply)
3306 if $reply;
3307
3308 } else { 3347 } else {
3309 error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n"; 3348 error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n";
3310 } 3349 }
3311 3350
3312 cf::override; 3351 cf::override;
3480=cut 3519=cut
3481 3520
3482############################################################################# 3521#############################################################################
3483# the server's init and main functions 3522# the server's init and main functions
3484 3523
3524our %FACEHASH; # hash => idx, #d# HACK for http server
3525
3526# internal api, not fianlised
3527sub set_face {
3528 my ($name, $type, $data) = @_;
3529
3530 my $idx = cf::face::find $name;
3531
3532 if ($idx) {
3533 delete $FACEHASH{cf::face::get_chksum $idx};
3534 } else {
3535 $idx = cf::face::alloc $name;
3536 }
3537
3538 my $hash = cf::face::mangle_chksum Digest::MD5::md5 $data;
3539
3540 cf::face::set_type $idx, $type;
3541 cf::face::set_data $idx, 0, $data, $hash;
3542 cf::face::set_meta $idx, $type & 1 ? undef : undef;
3543 $FACEHASH{$hash} = $idx;#d#
3544
3545 $idx
3546}
3547
3485sub load_facedata($) { 3548sub load_facedata($) {
3486 my ($path) = @_; 3549 my ($path) = @_;
3487 3550
3488 # HACK to clear player env face cache, we need some signal framework 3551 # HACK to clear player env face cache, we need some signal framework
3489 # for this (global event?) 3552 # for this (global event?)
3496 my $facedata = decode_storable load_file $path; 3559 my $facedata = decode_storable load_file $path;
3497 3560
3498 $facedata->{version} == 2 3561 $facedata->{version} == 2
3499 or cf::cleanup "$path: version mismatch, cannot proceed."; 3562 or cf::cleanup "$path: version mismatch, cannot proceed.";
3500 3563
3501 # patch in the exptable
3502 my $exp_table = $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]);
3503 $facedata->{resource}{"res/exp_table"} = {
3504 type => FT_RSRC,
3505 data => $exp_table,
3506 hash => (Digest::MD5::md5 $exp_table),
3507 };
3508 cf::cede_to_tick; 3564 cf::cede_to_tick;
3509 3565
3510 { 3566 {
3511 my $faces = $facedata->{faceinfo}; 3567 my $faces = delete $facedata->{faceinfo};
3512 3568
3513 while (my ($face, $info) = each %$faces) { 3569 for my $face (sort keys %$faces) {
3570 my $info = $faces->{$face};
3514 my $idx = (cf::face::find $face) || cf::face::alloc $face; 3571 my $idx = (cf::face::find $face) || cf::face::alloc $face;
3515 3572
3516 cf::face::set_visibility $idx, $info->{visibility}; 3573 cf::face::set_visibility $idx, $info->{visibility};
3517 cf::face::set_magicmap $idx, $info->{magicmap}; 3574 cf::face::set_magicmap $idx, $info->{magicmap};
3518 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; 3575 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32};
3519 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; 3576 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64};
3520 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; 3577 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ;
3521 3578 $FACEHASH{$info->{hash64}} = $idx;#d#
3579
3522 cf::cede_to_tick; 3580 cf::cede_to_tick;
3523 } 3581 }
3524 3582
3525 while (my ($face, $info) = each %$faces) { 3583 while (my ($face, $info) = each %$faces) {
3526 next unless $info->{smooth}; 3584 next unless $info->{smooth};
3538 cf::cede_to_tick; 3596 cf::cede_to_tick;
3539 } 3597 }
3540 } 3598 }
3541 3599
3542 { 3600 {
3543 my $anims = $facedata->{animinfo}; 3601 my $anims = delete $facedata->{animinfo};
3544 3602
3545 while (my ($anim, $info) = each %$anims) { 3603 while (my ($anim, $info) = each %$anims) {
3546 cf::anim::set $anim, $info->{frames}, $info->{facings}; 3604 cf::anim::set $anim, $info->{frames}, $info->{facings};
3547 cf::cede_to_tick; 3605 cf::cede_to_tick;
3548 } 3606 }
3549 3607
3550 cf::anim::invalidate_all; # d'oh 3608 cf::anim::invalidate_all; # d'oh
3551 } 3609 }
3552 3610
3553 { 3611 {
3554 my $res = $facedata->{resource}; 3612 my $res = delete $facedata->{resource};
3555 3613
3556 while (my ($name, $info) = each %$res) { 3614 while (my ($name, $info) = each %$res) {
3557 if (defined (my $type = $info->{type})) { 3615 if (defined (my $type = $info->{type})) {
3558 # TODO: different hash - must free and use new index, or cache ixface data queue 3616 # TODO: different hash - must free and use new index, or cache ixface data queue
3559 my $idx = (cf::face::find $name) || cf::face::alloc $name; 3617 my $idx = (cf::face::find $name) || cf::face::alloc $name;
3560 3618
3619 cf::face::set_type $idx, $type;
3561 cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; 3620 cf::face::set_data $idx, 0, $info->{data}, $info->{hash};
3562 cf::face::set_type $idx, $type;
3563 cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already 3621 cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already
3622 $FACEHASH{$info->{hash}} = $idx;#d#
3564 } else { 3623 } else {
3565# $RESOURCE{$name} = $info; # unused 3624# $RESOURCE{$name} = $info; # unused
3566 } 3625 }
3567 3626
3568 cf::cede_to_tick; 3627 cf::cede_to_tick;
3588 my $status = load_resource_file_ $_[0]; 3647 my $status = load_resource_file_ $_[0];
3589 get_slot 0.1, 100; 3648 get_slot 0.1, 100;
3590 cf::arch::commit_load; 3649 cf::arch::commit_load;
3591 3650
3592 $status 3651 $status
3652}
3653
3654sub reload_exp_table {
3655 _reload_exp_table;
3656
3657 set_face "res/exp_table" => FT_RSRC,
3658 JSON::XS->new->utf8->canonical->encode (
3659 [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]
3660 );
3661}
3662
3663sub reload_materials {
3664 _reload_materials;
3593} 3665}
3594 3666
3595sub reload_regions { 3667sub reload_regions {
3596 # HACK to clear player env face cache, we need some signal framework 3668 # HACK to clear player env face cache, we need some signal framework
3597 # for this (global event?) 3669 # for this (global event?)
3612} 3684}
3613 3685
3614sub reload_archetypes { 3686sub reload_archetypes {
3615 load_resource_file "$DATADIR/archetypes" 3687 load_resource_file "$DATADIR/archetypes"
3616 or die "unable to load archetypes\n"; 3688 or die "unable to load archetypes\n";
3689
3690 set_face "res/skill_info" => FT_RSRC,
3691 JSON::XS->new->utf8->canonical->encode (
3692 [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1]
3693 );
3694 set_face "res/spell_paths" => FT_RSRC,
3695 JSON::XS->new->utf8->canonical->encode (
3696 [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1]
3697 );
3617} 3698}
3618 3699
3619sub reload_treasures { 3700sub reload_treasures {
3620 load_resource_file "$DATADIR/treasures" 3701 load_resource_file "$DATADIR/treasures"
3621 or die "unable to load treasurelists\n"; 3702 or die "unable to load treasurelists\n";
3642} 3723}
3643 3724
3644sub reload_resources { 3725sub reload_resources {
3645 trace "reloading resource files...\n"; 3726 trace "reloading resource files...\n";
3646 3727
3647 reload_exp_table;
3648 reload_materials; 3728 reload_materials;
3649 reload_facedata; 3729 reload_facedata;
3730 reload_exp_table;
3650 reload_sound; 3731 reload_sound;
3651 reload_archetypes; 3732 reload_archetypes;
3652 reload_regions; 3733 reload_regions;
3653 reload_treasures; 3734 reload_treasures;
3654 3735
3713 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3794 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3714 3795
3715 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3796 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3716 3797
3717 # we must not ever block the main coroutine 3798 # we must not ever block the main coroutine
3718 local $Coro::idle = sub { 3799 $Coro::idle = sub {
3719 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3800 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3720 (async { 3801 (async {
3721 $Coro::current->{desc} = "IDLE BUG HANDLER"; 3802 $Coro::current->{desc} = "IDLE BUG HANDLER";
3722 EV::loop EV::LOOP_ONESHOT; 3803 EV::loop EV::LOOP_ONESHOT;
3723 })->prio (Coro::PRIO_MAX); 3804 })->prio (Coro::PRIO_MAX);
3726 evthread_start IO::AIO::poll_fileno; 3807 evthread_start IO::AIO::poll_fileno;
3727 3808
3728 cf::sync_job { 3809 cf::sync_job {
3729 cf::incloader::init (); 3810 cf::incloader::init ();
3730 3811
3812 db_init;
3813
3731 cf::init_anim; 3814 cf::init_anim;
3732 cf::init_attackmess; 3815 cf::init_attackmess;
3733 cf::init_dynamic; 3816 cf::init_dynamic;
3734 3817
3735 cf::load_settings; 3818 cf::load_settings;
3736 3819
3737 reload_resources; 3820 reload_resources;
3738 reload_config; 3821 reload_config;
3739 db_init;
3740 3822
3741 cf::init_uuid; 3823 cf::init_uuid;
3742 cf::init_signals; 3824 cf::init_signals;
3743 cf::init_skills; 3825 cf::init_skills;
3744 3826
4169 } 4251 }
4170} 4252}
4171 4253
4172{ 4254{
4173 # configure BDB 4255 # configure BDB
4256 info "initialising database";
4174 4257
4175 BDB::min_parallel 16; 4258 BDB::min_parallel 16;
4176 BDB::max_poll_reqs $TICK * 0.1; 4259 BDB::max_poll_reqs $TICK * 0.1;
4177 #$AnyEvent::BDB::WATCHER->priority (1); 4260 #$AnyEvent::BDB::WATCHER->priority (1);
4178 4261
4207 BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { }; 4290 BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { };
4208 }; 4291 };
4209 $BDB_TRICKLE_WATCHER = EV::periodic 0, 10, 0, sub { 4292 $BDB_TRICKLE_WATCHER = EV::periodic 0, 10, 0, sub {
4210 BDB::db_env_memp_trickle $DB_ENV, 20, 0, sub { }; 4293 BDB::db_env_memp_trickle $DB_ENV, 20, 0, sub { };
4211 }; 4294 };
4295
4296 info "database initialised";
4212} 4297}
4213 4298
4214{ 4299{
4215 # configure IO::AIO 4300 # configure IO::AIO
4216 4301
4302 info "initialising aio";
4217 IO::AIO::min_parallel 8; 4303 IO::AIO::min_parallel 8;
4218 IO::AIO::max_poll_time $TICK * 0.1; 4304 IO::AIO::max_poll_time $TICK * 0.1;
4219 undef $AnyEvent::AIO::WATCHER; 4305 undef $AnyEvent::AIO::WATCHER;
4306 info "aio initialised";
4220} 4307}
4221 4308
4222our $_log_backtrace; 4309our $_log_backtrace;
4223our $_log_backtrace_last; 4310our $_log_backtrace_last;
4224 4311

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines