ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.367 by root, Mon Apr 12 05:22:38 2010 UTC vs.
Revision 1.377 by root, Wed Apr 21 03:12:46 2010 UTC

52#include <XSUB.h> 52#include <XSUB.h>
53 53
54#include "CoroAPI.h" 54#include "CoroAPI.h"
55#include "perlxsi.c" 55#include "perlxsi.c"
56 56
57extern sint64 *levels; // the experience table
58
59typedef object_thawer &object_thawer_ref; 57typedef object_thawer &object_thawer_ref;
60typedef object_freezer &object_freezer_ref; 58typedef object_freezer &object_freezer_ref;
61 59
62typedef std::string std__string; 60typedef std::string std__string;
63 61
85 *stash_cf_mapspace_wrap, 83 *stash_cf_mapspace_wrap,
86 *stash_cf_client_wrap, 84 *stash_cf_client_wrap,
87 *stash_cf_arch_wrap, 85 *stash_cf_arch_wrap,
88 *stash_cf_party_wrap, 86 *stash_cf_party_wrap,
89 *stash_cf_region_wrap, 87 *stash_cf_region_wrap,
90 *stash_cf_living_wrap; 88 *stash_cf_living_wrap,
89 *stash_ext_map_world;
91 90
92static SV 91static SV
93 *cv_cf_do_invoke, 92 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 93 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 94 *cv_cf_client_send_msg,
479 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 478 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
480 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 479 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
481 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 480 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
482 && !sv_derived_from (sv, "cf::object"))) 481 && !sv_derived_from (sv, "cf::object")))
483 croak ("object of type cf::object expected"); 482 croak ("object of type cf::object expected");
483
484 return SvPTR_nc (sv);
485}
486
487static long noinline
488SvPTR_ornull_maptile (SV *sv)
489{
490 if (expect_false (!SvOK (sv))) return 0;
491
492 if (!SvROK (sv)
493 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
494 && SvSTASH (SvRV (sv)) != stash_ext_map_world
495 && !sv_derived_from (sv, "cf::map")))
496 croak ("object of type cf::map expected");
484 497
485 return SvPTR_nc (sv); 498 return SvPTR_nc (sv);
486} 499}
487 500
488static long noinline 501static long noinline
565static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 578static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
566static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 579static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
567static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 580static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
568static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 581static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
569static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 582static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
570static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 583static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
571static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 584static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
572static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 585static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
586static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
573static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 587static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
574static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
575static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 588static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
576static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 589static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
577static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 590static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
578static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 591static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
579static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 592static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
695template<class type> 708template<class type>
696static void noinline 709static void noinline
697cf_obj_to (SV *arg, type &var) 710cf_obj_to (SV *arg, type &var)
698{ 711{
699 sv_to (arg, var); 712 sv_to (arg, var);
700 if (!var) 713 if (expect_false (!var))
701 croak ("must not pass invalid/null cf_obj here"); 714 croak ("must not pass invalid/null cf_obj here");
702} 715}
703 716
704template<class object> 717template<class object>
705static void noinline 718static void noinline
706cf_obj_ornull_to (SV *arg, object *&var) 719cf_obj_ornull_to (SV *arg, object *&var)
707{ 720{
708 if (SvOK (arg)) 721 if (SvOK (arg))
709 { 722 {
710 sv_to (arg, var); 723 sv_to (arg, var);
711 if (!var) 724 if (expect_false (!var))
712 croak ("unable to convert perl object to C++ object"); 725 croak ("unable to convert perl object to C++ object");
713 } 726 }
714 else 727 else
715 var = 0; 728 var = 0;
716} 729}
1139 1152
1140 return retval; 1153 return retval;
1141} 1154}
1142 1155
1143maptile * 1156maptile *
1144find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty) 1157find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse)
1145{ 1158{
1146 CALL_BEGIN (3); 1159 CALL_BEGIN (4);
1147 CALL_ARG (dirname); 1160 CALL_ARG (dirname);
1148 CALL_ARG (stylename); 1161 CALL_ARG (stylename);
1149 CALL_ARG (difficulty); 1162 CALL_ARG (difficulty);
1163 CALL_ARG (recurse);
1150 CALL_CALL ("ext::map_random::find_style", G_SCALAR); 1164 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1151 1165
1152 maptile *retval = 0; 1166 maptile *retval = 0;
1153 if (count) sv_to (POPs, retval); 1167 if (count) sv_to (POPs, retval);
1154 1168
1377 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1391 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1378 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1392 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1379 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1393 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1380 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1394 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1381 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1395 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1396 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1382 1397
1383 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1398 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1384 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1399 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1385 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1400 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1386 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1401 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1664 switch (items) 1679 switch (items)
1665 { 1680 {
1666 case 0: RETVAL = gen (); break; 1681 case 0: RETVAL = gen (); break;
1667 case 1: RETVAL = gen (SvUV (ST (0))); break; 1682 case 1: RETVAL = gen (SvUV (ST (0))); break;
1668 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1683 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1669 default: croak ("cf::rndm requires none, one or two parameters."); break; 1684 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1670 } 1685 }
1671} 1686}
1672 OUTPUT: 1687 OUTPUT:
1673 RETVAL 1688 RETVAL
1674 1689
1798 1813
1799int random_roll (int min, int max, object *op, int goodbad); 1814int random_roll (int min, int max, object *op, int goodbad);
1800 1815
1801const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1816const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1802 1817
1803int
1804exp_to_level (val64 exp) 1818int exp_to_level (val64 exp)
1805 CODE:
1806{
1807 int i = 0;
1808 1819
1809 RETVAL = settings.max_level;
1810
1811 for (i = 1; i <= settings.max_level; i++)
1812 {
1813 if (levels[i] > exp)
1814 {
1815 RETVAL = i - 1;
1816 break;
1817 }
1818 }
1819}
1820 OUTPUT: RETVAL
1821
1822val64
1823level_to_min_exp (int level) 1820val64 level_to_min_exp (int level)
1824 CODE:
1825 if (level > settings.max_level)
1826 RETVAL = levels[settings.max_level];
1827 else if (level < 1)
1828 RETVAL = 0;
1829 else
1830 RETVAL = levels[level];
1831 OUTPUT: RETVAL
1832 1821
1833SV * 1822SV *
1834resistance_to_string (int atnr) 1823resistance_to_string (int atnr)
1835 CODE: 1824 CODE:
1836 if (atnr >= 0 && atnr < NROFATTACKS) 1825 if (atnr >= 0 && atnr < NROFATTACKS)
1894 CODE: 1883 CODE:
1895 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1884 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1896 OUTPUT: 1885 OUTPUT:
1897 RETVAL 1886 RETVAL
1898 1887
1888bool should_invoke (attachable *obj, int event)
1889 CODE:
1890 RETVAL = obj->should_invoke ((event_type)event);
1891 OUTPUT: RETVAL
1892
1899void 1893void
1900debug_trace (attachable *obj, bool on = true) 1894debug_trace (attachable *obj, bool on = true)
1901 CODE: 1895 CODE:
1902 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1896 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1903 if (on) 1897 if (on)
2027} 2021}
2028 OUTPUT: 2022 OUTPUT:
2029 RETVAL 2023 RETVAL
2030 2024
2031object *find_best_object_match (object *op, utf8_string match) 2025object *find_best_object_match (object *op, utf8_string match)
2032
2033object *find_marked_object (object *op)
2034
2035int need_identify (object *obj);
2036 2026
2037int apply_shop_mat (object *shop_mat, object *op); 2027int apply_shop_mat (object *shop_mat, object *op);
2038 2028
2039int move (object *op, int dir, object *originator = op) 2029int move (object *op, int dir, object *originator = op)
2040 CODE: 2030 CODE:
2468 if (oblinkpt *obp = map->find_link (connection)) 2458 if (oblinkpt *obp = map->find_link (connection))
2469 for (objectlink *ol = obp->link; ol; ol = ol->next) 2459 for (objectlink *ol = obp->link; ol; ol = ol->next)
2470 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2460 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2471 2461
2472void 2462void
2473get_map_flags (maptile *map, int x, int y) 2463normalise (maptile *map, int x, int y, int dir = 0)
2474 PPCODE: 2464 PPCODE:
2475{ 2465{
2476 maptile *nmap = 0; 2466 mapxy pos (map, x, y);
2477 I16 nx = 0, ny = 0; 2467 if (!pos.move (dir).normalise ())
2468 XSRETURN_EMPTY;
2478 2469
2479 PUTBACK;
2480 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2481 SPAGAIN;
2482
2483 EXTEND (SP, 4); 2470 EXTEND (SP, 3);
2484 PUSHs (sv_2mortal (newSViv (flags)));
2485
2486 if (GIMME_V == G_ARRAY)
2487 {
2488 PUSHs (sv_2mortal (to_sv (nmap))); 2471 PUSHs (sv_2mortal (to_sv (pos.m)));
2489 PUSHs (sv_2mortal (newSViv (nx))); 2472 PUSHs (sv_2mortal (to_sv (pos.x)));
2490 PUSHs (sv_2mortal (newSViv (ny))); 2473 PUSHs (sv_2mortal (to_sv (pos.y)));
2491 }
2492} 2474}
2493 2475
2494mapspace * 2476mapspace *
2495ms (maptile *map, unsigned int x, unsigned int y) 2477ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2496 PROTOTYPE: $$$ 2478 PROTOTYPE: $$$;$
2497 CODE: 2479 CODE:
2498{ 2480{
2499 maptile *nmap = 0; 2481 mapxy pos (map, x, y);
2500 I16 nx, ny; 2482 if (!pos.move (dir).normalise ())
2501
2502 PUTBACK;
2503 get_map_flags (map, &nmap, x, y, &nx, &ny);
2504 SPAGAIN;
2505
2506 if (!nmap)
2507 XSRETURN_UNDEF; 2483 XSRETURN_UNDEF;
2508 2484
2509 RETVAL = &nmap->at (nx, ny); 2485 RETVAL = &*pos;
2510} 2486}
2511 OUTPUT: 2487 OUTPUT:
2512 RETVAL 2488 RETVAL
2513 2489
2514void 2490void
2515at (maptile *map, unsigned int x, unsigned int y) 2491at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2516 PROTOTYPE: $$$ 2492 PROTOTYPE: $$$;$
2517 PPCODE: 2493 PPCODE:
2518{ 2494 mapxy pos (map, x, y);
2519 maptile *nmap = 0; 2495 if (pos.move (dir).normalise ())
2520 I16 nx, ny;
2521
2522 PUTBACK;
2523 get_map_flags (map, &nmap, x, y, &nx, &ny);
2524 SPAGAIN;
2525
2526 if (nmap)
2527 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2496 for (object *o = pos->bot; o; o = o->above)
2528 XPUSHs (sv_2mortal (to_sv (o))); 2497 XPUSHs (sv_2mortal (to_sv (o)));
2529}
2530 2498
2531SV * 2499SV *
2532bot_at (maptile *map, unsigned int x, unsigned int y) 2500bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2533 PROTOTYPE: $$$ 2501 PROTOTYPE: $$$;$
2534 ALIAS: 2502 ALIAS:
2535 top_at = 1 2503 top_at = 1
2536 flags_at = 2 2504 flags_at = 2
2537 light_at = 3 2505 light_at = 3
2538 move_block_at = 4 2506 move_block_at = 4
2539 move_slow_at = 5 2507 move_slow_at = 5
2540 move_on_at = 6 2508 move_on_at = 6
2541 move_off_at = 7 2509 move_off_at = 7
2542 CODE: 2510 CODE:
2543{ 2511{
2544 sint16 nx = x; 2512 mapxy pos (map, x, y);
2545 sint16 ny = y; 2513 if (!pos.move (dir).normalise ())
2546
2547 if (!xy_normalise (map, nx, ny))
2548 XSRETURN_UNDEF; 2514 XSRETURN_UNDEF;
2549 2515
2550 mapspace &ms = map->at (nx, ny); 2516 mapspace &ms = *pos;
2551 2517
2552 ms.update (); 2518 ms.update ();
2553 2519
2554 switch (ix) 2520 switch (ix)
2555 { 2521 {
2807 while (!RETVAL); // crude way to leave index 0 2773 while (!RETVAL); // crude way to leave index 0
2808 2774
2809 faces [RETVAL].name = name; 2775 faces [RETVAL].name = name;
2810 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2776 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2811 2777
2812 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2778 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2813 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2779 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2780 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2814} 2781}
2815 OUTPUT: RETVAL 2782 OUTPUT: RETVAL
2816 2783
2817void set_type (faceidx idx, int value) 2784void set_type (faceidx idx, int value)
2818 ALIAS: 2785 ALIAS:
2952 sv_to (sv, self); 2919 sv_to (sv, self);
2953 delete self; 2920 delete self;
2954 2921
2955MODULE = cf PACKAGE = cf::object::thawer 2922MODULE = cf PACKAGE = cf::object::thawer
2956 2923
2957INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2924INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2925
2926bool
2927errors_are_fatal (bool fatal)
2928 CODE:
2929 RETVAL = object_thawer::errors_are_fatal;
2930 object_thawer::errors_are_fatal = fatal;
2931 OUTPUT:
2932 RETVAL
2958 2933
2959SV * 2934SV *
2960new_from_file (char *klass, octet_string path) 2935new_from_file (char *klass, octet_string path)
2961 CODE: 2936 CODE:
2962 object_thawer *f = new object_thawer (path); 2937 object_thawer *f = new object_thawer (path);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines