--- deliantra/server/lib/cf.pm 2007/12/17 06:36:34 1.400 +++ deliantra/server/lib/cf.pm 2008/01/14 11:41:48 1.409 @@ -6,7 +6,7 @@ use Symbol; use List::Util; use Socket; -use EV; +use EV 1.86; use Opcode; use Safe; use Safe::Hole; @@ -29,7 +29,7 @@ use Data::Dumper; use Digest::MD5; use Fcntl; -use YAML::Syck (); +use YAML (); use IO::AIO 2.51 (); use Time::HiRes; use Compress::LZF; @@ -41,9 +41,6 @@ Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later -# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode? -$YAML::Syck::ImplicitUnicode = 1; - $Coro::main->prio (Coro::PRIO_MAX); # run main coroutine ("the server") with very high priority sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload @@ -71,6 +68,7 @@ our $PLAYERDIR = "$LOCALDIR/" . playerdir; our $RANDOMDIR = "$LOCALDIR/random"; our $BDBDIR = "$LOCALDIR/db"; +our %RESOURCE; our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) our $TICK_WATCHER; @@ -195,6 +193,11 @@ }; } +$Coro::State::DIEHOOK = sub { + warn Carp::longmess $_[0]; + Coro::terminate; +}; + @safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; @safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; @safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; @@ -970,7 +973,7 @@ 0 } -=item $bool = cf::global::invoke (EVENT_CLASS_XXX, ...) +=item $bool = cf::global->invoke (EVENT_CLASS_XXX, ...) =item $bool = $attachable->invoke (EVENT_CLASS_XXX, ...) @@ -3151,6 +3154,7 @@ while (my ($face, $info) = each %$faces) { my $idx = (cf::face::find $face) || cf::face::alloc $face; + cf::face::set_visibility $idx, $info->{visibility}; cf::face::set_magicmap $idx, $info->{magicmap}; cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32}; @@ -3161,8 +3165,10 @@ while (my ($face, $info) = each %$faces) { next unless $info->{smooth}; + my $idx = cf::face::find $face or next; + if (my $smooth = cf::face::find $info->{smooth}) { cf::face::set_smooth $idx, $smooth; cf::face::set_smoothlevel $idx, $info->{smoothlevel}; @@ -3190,52 +3196,58 @@ # that gcfclient doesn't grok a >10000 face index. my $res = $facedata->{resource}; - my $soundconf = delete $res->{"res/sound.conf"}; - while (my ($name, $info) = each %$res) { - my $idx = (cf::face::find $name) || cf::face::alloc $name; - my $data; + if (defined $info->{type}) { + my $idx = (cf::face::find $name) || cf::face::alloc $name; + my $data; + + if ($info->{type} & 1) { + # prepend meta info + + my $meta = $enc->encode ({ + name => $name, + %{ $info->{meta} || {} }, + }); - if ($info->{type} & 1) { - # prepend meta info - - my $meta = $enc->encode ({ - name => $name, - %{ $info->{meta} || {} }, - }); + $data = pack "(w/a*)*", $meta, $info->{data}; + } else { + $data = $info->{data}; + } - $data = pack "(w/a*)*", $meta, $info->{data}; + cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data; + cf::face::set_type $idx, $info->{type}; } else { - $data = $info->{data}; + $RESOURCE{$name} = $info; } - cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data; - cf::face::set_type $idx, $info->{type}; - cf::cede_to_tick; } + } + + cf::global->invoke (EVENT_GLOBAL_RESOURCE_UPDATE); + + 1 +} - if ($soundconf) { - $soundconf = $enc->decode (delete $soundconf->{data}); +cf::global->attach (on_resource_update => sub { + if (my $soundconf = $RESOURCE{"res/sound.conf"}) { + $soundconf = JSON::XS->new->utf8->relaxed->decode ($soundconf->{data}); - for (0 .. SOUND_CAST_SPELL_0 - 1) { - my $sound = $soundconf->{compat}[$_] - or next; + for (0 .. SOUND_CAST_SPELL_0 - 1) { + my $sound = $soundconf->{compat}[$_] + or next; - my $face = cf::face::find "sound/$sound->[1]"; - cf::sound::set $sound->[0] => $face; - cf::sound::old_sound_index $_, $face; # gcfclient-compat - } + my $face = cf::face::find "sound/$sound->[1]"; + cf::sound::set $sound->[0] => $face; + cf::sound::old_sound_index $_, $face; # gcfclient-compat + } - while (my ($k, $v) = each %{$soundconf->{event}}) { - my $face = cf::face::find "sound/$v"; - cf::sound::set $k => $face; - } + while (my ($k, $v) = each %{$soundconf->{event}}) { + my $face = cf::face::find "sound/$v"; + cf::sound::set $k => $face; } } - - 1 -} +}); register_exticmd fx_want => sub { my ($ns, $want) = @_; @@ -3300,7 +3312,7 @@ or return; local $/; - *CFG = YAML::Syck::Load <$fh>; + *CFG = YAML::Load <$fh>; $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37]; @@ -3552,8 +3564,8 @@ # coro crashes during coro_state_free->destroy here. $RELOAD_WATCHER ||= EV::timer 0, 0, sub { - undef $RELOAD_WATCHER; do_reload_perl; + undef $RELOAD_WATCHER; }; } @@ -3605,11 +3617,11 @@ cf::server_tick; # one server iteration - $RUNTIME += $TICK; - $NEXT_TICK += $TICK; + $RUNTIME += $TICK; + $NEXT_TICK = $_[0]->at; if ($NOW >= $NEXT_RUNTIME_WRITE) { - $NEXT_RUNTIME_WRITE = $NOW + 10; + $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; Coro::async_pool { $Coro::current->{desc} = "runtime saver"; write_runtime @@ -3632,8 +3644,11 @@ $TICK_WATCHER->priority (EV::MAXPRI); { + # configure BDB + BDB::min_parallel 8; BDB::max_poll_reqs $TICK * 0.1; + $Coro::BDB::WATCHER->priority (1); unless ($DB_ENV) { $DB_ENV = BDB::db_env_create; @@ -3670,11 +3685,11 @@ } { - IO::AIO::min_parallel 8; + # configure IO::AIO - undef $Coro::AIO::WATCHER; + IO::AIO::min_parallel 8; IO::AIO::max_poll_time $TICK * 0.1; - $AIO_POLL_WATCHER = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; + $Coro::AIO::WATCHER->priority (1); } my $_log_backtrace;