… | |
… | |
69 | our $TMPDIR = "$LOCALDIR/" . tmpdir; |
69 | our $TMPDIR = "$LOCALDIR/" . tmpdir; |
70 | our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; |
70 | our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; |
71 | our $PLAYERDIR = "$LOCALDIR/" . playerdir; |
71 | our $PLAYERDIR = "$LOCALDIR/" . playerdir; |
72 | our $RANDOMDIR = "$LOCALDIR/random"; |
72 | our $RANDOMDIR = "$LOCALDIR/random"; |
73 | our $BDBDIR = "$LOCALDIR/db"; |
73 | our $BDBDIR = "$LOCALDIR/db"; |
|
|
74 | our %RESOURCE; |
74 | |
75 | |
75 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
76 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
76 | our $TICK_WATCHER; |
77 | our $TICK_WATCHER; |
77 | our $AIO_POLL_WATCHER; |
78 | our $AIO_POLL_WATCHER; |
78 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
79 | our $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 | |
977 | Generate an object-specific event with the given arguments. |
983 | Generate 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 | |
|
|
3235 | cf::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 | |
3240 | register_exticmd fx_want => sub { |
3255 | register_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) { |