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.131 by root, Mon Jan 8 18:18:35 2007 UTC vs.
Revision 1.139 by root, Thu Jan 11 23:17:05 2007 UTC

101 101
102unordered_vector<attachable *> attachable::mortals; 102unordered_vector<attachable *> attachable::mortals;
103 103
104attachable::~attachable () 104attachable::~attachable ()
105{ 105{
106 assert (!(flags & F_BORROWED)); 106 assert (!self);
107} 107}
108 108
109int 109int
110attachable::refcnt_cnt () const 110attachable::refcnt_cnt () const
111{ 111{
117{ 117{
118 if (self 118 if (self
119 && SvREFCNT (self) == 1 119 && SvREFCNT (self) == 1
120 && !HvTOTALKEYS (self)) 120 && !HvTOTALKEYS (self))
121 { 121 {
122 flags &= ~F_BORROWED;
123 refcnt_inc (); 122 refcnt_inc ();
124 SvREFCNT_dec ((SV *)self); 123 SvREFCNT_dec ((SV *)self);
125 } 124 }
126} 125}
127 126
128// check wether the object really is dead 127// check wether the object really is dead
129void 128void
130attachable::do_check () 129attachable::do_check ()
131{ 130{
132 if (refcnt > 0) 131 if (refcnt > 0 || refcnt_cnt () > 0)
133 return; 132 return;
134 133
135 optimise (); 134 destroy ();
136 135
137 if (self) 136 if (self)
138 { 137 {
139 if (refcnt + SvREFCNT (self) > 0) 138 hv_clear (self);
140 return; 139 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
141
142 assert (flags & F_BORROWED);
143
144 flags &= ~F_BORROWED;
145 refcnt_inc ();
146 SvREFCNT_dec (self); 140 SvREFCNT_dec (self);
147 self = 0; 141 self = 0;
148 } 142 }
149
150 if (refcnt > 0)
151 return;
152
153 destroy ();
154} 143}
155 144
156void 145void
157attachable::do_destroy () 146attachable::do_destroy ()
158{ 147{
227 216
228static int 217static int
229attachable_free (pTHX_ SV *sv, MAGIC *mg) 218attachable_free (pTHX_ SV *sv, MAGIC *mg)
230{ 219{
231 attachable *at = (attachable *)mg->mg_ptr; 220 attachable *at = (attachable *)mg->mg_ptr;
232 assert (!(at->flags & attachable::F_BORROWED));
233 at->self = 0; 221 at->self = 0;
234 // 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
235 //at->refcnt_chk (); 223 //at->refcnt_chk ();
236 return 0; 224 return 0;
237} 225}
248 { 236 {
249 obj->self = newHV (); 237 obj->self = newHV ();
250 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);
251 239
252 // borrow the refcnt from the object 240 // borrow the refcnt from the object
253 obj->flags |= attachable::F_BORROWED; 241 // it is important thta no refcnt_chk is being executed here
254 obj->refcnt_dec (); 242 obj->refcnt_dec ();
255 243
256 // now bless the object _once_ 244 // now bless the object _once_
257 return sv_bless (newRV_inc ((SV *)obj->self), stash); 245 return sv_bless (newRV_inc ((SV *)obj->self), stash);
258 } 246 }
318inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 306inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
319 307
320inline SV *to_sv (object & v) { return to_sv (&v); } 308inline SV *to_sv (object & v) { return to_sv (&v); }
321inline SV *to_sv (living & v) { return to_sv (&v); } 309inline SV *to_sv (living & v) { return to_sv (&v); }
322 310
323//TODO:
324inline SV *to_sv (New_Face * v) { return to_sv (v->name); } 311inline SV *to_sv (New_Face * v) { return to_sv (v->name); }
325inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 312inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
326 313
327inline SV *to_sv (UUID v) 314inline SV *to_sv (UUID v)
328{ 315{
354inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 341inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
355inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 342inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
356inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } 343inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
357inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 344inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
358 345
359inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO 346inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; }
360inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO 347inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); }
361 348
362template<class T> 349template<class T>
363inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 350inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
364 351
365template<int N> 352template<int N>
501 if (!ext->cb) 488 if (!ext->cb)
502 ext->cb = newAV (); 489 ext->cb = newAV ();
503 490
504 return newRV_inc ((SV *)ext->cb); 491 return newRV_inc ((SV *)ext->cb);
505} 492}
506
507#if 0
508void attachable::clear ()
509{
510 if (self)
511 {
512 // disconnect Perl from C, to avoid crashes
513 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
514
515 // clear the perl hash, might or might not be a good idea
516 hv_clear ((HV *)SvRV ((SV *)self));
517
518 SvREFCNT_dec (self);
519 self = 0;
520 }
521
522 if (cb)
523 {
524 SvREFCNT_dec (cb);
525 cb = 0;
526 }
527
528 attach = 0;
529}
530#endif
531 493
532///////////////////////////////////////////////////////////////////////////// 494/////////////////////////////////////////////////////////////////////////////
533 495
534extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) 496extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
535{ 497{
830} 792}
831 793
832///////////////////////////////////////////////////////////////////////////// 794/////////////////////////////////////////////////////////////////////////////
833 795
834void 796void
835maptile::emergency_save () 797cfperl_emergency_save ()
836{ 798{
837 CALL_BEGIN (0); 799 CALL_BEGIN (0);
838 CALL_CALL ("cf::map::emergency_save", G_VOID); 800 CALL_CALL ("cf::emergency_save", G_VOID);
839 CALL_END; 801 CALL_END;
840} 802}
841 803
842maptile * 804maptile *
843maptile::find_sync (const char *path, maptile *origin) 805maptile::find_sync (const char *path, maptile *origin)
844{ 806{
845 CALL_BEGIN (2); 807 CALL_BEGIN (2);
846 CALL_ARG (path); 808 CALL_ARG (path);
847 CALL_ARG (origin); 809 CALL_ARG (origin);
848 CALL_CALL ("cf::map::find_sync", G_SCALAR); 810 CALL_CALL ("cf::map::find_sync", G_SCALAR);
811
812 maptile *retval;
813
814 if (count)
815 sv_to (POPs, retval);
816 else
817 retval = 0;
818
819 CALL_END;
820
821 return retval;
822}
823
824maptile *
825maptile::find_async (const char *path, maptile *origin)
826{
827 CALL_BEGIN (2);
828 CALL_ARG (path);
829 CALL_ARG (origin);
830 CALL_CALL ("cf::map::find_async", G_SCALAR);
849 831
850 maptile *retval; 832 maptile *retval;
851 833
852 if (count) 834 if (count)
853 sv_to (POPs, retval); 835 sv_to (POPs, retval);
1258 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1240 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1259 const_iv (FLAG_IS_WATER) 1241 const_iv (FLAG_IS_WATER)
1260 const_iv (FLAG_CONTENT_ON_GEN) 1242 const_iv (FLAG_CONTENT_ON_GEN)
1261 const_iv (FLAG_IS_A_TEMPLATE) 1243 const_iv (FLAG_IS_A_TEMPLATE)
1262 const_iv (FLAG_IS_BUILDABLE) 1244 const_iv (FLAG_IS_BUILDABLE)
1245 const_iv (FLAG_DESTROY_ON_DEATH)
1246 const_iv (FLAG_NO_SAVE)
1263 1247
1264 const_iv (NDI_BLACK) 1248 const_iv (NDI_BLACK)
1265 const_iv (NDI_WHITE) 1249 const_iv (NDI_WHITE)
1266 const_iv (NDI_NAVY) 1250 const_iv (NDI_NAVY)
1267 const_iv (NDI_RED) 1251 const_iv (NDI_RED)
1616 } 1600 }
1617 OUTPUT: RETVAL 1601 OUTPUT: RETVAL
1618 1602
1619void abort () 1603void abort ()
1620 1604
1605void cleanup (const char *cause, bool make_core = false)
1606
1621void emergency_save () 1607void emergency_save ()
1622 1608
1623void _exit (int status = 0) 1609void _exit (int status = 0)
1624 1610
1625#if _POSIX_MEMLOCK 1611#if _POSIX_MEMLOCK
1715 PPCODE: 1701 PPCODE:
1716 EXTEND (SP, object::mortals.size ()); 1702 EXTEND (SP, object::mortals.size ());
1717 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) 1703 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1718 PUSHs (to_sv (*i)); 1704 PUSHs (to_sv (*i));
1719 1705
1720object *first () 1706int objects_size ()
1721 CODE: 1707 CODE:
1722 RETVAL = object::first; 1708 RETVAL = objects.size ();
1709 OUTPUT: RETVAL
1710
1711object *objects (U32 index)
1712 CODE:
1713 RETVAL = index < objects.size () ? objects [index] : 0;
1714 OUTPUT: RETVAL
1715
1716int actives_size ()
1717 CODE:
1718 RETVAL = actives.size ();
1719 OUTPUT: RETVAL
1720
1721object *actives (U32 index)
1722 CODE:
1723 RETVAL = index < actives.size () ? actives [index] : 0;
1723 OUTPUT: RETVAL 1724 OUTPUT: RETVAL
1724 1725
1725# missing properties 1726# missing properties
1726 1727
1727object *head (object *op) 1728object *head (object *op)
1728 PROTOTYPE: $ 1729 PROTOTYPE: $
1729 CODE: 1730 CODE:
1730 RETVAL = op->head ? op->head : op; 1731 RETVAL = op->head_ ();
1731 OUTPUT: RETVAL 1732 OUTPUT: RETVAL
1732 1733
1733int is_head (object *op) 1734int is_head (object *op)
1734 PROTOTYPE: $ 1735 PROTOTYPE: $
1735 CODE: 1736 CODE:
1736 RETVAL = !op->head; 1737 RETVAL = op->head_ () == op;
1737 OUTPUT: RETVAL 1738 OUTPUT: RETVAL
1738 1739
1739void 1740void
1740inv (object *obj) 1741inv (object *obj)
1741 PROTOTYPE: $ 1742 PROTOTYPE: $
2226 int random_seed,\ 2227 int random_seed,\
2227 val64 total_map_hp,\ 2228 val64 total_map_hp,\
2228 int map_layout_style,\ 2229 int map_layout_style,\
2229 int treasureoptions,\ 2230 int treasureoptions,\
2230 int symmetry_used,\ 2231 int symmetry_used,\
2231 region *region\ 2232 region *region,\
2233 char *custom\
2232) 2234)
2233 CODE: 2235 CODE:
2234{ 2236{
2235 random_map_params rmp; 2237 random_map_params rmp;
2236 2238
2268 rmp.total_map_hp = total_map_hp; 2270 rmp.total_map_hp = total_map_hp;
2269 rmp.map_layout_style = map_layout_style; 2271 rmp.map_layout_style = map_layout_style;
2270 rmp.treasureoptions = treasureoptions; 2272 rmp.treasureoptions = treasureoptions;
2271 rmp.symmetry_used = symmetry_used; 2273 rmp.symmetry_used = symmetry_used;
2272 rmp.region = region; 2274 rmp.region = region;
2275 rmp.custom = custom;
2273 2276
2274 RETVAL = generate_random_map (path, &rmp); 2277 RETVAL = generate_random_map (path, &rmp);
2275} 2278}
2276 OUTPUT: 2279 OUTPUT:
2277 RETVAL 2280 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines