… | |
… | |
71 | static int tick_pending; |
71 | static int tick_pending; |
72 | |
72 | |
73 | global gbl_ev; |
73 | global gbl_ev; |
74 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
74 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
75 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
75 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
|
|
76 | static AV *av_reflect; |
76 | |
77 | |
77 | bitset<NUM_EVENT_TYPES> ev_want_event; |
78 | bitset<NUM_EVENT_TYPES> ev_want_event; |
78 | bitset<NUM_TYPES> ev_want_type; |
79 | bitset<NUM_TYPES> ev_want_type; |
79 | |
80 | |
80 | static HV |
81 | static HV |
… | |
… | |
158 | SvREFCNT_inc (self); |
159 | SvREFCNT_inc (self); |
159 | hv_clear (self); |
160 | hv_clear (self); |
160 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
161 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
161 | SvREFCNT_dec (self); |
162 | SvREFCNT_dec (self); |
162 | |
163 | |
163 | // self *must* be null now because thats sv_unmagic's job. |
164 | // self *must* be null now because that's sv_unmagic's job. |
164 | assert (!this->self); |
165 | assert (!this->self); |
165 | } |
166 | } |
166 | } |
167 | } |
167 | |
168 | |
168 | void |
169 | void |
… | |
… | |
317 | fprintf (stderr, "P %p\n", pl); |
318 | fprintf (stderr, "P %p\n", pl); |
318 | |
319 | |
319 | for_all_clients (ns) |
320 | for_all_clients (ns) |
320 | if (find_backref (ptr, ns)) |
321 | if (find_backref (ptr, ns)) |
321 | fprintf (stderr, "C %p\n", ns); |
322 | fprintf (stderr, "C %p\n", ns); |
322 | |
|
|
323 | } |
323 | } |
324 | |
324 | |
325 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
325 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
326 | |
326 | |
327 | static SV * |
327 | static SV * |
… | |
… | |
405 | croak ("perl code used %s object, but C object is already destroyed, caught", klass); |
405 | croak ("perl code used %s object, but C object is already destroyed, caught", klass); |
406 | |
406 | |
407 | return (long)mg->mg_ptr; |
407 | return (long)mg->mg_ptr; |
408 | } |
408 | } |
409 | |
409 | |
410 | static long |
410 | static long noinline |
411 | SvPTR_ornull (SV *sv, const char *klass) |
411 | SvPTR_ornull (SV *sv, const char *klass) |
412 | { |
412 | { |
413 | if (SvOK (sv)) |
413 | if (SvOK (sv)) |
414 | return SvPTR (sv, klass); |
414 | return SvPTR (sv, klass); |
415 | else |
415 | else |
… | |
… | |
607 | va_end (ap); |
607 | va_end (ap); |
608 | |
608 | |
609 | return sv; |
609 | return sv; |
610 | } |
610 | } |
611 | |
611 | |
|
|
612 | // typemap support, mostly to avoid excessive inlining |
|
|
613 | template<class type> |
|
|
614 | static void noinline |
|
|
615 | cf_obj_to (SV *arg, type &var) |
|
|
616 | { |
|
|
617 | sv_to (arg, var); |
|
|
618 | if (!var) |
|
|
619 | croak ("must not pass invalid/null cf_obj here"); |
|
|
620 | } |
|
|
621 | |
|
|
622 | template<class object> |
|
|
623 | static void noinline |
|
|
624 | cf_obj_ornull_to (SV *arg, object *&var) |
|
|
625 | { |
|
|
626 | if (SvOK (arg)) |
|
|
627 | { |
|
|
628 | sv_to (arg, var); |
|
|
629 | if (!var) |
|
|
630 | croak ("unable to convert perl object to C++ object"); |
|
|
631 | } |
|
|
632 | else |
|
|
633 | var = 0; |
|
|
634 | } |
|
|
635 | |
612 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
636 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
613 | |
637 | |
614 | SV * |
638 | SV * |
615 | registry (attachable *ext) |
639 | registry (attachable *ext) |
616 | { |
640 | { |
… | |
… | |
660 | printf ("unable to bootstrap perl, aborting:\n%s", SvPV_nolen (ERRSV)); |
684 | printf ("unable to bootstrap perl, aborting:\n%s", SvPV_nolen (ERRSV)); |
661 | exit (EXIT_FAILURE); |
685 | exit (EXIT_FAILURE); |
662 | } |
686 | } |
663 | } |
687 | } |
664 | |
688 | |
|
|
689 | void |
665 | void cfperl_main () |
690 | cfperl_main () |
666 | { |
691 | { |
667 | dSP; |
692 | dSP; |
668 | |
693 | |
669 | PUSHMARK (SP); |
694 | PUSHMARK (SP); |
670 | PUTBACK; |
695 | PUTBACK; |
… | |
… | |
695 | # undef def |
720 | # undef def |
696 | }; |
721 | }; |
697 | |
722 | |
698 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
723 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
699 | |
724 | |
700 | static void |
725 | static void noinline |
701 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
726 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
702 | { |
727 | { |
703 | // event must be in array |
728 | // event must be in array |
704 | if (event >= 0 && event <= AvFILLp (registry)) |
729 | if (event >= 0 && event <= AvFILLp (registry)) |
705 | { |
730 | { |
… | |
… | |
791 | { |
816 | { |
792 | attachable::gather_callbacks (callbacks, event); |
817 | attachable::gather_callbacks (callbacks, event); |
793 | ::gather_callbacks (callbacks, cb_map, event); |
818 | ::gather_callbacks (callbacks, cb_map, event); |
794 | } |
819 | } |
795 | |
820 | |
796 | void |
821 | static void noinline |
797 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
822 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
798 | { |
823 | { |
799 | for (int event = 0; event <= AvFILLp (registry); ++event) |
824 | for (int event = 0; event <= AvFILLp (registry); ++event) |
800 | { |
825 | { |
801 | SV *cbs_ = AvARRAY (registry)[event]; |
826 | SV *cbs_ = AvARRAY (registry)[event]; |
… | |
… | |
811 | } |
836 | } |
812 | } |
837 | } |
813 | } |
838 | } |
814 | |
839 | |
815 | // very slow and inefficient way to recalculate the global want bitsets |
840 | // very slow and inefficient way to recalculate the global want bitsets |
816 | void |
841 | static void |
817 | _recalc_want () |
842 | _recalc_want () |
818 | { |
843 | { |
819 | ev_want_event.reset (); |
844 | ev_want_event.reset (); |
820 | |
845 | |
821 | _recalc_want (ev_want_event, cb_global); |
846 | _recalc_want (ev_want_event, cb_global); |
… | |
… | |
931 | } |
956 | } |
932 | |
957 | |
933 | ///////////////////////////////////////////////////////////////////////////// |
958 | ///////////////////////////////////////////////////////////////////////////// |
934 | // various c++ => perl glue functions |
959 | // various c++ => perl glue functions |
935 | |
960 | |
|
|
961 | void |
936 | void cfperl_tick () |
962 | cfperl_tick () |
937 | { |
963 | { |
938 | tick_pending = 1; |
964 | tick_pending = 1; |
939 | |
965 | |
940 | if (tick_inhibit) |
966 | if (tick_inhibit) |
941 | return; |
967 | return; |
… | |
… | |
1003 | CALL_END; |
1029 | CALL_END; |
1004 | |
1030 | |
1005 | return can; |
1031 | return can; |
1006 | } |
1032 | } |
1007 | |
1033 | |
|
|
1034 | void |
|
|
1035 | cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator) |
|
|
1036 | { |
|
|
1037 | CALL_BEGIN (4); |
|
|
1038 | CALL_ARG (ob); |
|
|
1039 | CALL_ARG (state); |
|
|
1040 | CALL_ARG (activator); |
|
|
1041 | CALL_ARG (originator); |
|
|
1042 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
|
|
1043 | CALL_END; |
|
|
1044 | } |
|
|
1045 | |
1008 | player * |
1046 | player * |
1009 | player::find (const char *name) |
1047 | player::find (const char *name) |
1010 | { |
1048 | { |
1011 | CALL_BEGIN (1); |
1049 | CALL_BEGIN (1); |
1012 | CALL_ARG (name); |
1050 | CALL_ARG (name); |
… | |
… | |
1150 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
1188 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
1151 | CALL_END; |
1189 | CALL_END; |
1152 | #endif |
1190 | #endif |
1153 | } |
1191 | } |
1154 | |
1192 | |
|
|
1193 | bool is_match_expr (const char *expr) |
|
|
1194 | { |
|
|
1195 | return !strncmp (expr, "match ", sizeof ("match ") - 1); |
|
|
1196 | } |
|
|
1197 | |
|
|
1198 | bool match (const char *expr, object *ob, object *self, object *source, object *originator) |
|
|
1199 | { |
|
|
1200 | bool matched; |
|
|
1201 | |
|
|
1202 | CALL_BEGIN (5); |
|
|
1203 | CALL_ARG (expr); |
|
|
1204 | CALL_ARG (ob); |
|
|
1205 | CALL_ARG (self); |
|
|
1206 | CALL_ARG (source); |
|
|
1207 | CALL_ARG (originator); |
|
|
1208 | CALL_CALL ("cf::match::match", G_SCALAR); |
|
|
1209 | |
|
|
1210 | matched = count && SvTRUE (POPs); |
|
|
1211 | |
|
|
1212 | CALL_END; |
|
|
1213 | |
|
|
1214 | return matched; |
|
|
1215 | } |
|
|
1216 | |
1155 | ///////////////////////////////////////////////////////////////////////////// |
1217 | ///////////////////////////////////////////////////////////////////////////// |
1156 | |
1218 | |
1157 | struct EVAPI *evapi::GEVAPI; |
1219 | struct EVAPI *evapi::GEVAPI; |
1158 | struct CoroAPI *coroapi::GCoroAPI; |
1220 | struct CoroAPI *coroapi::GCoroAPI; |
1159 | |
1221 | |
|
|
1222 | void |
1160 | void coroapi::do_cede_to_tick () |
1223 | coroapi::do_cede_to_tick () |
1161 | { |
1224 | { |
1162 | cede_pending = 0; |
1225 | cede_pending = 0; |
1163 | cede (); |
1226 | cede (); |
1164 | } |
1227 | } |
1165 | |
1228 | |
… | |
… | |
1189 | ev_io_set ((ev_io *)this, fd, events); |
1252 | ev_io_set ((ev_io *)this, fd, events); |
1190 | if (active) start (); |
1253 | if (active) start (); |
1191 | } |
1254 | } |
1192 | } |
1255 | } |
1193 | |
1256 | |
1194 | void |
1257 | static void |
1195 | _connect_to_perl () |
1258 | _connect_to_perl () |
1196 | { |
1259 | { |
1197 | stash_cf = gv_stashpv ("cf", 1); |
1260 | stash_cf = gv_stashpv ("cf", 1); |
1198 | |
1261 | |
1199 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1262 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
… | |
… | |
1217 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1280 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1218 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1281 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1219 | cb_client = get_av ("cf::CB_CLIENT", 1); |
1282 | cb_client = get_av ("cf::CB_CLIENT", 1); |
1220 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1283 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1221 | cb_map = get_av ("cf::CB_MAP" , 1); |
1284 | cb_map = get_av ("cf::CB_MAP" , 1); |
|
|
1285 | |
|
|
1286 | av_reflect = get_av ("cf::REFLECT" , 1); |
1222 | } |
1287 | } |
1223 | |
1288 | |
1224 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1289 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1225 | |
1290 | |
1226 | BOOT: |
1291 | BOOT: |
… | |
… | |
1289 | const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON) |
1354 | 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) |
1355 | 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) |
1356 | 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) |
1357 | 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) |
1358 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
|
|
1359 | const_iv (MAPSCRIPT) const_iv (SAFE_GROUND) |
1294 | |
1360 | |
1295 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1361 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1296 | |
1362 | |
1297 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1363 | 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) |
1364 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
… | |
… | |
2104 | |
2170 | |
2105 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2171 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2106 | |
2172 | |
2107 | int calc_skill_exp (object *who, object *op, object *skill); |
2173 | int calc_skill_exp (object *who, object *op, object *skill); |
2108 | |
2174 | |
2109 | void push_button (object *op); |
2175 | void push_button (object *op, object *originator); |
2110 | |
2176 | |
2111 | void use_trigger (object *op); |
2177 | 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 | |
2178 | |
2117 | void handle_apply_yield (object *op); |
2179 | void handle_apply_yield (object *op); |
|
|
2180 | |
|
|
2181 | int convert_item (object *item, object *converter); |
2118 | |
2182 | |
2119 | |
2183 | |
2120 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2184 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2121 | |
2185 | |
2122 | # no clean way to get an object from an archetype - stupid idiotic |
2186 | # no clean way to get an object from an archetype - stupid idiotic |
… | |
… | |
2328 | void |
2392 | void |
2329 | adjust_daylight () |
2393 | adjust_daylight () |
2330 | CODE: |
2394 | CODE: |
2331 | maptile::adjust_daylight (); |
2395 | maptile::adjust_daylight (); |
2332 | |
2396 | |
|
|
2397 | int |
|
|
2398 | outdoor_darkness (int darkness = 0) |
|
|
2399 | CODE: |
|
|
2400 | RETVAL = maptile::outdoor_darkness; |
|
|
2401 | if (items) |
|
|
2402 | maptile::outdoor_darkness = darkness; |
|
|
2403 | OUTPUT: |
|
|
2404 | RETVAL |
|
|
2405 | |
2333 | void |
2406 | void |
2334 | maptile::instantiate () |
2407 | maptile::instantiate () |
2335 | |
2408 | |
2336 | maptile *new () |
2409 | maptile *new () |
2337 | PROTOTYPE: |
2410 | PROTOTYPE: |
… | |
… | |
2445 | } |
2518 | } |
2446 | |
2519 | |
2447 | int out_of_map (maptile *map, int x, int y) |
2520 | int out_of_map (maptile *map, int x, int y) |
2448 | |
2521 | |
2449 | void |
2522 | void |
2450 | trigger (maptile *map, long connection, bool state = true) |
2523 | 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: |
2524 | PPCODE: |
2457 | oblinkpt *obp = get_connection_links (map, connection); |
2525 | if (oblinkpt *obp = map->find_link (connection)) |
2458 | if (obp) |
|
|
2459 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2526 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2460 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2527 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2461 | |
2528 | |
2462 | void |
2529 | void |
2463 | get_map_flags (maptile *map, int x, int y) |
2530 | get_map_flags (maptile *map, int x, int y) |
… | |
… | |
2693 | PROTOTYPE: $ |
2760 | PROTOTYPE: $ |
2694 | CODE: |
2761 | CODE: |
2695 | RETVAL = region::find (name); |
2762 | RETVAL = region::find (name); |
2696 | OUTPUT: RETVAL |
2763 | OUTPUT: RETVAL |
2697 | |
2764 | |
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) |
2765 | int specificity (region *rgn) |
2705 | CODE: |
2766 | CODE: |
2706 | RETVAL = 0; |
2767 | RETVAL = 0; |
2707 | while (rgn = rgn->parent) |
2768 | while (rgn = rgn->parent) |
2708 | RETVAL++; |
2769 | RETVAL++; |