1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
10 | * |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
15 | * |
15 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * and the GNU General Public License along with this program. If not, see |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
18 | * <http://www.gnu.org/licenses/>. |
19 | * |
19 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
21 | */ |
22 | |
22 | |
23 | #include "autoconf.h" |
23 | #include "autoconf.h" |
24 | |
24 | |
… | |
… | |
253 | { |
253 | { |
254 | static int last_mortalcount; |
254 | static int last_mortalcount; |
255 | if (mortals.size () != last_mortalcount) |
255 | if (mortals.size () != last_mortalcount) |
256 | { |
256 | { |
257 | last_mortalcount = mortals.size (); |
257 | last_mortalcount = mortals.size (); |
258 | LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); |
258 | object *specimen = is_a<object> (mortals [rndm (mortals.size ())]); |
|
|
259 | |
|
|
260 | LOG (llevInfo, "%d mortals (random specimen: %s).\n", |
|
|
261 | (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)"); |
259 | |
262 | |
260 | if (0) |
263 | if (0) |
261 | { |
264 | { |
262 | for (int j = 0; j < mortals.size (); ++j)//D |
265 | for (int j = 0; j < mortals.size (); ++j)//D |
263 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
266 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
… | |
… | |
622 | STRLEN len; |
625 | STRLEN len; |
623 | char *data = SvPVbyte (sv, len); |
626 | char *data = SvPVbyte (sv, len); |
624 | v.assign (data, len); |
627 | v.assign (data, len); |
625 | } |
628 | } |
626 | |
629 | |
|
|
630 | static inline void sv_to (SV *sv, refcnt_buf &v) |
|
|
631 | { |
|
|
632 | STRLEN len; |
|
|
633 | char *data = SvPVbyte (sv, len); |
|
|
634 | refcnt_buf buf (data, len); |
|
|
635 | v = buf; |
|
|
636 | } |
|
|
637 | |
627 | static inline void sv_to (SV *sv, UUID &v) |
638 | static inline void sv_to (SV *sv, UUID &v) |
628 | { |
639 | { |
629 | if (!v.parse (SvPV_nolen (sv))) |
640 | if (!v.parse (SvPV_nolen (sv))) |
630 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
641 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
631 | } |
642 | } |
… | |
… | |
1528 | |
1539 | |
1529 | void _gv_clear (SV *gv) |
1540 | void _gv_clear (SV *gv) |
1530 | CODE: |
1541 | CODE: |
1531 | assert (SvTYPE (gv) == SVt_PVGV); |
1542 | assert (SvTYPE (gv) == SVt_PVGV); |
1532 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
1543 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
|
|
1544 | SvREFCNT_inc (gv); |
1533 | f (GvGP (gv)->gp_form); |
1545 | f (GvGP (gv)->gp_form); |
1534 | f (GvGP (gv)->gp_io); |
1546 | f (GvGP (gv)->gp_io); |
1535 | f (GvGP (gv)->gp_sv); |
1547 | f (GvGP (gv)->gp_sv); |
1536 | f (GvGP (gv)->gp_av); |
1548 | f (GvGP (gv)->gp_av); |
1537 | f (GvGP (gv)->gp_hv); |
1549 | f (GvGP (gv)->gp_hv); |
1538 | f (GvGP (gv)->gp_cv); |
1550 | f (GvGP (gv)->gp_cv); |
1539 | GvCVGEN (gv) = 0; |
1551 | GvCVGEN (gv) = 0; |
1540 | GvMULTI_off (gv); |
1552 | GvMULTI_off (gv); |
|
|
1553 | SvREFCNT_dec (gv); |
1541 | # undef f |
1554 | # undef f |
1542 | |
1555 | |
1543 | void _connect_to_perl_1 () |
1556 | void _connect_to_perl_1 () |
1544 | |
1557 | |
1545 | void _connect_to_perl_2 () |
1558 | void _connect_to_perl_2 () |
… | |
… | |
2133 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2146 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2134 | |
2147 | |
2135 | if (RETVAL->destroyed ()) |
2148 | if (RETVAL->destroyed ()) |
2136 | RETVAL = 0; |
2149 | RETVAL = 0; |
2137 | } |
2150 | } |
|
|
2151 | OUTPUT: |
|
|
2152 | RETVAL |
2138 | |
2153 | |
2139 | shstr |
2154 | shstr |
2140 | object::kv_get (shstr key) |
2155 | object::kv_get (shstr key) |
2141 | CODE: |
2156 | CODE: |
2142 | RETVAL = THIS->kv.get (key); |
2157 | RETVAL = THIS->kv.get (key); |
… | |
… | |
2623 | PPCODE: |
2638 | PPCODE: |
2624 | EXTEND (SP, clients.size ()); |
2639 | EXTEND (SP, clients.size ()); |
2625 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2640 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2626 | PUSHs (sv_2mortal (to_sv (*i))); |
2641 | PUSHs (sv_2mortal (to_sv (*i))); |
2627 | |
2642 | |
|
|
2643 | STRLEN |
|
|
2644 | client::inbuf_append (SV *data) |
|
|
2645 | CODE: |
|
|
2646 | { |
|
|
2647 | STRLEN len; |
|
|
2648 | char *ptr = SvPVbyte (data, len); |
|
|
2649 | |
|
|
2650 | min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len); |
|
|
2651 | memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len); |
|
|
2652 | THIS->inbuf_len += len; |
|
|
2653 | |
|
|
2654 | THIS->inbuf_handle (); |
|
|
2655 | |
|
|
2656 | RETVAL = len; |
|
|
2657 | } |
|
|
2658 | OUTPUT: RETVAL |
|
|
2659 | |
2628 | void |
2660 | void |
2629 | client::send_packet (SV *packet) |
2661 | client::send_packet (SV *packet) |
2630 | CODE: |
2662 | CODE: |
2631 | { |
2663 | { |
2632 | STRLEN len; |
2664 | STRLEN len; |
… | |
… | |
2687 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2719 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2688 | |
2720 | |
2689 | faceidx alloc (utf8_string name) |
2721 | faceidx alloc (utf8_string name) |
2690 | CODE: |
2722 | CODE: |
2691 | { |
2723 | { |
2692 | do |
2724 | RETVAL = face_alloc (); |
2693 | { |
|
|
2694 | RETVAL = faces.size (); |
|
|
2695 | faces.resize (RETVAL + 1); |
|
|
2696 | } |
|
|
2697 | while (!RETVAL); // crude way to leave index 0 |
|
|
2698 | |
2725 | |
2699 | faces [RETVAL].name = name; |
2726 | faces [RETVAL].name = name; |
2700 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2727 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2701 | |
2728 | |
2702 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2729 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2703 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2730 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2704 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2731 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2705 | } |
2732 | } |
|
|
2733 | OUTPUT: RETVAL |
|
|
2734 | |
|
|
2735 | faceidx faces_size () |
|
|
2736 | CODE: |
|
|
2737 | RETVAL = faces.size (); |
2706 | OUTPUT: RETVAL |
2738 | OUTPUT: RETVAL |
2707 | |
2739 | |
2708 | void set_type (faceidx idx, int value) |
2740 | void set_type (faceidx idx, int value) |
2709 | ALIAS: |
2741 | ALIAS: |
2710 | set_type = 0 |
2742 | set_type = 0 |
… | |
… | |
2756 | if (!d) XSRETURN_UNDEF; |
2788 | if (!d) XSRETURN_UNDEF; |
2757 | RETVAL = d->data.size (); |
2789 | RETVAL = d->data.size (); |
2758 | OUTPUT: |
2790 | OUTPUT: |
2759 | RETVAL |
2791 | RETVAL |
2760 | |
2792 | |
|
|
2793 | void set_meta (faceidx idx, SV *sv) |
|
|
2794 | CODE: |
|
|
2795 | { |
|
|
2796 | faceinfo *f = face_info (idx); assert (f); |
|
|
2797 | SvREFCNT_dec (f->meta_hv); |
|
|
2798 | f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0; |
|
|
2799 | } |
|
|
2800 | |
2761 | SV *get_chksum (faceidx idx, int faceset = 0) |
2801 | SV *get_chksum (faceidx idx, int faceset = 0) |
2762 | CODE: |
2802 | CODE: |
2763 | facedata *d = face_data (idx, faceset); |
2803 | facedata *d = face_data (idx, faceset); |
2764 | if (!d) XSRETURN_UNDEF; |
2804 | if (!d) XSRETURN_UNDEF; |
2765 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2805 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2766 | OUTPUT: |
2806 | OUTPUT: |
2767 | RETVAL |
2807 | RETVAL |
2768 | |
2808 | |
|
|
2809 | int get_type (faceidx idx) |
|
|
2810 | CODE: |
|
|
2811 | faceinfo *f = face_info (idx); |
|
|
2812 | if (!f) XSRETURN_UNDEF; |
|
|
2813 | RETVAL = f->type; |
|
|
2814 | OUTPUT: |
|
|
2815 | RETVAL |
|
|
2816 | |
2769 | SV *get_data (faceidx idx, int faceset = 0) |
2817 | SV *get_data (faceidx idx, int faceset = 0) |
2770 | CODE: |
2818 | CODE: |
2771 | facedata *d = face_data (idx, faceset); |
2819 | facedata *d = face_data (idx, faceset); |
2772 | if (!d) XSRETURN_UNDEF; |
2820 | if (!d) XSRETURN_UNDEF; |
2773 | RETVAL = newSVpvn (d->data.data (), d->data.length ()); |
2821 | RETVAL = newSVpvn (d->data, d->data.size ()); |
2774 | OUTPUT: |
2822 | OUTPUT: |
2775 | RETVAL |
2823 | RETVAL |
2776 | |
2824 | |
|
|
2825 | SV *get_meta (faceidx idx) |
|
|
2826 | CODE: |
|
|
2827 | faceinfo *f = face_info (idx); assert (f); |
|
|
2828 | if (!f || !f->meta_hv) XSRETURN_UNDEF; |
|
|
2829 | RETVAL = newRV_inc ((SV *)f->meta_hv); |
|
|
2830 | OUTPUT: |
|
|
2831 | RETVAL |
|
|
2832 | |
2777 | void invalidate (faceidx idx) |
2833 | void invalidate (faceidx idx) |
2778 | CODE: |
2834 | CODE: |
2779 | for_all_clients (ns) |
2835 | for_all_clients (ns) |
2780 | { |
2836 | ns->invalidate_face (idx); |
2781 | ns->faces_sent [idx] = false; |
|
|
2782 | ns->force_newmap = true; |
|
|
2783 | } |
|
|
2784 | |
2837 | |
2785 | void invalidate_all () |
2838 | void invalidate_all () |
2786 | CODE: |
2839 | CODE: |
2787 | for_all_clients (ns) |
2840 | for_all_clients (ns) |
2788 | { |
2841 | ns->invalidate_all_faces (); |
2789 | ns->faces_sent.reset (); |
|
|
2790 | ns->force_newmap = true; |
|
|
2791 | } |
|
|
2792 | |
2842 | |
2793 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2843 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2794 | |
2844 | |
2795 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2845 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2796 | |
2846 | |
… | |
… | |
2800 | OUTPUT: RETVAL |
2850 | OUTPUT: RETVAL |
2801 | |
2851 | |
2802 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2852 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2803 | CODE: |
2853 | CODE: |
2804 | { |
2854 | { |
2805 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2855 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2806 | croak ("frames must be an arrayref"); |
2856 | croak ("frames must be an arrayref"); |
2807 | |
2857 | |
2808 | AV *av = (AV *)SvRV (frames); |
2858 | AV *av = (AV *)SvRV (frames); |
2809 | |
2859 | |
2810 | animation *anim = &animation::find (name); |
2860 | animation *anim = &animation::find (name); |
2811 | if (anim->number) |
2861 | if (anim->number) |
2812 | { |
2862 | { |
2813 | anim->resize (av_len (av) + 1); |
2863 | anim->resize (av_len (av) + 1); |
2814 | anim->facings = facings; |
2864 | anim->facings = facings; |
2815 | } |
2865 | } |