… | |
… | |
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 |
… | |
… | |
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, object *activator, int state) |
|
|
1036 | { |
|
|
1037 | CALL_BEGIN (3); |
|
|
1038 | CALL_ARG (ob); |
|
|
1039 | CALL_ARG (activator); |
|
|
1040 | CALL_ARG (state); |
|
|
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); |
… | |
… | |
1074 | maptile::do_load_sync () |
1111 | maptile::do_load_sync () |
1075 | { |
1112 | { |
1076 | CALL_BEGIN (1); |
1113 | CALL_BEGIN (1); |
1077 | CALL_ARG (this); |
1114 | CALL_ARG (this); |
1078 | CALL_CALL ("cf::map::do_load_sync", G_SCALAR); |
1115 | CALL_CALL ("cf::map::do_load_sync", G_SCALAR); |
1079 | CALL_END; |
|
|
1080 | } |
|
|
1081 | |
|
|
1082 | void |
|
|
1083 | maptile::change_all_map_light (int change) |
|
|
1084 | { |
|
|
1085 | CALL_BEGIN (1); |
|
|
1086 | CALL_ARG (change); |
|
|
1087 | CALL_CALL ("cf::map::change_all_map_light", G_VOID); |
|
|
1088 | CALL_END; |
1116 | CALL_END; |
1089 | } |
1117 | } |
1090 | |
1118 | |
1091 | void |
1119 | void |
1092 | object::enter_exit (object *exit) |
1120 | object::enter_exit (object *exit) |
… | |
… | |
1164 | ///////////////////////////////////////////////////////////////////////////// |
1192 | ///////////////////////////////////////////////////////////////////////////// |
1165 | |
1193 | |
1166 | struct EVAPI *evapi::GEVAPI; |
1194 | struct EVAPI *evapi::GEVAPI; |
1167 | struct CoroAPI *coroapi::GCoroAPI; |
1195 | struct CoroAPI *coroapi::GCoroAPI; |
1168 | |
1196 | |
|
|
1197 | void |
1169 | void coroapi::do_cede_to_tick () |
1198 | coroapi::do_cede_to_tick () |
1170 | { |
1199 | { |
1171 | cede_pending = 0; |
1200 | cede_pending = 0; |
1172 | cede (); |
1201 | cede (); |
1173 | } |
1202 | } |
1174 | |
1203 | |
… | |
… | |
1198 | ev_io_set ((ev_io *)this, fd, events); |
1227 | ev_io_set ((ev_io *)this, fd, events); |
1199 | if (active) start (); |
1228 | if (active) start (); |
1200 | } |
1229 | } |
1201 | } |
1230 | } |
1202 | |
1231 | |
1203 | void |
1232 | static void |
1204 | _connect_to_perl () |
1233 | _connect_to_perl () |
1205 | { |
1234 | { |
1206 | stash_cf = gv_stashpv ("cf", 1); |
1235 | stash_cf = gv_stashpv ("cf", 1); |
1207 | |
1236 | |
1208 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1237 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
… | |
… | |
1298 | 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) |
1299 | 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) |
1300 | 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) |
1301 | 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) |
1302 | 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) |
1303 | |
1333 | |
1304 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1334 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1305 | |
1335 | |
1306 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1336 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1307 | 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) |
… | |
… | |
1339 | const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED) |
1369 | const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED) |
1340 | const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON) |
1370 | const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON) |
1341 | const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON) |
1371 | const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON) |
1342 | const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_DEBUG) const_iv (FLAG_BERSERK) |
1372 | const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_DEBUG) const_iv (FLAG_BERSERK) |
1343 | const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL) |
1373 | const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL) |
1344 | const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER) |
1374 | const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER) const_iv (FLAG_WIZLOOK) |
1345 | const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE) |
1375 | const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE) |
1346 | const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE) |
1376 | const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE) |
1347 | |
1377 | |
1348 | const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) |
1378 | const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) |
1349 | const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) |
1379 | const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) |
… | |
… | |
1600 | |
1630 | |
1601 | void init_attackmess () |
1631 | void init_attackmess () |
1602 | |
1632 | |
1603 | void init_dynamic () |
1633 | void init_dynamic () |
1604 | |
1634 | |
1605 | void init_block () |
|
|
1606 | |
|
|
1607 | void load_settings () |
1635 | void load_settings () |
1608 | |
1636 | |
1609 | void load_materials () |
1637 | void load_materials () |
1610 | |
1638 | |
1611 | void init_uuid () |
1639 | void init_uuid () |
… | |
… | |
2119 | |
2147 | |
2120 | void push_button (object *op); |
2148 | void push_button (object *op); |
2121 | |
2149 | |
2122 | void use_trigger (object *op); |
2150 | void use_trigger (object *op); |
2123 | |
2151 | |
2124 | void add_button_link (object *button, maptile *map, int connected); |
|
|
2125 | |
|
|
2126 | void remove_button_link (object *op); |
|
|
2127 | |
|
|
2128 | void handle_apply_yield (object *op); |
2152 | void handle_apply_yield (object *op); |
2129 | |
2153 | |
2130 | |
2154 | |
2131 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2155 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2132 | |
2156 | |
… | |
… | |
2250 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
2274 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
2251 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2275 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2252 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2276 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2253 | pl->orig_stats = pl->ob->stats; |
2277 | pl->orig_stats = pl->ob->stats; |
2254 | |
2278 | |
2255 | void clear_los (player *pl) |
|
|
2256 | |
|
|
2257 | # should only be temporary |
2279 | # should only be temporary |
2258 | void esrv_new_player (player *pl) |
2280 | void esrv_new_player (player *pl) |
2259 | |
2281 | |
|
|
2282 | #d# TODO: replace by blocked_los accessor, fix code using this |
2260 | bool |
2283 | bool |
2261 | cell_visible (player *pl, int dx, int dy) |
2284 | cell_visible (player *pl, int dx, int dy) |
2262 | CODE: |
2285 | CODE: |
2263 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
2286 | RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; |
2264 | && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]; |
|
|
2265 | OUTPUT: |
2287 | OUTPUT: |
2266 | RETVAL |
2288 | RETVAL |
2267 | |
2289 | |
2268 | void |
2290 | void |
2269 | send (player *pl, SV *packet) |
2291 | send (player *pl, SV *packet) |
… | |
… | |
2337 | } |
2359 | } |
2338 | |
2360 | |
2339 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2361 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2340 | |
2362 | |
2341 | void |
2363 | void |
|
|
2364 | adjust_daylight () |
|
|
2365 | CODE: |
|
|
2366 | maptile::adjust_daylight (); |
|
|
2367 | |
|
|
2368 | void |
2342 | maptile::instantiate () |
2369 | maptile::instantiate () |
2343 | |
2370 | |
2344 | maptile *new () |
2371 | maptile *new () |
2345 | PROTOTYPE: |
2372 | PROTOTYPE: |
2346 | CODE: |
2373 | CODE: |
… | |
… | |
2453 | } |
2480 | } |
2454 | |
2481 | |
2455 | int out_of_map (maptile *map, int x, int y) |
2482 | int out_of_map (maptile *map, int x, int y) |
2456 | |
2483 | |
2457 | void |
2484 | void |
2458 | trigger (maptile *map, long connection, bool state = true) |
2485 | find_link (maptile *map, shstr_tmp connection) |
2459 | CODE: |
|
|
2460 | activate_connection (map, connection, state); |
|
|
2461 | |
|
|
2462 | void |
|
|
2463 | get_connection (maptile *map, long connection) |
|
|
2464 | PPCODE: |
2486 | PPCODE: |
2465 | oblinkpt *obp = get_connection_links (map, connection); |
2487 | if (oblinkpt *obp = map->find_link (connection)) |
2466 | if (obp) |
|
|
2467 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2488 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2468 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2489 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2469 | |
2490 | |
2470 | void |
2491 | void |
2471 | get_map_flags (maptile *map, int x, int y) |
2492 | get_map_flags (maptile *map, int x, int y) |
… | |
… | |
2701 | PROTOTYPE: $ |
2722 | PROTOTYPE: $ |
2702 | CODE: |
2723 | CODE: |
2703 | RETVAL = region::find (name); |
2724 | RETVAL = region::find (name); |
2704 | OUTPUT: RETVAL |
2725 | OUTPUT: RETVAL |
2705 | |
2726 | |
2706 | region *find_fuzzy (utf8_string name) |
|
|
2707 | PROTOTYPE: $ |
|
|
2708 | CODE: |
|
|
2709 | RETVAL = region::find_fuzzy (name); |
|
|
2710 | OUTPUT: RETVAL |
|
|
2711 | |
|
|
2712 | int specificity (region *rgn) |
2727 | int specificity (region *rgn) |
2713 | CODE: |
2728 | CODE: |
2714 | RETVAL = 0; |
2729 | RETVAL = 0; |
2715 | while (rgn = rgn->parent) |
2730 | while (rgn = rgn->parent) |
2716 | RETVAL++; |
2731 | RETVAL++; |