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.401 by root, Mon Dec 17 06:45:53 2007 UTC vs.
Revision 1.407 by root, Sun Jan 13 09:53:53 2008 UTC

4use strict; 4use strict;
5 5
6use Symbol; 6use Symbol;
7use List::Util; 7use List::Util;
8use Socket; 8use Socket;
9use EV; 9use EV 1.86;
10use Opcode; 10use Opcode;
11use Safe; 11use Safe;
12use Safe::Hole; 12use Safe::Hole;
13use Storable (); 13use Storable ();
14 14
69our $TMPDIR = "$LOCALDIR/" . tmpdir; 69our $TMPDIR = "$LOCALDIR/" . tmpdir;
70our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; 70our $UNIQUEDIR = "$LOCALDIR/" . uniquedir;
71our $PLAYERDIR = "$LOCALDIR/" . playerdir; 71our $PLAYERDIR = "$LOCALDIR/" . playerdir;
72our $RANDOMDIR = "$LOCALDIR/random"; 72our $RANDOMDIR = "$LOCALDIR/random";
73our $BDBDIR = "$LOCALDIR/db"; 73our $BDBDIR = "$LOCALDIR/db";
74our %RESOURCE;
74 75
75our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 76our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
76our $TICK_WATCHER; 77our $TICK_WATCHER;
77our $AIO_POLL_WATCHER; 78our $AIO_POLL_WATCHER;
78our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 79our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
192 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge; 193 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge;
193 194
194 LOG llevError, $msg; 195 LOG llevError, $msg;
195 }; 196 };
196} 197}
198
199$Coro::State::DIEHOOK = sub {
200 warn Carp::longmess $_[0];
201 Coro::terminate;
202};
197 203
198@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; 204@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable';
199@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; 205@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable';
200@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; 206@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable';
201@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable'; 207@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable';
968 } 974 }
969 975
970 0 976 0
971} 977}
972 978
973=item $bool = cf::global::invoke (EVENT_CLASS_XXX, ...) 979=item $bool = cf::global->invoke (EVENT_CLASS_XXX, ...)
974 980
975=item $bool = $attachable->invoke (EVENT_CLASS_XXX, ...) 981=item $bool = $attachable->invoke (EVENT_CLASS_XXX, ...)
976 982
977Generate an object-specific event with the given arguments. 983Generate an object-specific event with the given arguments.
978 984
3149 { 3155 {
3150 my $faces = $facedata->{faceinfo}; 3156 my $faces = $facedata->{faceinfo};
3151 3157
3152 while (my ($face, $info) = each %$faces) { 3158 while (my ($face, $info) = each %$faces) {
3153 my $idx = (cf::face::find $face) || cf::face::alloc $face; 3159 my $idx = (cf::face::find $face) || cf::face::alloc $face;
3160
3154 cf::face::set_visibility $idx, $info->{visibility}; 3161 cf::face::set_visibility $idx, $info->{visibility};
3155 cf::face::set_magicmap $idx, $info->{magicmap}; 3162 cf::face::set_magicmap $idx, $info->{magicmap};
3156 cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32}; 3163 cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32};
3157 cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64}; 3164 cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64};
3158 3165
3159 cf::cede_to_tick; 3166 cf::cede_to_tick;
3160 } 3167 }
3161 3168
3162 while (my ($face, $info) = each %$faces) { 3169 while (my ($face, $info) = each %$faces) {
3163 next unless $info->{smooth}; 3170 next unless $info->{smooth};
3171
3164 my $idx = cf::face::find $face 3172 my $idx = cf::face::find $face
3165 or next; 3173 or next;
3174
3166 if (my $smooth = cf::face::find $info->{smooth}) { 3175 if (my $smooth = cf::face::find $info->{smooth}) {
3167 cf::face::set_smooth $idx, $smooth; 3176 cf::face::set_smooth $idx, $smooth;
3168 cf::face::set_smoothlevel $idx, $info->{smoothlevel}; 3177 cf::face::set_smoothlevel $idx, $info->{smoothlevel};
3169 } else { 3178 } else {
3170 warn "smooth face '$info->{smooth}' not found for face '$face'"; 3179 warn "smooth face '$info->{smooth}' not found for face '$face'";
3188 { 3197 {
3189 # TODO: for gcfclient pleasure, we should give resources 3198 # TODO: for gcfclient pleasure, we should give resources
3190 # that gcfclient doesn't grok a >10000 face index. 3199 # that gcfclient doesn't grok a >10000 face index.
3191 my $res = $facedata->{resource}; 3200 my $res = $facedata->{resource};
3192 3201
3193 my $soundconf = delete $res->{"res/sound.conf"};
3194
3195 while (my ($name, $info) = each %$res) { 3202 while (my ($name, $info) = each %$res) {
3203 if (defined $info->{type}) {
3196 my $idx = (cf::face::find $name) || cf::face::alloc $name; 3204 my $idx = (cf::face::find $name) || cf::face::alloc $name;
3197 my $data; 3205 my $data;
3198 3206
3199 if ($info->{type} & 1) { 3207 if ($info->{type} & 1) {
3200 # prepend meta info 3208 # prepend meta info
3201 3209
3202 my $meta = $enc->encode ({ 3210 my $meta = $enc->encode ({
3203 name => $name, 3211 name => $name,
3204 %{ $info->{meta} || {} }, 3212 %{ $info->{meta} || {} },
3205 }); 3213 });
3206 3214
3207 $data = pack "(w/a*)*", $meta, $info->{data}; 3215 $data = pack "(w/a*)*", $meta, $info->{data};
3216 } else {
3217 $data = $info->{data};
3218 }
3219
3220 cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data;
3221 cf::face::set_type $idx, $info->{type};
3208 } else { 3222 } else {
3209 $data = $info->{data}; 3223 $RESOURCE{$name} = $info;
3210 } 3224 }
3211 3225
3212 cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data;
3213 cf::face::set_type $idx, $info->{type};
3214
3215 cf::cede_to_tick; 3226 cf::cede_to_tick;
3216 } 3227 }
3217
3218 if ($soundconf) {
3219 $soundconf = $enc->decode (delete $soundconf->{data});
3220
3221 for (0 .. SOUND_CAST_SPELL_0 - 1) {
3222 my $sound = $soundconf->{compat}[$_]
3223 or next;
3224
3225 my $face = cf::face::find "sound/$sound->[1]";
3226 cf::sound::set $sound->[0] => $face;
3227 cf::sound::old_sound_index $_, $face; # gcfclient-compat
3228 }
3229
3230 while (my ($k, $v) = each %{$soundconf->{event}}) {
3231 my $face = cf::face::find "sound/$v";
3232 cf::sound::set $k => $face;
3233 }
3234 }
3235 } 3228 }
3229
3230 cf::global->invoke (EVENT_GLOBAL_RESOURCE_UPDATE);
3236 3231
3237 1 3232 1
3238} 3233}
3234
3235cf::global->attach (on_resource_update => sub {
3236 if (my $soundconf = $RESOURCE{"res/sound.conf"}) {
3237 $soundconf = JSON::XS->new->utf8->relaxed->decode ($soundconf->{data});
3238
3239 for (0 .. SOUND_CAST_SPELL_0 - 1) {
3240 my $sound = $soundconf->{compat}[$_]
3241 or next;
3242
3243 my $face = cf::face::find "sound/$sound->[1]";
3244 cf::sound::set $sound->[0] => $face;
3245 cf::sound::old_sound_index $_, $face; # gcfclient-compat
3246 }
3247
3248 while (my ($k, $v) = each %{$soundconf->{event}}) {
3249 my $face = cf::face::find "sound/$v";
3250 cf::sound::set $k => $face;
3251 }
3252 }
3253});
3239 3254
3240register_exticmd fx_want => sub { 3255register_exticmd fx_want => sub {
3241 my ($ns, $want) = @_; 3256 my ($ns, $want) = @_;
3242 3257
3243 while (my ($k, $v) = each %$want) { 3258 while (my ($k, $v) = each %$want) {
3603 3618
3604 $NOW = $tick_start = EV::now; 3619 $NOW = $tick_start = EV::now;
3605 3620
3606 cf::server_tick; # one server iteration 3621 cf::server_tick; # one server iteration
3607 3622
3608 $RUNTIME += $TICK; 3623 $RUNTIME += $TICK;
3609 $NEXT_TICK += $TICK; 3624 $NEXT_TICK = $_[0]->at;
3610 3625
3611 if ($NOW >= $NEXT_RUNTIME_WRITE) { 3626 if ($NOW >= $NEXT_RUNTIME_WRITE) {
3612 $NEXT_RUNTIME_WRITE = $NOW + 10; 3627 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.;
3613 Coro::async_pool { 3628 Coro::async_pool {
3614 $Coro::current->{desc} = "runtime saver"; 3629 $Coro::current->{desc} = "runtime saver";
3615 write_runtime 3630 write_runtime
3616 or warn "ERROR: unable to write runtime file: $!"; 3631 or warn "ERROR: unable to write runtime file: $!";
3617 }; 3632 };
3634{ 3649{
3635 # configure BDB 3650 # configure BDB
3636 3651
3637 BDB::min_parallel 8; 3652 BDB::min_parallel 8;
3638 BDB::max_poll_reqs $TICK * 0.1; 3653 BDB::max_poll_reqs $TICK * 0.1;
3654 $Coro::BDB::WATCHER->priority (1);
3639 3655
3640 unless ($DB_ENV) { 3656 unless ($DB_ENV) {
3641 $DB_ENV = BDB::db_env_create; 3657 $DB_ENV = BDB::db_env_create;
3642 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC 3658 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC
3643 | BDB::LOG_AUTOREMOVE, 1); 3659 | BDB::LOG_AUTOREMOVE, 1);
3674{ 3690{
3675 # configure IO::AIO 3691 # configure IO::AIO
3676 3692
3677 IO::AIO::min_parallel 8; 3693 IO::AIO::min_parallel 8;
3678 IO::AIO::max_poll_time $TICK * 0.1; 3694 IO::AIO::max_poll_time $TICK * 0.1;
3695 $Coro::AIO::WATCHER->priority (1);
3679} 3696}
3680 3697
3681my $_log_backtrace; 3698my $_log_backtrace;
3682 3699
3683sub _log_backtrace { 3700sub _log_backtrace {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines