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.49 by root, Sun Sep 10 14:54:02 2006 UTC vs.
Revision 1.69 by root, Fri Nov 24 09:44:14 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::archetype::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
188inline SV *to_sv (object & v) { return to_sv (&v); } 143inline SV *to_sv (object & 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); }
194 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}
156
195inline void sv_to (SV *sv, shstr &v) { v = SvPV_nolen (sv); } 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 = strdup (SvPV_nolen (sv)); } //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); }
199inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 161inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
200inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 162inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
201inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } 163inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); }
202inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } 164inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); }
203inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } 165inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); }
204inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } 166inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); }
205inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 167inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
206inline void sv_to (SV *sv, signed long long &v) { v = SvVAL64 (sv); } 168inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
207inline void sv_to (SV *sv, unsigned long long &v) { v = SvVAL64 (sv); } 169inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (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::archetype"); } 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
219inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO 181inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO
220 182
183template<class T>
184inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
185
221template<int N> 186template<int N>
222inline void sv_to (SV *sv, char (&v)[N]) { snprintf (v, N, "%s", 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}
223 199
224static SV * 200static SV *
225newSVdt_va (va_list &ap, data_type type) 201newSVdt_va (va_list &ap, data_type type)
226{ 202{
227 SV *sv; 203 SV *sv;
259 sv = to_sv (va_arg (ap, object *)); 235 sv = to_sv (va_arg (ap, object *));
260 break; 236 break;
261 237
262 case DT_MAP: 238 case DT_MAP:
263 // va_arg (object *) when void * is passed is an XSI extension 239 // va_arg (object *) when void * is passed is an XSI extension
264 sv = to_sv (va_arg (ap, mapstruct *)); 240 sv = to_sv (va_arg (ap, maptile *));
265 break; 241 break;
266 242
267 case DT_PLAYER: 243 case DT_PLAYER:
268 sv = to_sv (va_arg (ap, player *)); 244 sv = to_sv (va_arg (ap, player *));
269 break; 245 break;
346 { 322 {
347 if (cb) 323 if (cb)
348 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) 324 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1)))
349 INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); 325 INVOKE_OBJECT (DESTROY, static_cast<object *>(this));
350 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) 326 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1)))
351 INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); 327 INVOKE_MAP (DESTROY, static_cast<maptile *>(this));
352 328
353 // disconnect Perl from C, to avoid crashes 329 // disconnect Perl from C, to avoid crashes
354 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); 330 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
355 331
356 // 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
484 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);
485 FREETMPS; 461 FREETMPS;
486 LEAVE; 462 LEAVE;
487} 463}
488 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
489int fprintf (object_freezer &freezer, const char *format, ...) 486int fprintf (object_freezer &freezer, const char *format, ...)
490{ 487{
491 va_list ap; 488 va_list ap;
492 489
493 va_start (ap, format); 490 va_start (ap, format);
502 499
503int fputs (const char *s, object_freezer &freezer) 500int fputs (const char *s, object_freezer &freezer)
504{ 501{
505 freezer.add (s); 502 freezer.add (s);
506} 503}
504
505static const char thawer_eof[] = "\n\n\n\0\0\0";
507 506
508object_thawer::object_thawer (const char *filename) 507object_thawer::object_thawer (const char *filename)
509{ 508{
510 static const char eof[] = "\n\n\n\0\0\0"; 509 static const char eof[] = "\n\n\n\0\0\0";
511 510
549 548
550 PUTBACK; 549 PUTBACK;
551 FREETMPS; 550 FREETMPS;
552 LEAVE; 551 LEAVE;
553 } 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);
554} 561}
555 562
556void 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)
557{ 564{
558 if (!av || oid < 0) // this is actually an error of sorts 565 if (!av || oid < 0) // this is actually an error of sorts
874 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))
875 { 882 {
876 printf ("unable to initialize perl-interpreter, aborting.\n"); 883 printf ("unable to initialize perl-interpreter, aborting.\n");
877 exit (EXIT_FAILURE); 884 exit (EXIT_FAILURE);
878 } 885 }
879
880 obj_cache = newHV ();
881} 886}
882 887
883void cfperl_main () 888void cfperl_main ()
884{ 889{
885 dSP; 890 dSP;
936 941
937 AV *callbacks = 0; 942 AV *callbacks = 0;
938 943
939 object *op; 944 object *op;
940 player *pl; 945 player *pl;
941 mapstruct *map; 946 maptile *map;
942 947
943 // callback call ordering is: 948 // callback call ordering is:
944 // 1. per-object callback (NYI) 949 // 1. per-object callback (NYI)
945 // 2. per-class object 950 // 2. per-class object
946 // 2a. per-type callback 951 // 2a. per-type callback
996 break; 1001 break;
997 1002
998 case KLASS_MAP: 1003 case KLASS_MAP:
999 dt = (data_type) va_arg (ap, int); 1004 dt = (data_type) va_arg (ap, int);
1000 assert (("first argument must be of type object", dt == DT_MAP)); 1005 assert (("first argument must be of type object", dt == DT_MAP));
1001 map = va_arg (ap, mapstruct *); 1006 map = va_arg (ap, maptile *);
1002 1007
1003 if (map->cb) 1008 if (map->cb)
1004 gather_callbacks (callbacks, map->cb, event); 1009 gather_callbacks (callbacks, map->cb, event);
1005 1010
1006 gather_callbacks (callbacks, cb_map, event); 1011 gather_callbacks (callbacks, cb_map, event);
1086MODULE = cf PACKAGE = cf PREFIX = cf_ 1091MODULE = cf PACKAGE = cf PREFIX = cf_
1087 1092
1088BOOT: 1093BOOT:
1089{ 1094{
1090 HV *stash = gv_stashpv ("cf", 1); 1095 HV *stash = gv_stashpv ("cf", 1);
1096
1097 newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1091 1098
1092 static const struct { 1099 static const struct {
1093 const char *name; 1100 const char *name;
1094 IV iv; 1101 IV iv;
1095 } *civ, const_iv[] = { 1102 } *civ, const_iv[] = {
1258 const_iv (AT_BLIND) 1265 const_iv (AT_BLIND)
1259 const_iv (AT_INTERNAL) 1266 const_iv (AT_INTERNAL)
1260 const_iv (AT_LIFE_STEALING) 1267 const_iv (AT_LIFE_STEALING)
1261 const_iv (AT_DISEASE) 1268 const_iv (AT_DISEASE)
1262 1269
1263 const_iv (QUEST_IN_PROGRESS)
1264 const_iv (QUEST_DONE_QUEST)
1265 const_iv (QUEST_DONE_TASK)
1266 const_iv (QUEST_START_QUEST)
1267 const_iv (QUEST_END_QUEST)
1268 const_iv (QUEST_START_TASK)
1269 const_iv (QUEST_END_TASK)
1270 const_iv (QUEST_OVERRIDE)
1271 const_iv (QUEST_ON_ACTIVATE)
1272
1273 const_iv (WEAP_HIT) 1270 const_iv (WEAP_HIT)
1274 const_iv (WEAP_SLASH) 1271 const_iv (WEAP_SLASH)
1275 const_iv (WEAP_PIERCE) 1272 const_iv (WEAP_PIERCE)
1276 const_iv (WEAP_CLEAVE) 1273 const_iv (WEAP_CLEAVE)
1277 const_iv (WEAP_SLICE) 1274 const_iv (WEAP_SLICE)
1398 const_iv (NDI_MAX_COLOR) 1395 const_iv (NDI_MAX_COLOR)
1399 const_iv (NDI_COLOR_MASK) 1396 const_iv (NDI_COLOR_MASK)
1400 const_iv (NDI_UNIQUE) 1397 const_iv (NDI_UNIQUE)
1401 const_iv (NDI_ALL) 1398 const_iv (NDI_ALL)
1402 1399
1400 const_iv (UPD_LOCATION)
1401 const_iv (UPD_FLAGS)
1402 const_iv (UPD_WEIGHT)
1403 const_iv (UPD_FACE)
1404 const_iv (UPD_NAME)
1405 const_iv (UPD_ANIM)
1406 const_iv (UPD_ANIMSPEED)
1407 const_iv (UPD_NROF)
1408
1409 const_iv (UPD_SP_MANA)
1410 const_iv (UPD_SP_GRACE)
1411 const_iv (UPD_SP_DAMAGE)
1412
1403 const_iv (F_APPLIED) 1413 const_iv (F_APPLIED)
1404 const_iv (F_LOCATION) 1414 const_iv (F_LOCATION)
1405 const_iv (F_UNPAID) 1415 const_iv (F_UNPAID)
1406 const_iv (F_MAGIC) 1416 const_iv (F_MAGIC)
1407 const_iv (F_CURSED) 1417 const_iv (F_CURSED)
1620{ 1630{
1621 // reattach to all attachable objects in the game. 1631 // reattach to all attachable objects in the game.
1622 for (player *pl = first_player; pl; pl = pl->next) 1632 for (player *pl = first_player; pl; pl = pl->next)
1623 reattach (pl); 1633 reattach (pl);
1624 1634
1625 for (mapstruct *map = first_map; map; map = map->next) 1635 for (maptile *map = first_map; map; map = map->next)
1626 reattach (map); 1636 reattach (map);
1627 1637
1628 for (object *op = objects; op; op = op->next) 1638 for (object *op = object::first; op; op = op->next)
1629 reattach (op); 1639 reattach (op);
1630} 1640}
1631 1641
1632NV floor (NV x) 1642NV floor (NV x)
1633 1643
1681 case 5: RETVAL = settings.playerdir; break; 1691 case 5: RETVAL = settings.playerdir; break;
1682 case 6: RETVAL = settings.datadir ; break; 1692 case 6: RETVAL = settings.datadir ; break;
1683 } 1693 }
1684 OUTPUT: RETVAL 1694 OUTPUT: RETVAL
1685 1695
1686int 1696void _exit (int status = 0)
1697
1687cf_find_animation (char *text) 1698int cf_find_animation (char *text)
1688 PROTOTYPE: $ 1699 PROTOTYPE: $
1689 1700
1690int random_roll(int min, int max, object *op, int goodbad); 1701int random_roll(int min, int max, object *op, int goodbad);
1691 1702
1692const char *cost_string_from_value(uint64 cost, int approx = 0) 1703const char *cost_string_from_value(uint64 cost, int approx = 0)
1745 OUTPUT: 1756 OUTPUT:
1746 RETVAL 1757 RETVAL
1747 1758
1748MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1759MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1749 1760
1761INCLUDE: $PERL genacc object ../include/object.h |
1762
1750int invoke (object *op, int event, ...) 1763int invoke (object *op, int event, ...)
1751 CODE: 1764 CODE:
1752 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");
1753 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 1766 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1754 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)));
1759 CODE: 1772 CODE:
1760 RETVAL = registry_of (op); 1773 RETVAL = registry_of (op);
1761 OUTPUT: 1774 OUTPUT:
1762 RETVAL 1775 RETVAL
1763 1776
1764INCLUDE: $PERL genacc object ../include/object.h | 1777void mortals ()
1778 PPCODE:
1779 EXTEND (SP, object::mortals.size ());
1780 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1781 PUSHs (to_sv (*i));
1782
1783object *first ()
1784 CODE:
1785 RETVAL = object::first;
1786 OUTPUT: RETVAL
1765 1787
1766# missing properties 1788# missing properties
1767 1789
1768int flag (object *op, int flag, int value = 1) 1790int flag (object *op, int flag, int value = 1)
1769 PROTOTYPE: $$;$ 1791 PROTOTYPE: $$;$
1774 SET_FLAG (op, flag); 1796 SET_FLAG (op, flag);
1775 else 1797 else
1776 CLEAR_FLAG (op, flag); 1798 CLEAR_FLAG (op, flag);
1777 OUTPUT: RETVAL 1799 OUTPUT: RETVAL
1778 1800
1801object *head (object *op)
1802 PROTOTYPE: $
1803 CODE:
1804 RETVAL = op->head ? op->head : op;
1805 OUTPUT: RETVAL
1806
1807int is_head (object *op)
1808 PROTOTYPE: $
1809 CODE:
1810 RETVAL = !op->head;
1811 OUTPUT: RETVAL
1812
1779void 1813void
1780inv (object *obj) 1814inv (object *obj)
1781 PROTOTYPE: $ 1815 PROTOTYPE: $
1782 PPCODE: 1816 PPCODE:
1783{ 1817{
1784 object *o; 1818 object *o;
1785 for (o = obj->inv; o; o = o->below) 1819 for (o = obj->inv; o; o = o->below)
1786 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1820 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1787} 1821}
1788 1822
1823object *find_best_object_match (object *op, const char *match)
1824
1825object *find_marked_object (object *op)
1826
1789int cf_object_get_resistance (object *op, int rtype) 1827int cf_object_get_resistance (object *op, int rtype)
1790 ALIAS: resistance = 0 1828 ALIAS: resistance = 0
1791 1829
1792int need_identify (const object *obj); 1830int need_identify (const object *obj);
1793 1831
1809 1847
1810object *cf_object_present_archname_inside (object *op, char *whatstr) 1848object *cf_object_present_archname_inside (object *op, char *whatstr)
1811 1849
1812int 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)
1813 1851
1814int 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)
1815 1853
1816object *cf_object_clone (object *op, int clonetype = 0) 1854object *cf_object_clone (object *op, int clonetype = 0)
1817 1855
1818int cf_object_pay_item (object *op, object *buyer) 1856int cf_object_pay_item (object *op, object *buyer)
1819 1857
1851 1889
1852object *cf_object_insert_object (object *op, object *container) 1890object *cf_object_insert_object (object *op, object *container)
1853 1891
1854object *cf_object_insert_in_ob (object *ob, object *where) 1892object *cf_object_insert_in_ob (object *ob, object *where)
1855 1893
1856int cf_object_teleport (object *op, mapstruct *map, int x, int y) 1894int cf_object_teleport (object *op, maptile *map, int x, int y)
1857 1895
1858void cf_object_update (object *op, int flags) 1896void cf_object_update (object *op, int flags)
1859 1897
1860void cf_object_pickup (object *op, object *what) 1898void cf_object_pickup (object *op, object *what)
1861 1899
1871 1909
1872void push_button (object *op); 1910void push_button (object *op);
1873 1911
1874void use_trigger (object *op); 1912void use_trigger (object *op);
1875 1913
1876void add_button_link (object *button, mapstruct *map, int connected); 1914void add_button_link (object *button, maptile *map, int connected);
1877 1915
1878void remove_button_link (object *op); 1916void remove_button_link (object *op);
1879 1917
1880void 1918void
1881cf_object_set_resistance (object *op, int rtype, int val) 1919cf_object_set_resistance (object *op, int rtype, int val)
1899 CODE: 1937 CODE:
1900 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1938 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1901 OUTPUT: 1939 OUTPUT:
1902 RETVAL 1940 RETVAL
1903 1941
1904object *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)
1905 PROTOTYPE: $$$$$$ 1943 PROTOTYPE: $$$$$$
1906 CODE: 1944 CODE:
1907{ 1945{
1908 int unused_type; 1946 int unused_type;
1909 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);
1947bool on_same_map_as (object *ob, object *other) 1985bool on_same_map_as (object *ob, object *other)
1948 CODE: 1986 CODE:
1949 RETVAL = on_same_map (ob, other); 1987 RETVAL = on_same_map (ob, other);
1950 OUTPUT: RETVAL 1988 OUTPUT: RETVAL
1951 1989
1952char * 1990const char *
1953base_name (object *ob, int plural) 1991base_name (object *op, int plural = op->nrof > 1)
1954 CODE: 1992 CODE:
1955 RETVAL = cf_query_base_name (ob, plural); 1993 RETVAL = query_base_name (op, plural);
1956 OUTPUT: RETVAL 1994 OUTPUT: RETVAL
1957 1995
1958MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1996MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1959 1997
1960player *player (object *op) 1998player *player (object *op)
1979 2017
1980void cf_player_set_party (object *op, partylist *party) 2018void cf_player_set_party (object *op, partylist *party)
1981 2019
1982void kill_player (object *op) 2020void kill_player (object *op)
1983 2021
2022void esrv_update_item (object *op, int what, object *item)
2023 C_ARGS: what, op, item
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
1984MODULE = 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
1985 2057
1986int invoke (player *pl, int event, ...) 2058int invoke (player *pl, int event, ...)
1987 CODE: 2059 CODE:
1988 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");
1989 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2061 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2002 2074
2003void cf_player_move (player *pl, int dir) 2075void cf_player_move (player *pl, int dir)
2004 2076
2005void 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);
2006 2078
2007# nonstandard
2008object *ob (player *pl)
2009 CODE:
2010 RETVAL = pl->ob;
2011 OUTPUT: RETVAL
2012
2013player *first () 2079player *first ()
2014 CODE: 2080 CODE:
2015 RETVAL = first_player; 2081 RETVAL = first_player;
2016 OUTPUT: RETVAL 2082 OUTPUT: RETVAL
2017 2083
2023bool 2089bool
2024cell_visible (player *pl, int dx, int dy) 2090cell_visible (player *pl, int dx, int dy)
2025 CODE: 2091 CODE:
2026 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
2027 && !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];
2028 OUTPUT:
2029 RETVAL
2030
2031char *
2032client (player *pl)
2033 CODE:
2034 RETVAL = pl->socket.client;
2035 OUTPUT:
2036 RETVAL
2037
2038char *
2039host (player *pl)
2040 CODE:
2041 RETVAL = pl->socket.host;
2042 OUTPUT:
2043 RETVAL
2044
2045char *
2046killer (player *pl, char *killer = 0)
2047 CODE:
2048 if (killer)
2049 snprintf (pl->killer, sizeof (pl->killer), "%s", killer);
2050 RETVAL = pl->killer;
2051 OUTPUT: 2094 OUTPUT:
2052 RETVAL 2095 RETVAL
2053 2096
2054void 2097void
2055buggy_mapscroll (player *pl, int value = 1) 2098buggy_mapscroll (player *pl, int value = 1)
2121 OUTPUT: RETVAL 2164 OUTPUT: RETVAL
2122 2165
2123 2166
2124MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2167MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2125 2168
2126mapstruct *first () 2169maptile *first ()
2127 PROTOTYPE: 2170 PROTOTYPE:
2128 CODE: 2171 CODE:
2129 RETVAL = first_map; 2172 RETVAL = first_map;
2130 OUTPUT: RETVAL 2173 OUTPUT: RETVAL
2131 2174
2132int invoke (mapstruct *map, int event, ...) 2175int invoke (maptile *map, int event, ...)
2133 CODE: 2176 CODE:
2134 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");
2135 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2178 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2136 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)));
2137 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); 2180 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av));
2138 OUTPUT: RETVAL 2181 OUTPUT: RETVAL
2139 2182
2140SV *registry (mapstruct *map) 2183SV *registry (maptile *map)
2141 CODE: 2184 CODE:
2142 RETVAL = registry_of (map); 2185 RETVAL = registry_of (map);
2143 OUTPUT: 2186 OUTPUT:
2144 RETVAL 2187 RETVAL
2145 2188
2146INCLUDE: $PERL genacc mapstruct ../include/map.h | 2189INCLUDE: $PERL genacc maptile ../include/map.h |
2147 2190
2148mapstruct *new (int width, int height) 2191maptile *new (int width, int height)
2149 PROTOTYPE: 2192 PROTOTYPE:
2150 CODE: 2193 CODE:
2151{ 2194{
2152 RETVAL = get_empty_map (width, height); 2195 RETVAL = get_empty_map (width, height);
2153} 2196}
2154 OUTPUT: 2197 OUTPUT:
2155 RETVAL 2198 RETVAL
2156 2199
2157void delete_map (mapstruct *map) 2200void delete_map (maptile *map)
2158 2201
2159void clean_tmp_map (mapstruct *map) 2202void clean_tmp_map (maptile *map)
2160 2203
2161void 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)
2162 2205
2163mapstruct *tile_map (mapstruct *map, unsigned int dir) 2206maptile *tile_map (maptile *map, unsigned int dir)
2164 CODE: 2207 CODE:
2165 RETVAL = dir < 4 ? map->tile_map [dir] : 0; 2208 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
2166 OUTPUT: 2209 OUTPUT:
2167 RETVAL 2210 RETVAL
2168 2211
2169char *tile_path (mapstruct *map, unsigned int dir) 2212char *tile_path (maptile *map, unsigned int dir)
2170 CODE: 2213 CODE:
2171 if (dir >= 4) 2214 if (dir >= 4)
2172 XSRETURN_UNDEF; 2215 XSRETURN_UNDEF;
2173 RETVAL = map->tile_path [dir]; 2216 RETVAL = map->tile_path [dir];
2174 OUTPUT: 2217 OUTPUT:
2175 RETVAL 2218 RETVAL
2176 2219
2177mapstruct *ready_map_name (char *name, int flags = 0) 2220maptile *ready_map_name (char *name, int flags = 0)
2178 PROTOTYPE: $;$ 2221 PROTOTYPE: $;$
2179 ALIAS: 2222 ALIAS:
2180 find = 0 2223 find = 0
2181 get_map = 1 2224 get_map = 1
2182 2225
2183mapstruct *has_been_loaded (char *name) 2226maptile *has_been_loaded (char *name)
2184 PROTOTYPE: $ 2227 PROTOTYPE: $
2185 2228
2186int in_memory (mapstruct *map) 2229int in_memory (maptile *map)
2187 CODE: 2230 CODE:
2188 RETVAL = map->in_memory; 2231 RETVAL = map->in_memory;
2189 OUTPUT: 2232 OUTPUT:
2190 RETVAL 2233 RETVAL
2191 2234
2192void 2235void
2193trigger (mapstruct *map, long connection, bool state = true) 2236trigger (maptile *map, long connection, bool state = true)
2194 CODE: 2237 CODE:
2195 activate_connection (map, connection, state); 2238 activate_connection (map, connection, state);
2196 2239
2197void 2240void
2198get_connection (mapstruct *map, long connection) 2241get_connection (maptile *map, long connection)
2199 PPCODE: 2242 PPCODE:
2200 oblinkpt *obp = get_connection_links (map, connection); 2243 oblinkpt *obp = get_connection_links (map, connection);
2201 if (obp) 2244 if (obp)
2202 for (objectlink *ol = obp->link; ol; ol = ol->next) 2245 for (objectlink *ol = obp->link; ol; ol = ol->next)
2203 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); 2246 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob)));
2204 2247
2205object *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)
2206 2249
2207object *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)
2208 2251
2209object* 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)
2210 C_ARGS: str, map, nx, ny 2253 C_ARGS: str, map, nx, ny
2211 2254
2212void 2255void
2213cf_map_normalise (mapstruct *map, int x, int y) 2256cf_map_normalise (maptile *map, int x, int y)
2214 PPCODE: 2257 PPCODE:
2215{ 2258{
2216 mapstruct *nmap = 0; 2259 maptile *nmap = 0;
2217 I16 nx = 0, ny = 0; 2260 I16 nx = 0, ny = 0;
2218 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2261 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2219 2262
2220 EXTEND (SP, 4); 2263 EXTEND (SP, 4);
2221 PUSHs (sv_2mortal (newSViv (flags))); 2264 PUSHs (sv_2mortal (newSViv (flags)));
2227 PUSHs (sv_2mortal (newSViv (ny))); 2270 PUSHs (sv_2mortal (newSViv (ny)));
2228 } 2271 }
2229} 2272}
2230 2273
2231void 2274void
2232at (mapstruct *map, unsigned int x, unsigned int y) 2275at (maptile *map, unsigned int x, unsigned int y)
2233 PROTOTYPE: $$$ 2276 PROTOTYPE: $$$
2234 PPCODE: 2277 PPCODE:
2235{ 2278{
2236 object *o; 2279 object *o;
2237 mapstruct *nmap = 0; 2280 maptile *nmap = 0;
2238 I16 nx, ny; 2281 I16 nx, ny;
2239 2282
2240 get_map_flags (map, &nmap, x, y, &nx, &ny); 2283 get_map_flags (map, &nmap, x, y, &nx, &ny);
2241 2284
2242 if (nmap) 2285 if (nmap)
2243 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)
2244 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 2287 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
2245} 2288}
2246 2289
2247SV * 2290SV *
2248bot_at (mapstruct *obj, unsigned int x, unsigned int y) 2291bot_at (maptile *obj, unsigned int x, unsigned int y)
2249 PROTOTYPE: $$$ 2292 PROTOTYPE: $$$
2250 ALIAS: 2293 ALIAS:
2251 top_at = 1 2294 top_at = 1
2252 flags_at = 2 2295 flags_at = 2
2253 light_at = 3 2296 light_at = 3
2275 2318
2276MODULE = cf PACKAGE = cf::arch 2319MODULE = cf PACKAGE = cf::arch
2277 2320
2278archetype *find (const char *name) 2321archetype *find (const char *name)
2279 CODE: 2322 CODE:
2280 RETVAL = find_archetype (name); 2323 RETVAL = archetype::find (name);
2281 OUTPUT: 2324 OUTPUT:
2282 RETVAL 2325 RETVAL
2283 2326
2284archetype *first() 2327archetype *first()
2285 PROTOTYPE: 2328 PROTOTYPE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines