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.312 by root, Tue Dec 23 06:58:24 2008 UTC vs.
Revision 1.320 by root, Thu Jul 16 21:42:56 2009 UTC

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
168void 168void
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
327static SV * 326static 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
410static long 409static long noinline
411SvPTR_ornull (SV *sv, const char *klass) 410SvPTR_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
612template<class type>
613static void noinline
614cf_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
621template<class object>
622static void noinline
623cf_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
614SV * 637SV *
615registry (attachable *ext) 638registry (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
688void
665void cfperl_main () 689cfperl_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
700static void 724static void noinline
701gather_callbacks (AV *&callbacks, AV *registry, event_type event) 725gather_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
796void 820static 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
816void 840static 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
960void
936void cfperl_tick () 961cfperl_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
1033void
1034cfperl_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
1008player * 1045player *
1009player::find (const char *name) 1046player::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
1157struct EVAPI *evapi::GEVAPI; 1194struct EVAPI *evapi::GEVAPI;
1158struct CoroAPI *coroapi::GCoroAPI; 1195struct CoroAPI *coroapi::GCoroAPI;
1159 1196
1197void
1160void coroapi::do_cede_to_tick () 1198coroapi::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
1194void 1232static 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
2105int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2144int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2106 2145
2107int calc_skill_exp (object *who, object *op, object *skill); 2146int calc_skill_exp (object *who, object *op, object *skill);
2108 2147
2109void push_button (object *op); 2148void push_button (object *op, object *originator);
2110 2149
2111void use_trigger (object *op); 2150void use_trigger (object *op, object *originator);
2112
2113void add_button_link (object *button, maptile *map, int connected);
2114
2115void remove_button_link (object *op);
2116 2151
2117void handle_apply_yield (object *op); 2152void handle_apply_yield (object *op);
2153
2154int convert_item (object *item, object *converter);
2118 2155
2119 2156
2120MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2157MODULE = 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
2328void 2365void
2329adjust_daylight () 2366adjust_daylight ()
2330 CODE: 2367 CODE:
2331 maptile::adjust_daylight (); 2368 maptile::adjust_daylight ();
2332 2369
2370int
2371outdoor_darkness (int darkness = 0)
2372 CODE:
2373 RETVAL = maptile::outdoor_darkness;
2374 if (items)
2375 maptile::outdoor_darkness = darkness;
2376 OUTPUT:
2377 RETVAL
2378
2333void 2379void
2334maptile::instantiate () 2380maptile::instantiate ()
2335 2381
2336maptile *new () 2382maptile *new ()
2337 PROTOTYPE: 2383 PROTOTYPE:
2445 } 2491 }
2446 2492
2447int out_of_map (maptile *map, int x, int y) 2493int out_of_map (maptile *map, int x, int y)
2448 2494
2449void 2495void
2450trigger (maptile *map, long connection, bool state = true) 2496find_link (maptile *map, shstr_tmp connection)
2451 CODE:
2452 activate_connection (map, connection, state);
2453
2454void
2455get_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
2462void 2502void
2463get_map_flags (maptile *map, int x, int y) 2503get_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
2698region *find_fuzzy (utf8_string name)
2699 PROTOTYPE: $
2700 CODE:
2701 RETVAL = region::find_fuzzy (name);
2702 OUTPUT: RETVAL
2703
2704int specificity (region *rgn) 2738int 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++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines