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.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{
833 CALL_CALL ("cf::map::emergency_save", G_VOID); 838 CALL_CALL ("cf::map::emergency_save", G_VOID);
834 CALL_END; 839 CALL_END;
835} 840}
836 841
837maptile * 842maptile *
838maptile::load_map_sync (const char *path, maptile *origin) 843maptile::find_sync (const char *path, maptile *origin)
839{ 844{
840 CALL_BEGIN (2); 845 CALL_BEGIN (2);
841 CALL_ARG (path); 846 CALL_ARG (path);
842 CALL_ARG (origin); 847 CALL_ARG (origin);
843 CALL_CALL ("cf::map::load_map_sync", G_SCALAR); 848 CALL_CALL ("cf::map::find_sync", G_SCALAR);
844 849
845 maptile *retval; 850 maptile *retval;
846 851
847 if (count) 852 if (count)
848 sv_to (POPs, retval); 853 sv_to (POPs, retval);
850 retval = 0; 855 retval = 0;
851 856
852 CALL_END; 857 CALL_END;
853 858
854 return retval; 859 return retval;
860}
861
862void
863maptile::do_load_sync ()
864{
865 CALL_BEGIN (1);
866 CALL_ARG (this);
867 CALL_CALL ("cf::map::do_load_sync", G_SCALAR);
868 CALL_END;
855} 869}
856 870
857void 871void
858maptile::change_all_map_light (int change) 872maptile::change_all_map_light (int change)
859{ 873{
1466 const_iv (ST_SETUP) 1480 const_iv (ST_SETUP)
1467 const_iv (ST_PLAYING) 1481 const_iv (ST_PLAYING)
1468 const_iv (ST_CUSTOM) 1482 const_iv (ST_CUSTOM)
1469 1483
1470 const_iv (ST_CHANGE_CLASS) 1484 const_iv (ST_CHANGE_CLASS)
1471 const_iv (ST_CONFIRM_QUIT)
1472 const_iv (ST_GET_PARTY_PASSWORD)
1473 1485
1474 const_iv (IO_HEADER) 1486 const_iv (IO_HEADER)
1475 const_iv (IO_OBJECTS) 1487 const_iv (IO_OBJECTS)
1476 const_iv (IO_UNIQUES) 1488 const_iv (IO_UNIQUES)
1477 1489
1531 1543
1532void _global_reattach () 1544void _global_reattach ()
1533 CODE: 1545 CODE:
1534{ 1546{
1535 // reattach to all attachable objects in the game. 1547 // reattach to all attachable objects in the game.
1536 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 1548 for_all_clients (ns)
1537 (*i)->reattach (); 1549 ns->reattach ();
1538 1550
1539 for_all_players (pl) 1551 for_all_players (pl)
1540 pl->reattach (); 1552 pl->reattach ();
1541 1553
1542 //TODO 1554 //TODO
1543 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) 1555 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i)
1544 // i->second->reattach (); 1556 // i->second->reattach ();
1545 1557
1546 for (object *op = object::first; op; op = op->next) 1558 for_all_objects (op)
1547 op->reattach (); 1559 op->reattach ();
1548} 1560}
1549 1561
1550NV floor (NV x) 1562NV floor (NV x)
1551 1563
1671 CODE: 1683 CODE:
1672 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1684 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1673 OUTPUT: 1685 OUTPUT:
1674 RETVAL 1686 RETVAL
1675 1687
1676#bool 1688INCLUDE: $PERL genacc attachable ../include/cfperl.h |
1677#destroyed (attachable *at)
1678#
1679#void
1680#destroy (attachable *at)
1681 1689
1682MODULE = cf PACKAGE = cf::global 1690MODULE = cf PACKAGE = cf::global
1683 1691
1684int invoke (SV *klass, int event, ...) 1692int invoke (SV *klass, int event, ...)
1685 CODE: 1693 CODE:
1988 CODE: 1996 CODE:
1989 pl->ob->stats.hp = pl->ob->stats.maxhp; 1997 pl->ob->stats.hp = pl->ob->stats.maxhp;
1990 pl->ob->stats.sp = pl->ob->stats.maxsp; 1998 pl->ob->stats.sp = pl->ob->stats.maxsp;
1991 pl->ob->stats.grace = pl->ob->stats.maxgrace; 1999 pl->ob->stats.grace = pl->ob->stats.maxgrace;
1992 pl->orig_stats = pl->ob->stats; 2000 pl->orig_stats = pl->ob->stats;
1993
1994player *cf_player_find (char *name)
1995 PROTOTYPE: $
1996 2001
1997void cf_player_move (player *pl, int dir) 2002void cf_player_move (player *pl, int dir)
1998 2003
1999void 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);
2000 2005
2046 if (y) sv_to (y, pl->bed_y); 2051 if (y) sv_to (y, pl->bed_y);
2047 2052
2048void 2053void
2049list () 2054list ()
2050 PPCODE: 2055 PPCODE:
2051 for (player *pl = first_player; pl; pl = pl->next) 2056 for_all_players (pl)
2052 XPUSHs (sv_2mortal (to_sv (pl))); 2057 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 2058
2076 2059
2077MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2060MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2078 2061
2079int invoke (maptile *map, int event, ...) 2062int invoke (maptile *map, int event, ...)
2095 PROTOTYPE: 2078 PROTOTYPE:
2096 CODE: 2079 CODE:
2097 RETVAL = new maptile; 2080 RETVAL = new maptile;
2098 OUTPUT: 2081 OUTPUT:
2099 RETVAL 2082 RETVAL
2100
2101void
2102maptile::destroy ()
2103 2083
2104void 2084void
2105maptile::players () 2085maptile::players ()
2106 PPCODE: 2086 PPCODE:
2107 if (GIMME_V == G_SCALAR) 2087 if (GIMME_V == G_SCALAR)
2375 char *buf = SvPVbyte (packet, len); 2355 char *buf = SvPVbyte (packet, len);
2376 2356
2377 THIS->send_packet (buf, len); 2357 THIS->send_packet (buf, len);
2378} 2358}
2379 2359
2380void
2381client::destroy ()
2382

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines