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.51 by root, Mon Aug 28 14:05:24 2006 UTC vs.
Revision 1.54 by root, Tue Aug 29 14:49:28 2006 UTC

107############################################################################# 107#############################################################################
108# "new" plug-in system 108# "new" plug-in system
109 109
110=item $object->attach ($attachment, key => $value...) 110=item $object->attach ($attachment, key => $value...)
111 111
112=item $object->detach ($attachment)
113
112Attach a pre-registered attachment to an object. 114Attach/detach a pre-registered attachment to an object.
113 115
114=item $player->attach ($attachment, key => $value...) 116=item $player->attach ($attachment, key => $value...)
115 117
118=item $player->detach ($attachment)
119
116Attach a pre-registered attachment to a player. 120Attach/detach a pre-registered attachment to a player.
117 121
118=item $map->attach ($attachment, key => $value...) # not yet persistent 122=item $map->attach ($attachment, key => $value...)
119 123
124=item $map->detach ($attachment)
125
120Attach a pre-registered attachment to a map. 126Attach/detach a pre-registered attachment to a map.
121 127
122=item cf::attach_global ... 128=item cf::attach_global ...
123 129
124Attach handlers for global events. 130Attach handlers for global events.
125 131
173=item cf::attach_to_maps ... 179=item cf::attach_to_maps ...
174 180
175Attach handlers to all maps. 181Attach handlers to all maps.
176 182
177=item cf:register_attachment $name, ... 183=item cf:register_attachment $name, ...
184
185Register an attachment by name through which objects can refer to this
186attachment.
187
188=item cf:register_map_attachment $name, ...
189
190Register an attachment by name through which maps can refer to this
191attachment.
178 192
179=cut 193=cut
180 194
181# the following variables are defined in .xs and must not be re-created 195# the following variables are defined in .xs and must not be re-created
182our @CB_GLOBAL = (); # registry for all global events 196our @CB_GLOBAL = (); # registry for all global events
268 282
269 $res->{attachment} = $name; 283 $res->{attachment} = $name;
270 $res 284 $res
271} 285}
272 286
273sub cf::object::attach { 287*cf::object::attach =
288*cf::player::attach =
289*cf::map::attach = sub {
274 my ($obj, $name, %arg) = @_; 290 my ($obj, $name, %arg) = @_;
275 291
276 _attach_attachment $obj, $name, %arg; 292 _attach_attachment $obj, $name, %arg;
277} 293}
278 294
295# all those should be optimised
296*cf::object::detach =
279sub cf::player::attach { 297*cf::player::detach =
298*cf::map::detach = sub {
280 my ($obj, $name, %arg) = @_; 299 my ($obj, $name) = @_;
281 300
282 _attach_attachment KLASS_PLAYER, $obj, $name, %arg; 301 delete $obj->{_attachment}{$name};
283} 302 reattach $obj;
284 303};
285sub cf::map::attach {
286 my ($obj, $name, %arg) = @_;
287
288 _attach_attachment KLASS_MAP, $obj, $name, %arg;
289}
290 304
291sub attach_global { 305sub attach_global {
292 _attach @CB_GLOBAL, KLASS_GLOBAL, @_ 306 _attach @CB_GLOBAL, KLASS_GLOBAL, @_
293} 307}
294 308
313 327
314sub register_attachment { 328sub register_attachment {
315 my $name = shift; 329 my $name = shift;
316 330
317 $attachment{$name} = [[KLASS_OBJECT, @_]]; 331 $attachment{$name} = [[KLASS_OBJECT, @_]];
332}
333
334sub register_map_attachment {
335 my $name = shift;
336
337 $attachment{$name} = [[KLASS_MAP, @_]];
318} 338}
319 339
320our $override; 340our $override;
321our @invoke_results = (); # referenced from .xs code. TODO: play tricks with reify and mortals? 341our @invoke_results = (); # referenced from .xs code. TODO: play tricks with reify and mortals?
322 342

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines