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.125 by root, Thu Jan 4 00:53:54 2007 UTC vs.
Revision 1.134 by root, Tue Jan 9 21:32:42 2007 UTC

99 99
100////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 100//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101 101
102unordered_vector<attachable *> attachable::mortals; 102unordered_vector<attachable *> attachable::mortals;
103 103
104#if 0
105attachable *attachable::rc_first;
106
107attachable::attachable ()
108{
109 refcnt = 0;
110 rc_next = rc_first;
111 rc_first = this;
112}
113#endif
114
115attachable::~attachable () 104attachable::~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
109int
110attachable::refcnt_cnt () const
111{
112 return refcnt + (self ? SvREFCNT (self) : 0);
113}
114
115void
116attachable::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
125void 128void
126attachable::do_check () 129attachable::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
146void 145void
147attachable::do_destroy () 146attachable::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
155void 156void
156attachable::destroy () 157attachable::destroy ()
160 161
161 flags |= F_DESTROYED; 162 flags |= F_DESTROYED;
162 do_destroy (); 163 do_destroy ();
163} 164}
164 165
166void
165void attachable::check_mortals () 167attachable::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
215static int 217static int
216attachable_free (pTHX_ SV *sv, MAGIC *mg) 218attachable_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
247static void 251static void
248clearSVptr (SV *sv) 252clearSVptr (SV *sv)
249{ 253{
333inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 337inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
334inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 338inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
335inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 339inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
336inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 340inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
337inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 341inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
342inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
338inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 343inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
339inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } 344inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
340inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 345inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
341 346
342inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO 347inline 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
515void 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
529extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) 522extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
530{ 523{
825} 818}
826 819
827///////////////////////////////////////////////////////////////////////////// 820/////////////////////////////////////////////////////////////////////////////
828 821
829void 822void
830maptile::emergency_save () 823cfperl_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
837maptile * 830maptile *
838maptile::load_map_sync (const char *path, maptile *origin) 831maptile::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
850void
851maptile::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
857void 859void
858maptile::change_all_map_light (int change) 860maptile::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
1532void _global_reattach () 1532void _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
1550NV floor (NV x) 1550NV floor (NV x)
1551 1551
1604 } 1604 }
1605 OUTPUT: RETVAL 1605 OUTPUT: RETVAL
1606 1606
1607void abort () 1607void abort ()
1608 1608
1609void cleanup (const char *cause, bool make_core = false)
1610
1609void emergency_save () 1611void emergency_save ()
1610 1612
1611void _exit (int status = 0) 1613void _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 1678INCLUDE: $PERL genacc attachable ../include/cfperl.h |
1677#destroyed (attachable *at)
1678#
1679#void
1680#destroy (attachable *at)
1681 1679
1682MODULE = cf PACKAGE = cf::global 1680MODULE = cf PACKAGE = cf::global
1683 1681
1684int invoke (SV *klass, int event, ...) 1682int 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
1712object *first () 1710int objects_size ()
1713 CODE: 1711 CODE:
1714 RETVAL = object::first; 1712 RETVAL = objects.size ();
1713 OUTPUT: RETVAL
1714
1715object *objects (U32 index)
1716 CODE:
1717 RETVAL = index < objects.size () ? objects [index] : 0;
1718 OUTPUT: RETVAL
1719
1720int actives_size ()
1721 CODE:
1722 RETVAL = actives.size ();
1723 OUTPUT: RETVAL
1724
1725object *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
1719object *head (object *op) 1732object *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
1725int is_head (object *op) 1738int 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
1731void 1744void
1732inv (object *obj) 1745inv (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
1994player *cf_player_find (char *name)
1995 PROTOTYPE: $
1996 2006
1997void cf_player_move (player *pl, int dir) 2007void cf_player_move (player *pl, int dir)
1998 2008
1999void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2009void 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
2048void 2058void
2049list () 2059list ()
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
2054bool
2055peaceful (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
2064living *
2065orig_stats (player *pl)
2066 CODE:
2067 RETVAL = &pl->orig_stats;
2068 OUTPUT: RETVAL
2069
2070living *
2071last_stats (player *pl)
2072 CODE:
2073 RETVAL = &pl->last_stats;
2074 OUTPUT: RETVAL
2075 2063
2076 2064
2077MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2065MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2078 2066
2079int invoke (maptile *map, int event, ...) 2067int 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
2101void
2102maptile::destroy ()
2103 2088
2104void 2089void
2105maptile::players () 2090maptile::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
2380void
2381client::destroy ()
2382

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines