… | |
… | |
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; |
… | |
… | |
1078 | CALL_CALL ("cf::map::do_load_sync", G_SCALAR); |
1104 | CALL_CALL ("cf::map::do_load_sync", G_SCALAR); |
1079 | CALL_END; |
1105 | CALL_END; |
1080 | } |
1106 | } |
1081 | |
1107 | |
1082 | void |
1108 | 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; |
|
|
1089 | } |
|
|
1090 | |
|
|
1091 | void |
|
|
1092 | object::enter_exit (object *exit) |
1109 | object::enter_exit (object *exit) |
1093 | { |
1110 | { |
1094 | if (type != PLAYER) |
1111 | if (type != PLAYER) |
1095 | return; |
1112 | return; |
1096 | |
1113 | |
… | |
… | |
1164 | ///////////////////////////////////////////////////////////////////////////// |
1181 | ///////////////////////////////////////////////////////////////////////////// |
1165 | |
1182 | |
1166 | struct EVAPI *evapi::GEVAPI; |
1183 | struct EVAPI *evapi::GEVAPI; |
1167 | struct CoroAPI *coroapi::GCoroAPI; |
1184 | struct CoroAPI *coroapi::GCoroAPI; |
1168 | |
1185 | |
|
|
1186 | void |
1169 | void coroapi::do_cede_to_tick () |
1187 | coroapi::do_cede_to_tick () |
1170 | { |
1188 | { |
1171 | cede_pending = 0; |
1189 | cede_pending = 0; |
1172 | cede (); |
1190 | cede (); |
1173 | } |
1191 | } |
1174 | |
1192 | |
… | |
… | |
1198 | ev_io_set ((ev_io *)this, fd, events); |
1216 | ev_io_set ((ev_io *)this, fd, events); |
1199 | if (active) start (); |
1217 | if (active) start (); |
1200 | } |
1218 | } |
1201 | } |
1219 | } |
1202 | |
1220 | |
1203 | void |
1221 | static void |
1204 | _connect_to_perl () |
1222 | _connect_to_perl () |
1205 | { |
1223 | { |
1206 | stash_cf = gv_stashpv ("cf", 1); |
1224 | stash_cf = gv_stashpv ("cf", 1); |
1207 | |
1225 | |
1208 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1226 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
… | |
… | |
1339 | const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED) |
1357 | 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) |
1358 | 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) |
1359 | 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) |
1360 | 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) |
1361 | 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) |
1362 | 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) |
1363 | 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) |
1364 | const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE) |
1347 | |
1365 | |
1348 | const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) |
1366 | 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) |
1367 | const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) |
… | |
… | |
1600 | |
1618 | |
1601 | void init_attackmess () |
1619 | void init_attackmess () |
1602 | |
1620 | |
1603 | void init_dynamic () |
1621 | void init_dynamic () |
1604 | |
1622 | |
1605 | void init_block () |
|
|
1606 | |
|
|
1607 | void load_settings () |
1623 | void load_settings () |
1608 | |
1624 | |
1609 | void load_materials () |
1625 | void load_materials () |
1610 | |
1626 | |
1611 | void init_uuid () |
1627 | void init_uuid () |
… | |
… | |
1795 | PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks))); |
1811 | PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks))); |
1796 | PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks))); |
1812 | PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks))); |
1797 | PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks))); |
1813 | PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks))); |
1798 | PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost))); |
1814 | PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost))); |
1799 | #endif |
1815 | #endif |
1800 | EXTEND (SP, 2*2); |
1816 | EXTEND (SP, 5*2); |
1801 | PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); |
1817 | PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); |
1802 | PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); |
1818 | PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); |
1803 | PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
1819 | PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
|
|
1820 | PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); |
|
|
1821 | PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); |
1804 | } |
1822 | } |
1805 | |
1823 | |
1806 | int find_animation (utf8_string text) |
1824 | int find_animation (utf8_string text) |
1807 | PROTOTYPE: $ |
1825 | PROTOTYPE: $ |
1808 | |
1826 | |
… | |
… | |
2248 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
2266 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
2249 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2267 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2250 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2268 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2251 | pl->orig_stats = pl->ob->stats; |
2269 | pl->orig_stats = pl->ob->stats; |
2252 | |
2270 | |
2253 | void clear_los (player *pl) |
2271 | # should only be temporary |
2254 | |
|
|
2255 | void esrv_new_player (player *pl) |
2272 | void esrv_new_player (player *pl) |
2256 | |
2273 | |
|
|
2274 | #d# TODO: replace by blocked_los accessor, fix code using this |
2257 | bool |
2275 | bool |
2258 | cell_visible (player *pl, int dx, int dy) |
2276 | cell_visible (player *pl, int dx, int dy) |
2259 | CODE: |
2277 | CODE: |
2260 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
2278 | RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; |
2261 | && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]; |
|
|
2262 | OUTPUT: |
2279 | OUTPUT: |
2263 | RETVAL |
2280 | RETVAL |
2264 | |
2281 | |
2265 | void |
2282 | void |
2266 | send (player *pl, SV *packet) |
2283 | send (player *pl, SV *packet) |
… | |
… | |
2334 | } |
2351 | } |
2335 | |
2352 | |
2336 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2353 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2337 | |
2354 | |
2338 | void |
2355 | void |
|
|
2356 | adjust_daylight () |
|
|
2357 | CODE: |
|
|
2358 | maptile::adjust_daylight (); |
|
|
2359 | |
|
|
2360 | void |
2339 | maptile::instantiate () |
2361 | maptile::instantiate () |
2340 | |
2362 | |
2341 | maptile *new () |
2363 | maptile *new () |
2342 | PROTOTYPE: |
2364 | PROTOTYPE: |
2343 | CODE: |
2365 | CODE: |
… | |
… | |
2522 | for (object *o = nmap->at (nx, ny).bot; o; o = o->above) |
2544 | for (object *o = nmap->at (nx, ny).bot; o; o = o->above) |
2523 | XPUSHs (sv_2mortal (to_sv (o))); |
2545 | XPUSHs (sv_2mortal (to_sv (o))); |
2524 | } |
2546 | } |
2525 | |
2547 | |
2526 | SV * |
2548 | SV * |
2527 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2549 | bot_at (maptile *map, unsigned int x, unsigned int y) |
2528 | PROTOTYPE: $$$ |
2550 | PROTOTYPE: $$$ |
2529 | ALIAS: |
2551 | ALIAS: |
2530 | top_at = 1 |
2552 | top_at = 1 |
2531 | flags_at = 2 |
2553 | flags_at = 2 |
2532 | light_at = 3 |
2554 | light_at = 3 |
2533 | move_block_at = 4 |
2555 | move_block_at = 4 |
2534 | move_slow_at = 5 |
2556 | move_slow_at = 5 |
2535 | move_on_at = 6 |
2557 | move_on_at = 6 |
2536 | move_off_at = 7 |
2558 | move_off_at = 7 |
2537 | INIT: |
|
|
2538 | if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; |
|
|
2539 | CODE: |
2559 | CODE: |
|
|
2560 | { |
|
|
2561 | sint16 nx = x; |
|
|
2562 | sint16 ny = y; |
|
|
2563 | |
|
|
2564 | if (!xy_normalise (map, nx, ny)) |
|
|
2565 | XSRETURN_UNDEF; |
|
|
2566 | |
|
|
2567 | mapspace &ms = map->at (nx, ny); |
|
|
2568 | |
|
|
2569 | ms.update (); |
|
|
2570 | |
2540 | switch (ix) |
2571 | switch (ix) |
2541 | { |
2572 | { |
2542 | case 0: RETVAL = to_sv (GET_MAP_OB (obj, x, y)); break; |
2573 | case 0: RETVAL = to_sv (ms.bot ); break; |
2543 | case 1: RETVAL = to_sv (GET_MAP_TOP (obj, x, y)); break; |
2574 | case 1: RETVAL = to_sv (ms.top ); break; |
2544 | case 2: RETVAL = newSVuv (GET_MAP_FLAGS (obj, x, y)); break; |
2575 | case 2: RETVAL = newSVuv (ms.flags_ ); break; |
2545 | case 3: RETVAL = newSViv (GET_MAP_LIGHT (obj, x, y)); break; |
2576 | case 3: RETVAL = newSViv (ms.light ); break; |
2546 | case 4: RETVAL = newSVuv (GET_MAP_MOVE_BLOCK (obj, x, y)); break; |
2577 | case 4: RETVAL = newSVuv (ms.move_block); break; |
2547 | case 5: RETVAL = newSVuv (GET_MAP_MOVE_SLOW (obj, x, y)); break; |
2578 | case 5: RETVAL = newSVuv (ms.move_slow ); break; |
2548 | case 6: RETVAL = newSVuv (GET_MAP_MOVE_ON (obj, x, y)); break; |
2579 | case 6: RETVAL = newSVuv (ms.move_on ); break; |
2549 | case 7: RETVAL = newSVuv (GET_MAP_MOVE_OFF (obj, x, y)); break; |
2580 | case 7: RETVAL = newSVuv (ms.move_off ); break; |
2550 | } |
2581 | } |
|
|
2582 | } |
2551 | OUTPUT: RETVAL |
2583 | OUTPUT: RETVAL |
2552 | |
2584 | |
2553 | void fix_walls (maptile *map, int x, int y) |
2585 | void fix_walls (maptile *map, int x, int y) |
2554 | |
2586 | |
2555 | void fix_walls_around (maptile *map, int x, int y) |
2587 | void fix_walls_around (maptile *map, int x, int y) |
… | |
… | |
2688 | PROTOTYPE: $ |
2720 | PROTOTYPE: $ |
2689 | CODE: |
2721 | CODE: |
2690 | RETVAL = region::find (name); |
2722 | RETVAL = region::find (name); |
2691 | OUTPUT: RETVAL |
2723 | OUTPUT: RETVAL |
2692 | |
2724 | |
2693 | region *find_fuzzy (utf8_string name) |
|
|
2694 | PROTOTYPE: $ |
|
|
2695 | CODE: |
|
|
2696 | RETVAL = region::find_fuzzy (name); |
|
|
2697 | OUTPUT: RETVAL |
|
|
2698 | |
|
|
2699 | int specificity (region *rgn) |
2725 | int specificity (region *rgn) |
2700 | CODE: |
2726 | CODE: |
2701 | RETVAL = 0; |
2727 | RETVAL = 0; |
2702 | while (rgn = rgn->parent) |
2728 | while (rgn = rgn->parent) |
2703 | RETVAL++; |
2729 | RETVAL++; |