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.91 by elmex, Sun Dec 17 22:03:44 2006 UTC vs.
Revision 1.92 by root, Thu Dec 21 06:42:28 2006 UTC

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
157Attach/detach a pre-registered attachment to a client.
158
159=item $client->attach ($attachment, key => $value...)
160
161=item $client->detach ($attachment)
162
157Attach/detach a pre-registered attachment to a map. 163Attach/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
165Checks wether the named attachment is currently attached to the object. 173Checks 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
216Attach handlers to all players. 224Attach handlers to all players.
217 225
226=item cf::attach_to_clients ...
227
228Attach handlers to all players.
229
218=item cf::attach_to_maps ... 230=item cf::attach_to_maps ...
219 231
220Attach handlers to all maps. 232Attach 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
240our @CB_GLOBAL = (); # registry for all global events 252our @CB_GLOBAL = (); # registry for all global events
241our @CB_OBJECT = (); # all objects (should not be used except in emergency) 253our @CB_OBJECT = (); # all objects (should not be used except in emergency)
242our @CB_PLAYER = (); 254our @CB_PLAYER = ();
255our @CB_CLIENT = ();
243our @CB_TYPE = (); # registry for type (cf-object class) based events 256our @CB_TYPE = (); # registry for type (cf-object class) based events
244our @CB_MAP = (); 257our @CB_MAP = ();
245 258
246my %attachment; 259my %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
374sub attach_to_players { 390sub attach_to_players {
375 _attach @CB_PLAYER, KLASS_PLAYER, @_ 391 _attach @CB_PLAYER, KLASS_PLAYER, @_
376} 392}
377 393
394sub attach_to_clients {
395 _attach @CB_CLIENT, KLASS_CLIENT, @_
396}
397
378sub attach_to_maps { 398sub attach_to_maps {
379 _attach @CB_MAP, KLASS_MAP, @_ 399 _attach @CB_MAP, KLASS_MAP, @_
380} 400}
381 401
382sub register_attachment { 402sub register_attachment {
387 407
388sub register_player_attachment { 408sub 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
414sub register_client_attachment {
415 my $name = shift;
416
417 $attachment{$name} = [[KLASS_CLIENT, @_]];
392} 418}
393 419
394sub register_map_attachment { 420sub 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
439Generate a global/object/player/map-specific event with the given arguments. 467Generate a global/object/player/map-specific event with the given arguments.
440 468
441This API is preliminary (most likely, the EVENT_KLASS_xxx prefix will be 469This 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
457Just because you have a perl object does not mean that the corresponding 485Just because you have a perl object does not mean that the corresponding
458C-level object still exists. If you try to access an object that has no 486C-level object still exists. If you try to access an object that has no
459valid C counterpart anymore you get an exception at runtime. This method 487valid C counterpart anymore you get an exception at runtime. This method
460can be used to test for existence of the C object part without causing an 488can 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines