… | |
… | |
112 | { |
112 | { |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
114 | } |
114 | } |
115 | |
115 | |
116 | void |
116 | void |
|
|
117 | attachable::sever_self () |
|
|
118 | { |
|
|
119 | if (HV *self = this->self) |
|
|
120 | { |
|
|
121 | // keep a refcount because sv_unmagic might call attachable_free, |
|
|
122 | // which might clear self, causing sv_unmagic to crash on a now |
|
|
123 | // invalid object. |
|
|
124 | SvREFCNT_inc (self); |
|
|
125 | hv_clear (self); |
|
|
126 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
127 | SvREFCNT_dec (self); |
|
|
128 | |
|
|
129 | // self *must* be null now because thats sv_unmagic's job. |
|
|
130 | assert (!this->self); |
|
|
131 | } |
|
|
132 | } |
|
|
133 | |
|
|
134 | void |
117 | attachable::optimise () |
135 | attachable::optimise () |
118 | { |
136 | { |
119 | if (self |
137 | if (self |
120 | && SvREFCNT (self) == 1 |
138 | && SvREFCNT (self) == 1 |
121 | && !HvTOTALKEYS (self)) |
139 | && !HvTOTALKEYS (self)) |
122 | { |
140 | sever_self (); |
123 | SV *self = (SV *)this->self; |
|
|
124 | |
|
|
125 | SvREFCNT_inc (self); |
|
|
126 | sv_unmagic (self, PERL_MAGIC_ext); |
|
|
127 | SvREFCNT_dec (self); |
|
|
128 | assert (!this->self); |
|
|
129 | } |
|
|
130 | } |
141 | } |
131 | |
142 | |
132 | // check wether the object really is dead |
143 | // check wether the object really is dead |
133 | void |
144 | void |
134 | attachable::do_check () |
145 | attachable::do_check () |
… | |
… | |
149 | SvREFCNT_dec (cb); |
160 | SvREFCNT_dec (cb); |
150 | cb = 0; |
161 | cb = 0; |
151 | } |
162 | } |
152 | |
163 | |
153 | if (self) |
164 | if (self) |
154 | { |
165 | sever_self (); |
155 | hv_clear (self); |
|
|
156 | |
|
|
157 | SV *self = (SV *)this->self; |
|
|
158 | SvREFCNT_inc (self); |
|
|
159 | sv_unmagic (self, PERL_MAGIC_ext); |
|
|
160 | SvREFCNT_dec (self); |
|
|
161 | // self is now 0 |
|
|
162 | assert (!this->self);//D//TODO remove soon |
|
|
163 | } |
|
|
164 | |
166 | |
165 | mortals.push_back (this); |
167 | mortals.push_back (this); |
166 | } |
168 | } |
167 | |
169 | |
168 | void |
170 | void |
… | |
… | |
1647 | |
1649 | |
1648 | void cleanup (const char *cause, bool make_core = false) |
1650 | void cleanup (const char *cause, bool make_core = false) |
1649 | |
1651 | |
1650 | void emergency_save () |
1652 | void emergency_save () |
1651 | |
1653 | |
|
|
1654 | void _exit (int status = EXIT_SUCCESS) |
|
|
1655 | |
1652 | UV sv_2watcher (SV *w) |
1656 | UV sv_2watcher (SV *w) |
1653 | CODE: |
1657 | CODE: |
1654 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1658 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1655 | OUTPUT: |
1659 | OUTPUT: |
1656 | RETVAL |
1660 | RETVAL |
1657 | |
|
|
1658 | void _exit (int status = 0) |
|
|
1659 | |
1661 | |
1660 | #if _POSIX_MEMLOCK |
1662 | #if _POSIX_MEMLOCK |
1661 | |
1663 | |
1662 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1664 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1663 | |
1665 | |
… | |
… | |
2139 | EXTEND (SP, THIS->players); |
2141 | EXTEND (SP, THIS->players); |
2140 | for_all_players (pl) |
2142 | for_all_players (pl) |
2141 | if (pl->ob && pl->ob->map == THIS) |
2143 | if (pl->ob && pl->ob->map == THIS) |
2142 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2144 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2143 | } |
2145 | } |
|
|
2146 | |
|
|
2147 | void |
|
|
2148 | maptile::set_regiondata (SV *data, SV *plt) |
|
|
2149 | CODE: |
|
|
2150 | { |
|
|
2151 | if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV) |
|
|
2152 | croak ("maptile::set_regiondata needs arrayref as plt arg"); |
|
|
2153 | |
|
|
2154 | AV *av = (AV *)SvRV (plt); |
|
|
2155 | |
|
|
2156 | region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *)); |
|
|
2157 | |
|
|
2158 | for (int i = av_len (av) + 1; i--; ) |
|
|
2159 | regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1))); |
|
|
2160 | |
|
|
2161 | THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data)); |
|
|
2162 | THIS->regionmap = regionmap; |
|
|
2163 | } |
2144 | |
2164 | |
2145 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2165 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2146 | |
2166 | |
2147 | int out_of_map (maptile *map, int x, int y) |
2167 | int out_of_map (maptile *map, int x, int y) |
2148 | |
2168 | |
… | |
… | |
2361 | OUTPUT: RETVAL |
2381 | OUTPUT: RETVAL |
2362 | |
2382 | |
2363 | region *find (char *name) |
2383 | region *find (char *name) |
2364 | PROTOTYPE: $ |
2384 | PROTOTYPE: $ |
2365 | CODE: |
2385 | CODE: |
2366 | RETVAL = get_region_by_name (name); |
2386 | RETVAL = region::find (name); |
2367 | OUTPUT: RETVAL |
2387 | OUTPUT: RETVAL |
2368 | |
2388 | |
2369 | INCLUDE: $PERL genacc region ../include/map.h | |
2389 | INCLUDE: $PERL genacc region ../include/map.h | |
2370 | |
2390 | |
2371 | MODULE = cf PACKAGE = cf::living |
2391 | MODULE = cf PACKAGE = cf::living |