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.137 by root, Thu Jan 11 00:41:08 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);
1616 } 1623 }
1617 OUTPUT: RETVAL 1624 OUTPUT: RETVAL
1618 1625
1619void abort () 1626void abort ()
1620 1627
1628void cleanup (const char *cause, bool make_core = false)
1629
1621void emergency_save () 1630void emergency_save ()
1622 1631
1623void _exit (int status = 0) 1632void _exit (int status = 0)
1624 1633
1625#if _POSIX_MEMLOCK 1634#if _POSIX_MEMLOCK
1715 PPCODE: 1724 PPCODE:
1716 EXTEND (SP, object::mortals.size ()); 1725 EXTEND (SP, object::mortals.size ());
1717 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) 1726 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1718 PUSHs (to_sv (*i)); 1727 PUSHs (to_sv (*i));
1719 1728
1720object *first () 1729int objects_size ()
1721 CODE: 1730 CODE:
1722 RETVAL = object::first; 1731 RETVAL = objects.size ();
1732 OUTPUT: RETVAL
1733
1734object *objects (U32 index)
1735 CODE:
1736 RETVAL = index < objects.size () ? objects [index] : 0;
1737 OUTPUT: RETVAL
1738
1739int actives_size ()
1740 CODE:
1741 RETVAL = actives.size ();
1742 OUTPUT: RETVAL
1743
1744object *actives (U32 index)
1745 CODE:
1746 RETVAL = index < actives.size () ? actives [index] : 0;
1723 OUTPUT: RETVAL 1747 OUTPUT: RETVAL
1724 1748
1725# missing properties 1749# missing properties
1726 1750
1727object *head (object *op) 1751object *head (object *op)
1728 PROTOTYPE: $ 1752 PROTOTYPE: $
1729 CODE: 1753 CODE:
1730 RETVAL = op->head ? op->head : op; 1754 RETVAL = op->head_ ();
1731 OUTPUT: RETVAL 1755 OUTPUT: RETVAL
1732 1756
1733int is_head (object *op) 1757int is_head (object *op)
1734 PROTOTYPE: $ 1758 PROTOTYPE: $
1735 CODE: 1759 CODE:
1736 RETVAL = !op->head; 1760 RETVAL = op->head_ () == op;
1737 OUTPUT: RETVAL 1761 OUTPUT: RETVAL
1738 1762
1739void 1763void
1740inv (object *obj) 1764inv (object *obj)
1741 PROTOTYPE: $ 1765 PROTOTYPE: $
2226 int random_seed,\ 2250 int random_seed,\
2227 val64 total_map_hp,\ 2251 val64 total_map_hp,\
2228 int map_layout_style,\ 2252 int map_layout_style,\
2229 int treasureoptions,\ 2253 int treasureoptions,\
2230 int symmetry_used,\ 2254 int symmetry_used,\
2231 region *region\ 2255 region *region,\
2256 char *custom\
2232) 2257)
2233 CODE: 2258 CODE:
2234{ 2259{
2235 random_map_params rmp; 2260 random_map_params rmp;
2236 2261
2268 rmp.total_map_hp = total_map_hp; 2293 rmp.total_map_hp = total_map_hp;
2269 rmp.map_layout_style = map_layout_style; 2294 rmp.map_layout_style = map_layout_style;
2270 rmp.treasureoptions = treasureoptions; 2295 rmp.treasureoptions = treasureoptions;
2271 rmp.symmetry_used = symmetry_used; 2296 rmp.symmetry_used = symmetry_used;
2272 rmp.region = region; 2297 rmp.region = region;
2298 rmp.custom = custom;
2273 2299
2274 RETVAL = generate_random_map (path, &rmp); 2300 RETVAL = generate_random_map (path, &rmp);
2275} 2301}
2276 OUTPUT: 2302 OUTPUT:
2277 RETVAL 2303 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines