… | |
… | |
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::find_sync (const char *path, maptile *origin) |
831 | maptile::find_sync (const char *path, maptile *origin) |
… | |
… | |
1475 | const_iv (ST_SETUP) |
1468 | const_iv (ST_SETUP) |
1476 | const_iv (ST_PLAYING) |
1469 | const_iv (ST_PLAYING) |
1477 | const_iv (ST_CUSTOM) |
1470 | const_iv (ST_CUSTOM) |
1478 | |
1471 | |
1479 | const_iv (ST_CHANGE_CLASS) |
1472 | const_iv (ST_CHANGE_CLASS) |
1480 | const_iv (ST_CONFIRM_QUIT) |
|
|
1481 | const_iv (ST_GET_PARTY_PASSWORD) |
|
|
1482 | |
1473 | |
1483 | const_iv (IO_HEADER) |
1474 | const_iv (IO_HEADER) |
1484 | const_iv (IO_OBJECTS) |
1475 | const_iv (IO_OBJECTS) |
1485 | const_iv (IO_UNIQUES) |
1476 | const_iv (IO_UNIQUES) |
1486 | |
1477 | |
… | |
… | |
1540 | |
1531 | |
1541 | void _global_reattach () |
1532 | void _global_reattach () |
1542 | CODE: |
1533 | CODE: |
1543 | { |
1534 | { |
1544 | // reattach to all attachable objects in the game. |
1535 | // reattach to all attachable objects in the game. |
1545 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
1536 | for_all_clients (ns) |
1546 | (*i)->reattach (); |
1537 | ns->reattach (); |
1547 | |
1538 | |
1548 | for_all_players (pl) |
1539 | for_all_players (pl) |
1549 | pl->reattach (); |
1540 | pl->reattach (); |
1550 | |
1541 | |
1551 | //TODO |
1542 | //TODO |
1552 | //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) |
1543 | //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) |
1553 | // i->second->reattach (); |
1544 | // i->second->reattach (); |
1554 | |
1545 | |
1555 | for (object *op = object::first; op; op = op->next) |
1546 | for_all_objects (op) |
1556 | op->reattach (); |
1547 | op->reattach (); |
1557 | } |
1548 | } |
1558 | |
1549 | |
1559 | NV floor (NV x) |
1550 | NV floor (NV x) |
1560 | |
1551 | |
… | |
… | |
1613 | } |
1604 | } |
1614 | OUTPUT: RETVAL |
1605 | OUTPUT: RETVAL |
1615 | |
1606 | |
1616 | void abort () |
1607 | void abort () |
1617 | |
1608 | |
|
|
1609 | void cleanup (const char *cause, bool make_core = false) |
|
|
1610 | |
1618 | void emergency_save () |
1611 | void emergency_save () |
1619 | |
1612 | |
1620 | void _exit (int status = 0) |
1613 | void _exit (int status = 0) |
1621 | |
1614 | |
1622 | #if _POSIX_MEMLOCK |
1615 | #if _POSIX_MEMLOCK |
… | |
… | |
1680 | CODE: |
1673 | CODE: |
1681 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1674 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1682 | OUTPUT: |
1675 | OUTPUT: |
1683 | RETVAL |
1676 | RETVAL |
1684 | |
1677 | |
1685 | #bool |
1678 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1686 | #destroyed (attachable *at) |
|
|
1687 | # |
|
|
1688 | #void |
|
|
1689 | #destroy (attachable *at) |
|
|
1690 | |
1679 | |
1691 | MODULE = cf PACKAGE = cf::global |
1680 | MODULE = cf PACKAGE = cf::global |
1692 | |
1681 | |
1693 | int invoke (SV *klass, int event, ...) |
1682 | int invoke (SV *klass, int event, ...) |
1694 | CODE: |
1683 | CODE: |
… | |
… | |
1716 | PPCODE: |
1705 | PPCODE: |
1717 | EXTEND (SP, object::mortals.size ()); |
1706 | EXTEND (SP, object::mortals.size ()); |
1718 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
1707 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
1719 | PUSHs (to_sv (*i)); |
1708 | PUSHs (to_sv (*i)); |
1720 | |
1709 | |
1721 | object *first () |
1710 | int objects_size () |
1722 | CODE: |
1711 | CODE: |
1723 | 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; |
1724 | OUTPUT: RETVAL |
1728 | OUTPUT: RETVAL |
1725 | |
1729 | |
1726 | # missing properties |
1730 | # missing properties |
1727 | |
1731 | |
1728 | object *head (object *op) |
1732 | object *head (object *op) |
1729 | PROTOTYPE: $ |
1733 | PROTOTYPE: $ |
1730 | CODE: |
1734 | CODE: |
1731 | RETVAL = op->head ? op->head : op; |
1735 | RETVAL = op->head_ (); |
1732 | OUTPUT: RETVAL |
1736 | OUTPUT: RETVAL |
1733 | |
1737 | |
1734 | int is_head (object *op) |
1738 | int is_head (object *op) |
1735 | PROTOTYPE: $ |
1739 | PROTOTYPE: $ |
1736 | CODE: |
1740 | CODE: |
1737 | RETVAL = !op->head; |
1741 | RETVAL = op->head_ () == op; |
1738 | OUTPUT: RETVAL |
1742 | OUTPUT: RETVAL |
1739 | |
1743 | |
1740 | void |
1744 | void |
1741 | inv (object *obj) |
1745 | inv (object *obj) |
1742 | PROTOTYPE: $ |
1746 | PROTOTYPE: $ |
… | |
… | |
1997 | CODE: |
2001 | CODE: |
1998 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
2002 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
1999 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2003 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2000 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2004 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2001 | pl->orig_stats = pl->ob->stats; |
2005 | pl->orig_stats = pl->ob->stats; |
2002 | |
|
|
2003 | player *cf_player_find (char *name) |
|
|
2004 | PROTOTYPE: $ |
|
|
2005 | |
2006 | |
2006 | void cf_player_move (player *pl, int dir) |
2007 | void cf_player_move (player *pl, int dir) |
2007 | |
2008 | |
2008 | 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); |
2009 | |
2010 | |
… | |
… | |
2055 | if (y) sv_to (y, pl->bed_y); |
2056 | if (y) sv_to (y, pl->bed_y); |
2056 | |
2057 | |
2057 | void |
2058 | void |
2058 | list () |
2059 | list () |
2059 | PPCODE: |
2060 | PPCODE: |
2060 | for (player *pl = first_player; pl; pl = pl->next) |
2061 | for_all_players (pl) |
2061 | XPUSHs (sv_2mortal (to_sv (pl))); |
2062 | XPUSHs (sv_2mortal (to_sv (pl))); |
2062 | |
|
|
2063 | bool |
|
|
2064 | peaceful (player *pl, bool new_setting = 0) |
|
|
2065 | PROTOTYPE: $;$ |
|
|
2066 | CODE: |
|
|
2067 | RETVAL = pl->peaceful; |
|
|
2068 | if (items > 1) |
|
|
2069 | pl->peaceful = new_setting; |
|
|
2070 | OUTPUT: |
|
|
2071 | RETVAL |
|
|
2072 | |
|
|
2073 | living * |
|
|
2074 | orig_stats (player *pl) |
|
|
2075 | CODE: |
|
|
2076 | RETVAL = &pl->orig_stats; |
|
|
2077 | OUTPUT: RETVAL |
|
|
2078 | |
|
|
2079 | living * |
|
|
2080 | last_stats (player *pl) |
|
|
2081 | CODE: |
|
|
2082 | RETVAL = &pl->last_stats; |
|
|
2083 | OUTPUT: RETVAL |
|
|
2084 | |
2063 | |
2085 | |
2064 | |
2086 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2065 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2087 | |
2066 | |
2088 | int invoke (maptile *map, int event, ...) |
2067 | int invoke (maptile *map, int event, ...) |
… | |
… | |
2104 | PROTOTYPE: |
2083 | PROTOTYPE: |
2105 | CODE: |
2084 | CODE: |
2106 | RETVAL = new maptile; |
2085 | RETVAL = new maptile; |
2107 | OUTPUT: |
2086 | OUTPUT: |
2108 | RETVAL |
2087 | RETVAL |
2109 | |
|
|
2110 | void |
|
|
2111 | maptile::destroy () |
|
|
2112 | |
2088 | |
2113 | void |
2089 | void |
2114 | maptile::players () |
2090 | maptile::players () |
2115 | PPCODE: |
2091 | PPCODE: |
2116 | if (GIMME_V == G_SCALAR) |
2092 | if (GIMME_V == G_SCALAR) |
… | |
… | |
2384 | char *buf = SvPVbyte (packet, len); |
2360 | char *buf = SvPVbyte (packet, len); |
2385 | |
2361 | |
2386 | THIS->send_packet (buf, len); |
2362 | THIS->send_packet (buf, len); |
2387 | } |
2363 | } |
2388 | |
2364 | |
2389 | void |
|
|
2390 | client::destroy () |
|
|
2391 | |
|
|