… | |
… | |
152 | |
152 | |
153 | =item $map->attach ($attachment, key => $value...) |
153 | =item $map->attach ($attachment, key => $value...) |
154 | |
154 | |
155 | =item $map->detach ($attachment) |
155 | =item $map->detach ($attachment) |
156 | |
156 | |
|
|
157 | Attach/detach a pre-registered attachment to a client. |
|
|
158 | |
|
|
159 | =item $client->attach ($attachment, key => $value...) |
|
|
160 | |
|
|
161 | =item $client->detach ($attachment) |
|
|
162 | |
157 | Attach/detach a pre-registered attachment to a map. |
163 | Attach/detach a pre-registered attachment to a map. |
158 | |
164 | |
159 | =item $bool = $object->attached ($name) |
165 | =item $bool = $object->attached ($name) |
160 | |
166 | |
161 | =item $bool = $player->attached ($name) |
167 | =item $bool = $player->attached ($name) |
|
|
168 | |
|
|
169 | =item $bool = $client->attached ($name) |
162 | |
170 | |
163 | =item $bool = $map->attached ($name) |
171 | =item $bool = $map->attached ($name) |
164 | |
172 | |
165 | Checks wether the named attachment is currently attached to the object. |
173 | Checks wether the named attachment is currently attached to the object. |
166 | |
174 | |
… | |
… | |
213 | |
221 | |
214 | =item cf::attach_to_players ... |
222 | =item cf::attach_to_players ... |
215 | |
223 | |
216 | Attach handlers to all players. |
224 | Attach handlers to all players. |
217 | |
225 | |
|
|
226 | =item cf::attach_to_clients ... |
|
|
227 | |
|
|
228 | Attach handlers to all players. |
|
|
229 | |
218 | =item cf::attach_to_maps ... |
230 | =item cf::attach_to_maps ... |
219 | |
231 | |
220 | Attach handlers to all maps. |
232 | Attach handlers to all maps. |
221 | |
233 | |
222 | =item cf:register_attachment $name, ... |
234 | =item cf:register_attachment $name, ... |
… | |
… | |
238 | |
250 | |
239 | # the following variables are defined in .xs and must not be re-created |
251 | # the following variables are defined in .xs and must not be re-created |
240 | our @CB_GLOBAL = (); # registry for all global events |
252 | our @CB_GLOBAL = (); # registry for all global events |
241 | our @CB_OBJECT = (); # all objects (should not be used except in emergency) |
253 | our @CB_OBJECT = (); # all objects (should not be used except in emergency) |
242 | our @CB_PLAYER = (); |
254 | our @CB_PLAYER = (); |
|
|
255 | our @CB_CLIENT = (); |
243 | our @CB_TYPE = (); # registry for type (cf-object class) based events |
256 | our @CB_TYPE = (); # registry for type (cf-object class) based events |
244 | our @CB_MAP = (); |
257 | our @CB_MAP = (); |
245 | |
258 | |
246 | my %attachment; |
259 | my %attachment; |
247 | |
260 | |
… | |
… | |
330 | $res |
343 | $res |
331 | } |
344 | } |
332 | |
345 | |
333 | *cf::object::attach = |
346 | *cf::object::attach = |
334 | *cf::player::attach = |
347 | *cf::player::attach = |
|
|
348 | *cf::client::attach = |
335 | *cf::map::attach = sub { |
349 | *cf::map::attach = sub { |
336 | my ($obj, $name, %arg) = @_; |
350 | my ($obj, $name, %arg) = @_; |
337 | |
351 | |
338 | _attach_attachment $obj, $name, %arg; |
352 | _attach_attachment $obj, $name, %arg; |
339 | }; |
353 | }; |
340 | |
354 | |
341 | # all those should be optimised |
355 | # all those should be optimised |
342 | *cf::object::detach = |
356 | *cf::object::detach = |
343 | *cf::player::detach = |
357 | *cf::player::detach = |
|
|
358 | *cf::client::detach = |
344 | *cf::map::detach = sub { |
359 | *cf::map::detach = sub { |
345 | my ($obj, $name) = @_; |
360 | my ($obj, $name) = @_; |
346 | |
361 | |
347 | delete $obj->{_attachment}{$name}; |
362 | delete $obj->{_attachment}{$name}; |
348 | reattach ($obj); |
363 | reattach ($obj); |
349 | }; |
364 | }; |
350 | |
365 | |
351 | *cf::object::attached = |
366 | *cf::object::attached = |
352 | *cf::player::attached = |
367 | *cf::player::attached = |
|
|
368 | *cf::client::attached = |
353 | *cf::map::attached = sub { |
369 | *cf::map::attached = sub { |
354 | my ($obj, $name) = @_; |
370 | my ($obj, $name) = @_; |
355 | |
371 | |
356 | exists $obj->{_attachment}{$name} |
372 | exists $obj->{_attachment}{$name} |
357 | }; |
373 | }; |
… | |
… | |
373 | |
389 | |
374 | sub attach_to_players { |
390 | sub attach_to_players { |
375 | _attach @CB_PLAYER, KLASS_PLAYER, @_ |
391 | _attach @CB_PLAYER, KLASS_PLAYER, @_ |
376 | } |
392 | } |
377 | |
393 | |
|
|
394 | sub attach_to_clients { |
|
|
395 | _attach @CB_CLIENT, KLASS_CLIENT, @_ |
|
|
396 | } |
|
|
397 | |
378 | sub attach_to_maps { |
398 | sub attach_to_maps { |
379 | _attach @CB_MAP, KLASS_MAP, @_ |
399 | _attach @CB_MAP, KLASS_MAP, @_ |
380 | } |
400 | } |
381 | |
401 | |
382 | sub register_attachment { |
402 | sub register_attachment { |
… | |
… | |
387 | |
407 | |
388 | sub register_player_attachment { |
408 | sub register_player_attachment { |
389 | my $name = shift; |
409 | my $name = shift; |
390 | |
410 | |
391 | $attachment{$name} = [[KLASS_PLAYER, @_]]; |
411 | $attachment{$name} = [[KLASS_PLAYER, @_]]; |
|
|
412 | } |
|
|
413 | |
|
|
414 | sub register_client_attachment { |
|
|
415 | my $name = shift; |
|
|
416 | |
|
|
417 | $attachment{$name} = [[KLASS_CLIENT, @_]]; |
392 | } |
418 | } |
393 | |
419 | |
394 | sub register_map_attachment { |
420 | sub register_map_attachment { |
395 | my $name = shift; |
421 | my $name = shift; |
396 | |
422 | |
… | |
… | |
432 | |
458 | |
433 | =item $bool = $object->invoke (EVENT_OBJECT_XXX, ...) |
459 | =item $bool = $object->invoke (EVENT_OBJECT_XXX, ...) |
434 | |
460 | |
435 | =item $bool = $player->invoke (EVENT_PLAYER_XXX, ...) |
461 | =item $bool = $player->invoke (EVENT_PLAYER_XXX, ...) |
436 | |
462 | |
|
|
463 | =item $bool = $client->invoke (EVENT_CLIENT_XXX, ...) |
|
|
464 | |
437 | =item $bool = $map->invoke (EVENT_MAP_XXX, ...) |
465 | =item $bool = $map->invoke (EVENT_MAP_XXX, ...) |
438 | |
466 | |
439 | Generate a global/object/player/map-specific event with the given arguments. |
467 | Generate a global/object/player/map-specific event with the given arguments. |
440 | |
468 | |
441 | This API is preliminary (most likely, the EVENT_KLASS_xxx prefix will be |
469 | This API is preliminary (most likely, the EVENT_KLASS_xxx prefix will be |
… | |
… | |
450 | |
478 | |
451 | =head2 METHODS VALID FOR ALL CORE OBJECTS |
479 | =head2 METHODS VALID FOR ALL CORE OBJECTS |
452 | |
480 | |
453 | =over 4 |
481 | =over 4 |
454 | |
482 | |
455 | =item $object->valid, $player->valid, $map->valid |
483 | =item $object->valid, $player->valid, $client->valid, $map->valid |
456 | |
484 | |
457 | Just because you have a perl object does not mean that the corresponding |
485 | Just because you have a perl object does not mean that the corresponding |
458 | C-level object still exists. If you try to access an object that has no |
486 | C-level object still exists. If you try to access an object that has no |
459 | valid C counterpart anymore you get an exception at runtime. This method |
487 | valid C counterpart anymore you get an exception at runtime. This method |
460 | can be used to test for existence of the C object part without causing an |
488 | can be used to test for existence of the C object part without causing an |
… | |
… | |
464 | |
492 | |
465 | =cut |
493 | =cut |
466 | |
494 | |
467 | *cf::object::valid = |
495 | *cf::object::valid = |
468 | *cf::player::valid = |
496 | *cf::player::valid = |
|
|
497 | *cf::client::valid = |
469 | *cf::map::valid = \&cf::_valid; |
498 | *cf::map::valid = \&cf::_valid; |
470 | |
499 | |
471 | ############################################################################# |
500 | ############################################################################# |
472 | # object support |
501 | # object support |
473 | |
502 | |