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.227 by root, Tue Jul 10 16:24:00 2007 UTC vs.
Revision 1.242 by root, Mon Aug 6 10:54:12 2007 UTC

246 delete obj; 246 delete obj;
247 } 247 }
248 } 248 }
249} 249}
250 250
251void
252attachable::set_key (const char *key, const char *value)
253{
254 if (!self)
255 self = newHV ();
256
257 if (value)
258 hv_store (self, key, strlen (key), newSVpv (value, 0), 0);
259 else
260 hv_delete (self, key, strlen (key), G_DISCARD);
261}
262
251attachable & 263attachable &
252attachable::operator =(const attachable &src) 264attachable::operator =(const attachable &src)
253{ 265{
254 //if (self || cb) 266 //if (self || cb)
255 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); 267 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
330{ 342{
331 if (!obj) 343 if (!obj)
332 return &PL_sv_undef; 344 return &PL_sv_undef;
333 345
334 if (!obj->self) 346 if (!obj->self)
347 obj->self = newHV ();
348
349 if (!SvOBJECT (obj->self))
335 { 350 {
336 obj->self = newHV ();
337 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 351 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
338 352
339 // now bless the object _once_ 353 // now bless the object _once_
354 //TODO: create a class registry with c++ type<=>perl name<=>stash and use it here and elsewhere
340 return sv_bless (newRV_inc ((SV *)obj->self), stash); 355 return sv_bless (newRV_inc ((SV *)obj->self), stash);
341 } 356 }
342 else 357 else
343 { 358 {
344 SV *sv = newRV_inc ((SV *)obj->self); 359 SV *sv = newRV_inc ((SV *)obj->self);
417inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 432inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
418inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 433inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
419inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 434inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
420inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 435inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
421inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 436inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
437inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
422inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 438inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
423inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); }
424inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 439inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
425 440
426inline SV *to_sv (object & v) { return to_sv (&v); } 441inline SV *to_sv (object & v) { return to_sv (&v); }
427inline SV *to_sv (living & v) { return to_sv (&v); } 442inline SV *to_sv (living & v) { return to_sv (&v); }
428 443
454inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 469inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
455inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 470inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
456inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 471inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
457inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 472inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
458inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 473inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
474inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); }
459inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 475inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
460inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 476inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
461inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
462inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 477inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
463 478
464//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 479//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
465inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 480inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
466 481
949} 964}
950 965
951SV * 966SV *
952cfperl_result (int idx) 967cfperl_result (int idx)
953{ 968{
954 AV *av = get_av ("cfperl::invoke_results", 0); 969 AV *av = get_av ("cf::INVOKE_RESULTS", 0);
955 if (!av) 970 if (!av)
956 return &PL_sv_undef; 971 return &PL_sv_undef;
957 972
958 SV **sv = av_fetch (av, idx, 0); 973 SV **sv = av_fetch (av, idx, 0);
959 if (!sv) 974 if (!sv)
1006void 1021void
1007cfperl_send_msg (client *ns, int color, const char *type, const char *msg) 1022cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
1008{ 1023{
1009 CALL_BEGIN (4); 1024 CALL_BEGIN (4);
1010 CALL_ARG (ns); 1025 CALL_ARG (ns);
1011 CALL_ARG (color);
1012 CALL_ARG (type); 1026 CALL_ARG (type);
1013 CALL_ARG_SV (newSVpv_utf8 (msg)); 1027 CALL_ARG_SV (newSVpv_utf8 (msg));
1028 CALL_ARG (color);
1014 CALL_CALL ("cf::client::send_msg", G_VOID); 1029 CALL_CALL ("cf::client::send_msg", G_VOID);
1015 CALL_END; 1030 CALL_END;
1031}
1032
1033int
1034cfperl_can_merge (object *ob1, object *ob2)
1035{
1036 int can;
1037
1038 CALL_BEGIN (2);
1039 CALL_ARG (ob1);
1040 CALL_ARG (ob2);
1041 CALL_CALL ("cf::_can_merge", G_SCALAR);
1042 can = count && SvTRUE (TOPs);
1043 CALL_END;
1044
1045 return can;
1016} 1046}
1017 1047
1018maptile * 1048maptile *
1019maptile::find_sync (const char *path, maptile *origin) 1049maptile::find_sync (const char *path, maptile *origin)
1020{ 1050{
1354 1384
1355 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) 1385 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED)
1356 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) 1386 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN)
1357 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD) 1387 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD)
1358 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE) 1388 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE)
1389 const_iv (NDI_ALL) const_iv (NDI_DEF) const_iv (NDI_REPLY) const_iv (NDI_CLIENT_MASK)
1359 const_iv (NDI_ALL) 1390 const_iv (NDI_NOCREATE)
1360 1391
1361 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1392 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1362 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1393 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1363 1394
1364 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1395 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1491 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1522 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1492 1523
1493 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) 1524 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1494 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) 1525 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1495 const_iv (GT_MINIMAL) 1526 const_iv (GT_MINIMAL)
1527
1528 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND)
1529 const_iv (FT_RSRC) const_iv (FT_NUM)
1496 }; 1530 };
1497 1531
1498 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1532 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1499 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1533 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1500 1534
1534 1568
1535 for_all_objects (op) 1569 for_all_objects (op)
1536 op->reattach (); 1570 op->reattach ();
1537} 1571}
1538 1572
1539void _post_tick ()
1540 CODE:
1541 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1542
1543# support function for map-world.ext 1573# support function for map-world.ext
1544void _quantise (SV *data_sv, SV *plt_sv) 1574void _quantise (SV *data_sv, SV *plt_sv)
1545 CODE: 1575 CODE:
1546{ 1576{
1547 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) 1577 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1579 len -= 3; 1609 len -= 3;
1580 } 1610 }
1581 1611
1582 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1612 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1583} 1613}
1614
1615void _post_tick ()
1616 CODE:
1617 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1618
1619NV till_cede ()
1620 CODE:
1621 RETVAL = coroapi::next_cede - now ();
1622 OUTPUT:
1623 RETVAL
1624
1625NV till_tick ()
1626 CODE:
1627 RETVAL = SvNV (sv_next_tick) - now ();
1628 OUTPUT:
1629 RETVAL
1584 1630
1585NV floor (NV x) 1631NV floor (NV x)
1586 1632
1587NV ceil (NV x) 1633NV ceil (NV x)
1588 1634
1631octet_string path_combine (octet_string base, octet_string path) 1677octet_string path_combine (octet_string base, octet_string path)
1632 PROTOTYPE: $$ 1678 PROTOTYPE: $$
1633 1679
1634octet_string path_combine_and_normalize (octet_string base, octet_string path) 1680octet_string path_combine_and_normalize (octet_string base, octet_string path)
1635 PROTOTYPE: $$ 1681 PROTOTYPE: $$
1636
1637const_octet_string
1638get_maps_directory (octet_string path)
1639 PROTOTYPE: $
1640 ALIAS: maps_directory = 0
1641 CODE:
1642 RETVAL = create_pathname (path);
1643 OUTPUT: RETVAL
1644 1682
1645void 1683void
1646sub_generation_inc () 1684sub_generation_inc ()
1647 CODE: 1685 CODE:
1648 PL_sub_generation++; 1686 PL_sub_generation++;
1770#object *mortals (U32 index) 1808#object *mortals (U32 index)
1771# CODE: 1809# CODE:
1772# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; 1810# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0;
1773# OUTPUT: RETVAL 1811# OUTPUT: RETVAL
1774 1812
1775INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h | 1813INCLUDE: $PERL $srcdir/genacc attachable ../include/util.h ../include/cfperl.h |
1776 1814
1777MODULE = cf PACKAGE = cf::global 1815MODULE = cf PACKAGE = cf::global
1778 1816
1779int invoke (SV *klass, int event, ...) 1817int invoke (SV *klass, int event, ...)
1780 CODE: 1818 CODE:
1994 2032
1995void add_button_link (object *button, maptile *map, int connected); 2033void add_button_link (object *button, maptile *map, int connected);
1996 2034
1997void remove_button_link (object *op); 2035void remove_button_link (object *op);
1998 2036
2037void handle_apply_yield (object *op);
2038
1999 2039
2000MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2040MODULE = cf PACKAGE = cf::object PREFIX = cf_
2001 2041
2002object *cf_insert_ob_in_ob (object *ob, object *where) 2042object *cf_insert_ob_in_ob (object *ob, object *where)
2003 2043
2104 pl->orig_stats = pl->ob->stats; 2144 pl->orig_stats = pl->ob->stats;
2105 2145
2106void clear_los (player *pl) 2146void clear_los (player *pl)
2107 2147
2108void cf_player_move (player *pl, int dir) 2148void cf_player_move (player *pl, int dir)
2109
2110void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2111 2149
2112bool 2150bool
2113cell_visible (player *pl, int dx, int dy) 2151cell_visible (player *pl, int dx, int dy)
2114 CODE: 2152 CODE:
2115 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2153 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2254 palette = SvRV (palette); 2292 palette = SvRV (palette);
2255 2293
2256 STRLEN idxlen; 2294 STRLEN idxlen;
2257 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2295 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2258 2296
2259 region **regionmap = (region **)malloc ( 2297 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2260 (av_len ((AV *)palette) + 1) * sizeof (region *));
2261 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2298 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2262 2299
2263 for (int i = av_len ((AV *)palette) + 1; i--; ) 2300 for (int i = av_len ((AV *)palette) + 1; i--; )
2264 regionmap [i] = region::find ( 2301 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2265 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2266 2302
2267 for (int y = 0; y < THIS->height; ++y) 2303 for (int y = 0; y < THIS->height; ++y)
2268 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2304 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2269 2305
2270 sfree (THIS->regions, THIS->size ()); 2306 sfree (THIS->regions, THIS->size ());
2271 free (THIS->regionmap); 2307 delete [] THIS->regionmap;
2272 2308
2273 THIS->regions = regions; 2309 THIS->regions = regions;
2274 THIS->regionmap = regionmap; 2310 THIS->regionmap = regionmap;
2275} 2311}
2276 2312
2296 } 2332 }
2297 } 2333 }
2298 2334
2299 op->destroy (); 2335 op->destroy ();
2300} 2336}
2301
2302void play_sound_map (maptile *map, int x, int y, int sound_num)
2303 2337
2304int out_of_map (maptile *map, int x, int y) 2338int out_of_map (maptile *map, int x, int y)
2305 2339
2306void 2340void
2307trigger (maptile *map, long connection, bool state = true) 2341trigger (maptile *map, long connection, bool state = true)
2579 char *buf = SvPVbyte (packet, len); 2613 char *buf = SvPVbyte (packet, len);
2580 2614
2581 THIS->send_packet (buf, len); 2615 THIS->send_packet (buf, len);
2582} 2616}
2583 2617
2618faceidx
2619client::need_face (utf8_string name, int pri = 0)
2620 CODE:
2621 RETVAL = face_find (name, 0);
2622 if (RETVAL)
2623 {
2624 THIS->send_face (RETVAL, pri);
2625 THIS->flush_fx ();
2626 }
2627 OUTPUT:
2628 RETVAL
2629
2630int
2631client::fx_want (int idx, int value = -1)
2632 CODE:
2633 if (0 < idx && idx < FT_NUM)
2634 {
2635 RETVAL = THIS->fx_want [idx];
2636 if (items > 2)
2637 THIS->fx_want [idx] = value;
2638 }
2639 else
2640 RETVAL = 0;
2641 OUTPUT:
2642 RETVAL
2643
2644MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2645
2646faceidx sound_find (utf8_string name)
2647
2648void sound_set (utf8_string str, faceidx face)
2649
2650# dire hack
2651void old_sound_index (int idx, faceidx face)
2652 CODE:
2653 extern faceidx old_sound_index [SOUND_CAST_SPELL_0];
2654 old_sound_index [idx] = face;
2655
2584MODULE = cf PACKAGE = cf::face PREFIX = face_ 2656MODULE = cf PACKAGE = cf::face PREFIX = face_
2585 2657
2586#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | 2658#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2587 2659
2588faceidx face_find (utf8_string name, faceidx defidx = 0) 2660faceidx face_find (utf8_string name, faceidx defidx = 0)
2611 set_visibility = 1 2683 set_visibility = 1
2612 set_magicmap = 2 2684 set_magicmap = 2
2613 set_smooth = 3 2685 set_smooth = 3
2614 set_smoothlevel = 4 2686 set_smoothlevel = 4
2615 CODE: 2687 CODE:
2616 faceinfo *f = face_info (idx); 2688 faceinfo *f = face_info (idx); assert (f);
2617 assert (f);
2618 switch (ix) 2689 switch (ix)
2619 { 2690 {
2620 case 0: f->type = value; break; 2691 case 0: f->type = value; break;
2621 case 1: f->visibility = value; break; 2692 case 1: f->visibility = value; break;
2622 case 2: f->magicmap = value; break; 2693 case 2: f->magicmap = value; break;
2625 } 2696 }
2626 2697
2627void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2698void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2628 CODE: 2699 CODE:
2629{ 2700{
2630 facedata *d = face_data (idx, faceset); 2701 faceinfo *f = face_info (idx); assert (f);
2631 assert (d); 2702 facedata *d = &(faceset ? f->data64 : f->data32);
2632 sv_to (data, d->data); 2703 sv_to (data, d->data);
2633 STRLEN clen; 2704 STRLEN clen;
2634 char *cdata = SvPVbyte (chksum, clen); 2705 char *cdata = SvPVbyte (chksum, clen);
2635 clen = min (CHKSUM_SIZE, clen); 2706 clen = min (CHKSUM_SIZE, clen);
2636 2707
2646 ns->force_newmap = true; 2717 ns->force_newmap = true;
2647 } 2718 }
2648 } 2719 }
2649} 2720}
2650 2721
2722int get_data_size (faceidx idx, int faceset = 0)
2723 CODE:
2724 facedata *d = face_data (idx, faceset); assert (d);
2725 RETVAL = d->data.size ();
2726 OUTPUT:
2727 RETVAL
2728
2729SV *get_chksum (faceidx idx, int faceset = 0)
2730 CODE:
2731 facedata *d = face_data (idx, faceset); assert (d);
2732 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2733 OUTPUT:
2734 RETVAL
2735
2651void invalidate (faceidx idx) 2736void invalidate (faceidx idx)
2652 CODE: 2737 CODE:
2653 for_all_clients (ns) 2738 for_all_clients (ns)
2654 { 2739 {
2655 ns->faces_sent [idx] = false; 2740 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines