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.403 by root, Mon Dec 17 07:09:18 2007 UTC vs.
Revision 1.406 by root, Mon Dec 17 08:27:44 2007 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
968 } 969 }
969 970
970 0 971 0
971} 972}
972 973
973=item $bool = cf::global::invoke (EVENT_CLASS_XXX, ...) 974=item $bool = cf::global->invoke (EVENT_CLASS_XXX, ...)
974 975
975=item $bool = $attachable->invoke (EVENT_CLASS_XXX, ...) 976=item $bool = $attachable->invoke (EVENT_CLASS_XXX, ...)
976 977
977Generate an object-specific event with the given arguments. 978Generate an object-specific event with the given arguments.
978 979
3149 { 3150 {
3150 my $faces = $facedata->{faceinfo}; 3151 my $faces = $facedata->{faceinfo};
3151 3152
3152 while (my ($face, $info) = each %$faces) { 3153 while (my ($face, $info) = each %$faces) {
3153 my $idx = (cf::face::find $face) || cf::face::alloc $face; 3154 my $idx = (cf::face::find $face) || cf::face::alloc $face;
3155
3154 cf::face::set_visibility $idx, $info->{visibility}; 3156 cf::face::set_visibility $idx, $info->{visibility};
3155 cf::face::set_magicmap $idx, $info->{magicmap}; 3157 cf::face::set_magicmap $idx, $info->{magicmap};
3156 cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32}; 3158 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}; 3159 cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64};
3158 3160
3159 cf::cede_to_tick; 3161 cf::cede_to_tick;
3160 } 3162 }
3161 3163
3162 while (my ($face, $info) = each %$faces) { 3164 while (my ($face, $info) = each %$faces) {
3163 next unless $info->{smooth}; 3165 next unless $info->{smooth};
3166
3164 my $idx = cf::face::find $face 3167 my $idx = cf::face::find $face
3165 or next; 3168 or next;
3169
3166 if (my $smooth = cf::face::find $info->{smooth}) { 3170 if (my $smooth = cf::face::find $info->{smooth}) {
3167 cf::face::set_smooth $idx, $smooth; 3171 cf::face::set_smooth $idx, $smooth;
3168 cf::face::set_smoothlevel $idx, $info->{smoothlevel}; 3172 cf::face::set_smoothlevel $idx, $info->{smoothlevel};
3169 } else { 3173 } else {
3170 warn "smooth face '$info->{smooth}' not found for face '$face'"; 3174 warn "smooth face '$info->{smooth}' not found for face '$face'";
3188 { 3192 {
3189 # TODO: for gcfclient pleasure, we should give resources 3193 # TODO: for gcfclient pleasure, we should give resources
3190 # that gcfclient doesn't grok a >10000 face index. 3194 # that gcfclient doesn't grok a >10000 face index.
3191 my $res = $facedata->{resource}; 3195 my $res = $facedata->{resource};
3192 3196
3193 my $soundconf = delete $res->{"res/sound.conf"};
3194
3195 while (my ($name, $info) = each %$res) { 3197 while (my ($name, $info) = each %$res) {
3198 if (defined $info->{type}) {
3196 my $idx = (cf::face::find $name) || cf::face::alloc $name; 3199 my $idx = (cf::face::find $name) || cf::face::alloc $name;
3197 my $data; 3200 my $data;
3198 3201
3199 if ($info->{type} & 1) { 3202 if ($info->{type} & 1) {
3200 # prepend meta info 3203 # prepend meta info
3201 3204
3202 my $meta = $enc->encode ({ 3205 my $meta = $enc->encode ({
3203 name => $name, 3206 name => $name,
3204 %{ $info->{meta} || {} }, 3207 %{ $info->{meta} || {} },
3205 }); 3208 });
3206 3209
3207 $data = pack "(w/a*)*", $meta, $info->{data}; 3210 $data = pack "(w/a*)*", $meta, $info->{data};
3211 } else {
3212 $data = $info->{data};
3213 }
3214
3215 cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data;
3216 cf::face::set_type $idx, $info->{type};
3208 } else { 3217 } else {
3209 $data = $info->{data}; 3218 $RESOURCE{$name} = $info;
3210 } 3219 }
3211 3220
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; 3221 cf::cede_to_tick;
3216 } 3222 }
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 } 3223 }
3224
3225 cf::global->invoke (EVENT_GLOBAL_RESOURCE_UPDATE);
3236 3226
3237 1 3227 1
3238} 3228}
3229
3230cf::global->attach (on_resource_update => sub {
3231 if (my $soundconf = $RESOURCE{"res/sound.conf"}) {
3232 $soundconf = JSON::XS->new->utf8->relaxed->decode ($soundconf->{data});
3233
3234 for (0 .. SOUND_CAST_SPELL_0 - 1) {
3235 my $sound = $soundconf->{compat}[$_]
3236 or next;
3237
3238 my $face = cf::face::find "sound/$sound->[1]";
3239 cf::sound::set $sound->[0] => $face;
3240 cf::sound::old_sound_index $_, $face; # gcfclient-compat
3241 }
3242
3243 while (my ($k, $v) = each %{$soundconf->{event}}) {
3244 my $face = cf::face::find "sound/$v";
3245 cf::sound::set $k => $face;
3246 }
3247 }
3248});
3239 3249
3240register_exticmd fx_want => sub { 3250register_exticmd fx_want => sub {
3241 my ($ns, $want) = @_; 3251 my ($ns, $want) = @_;
3242 3252
3243 while (my ($k, $v) = each %$want) { 3253 while (my ($k, $v) = each %$want) {
3603 3613
3604 $NOW = $tick_start = EV::now; 3614 $NOW = $tick_start = EV::now;
3605 3615
3606 cf::server_tick; # one server iteration 3616 cf::server_tick; # one server iteration
3607 3617
3608 $RUNTIME += $TICK; 3618 $RUNTIME += $TICK;
3609 $NEXT_TICK += $TICK; 3619 $NEXT_TICK = $_[0]->at;
3610 3620
3611 if ($NOW >= $NEXT_RUNTIME_WRITE) { 3621 if ($NOW >= $NEXT_RUNTIME_WRITE) {
3612 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; 3622 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.;
3613 Coro::async_pool { 3623 Coro::async_pool {
3614 $Coro::current->{desc} = "runtime saver"; 3624 $Coro::current->{desc} = "runtime saver";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines