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.20 by root, Mon Aug 28 14:05:24 2006 UTC vs.
Revision 1.39 by elmex, Fri Sep 1 17:16:47 2006 UTC

21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24*/ 24*/
25 25
26#include <EXTERN.h>
27#include <perl.h>
28#include <XSUB.h>
29
30#undef save_long // clashes with libproto.h
31
32#define PLUGIN_NAME "perl" 26#define PLUGIN_NAME "perl"
33#define PLUGIN_VERSION "cfperl 0.5" 27#define PLUGIN_VERSION "cfperl 0.5"
34
35#ifndef __CEXTRACT__
36#include <plugin.h>
37#endif
38
39#undef MODULEAPI
40#ifdef WIN32
41#else
42#define MODULEAPI
43#endif
44 28
45#include <plugin_common.h> 29#include <plugin_common.h>
46#include <sounds.h> 30#include <sounds.h>
47#include <cstdarg> 31#include <cstdarg>
48#include <sproto.h> 32#include <sproto.h>
49 33
50#include "cfperl.h" 34#include "cfperl.h"
51#include "shstr.h" 35#include "shstr.h"
52 36
37#include <EXTERN.h>
38#include <perl.h>
39#include <XSUB.h>
40
53#include "perlxsi.c" 41#include "perlxsi.c"
54 42
55extern sint64 *levels; // the experience table 43extern sint64 *levels; // the experience table
56 44
57typedef object object_ornull; 45typedef object object_ornull;
61#define newSVval64 newSVnv 49#define newSVval64 newSVnv
62#define SvVAL64 SvNV 50#define SvVAL64 SvNV
63 51
64static f_plug_api gethook = cfapi_get_hooks; 52static f_plug_api gethook = cfapi_get_hooks;
65static f_plug_api object_set_property = cfapi_object_set_property; 53static f_plug_api object_set_property = cfapi_object_set_property;
66static f_plug_api map_get_map = cfapi_map_get_map;
67static f_plug_api object_insert = cfapi_object_insert; 54static f_plug_api object_insert = cfapi_object_insert;
55
56static bool perl_booted;
68 57
69/* this is a stupid way to do things, and awkward to use for plug-in authors */ 58/* this is a stupid way to do things, and awkward to use for plug-in authors */
70typedef struct 59typedef struct
71{ 60{
72 object* who; 61 object* who;
117 return &PL_sv_undef; 106 return &PL_sv_undef;
118 107
119 if (!obj->self) 108 if (!obj->self)
120 obj->self = newSVptr (obj, klass); 109 obj->self = newSVptr (obj, klass);
121 110
122 return newSVsv (static_cast<SV *>(obj->self)); 111 return newSVsv (obj->self);
123} 112}
124 113
125static void 114static void
126SVptr_cache_set (void *ptr, SV *sv) 115SVptr_cache_set (void *ptr, SV *sv)
127{ 116{
313 return newRV_inc ((SV *)ext->cb); 302 return newRV_inc ((SV *)ext->cb);
314} 303}
315 304
316void attachable_base::clear () 305void attachable_base::clear ()
317{ 306{
318 //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D 307 if (self)
308 {
309 if (cb)
310 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1)))
311 INVOKE_OBJECT (DESTROY, static_cast<object *>(this));
312 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1)))
313 INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this));
319 314
315 // disconnect Perl from C, to avoid crashes
316 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
317
318 // clear the perl hash, might or might not be a good idea
319 hv_clear ((HV *)SvRV ((SV *)self));
320
320 if (self) SvREFCNT_dec (self); 321 SvREFCNT_dec (self);
322 self = 0;
323 }
324
325 if (cb)
326 {
321 if (cb) SvREFCNT_dec (cb); 327 SvREFCNT_dec (cb);
328 cb = 0;
329 }
322 330
331 if (attach)
332 {
323 if (attach) free_string (attach); 333 free_string (attach);
324
325 self = 0;
326 cb = 0;
327 attach = 0; 334 attach = 0;
335 }
328} 336}
329 337
330void attachable_base::optimise () 338void attachable_base::optimise ()
331{ 339{
332 if (!self) 340 if (!self)
341 SvREFCNT_dec ((SV *)self); 349 SvREFCNT_dec ((SV *)self);
342 self = 0; 350 self = 0;
343 } 351 }
344} 352}
345 353
346void 354void attachable_base::instantiate (data_type type, void *obj)
347object::instantiate_ ()
348{ 355{
349 dSP; 356 dSP;
350 ENTER; 357 ENTER;
351 SAVETMPS; 358 SAVETMPS;
352 PUSHMARK (SP); 359 PUSHMARK (SP);
353 EXTEND (SP, 2); 360 EXTEND (SP, 2);
354 PUSHs (sv_2mortal (newSVdt (DT_OBJECT, static_cast<object *>(this)))); 361 PUSHs (sv_2mortal (newSVdt (type, obj)));
355 PUSHs (sv_2mortal (newSVpv (attach, 0))); 362 PUSHs (sv_2mortal (newSVpv (attach, 0)));
363
364 free_string (attach);
365 attach = 0;
366
356 PUTBACK; 367 PUTBACK;
357 call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); 368 call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL);
358 FREETMPS; 369 FREETMPS;
359 LEAVE; 370 LEAVE;
360 371
361 INVOKE_OBJECT (INSTANTIATE, this); 372 switch (type)
373 {
374 case DT_OBJECT: INVOKE_OBJECT (INSTANTIATE, obj); break;
375 case DT_MAP: INVOKE_MAP (INSTANTIATE, obj); break;
376 }
362} 377}
363 378
364///////////////////////////////////////////////////////////////////////////// 379/////////////////////////////////////////////////////////////////////////////
365 380
366void reattach (data_type type, void *obj) 381void reattach (data_type type, void *obj)
367{ 382{
383 //TODO only do this when the object has _attachment's
384
368 dSP; 385 dSP;
369 ENTER; 386 ENTER;
370 SAVETMPS; 387 SAVETMPS;
371 PUSHMARK (SP); 388 PUSHMARK (SP);
372 XPUSHs (sv_2mortal (newSVdt (type, obj))); 389 XPUSHs (sv_2mortal (newSVdt (type, obj)));
387void reattach (attachable<subclass> *obj) 404void reattach (attachable<subclass> *obj)
388{ 405{
389 obj->optimise (); 406 obj->optimise ();
390 407
391 if (obj->self) 408 if (obj->self)
392 reattach (subclass::get_dt (), (subclass *)obj); 409 reattach ((data_type) cftype<subclass>::dt, (subclass *)obj);
393} 410}
394 411
412#include "kw_hash.h"
413
414object_freezer::object_freezer ()
415: dynbuf (128 * 1024, 64 * 1024)
416{
417 av = newAV ();
418}
419
420object_freezer::~object_freezer ()
421{
422 SvREFCNT_dec (av);
423}
424
425void object_freezer::put (attachable_base *ext)
426{
427 ext->optimise ();
428
429 if (ext->self)
430 {
431 int idx = AvFILLp ((AV *)av) + 1;
432 av_store (av, idx, SvREFCNT_inc (ext->self));
433
434 add ((void *)"oid ", 4);
435 add ((sint32)idx);
436 add ('\n');
437 }
438}
439
440bool object_freezer::save (const char *filename)
441{
442 dSP;
443 ENTER;
444 SAVETMPS;
445 PUSHMARK (SP);
446 EXTEND (SP, 3);
447 PUSHs (sv_2mortal (newSVpv (filename, 0)));
448 PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ()))));
449 PUSHs (sv_2mortal (newRV_inc ((SV *)av)));
450 PUTBACK;
451 call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL);
452 FREETMPS;
453 LEAVE;
454}
455
456int fprintf (object_freezer &freezer, const char *format, ...)
457{
458 va_list ap;
459
460 va_start (ap, format);
461
462 int len = vsnprintf ((char *)freezer.force (1024), 1024, format, ap);
463
464 if (len >= 0)
465 freezer.alloc (len);
466
467 va_end (ap);
468}
469
470int fputs (const char *s, object_freezer &freezer)
471{
472 freezer.add (s);
473}
474
395object_freezer::object_freezer (const char *filename) 475object_thawer::object_thawer (const char *filename)
396{ 476{
397 this->filename = (SV *)newSVpv (filename, 0); 477 av = 0;
478 fp = 0;
398 479
399 char filename2 [4096]; 480 if (!filename)
400 snprintf (filename2, 4096, "%s~", filename); 481 return;
401 482
402 fp = fopen (filename2, "w"); 483 fp = fopen (filename, "r");
403
404 if (!fp) 484 if (!fp)
405 LOG (llevError, "cannot open file '%s' for writing: %s\n", filename2, strerror (errno));
406
407 av = (AV *)newAV ();
408}
409
410object_freezer::~object_freezer ()
411{
412 if (fp)
413 { 485 {
414 fclose (fp); 486 LOG (llevError, "object_thawer: unable to open '%s': %s.\n", filename, strerror (errno));
487 return;
488 }
415 489
490 if (perl_booted)
491 {
416 dSP; 492 dSP;
417 ENTER; 493 ENTER;
418 SAVETMPS; 494 SAVETMPS;
419 PUSHMARK (SP); 495 PUSHMARK (SP);
420 XPUSHs (sv_2mortal ((SV *)filename)); 496 XPUSHs (sv_2mortal (newSVpv (filename, 0)));
421 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
422 PUTBACK; 497 PUTBACK;
423 call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); 498
499 if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL))
500 {
501 SPAGAIN;
502 SV *sv = POPs;
503 if (SvROK (sv))
504 av = (AV *)SvREFCNT_inc (SvRV (sv));
505 }
506
424 FREETMPS; 507 FREETMPS;
425 LEAVE; 508 LEAVE;
426 } 509 }
427 else
428 SvREFCNT_dec ((SV *)filename);
429}
430
431void object_freezer::put (attachable_base *ext)
432{
433 ext->optimise ();
434
435 if (ext->self)
436 {
437 int idx = AvFILLp ((AV *)av) + 1;
438 av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self));
439 fprintf (fp, "oid %d\n", idx);
440 }
441}
442
443object_thawer::object_thawer (FILE *fp, const char *filename)
444{
445 this->fp = fp;
446 av = 0;
447
448 if (!filename)
449 return;
450
451 dSP;
452 ENTER;
453 SAVETMPS;
454 PUSHMARK (SP);
455 XPUSHs (sv_2mortal (newSVpv (filename, 0)));
456 PUTBACK;
457
458 if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL))
459 {
460 SPAGAIN;
461 SV *sv = POPs;
462 if (SvROK (sv))
463 av = SvREFCNT_inc (SvRV (sv));
464 }
465
466 FREETMPS;
467 LEAVE;
468} 510}
469 511
470void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) 512void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid)
471{ 513{
472 if (!av || oid < 0) // this is actually an error of sorts 514 if (!av || oid < 0) // this is actually an error of sorts
482 printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); 524 printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid);
483 return; 525 return;
484 } 526 }
485 527
486 ext->self = *svp; *svp = &PL_sv_undef; 528 ext->self = *svp; *svp = &PL_sv_undef;
487 sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); 529 sv_magic (SvRV (ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0);
488 530
489 reattach (type, obj); 531 reattach (type, obj);
490} 532}
491 533
492object_thawer::~object_thawer () 534object_thawer::~object_thawer ()
493{ 535{
536 if (fp) fclose (fp);
494 if (av) SvREFCNT_dec ((AV *)av); 537 if (av) SvREFCNT_dec ((AV *)av);
495} 538}
496 539
540token object_thawer::get_token ()
541{
542#if 0
543 for (;;)
544 {
545 if (!fgets (line, sizeof (line), fp))
546 return token (KW_eof);
547
548 unsigned char *p = (unsigned char *)line;
549
550 while (*p > ' ')
551 p++;
552
553 int len = p - (unsigned char *)line;
554
555 while ((*p - 1) < ' ')
556 p++;
557
558 if (*p)
559 {
560 char *v = p;
561
562 while (*p && *p != '\n')
563 p++;
564
565 *p = 0;
566
567 return token (k, v);
568 }
569 else
570 return token (k);
571 }
572#endif
573}
574
497///////////////////////////////////////////////////////////////////////////// 575/////////////////////////////////////////////////////////////////////////////
498 576
499extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) 577extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
500{ 578{
501 return 0; 579 return 0;
598} 676}
599 677
600void 678void
601cfperl_init () 679cfperl_init ()
602{ 680{
681 PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0);
682 perl = perl_alloc ();
683 perl_construct (perl);
684
685 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
686
603 char *argv[] = { 687 char *argv[] = {
604 "", 688 "",
605 "-e" 689 "-e"
606 "BEGIN {"
607 " cf->bootstrap;" 690 "cf->bootstrap;"
608 " unshift @INC, cf::datadir ();" 691 "unshift @INC, cf::datadir ();"
609 "}"
610 ""
611 "use cf;"
612 }; 692 };
613
614 perl = perl_alloc ();
615 perl_construct (perl);
616
617 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
618 693
619 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 694 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
620 { 695 {
621 printf ("unable to initialize perl-interpreter, aborting.\n"); 696 printf ("unable to initialize perl-interpreter, aborting.\n");
622
623 exit (EXIT_FAILURE); 697 exit (EXIT_FAILURE);
624 //perl_destruct (perl);
625 //perl_free (perl);
626 //perl = 0;
627 //return;
628 } 698 }
629 699
630 obj_cache = newHV (); 700 obj_cache = newHV ();
701}
702
703void cfperl_boot ()
704{
705 perl_booted = true;
706
707 eval_pv ("require cf", 1);
631} 708}
632 709
633void cfperl_main () 710void cfperl_main ()
634{ 711{
635 dSP; 712 dSP;
707 dt = (data_type) va_arg (ap, int); 784 dt = (data_type) va_arg (ap, int);
708 assert (("first argument must be of type object", dt == DT_OBJECT)); 785 assert (("first argument must be of type object", dt == DT_OBJECT));
709 op = va_arg (ap, object *); 786 op = va_arg (ap, object *);
710 787
711 if (op->cb) 788 if (op->cb)
712 gather_callbacks (callbacks, (AV *)op->cb, event); 789 gather_callbacks (callbacks, op->cb, event);
713 790
714 if (op->type) 791 if (op->type)
715 { 792 {
716 if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) 793 if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type))
717 { 794 {
738 dt = (data_type) va_arg (ap, int); 815 dt = (data_type) va_arg (ap, int);
739 assert (("first argument must be of type player", dt == DT_PLAYER)); 816 assert (("first argument must be of type player", dt == DT_PLAYER));
740 pl = va_arg (ap, player *); 817 pl = va_arg (ap, player *);
741 818
742 if (pl->cb) 819 if (pl->cb)
743 gather_callbacks (callbacks, (AV *)pl->cb, event); 820 gather_callbacks (callbacks, pl->cb, event);
744 821
745 gather_callbacks (callbacks, cb_player, event); 822 gather_callbacks (callbacks, cb_player, event);
746 break; 823 break;
747 824
748 case KLASS_MAP: 825 case KLASS_MAP:
749 dt = (data_type) va_arg (ap, int); 826 dt = (data_type) va_arg (ap, int);
750 assert (("first argument must be of type object", dt == DT_MAP)); 827 assert (("first argument must be of type object", dt == DT_MAP));
751 map = va_arg (ap, mapstruct *); 828 map = va_arg (ap, mapstruct *);
752 829
753 if (map->cb) 830 if (map->cb)
754 gather_callbacks (callbacks, (AV *)map->cb, event); 831 gather_callbacks (callbacks, map->cb, event);
755 832
756 gather_callbacks (callbacks, cb_map, event); 833 gather_callbacks (callbacks, cb_map, event);
757 break; 834 break;
758 835
759 default: 836 default:
1211 1288
1212 const_iv (SK_EXP_ADD_SKILL) 1289 const_iv (SK_EXP_ADD_SKILL)
1213 const_iv (SK_EXP_TOTAL) 1290 const_iv (SK_EXP_TOTAL)
1214 const_iv (SK_EXP_NONE) 1291 const_iv (SK_EXP_NONE)
1215 const_iv (SK_SUBTRACT_SKILL_EXP) 1292 const_iv (SK_SUBTRACT_SKILL_EXP)
1293 const_iv (SK_EXP_SKILL_ONLY)
1216 1294
1217 const_iv (SK_LOCKPICKING) 1295 const_iv (SK_LOCKPICKING)
1218 const_iv (SK_HIDING) 1296 const_iv (SK_HIDING)
1219 const_iv (SK_SMITHERY) 1297 const_iv (SK_SMITHERY)
1220 const_iv (SK_BOWYER) 1298 const_iv (SK_BOWYER)
1379 prop (CFAPI_INT, MAP_PROP_WINDDIR) 1457 prop (CFAPI_INT, MAP_PROP_WINDDIR)
1380 prop (CFAPI_INT, MAP_PROP_SKY) 1458 prop (CFAPI_INT, MAP_PROP_SKY)
1381 prop (CFAPI_INT, MAP_PROP_WPARTX) 1459 prop (CFAPI_INT, MAP_PROP_WPARTX)
1382 prop (CFAPI_INT, MAP_PROP_WPARTY) 1460 prop (CFAPI_INT, MAP_PROP_WPARTY)
1383 prop (CFAPI_STRING, MAP_PROP_MESSAGE) 1461 prop (CFAPI_STRING, MAP_PROP_MESSAGE)
1384 prop (CFAPI_PMAP, MAP_PROP_NEXT)
1385 prop (CFAPI_PREGION, MAP_PROP_REGION) 1462 prop (CFAPI_PREGION, MAP_PROP_REGION)
1386 prop (CFAPI_POBJECT, OBJECT_PROP_OB_ABOVE)
1387 prop (CFAPI_POBJECT, OBJECT_PROP_OB_BELOW)
1388 prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) 1463 prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB)
1389 prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) 1464 prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB)
1390 prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) 1465 prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY)
1391 prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) 1466 prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT)
1392 prop (CFAPI_POBJECT, OBJECT_PROP_HEAD)
1393 prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) 1467 prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER)
1394 prop (CFAPI_PMAP, OBJECT_PROP_MAP) 1468 prop (CFAPI_PMAP, OBJECT_PROP_MAP)
1395 prop (CFAPI_INT, OBJECT_PROP_COUNT) 1469 prop (CFAPI_INT, OBJECT_PROP_COUNT)
1396 prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) 1470 prop (CFAPI_INT, OBJECT_PROP_REFCOUNT)
1397 prop (CFAPI_STRING, OBJECT_PROP_NAME) 1471 prop (CFAPI_STRING, OBJECT_PROP_NAME)
1577const char *cost_string_from_value(uint64 cost, int approx = 0) 1651const char *cost_string_from_value(uint64 cost, int approx = 0)
1578 1652
1579int invoke (int event, ...) 1653int invoke (int event, ...)
1580 CODE: 1654 CODE:
1581 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); 1655 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1582 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 1; i < items; i++) av_push (av, ST (i)); 1656 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1657 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1583 RETVAL = INVOKE_((event_type)event, ARG_AV (av)); 1658 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1584 OUTPUT: RETVAL 1659 OUTPUT: RETVAL
1585 1660
1586int 1661int
1587exp_to_level (val64 exp) 1662exp_to_level (val64 exp)
1620 RETVAL = newSVpv (resist_plus[atnr], 0); 1695 RETVAL = newSVpv (resist_plus[atnr], 0);
1621 else 1696 else
1622 XSRETURN_UNDEF; 1697 XSRETURN_UNDEF;
1623 OUTPUT: RETVAL 1698 OUTPUT: RETVAL
1624 1699
1700int
1701_valid (SV *obj)
1702 CODE:
1703 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1704 OUTPUT:
1705 RETVAL
1706
1625MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1707MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1626 1708
1627int invoke (object *op, int event, ...) 1709int invoke (object *op, int event, ...)
1628 CODE: 1710 CODE:
1629 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); 1711 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT");
1630 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); 1712 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1713 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1631 RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); 1714 RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av));
1632 OUTPUT: RETVAL 1715 OUTPUT: RETVAL
1633 1716
1634SV *registry (object *op) 1717SV *registry (object *op)
1635 CODE: 1718 CODE:
1636 RETVAL = registry_of (op); 1719 RETVAL = registry_of (op);
1637 OUTPUT: 1720 OUTPUT:
1721 RETVAL
1722
1723object *head (object *op)
1724 PROTOTYPE: $
1725 ALIAS:
1726 more = 1
1727 above = 2
1728 below = 3
1729 CODE:
1730 switch (ix)
1731 {
1732 case 0: RETVAL = op->head ? op->head : op; break; // DOH!
1733 case 1: RETVAL = op->more; break;
1734 case 2: RETVAL = op->above; break;
1735 case 3: RETVAL = op->below; break;
1736 }
1737 OUTPUT:
1638 RETVAL 1738 RETVAL
1639 1739
1640SV * 1740SV *
1641get_property (object *obj, int type, int idx) 1741get_property (object *obj, int type, int idx)
1642 CODE: 1742 CODE:
1722 1822
1723int need_identify (const object *obj); 1823int need_identify (const object *obj);
1724 1824
1725int apply_shop_mat (object *shop_mat, object *op); 1825int apply_shop_mat (object *shop_mat, object *op);
1726 1826
1727void cf_object_move (object *op, int dir, object *originator = op) 1827int move (object *op, int dir, object *originator = op)
1828 CODE:
1829 RETVAL = move_ob (op, dir, originator);
1830 OUTPUT:
1831 RETVAL
1728 1832
1729void cf_object_apply (object *op, object *author, int flags = 0) 1833void cf_object_apply (object *op, object *author, int flags = 0)
1730 1834
1731void cf_object_apply_below (object *op) 1835void cf_object_apply_below (object *op)
1732 1836
1773int cf_object_out_of_map (object *op, int x, int y) 1877int cf_object_out_of_map (object *op, int x, int y)
1774 1878
1775void cf_object_drop (object *op, object *author) 1879void cf_object_drop (object *op, object *author)
1776 1880
1777void cf_object_take (object *op, object *author) 1881void cf_object_take (object *op, object *author)
1778
1779void cf_object_say (object *op, char *msg)
1780
1781void cf_object_speak (object *op, char *msg)
1782 1882
1783object *cf_object_insert_object (object *op, object *container) 1883object *cf_object_insert_object (object *op, object *container)
1784 1884
1785const char *cf_object_get_msg (object *ob) 1885const char *cf_object_get_msg (object *ob)
1786 ALIAS: msg = 0 1886 ALIAS: msg = 0
1925MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2025MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1926 2026
1927int invoke (player *pl, int event, ...) 2027int invoke (player *pl, int event, ...)
1928 CODE: 2028 CODE:
1929 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); 2029 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
1930 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); 2030 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2031 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1931 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); 2032 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av));
1932 OUTPUT: RETVAL 2033 OUTPUT: RETVAL
1933 2034
1934SV *registry (player *pl) 2035SV *registry (player *pl)
1935 CODE: 2036 CODE:
2062 OUTPUT: RETVAL 2163 OUTPUT: RETVAL
2063 2164
2064 2165
2065MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2166MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2066 2167
2168mapstruct *first ()
2169 PROTOTYPE:
2170 CODE:
2171 RETVAL = first_map;
2172 OUTPUT: RETVAL
2173
2174mapstruct *next (mapstruct *map)
2175 PROTOTYPE:
2176 CODE:
2177 RETVAL = map->next;
2178 OUTPUT: RETVAL
2179
2067int invoke (mapstruct *map, int event, ...) 2180int invoke (mapstruct *map, int event, ...)
2068 CODE: 2181 CODE:
2069 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); 2182 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP");
2070 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); 2183 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2184 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2071 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); 2185 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av));
2072 OUTPUT: 2186 OUTPUT: RETVAL
2073 RETVAL
2074 2187
2075SV *registry (mapstruct *map) 2188SV *registry (mapstruct *map)
2076 CODE: 2189 CODE:
2077 RETVAL = registry_of (map); 2190 RETVAL = registry_of (map);
2078 OUTPUT: 2191 OUTPUT:
2098 2211
2099mapstruct *new (int width, int height) 2212mapstruct *new (int width, int height)
2100 PROTOTYPE: 2213 PROTOTYPE:
2101 CODE: 2214 CODE:
2102{ 2215{
2103 int unused_type; 2216 RETVAL = get_empty_map (width, height);
2104 RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height);
2105} 2217}
2106 OUTPUT: 2218 OUTPUT:
2107 RETVAL 2219 RETVAL
2108 2220
2109void delete_map (mapstruct *map) 2221void delete_map (mapstruct *map)
2124 XSRETURN_UNDEF; 2236 XSRETURN_UNDEF;
2125 RETVAL = map->tile_path [dir]; 2237 RETVAL = map->tile_path [dir];
2126 OUTPUT: 2238 OUTPUT:
2127 RETVAL 2239 RETVAL
2128 2240
2129mapstruct *cf_map_get_map (char *name) 2241mapstruct *ready_map_name (char *name, int flags = 0)
2130 PROTOTYPE: $ 2242 PROTOTYPE: $;$
2131 ALIAS: map = 0 2243 ALIAS:
2244 find = 0
2245 get_map = 1
2132 2246
2133mapstruct *has_been_loaded (char *name) 2247mapstruct *has_been_loaded (char *name)
2134 PROTOTYPE: $ 2248 PROTOTYPE: $
2135
2136mapstruct *cf_map_get_first ()
2137 PROTOTYPE:
2138 ALIAS: first = 0
2139 2249
2140# whoever "designed" the plug-in api should have wasted 2250# whoever "designed" the plug-in api should have wasted
2141# his/her time with staying away from the project - would have 2251# his/her time with staying away from the project - would have
2142# saved others a lot of time, without doubt. 2252# saved others a lot of time, without doubt.
2143void set_path (mapstruct *where, char *path) 2253void set_path (mapstruct *where, char *path)
2157 RETVAL 2267 RETVAL
2158 2268
2159void set_unique (mapstruct *map, bool unique) 2269void set_unique (mapstruct *map, bool unique)
2160 CODE: 2270 CODE:
2161 map->unique = unique; 2271 map->unique = unique;
2272
2273void
2274trigger (mapstruct *map, long connection, bool state = true)
2275 CODE:
2276 activate_connection (map, connection, state);
2277
2278void
2279get_connection (mapstruct *map, long connection)
2280 PPCODE:
2281 oblinkpt *obp = get_connection_links (map, connection);
2282 if (obp)
2283 for (objectlink *ol = obp->link; ol; ol = ol->next)
2284 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob)));
2162 2285
2163object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) 2286object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags)
2164 2287
2165object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 2288object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
2166 2289
2228 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2351 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
2229 } 2352 }
2230 OUTPUT: 2353 OUTPUT:
2231 RETVAL 2354 RETVAL
2232 2355
2233# "deserialise" perl map data into the map # TODO# compatibility cruft, remove
2234void
2235_set_obs (mapstruct *map, SV *sv)
2236 CODE:
2237{
2238 object *o;
2239 AV *av;
2240 int x, y;
2241 AV *obs = (AV *)SvRV (sv);
2242
2243 for (y = 0; y < MAP_HEIGHT (map); y++)
2244 for (x = 0; x < MAP_WIDTH (map); x++)
2245 {
2246 sv = *av_fetch (obs, x + y * MAP_HEIGHT (map), 1);
2247
2248 if (!SvROK (sv))
2249 continue;
2250
2251 av = (AV *)SvRV (sv);
2252
2253 for (o = GET_MAP_OB (map, x, y); o; o = o->above)
2254 {
2255 sv = av_shift (av);
2256
2257 if (SvROK (sv))
2258 {
2259 sv_magic ((SV *)SvRV (sv), 0, PERL_MAGIC_ext, (char *)o, 0);
2260 SVptr_cache_set (o, sv);
2261 }
2262 }
2263 }
2264}
2265
2266 2356
2267MODULE = cf PACKAGE = cf::arch 2357MODULE = cf PACKAGE = cf::arch
2358
2359archetype *find (const char *name)
2360 CODE:
2361 RETVAL = find_archetype (name);
2362 OUTPUT:
2363 RETVAL
2268 2364
2269archetype *first() 2365archetype *first()
2270 PROTOTYPE: 2366 PROTOTYPE:
2271 CODE: 2367 CODE:
2272 RETVAL = first_archetype; 2368 RETVAL = first_archetype;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines