… | |
… | |
158 | SvREFCNT_inc (self); |
158 | SvREFCNT_inc (self); |
159 | hv_clear (self); |
159 | hv_clear (self); |
160 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
160 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
161 | SvREFCNT_dec (self); |
161 | SvREFCNT_dec (self); |
162 | |
162 | |
163 | // self *must* be null now because thats sv_unmagic's job. |
163 | // self *must* be null now because that's sv_unmagic's job. |
164 | assert (!this->self); |
164 | assert (!this->self); |
165 | } |
165 | } |
166 | } |
166 | } |
167 | |
167 | |
168 | void |
168 | void |
… | |
… | |
317 | fprintf (stderr, "P %p\n", pl); |
317 | fprintf (stderr, "P %p\n", pl); |
318 | |
318 | |
319 | for_all_clients (ns) |
319 | for_all_clients (ns) |
320 | if (find_backref (ptr, ns)) |
320 | if (find_backref (ptr, ns)) |
321 | fprintf (stderr, "C %p\n", ns); |
321 | fprintf (stderr, "C %p\n", ns); |
322 | |
|
|
323 | } |
322 | } |
324 | |
323 | |
325 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
324 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
326 | |
325 | |
327 | static SV * |
326 | static SV * |
… | |
… | |
405 | croak ("perl code used %s object, but C object is already destroyed, caught", klass); |
404 | croak ("perl code used %s object, but C object is already destroyed, caught", klass); |
406 | |
405 | |
407 | return (long)mg->mg_ptr; |
406 | return (long)mg->mg_ptr; |
408 | } |
407 | } |
409 | |
408 | |
410 | static long |
409 | static long noinline |
411 | SvPTR_ornull (SV *sv, const char *klass) |
410 | SvPTR_ornull (SV *sv, const char *klass) |
412 | { |
411 | { |
413 | if (SvOK (sv)) |
412 | if (SvOK (sv)) |
414 | return SvPTR (sv, klass); |
413 | return SvPTR (sv, klass); |
415 | else |
414 | else |
… | |
… | |
607 | va_end (ap); |
606 | va_end (ap); |
608 | |
607 | |
609 | return sv; |
608 | return sv; |
610 | } |
609 | } |
611 | |
610 | |
|
|
611 | // typemap support, mostly to avoid excessive inlining |
|
|
612 | template<class type> |
|
|
613 | static void noinline |
|
|
614 | cf_obj_to (SV *arg, type &var) |
|
|
615 | { |
|
|
616 | sv_to (arg, var); |
|
|
617 | if (!var) |
|
|
618 | croak ("must not pass invalid/null cf_obj here"); |
|
|
619 | } |
|
|
620 | |
|
|
621 | template<class object> |
|
|
622 | static void noinline |
|
|
623 | cf_obj_ornull_to (SV *arg, object *&var) |
|
|
624 | { |
|
|
625 | if (SvOK (arg)) |
|
|
626 | { |
|
|
627 | sv_to (arg, var); |
|
|
628 | if (!var) |
|
|
629 | croak ("unable to convert perl object to C++ object"); |
|
|
630 | } |
|
|
631 | else |
|
|
632 | var = 0; |
|
|
633 | } |
|
|
634 | |
612 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
635 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
613 | |
636 | |
614 | SV * |
637 | SV * |
615 | registry (attachable *ext) |
638 | registry (attachable *ext) |
616 | { |
639 | { |
… | |
… | |
660 | printf ("unable to bootstrap perl, aborting:\n%s", SvPV_nolen (ERRSV)); |
683 | printf ("unable to bootstrap perl, aborting:\n%s", SvPV_nolen (ERRSV)); |
661 | exit (EXIT_FAILURE); |
684 | exit (EXIT_FAILURE); |
662 | } |
685 | } |
663 | } |
686 | } |
664 | |
687 | |
|
|
688 | void |
665 | void cfperl_main () |
689 | cfperl_main () |
666 | { |
690 | { |
667 | dSP; |
691 | dSP; |
668 | |
692 | |
669 | PUSHMARK (SP); |
693 | PUSHMARK (SP); |
670 | PUTBACK; |
694 | PUTBACK; |
… | |
… | |
695 | # undef def |
719 | # undef def |
696 | }; |
720 | }; |
697 | |
721 | |
698 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
722 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
699 | |
723 | |
700 | static void |
724 | static void noinline |
701 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
725 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
702 | { |
726 | { |
703 | // event must be in array |
727 | // event must be in array |
704 | if (event >= 0 && event <= AvFILLp (registry)) |
728 | if (event >= 0 && event <= AvFILLp (registry)) |
705 | { |
729 | { |
… | |
… | |
791 | { |
815 | { |
792 | attachable::gather_callbacks (callbacks, event); |
816 | attachable::gather_callbacks (callbacks, event); |
793 | ::gather_callbacks (callbacks, cb_map, event); |
817 | ::gather_callbacks (callbacks, cb_map, event); |
794 | } |
818 | } |
795 | |
819 | |
796 | void |
820 | static void noinline |
797 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
821 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
798 | { |
822 | { |
799 | for (int event = 0; event <= AvFILLp (registry); ++event) |
823 | for (int event = 0; event <= AvFILLp (registry); ++event) |
800 | { |
824 | { |
801 | SV *cbs_ = AvARRAY (registry)[event]; |
825 | SV *cbs_ = AvARRAY (registry)[event]; |
… | |
… | |
811 | } |
835 | } |
812 | } |
836 | } |
813 | } |
837 | } |
814 | |
838 | |
815 | // very slow and inefficient way to recalculate the global want bitsets |
839 | // very slow and inefficient way to recalculate the global want bitsets |
816 | void |
840 | static void |
817 | _recalc_want () |
841 | _recalc_want () |
818 | { |
842 | { |
819 | ev_want_event.reset (); |
843 | ev_want_event.reset (); |
820 | |
844 | |
821 | _recalc_want (ev_want_event, cb_global); |
845 | _recalc_want (ev_want_event, cb_global); |
… | |
… | |
931 | } |
955 | } |
932 | |
956 | |
933 | ///////////////////////////////////////////////////////////////////////////// |
957 | ///////////////////////////////////////////////////////////////////////////// |
934 | // various c++ => perl glue functions |
958 | // various c++ => perl glue functions |
935 | |
959 | |
|
|
960 | void |
936 | void cfperl_tick () |
961 | cfperl_tick () |
937 | { |
962 | { |
938 | tick_pending = 1; |
963 | tick_pending = 1; |
939 | |
964 | |
940 | if (tick_inhibit) |
965 | if (tick_inhibit) |
941 | return; |
966 | return; |
… | |
… | |
1003 | CALL_END; |
1028 | CALL_END; |
1004 | |
1029 | |
1005 | return can; |
1030 | return can; |
1006 | } |
1031 | } |
1007 | |
1032 | |
|
|
1033 | void |
|
|
1034 | cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator) |
|
|
1035 | { |
|
|
1036 | CALL_BEGIN (4); |
|
|
1037 | CALL_ARG (ob); |
|
|
1038 | CALL_ARG (state); |
|
|
1039 | CALL_ARG (activator); |
|
|
1040 | CALL_ARG (originator); |
|
|
1041 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
|
|
1042 | CALL_END; |
|
|
1043 | } |
|
|
1044 | |
1008 | player * |
1045 | player * |
1009 | player::find (const char *name) |
1046 | player::find (const char *name) |
1010 | { |
1047 | { |
1011 | CALL_BEGIN (1); |
1048 | CALL_BEGIN (1); |
1012 | CALL_ARG (name); |
1049 | CALL_ARG (name); |
… | |
… | |
1155 | ///////////////////////////////////////////////////////////////////////////// |
1192 | ///////////////////////////////////////////////////////////////////////////// |
1156 | |
1193 | |
1157 | struct EVAPI *evapi::GEVAPI; |
1194 | struct EVAPI *evapi::GEVAPI; |
1158 | struct CoroAPI *coroapi::GCoroAPI; |
1195 | struct CoroAPI *coroapi::GCoroAPI; |
1159 | |
1196 | |
|
|
1197 | void |
1160 | void coroapi::do_cede_to_tick () |
1198 | coroapi::do_cede_to_tick () |
1161 | { |
1199 | { |
1162 | cede_pending = 0; |
1200 | cede_pending = 0; |
1163 | cede (); |
1201 | cede (); |
1164 | } |
1202 | } |
1165 | |
1203 | |
… | |
… | |
1189 | ev_io_set ((ev_io *)this, fd, events); |
1227 | ev_io_set ((ev_io *)this, fd, events); |
1190 | if (active) start (); |
1228 | if (active) start (); |
1191 | } |
1229 | } |
1192 | } |
1230 | } |
1193 | |
1231 | |
1194 | void |
1232 | static void |
1195 | _connect_to_perl () |
1233 | _connect_to_perl () |
1196 | { |
1234 | { |
1197 | stash_cf = gv_stashpv ("cf", 1); |
1235 | stash_cf = gv_stashpv ("cf", 1); |
1198 | |
1236 | |
1199 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1237 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
… | |
… | |
1289 | const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON) |
1327 | const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON) |
1290 | const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) |
1328 | const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) |
1291 | const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) |
1329 | const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) |
1292 | const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) |
1330 | const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) |
1293 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
1331 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
|
|
1332 | const_iv (MAPSCRIPT) const_iv (SAFE_GROUND) |
1294 | |
1333 | |
1295 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1334 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1296 | |
1335 | |
1297 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1336 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1298 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
1337 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
… | |
… | |
2104 | |
2143 | |
2105 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2144 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2106 | |
2145 | |
2107 | int calc_skill_exp (object *who, object *op, object *skill); |
2146 | int calc_skill_exp (object *who, object *op, object *skill); |
2108 | |
2147 | |
2109 | void push_button (object *op); |
2148 | void push_button (object *op, object *originator); |
2110 | |
2149 | |
2111 | void use_trigger (object *op); |
2150 | void use_trigger (object *op, object *originator); |
2112 | |
|
|
2113 | void add_button_link (object *button, maptile *map, int connected); |
|
|
2114 | |
|
|
2115 | void remove_button_link (object *op); |
|
|
2116 | |
2151 | |
2117 | void handle_apply_yield (object *op); |
2152 | void handle_apply_yield (object *op); |
|
|
2153 | |
|
|
2154 | int convert_item (object *item, object *converter); |
2118 | |
2155 | |
2119 | |
2156 | |
2120 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2157 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2121 | |
2158 | |
2122 | # no clean way to get an object from an archetype - stupid idiotic |
2159 | # no clean way to get an object from an archetype - stupid idiotic |
… | |
… | |
2328 | void |
2365 | void |
2329 | adjust_daylight () |
2366 | adjust_daylight () |
2330 | CODE: |
2367 | CODE: |
2331 | maptile::adjust_daylight (); |
2368 | maptile::adjust_daylight (); |
2332 | |
2369 | |
|
|
2370 | int |
|
|
2371 | outdoor_darkness (int darkness = 0) |
|
|
2372 | CODE: |
|
|
2373 | RETVAL = maptile::outdoor_darkness; |
|
|
2374 | if (items) |
|
|
2375 | maptile::outdoor_darkness = darkness; |
|
|
2376 | OUTPUT: |
|
|
2377 | RETVAL |
|
|
2378 | |
2333 | void |
2379 | void |
2334 | maptile::instantiate () |
2380 | maptile::instantiate () |
2335 | |
2381 | |
2336 | maptile *new () |
2382 | maptile *new () |
2337 | PROTOTYPE: |
2383 | PROTOTYPE: |
… | |
… | |
2445 | } |
2491 | } |
2446 | |
2492 | |
2447 | int out_of_map (maptile *map, int x, int y) |
2493 | int out_of_map (maptile *map, int x, int y) |
2448 | |
2494 | |
2449 | void |
2495 | void |
2450 | trigger (maptile *map, long connection, bool state = true) |
2496 | find_link (maptile *map, shstr_tmp connection) |
2451 | CODE: |
|
|
2452 | activate_connection (map, connection, state); |
|
|
2453 | |
|
|
2454 | void |
|
|
2455 | get_connection (maptile *map, long connection) |
|
|
2456 | PPCODE: |
2497 | PPCODE: |
2457 | oblinkpt *obp = get_connection_links (map, connection); |
2498 | if (oblinkpt *obp = map->find_link (connection)) |
2458 | if (obp) |
|
|
2459 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2499 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2460 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2500 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2461 | |
2501 | |
2462 | void |
2502 | void |
2463 | get_map_flags (maptile *map, int x, int y) |
2503 | get_map_flags (maptile *map, int x, int y) |
… | |
… | |
2693 | PROTOTYPE: $ |
2733 | PROTOTYPE: $ |
2694 | CODE: |
2734 | CODE: |
2695 | RETVAL = region::find (name); |
2735 | RETVAL = region::find (name); |
2696 | OUTPUT: RETVAL |
2736 | OUTPUT: RETVAL |
2697 | |
2737 | |
2698 | region *find_fuzzy (utf8_string name) |
|
|
2699 | PROTOTYPE: $ |
|
|
2700 | CODE: |
|
|
2701 | RETVAL = region::find_fuzzy (name); |
|
|
2702 | OUTPUT: RETVAL |
|
|
2703 | |
|
|
2704 | int specificity (region *rgn) |
2738 | int specificity (region *rgn) |
2705 | CODE: |
2739 | CODE: |
2706 | RETVAL = 0; |
2740 | RETVAL = 0; |
2707 | while (rgn = rgn->parent) |
2741 | while (rgn = rgn->parent) |
2708 | RETVAL++; |
2742 | RETVAL++; |