… | |
… | |
99 | |
99 | |
100 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
100 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
101 | |
101 | |
102 | unordered_vector<attachable *> attachable::mortals; |
102 | unordered_vector<attachable *> attachable::mortals; |
103 | |
103 | |
104 | #if 0 |
|
|
105 | attachable *attachable::rc_first; |
|
|
106 | |
|
|
107 | attachable::attachable () |
|
|
108 | { |
|
|
109 | refcnt = 0; |
|
|
110 | rc_next = rc_first; |
|
|
111 | rc_first = this; |
|
|
112 | } |
|
|
113 | #endif |
|
|
114 | |
|
|
115 | attachable::~attachable () |
104 | attachable::~attachable () |
116 | { |
105 | { |
117 | assert (!(flags & F_BORROWED));//D//TODO//remove when stable |
|
|
118 | #if 0 |
|
|
119 | assert (!rc_next); |
|
|
120 | assert (!refcnt); |
106 | assert (!self); |
121 | #endif |
107 | } |
|
|
108 | |
|
|
109 | int |
|
|
110 | attachable::refcnt_cnt () const |
|
|
111 | { |
|
|
112 | return refcnt + (self ? SvREFCNT (self) : 0); |
|
|
113 | } |
|
|
114 | |
|
|
115 | void |
|
|
116 | attachable::optimise () |
|
|
117 | { |
|
|
118 | if (self |
|
|
119 | && SvREFCNT (self) == 1 |
|
|
120 | && !HvTOTALKEYS (self)) |
|
|
121 | { |
|
|
122 | refcnt_inc (); |
|
|
123 | SvREFCNT_dec ((SV *)self); |
|
|
124 | } |
122 | } |
125 | } |
123 | |
126 | |
124 | // check wether the object really is dead |
127 | // check wether the object really is dead |
125 | void |
128 | void |
126 | attachable::do_check () |
129 | attachable::do_check () |
127 | { |
130 | { |
128 | if (refcnt > 0) |
131 | if (refcnt > 0 || refcnt_cnt () > 0) |
129 | return; |
132 | return; |
130 | |
133 | |
131 | // try to unborrow the refcnt from perl |
134 | destroy (); |
132 | if (flags & F_BORROWED) |
135 | |
|
|
136 | if (self) |
133 | { |
137 | { |
134 | assert (self);//D//TODO//remove when stable |
138 | hv_clear (self); |
135 | flags &= ~F_BORROWED; |
139 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
136 | refcnt_inc (); |
|
|
137 | SvREFCNT_dec (self); |
140 | SvREFCNT_dec (self); |
|
|
141 | self = 0; |
138 | } |
142 | } |
139 | |
|
|
140 | if (refcnt > 0 || self) |
|
|
141 | return; |
|
|
142 | |
|
|
143 | destroy (); |
|
|
144 | } |
143 | } |
145 | |
144 | |
146 | void |
145 | void |
147 | attachable::do_destroy () |
146 | attachable::do_destroy () |
148 | { |
147 | { |
149 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
148 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
150 | |
149 | |
151 | //TODO: call generic destroy callback |
150 | if (self) |
|
|
151 | hv_clear (self); |
|
|
152 | |
152 | mortals.push_back (this); |
153 | mortals.push_back (this); |
153 | } |
154 | } |
154 | |
155 | |
155 | void |
156 | void |
156 | attachable::destroy () |
157 | attachable::destroy () |
… | |
… | |
160 | |
161 | |
161 | flags |= F_DESTROYED; |
162 | flags |= F_DESTROYED; |
162 | do_destroy (); |
163 | do_destroy (); |
163 | } |
164 | } |
164 | |
165 | |
|
|
166 | void |
165 | void attachable::check_mortals () |
167 | attachable::check_mortals () |
166 | { |
168 | { |
167 | for (int i = 0; i < mortals.size (); ) |
169 | for (int i = 0; i < mortals.size (); ) |
168 | { |
170 | { |
169 | attachable *obj = mortals [i]; |
171 | attachable *obj = mortals [i]; |
170 | |
172 | |
… | |
… | |
214 | |
216 | |
215 | static int |
217 | static int |
216 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
218 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
217 | { |
219 | { |
218 | attachable *at = (attachable *)mg->mg_ptr; |
220 | attachable *at = (attachable *)mg->mg_ptr; |
219 | assert (!(at->flags & attachable::F_BORROWED));//D//TODO//remove when stable |
|
|
220 | at->self = 0; |
221 | at->self = 0; |
221 | // next line makes sense, but most objects still have refcnt 0 by default |
222 | // next line makes sense, but most objects still have refcnt 0 by default |
222 | //at->refcnt_chk (); |
223 | //at->refcnt_chk (); |
223 | return 0; |
224 | return 0; |
224 | } |
225 | } |
… | |
… | |
235 | { |
236 | { |
236 | obj->self = newHV (); |
237 | obj->self = newHV (); |
237 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
238 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
238 | |
239 | |
239 | // borrow the refcnt from the object |
240 | // borrow the refcnt from the object |
240 | obj->flags |= attachable::F_BORROWED; |
241 | // it is important thta no refcnt_chk is being executed here |
241 | obj->refcnt_dec (); |
242 | obj->refcnt_dec (); |
|
|
243 | |
|
|
244 | // now bless the object _once_ |
|
|
245 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
242 | } |
246 | } |
243 | |
247 | else |
244 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
248 | return newRV_inc ((SV *)obj->self); |
245 | } |
249 | } |
246 | |
250 | |
247 | static void |
251 | static void |
248 | clearSVptr (SV *sv) |
252 | clearSVptr (SV *sv) |
249 | { |
253 | { |
… | |
… | |
333 | inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
337 | inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
334 | inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
338 | inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
335 | inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
339 | inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
336 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
340 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
337 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
341 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
|
|
342 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
338 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
343 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
339 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
344 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
340 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
345 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
341 | |
346 | |
342 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
347 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
… | |
… | |
509 | } |
514 | } |
510 | |
515 | |
511 | attach = 0; |
516 | attach = 0; |
512 | } |
517 | } |
513 | #endif |
518 | #endif |
514 | |
|
|
515 | void attachable::optimise () |
|
|
516 | { |
|
|
517 | if (self |
|
|
518 | && SvREFCNT (self) == 1 |
|
|
519 | && !HvTOTALKEYS (self)) |
|
|
520 | { |
|
|
521 | flags &= ~F_BORROWED; |
|
|
522 | refcnt_inc (); |
|
|
523 | SvREFCNT_dec ((SV *)self); |
|
|
524 | } |
|
|
525 | } |
|
|
526 | |
519 | |
527 | ///////////////////////////////////////////////////////////////////////////// |
520 | ///////////////////////////////////////////////////////////////////////////// |
528 | |
521 | |
529 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
522 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
530 | { |
523 | { |
… | |
… | |
825 | } |
818 | } |
826 | |
819 | |
827 | ///////////////////////////////////////////////////////////////////////////// |
820 | ///////////////////////////////////////////////////////////////////////////// |
828 | |
821 | |
829 | void |
822 | void |
830 | maptile::emergency_save () |
823 | cfperl_emergency_save () |
831 | { |
824 | { |
832 | CALL_BEGIN (0); |
825 | CALL_BEGIN (0); |
833 | CALL_CALL ("cf::map::emergency_save", G_VOID); |
826 | CALL_CALL ("cf::emergency_save", G_VOID); |
834 | CALL_END; |
827 | CALL_END; |
835 | } |
828 | } |
836 | |
829 | |
837 | maptile * |
830 | maptile * |
838 | maptile::load_map_sync (const char *path, maptile *origin) |
831 | maptile::find_sync (const char *path, maptile *origin) |
839 | { |
832 | { |
840 | CALL_BEGIN (2); |
833 | CALL_BEGIN (2); |
841 | CALL_ARG (path); |
834 | CALL_ARG (path); |
842 | CALL_ARG (origin); |
835 | CALL_ARG (origin); |
843 | CALL_CALL ("cf::map::load_map_sync", G_SCALAR); |
836 | CALL_CALL ("cf::map::find_sync", G_SCALAR); |
844 | |
837 | |
845 | maptile *retval; |
838 | maptile *retval; |
846 | |
839 | |
847 | if (count) |
840 | if (count) |
848 | sv_to (POPs, retval); |
841 | sv_to (POPs, retval); |
… | |
… | |
850 | retval = 0; |
843 | retval = 0; |
851 | |
844 | |
852 | CALL_END; |
845 | CALL_END; |
853 | |
846 | |
854 | return retval; |
847 | return retval; |
|
|
848 | } |
|
|
849 | |
|
|
850 | void |
|
|
851 | maptile::do_load_sync () |
|
|
852 | { |
|
|
853 | CALL_BEGIN (1); |
|
|
854 | CALL_ARG (this); |
|
|
855 | CALL_CALL ("cf::map::do_load_sync", G_SCALAR); |
|
|
856 | CALL_END; |
855 | } |
857 | } |
856 | |
858 | |
857 | void |
859 | void |
858 | maptile::change_all_map_light (int change) |
860 | maptile::change_all_map_light (int change) |
859 | { |
861 | { |
… | |
… | |
1466 | const_iv (ST_SETUP) |
1468 | const_iv (ST_SETUP) |
1467 | const_iv (ST_PLAYING) |
1469 | const_iv (ST_PLAYING) |
1468 | const_iv (ST_CUSTOM) |
1470 | const_iv (ST_CUSTOM) |
1469 | |
1471 | |
1470 | const_iv (ST_CHANGE_CLASS) |
1472 | const_iv (ST_CHANGE_CLASS) |
1471 | const_iv (ST_CONFIRM_QUIT) |
|
|
1472 | const_iv (ST_GET_PARTY_PASSWORD) |
|
|
1473 | |
1473 | |
1474 | const_iv (IO_HEADER) |
1474 | const_iv (IO_HEADER) |
1475 | const_iv (IO_OBJECTS) |
1475 | const_iv (IO_OBJECTS) |
1476 | const_iv (IO_UNIQUES) |
1476 | const_iv (IO_UNIQUES) |
1477 | |
1477 | |
… | |
… | |
1531 | |
1531 | |
1532 | void _global_reattach () |
1532 | void _global_reattach () |
1533 | CODE: |
1533 | CODE: |
1534 | { |
1534 | { |
1535 | // reattach to all attachable objects in the game. |
1535 | // reattach to all attachable objects in the game. |
1536 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
1536 | for_all_clients (ns) |
1537 | (*i)->reattach (); |
1537 | ns->reattach (); |
1538 | |
1538 | |
1539 | for_all_players (pl) |
1539 | for_all_players (pl) |
1540 | pl->reattach (); |
1540 | pl->reattach (); |
1541 | |
1541 | |
1542 | //TODO |
1542 | //TODO |
1543 | //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) |
1543 | //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) |
1544 | // i->second->reattach (); |
1544 | // i->second->reattach (); |
1545 | |
1545 | |
1546 | for (object *op = object::first; op; op = op->next) |
1546 | for_all_objects (op) |
1547 | op->reattach (); |
1547 | op->reattach (); |
1548 | } |
1548 | } |
1549 | |
1549 | |
1550 | NV floor (NV x) |
1550 | NV floor (NV x) |
1551 | |
1551 | |
… | |
… | |
1604 | } |
1604 | } |
1605 | OUTPUT: RETVAL |
1605 | OUTPUT: RETVAL |
1606 | |
1606 | |
1607 | void abort () |
1607 | void abort () |
1608 | |
1608 | |
|
|
1609 | void cleanup (const char *cause, bool make_core = false) |
|
|
1610 | |
1609 | void emergency_save () |
1611 | void emergency_save () |
1610 | |
1612 | |
1611 | void _exit (int status = 0) |
1613 | void _exit (int status = 0) |
1612 | |
1614 | |
1613 | #if _POSIX_MEMLOCK |
1615 | #if _POSIX_MEMLOCK |
… | |
… | |
1671 | CODE: |
1673 | CODE: |
1672 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1674 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1673 | OUTPUT: |
1675 | OUTPUT: |
1674 | RETVAL |
1676 | RETVAL |
1675 | |
1677 | |
1676 | #bool |
1678 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1677 | #destroyed (attachable *at) |
|
|
1678 | # |
|
|
1679 | #void |
|
|
1680 | #destroy (attachable *at) |
|
|
1681 | |
1679 | |
1682 | MODULE = cf PACKAGE = cf::global |
1680 | MODULE = cf PACKAGE = cf::global |
1683 | |
1681 | |
1684 | int invoke (SV *klass, int event, ...) |
1682 | int invoke (SV *klass, int event, ...) |
1685 | CODE: |
1683 | CODE: |
… | |
… | |
1707 | PPCODE: |
1705 | PPCODE: |
1708 | EXTEND (SP, object::mortals.size ()); |
1706 | EXTEND (SP, object::mortals.size ()); |
1709 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
1707 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
1710 | PUSHs (to_sv (*i)); |
1708 | PUSHs (to_sv (*i)); |
1711 | |
1709 | |
1712 | object *first () |
1710 | int objects_size () |
1713 | CODE: |
1711 | CODE: |
1714 | RETVAL = object::first; |
1712 | RETVAL = objects.size (); |
|
|
1713 | OUTPUT: RETVAL |
|
|
1714 | |
|
|
1715 | object *objects (U32 index) |
|
|
1716 | CODE: |
|
|
1717 | RETVAL = index < objects.size () ? objects [index] : 0; |
|
|
1718 | OUTPUT: RETVAL |
|
|
1719 | |
|
|
1720 | int actives_size () |
|
|
1721 | CODE: |
|
|
1722 | RETVAL = actives.size (); |
|
|
1723 | OUTPUT: RETVAL |
|
|
1724 | |
|
|
1725 | object *actives (U32 index) |
|
|
1726 | CODE: |
|
|
1727 | RETVAL = index < actives.size () ? actives [index] : 0; |
1715 | OUTPUT: RETVAL |
1728 | OUTPUT: RETVAL |
1716 | |
1729 | |
1717 | # missing properties |
1730 | # missing properties |
1718 | |
1731 | |
1719 | object *head (object *op) |
1732 | object *head (object *op) |
1720 | PROTOTYPE: $ |
1733 | PROTOTYPE: $ |
1721 | CODE: |
1734 | CODE: |
1722 | RETVAL = op->head ? op->head : op; |
1735 | RETVAL = op->head_ (); |
1723 | OUTPUT: RETVAL |
1736 | OUTPUT: RETVAL |
1724 | |
1737 | |
1725 | int is_head (object *op) |
1738 | int is_head (object *op) |
1726 | PROTOTYPE: $ |
1739 | PROTOTYPE: $ |
1727 | CODE: |
1740 | CODE: |
1728 | RETVAL = !op->head; |
1741 | RETVAL = op->head_ () == op; |
1729 | OUTPUT: RETVAL |
1742 | OUTPUT: RETVAL |
1730 | |
1743 | |
1731 | void |
1744 | void |
1732 | inv (object *obj) |
1745 | inv (object *obj) |
1733 | PROTOTYPE: $ |
1746 | PROTOTYPE: $ |
… | |
… | |
1988 | CODE: |
2001 | CODE: |
1989 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
2002 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
1990 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2003 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
1991 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2004 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
1992 | pl->orig_stats = pl->ob->stats; |
2005 | pl->orig_stats = pl->ob->stats; |
1993 | |
|
|
1994 | player *cf_player_find (char *name) |
|
|
1995 | PROTOTYPE: $ |
|
|
1996 | |
2006 | |
1997 | void cf_player_move (player *pl, int dir) |
2007 | void cf_player_move (player *pl, int dir) |
1998 | |
2008 | |
1999 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2009 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2000 | |
2010 | |
… | |
… | |
2046 | if (y) sv_to (y, pl->bed_y); |
2056 | if (y) sv_to (y, pl->bed_y); |
2047 | |
2057 | |
2048 | void |
2058 | void |
2049 | list () |
2059 | list () |
2050 | PPCODE: |
2060 | PPCODE: |
2051 | for (player *pl = first_player; pl; pl = pl->next) |
2061 | for_all_players (pl) |
2052 | XPUSHs (sv_2mortal (to_sv (pl))); |
2062 | XPUSHs (sv_2mortal (to_sv (pl))); |
2053 | |
|
|
2054 | bool |
|
|
2055 | peaceful (player *pl, bool new_setting = 0) |
|
|
2056 | PROTOTYPE: $;$ |
|
|
2057 | CODE: |
|
|
2058 | RETVAL = pl->peaceful; |
|
|
2059 | if (items > 1) |
|
|
2060 | pl->peaceful = new_setting; |
|
|
2061 | OUTPUT: |
|
|
2062 | RETVAL |
|
|
2063 | |
|
|
2064 | living * |
|
|
2065 | orig_stats (player *pl) |
|
|
2066 | CODE: |
|
|
2067 | RETVAL = &pl->orig_stats; |
|
|
2068 | OUTPUT: RETVAL |
|
|
2069 | |
|
|
2070 | living * |
|
|
2071 | last_stats (player *pl) |
|
|
2072 | CODE: |
|
|
2073 | RETVAL = &pl->last_stats; |
|
|
2074 | OUTPUT: RETVAL |
|
|
2075 | |
2063 | |
2076 | |
2064 | |
2077 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2065 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2078 | |
2066 | |
2079 | int invoke (maptile *map, int event, ...) |
2067 | int invoke (maptile *map, int event, ...) |
… | |
… | |
2095 | PROTOTYPE: |
2083 | PROTOTYPE: |
2096 | CODE: |
2084 | CODE: |
2097 | RETVAL = new maptile; |
2085 | RETVAL = new maptile; |
2098 | OUTPUT: |
2086 | OUTPUT: |
2099 | RETVAL |
2087 | RETVAL |
2100 | |
|
|
2101 | void |
|
|
2102 | maptile::destroy () |
|
|
2103 | |
2088 | |
2104 | void |
2089 | void |
2105 | maptile::players () |
2090 | maptile::players () |
2106 | PPCODE: |
2091 | PPCODE: |
2107 | if (GIMME_V == G_SCALAR) |
2092 | if (GIMME_V == G_SCALAR) |
… | |
… | |
2375 | char *buf = SvPVbyte (packet, len); |
2360 | char *buf = SvPVbyte (packet, len); |
2376 | |
2361 | |
2377 | THIS->send_packet (buf, len); |
2362 | THIS->send_packet (buf, len); |
2378 | } |
2363 | } |
2379 | |
2364 | |
2380 | void |
|
|
2381 | client::destroy () |
|
|
2382 | |
|
|