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.60 by root, Fri Sep 15 20:58:58 2006 UTC vs.
Revision 1.61 by root, Sat Sep 16 22:24:13 2006 UTC

40 40
41#include "perlxsi.c" 41#include "perlxsi.c"
42 42
43extern sint64 *levels; // the experience table 43extern sint64 *levels; // the experience table
44 44
45typedef object object_ornull; 45typedef object object_ornull;
46typedef mapstruct mapstruct_ornull; 46typedef maptile maptile_ornull;
47 47
48typedef double val64; 48typedef double val64;
49#define newSVval64 newSVnv 49#define newSVval64 newSVnv
50#define SvVAL64 SvNV 50#define SvVAL64 SvNV
51 51
55 55
56static HV *obj_cache; 56static HV *obj_cache;
57static PerlInterpreter *perl; 57static PerlInterpreter *perl;
58 58
59static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 59static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map;
60
61#define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value))))
62#define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype))
63#define PUSH_OB PUSHcfapi_va(POBJECT, object *)
64#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
65#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
66#define PUSH_PV PUSHcfapi_va(STRING, const char *)
67#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
68 60
69////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 61//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
70 62
71static SV * 63static SV *
72newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) 64newSVptr (void *ptr, const char *klass, HV *hv = newHV ())
177inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 169inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
178inline SV *to_sv (float v) { return newSVnv (v); } 170inline SV *to_sv (float v) { return newSVnv (v); }
179inline SV *to_sv (double v) { return newSVnv (v); } 171inline SV *to_sv (double v) { return newSVnv (v); }
180inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } 172inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); }
181inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); } 173inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); }
182inline SV *to_sv (mapstruct * v) { return newSVattachable (v, "cf::map::wrap"); } 174inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); }
183inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } 175inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); }
184inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } 176inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); }
185inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); } 177inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); }
186inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } 178inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); }
187 179
208inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 200inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
209inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 201inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
210inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); } 202inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); }
211inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); } 203inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); }
212inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); } 204inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); }
213inline void sv_to (SV *sv, mapstruct * &v) { v = (mapstruct *)SvPTR_ornull (sv, "cf::map"); } 205inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)SvPTR_ornull (sv, "cf::map"); }
214inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 206inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
215inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } 207inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
216inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 208inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
217 209
218inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO 210inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO
262 sv = to_sv (va_arg (ap, object *)); 254 sv = to_sv (va_arg (ap, object *));
263 break; 255 break;
264 256
265 case DT_MAP: 257 case DT_MAP:
266 // va_arg (object *) when void * is passed is an XSI extension 258 // va_arg (object *) when void * is passed is an XSI extension
267 sv = to_sv (va_arg (ap, mapstruct *)); 259 sv = to_sv (va_arg (ap, maptile *));
268 break; 260 break;
269 261
270 case DT_PLAYER: 262 case DT_PLAYER:
271 sv = to_sv (va_arg (ap, player *)); 263 sv = to_sv (va_arg (ap, player *));
272 break; 264 break;
349 { 341 {
350 if (cb) 342 if (cb)
351 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) 343 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1)))
352 INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); 344 INVOKE_OBJECT (DESTROY, static_cast<object *>(this));
353 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) 345 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1)))
354 INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); 346 INVOKE_MAP (DESTROY, static_cast<maptile *>(this));
355 347
356 // disconnect Perl from C, to avoid crashes 348 // disconnect Perl from C, to avoid crashes
357 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); 349 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
358 350
359 // clear the perl hash, might or might not be a good idea 351 // clear the perl hash, might or might not be a good idea
939 931
940 AV *callbacks = 0; 932 AV *callbacks = 0;
941 933
942 object *op; 934 object *op;
943 player *pl; 935 player *pl;
944 mapstruct *map; 936 maptile *map;
945 937
946 // callback call ordering is: 938 // callback call ordering is:
947 // 1. per-object callback (NYI) 939 // 1. per-object callback (NYI)
948 // 2. per-class object 940 // 2. per-class object
949 // 2a. per-type callback 941 // 2a. per-type callback
999 break; 991 break;
1000 992
1001 case KLASS_MAP: 993 case KLASS_MAP:
1002 dt = (data_type) va_arg (ap, int); 994 dt = (data_type) va_arg (ap, int);
1003 assert (("first argument must be of type object", dt == DT_MAP)); 995 assert (("first argument must be of type object", dt == DT_MAP));
1004 map = va_arg (ap, mapstruct *); 996 map = va_arg (ap, maptile *);
1005 997
1006 if (map->cb) 998 if (map->cb)
1007 gather_callbacks (callbacks, map->cb, event); 999 gather_callbacks (callbacks, map->cb, event);
1008 1000
1009 gather_callbacks (callbacks, cb_map, event); 1001 gather_callbacks (callbacks, cb_map, event);
1626{ 1618{
1627 // reattach to all attachable objects in the game. 1619 // reattach to all attachable objects in the game.
1628 for (player *pl = first_player; pl; pl = pl->next) 1620 for (player *pl = first_player; pl; pl = pl->next)
1629 reattach (pl); 1621 reattach (pl);
1630 1622
1631 for (mapstruct *map = first_map; map; map = map->next) 1623 for (maptile *map = first_map; map; map = map->next)
1632 reattach (map); 1624 reattach (map);
1633 1625
1634 for (object *op = object::first; op; op = op->next) 1626 for (object *op = object::first; op; op = op->next)
1635 reattach (op); 1627 reattach (op);
1636} 1628}
1843 1835
1844object *cf_object_present_archname_inside (object *op, char *whatstr) 1836object *cf_object_present_archname_inside (object *op, char *whatstr)
1845 1837
1846int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1838int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1847 1839
1848int cf_object_change_map (object *op, int x, int y, mapstruct *map) 1840int cf_object_change_map (object *op, int x, int y, maptile *map)
1849 1841
1850object *cf_object_clone (object *op, int clonetype = 0) 1842object *cf_object_clone (object *op, int clonetype = 0)
1851 1843
1852int cf_object_pay_item (object *op, object *buyer) 1844int cf_object_pay_item (object *op, object *buyer)
1853 1845
1885 1877
1886object *cf_object_insert_object (object *op, object *container) 1878object *cf_object_insert_object (object *op, object *container)
1887 1879
1888object *cf_object_insert_in_ob (object *ob, object *where) 1880object *cf_object_insert_in_ob (object *ob, object *where)
1889 1881
1890int cf_object_teleport (object *op, mapstruct *map, int x, int y) 1882int cf_object_teleport (object *op, maptile *map, int x, int y)
1891 1883
1892void cf_object_update (object *op, int flags) 1884void cf_object_update (object *op, int flags)
1893 1885
1894void cf_object_pickup (object *op, object *what) 1886void cf_object_pickup (object *op, object *what)
1895 1887
1905 1897
1906void push_button (object *op); 1898void push_button (object *op);
1907 1899
1908void use_trigger (object *op); 1900void use_trigger (object *op);
1909 1901
1910void add_button_link (object *button, mapstruct *map, int connected); 1902void add_button_link (object *button, maptile *map, int connected);
1911 1903
1912void remove_button_link (object *op); 1904void remove_button_link (object *op);
1913 1905
1914void 1906void
1915cf_object_set_resistance (object *op, int rtype, int val) 1907cf_object_set_resistance (object *op, int rtype, int val)
1933 CODE: 1925 CODE:
1934 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1926 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1935 OUTPUT: 1927 OUTPUT:
1936 RETVAL 1928 RETVAL
1937 1929
1938object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) 1930object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1939 PROTOTYPE: $$$$$$ 1931 PROTOTYPE: $$$$$$
1940 CODE: 1932 CODE:
1941{ 1933{
1942 int unused_type; 1934 int unused_type;
1943 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1935 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
2158 OUTPUT: RETVAL 2150 OUTPUT: RETVAL
2159 2151
2160 2152
2161MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2153MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2162 2154
2163mapstruct *first () 2155maptile *first ()
2164 PROTOTYPE: 2156 PROTOTYPE:
2165 CODE: 2157 CODE:
2166 RETVAL = first_map; 2158 RETVAL = first_map;
2167 OUTPUT: RETVAL 2159 OUTPUT: RETVAL
2168 2160
2169int invoke (mapstruct *map, int event, ...) 2161int invoke (maptile *map, int event, ...)
2170 CODE: 2162 CODE:
2171 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); 2163 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP");
2172 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2164 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2173 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 2165 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2174 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); 2166 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av));
2175 OUTPUT: RETVAL 2167 OUTPUT: RETVAL
2176 2168
2177SV *registry (mapstruct *map) 2169SV *registry (maptile *map)
2178 CODE: 2170 CODE:
2179 RETVAL = registry_of (map); 2171 RETVAL = registry_of (map);
2180 OUTPUT: 2172 OUTPUT:
2181 RETVAL 2173 RETVAL
2182 2174
2183INCLUDE: $PERL genacc mapstruct ../include/map.h | 2175INCLUDE: $PERL genacc maptile ../include/map.h |
2184 2176
2185mapstruct *new (int width, int height) 2177maptile *new (int width, int height)
2186 PROTOTYPE: 2178 PROTOTYPE:
2187 CODE: 2179 CODE:
2188{ 2180{
2189 RETVAL = get_empty_map (width, height); 2181 RETVAL = get_empty_map (width, height);
2190} 2182}
2191 OUTPUT: 2183 OUTPUT:
2192 RETVAL 2184 RETVAL
2193 2185
2194void delete_map (mapstruct *map) 2186void delete_map (maptile *map)
2195 2187
2196void clean_tmp_map (mapstruct *map) 2188void clean_tmp_map (maptile *map)
2197 2189
2198void play_sound_map (mapstruct *map, int x, int y, int sound_num) 2190void play_sound_map (maptile *map, int x, int y, int sound_num)
2199 2191
2200mapstruct *tile_map (mapstruct *map, unsigned int dir) 2192maptile *tile_map (maptile *map, unsigned int dir)
2201 CODE: 2193 CODE:
2202 RETVAL = dir < 4 ? map->tile_map [dir] : 0; 2194 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
2203 OUTPUT: 2195 OUTPUT:
2204 RETVAL 2196 RETVAL
2205 2197
2206char *tile_path (mapstruct *map, unsigned int dir) 2198char *tile_path (maptile *map, unsigned int dir)
2207 CODE: 2199 CODE:
2208 if (dir >= 4) 2200 if (dir >= 4)
2209 XSRETURN_UNDEF; 2201 XSRETURN_UNDEF;
2210 RETVAL = map->tile_path [dir]; 2202 RETVAL = map->tile_path [dir];
2211 OUTPUT: 2203 OUTPUT:
2212 RETVAL 2204 RETVAL
2213 2205
2214mapstruct *ready_map_name (char *name, int flags = 0) 2206maptile *ready_map_name (char *name, int flags = 0)
2215 PROTOTYPE: $;$ 2207 PROTOTYPE: $;$
2216 ALIAS: 2208 ALIAS:
2217 find = 0 2209 find = 0
2218 get_map = 1 2210 get_map = 1
2219 2211
2220mapstruct *has_been_loaded (char *name) 2212maptile *has_been_loaded (char *name)
2221 PROTOTYPE: $ 2213 PROTOTYPE: $
2222 2214
2223int in_memory (mapstruct *map) 2215int in_memory (maptile *map)
2224 CODE: 2216 CODE:
2225 RETVAL = map->in_memory; 2217 RETVAL = map->in_memory;
2226 OUTPUT: 2218 OUTPUT:
2227 RETVAL 2219 RETVAL
2228 2220
2229void 2221void
2230trigger (mapstruct *map, long connection, bool state = true) 2222trigger (maptile *map, long connection, bool state = true)
2231 CODE: 2223 CODE:
2232 activate_connection (map, connection, state); 2224 activate_connection (map, connection, state);
2233 2225
2234void 2226void
2235get_connection (mapstruct *map, long connection) 2227get_connection (maptile *map, long connection)
2236 PPCODE: 2228 PPCODE:
2237 oblinkpt *obp = get_connection_links (map, connection); 2229 oblinkpt *obp = get_connection_links (map, connection);
2238 if (obp) 2230 if (obp)
2239 for (objectlink *ol = obp->link; ol; ol = ol->next) 2231 for (objectlink *ol = obp->link; ol; ol = ol->next)
2240 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); 2232 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob)));
2241 2233
2242object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) 2234object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags)
2243 2235
2244object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 2236object *cf_map_insert_object (maptile *where, object* op, int x, int y)
2245 2237
2246object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 2238object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2247 C_ARGS: str, map, nx, ny 2239 C_ARGS: str, map, nx, ny
2248 2240
2249void 2241void
2250cf_map_normalise (mapstruct *map, int x, int y) 2242cf_map_normalise (maptile *map, int x, int y)
2251 PPCODE: 2243 PPCODE:
2252{ 2244{
2253 mapstruct *nmap = 0; 2245 maptile *nmap = 0;
2254 I16 nx = 0, ny = 0; 2246 I16 nx = 0, ny = 0;
2255 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2247 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2256 2248
2257 EXTEND (SP, 4); 2249 EXTEND (SP, 4);
2258 PUSHs (sv_2mortal (newSViv (flags))); 2250 PUSHs (sv_2mortal (newSViv (flags)));
2264 PUSHs (sv_2mortal (newSViv (ny))); 2256 PUSHs (sv_2mortal (newSViv (ny)));
2265 } 2257 }
2266} 2258}
2267 2259
2268void 2260void
2269at (mapstruct *map, unsigned int x, unsigned int y) 2261at (maptile *map, unsigned int x, unsigned int y)
2270 PROTOTYPE: $$$ 2262 PROTOTYPE: $$$
2271 PPCODE: 2263 PPCODE:
2272{ 2264{
2273 object *o; 2265 object *o;
2274 mapstruct *nmap = 0; 2266 maptile *nmap = 0;
2275 I16 nx, ny; 2267 I16 nx, ny;
2276 2268
2277 get_map_flags (map, &nmap, x, y, &nx, &ny); 2269 get_map_flags (map, &nmap, x, y, &nx, &ny);
2278 2270
2279 if (nmap) 2271 if (nmap)
2280 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) 2272 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
2281 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 2273 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
2282} 2274}
2283 2275
2284SV * 2276SV *
2285bot_at (mapstruct *obj, unsigned int x, unsigned int y) 2277bot_at (maptile *obj, unsigned int x, unsigned int y)
2286 PROTOTYPE: $$$ 2278 PROTOTYPE: $$$
2287 ALIAS: 2279 ALIAS:
2288 top_at = 1 2280 top_at = 1
2289 flags_at = 2 2281 flags_at = 2
2290 light_at = 3 2282 light_at = 3

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines