… | |
… | |
36 | |
36 | |
37 | #include <EXTERN.h> |
37 | #include <EXTERN.h> |
38 | #include <perl.h> |
38 | #include <perl.h> |
39 | #include <XSUB.h> |
39 | #include <XSUB.h> |
40 | |
40 | |
|
|
41 | #include "CoroAPI.h" |
41 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
42 | |
43 | |
43 | extern sint64 *levels; // the experience table |
44 | extern sint64 *levels; // the experience table |
44 | |
45 | |
45 | typedef object object_ornull; |
46 | typedef object object_ornull; |
… | |
… | |
59 | static f_plug_api object_set_property = cfapi_object_set_property; |
60 | static f_plug_api object_set_property = cfapi_object_set_property; |
60 | static f_plug_api object_insert = cfapi_object_insert; |
61 | static f_plug_api object_insert = cfapi_object_insert; |
61 | |
62 | |
62 | static PerlInterpreter *perl; |
63 | static PerlInterpreter *perl; |
63 | |
64 | |
|
|
65 | global gbl_ev; |
64 | static AV *cb_global, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
66 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
|
|
67 | |
|
|
68 | static HV |
|
|
69 | *stash_cf, |
|
|
70 | *stash_cf_object_wrap, |
|
|
71 | *stash_cf_object_player_wrap, |
|
|
72 | *stash_cf_player_wrap, |
|
|
73 | *stash_cf_map_wrap, |
|
|
74 | *stash_cf_client_wrap, |
|
|
75 | *stash_cf_arch_wrap, |
|
|
76 | *stash_cf_party_wrap, |
|
|
77 | *stash_cf_region_wrap, |
|
|
78 | *stash_cf_living_wrap; |
|
|
79 | |
|
|
80 | // helper cast function, returns super class * or 0 |
|
|
81 | template<class super> |
|
|
82 | static super * |
|
|
83 | is_a (attachable *at) |
|
|
84 | { |
|
|
85 | //return dynamic_cast<super *>(at); // slower, safer |
|
|
86 | if (typeid (*at) == typeid (super)) |
|
|
87 | return static_cast<super *>(at); |
|
|
88 | else |
|
|
89 | return 0; |
|
|
90 | } |
65 | |
91 | |
66 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
92 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
67 | |
93 | |
|
|
94 | unordered_vector<attachable *> attachable::mortals; |
|
|
95 | |
|
|
96 | #if 0 |
|
|
97 | attachable *attachable::rc_first; |
|
|
98 | |
|
|
99 | attachable::attachable () |
|
|
100 | { |
|
|
101 | refcnt = 0; |
|
|
102 | rc_next = rc_first; |
|
|
103 | rc_first = this; |
|
|
104 | } |
|
|
105 | #endif |
|
|
106 | |
|
|
107 | attachable::~attachable () |
|
|
108 | { |
|
|
109 | assert (!(flags & F_BORROWED));//D//TODO//remove when stable |
|
|
110 | #if 0 |
|
|
111 | assert (!rc_next); |
|
|
112 | assert (!refcnt); |
|
|
113 | #endif |
|
|
114 | } |
|
|
115 | |
|
|
116 | // check wether the object really is dead |
|
|
117 | void |
|
|
118 | attachable::do_check () |
|
|
119 | { |
|
|
120 | if (refcnt > 0) |
|
|
121 | return; |
|
|
122 | |
|
|
123 | // try to unborrow the refcnt from perl |
|
|
124 | if (flags & F_BORROWED) |
|
|
125 | { |
|
|
126 | assert (self);//D//TODO//remove when stable |
|
|
127 | flags &= ~F_BORROWED; |
|
|
128 | refcnt_inc (); |
|
|
129 | SvREFCNT_dec (self); |
|
|
130 | } |
|
|
131 | |
|
|
132 | if (refcnt > 0 || self) |
|
|
133 | return; |
|
|
134 | |
|
|
135 | destroy (); |
|
|
136 | } |
|
|
137 | |
|
|
138 | void |
|
|
139 | attachable::do_destroy () |
|
|
140 | { |
|
|
141 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
|
|
142 | |
|
|
143 | //TODO: call generic destroy callback |
|
|
144 | mortals.push_back (this); |
|
|
145 | } |
|
|
146 | |
|
|
147 | void |
|
|
148 | attachable::destroy () |
|
|
149 | { |
|
|
150 | if (destroyed ()) |
|
|
151 | return; |
|
|
152 | |
|
|
153 | flags |= F_DESTROYED; |
|
|
154 | do_destroy (); |
|
|
155 | } |
|
|
156 | |
|
|
157 | void attachable::check_mortals () |
|
|
158 | { |
|
|
159 | for (int i = 0; i < mortals.size (); ) |
|
|
160 | { |
|
|
161 | attachable *obj = mortals [i]; |
|
|
162 | |
|
|
163 | obj->refcnt_chk (); // unborrow from perl, if necessary |
|
|
164 | |
|
|
165 | if (obj->refcnt || obj->self) |
|
|
166 | { |
|
|
167 | #if 0 |
|
|
168 | if (mortals.size() > 5)fprintf (stderr, "%d delaying %d:%p:%s %d (self %p:%d)\n", time(0),i, obj, typeid (*obj).name (), |
|
|
169 | obj->refcnt, obj->self, obj->self ? SvREFCNT(obj->self): - 1);//D |
|
|
170 | #endif |
|
|
171 | |
|
|
172 | ++i; // further delay freeing |
|
|
173 | }//D |
|
|
174 | else |
|
|
175 | { |
|
|
176 | //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D |
|
|
177 | mortals.erase (i); |
|
|
178 | delete obj; |
|
|
179 | } |
|
|
180 | } |
|
|
181 | } |
|
|
182 | |
|
|
183 | attachable & |
|
|
184 | attachable::operator =(const attachable &src) |
|
|
185 | { |
|
|
186 | //if (self || cb) |
|
|
187 | //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); |
|
|
188 | |
|
|
189 | attach = src.attach; |
|
|
190 | return *this; |
|
|
191 | } |
|
|
192 | |
|
|
193 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
194 | |
68 | static SV * |
195 | static SV * |
69 | newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) |
196 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
70 | { |
197 | { |
71 | SV *sv; |
198 | SV *sv; |
72 | |
199 | |
73 | if (!ptr) |
200 | if (!ptr) |
74 | return &PL_sv_undef; |
201 | return &PL_sv_undef; |
75 | |
202 | |
76 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
203 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
77 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
204 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
78 | } |
205 | } |
79 | |
206 | |
80 | template<class attachable> |
207 | static int |
|
|
208 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
209 | { |
|
|
210 | attachable *at = (attachable *)mg->mg_ptr; |
|
|
211 | assert (!(at->flags & attachable::F_BORROWED));//D//TODO//remove when stable |
|
|
212 | at->self = 0; |
|
|
213 | // next line makes sense, but most objects still have refcnt 0 by default |
|
|
214 | //at->refcnt_chk (); |
|
|
215 | return 0; |
|
|
216 | } |
|
|
217 | |
|
|
218 | static MGVTBL vtbl_attachable = {0, 0, 0, 0, attachable_free}; |
|
|
219 | |
81 | SV * |
220 | SV * |
82 | newSVattachable (attachable *obj, const char *klass) |
221 | newSVattachable (attachable *obj, HV *stash) |
83 | { |
222 | { |
84 | if (!obj) |
223 | if (!obj) |
85 | return &PL_sv_undef; |
224 | return &PL_sv_undef; |
86 | |
225 | |
87 | if (!obj->self) |
226 | if (!obj->self) |
88 | obj->self = newSVptr (obj, klass); |
227 | { |
|
|
228 | obj->self = newHV (); |
|
|
229 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &vtbl_attachable, (char *)obj, 0); |
89 | |
230 | |
90 | return newSVsv (obj->self); |
231 | // borrow the refcnt from the object |
|
|
232 | obj->flags |= attachable::F_BORROWED; |
|
|
233 | obj->refcnt_dec (); |
|
|
234 | } |
|
|
235 | |
|
|
236 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
91 | } |
237 | } |
92 | |
238 | |
93 | static void |
239 | static void |
94 | clearSVptr (SV *sv) |
240 | clearSVptr (SV *sv) |
95 | { |
241 | { |
… | |
… | |
136 | inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
282 | inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
137 | inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
283 | inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
138 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
284 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
139 | inline SV *to_sv (float v) { return newSVnv (v); } |
285 | inline SV *to_sv (float v) { return newSVnv (v); } |
140 | inline SV *to_sv (double v) { return newSVnv (v); } |
286 | inline SV *to_sv (double v) { return newSVnv (v); } |
141 | inline SV *to_sv (client * v) { return newSVattachable (v, "cf::client::wrap"); } |
287 | inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
142 | inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } |
288 | inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
143 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); } |
289 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
144 | inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); } |
290 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
145 | inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } |
291 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
146 | inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } |
292 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
147 | inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); } |
293 | inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); } |
148 | inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } |
294 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
149 | |
295 | |
150 | inline SV *to_sv (object & v) { return to_sv (&v); } |
296 | inline SV *to_sv (object & v) { return to_sv (&v); } |
151 | inline SV *to_sv (living & v) { return to_sv (&v); } |
297 | inline SV *to_sv (living & v) { return to_sv (&v); } |
152 | |
298 | |
153 | //TODO: |
299 | //TODO: |
… | |
… | |
206 | |
352 | |
207 | if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version) |
353 | if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version) |
208 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
354 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
209 | } |
355 | } |
210 | |
356 | |
211 | inline void sv_to (SV *sv, object::flags_t::reference v) { v = boolSV (sv); } |
357 | inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); } |
212 | |
358 | |
213 | static SV * |
359 | static SV * |
214 | newSVdt_va (va_list &ap, data_type type) |
360 | newSVdt_va (va_list &ap, data_type type) |
215 | { |
361 | { |
216 | SV *sv; |
362 | SV *sv; |
… | |
… | |
323 | } |
469 | } |
324 | |
470 | |
325 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
471 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
326 | |
472 | |
327 | SV * |
473 | SV * |
328 | registry (attachable_base *ext) |
474 | registry (attachable *ext) |
329 | { |
475 | { |
330 | if (!ext->cb) |
476 | if (!ext->cb) |
331 | ext->cb = newAV (); |
477 | ext->cb = newAV (); |
332 | |
478 | |
333 | return newRV_inc ((SV *)ext->cb); |
479 | return newRV_inc ((SV *)ext->cb); |
334 | } |
480 | } |
335 | |
481 | |
|
|
482 | #if 0 |
336 | void attachable_base::clear () |
483 | void attachable::clear () |
337 | { |
484 | { |
338 | if (self) |
485 | if (self) |
339 | { |
486 | { |
340 | if (cb) |
|
|
341 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
|
|
342 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
|
|
343 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
|
|
344 | INVOKE_MAP (DESTROY, static_cast<maptile *>(this)); |
|
|
345 | |
|
|
346 | // disconnect Perl from C, to avoid crashes |
487 | // disconnect Perl from C, to avoid crashes |
347 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
488 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
348 | |
489 | |
349 | // clear the perl hash, might or might not be a good idea |
490 | // clear the perl hash, might or might not be a good idea |
350 | hv_clear ((HV *)SvRV ((SV *)self)); |
491 | hv_clear ((HV *)SvRV ((SV *)self)); |
… | |
… | |
359 | cb = 0; |
500 | cb = 0; |
360 | } |
501 | } |
361 | |
502 | |
362 | attach = 0; |
503 | attach = 0; |
363 | } |
504 | } |
|
|
505 | #endif |
364 | |
506 | |
365 | void attachable_base::optimise () |
507 | void attachable::optimise () |
366 | { |
508 | { |
367 | if (!self) |
509 | if (self |
368 | return; |
|
|
369 | |
|
|
370 | HV *hv = (HV *)SvRV ((SV *)self); |
|
|
371 | |
|
|
372 | if (SvREFCNT ((SV *)self) == 1 |
|
|
373 | && SvREFCNT ((SV *)hv) == 1 |
510 | && SvREFCNT (self) == 1 |
374 | && !HvTOTALKEYS (hv)) |
511 | && !HvTOTALKEYS (self)) |
375 | { |
512 | { |
|
|
513 | flags &= ~F_BORROWED; |
|
|
514 | refcnt_inc (); |
376 | SvREFCNT_dec ((SV *)self); |
515 | SvREFCNT_dec ((SV *)self); |
377 | self = 0; |
|
|
378 | } |
|
|
379 | } |
|
|
380 | |
|
|
381 | void attachable_base::instantiate (data_type type, void *obj) |
|
|
382 | { |
|
|
383 | dSP; |
|
|
384 | ENTER; |
|
|
385 | SAVETMPS; |
|
|
386 | PUSHMARK (SP); |
|
|
387 | EXTEND (SP, 2); |
|
|
388 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
|
|
389 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
|
|
390 | |
|
|
391 | attach = 0; |
|
|
392 | |
|
|
393 | PUTBACK; |
|
|
394 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
|
|
395 | FREETMPS; |
|
|
396 | LEAVE; |
|
|
397 | |
|
|
398 | switch (type) |
|
|
399 | { |
|
|
400 | case DT_OBJECT: INVOKE_OBJECT (INSTANTIATE, obj); break; |
|
|
401 | case DT_MAP: INVOKE_MAP (INSTANTIATE, obj); break; |
|
|
402 | } |
516 | } |
403 | } |
517 | } |
404 | |
518 | |
405 | ///////////////////////////////////////////////////////////////////////////// |
519 | ///////////////////////////////////////////////////////////////////////////// |
406 | |
|
|
407 | void reattach (data_type type, void *obj) |
|
|
408 | { |
|
|
409 | //TODO only do this when the object has _attachment's |
|
|
410 | |
|
|
411 | dSP; |
|
|
412 | ENTER; |
|
|
413 | SAVETMPS; |
|
|
414 | PUSHMARK (SP); |
|
|
415 | XPUSHs (sv_2mortal (newSVdt (type, obj))); |
|
|
416 | PUTBACK; |
|
|
417 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
|
|
418 | FREETMPS; |
|
|
419 | LEAVE; |
|
|
420 | |
|
|
421 | switch (type) |
|
|
422 | { |
|
|
423 | case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; |
|
|
424 | case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; |
|
|
425 | case DT_CLIENT: INVOKE_CLIENT (REATTACH, obj); break; |
|
|
426 | case DT_MAP: INVOKE_MAP (REATTACH, obj); break; |
|
|
427 | } |
|
|
428 | } |
|
|
429 | |
|
|
430 | template<class subclass> |
|
|
431 | void reattach (attachable<subclass> *obj) |
|
|
432 | { |
|
|
433 | obj->optimise (); |
|
|
434 | |
|
|
435 | if (obj->self) |
|
|
436 | reattach ((data_type) cftype<subclass>::dt, (subclass *)obj); |
|
|
437 | } |
|
|
438 | |
520 | |
439 | #include "kw_hash.h" |
521 | #include "kw_hash.h" |
440 | |
522 | |
441 | object_freezer::object_freezer () |
523 | object_freezer::object_freezer () |
442 | : dynbuf (128 * 1024, 64 * 1024) |
524 | : dynbuf (128 * 1024, 64 * 1024) |
… | |
… | |
447 | object_freezer::~object_freezer () |
529 | object_freezer::~object_freezer () |
448 | { |
530 | { |
449 | SvREFCNT_dec (av); |
531 | SvREFCNT_dec (av); |
450 | } |
532 | } |
451 | |
533 | |
452 | void object_freezer::put (attachable_base *ext) |
534 | void object_freezer::put (attachable *ext) |
453 | { |
535 | { |
454 | ext->optimise (); |
536 | ext->optimise (); |
455 | |
537 | |
456 | if (ext->self) |
538 | if (ext->self) |
457 | { |
539 | { |
458 | int idx = AvFILLp ((AV *)av) + 1; |
540 | int idx = AvFILLp ((AV *)av) + 1; |
459 | av_store (av, idx, SvREFCNT_inc (ext->self)); |
541 | av_store (av, idx, newRV_inc ((SV *)ext->self)); |
460 | |
542 | |
461 | add ((void *)"oid ", 4); |
543 | add ((void *)"oid ", 4); |
462 | add ((sint32)idx); |
544 | add ((sint32)idx); |
463 | add ('\n'); |
545 | add ('\n'); |
464 | } |
546 | } |
… | |
… | |
576 | text = newSVpv (data, 0); |
658 | text = newSVpv (data, 0); |
577 | sv_catpv (text, thawer_eof); |
659 | sv_catpv (text, thawer_eof); |
578 | line = SvPVbyte_nolen (text); |
660 | line = SvPVbyte_nolen (text); |
579 | } |
661 | } |
580 | |
662 | |
581 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
663 | void object_thawer::get (attachable *obj, int oid) |
582 | { |
664 | { |
583 | if (!av || oid < 0) // this is actually an error of sorts |
665 | if (!av || oid < 0) // this is actually an error of sorts |
584 | return; |
666 | return; |
585 | |
667 | |
586 | // we have to "re-instantiate"/reattach to an object, so nuke ext->attach |
668 | // object must be virgin |
587 | ext->clear (); |
669 | assert (!obj->self); |
588 | |
670 | |
589 | SV **svp = av_fetch ((AV *)av, oid, 0); |
671 | SV **svp = av_fetch ((AV *)av, oid, 0); |
590 | |
672 | |
591 | if (!svp || !SvROK (*svp)) |
673 | if (!svp || !SvROK (*svp)) |
592 | { |
674 | { |
593 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
675 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
594 | return; |
676 | return; |
595 | } |
677 | } |
596 | |
678 | |
597 | ext->self = *svp; *svp = &PL_sv_undef; |
679 | obj->self = (HV *)SvRV (*svp); |
598 | sv_magic (SvRV (ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
680 | SvRV_set (*svp, &PL_sv_undef); |
599 | |
681 | |
600 | reattach (type, obj); |
682 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &vtbl_attachable, (char *)obj, 0); |
|
|
683 | obj->reattach (); |
|
|
684 | |
|
|
685 | // borrow a refcount for the perl object |
|
|
686 | obj->flags |= attachable::F_BORROWED; |
|
|
687 | obj->refcnt_dec (); |
601 | } |
688 | } |
602 | |
689 | |
603 | object_thawer::~object_thawer () |
690 | object_thawer::~object_thawer () |
604 | { |
691 | { |
605 | if (text) SvREFCNT_dec (text); |
692 | if (text) SvREFCNT_dec (text); |
… | |
… | |
843 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
930 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
844 | |
931 | |
845 | char *argv[] = { |
932 | char *argv[] = { |
846 | "", |
933 | "", |
847 | "-e" |
934 | "-e" |
848 | "use Event;" // required for bootstrap |
935 | "use Event; use Coro;" // required for bootstrap |
849 | "cf->bootstrap;" // required for datadir :*> |
936 | "cf->bootstrap;" // required for datadir :*> |
850 | "unshift @INC, cf::datadir ();" |
937 | "unshift @INC, cf::datadir ();" |
851 | "require cf;" |
938 | "require cf;" |
852 | }; |
939 | }; |
853 | |
940 | |
854 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
941 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
… | |
… | |
863 | dSP; |
950 | dSP; |
864 | |
951 | |
865 | PUSHMARK (SP); |
952 | PUSHMARK (SP); |
866 | PUTBACK; |
953 | PUTBACK; |
867 | call_pv ("cf::main", G_DISCARD | G_VOID); |
954 | call_pv ("cf::main", G_DISCARD | G_VOID); |
|
|
955 | } |
|
|
956 | |
|
|
957 | void |
|
|
958 | attachable::instantiate () |
|
|
959 | { |
|
|
960 | if (attach) |
|
|
961 | { |
|
|
962 | invoke (EVENT_ATTACHABLE_INSTANTIATE, ARG_STRING (attach), DT_END); |
|
|
963 | attach = 0; |
|
|
964 | } |
|
|
965 | } |
|
|
966 | |
|
|
967 | void |
|
|
968 | attachable::reattach () |
|
|
969 | { |
|
|
970 | optimise (); |
|
|
971 | //TODO: check for _attachment's, very important for restarts |
|
|
972 | invoke (EVENT_ATTACHABLE_REATTACH, DT_END); |
868 | } |
973 | } |
869 | |
974 | |
870 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
975 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
871 | # define def(type,name) KLASS_ ## type, |
976 | # define def(type,name) KLASS_ ## type, |
872 | # include "eventinc.h" |
977 | # include "eventinc.h" |
… | |
… | |
903 | } |
1008 | } |
904 | } |
1009 | } |
905 | } |
1010 | } |
906 | } |
1011 | } |
907 | |
1012 | |
|
|
1013 | void |
|
|
1014 | attachable::gather_callbacks (AV *&callbacks, event_type event) const |
|
|
1015 | { |
|
|
1016 | ::gather_callbacks (callbacks, cb_attachable, event); |
|
|
1017 | |
|
|
1018 | if (cb) |
|
|
1019 | ::gather_callbacks (callbacks, cb, event); |
|
|
1020 | } |
|
|
1021 | |
|
|
1022 | void |
|
|
1023 | global::gather_callbacks (AV *&callbacks, event_type event) const |
|
|
1024 | { |
|
|
1025 | ::gather_callbacks (callbacks, cb_object, event); |
|
|
1026 | } |
|
|
1027 | |
|
|
1028 | void |
|
|
1029 | object::gather_callbacks (AV *&callbacks, event_type event) const |
|
|
1030 | { |
|
|
1031 | if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
|
|
1032 | { |
|
|
1033 | SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES]; |
|
|
1034 | |
|
|
1035 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
1036 | ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
1037 | } |
|
|
1038 | |
|
|
1039 | if (type <= AvFILLp (cb_type)) |
|
|
1040 | { |
|
|
1041 | SV *registry = AvARRAY (cb_type)[type]; |
|
|
1042 | |
|
|
1043 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
1044 | ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
1045 | } |
|
|
1046 | |
|
|
1047 | attachable::gather_callbacks (callbacks, event); |
|
|
1048 | ::gather_callbacks (callbacks, cb_object, event); |
|
|
1049 | } |
|
|
1050 | |
|
|
1051 | void |
|
|
1052 | archetype::gather_callbacks (AV *&callbacks, event_type event) const |
|
|
1053 | { |
|
|
1054 | attachable::gather_callbacks (callbacks, event); |
|
|
1055 | //TODO//::gather_callbacks (callbacks, cb_archetype, event); |
|
|
1056 | } |
|
|
1057 | |
|
|
1058 | void |
|
|
1059 | client::gather_callbacks (AV *&callbacks, event_type event) const |
|
|
1060 | { |
|
|
1061 | attachable::gather_callbacks (callbacks, event); |
|
|
1062 | ::gather_callbacks (callbacks, cb_client, event); |
|
|
1063 | } |
|
|
1064 | |
|
|
1065 | void |
|
|
1066 | player::gather_callbacks (AV *&callbacks, event_type event) const |
|
|
1067 | { |
|
|
1068 | attachable::gather_callbacks (callbacks, event); |
|
|
1069 | ::gather_callbacks (callbacks, cb_player, event); |
|
|
1070 | } |
|
|
1071 | |
|
|
1072 | void |
|
|
1073 | maptile::gather_callbacks (AV *&callbacks, event_type event) const |
|
|
1074 | { |
|
|
1075 | attachable::gather_callbacks (callbacks, event); |
|
|
1076 | ::gather_callbacks (callbacks, cb_map, event); |
|
|
1077 | } |
|
|
1078 | |
|
|
1079 | bool |
908 | bool cfperl_invoke (event_type event, ...) |
1080 | attachable::invoke (event_type event, ...) |
909 | { |
1081 | { |
910 | data_type dt; |
1082 | data_type dt; |
911 | va_list ap; |
1083 | va_list ap; |
912 | |
1084 | |
913 | va_start (ap, event); |
1085 | va_start (ap, event); |
914 | |
1086 | |
915 | AV *callbacks = 0; |
|
|
916 | |
|
|
917 | object *op; |
|
|
918 | player *pl; |
|
|
919 | maptile *map; |
|
|
920 | client *ns; |
|
|
921 | |
|
|
922 | // callback call ordering is: |
1087 | // callback call ordering should be: |
923 | // 1. per-object callback |
1088 | // 1. per-object callback |
924 | // 2. per-class object |
1089 | // 2. per-class object |
925 | // 3. per-type callback |
1090 | // 3. per-type callback |
926 | // 4. global callbacks |
1091 | // 4. global callbacks |
927 | |
1092 | |
|
|
1093 | AV *callbacks = 0; |
928 | gather_callbacks (callbacks, cb_global, event); |
1094 | gather_callbacks (callbacks, event); |
929 | |
|
|
930 | switch (KLASS_OF (event)) |
|
|
931 | { |
|
|
932 | case KLASS_GLOBAL: |
|
|
933 | break; |
|
|
934 | |
|
|
935 | case KLASS_OBJECT: |
|
|
936 | dt = (data_type) va_arg (ap, int); |
|
|
937 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
|
|
938 | op = va_arg (ap, object *); |
|
|
939 | |
|
|
940 | if (op->cb) |
|
|
941 | gather_callbacks (callbacks, op->cb, event); |
|
|
942 | |
|
|
943 | if (op->type) |
|
|
944 | { |
|
|
945 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
|
|
946 | { |
|
|
947 | SV *registry = AvARRAY (cb_type)[op->type + op->subtype * NUM_SUBTYPES]; |
|
|
948 | |
|
|
949 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
950 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
951 | } |
|
|
952 | |
|
|
953 | if (op->type <= AvFILLp (cb_type)) |
|
|
954 | { |
|
|
955 | SV *registry = AvARRAY (cb_type)[op->type]; |
|
|
956 | |
|
|
957 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
958 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
959 | } |
|
|
960 | } |
|
|
961 | |
|
|
962 | gather_callbacks (callbacks, cb_object, event); |
|
|
963 | |
|
|
964 | break; |
|
|
965 | |
|
|
966 | case KLASS_PLAYER: |
|
|
967 | dt = (data_type) va_arg (ap, int); |
|
|
968 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
|
|
969 | pl = va_arg (ap, player *); |
|
|
970 | |
|
|
971 | if (pl->cb) |
|
|
972 | gather_callbacks (callbacks, pl->cb, event); |
|
|
973 | |
|
|
974 | gather_callbacks (callbacks, cb_player, event); |
|
|
975 | break; |
|
|
976 | |
|
|
977 | case KLASS_MAP: |
|
|
978 | dt = (data_type) va_arg (ap, int); |
|
|
979 | assert (("first argument must be of type object", dt == DT_MAP)); |
|
|
980 | map = va_arg (ap, maptile *); |
|
|
981 | |
|
|
982 | if (map->cb) |
|
|
983 | gather_callbacks (callbacks, map->cb, event); |
|
|
984 | |
|
|
985 | gather_callbacks (callbacks, cb_map, event); |
|
|
986 | break; |
|
|
987 | |
|
|
988 | case KLASS_CLIENT: |
|
|
989 | dt = (data_type) va_arg (ap, int); |
|
|
990 | assert (("first argument must be of type client", dt == DT_CLIENT)); |
|
|
991 | ns = va_arg (ap, client *); |
|
|
992 | |
|
|
993 | if (ns->cb) |
|
|
994 | gather_callbacks (callbacks, ns->cb, event); |
|
|
995 | |
|
|
996 | gather_callbacks (callbacks, cb_client, event); |
|
|
997 | break; |
|
|
998 | |
|
|
999 | default: |
|
|
1000 | assert (("unsupported event klass in cfperl_invoke", 0)); |
|
|
1001 | } |
|
|
1002 | |
1095 | |
1003 | // short-circuit processing if no callbacks found/defined |
1096 | // short-circuit processing if no callbacks found/defined |
1004 | if (!callbacks) |
1097 | if (!callbacks) |
1005 | return 0; |
1098 | return 0; |
1006 | |
1099 | |
… | |
… | |
1012 | EXTEND (SP, 3); |
1105 | EXTEND (SP, 3); |
1013 | |
1106 | |
1014 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
1107 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
1015 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
1108 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
1016 | |
1109 | |
1017 | switch (KLASS_OF (event)) |
1110 | //TODO: unhack |
1018 | { |
1111 | if (object *op = is_a<object>(this)) PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); |
1019 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
1112 | else if (player *pl = is_a<player>(this)) PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); |
1020 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
1113 | else if (client *ns = is_a<client>(this)) PUSHs (sv_2mortal (newSVdt (DT_CLIENT, ns))); |
1021 | case KLASS_CLIENT: PUSHs (sv_2mortal (newSVdt (DT_CLIENT, ns))); break; |
1114 | else if (maptile *m = is_a<maptile>(this)) PUSHs (sv_2mortal (newSVdt (DT_MAP, m))); |
1022 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
1115 | else if (global *gl = is_a<global>(this)) /*nop*/; |
1023 | } |
1116 | else |
|
|
1117 | abort (); //TODO |
1024 | |
1118 | |
1025 | for (;;) |
1119 | for (;;) |
1026 | { |
1120 | { |
1027 | dt = (data_type) va_arg (ap, int); |
1121 | dt = (data_type) va_arg (ap, int); |
1028 | |
1122 | |
1029 | if (dt == DT_END) |
1123 | if (dt == DT_END) |
1030 | break; |
1124 | break; |
1031 | |
|
|
1032 | if (dt == DT_AV) |
1125 | else if (dt == DT_AV) |
1033 | { |
1126 | { |
1034 | AV *av = va_arg (ap, AV *); |
1127 | AV *av = va_arg (ap, AV *); |
1035 | |
1128 | |
1036 | for (int i = 0; i <= av_len (av); ++i) |
1129 | for (int i = 0; i <= av_len (av); ++i) |
1037 | XPUSHs (*av_fetch (av, i, 1)); |
1130 | XPUSHs (*av_fetch (av, i, 1)); |
… | |
… | |
1138 | pe->poll = events; |
1231 | pe->poll = events; |
1139 | if (pe->poll) start (); |
1232 | if (pe->poll) start (); |
1140 | } |
1233 | } |
1141 | } |
1234 | } |
1142 | |
1235 | |
|
|
1236 | void |
|
|
1237 | _connect_to_perl () |
|
|
1238 | { |
|
|
1239 | stash_cf = gv_stashpv ("cf" , 1); |
|
|
1240 | |
|
|
1241 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
|
|
1242 | stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); |
|
|
1243 | stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); |
|
|
1244 | stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); |
|
|
1245 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
|
|
1246 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
|
|
1247 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
|
|
1248 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
|
|
1249 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
|
|
1250 | |
|
|
1251 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
|
|
1252 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
|
|
1253 | cb_object = get_av ("cf::CB_OBJECT", 1); |
|
|
1254 | cb_player = get_av ("cf::CB_PLAYER", 1); |
|
|
1255 | cb_client = get_av ("cf::CB_CLIENT", 1); |
|
|
1256 | cb_type = get_av ("cf::CB_TYPE" , 1); |
|
|
1257 | cb_map = get_av ("cf::CB_MAP" , 1); |
|
|
1258 | } |
|
|
1259 | |
1143 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1260 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1144 | |
1261 | |
1145 | BOOT: |
1262 | BOOT: |
1146 | { |
1263 | { |
1147 | HV *stash = gv_stashpv ("cf", 1); |
1264 | _connect_to_perl (); |
1148 | |
1265 | |
1149 | I_EVENT_API (PACKAGE); |
1266 | I_EVENT_API (PACKAGE); |
1150 | watcher_base::GEventAPI = GEventAPI; |
1267 | watcher_base::GEventAPI = GEventAPI; |
|
|
1268 | I_CORO_API (PACKAGE); |
1151 | |
1269 | |
1152 | newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1270 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1153 | |
1271 | |
1154 | static const struct { |
1272 | static const struct { |
1155 | const char *name; |
1273 | const char *name; |
1156 | IV iv; |
1274 | IV iv; |
1157 | } *civ, const_iv[] = { |
1275 | } *civ, const_iv[] = { |
… | |
… | |
1623 | const_iv (MAP_IN_MEMORY) |
1741 | const_iv (MAP_IN_MEMORY) |
1624 | const_iv (MAP_SWAPPED) |
1742 | const_iv (MAP_SWAPPED) |
1625 | const_iv (MAP_LOADING) |
1743 | const_iv (MAP_LOADING) |
1626 | const_iv (MAP_SAVING) |
1744 | const_iv (MAP_SAVING) |
1627 | |
1745 | |
|
|
1746 | const_iv (KLASS_ATTACHABLE) |
1628 | const_iv (KLASS_GLOBAL) |
1747 | const_iv (KLASS_GLOBAL) |
1629 | const_iv (KLASS_OBJECT) |
1748 | const_iv (KLASS_OBJECT) |
1630 | const_iv (KLASS_CLIENT) |
1749 | const_iv (KLASS_CLIENT) |
1631 | const_iv (KLASS_PLAYER) |
1750 | const_iv (KLASS_PLAYER) |
1632 | const_iv (KLASS_MAP) |
1751 | const_iv (KLASS_MAP) |
… | |
… | |
1644 | const_iv (ST_CONFIRM_QUIT) |
1763 | const_iv (ST_CONFIRM_QUIT) |
1645 | const_iv (ST_GET_PARTY_PASSWORD) |
1764 | const_iv (ST_GET_PARTY_PASSWORD) |
1646 | }; |
1765 | }; |
1647 | |
1766 | |
1648 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1767 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1649 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1768 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1650 | |
1769 | |
1651 | static const struct { |
1770 | static const struct { |
1652 | const char *name; |
1771 | const char *name; |
1653 | int skip; |
1772 | int skip; |
1654 | IV klass; |
1773 | IV klass; |
… | |
… | |
1665 | { |
1784 | { |
1666 | AV *event = newAV (); |
1785 | AV *event = newAV (); |
1667 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1786 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1668 | av_push (event, newSViv (eiv->klass)); |
1787 | av_push (event, newSViv (eiv->klass)); |
1669 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1788 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1670 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1789 | newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); |
1671 | } |
1790 | } |
1672 | } |
1791 | } |
1673 | |
1792 | |
1674 | void _init_vars () |
1793 | void _connect_to_perl () |
1675 | CODE: |
|
|
1676 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
|
|
1677 | cb_object = get_av ("cf::CB_OBJECT", 1); |
|
|
1678 | cb_player = get_av ("cf::CB_PLAYER", 1); |
|
|
1679 | cb_client = get_av ("cf::CB_CLIENT", 1); |
|
|
1680 | cb_type = get_av ("cf::CB_TYPE" , 1); |
|
|
1681 | cb_map = get_av ("cf::CB_MAP" , 1); |
|
|
1682 | |
1794 | |
1683 | void _global_reattach () |
1795 | void _global_reattach () |
1684 | CODE: |
1796 | CODE: |
1685 | { |
1797 | { |
1686 | // reattach to all attachable objects in the game. |
1798 | // reattach to all attachable objects in the game. |
1687 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
1799 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
1688 | reattach (*i); |
1800 | (*i)->reattach (); |
1689 | |
1801 | |
1690 | for (player *pl = first_player; pl; pl = pl->next) |
1802 | for_all_players (pl) |
1691 | reattach (pl); |
1803 | pl->reattach (); |
1692 | |
1804 | |
1693 | for (maptile *map = first_map; map; map = map->next) |
1805 | for_all_maps (m) |
1694 | reattach (map); |
1806 | m->reattach (); |
1695 | |
1807 | |
1696 | for (object *op = object::first; op; op = op->next) |
1808 | for (object *op = object::first; op; op = op->next) |
1697 | reattach (op); |
1809 | op->reattach (); |
1698 | } |
1810 | } |
1699 | |
1811 | |
1700 | NV floor (NV x) |
1812 | NV floor (NV x) |
1701 | |
1813 | |
1702 | NV ceil (NV x) |
1814 | NV ceil (NV x) |
… | |
… | |
1813 | int invoke (SV *klass, int event, ...) |
1925 | int invoke (SV *klass, int event, ...) |
1814 | CODE: |
1926 | CODE: |
1815 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1927 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1816 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1928 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1817 | for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1929 | for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1818 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
1930 | RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); |
1819 | OUTPUT: RETVAL |
1931 | OUTPUT: RETVAL |
1820 | |
1932 | |
1821 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1933 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1822 | |
1934 | |
1823 | INCLUDE: $PERL genacc object ../include/object.h | |
1935 | INCLUDE: $PERL genacc object ../include/object.h | |
… | |
… | |
1825 | int invoke (object *op, int event, ...) |
1937 | int invoke (object *op, int event, ...) |
1826 | CODE: |
1938 | CODE: |
1827 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1939 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1828 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1940 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1829 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1941 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1830 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
1942 | RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); |
1831 | OUTPUT: RETVAL |
1943 | OUTPUT: RETVAL |
1832 | |
1944 | |
1833 | SV *registry (object *op) |
1945 | SV *registry (object *op) |
1834 | |
1946 | |
1835 | void mortals () |
1947 | void mortals () |
… | |
… | |
1889 | |
2001 | |
1890 | object *find_best_object_match (object *op, const char *match) |
2002 | object *find_best_object_match (object *op, const char *match) |
1891 | |
2003 | |
1892 | object *find_marked_object (object *op) |
2004 | object *find_marked_object (object *op) |
1893 | |
2005 | |
1894 | int need_identify (const object *obj); |
2006 | int need_identify (object *obj); |
1895 | |
2007 | |
1896 | int apply_shop_mat (object *shop_mat, object *op); |
2008 | int apply_shop_mat (object *shop_mat, object *op); |
1897 | |
2009 | |
1898 | int move (object *op, int dir, object *originator = op) |
2010 | int move (object *op, int dir, object *originator = op) |
1899 | CODE: |
2011 | CODE: |
… | |
… | |
1912 | void remove (object *op) |
2024 | void remove (object *op) |
1913 | CODE: |
2025 | CODE: |
1914 | op->remove (); |
2026 | op->remove (); |
1915 | |
2027 | |
1916 | void |
2028 | void |
1917 | object::destroy (int recursive = 0) |
2029 | object::destroy (bool destroy_inventory = false) |
|
|
2030 | |
|
|
2031 | void |
|
|
2032 | object::destroy_inv (bool drop_to_ground = false) |
|
|
2033 | |
|
|
2034 | void |
|
|
2035 | object::set_speed (float speed) |
1918 | |
2036 | |
1919 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
2037 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1920 | |
2038 | |
1921 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
2039 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1922 | |
2040 | |
… | |
… | |
1963 | OUTPUT: RETVAL |
2081 | OUTPUT: RETVAL |
1964 | |
2082 | |
1965 | int query_money (object *op) |
2083 | int query_money (object *op) |
1966 | ALIAS: money = 0 |
2084 | ALIAS: money = 0 |
1967 | |
2085 | |
1968 | int query_cost (object *op, object *who, int flags) |
2086 | val64 query_cost (object *op, object *who, int flags) |
1969 | ALIAS: cost = 0 |
2087 | ALIAS: cost = 0 |
1970 | |
2088 | |
1971 | void spring_trap (object *op, object *victim) |
2089 | void spring_trap (object *op, object *victim) |
1972 | |
2090 | |
1973 | int check_trigger (object *op, object *cause) |
2091 | int check_trigger (object *op, object *cause) |
… | |
… | |
2135 | int invoke (player *pl, int event, ...) |
2253 | int invoke (player *pl, int event, ...) |
2136 | CODE: |
2254 | CODE: |
2137 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2255 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2138 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2256 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2139 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2257 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2140 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
2258 | RETVAL = pl->invoke ((event_type)event, ARG_AV (av), DT_END); |
2141 | OUTPUT: RETVAL |
2259 | OUTPUT: RETVAL |
2142 | |
2260 | |
2143 | SV *registry (player *pl) |
2261 | SV *registry (player *pl) |
2144 | |
2262 | |
2145 | player * |
2263 | player * |
… | |
… | |
2264 | int invoke (maptile *map, int event, ...) |
2382 | int invoke (maptile *map, int event, ...) |
2265 | CODE: |
2383 | CODE: |
2266 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2384 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2267 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2385 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2268 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2386 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2269 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2387 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2270 | OUTPUT: RETVAL |
2388 | OUTPUT: RETVAL |
2271 | |
2389 | |
2272 | SV *registry (maptile *map) |
2390 | SV *registry (maptile *map) |
2273 | |
2391 | |
2274 | INCLUDE: $PERL genacc maptile ../include/map.h | |
2392 | INCLUDE: $PERL genacc maptile ../include/map.h | |
… | |
… | |
2384 | move_block_at = 4 |
2502 | move_block_at = 4 |
2385 | move_slow_at = 5 |
2503 | move_slow_at = 5 |
2386 | move_on_at = 6 |
2504 | move_on_at = 6 |
2387 | move_off_at = 7 |
2505 | move_off_at = 7 |
2388 | INIT: |
2506 | INIT: |
2389 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF; |
2507 | if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; |
2390 | CODE: |
2508 | CODE: |
2391 | switch (ix) |
2509 | switch (ix) |
2392 | { |
2510 | { |
2393 | case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; |
2511 | case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; |
2394 | case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; |
2512 | case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; |
… | |
… | |
2493 | int invoke (client *ns, int event, ...) |
2611 | int invoke (client *ns, int event, ...) |
2494 | CODE: |
2612 | CODE: |
2495 | if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); |
2613 | if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); |
2496 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2614 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2497 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2615 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2498 | RETVAL = INVOKE_((event_type)event, ARG_CLIENT (ns), ARG_AV (av)); |
2616 | RETVAL = ns->invoke ((event_type)event, ARG_AV (av), DT_END); |
2499 | OUTPUT: RETVAL |
2617 | OUTPUT: RETVAL |
2500 | |
2618 | |
2501 | SV *registry (client *ns) |
2619 | SV *registry (client *ns) |
2502 | |
2620 | |
2503 | void |
2621 | void |