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.138 by root, Thu Jan 11 01:10:01 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>
830} 817}
831 818
832///////////////////////////////////////////////////////////////////////////// 819/////////////////////////////////////////////////////////////////////////////
833 820
834void 821void
835maptile::emergency_save () 822cfperl_emergency_save ()
836{ 823{
837 CALL_BEGIN (0); 824 CALL_BEGIN (0);
838 CALL_CALL ("cf::map::emergency_save", G_VOID); 825 CALL_CALL ("cf::emergency_save", G_VOID);
839 CALL_END; 826 CALL_END;
840} 827}
841 828
842maptile * 829maptile *
843maptile::find_sync (const char *path, maptile *origin) 830maptile::find_sync (const char *path, maptile *origin)
844{ 831{
845 CALL_BEGIN (2); 832 CALL_BEGIN (2);
846 CALL_ARG (path); 833 CALL_ARG (path);
847 CALL_ARG (origin); 834 CALL_ARG (origin);
848 CALL_CALL ("cf::map::find_sync", G_SCALAR); 835 CALL_CALL ("cf::map::find_sync", G_SCALAR);
836
837 maptile *retval;
838
839 if (count)
840 sv_to (POPs, retval);
841 else
842 retval = 0;
843
844 CALL_END;
845
846 return retval;
847}
848
849maptile *
850maptile::find_async (const char *path, maptile *origin)
851{
852 CALL_BEGIN (2);
853 CALL_ARG (path);
854 CALL_ARG (origin);
855 CALL_CALL ("cf::map::find_async", G_SCALAR);
849 856
850 maptile *retval; 857 maptile *retval;
851 858
852 if (count) 859 if (count)
853 sv_to (POPs, retval); 860 sv_to (POPs, retval);
1258 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1265 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1259 const_iv (FLAG_IS_WATER) 1266 const_iv (FLAG_IS_WATER)
1260 const_iv (FLAG_CONTENT_ON_GEN) 1267 const_iv (FLAG_CONTENT_ON_GEN)
1261 const_iv (FLAG_IS_A_TEMPLATE) 1268 const_iv (FLAG_IS_A_TEMPLATE)
1262 const_iv (FLAG_IS_BUILDABLE) 1269 const_iv (FLAG_IS_BUILDABLE)
1270 const_iv (FLAG_DESTROY_ON_DEATH)
1271 const_iv (FLAG_NO_SAVE)
1263 1272
1264 const_iv (NDI_BLACK) 1273 const_iv (NDI_BLACK)
1265 const_iv (NDI_WHITE) 1274 const_iv (NDI_WHITE)
1266 const_iv (NDI_NAVY) 1275 const_iv (NDI_NAVY)
1267 const_iv (NDI_RED) 1276 const_iv (NDI_RED)
1616 } 1625 }
1617 OUTPUT: RETVAL 1626 OUTPUT: RETVAL
1618 1627
1619void abort () 1628void abort ()
1620 1629
1630void cleanup (const char *cause, bool make_core = false)
1631
1621void emergency_save () 1632void emergency_save ()
1622 1633
1623void _exit (int status = 0) 1634void _exit (int status = 0)
1624 1635
1625#if _POSIX_MEMLOCK 1636#if _POSIX_MEMLOCK
1715 PPCODE: 1726 PPCODE:
1716 EXTEND (SP, object::mortals.size ()); 1727 EXTEND (SP, object::mortals.size ());
1717 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) 1728 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1718 PUSHs (to_sv (*i)); 1729 PUSHs (to_sv (*i));
1719 1730
1720object *first () 1731int objects_size ()
1721 CODE: 1732 CODE:
1722 RETVAL = object::first; 1733 RETVAL = objects.size ();
1734 OUTPUT: RETVAL
1735
1736object *objects (U32 index)
1737 CODE:
1738 RETVAL = index < objects.size () ? objects [index] : 0;
1739 OUTPUT: RETVAL
1740
1741int actives_size ()
1742 CODE:
1743 RETVAL = actives.size ();
1744 OUTPUT: RETVAL
1745
1746object *actives (U32 index)
1747 CODE:
1748 RETVAL = index < actives.size () ? actives [index] : 0;
1723 OUTPUT: RETVAL 1749 OUTPUT: RETVAL
1724 1750
1725# missing properties 1751# missing properties
1726 1752
1727object *head (object *op) 1753object *head (object *op)
1728 PROTOTYPE: $ 1754 PROTOTYPE: $
1729 CODE: 1755 CODE:
1730 RETVAL = op->head ? op->head : op; 1756 RETVAL = op->head_ ();
1731 OUTPUT: RETVAL 1757 OUTPUT: RETVAL
1732 1758
1733int is_head (object *op) 1759int is_head (object *op)
1734 PROTOTYPE: $ 1760 PROTOTYPE: $
1735 CODE: 1761 CODE:
1736 RETVAL = !op->head; 1762 RETVAL = op->head_ () == op;
1737 OUTPUT: RETVAL 1763 OUTPUT: RETVAL
1738 1764
1739void 1765void
1740inv (object *obj) 1766inv (object *obj)
1741 PROTOTYPE: $ 1767 PROTOTYPE: $
2226 int random_seed,\ 2252 int random_seed,\
2227 val64 total_map_hp,\ 2253 val64 total_map_hp,\
2228 int map_layout_style,\ 2254 int map_layout_style,\
2229 int treasureoptions,\ 2255 int treasureoptions,\
2230 int symmetry_used,\ 2256 int symmetry_used,\
2231 region *region\ 2257 region *region,\
2258 char *custom\
2232) 2259)
2233 CODE: 2260 CODE:
2234{ 2261{
2235 random_map_params rmp; 2262 random_map_params rmp;
2236 2263
2268 rmp.total_map_hp = total_map_hp; 2295 rmp.total_map_hp = total_map_hp;
2269 rmp.map_layout_style = map_layout_style; 2296 rmp.map_layout_style = map_layout_style;
2270 rmp.treasureoptions = treasureoptions; 2297 rmp.treasureoptions = treasureoptions;
2271 rmp.symmetry_used = symmetry_used; 2298 rmp.symmetry_used = symmetry_used;
2272 rmp.region = region; 2299 rmp.region = region;
2300 rmp.custom = custom;
2273 2301
2274 RETVAL = generate_random_map (path, &rmp); 2302 RETVAL = generate_random_map (path, &rmp);
2275} 2303}
2276 OUTPUT: 2304 OUTPUT:
2277 RETVAL 2305 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines