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.59 by root, Thu Sep 14 19:12:00 2006 UTC vs.
Revision 1.70 by elmex, Mon Dec 4 15:15:34 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
52static f_plug_api gethook = cfapi_get_hooks; 52static f_plug_api gethook = cfapi_get_hooks;
53static f_plug_api object_set_property = cfapi_object_set_property; 53static f_plug_api object_set_property = cfapi_object_set_property;
54static f_plug_api object_insert = cfapi_object_insert; 54static f_plug_api object_insert = cfapi_object_insert;
55 55
56static HV *obj_cache;
57static PerlInterpreter *perl; 56static PerlInterpreter *perl;
58 57
59static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 58static 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 59
69////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 60//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
70 61
71static SV * 62static SV *
72newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) 63newSVptr (void *ptr, const char *klass, HV *hv = newHV ())
89 80
90 if (!obj->self) 81 if (!obj->self)
91 obj->self = newSVptr (obj, klass); 82 obj->self = newSVptr (obj, klass);
92 83
93 return newSVsv (obj->self); 84 return newSVsv (obj->self);
94}
95
96static void
97SVptr_cache_set (void *ptr, SV *sv)
98{
99 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0);
100}
101
102static SV *
103SVptr_cache_get (void *ptr)
104{
105 SV **he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0);
106
107 return he ? *he : 0;
108}
109
110static SV *
111newSVptr_cached (void *ptr, const char *klass)
112{
113 SV *sv;
114
115 if (!ptr)
116 return &PL_sv_undef;
117
118 sv = SVptr_cache_get (ptr);
119
120 if (!sv)
121 {
122 HV *hv = newHV ();
123 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
124 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
125
126 SVptr_cache_set (ptr, sv);
127 }
128
129 return newSVsv (sv);
130} 85}
131 86
132static void 87static void
133clearSVptr (SV *sv) 88clearSVptr (SV *sv)
134{ 89{
177inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 132inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
178inline SV *to_sv (float v) { return newSVnv (v); } 133inline SV *to_sv (float v) { return newSVnv (v); }
179inline SV *to_sv (double v) { return newSVnv (v); } 134inline SV *to_sv (double v) { return newSVnv (v); }
180inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } 135inline 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"); } 136inline 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"); } 137inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); }
183inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } 138inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); }
184inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } 139inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); }
185inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); } 140inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); }
186inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } 141inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); }
187 142
189inline SV *to_sv (living & v) { return to_sv (&v); } 144inline SV *to_sv (living & v) { return to_sv (&v); }
190 145
191//TODO: 146//TODO:
192inline SV *to_sv (New_Face * v) { return to_sv (v->name); } 147inline SV *to_sv (New_Face * v) { return to_sv (v->name); }
193inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 148inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
149
150inline SV *to_sv (UUID v)
151{
152 char buf[128];
153 snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq);
154 return newSVpv (buf, 0);
155}
194 156
195inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 157inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
196inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed 158inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed
197inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 159inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
198inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 160inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
208inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 170inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
209inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 171inline 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"); } 172inline 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"); } 173inline 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"); } 174inline 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"); } 175inline 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"); } 176inline 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"); } 177inline 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"); } 178inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
217 179
218inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO 180inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO
221template<class T> 183template<class T>
222inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 184inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
223 185
224template<int N> 186template<int N>
225inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 187inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
188
189inline void sv_to (SV *sv, UUID &v)
190{
191 unsigned int version;
192 unsigned long long seq;
193
194 if (2 != sscanf (SvPV_nolen (sv), "<%d.%llx>", &version, &seq) || 1 != version)
195 croak ("unparsable uuid: %s", SvPV_nolen (sv));
196
197 v.seq = seq;
198}
226 199
227static SV * 200static SV *
228newSVdt_va (va_list &ap, data_type type) 201newSVdt_va (va_list &ap, data_type type)
229{ 202{
230 SV *sv; 203 SV *sv;
262 sv = to_sv (va_arg (ap, object *)); 235 sv = to_sv (va_arg (ap, object *));
263 break; 236 break;
264 237
265 case DT_MAP: 238 case DT_MAP:
266 // va_arg (object *) when void * is passed is an XSI extension 239 // va_arg (object *) when void * is passed is an XSI extension
267 sv = to_sv (va_arg (ap, mapstruct *)); 240 sv = to_sv (va_arg (ap, maptile *));
268 break; 241 break;
269 242
270 case DT_PLAYER: 243 case DT_PLAYER:
271 sv = to_sv (va_arg (ap, player *)); 244 sv = to_sv (va_arg (ap, player *));
272 break; 245 break;
349 { 322 {
350 if (cb) 323 if (cb)
351 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) 324 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1)))
352 INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); 325 INVOKE_OBJECT (DESTROY, static_cast<object *>(this));
353 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) 326 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1)))
354 INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); 327 INVOKE_MAP (DESTROY, static_cast<maptile *>(this));
355 328
356 // disconnect Perl from C, to avoid crashes 329 // disconnect Perl from C, to avoid crashes
357 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); 330 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
358 331
359 // clear the perl hash, might or might not be a good idea 332 // clear the perl hash, might or might not be a good idea
487 call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); 460 call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL);
488 FREETMPS; 461 FREETMPS;
489 LEAVE; 462 LEAVE;
490} 463}
491 464
465char *object_freezer::as_string ()
466{
467 dSP;
468 ENTER;
469 SAVETMPS;
470 PUSHMARK (SP);
471 EXTEND (SP, 3);
472 PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ()))));
473 PUSHs (sv_2mortal (newRV_inc ((SV *)av)));
474 PUTBACK;
475
476 char *res = call_pv ("cf::object_freezer_as_string", G_SCALAR | G_EVAL) > 0
477 ? strdup (SvPVbyte_nolen (POPs))
478 : strdup ("[fatal error]");
479
480 FREETMPS;
481 LEAVE;
482
483 return res;
484}
485
492int fprintf (object_freezer &freezer, const char *format, ...) 486int fprintf (object_freezer &freezer, const char *format, ...)
493{ 487{
494 va_list ap; 488 va_list ap;
495 489
496 va_start (ap, format); 490 va_start (ap, format);
505 499
506int fputs (const char *s, object_freezer &freezer) 500int fputs (const char *s, object_freezer &freezer)
507{ 501{
508 freezer.add (s); 502 freezer.add (s);
509} 503}
504
505static const char thawer_eof[] = "\n\n\n\0\0\0";
510 506
511object_thawer::object_thawer (const char *filename) 507object_thawer::object_thawer (const char *filename)
512{ 508{
513 static const char eof[] = "\n\n\n\0\0\0"; 509 static const char eof[] = "\n\n\n\0\0\0";
514 510
552 548
553 PUTBACK; 549 PUTBACK;
554 FREETMPS; 550 FREETMPS;
555 LEAVE; 551 LEAVE;
556 } 552 }
553}
554
555object_thawer::object_thawer (const char *data, AV *perlav)
556{
557 av = perlav;
558 text = newSVpv (data, 0);
559 sv_catpv (text, thawer_eof);
560 line = SvPVbyte_nolen (text);
557} 561}
558 562
559void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) 563void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid)
560{ 564{
561 if (!av || oid < 0) // this is actually an error of sorts 565 if (!av || oid < 0) // this is actually an error of sorts
877 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 881 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
878 { 882 {
879 printf ("unable to initialize perl-interpreter, aborting.\n"); 883 printf ("unable to initialize perl-interpreter, aborting.\n");
880 exit (EXIT_FAILURE); 884 exit (EXIT_FAILURE);
881 } 885 }
882
883 obj_cache = newHV ();
884} 886}
885 887
886void cfperl_main () 888void cfperl_main ()
887{ 889{
888 dSP; 890 dSP;
939 941
940 AV *callbacks = 0; 942 AV *callbacks = 0;
941 943
942 object *op; 944 object *op;
943 player *pl; 945 player *pl;
944 mapstruct *map; 946 maptile *map;
945 947
946 // callback call ordering is: 948 // callback call ordering is:
947 // 1. per-object callback (NYI) 949 // 1. per-object callback (NYI)
948 // 2. per-class object 950 // 2. per-class object
949 // 2a. per-type callback 951 // 2a. per-type callback
999 break; 1001 break;
1000 1002
1001 case KLASS_MAP: 1003 case KLASS_MAP:
1002 dt = (data_type) va_arg (ap, int); 1004 dt = (data_type) va_arg (ap, int);
1003 assert (("first argument must be of type object", dt == DT_MAP)); 1005 assert (("first argument must be of type object", dt == DT_MAP));
1004 map = va_arg (ap, mapstruct *); 1006 map = va_arg (ap, maptile *);
1005 1007
1006 if (map->cb) 1008 if (map->cb)
1007 gather_callbacks (callbacks, map->cb, event); 1009 gather_callbacks (callbacks, map->cb, event);
1008 1010
1009 gather_callbacks (callbacks, cb_map, event); 1011 gather_callbacks (callbacks, cb_map, event);
1089MODULE = cf PACKAGE = cf PREFIX = cf_ 1091MODULE = cf PACKAGE = cf PREFIX = cf_
1090 1092
1091BOOT: 1093BOOT:
1092{ 1094{
1093 HV *stash = gv_stashpv ("cf", 1); 1095 HV *stash = gv_stashpv ("cf", 1);
1096
1097 newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1094 1098
1095 static const struct { 1099 static const struct {
1096 const char *name; 1100 const char *name;
1097 IV iv; 1101 IV iv;
1098 } *civ, const_iv[] = { 1102 } *civ, const_iv[] = {
1626{ 1630{
1627 // reattach to all attachable objects in the game. 1631 // reattach to all attachable objects in the game.
1628 for (player *pl = first_player; pl; pl = pl->next) 1632 for (player *pl = first_player; pl; pl = pl->next)
1629 reattach (pl); 1633 reattach (pl);
1630 1634
1631 for (mapstruct *map = first_map; map; map = map->next) 1635 for (maptile *map = first_map; map; map = map->next)
1632 reattach (map); 1636 reattach (map);
1633 1637
1634 for (object *op = object::first; op; op = op->next) 1638 for (object *op = object::first; op; op = op->next)
1635 reattach (op); 1639 reattach (op);
1636} 1640}
1752 OUTPUT: 1756 OUTPUT:
1753 RETVAL 1757 RETVAL
1754 1758
1755MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1759MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1756 1760
1761INCLUDE: $PERL genacc object ../include/object.h |
1762
1757int invoke (object *op, int event, ...) 1763int invoke (object *op, int event, ...)
1758 CODE: 1764 CODE:
1759 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); 1765 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT");
1760 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 1766 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1761 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 1767 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1776 1782
1777object *first () 1783object *first ()
1778 CODE: 1784 CODE:
1779 RETVAL = object::first; 1785 RETVAL = object::first;
1780 OUTPUT: RETVAL 1786 OUTPUT: RETVAL
1781
1782INCLUDE: $PERL genacc object ../include/object.h |
1783 1787
1784# missing properties 1788# missing properties
1785 1789
1786int flag (object *op, int flag, int value = 1) 1790int flag (object *op, int flag, int value = 1)
1787 PROTOTYPE: $$;$ 1791 PROTOTYPE: $$;$
1843 1847
1844object *cf_object_present_archname_inside (object *op, char *whatstr) 1848object *cf_object_present_archname_inside (object *op, char *whatstr)
1845 1849
1846int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1850int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1847 1851
1848int cf_object_change_map (object *op, int x, int y, mapstruct *map) 1852int cf_object_change_map (object *op, int x, int y, maptile *map)
1849 1853
1850object *cf_object_clone (object *op, int clonetype = 0) 1854object *cf_object_clone (object *op, int clonetype = 0)
1851 1855
1852int cf_object_pay_item (object *op, object *buyer) 1856int cf_object_pay_item (object *op, object *buyer)
1853 1857
1885 1889
1886object *cf_object_insert_object (object *op, object *container) 1890object *cf_object_insert_object (object *op, object *container)
1887 1891
1888object *cf_object_insert_in_ob (object *ob, object *where) 1892object *cf_object_insert_in_ob (object *ob, object *where)
1889 1893
1890int cf_object_teleport (object *op, mapstruct *map, int x, int y) 1894int cf_object_teleport (object *op, maptile *map, int x, int y)
1891 1895
1892void cf_object_update (object *op, int flags) 1896void cf_object_update (object *op, int flags)
1893 1897
1894void cf_object_pickup (object *op, object *what) 1898void cf_object_pickup (object *op, object *what)
1895 1899
1905 1909
1906void push_button (object *op); 1910void push_button (object *op);
1907 1911
1908void use_trigger (object *op); 1912void use_trigger (object *op);
1909 1913
1910void add_button_link (object *button, mapstruct *map, int connected); 1914void add_button_link (object *button, maptile *map, int connected);
1911 1915
1912void remove_button_link (object *op); 1916void remove_button_link (object *op);
1913 1917
1914void 1918void
1915cf_object_set_resistance (object *op, int rtype, int val) 1919cf_object_set_resistance (object *op, int rtype, int val)
1933 CODE: 1937 CODE:
1934 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1938 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1935 OUTPUT: 1939 OUTPUT:
1936 RETVAL 1940 RETVAL
1937 1941
1938object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) 1942object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1939 PROTOTYPE: $$$$$$ 1943 PROTOTYPE: $$$$$$
1940 CODE: 1944 CODE:
1941{ 1945{
1942 int unused_type; 1946 int unused_type;
1943 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1947 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
2016void kill_player (object *op) 2020void kill_player (object *op)
2017 2021
2018void esrv_update_item (object *op, int what, object *item) 2022void esrv_update_item (object *op, int what, object *item)
2019 C_ARGS: what, op, item 2023 C_ARGS: what, op, item
2020 2024
2025void clear_los (object *op)
2026
2027int command_reset (object *op, char *params)
2028
2029int command_teleport (object *op, char *params)
2030
2031int command_summon (object *op, char *params)
2032
2033int command_arrest (object *op, char *params)
2034
2035int command_kick (object *op, char *params)
2036
2037int command_banish (object *op, char *params)
2038
2039
2021MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2040MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
2041
2042INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h |
2043
2044char *
2045client (player *pl)
2046 CODE:
2047 RETVAL = pl->socket.client;
2048 OUTPUT:
2049 RETVAL
2050
2051char *
2052host (player *pl)
2053 CODE:
2054 RETVAL = pl->socket.host;
2055 OUTPUT:
2056 RETVAL
2022 2057
2023int invoke (player *pl, int event, ...) 2058int invoke (player *pl, int event, ...)
2024 CODE: 2059 CODE:
2025 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); 2060 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
2026 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2061 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2039 2074
2040void cf_player_move (player *pl, int dir) 2075void cf_player_move (player *pl, int dir)
2041 2076
2042void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2077void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2043 2078
2044# nonstandard
2045object *ob (player *pl)
2046 CODE:
2047 RETVAL = pl->ob;
2048 OUTPUT: RETVAL
2049
2050player *first () 2079player *first ()
2051 CODE: 2080 CODE:
2052 RETVAL = first_player; 2081 RETVAL = first_player;
2053 OUTPUT: RETVAL 2082 OUTPUT: RETVAL
2054 2083
2060bool 2089bool
2061cell_visible (player *pl, int dx, int dy) 2090cell_visible (player *pl, int dx, int dy)
2062 CODE: 2091 CODE:
2063 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 2092 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
2064 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; 2093 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
2065 OUTPUT:
2066 RETVAL
2067
2068char *
2069client (player *pl)
2070 CODE:
2071 RETVAL = pl->socket.client;
2072 OUTPUT:
2073 RETVAL
2074
2075char *
2076host (player *pl)
2077 CODE:
2078 RETVAL = pl->socket.host;
2079 OUTPUT:
2080 RETVAL
2081
2082char *
2083killer (player *pl, char *killer = 0)
2084 CODE:
2085 if (killer)
2086 snprintf (pl->killer, sizeof (pl->killer), "%s", killer);
2087 RETVAL = pl->killer;
2088 OUTPUT: 2094 OUTPUT:
2089 RETVAL 2095 RETVAL
2090 2096
2091void 2097void
2092buggy_mapscroll (player *pl, int value = 1) 2098buggy_mapscroll (player *pl, int value = 1)
2158 OUTPUT: RETVAL 2164 OUTPUT: RETVAL
2159 2165
2160 2166
2161MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2167MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2162 2168
2163mapstruct *first () 2169maptile *first ()
2164 PROTOTYPE: 2170 PROTOTYPE:
2165 CODE: 2171 CODE:
2166 RETVAL = first_map; 2172 RETVAL = first_map;
2167 OUTPUT: RETVAL 2173 OUTPUT: RETVAL
2168 2174
2169int invoke (mapstruct *map, int event, ...) 2175int invoke (maptile *map, int event, ...)
2170 CODE: 2176 CODE:
2171 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); 2177 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP");
2172 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2178 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2173 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 2179 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)); 2180 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av));
2175 OUTPUT: RETVAL 2181 OUTPUT: RETVAL
2176 2182
2177SV *registry (mapstruct *map) 2183SV *registry (maptile *map)
2178 CODE: 2184 CODE:
2179 RETVAL = registry_of (map); 2185 RETVAL = registry_of (map);
2180 OUTPUT: 2186 OUTPUT:
2181 RETVAL 2187 RETVAL
2182 2188
2183INCLUDE: $PERL genacc mapstruct ../include/map.h | 2189INCLUDE: $PERL genacc maptile ../include/map.h |
2184 2190
2185mapstruct *new (int width, int height) 2191maptile *new (int width, int height)
2186 PROTOTYPE: 2192 PROTOTYPE:
2187 CODE: 2193 CODE:
2188{ 2194{
2189 RETVAL = get_empty_map (width, height); 2195 RETVAL = get_empty_map (width, height);
2190} 2196}
2191 OUTPUT: 2197 OUTPUT:
2192 RETVAL 2198 RETVAL
2193 2199
2194void delete_map (mapstruct *map) 2200void delete_map (maptile *map)
2195 2201
2196void clean_tmp_map (mapstruct *map) 2202void clean_tmp_map (maptile *map)
2197 2203
2198void play_sound_map (mapstruct *map, int x, int y, int sound_num) 2204void play_sound_map (maptile *map, int x, int y, int sound_num)
2199 2205
2200mapstruct *tile_map (mapstruct *map, unsigned int dir) 2206maptile *tile_map (maptile *map, unsigned int dir)
2201 CODE: 2207 CODE:
2202 RETVAL = dir < 4 ? map->tile_map [dir] : 0; 2208 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
2203 OUTPUT: 2209 OUTPUT:
2204 RETVAL 2210 RETVAL
2205 2211
2206char *tile_path (mapstruct *map, unsigned int dir) 2212char *tile_path (maptile *map, unsigned int dir)
2207 CODE: 2213 CODE:
2208 if (dir >= 4) 2214 if (dir >= 4)
2209 XSRETURN_UNDEF; 2215 XSRETURN_UNDEF;
2210 RETVAL = map->tile_path [dir]; 2216 RETVAL = map->tile_path [dir];
2211 OUTPUT: 2217 OUTPUT:
2212 RETVAL 2218 RETVAL
2213 2219
2214mapstruct *ready_map_name (char *name, int flags = 0) 2220maptile *ready_map_name (char *name, int flags = 0)
2215 PROTOTYPE: $;$ 2221 PROTOTYPE: $;$
2216 ALIAS: 2222 ALIAS:
2217 find = 0 2223 find = 0
2218 get_map = 1 2224 get_map = 1
2219 2225
2220mapstruct *has_been_loaded (char *name) 2226maptile *has_been_loaded (char *name)
2221 PROTOTYPE: $ 2227 PROTOTYPE: $
2222 2228
2223int in_memory (mapstruct *map) 2229int in_memory (maptile *map)
2224 CODE: 2230 CODE:
2225 RETVAL = map->in_memory; 2231 RETVAL = map->in_memory;
2226 OUTPUT: 2232 OUTPUT:
2227 RETVAL 2233 RETVAL
2228 2234
2229void 2235void
2230trigger (mapstruct *map, long connection, bool state = true) 2236trigger (maptile *map, long connection, bool state = true)
2231 CODE: 2237 CODE:
2232 activate_connection (map, connection, state); 2238 activate_connection (map, connection, state);
2233 2239
2234void 2240void
2235get_connection (mapstruct *map, long connection) 2241get_connection (maptile *map, long connection)
2236 PPCODE: 2242 PPCODE:
2237 oblinkpt *obp = get_connection_links (map, connection); 2243 oblinkpt *obp = get_connection_links (map, connection);
2238 if (obp) 2244 if (obp)
2239 for (objectlink *ol = obp->link; ol; ol = ol->next) 2245 for (objectlink *ol = obp->link; ol; ol = ol->next)
2240 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); 2246 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob)));
2241 2247
2242object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) 2248object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags)
2243 2249
2244object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 2250object *cf_map_insert_object (maptile *where, object* op, int x, int y)
2245 2251
2246object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 2252object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2247 C_ARGS: str, map, nx, ny 2253 C_ARGS: str, map, nx, ny
2248 2254
2249void 2255void
2250cf_map_normalise (mapstruct *map, int x, int y) 2256cf_map_normalise (maptile *map, int x, int y)
2251 PPCODE: 2257 PPCODE:
2252{ 2258{
2253 mapstruct *nmap = 0; 2259 maptile *nmap = 0;
2254 I16 nx = 0, ny = 0; 2260 I16 nx = 0, ny = 0;
2255 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2261 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2256 2262
2257 EXTEND (SP, 4); 2263 EXTEND (SP, 4);
2258 PUSHs (sv_2mortal (newSViv (flags))); 2264 PUSHs (sv_2mortal (newSViv (flags)));
2264 PUSHs (sv_2mortal (newSViv (ny))); 2270 PUSHs (sv_2mortal (newSViv (ny)));
2265 } 2271 }
2266} 2272}
2267 2273
2268void 2274void
2269at (mapstruct *map, unsigned int x, unsigned int y) 2275at (maptile *map, unsigned int x, unsigned int y)
2270 PROTOTYPE: $$$ 2276 PROTOTYPE: $$$
2271 PPCODE: 2277 PPCODE:
2272{ 2278{
2273 object *o; 2279 object *o;
2274 mapstruct *nmap = 0; 2280 maptile *nmap = 0;
2275 I16 nx, ny; 2281 I16 nx, ny;
2276 2282
2277 get_map_flags (map, &nmap, x, y, &nx, &ny); 2283 get_map_flags (map, &nmap, x, y, &nx, &ny);
2278 2284
2279 if (nmap) 2285 if (nmap)
2280 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) 2286 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
2281 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 2287 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
2282} 2288}
2283 2289
2284SV * 2290SV *
2285bot_at (mapstruct *obj, unsigned int x, unsigned int y) 2291bot_at (maptile *obj, unsigned int x, unsigned int y)
2286 PROTOTYPE: $$$ 2292 PROTOTYPE: $$$
2287 ALIAS: 2293 ALIAS:
2288 top_at = 1 2294 top_at = 1
2289 flags_at = 2 2295 flags_at = 2
2290 light_at = 3 2296 light_at = 3
2307 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2313 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
2308 } 2314 }
2309 OUTPUT: 2315 OUTPUT:
2310 RETVAL 2316 RETVAL
2311 2317
2318void fix_walls (maptile *map, int x, int y)
2319
2320void fix_walls_around (maptile *map, int x, int y)
2312 2321
2313MODULE = cf PACKAGE = cf::arch 2322MODULE = cf PACKAGE = cf::arch
2314 2323
2315archetype *find (const char *name) 2324archetype *find (const char *name)
2316 CODE: 2325 CODE:
2317 RETVAL = find_archetype (name); 2326 RETVAL = archetype::find (name);
2318 OUTPUT: 2327 OUTPUT:
2319 RETVAL 2328 RETVAL
2320 2329
2321archetype *first() 2330archetype *first()
2322 PROTOTYPE: 2331 PROTOTYPE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines