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.126 by root, Thu Jan 4 16:19:32 2007 UTC vs.
Revision 1.131 by root, Mon Jan 8 18:18:35 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 106 assert (!(flags & F_BORROWED));
118#if 0 107}
119 assert (!rc_next); 108
120 assert (!refcnt); 109int
121#endif 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 flags &= ~F_BORROWED;
123 refcnt_inc ();
124 SvREFCNT_dec ((SV *)self);
125 }
122} 126}
123 127
124// check wether the object really is dead 128// check wether the object really is dead
125void 129void
126attachable::do_check () 130attachable::do_check ()
127{ 131{
128 if (refcnt > 0) 132 if (refcnt > 0)
129 return; 133 return;
130 134
131 // try to unborrow the refcnt from perl 135 optimise ();
132 if (flags & F_BORROWED) 136
137 if (self)
133 { 138 {
134 assert (self);//D//TODO//remove when stable 139 if (refcnt + SvREFCNT (self) > 0)
140 return;
141
142 assert (flags & F_BORROWED);
143
135 flags &= ~F_BORROWED; 144 flags &= ~F_BORROWED;
136 refcnt_inc (); 145 refcnt_inc ();
137 SvREFCNT_dec (self); 146 SvREFCNT_dec (self);
147 self = 0;
138 } 148 }
139 149
140 if (refcnt > 0 || self) 150 if (refcnt > 0)
141 return; 151 return;
142 152
143 destroy (); 153 destroy ();
144} 154}
145 155
146void 156void
147attachable::do_destroy () 157attachable::do_destroy ()
148{ 158{
149 invoke (EVENT_ATTACHABLE_DESTROY, DT_END); 159 invoke (EVENT_ATTACHABLE_DESTROY, DT_END);
150 160
151 //TODO: call generic destroy callback 161 if (self)
162 hv_clear (self);
163
152 mortals.push_back (this); 164 mortals.push_back (this);
153} 165}
154 166
155void 167void
156attachable::destroy () 168attachable::destroy ()
160 172
161 flags |= F_DESTROYED; 173 flags |= F_DESTROYED;
162 do_destroy (); 174 do_destroy ();
163} 175}
164 176
177void
165void attachable::check_mortals () 178attachable::check_mortals ()
166{ 179{
167 for (int i = 0; i < mortals.size (); ) 180 for (int i = 0; i < mortals.size (); )
168 { 181 {
169 attachable *obj = mortals [i]; 182 attachable *obj = mortals [i];
170 183
214 227
215static int 228static int
216attachable_free (pTHX_ SV *sv, MAGIC *mg) 229attachable_free (pTHX_ SV *sv, MAGIC *mg)
217{ 230{
218 attachable *at = (attachable *)mg->mg_ptr; 231 attachable *at = (attachable *)mg->mg_ptr;
219 assert (!(at->flags & attachable::F_BORROWED));//D//TODO//remove when stable 232 assert (!(at->flags & attachable::F_BORROWED));
220 at->self = 0; 233 at->self = 0;
221 // next line makes sense, but most objects still have refcnt 0 by default 234 // next line makes sense, but most objects still have refcnt 0 by default
222 //at->refcnt_chk (); 235 //at->refcnt_chk ();
223 return 0; 236 return 0;
224} 237}
237 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 250 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
238 251
239 // borrow the refcnt from the object 252 // borrow the refcnt from the object
240 obj->flags |= attachable::F_BORROWED; 253 obj->flags |= attachable::F_BORROWED;
241 obj->refcnt_dec (); 254 obj->refcnt_dec ();
255
256 // now bless the object _once_
257 return sv_bless (newRV_inc ((SV *)obj->self), stash);
242 } 258 }
243 259 else
244 return sv_bless (newRV_inc ((SV *)obj->self), stash); 260 return newRV_inc ((SV *)obj->self);
245} 261}
246 262
247static void 263static void
248clearSVptr (SV *sv) 264clearSVptr (SV *sv)
249{ 265{
333inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 349inline 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"); } 350inline 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"); } 351inline 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"); } 352inline 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"); } 353inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
354inline 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"); } 355inline 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"); } 356inline 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"); } 357inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
341 358
342inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO 359inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO
509 } 526 }
510 527
511 attach = 0; 528 attach = 0;
512} 529}
513#endif 530#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 531
527///////////////////////////////////////////////////////////////////////////// 532/////////////////////////////////////////////////////////////////////////////
528 533
529extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) 534extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
530{ 535{
1475 const_iv (ST_SETUP) 1480 const_iv (ST_SETUP)
1476 const_iv (ST_PLAYING) 1481 const_iv (ST_PLAYING)
1477 const_iv (ST_CUSTOM) 1482 const_iv (ST_CUSTOM)
1478 1483
1479 const_iv (ST_CHANGE_CLASS) 1484 const_iv (ST_CHANGE_CLASS)
1480 const_iv (ST_CONFIRM_QUIT)
1481 const_iv (ST_GET_PARTY_PASSWORD)
1482 1485
1483 const_iv (IO_HEADER) 1486 const_iv (IO_HEADER)
1484 const_iv (IO_OBJECTS) 1487 const_iv (IO_OBJECTS)
1485 const_iv (IO_UNIQUES) 1488 const_iv (IO_UNIQUES)
1486 1489
1540 1543
1541void _global_reattach () 1544void _global_reattach ()
1542 CODE: 1545 CODE:
1543{ 1546{
1544 // reattach to all attachable objects in the game. 1547 // reattach to all attachable objects in the game.
1545 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 1548 for_all_clients (ns)
1546 (*i)->reattach (); 1549 ns->reattach ();
1547 1550
1548 for_all_players (pl) 1551 for_all_players (pl)
1549 pl->reattach (); 1552 pl->reattach ();
1550 1553
1551 //TODO 1554 //TODO
1552 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) 1555 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i)
1553 // i->second->reattach (); 1556 // i->second->reattach ();
1554 1557
1555 for (object *op = object::first; op; op = op->next) 1558 for_all_objects (op)
1556 op->reattach (); 1559 op->reattach ();
1557} 1560}
1558 1561
1559NV floor (NV x) 1562NV floor (NV x)
1560 1563
1680 CODE: 1683 CODE:
1681 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1684 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1682 OUTPUT: 1685 OUTPUT:
1683 RETVAL 1686 RETVAL
1684 1687
1685#bool 1688INCLUDE: $PERL genacc attachable ../include/cfperl.h |
1686#destroyed (attachable *at)
1687#
1688#void
1689#destroy (attachable *at)
1690 1689
1691MODULE = cf PACKAGE = cf::global 1690MODULE = cf PACKAGE = cf::global
1692 1691
1693int invoke (SV *klass, int event, ...) 1692int invoke (SV *klass, int event, ...)
1694 CODE: 1693 CODE:
1997 CODE: 1996 CODE:
1998 pl->ob->stats.hp = pl->ob->stats.maxhp; 1997 pl->ob->stats.hp = pl->ob->stats.maxhp;
1999 pl->ob->stats.sp = pl->ob->stats.maxsp; 1998 pl->ob->stats.sp = pl->ob->stats.maxsp;
2000 pl->ob->stats.grace = pl->ob->stats.maxgrace; 1999 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2001 pl->orig_stats = pl->ob->stats; 2000 pl->orig_stats = pl->ob->stats;
2002
2003player *cf_player_find (char *name)
2004 PROTOTYPE: $
2005 2001
2006void cf_player_move (player *pl, int dir) 2002void cf_player_move (player *pl, int dir)
2007 2003
2008void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2004void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2009 2005
2055 if (y) sv_to (y, pl->bed_y); 2051 if (y) sv_to (y, pl->bed_y);
2056 2052
2057void 2053void
2058list () 2054list ()
2059 PPCODE: 2055 PPCODE:
2060 for (player *pl = first_player; pl; pl = pl->next) 2056 for_all_players (pl)
2061 XPUSHs (sv_2mortal (to_sv (pl))); 2057 XPUSHs (sv_2mortal (to_sv (pl)));
2062
2063bool
2064peaceful (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
2073living *
2074orig_stats (player *pl)
2075 CODE:
2076 RETVAL = &pl->orig_stats;
2077 OUTPUT: RETVAL
2078
2079living *
2080last_stats (player *pl)
2081 CODE:
2082 RETVAL = &pl->last_stats;
2083 OUTPUT: RETVAL
2084 2058
2085 2059
2086MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2060MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2087 2061
2088int invoke (maptile *map, int event, ...) 2062int invoke (maptile *map, int event, ...)
2104 PROTOTYPE: 2078 PROTOTYPE:
2105 CODE: 2079 CODE:
2106 RETVAL = new maptile; 2080 RETVAL = new maptile;
2107 OUTPUT: 2081 OUTPUT:
2108 RETVAL 2082 RETVAL
2109
2110void
2111maptile::destroy ()
2112 2083
2113void 2084void
2114maptile::players () 2085maptile::players ()
2115 PPCODE: 2086 PPCODE:
2116 if (GIMME_V == G_SCALAR) 2087 if (GIMME_V == G_SCALAR)
2384 char *buf = SvPVbyte (packet, len); 2355 char *buf = SvPVbyte (packet, len);
2385 2356
2386 THIS->send_packet (buf, len); 2357 THIS->send_packet (buf, len);
2387} 2358}
2388 2359
2389void
2390client::destroy ()
2391

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines