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.374 by root, Thu Apr 15 06:05:52 2010 UTC vs.
Revision 1.384 by root, Fri Apr 30 21:00:40 2010 UTC

83 *stash_cf_mapspace_wrap, 83 *stash_cf_mapspace_wrap,
84 *stash_cf_client_wrap, 84 *stash_cf_client_wrap,
85 *stash_cf_arch_wrap, 85 *stash_cf_arch_wrap,
86 *stash_cf_party_wrap, 86 *stash_cf_party_wrap,
87 *stash_cf_region_wrap, 87 *stash_cf_region_wrap,
88 *stash_cf_living_wrap; 88 *stash_cf_living_wrap,
89 *stash_ext_map_world;
89 90
90static SV 91static SV
91 *cv_cf_do_invoke, 92 *cv_cf_do_invoke,
92 *cv_cf__can_merge, 93 *cv_cf__can_merge,
93 *cv_cf_client_send_msg, 94 *cv_cf_client_send_msg,
351#endif 352#endif
352 353
353////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 354//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
354 355
355static SV * 356static SV *
356newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 357newSVptr (void *ptr, HV *stash, HV *hv)
357{ 358{
358 SV *sv; 359 SV *sv;
359 360
360 if (!ptr) 361 if (!ptr)
361 return newSV (0); 362 return newSV (0);
362 363
363 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
364 return sv_bless (newRV_noinc ((SV *)hv), stash); 365 return sv_bless (newRV_noinc ((SV *)hv), stash);
366}
367
368static SV *
369newSVptr (void *ptr, HV *stash)
370{
371 return newSVptr (ptr, stash, newHV ());
365} 372}
366 373
367static int 374static int
368attachable_free (pTHX_ SV *sv, MAGIC *mg) 375attachable_free (pTHX_ SV *sv, MAGIC *mg)
369{ 376{
477 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 484 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
478 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 485 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
479 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 486 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
480 && !sv_derived_from (sv, "cf::object"))) 487 && !sv_derived_from (sv, "cf::object")))
481 croak ("object of type cf::object expected"); 488 croak ("object of type cf::object expected");
489
490 return SvPTR_nc (sv);
491}
492
493static long noinline
494SvPTR_ornull_maptile (SV *sv)
495{
496 if (expect_false (!SvOK (sv))) return 0;
497
498 if (!SvROK (sv)
499 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
500 && SvSTASH (SvRV (sv)) != stash_ext_map_world
501 && !sv_derived_from (sv, "cf::map")))
502 croak ("object of type cf::map expected");
482 503
483 return SvPTR_nc (sv); 504 return SvPTR_nc (sv);
484} 505}
485 506
486static long noinline 507static long noinline
563static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 584static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
564static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 585static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
565static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 586static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
566static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 587static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
567static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 588static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
568static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 589static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
569static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 590static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
570static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 591static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
592static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
571static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 593static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
572static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
573static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 594static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
574static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 595static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
575static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 596static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
576static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 597static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
577static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 598static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
693template<class type> 714template<class type>
694static void noinline 715static void noinline
695cf_obj_to (SV *arg, type &var) 716cf_obj_to (SV *arg, type &var)
696{ 717{
697 sv_to (arg, var); 718 sv_to (arg, var);
698 if (!var) 719 if (expect_false (!var))
699 croak ("must not pass invalid/null cf_obj here"); 720 croak ("must not pass invalid/null cf_obj here");
700} 721}
701 722
702template<class object> 723template<class object>
703static void noinline 724static void noinline
704cf_obj_ornull_to (SV *arg, object *&var) 725cf_obj_ornull_to (SV *arg, object *&var)
705{ 726{
706 if (SvOK (arg)) 727 if (SvOK (arg))
707 { 728 {
708 sv_to (arg, var); 729 sv_to (arg, var);
709 if (!var) 730 if (expect_false (!var))
710 croak ("unable to convert perl object to C++ object"); 731 croak ("unable to convert perl object to C++ object");
711 } 732 }
712 else 733 else
713 var = 0; 734 var = 0;
714} 735}
749 exit (EXIT_FAILURE); 770 exit (EXIT_FAILURE);
750 } 771 }
751 772
752 eval_pv ( 773 eval_pv (
753 "#line 1 'cfperl init'\n" 774 "#line 1 'cfperl init'\n"
754 "use EV ();\n" 775 "use EV ();\n" // required by bootstrap
755 "use Coro ();\n" 776 "use Coro ();\n" // required by bootstrap
756 "cf->bootstrap;\n" 777 "cf->bootstrap;\n" // required for cf::datadir
757 "unshift @INC, cf::datadir ();\n" 778 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
758 "require cf;\n", 779 "require cf;\n",
759 0 780 0
760 ); 781 );
761 782
762 if (SvTRUE (ERRSV)) 783 if (SvTRUE (ERRSV))
1376 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1397 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1377 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1398 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1378 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1399 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1379 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1400 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1380 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1401 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1402 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1381 1403
1382 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1404 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1383 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1405 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1384 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1406 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1385 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1407 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1434# undef def 1456# undef def
1435# define def(uc, flags) const_iv (SK_ ## uc) 1457# define def(uc, flags) const_iv (SK_ ## uc)
1436# include "skillinc.h" 1458# include "skillinc.h"
1437# undef def 1459# undef def
1438 1460
1439 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1440 const_iv (logBacktrace)
1441
1442 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1443 1462
1444 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1445 1464
1446 const_iv (MAX_TIME) 1465 const_iv (MAX_TIME)
1472 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1491 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1473 1492
1474 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1493 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1475 }; 1494 };
1476 1495
1477 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1496 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1478 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1497 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1479 1498
1480 static const struct { 1499 static const struct {
1481 const char *name; 1500 const char *name;
1482 int skip; 1501 int skip;
1488# undef def 1507# undef def
1489 }; 1508 };
1490 1509
1491 AV *av = get_av ("cf::EVENT", 1); 1510 AV *av = get_av ("cf::EVENT", 1);
1492 1511
1493 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1512 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1494 { 1513 {
1495 AV *event = newAV (); 1514 AV *event = newAV ();
1496 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1515 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1497 av_push (event, newSViv (eiv->klass)); 1516 av_push (event, newSViv (eiv->klass));
1498 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1517 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1867 CODE: 1886 CODE:
1868 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1869 OUTPUT: 1888 OUTPUT:
1870 RETVAL 1889 RETVAL
1871 1890
1891bool should_invoke (attachable *obj, int event)
1892 CODE:
1893 RETVAL = obj->should_invoke ((event_type)event);
1894 OUTPUT: RETVAL
1895
1872void 1896void
1873debug_trace (attachable *obj, bool on = true) 1897debug_trace (attachable *obj, bool on = true)
1874 CODE: 1898 CODE:
1875 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1899 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1876 if (on) 1900 if (on)
2062 2086
2063void pick_up (object *who, object *op) 2087void pick_up (object *who, object *op)
2064 2088
2065void update_object (object *op, int action) 2089void update_object (object *op, int action)
2066 2090
2067void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2091void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2068 2092
2069void player_lvl_adj (object *who, object *skill = 0) 2093void player_lvl_adj (object *who, object *skill = 0)
2070 2094
2071int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2095int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2072 2096
2437 if (oblinkpt *obp = map->find_link (connection)) 2461 if (oblinkpt *obp = map->find_link (connection))
2438 for (objectlink *ol = obp->link; ol; ol = ol->next) 2462 for (objectlink *ol = obp->link; ol; ol = ol->next)
2439 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2463 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2440 2464
2441void 2465void
2442get_map_flags (maptile *map, int x, int y) 2466xy_normalise (maptile *map, int x, int y, int dir = 0)
2443 PPCODE: 2467 PPCODE:
2444{ 2468{
2445 maptile *nmap = 0; 2469 mapxy pos (map, x, y);
2446 I16 nx = 0, ny = 0; 2470 if (!pos.move (dir).normalise ())
2471 XSRETURN_EMPTY;
2447 2472
2448 PUTBACK;
2449 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2450 SPAGAIN;
2451
2452 EXTEND (SP, 4); 2473 EXTEND (SP, 3);
2453 PUSHs (sv_2mortal (newSViv (flags)));
2454
2455 if (GIMME_V == G_ARRAY)
2456 {
2457 PUSHs (sv_2mortal (to_sv (nmap))); 2474 PUSHs (sv_2mortal (to_sv (pos.m)));
2458 PUSHs (sv_2mortal (newSViv (nx))); 2475 PUSHs (sv_2mortal (to_sv (pos.x)));
2459 PUSHs (sv_2mortal (newSViv (ny))); 2476 PUSHs (sv_2mortal (to_sv (pos.y)));
2460 }
2461} 2477}
2462 2478
2463mapspace * 2479mapspace *
2464ms (maptile *map, unsigned int x, unsigned int y) 2480ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2465 PROTOTYPE: $$$ 2481 PROTOTYPE: $$$;$
2466 CODE: 2482 CODE:
2467{ 2483{
2468 maptile *nmap = 0; 2484 mapxy pos (map, x, y);
2469 I16 nx, ny; 2485 if (!pos.move (dir).normalise ())
2470
2471 PUTBACK;
2472 get_map_flags (map, &nmap, x, y, &nx, &ny);
2473 SPAGAIN;
2474
2475 if (!nmap)
2476 XSRETURN_UNDEF; 2486 XSRETURN_UNDEF;
2477 2487
2478 RETVAL = &nmap->at (nx, ny); 2488 RETVAL = &*pos;
2479} 2489}
2480 OUTPUT: 2490 OUTPUT:
2481 RETVAL 2491 RETVAL
2482 2492
2483void 2493void
2484at (maptile *map, unsigned int x, unsigned int y) 2494at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2485 PROTOTYPE: $$$ 2495 PROTOTYPE: $$$;$
2486 PPCODE: 2496 PPCODE:
2487{ 2497 mapxy pos (map, x, y);
2488 maptile *nmap = 0; 2498 if (pos.move (dir).normalise ())
2489 I16 nx, ny;
2490
2491 PUTBACK;
2492 get_map_flags (map, &nmap, x, y, &nx, &ny);
2493 SPAGAIN;
2494
2495 if (nmap)
2496 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2499 for (object *o = pos->bot; o; o = o->above)
2497 XPUSHs (sv_2mortal (to_sv (o))); 2500 XPUSHs (sv_2mortal (to_sv (o)));
2498}
2499 2501
2500SV * 2502SV *
2501bot_at (maptile *map, unsigned int x, unsigned int y) 2503bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2502 PROTOTYPE: $$$ 2504 PROTOTYPE: $$$;$
2503 ALIAS: 2505 ALIAS:
2504 top_at = 1 2506 top_at = 1
2505 flags_at = 2 2507 flags_at = 2
2506 light_at = 3 2508 light_at = 3
2507 move_block_at = 4 2509 move_block_at = 4
2508 move_slow_at = 5 2510 move_slow_at = 5
2509 move_on_at = 6 2511 move_on_at = 6
2510 move_off_at = 7 2512 move_off_at = 7
2511 CODE: 2513 CODE:
2512{ 2514{
2513 sint16 nx = x; 2515 mapxy pos (map, x, y);
2514 sint16 ny = y; 2516 if (!pos.move (dir).normalise ())
2515
2516 if (!xy_normalise (map, nx, ny))
2517 XSRETURN_UNDEF; 2517 XSRETURN_UNDEF;
2518 2518
2519 mapspace &ms = map->at (nx, ny); 2519 mapspace &ms = *pos;
2520 2520
2521 ms.update (); 2521 ms.update ();
2522 2522
2523 switch (ix) 2523 switch (ix)
2524 { 2524 {
2658list () 2658list ()
2659 PPCODE: 2659 PPCODE:
2660 for_all_regions (rgn) 2660 for_all_regions (rgn)
2661 XPUSHs (sv_2mortal (to_sv (rgn))); 2661 XPUSHs (sv_2mortal (to_sv (rgn)));
2662 2662
2663region *find (utf8_string name)
2664 PROTOTYPE: $
2665 CODE:
2666 RETVAL = region::find (name);
2667 OUTPUT: RETVAL
2668
2669int specificity (region *rgn) 2663int specificity (region *rgn)
2670 CODE: 2664 CODE:
2671 RETVAL = 0; 2665 RETVAL = 0;
2672 while (rgn = rgn->parent) 2666 while (rgn = rgn->parent)
2673 RETVAL++; 2667 RETVAL++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines