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.39 by root, Fri Aug 25 13:24:50 2006 UTC vs.
Revision 1.40 by root, Fri Aug 25 15:21:57 2006 UTC

96############################################################################# 96#############################################################################
97# "new" plug-in system 97# "new" plug-in system
98 98
99=item cf::object::attach ... # NYI 99=item cf::object::attach ... # NYI
100 100
101=item cf::attach_global ... # NYI 101=item cf::attach_global ...
102 102
103=item cf::attach_to_type ... # NYI 103=item cf::attach_to_type ...
104 104
105=item cf::attach_to_objects ... # NYI 105=item cf::attach_to_objects ...
106 106
107=item cf::attach_to_players ... # NYI 107=item cf::attach_to_players ...
108 108
109=item cf::attach_to_maps ... # NYI 109=item cf::attach_to_maps ...
110 110
111 prio => $number, # higehr is earlier 111 prio => $number, # lower is earlier
112 on_xxx => \&cb, 112 on_xxx => \&cb,
113 package => package::, 113 package => package::,
114 114
115=cut 115=cut
116 116
117our %CB_CLASS = (); # registry for class-based events 117# the following variables are defined in .xs and must not be re-created
118our @CB_GLOBAL = (); # registry for all global events 118our @CB_GLOBAL = (); # registry for all global events
119our @CB_OBJECT = ();
120our @CB_PLAYER = ();
119our @CB_TYPE = (); # registry for type (cf-object class) based events 121our @CB_TYPE = (); # registry for type (cf-object class) based events
122our @CB_MAP = ();
120 123
121sub _attach_cb($\%$$$) { 124sub _attach_cb($\%$$$) {
122 my ($registry, $undo, $event, $prio, $cb) = @_; 125 my ($registry, $undo, $event, $prio, $cb) = @_;
123 126
124 use sort 'stable'; 127 use sort 'stable';
183 186
184sub attach_global { 187sub attach_global {
185 _attach @CB_GLOBAL, KLASS_GLOBAL, @_ 188 _attach @CB_GLOBAL, KLASS_GLOBAL, @_
186} 189}
187 190
188sub attach_type { 191sub attach_to_type {
189 my $type = shift; 192 my $type = shift;
190 _attach @{$CB_TYPE[$type]}, KLASS_MAP, @_ 193 _attach @{$CB_TYPE[$type]}, KLASS_OBJECT, @_
191} 194}
192 195
193sub attach_to_objects { 196sub attach_to_objects {
194 _attach @{$CB_CLASS{cf::object::wrap::}}, KLASS_OBJECT, @_ 197 _attach @CB_OBJECT, KLASS_OBJECT, @_
195} 198}
196 199
197sub attach_to_players { 200sub attach_to_players {
198 _attach @{$CB_CLASS{cf::player::wrap::}}, KLASS_PLAYER, @_ 201 _attach @CB_PLAYER, KLASS_PLAYER, @_
199} 202}
200 203
201sub attach_to_maps { 204sub attach_to_maps {
202 _attach @{$CB_CLASS{cf::map::wrap::}}, KLASS_MAP, @_ 205 _attach @CB_MAP, KLASS_MAP, @_
203} 206}
204 207
205our $override; 208our $override;
206 209
207sub override() { 210sub override() {
208 $override = 1 211 $override = 1
209} 212}
210 213
211sub invoke { 214sub invoke {
212 my $event = shift; 215 my $event = shift;
213 216 my $callbacks = shift;
214 my @cb;
215
216 if (my $ref = ref $_[0]) {
217 # 1. object-specific (NYI)
218 # 2. class-specific
219 push @cb, @{$CB_CLASS{$ref}[$event] || []};
220 }
221
222 # global
223 push @cb, @{$CB_GLOBAL[$event] || []};
224
225# warn "invoke id $EVENT[$event][0], args <@_> <=> @cb\n";#d#
226 217
227 local $override; 218 local $override;
228 219
229 for (@cb) { 220 for (@$callbacks) {
230 eval { &{$_->[1]} }; 221 eval { &{$_->[1]} };
231 222
232 if ($@) { 223 if ($@) {
233 warn "$@"; 224 warn "$@";
234 warn "... while processing $EVENT[$event][0] event, skipping processing altogether.\n"; 225 warn "... while processing $EVENT[$event][0] event, skipping processing altogether.\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines