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.243 by root, Fri Aug 24 00:26:10 2007 UTC vs.
Revision 1.303 by root, Tue Sep 23 04:29:11 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include "autoconf.h" 24#include "autoconf.h"
25
26#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5"
28
29#define CEDES_PER_TICK 5
30 25
31#if HAVE_EXECINFO_H 26#if HAVE_EXECINFO_H
32# include <execinfo.h> 27# include <execinfo.h>
33#endif 28#endif
34 29
35#include <plugin_common.h>
36#include <sounds.h>
37#include <cstdarg> 30#include <cstdarg>
38#include <sproto.h> 31#include <typeinfo>
39 32
33#include "global.h"
40#include "loader.h" 34#include "loader.h"
35#include "../random_maps/random_map.h"
41#include "cfperl.h" 36#include "evthread.h"
42#include "shstr.h" 37#include "sproto.h"
43 38
44#include <unistd.h> 39#include <unistd.h>
45#if _POSIX_MEMLOCK 40#if _POSIX_MEMLOCK
46# include <sys/mman.h> 41# include <sys/mman.h>
47#endif 42#endif
48 43
44#if HAVE_MALLOC_H
45# include <malloc.h>
46#endif
47
48#if !__GLIBC__
49# define malloc_trim(pad) -1
50#endif
51
49#include <EXTERN.h> 52#include <EXTERN.h>
50#include <perl.h> 53#include <perl.h>
51#include <XSUB.h> 54#include <XSUB.h>
52 55
53#include "CoroAPI.h" 56#include "CoroAPI.h"
54#include "perlxsi.c" 57#include "perlxsi.c"
55 58
56extern sint64 *levels; // the experience table 59extern sint64 *levels; // the experience table
57 60
58typedef object object_ornull; 61typedef object_thawer &object_thawer_ref;
59typedef maptile maptile_ornull; 62typedef object_freezer &object_freezer_ref;
60
61typedef char *octet_string;
62typedef char *utf8_string;
63typedef const char *const_octet_string;
64typedef const char *const_utf8_string;
65 63
66typedef std::string std__string; 64typedef std::string std__string;
67 65
68#if IVSIZE >= 8
69 typedef IV val64;
70# define newSVval64 newSViv
71# define SvVAL64 SvIV
72#else
73 typedef double val64;
74# define newSVval64 newSVnv
75# define SvVAL64 SvNV
76#endif
77
78static f_plug_api gethook = cfapi_get_hooks;
79static f_plug_api object_insert = cfapi_object_insert;
80
81static PerlInterpreter *perl; 66static PerlInterpreter *perl;
82 67
83tstamp NOW, runtime; 68tstamp NOW, runtime;
69
70static int tick_inhibit;
71static int tick_pending;
84 72
85global gbl_ev; 73global gbl_ev;
86static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 74static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
87static SV *sv_runtime, *sv_next_tick; 75static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now;
88 76
89bitset<NUM_EVENT_TYPES> ev_want_event; 77bitset<NUM_EVENT_TYPES> ev_want_event;
90bitset<NUM_TYPES> ev_want_type; 78bitset<NUM_TYPES> ev_want_type;
91 79
92static HV 80static HV
93 *stash_cf, 81 *stash_cf,
94 *stash_cf_object_wrap, 82 *stash_cf_object_wrap,
95 *stash_cf_object_player_wrap, 83 *stash_cf_object_player_wrap,
96 *stash_cf_player_wrap, 84 *stash_cf_player_wrap,
97 *stash_cf_map_wrap, 85 *stash_cf_map_wrap,
86 *stash_cf_mapspace_wrap,
98 *stash_cf_client_wrap, 87 *stash_cf_client_wrap,
99 *stash_cf_arch_wrap, 88 *stash_cf_arch_wrap,
100 *stash_cf_party_wrap, 89 *stash_cf_party_wrap,
101 *stash_cf_region_wrap, 90 *stash_cf_region_wrap,
102 *stash_cf_living_wrap; 91 *stash_cf_living_wrap;
92
93static inline SV *
94newSVpv_utf8 (const char *s)
95{
96 if (!s)
97 return newSV (0);
98
99 SV *sv = newSVpv (s, 0);
100 SvUTF8_on (sv);
101 return sv;
102}
103
104static inline SV *
105newSVpvn_utf8 (const char *s, STRLEN l)
106{
107 if (!s)
108 return newSV (0);
109
110 SV *sv = newSVpvn (s, l);
111 SvUTF8_on (sv);
112 return sv;
113}
103 114
104// helper cast function, returns super class * or 0 115// helper cast function, returns super class * or 0
105template<class super> 116template<class super>
106static super * 117static super *
107is_a (attachable *at) 118is_a (attachable *at)
247 } 258 }
248 } 259 }
249} 260}
250 261
251void 262void
252attachable::set_key (const char *key, const char *value) 263attachable::set_key (const char *key, const char *value, bool is_utf8)
253{ 264{
254 if (!self) 265 if (!self)
255 self = newHV (); 266 self = newHV ();
256 267
257 if (value) 268 if (value)
258 hv_store (self, key, strlen (key), newSVpv (value, 0), 0); 269 hv_store (self, key, strlen (key), is_utf8 ? newSVpv_utf8 (value) : newSVpv (value, 0), 0);
259 else 270 else
260 hv_delete (self, key, strlen (key), G_DISCARD); 271 hv_delete (self, key, strlen (key), G_DISCARD);
261} 272}
262 273
263attachable & 274attachable &
310newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 321newSVptr (void *ptr, HV *stash, HV *hv = newHV ())
311{ 322{
312 SV *sv; 323 SV *sv;
313 324
314 if (!ptr) 325 if (!ptr)
315 return &PL_sv_undef; 326 return newSV (0);
316 327
317 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 328 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
318 return sv_bless (newRV_noinc ((SV *)hv), stash); 329 return sv_bless (newRV_noinc ((SV *)hv), stash);
319} 330}
320 331
339 350
340static SV * 351static SV *
341newSVattachable (attachable *obj, HV *stash) 352newSVattachable (attachable *obj, HV *stash)
342{ 353{
343 if (!obj) 354 if (!obj)
344 return &PL_sv_undef; 355 return newSV (0);
345 356
346 if (!obj->self) 357 if (!obj->self)
347 obj->self = newHV (); 358 obj->self = newHV ();
348 359
349 if (!SvOBJECT (obj->self)) 360 if (!SvOBJECT (obj->self))
396 return SvPTR (sv, klass); 407 return SvPTR (sv, klass);
397 else 408 else
398 return 0; 409 return 0;
399} 410}
400 411
401static inline SV *
402newSVpv_utf8 (const char *s)
403{
404 SV *sv = newSVpv (s, 0);
405 SvUTF8_on (sv);
406 return sv;
407}
408
409static inline SV *
410newSVpvn_utf8 (const char *s, STRLEN l)
411{
412 SV *sv = newSVpvn (s, l);
413 SvUTF8_on (sv);
414 return sv;
415}
416
417inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; } 412inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length ()); }
418inline SV *to_sv (const char * v) { return newSVpv (v, 0); } 413inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); }
419inline SV *to_sv (bool v) { return newSViv (v); } 414inline SV *to_sv (bool v) { return newSViv (v); }
420inline SV *to_sv ( signed char v) { return newSViv (v); } 415inline SV *to_sv ( signed char v) { return newSViv (v); }
421inline SV *to_sv (unsigned char v) { return newSViv (v); } 416inline SV *to_sv (unsigned char v) { return newSViv (v); }
422inline SV *to_sv ( signed short v) { return newSViv (v); } 417inline SV *to_sv ( signed short v) { return newSViv (v); }
423inline SV *to_sv (unsigned short v) { return newSVuv (v); } 418inline SV *to_sv (unsigned short v) { return newSVuv (v); }
435inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 430inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
436inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 431inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
437inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 432inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
438inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 433inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
439inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 434inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
435inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
440 436
441inline SV *to_sv (object & v) { return to_sv (&v); } 437inline SV *to_sv (object & v) { return to_sv (&v); }
442inline SV *to_sv (living & v) { return to_sv (&v); } 438inline SV *to_sv (living & v) { return to_sv (&v); }
443 439
444inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 440inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
445inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } 441inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); }
446 442
443inline SV *to_sv (UUID v) { return newSVpv (v.c_str (), 0); }
444
447inline SV *to_sv (UUID v) 445inline SV *to_sv (dynbuf * v)
448{ 446{
449 char buf[128]; 447 SV *sv = newSV (0);
450 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
451 return newSVpv (buf, 0);
452}
453 448
449 sv_upgrade (sv, SVt_PV);
450 SvGROW (sv, v->size () + 1);
451 SvPOK_only (sv);
452 v->linearise (SvPVX (sv));
453 SvCUR_set (sv, v->size ());
454 *SvEND (sv) = 0;
455
456 return sv;
457}
458
459inline SV *to_sv (dynbuf_text * v)
460{
461 SV *sv = to_sv (static_cast<dynbuf *> (v));
462 SvUTF8_on (sv);
463 return sv;
464}
465
454inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } 466inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; }
455inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 467inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
456inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 468inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
457inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 469inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
458inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 470inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
459inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 471inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
460inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } 472inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); }
461inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } 473inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); }
462inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } 474inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); }
463inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } 475inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); }
464inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 476inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
465inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 477inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
466inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 478inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
467inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 479inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
468inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 480inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
469inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 481inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
470inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 482inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
471inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 483inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
472inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 484inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
473inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 485inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
474inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } 486inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); }
475inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 487inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
476inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 488inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
477inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 489inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
490inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *)SvPTR_ornull (sv, "cf::mapspace"); }
491inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); }
492inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); }
478 493
479//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 494//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
480inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 495inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
481 496
482template<class T> 497template<class T>
483inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 498inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
484 499
485template<int N> 500template<int N>
486inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 501inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
487 502
488inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 503inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
489inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 504inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
490inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 505inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
491inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 506inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
492 507
493inline void sv_to (SV *sv, std::string &v) 508inline void sv_to (SV *sv, std::string &v)
494{ 509{
495 STRLEN len; 510 STRLEN len;
496 char *data = SvPVbyte (sv, len); 511 char *data = SvPVbyte (sv, len);
497 v.assign (data, len); 512 v.assign (data, len);
498} 513}
499 514
500inline void sv_to (SV *sv, UUID &v) 515inline void sv_to (SV *sv, UUID &v)
501{ 516{
502 unsigned int version; 517 if (!v.parse (SvPV_nolen (sv)))
503
504 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version)
505 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 518 croak ("unparsable uuid: %s", SvPV_nolen (sv));
506} 519}
507 520
508inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); } 521inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); }
509 522
527 break; 540 break;
528 541
529 case DT_STRING: 542 case DT_STRING:
530 { 543 {
531 char *str = (char *)va_arg (ap, const char *); 544 char *str = (char *)va_arg (ap, const char *);
532 sv = str ? newSVpv (str, 0) : &PL_sv_undef; 545 sv = str ? newSVpv (str, 0) : newSV (0);
533 } 546 }
534 break; 547 break;
535 548
536 case DT_DATA: 549 case DT_DATA:
537 { 550 {
538 char *str = (char *)va_arg (ap, const void *); 551 char *str = (char *)va_arg (ap, const void *);
539 int len = va_arg (ap, int); 552 int len = va_arg (ap, int);
540 sv = str ? newSVpv (str, len) : &PL_sv_undef; 553 sv = str ? newSVpv (str, len) : newSV (0);
541 } 554 }
542 break; 555 break;
543 556
544 case DT_OBJECT: 557 case DT_OBJECT:
545 sv = to_sv (va_arg (ap, object *)); 558 sv = to_sv (va_arg (ap, object *));
587 va_end (ap); 600 va_end (ap);
588 601
589 return sv; 602 return sv;
590} 603}
591 604
592static SV *
593newSVcfapi (int type, ...)
594{
595 SV *sv;
596
597 va_list ap;
598 va_start (ap, type);
599
600 switch (type)
601 {
602 case CFAPI_INT: sv = newSViv (*va_arg (ap, int * )); break;
603 case CFAPI_LONG: sv = newSVval64 (*va_arg (ap, sint64 *)); break;
604 case CFAPI_DOUBLE: sv = newSVnv (*va_arg (ap, double *)); break;
605 case CFAPI_STRING: sv = newSVdt_va (ap, DT_STRING); break;
606 case CFAPI_POBJECT: sv = newSVdt_va (ap, DT_OBJECT); break;
607 case CFAPI_PMAP: sv = newSVdt_va (ap, DT_MAP ); break;
608 case CFAPI_PPLAYER: sv = newSVdt_va (ap, DT_PLAYER); break;
609 case CFAPI_PARCH: sv = newSVdt_va (ap, DT_ARCH ); break;
610 case CFAPI_PPARTY: sv = newSVdt_va (ap, DT_PARTY ); break;
611 case CFAPI_PREGION: sv = newSVdt_va (ap, DT_REGION); break;
612
613 default:
614 assert (("unhandled type in newSVcfapi", 0));
615 }
616
617 va_end (ap);
618
619 return sv;
620}
621
622////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 605//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
623 606
624SV * 607SV *
625registry (attachable *ext) 608registry (attachable *ext)
626{ 609{
630 return newRV_inc ((SV *)ext->cb); 613 return newRV_inc ((SV *)ext->cb);
631} 614}
632 615
633///////////////////////////////////////////////////////////////////////////// 616/////////////////////////////////////////////////////////////////////////////
634 617
635extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
636{
637 return 0;
638}
639
640static CommArray_s rtn_cmd;
641
642static int
643runPluginCommand (object *obj, char *params)
644{
645 return -1;
646}
647
648extern "C" void *cfperl_getPluginProperty (int *type, ...)
649{
650 va_list args;
651 char *propname;
652 int i;
653 va_start (args, type);
654 propname = va_arg (args, char *);
655 //printf ("Property name: %s\n", propname);
656
657 if (!strcmp (propname, "command?"))
658 return NULL;
659 else if (!strcmp (propname, "Identification"))
660 {
661 va_end (args);
662 return (void *)PLUGIN_NAME;
663 }
664 else if (!strcmp (propname, "FullName"))
665 {
666 va_end (args);
667 return (void *)PLUGIN_VERSION;
668 }
669 else
670 va_end (args);
671
672 return NULL;
673}
674
675extern "C" int cfperl_postInitPlugin ()
676{
677 int hooktype = 1;
678 int rtype = 0;
679
680 cf_init_plugin (gethook);
681
682 return 0;
683}
684
685extern "C" int cfperl_closePlugin ()
686{
687 return 0;
688}
689
690void 618void
691cfperl_init () 619cfperl_init ()
692{ 620{
621 extern char **environ;
622
693 PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); 623 PERL_SYS_INIT3 (&settings.argc, &settings.argv, &environ);
694 perl = perl_alloc (); 624 perl = perl_alloc ();
695 perl_construct (perl); 625 perl_construct (perl);
696 626
697 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 627 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
698 628
699 const char *argv[] = { 629 const char *argv[] = {
700 settings.argv [0], 630 settings.argv [0],
701 "-e" 631 "-e"
702 "use Event; use Coro;" // required for bootstrap 632 "use EV ();"
703 "cf->bootstrap;" // required for datadir :*> 633 "use Coro ();"
634 "cf->bootstrap;"
704 "unshift @INC, cf::datadir ();" 635 "unshift @INC, cf::datadir ();"
705 "require cf;" 636 "require cf;"
706 }; 637 };
707 638
708 if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL) 639 if (perl_parse (perl, xs_init, 2, (char **)argv, environ)
709 || perl_run (perl)) 640 || perl_run (perl))
710 { 641 {
711 printf ("unable to initialize perl-interpreter, aborting.\n"); 642 printf ("unable to initialize perl-interpreter, aborting.\n");
712 exit (EXIT_FAILURE); 643 exit (EXIT_FAILURE);
713 } 644 }
714
715 {
716 dSP;
717
718 PUSHMARK (SP);
719 PUTBACK;
720 call_pv ("cf::init", G_DISCARD | G_VOID);
721 }
722} 645}
723 646
724void cfperl_main () 647void cfperl_main ()
725{ 648{
726 dSP; 649 dSP;
988{ 911{
989 return SvNV (cfperl_result (idx)); 912 return SvNV (cfperl_result (idx));
990} 913}
991 914
992///////////////////////////////////////////////////////////////////////////// 915/////////////////////////////////////////////////////////////////////////////
916// various c++ => perl glue functions
917
918void cfperl_tick ()
919{
920 tick_pending = 1;
921
922 if (tick_inhibit)
923 return;
924
925 tick_pending = 0;
926
927 dSP;
928
929 PUSHMARK (SP);
930 PUTBACK;
931 call_pv ("cf::tick", G_DISCARD | G_VOID);
932
933 SvNV_set (sv_next_tick, get_next_tick ()); SvNOK_only (sv_next_tick);
934}
993 935
994void 936void
995cfperl_emergency_save () 937cfperl_emergency_save ()
996{ 938{
997 CALL_BEGIN (0); 939 CALL_BEGIN (0);
1043 CALL_END; 985 CALL_END;
1044 986
1045 return can; 987 return can;
1046} 988}
1047 989
990player *
991player::find (const char *name)
992{
993 CALL_BEGIN (1);
994 CALL_ARG (name);
995 CALL_CALL ("cf::player::find", G_SCALAR);
996
997 player *retval = 0;
998 if (count) sv_to (POPs, retval);
999
1000 CALL_END;
1001
1002 return retval;
1003}
1004
1005maptile *
1006find_style (const char *dirname, const char *stylename, int difficulty)
1007{
1008 CALL_BEGIN (3);
1009 CALL_ARG (dirname);
1010 CALL_ARG (stylename);
1011 CALL_ARG (difficulty);
1012 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1013
1014 maptile *retval = 0;
1015 if (count) sv_to (POPs, retval);
1016
1017 CALL_END;
1018
1019 return retval;
1020}
1021
1048maptile * 1022maptile *
1049maptile::find_sync (const char *path, maptile *origin) 1023maptile::find_sync (const char *path, maptile *origin)
1050{ 1024{
1051 CALL_BEGIN (2); 1025 CALL_BEGIN (2);
1052 CALL_ARG (path); 1026 CALL_ARG (path);
1053 CALL_ARG (origin); 1027 CALL_ARG (origin);
1054 CALL_CALL ("cf::map::find_sync", G_SCALAR); 1028 CALL_CALL ("cf::map::find_sync", G_SCALAR);
1055 1029
1056 maptile *retval; 1030 maptile *retval = 0;
1057
1058 if (count)
1059 sv_to (POPs, retval); 1031 if (count) sv_to (POPs, retval);
1060 else
1061 retval = 0;
1062 1032
1063 CALL_END; 1033 CALL_END;
1064 1034
1065 return retval; 1035 return retval;
1066} 1036}
1072 CALL_ARG (path); 1042 CALL_ARG (path);
1073 CALL_ARG (origin); 1043 CALL_ARG (origin);
1074 CALL_ARG (load); 1044 CALL_ARG (load);
1075 CALL_CALL ("cf::map::find_async", G_SCALAR); 1045 CALL_CALL ("cf::map::find_async", G_SCALAR);
1076 1046
1077 maptile *retval; 1047 maptile *retval = 0;
1078
1079 if (count)
1080 sv_to (POPs, retval); 1048 if (count) sv_to (POPs, retval);
1081 else
1082 retval = 0;
1083 1049
1084 CALL_END; 1050 CALL_END;
1085 1051
1086 return retval; 1052 return retval;
1087} 1053}
1113 CALL_BEGIN (2); 1079 CALL_BEGIN (2);
1114 CALL_ARG (this); 1080 CALL_ARG (this);
1115 CALL_ARG (exit); 1081 CALL_ARG (exit);
1116 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1082 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
1117 CALL_END; 1083 CALL_END;
1084}
1085
1086void
1087object::player_goto (const char *path, int x, int y)
1088{
1089 if (type != PLAYER)
1090 return;
1091
1092 CALL_BEGIN (4);
1093 CALL_ARG (this);
1094 CALL_ARG (path);
1095 CALL_ARG (x);
1096 CALL_ARG (y);
1097 CALL_CALL ("cf::object::player::goto", G_VOID);
1098 CALL_END;
1099}
1100
1101const char *
1102object::ref () const
1103{
1104 if (type == PLAYER)
1105 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1106 else
1107 return 0;
1108}
1109
1110object *
1111object::deref (const char *ref)
1112{
1113 object *retval = 0;
1114
1115 if (ref)
1116 {
1117 CALL_BEGIN (1);
1118 CALL_ARG (ref);
1119 CALL_CALL ("cf::object::deref", G_SCALAR);
1120
1121 if (count)
1122 sv_to (POPs, retval);
1123
1124 CALL_END;
1125 }
1126
1127 return retval;
1118} 1128}
1119 1129
1120void 1130void
1121log_backtrace (const char *msg) 1131log_backtrace (const char *msg)
1122{ 1132{
1133#endif 1143#endif
1134} 1144}
1135 1145
1136///////////////////////////////////////////////////////////////////////////// 1146/////////////////////////////////////////////////////////////////////////////
1137 1147
1138struct EventAPI *watcher_base::GEventAPI; 1148struct EVAPI *evapi::GEVAPI;
1139struct CoroAPI *coroapi::GCoroAPI; 1149struct CoroAPI *coroapi::GCoroAPI;
1140
1141int coroapi::cede_counter;
1142tstamp coroapi::next_cede;
1143 1150
1144void coroapi::do_cede_to_tick () 1151void coroapi::do_cede_to_tick ()
1145{ 1152{
1146 cede_counter = 0; 1153 cede_pending = 0;
1147
1148 cede (); 1154 cede ();
1149
1150 next_cede += (TICK / CEDES_PER_TICK) * 0.99;
1151 if (next_cede > SvNV (sv_next_tick) - 0.02)
1152 next_cede = SvNV (sv_next_tick);
1153}
1154
1155void coroapi::do_cede_every ()
1156{
1157 cede_counter = 0;
1158
1159 if (coroapi::nready ())
1160 coroapi::cede ();
1161}
1162
1163void coroapi::do_cede_to_tick_every ()
1164{
1165 cede_counter = 0;
1166
1167 cede_to_tick ();
1168} 1155}
1169 1156
1170void 1157void
1171coroapi::wait_for_tick () 1158coroapi::wait_for_tick ()
1172{ 1159{
1181 CALL_BEGIN (0); 1168 CALL_BEGIN (0);
1182 CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); 1169 CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD);
1183 CALL_END; 1170 CALL_END;
1184} 1171}
1185 1172
1186static void
1187iw_dispatch (pe_event *ev)
1188{
1189 iw *w = (iw *)ev->ext_data;
1190 w->call (*w);
1191}
1192
1193void
1194iw::alloc ()
1195{
1196 pe = GEventAPI->new_idle (0, 0);
1197
1198 WaREENTRANT_off (pe);
1199 pe->base.callback = (void *)iw_dispatch;
1200 pe->base.ext_data = (void *)this;
1201}
1202
1203static void iow_dispatch (pe_event *ev)
1204{
1205 iow *w = (iow *)ev->ext_data;
1206 w->call (*w, ((pe_ioevent *)ev)->got);
1207}
1208
1209void
1210iow::alloc ()
1211{
1212 pe = GEventAPI->new_io (0, 0);
1213
1214 WaREENTRANT_off (pe);
1215 pe->base.callback = (void *)iow_dispatch;
1216 pe->base.ext_data = (void *)this;
1217
1218 pe->fd = -1;
1219 pe->poll = 0;
1220}
1221
1222void
1223iow::fd (int fd)
1224{
1225 pe->fd = fd;
1226}
1227
1228int
1229iow::poll ()
1230{
1231 return pe->poll;
1232}
1233
1234void 1173void
1235iow::poll (int events) 1174iow::poll (int events)
1236{ 1175{
1237 if (pe->poll != events) 1176 if (events != this->events)
1238 { 1177 {
1178 int active = ev_is_active ((ev_io *)this);
1239 if (pe->poll) stop (); 1179 if (active) stop ();
1240 pe->poll = events; 1180 ev_io_set ((ev_io *)this, fd, events);
1241 if (pe->poll) start (); 1181 if (active) start ();
1242 } 1182 }
1243} 1183}
1244 1184
1245void 1185void
1246_connect_to_perl () 1186_connect_to_perl ()
1247{ 1187{
1248 stash_cf = gv_stashpv ("cf" , 1); 1188 stash_cf = gv_stashpv ("cf", 1);
1249 1189
1250 stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); 1190 stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1);
1251 stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); 1191 stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1);
1252 stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); 1192 stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1);
1253 stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); 1193 stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1);
1194 stash_cf_mapspace_wrap = gv_stashpv ("cf::mapspace::wrap" , 1);
1254 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1195 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1255 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1196 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1256 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1197 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1257 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1198 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1258 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1199 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1259 1200
1201 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1260 sv_runtime = get_sv ("cf::RUNTIME" , 1); sv_upgrade (sv_runtime , SVt_NV); 1202 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1203 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1261 sv_next_tick = get_sv ("cf::NEXT_TICK", 1); sv_upgrade (sv_next_tick, SVt_NV); 1204 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1262 1205
1263 cb_global = get_av ("cf::CB_GLOBAL", 1); 1206 cb_global = get_av ("cf::CB_GLOBAL", 1);
1264 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1207 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1265 cb_object = get_av ("cf::CB_OBJECT", 1); 1208 cb_object = get_av ("cf::CB_OBJECT", 1);
1266 cb_player = get_av ("cf::CB_PLAYER", 1); 1209 cb_player = get_av ("cf::CB_PLAYER", 1);
1271 1214
1272MODULE = cf PACKAGE = cf PREFIX = cf_ 1215MODULE = cf PACKAGE = cf PREFIX = cf_
1273 1216
1274BOOT: 1217BOOT:
1275{ 1218{
1276 I_EVENT_API (PACKAGE); watcher_base::GEventAPI = GEventAPI; 1219 I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI;
1277 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1220 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1278 1221
1279 _connect_to_perl (); 1222 _connect_to_perl ();
1280 1223
1281 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1224 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1282 1225
1300 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1243 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1301 1244
1302 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1245 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1303 1246
1304 const_iv (MAX_TIME) 1247 const_iv (MAX_TIME)
1248 const_iv (MAXSOCKBUF)
1305 1249
1306 const_iv (NUM_BODY_LOCATIONS) 1250 const_iv (NUM_BODY_LOCATIONS)
1307 const_iv (body_range) const_iv (body_shield) const_iv (body_combat) 1251 const_iv (body_range) const_iv (body_shield) const_iv (body_combat)
1308 const_iv (body_arm) const_iv (body_torso) const_iv (body_head) 1252 const_iv (body_arm) const_iv (body_torso) const_iv (body_head)
1309 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger) 1253 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger)
1375 const_iv (FLAG_CURSED) const_iv (FLAG_DAMNED) const_iv (FLAG_SEE_ANYWHERE) const_iv (FLAG_KNOWN_MAGICAL) 1319 const_iv (FLAG_CURSED) const_iv (FLAG_DAMNED) const_iv (FLAG_SEE_ANYWHERE) const_iv (FLAG_KNOWN_MAGICAL)
1376 const_iv (FLAG_KNOWN_CURSED) const_iv (FLAG_CAN_USE_SKILL) const_iv (FLAG_BEEN_APPLIED) const_iv (FLAG_READY_SCROLL) 1320 const_iv (FLAG_KNOWN_CURSED) const_iv (FLAG_CAN_USE_SKILL) const_iv (FLAG_BEEN_APPLIED) const_iv (FLAG_READY_SCROLL)
1377 const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED) 1321 const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED)
1378 const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON) 1322 const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON)
1379 const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON) 1323 const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON)
1380 const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_CLIENT_SENT) const_iv (FLAG_BERSERK) 1324 const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_DEBUG) const_iv (FLAG_BERSERK)
1381 const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL) 1325 const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL)
1382 const_iv (FLAG_OBJ_SAVE_ON_OVL) const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER) 1326 const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER)
1383 const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE) 1327 const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE)
1384 const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE) 1328 const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE)
1385 1329
1386 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) 1330 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED)
1387 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) 1331 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN)
1388 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD) 1332 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD)
1389 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE) 1333 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE)
1390 const_iv (NDI_ALL) const_iv (NDI_DEF) const_iv (NDI_REPLY) const_iv (NDI_CLIENT_MASK) 1334 const_iv (NDI_ALL) const_iv (NDI_DEF) const_iv (NDI_REPLY) const_iv (NDI_CLIENT_MASK)
1391 const_iv (NDI_NOCREATE) 1335 const_iv (NDI_NOCREATE) const_iv (NDI_CLEAR) const_iv (NDI_VERBATIM)
1392 1336
1393 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1337 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1394 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1338 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1395 1339
1396 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1340 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1448 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) 1392 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK)
1449 const_iv (F_LOCKED) 1393 const_iv (F_LOCKED)
1450 1394
1451 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) 1395 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL)
1452 1396
1453 const_iv (P_BLOCKSVIEW) const_iv (P_PLAYER) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE) 1397 const_iv (P_BLOCKSVIEW) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE)
1454 const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) 1398 const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE)
1455 1399
1456 const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) 1400 const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE)
1457 1401
1458 const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) 1402 const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON)
1459 const_iv (INS_ON_TOP) const_iv (INS_BELOW_ORIGINATOR) const_iv (INS_MAP_LOAD) 1403 const_iv (INS_ON_TOP) const_iv (INS_BELOW_ORIGINATOR)
1460 1404
1461 const_iv (WILL_APPLY_HANDLE) const_iv (WILL_APPLY_TREASURE) const_iv (WILL_APPLY_EARTHWALL) 1405 const_iv (WILL_APPLY_HANDLE) const_iv (WILL_APPLY_TREASURE) const_iv (WILL_APPLY_EARTHWALL)
1462 const_iv (WILL_APPLY_DOOR) const_iv (WILL_APPLY_FOOD) 1406 const_iv (WILL_APPLY_DOOR) const_iv (WILL_APPLY_FOOD)
1463 1407
1464 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1408 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1498 const_iv (ATNR_PARALYZE) const_iv (ATNR_TURN_UNDEAD) const_iv (ATNR_FEAR) const_iv (ATNR_CANCELLATION) 1442 const_iv (ATNR_PARALYZE) const_iv (ATNR_TURN_UNDEAD) const_iv (ATNR_FEAR) const_iv (ATNR_CANCELLATION)
1499 const_iv (ATNR_DEPLETE) const_iv (ATNR_DEATH) const_iv (ATNR_CHAOS) const_iv (ATNR_COUNTERSPELL) 1443 const_iv (ATNR_DEPLETE) const_iv (ATNR_DEATH) const_iv (ATNR_CHAOS) const_iv (ATNR_COUNTERSPELL)
1500 const_iv (ATNR_GODPOWER) const_iv (ATNR_HOLYWORD) const_iv (ATNR_BLIND) const_iv (ATNR_INTERNAL) 1444 const_iv (ATNR_GODPOWER) const_iv (ATNR_HOLYWORD) const_iv (ATNR_BLIND) const_iv (ATNR_INTERNAL)
1501 const_iv (ATNR_LIFE_STEALING) const_iv (ATNR_DISEASE) 1445 const_iv (ATNR_LIFE_STEALING) const_iv (ATNR_DISEASE)
1502 1446
1503 const_iv (MAP_IN_MEMORY) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) 1447 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1448 const_iv (MAP_INACTIVE)
1504 1449
1505 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1450 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1506 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1451 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1452
1453 const_iv (VERSION_CS) const_iv (VERSION_SC)
1507 1454
1508 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1455 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1509 1456
1510 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) 1457 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM)
1511 1458
1521 1468
1522 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1469 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1523 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1470 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1524 1471
1525 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) 1472 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1526 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) 1473 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_MINIMAL)
1527 const_iv (GT_MINIMAL)
1528 1474
1529 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND) 1475 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND)
1530 const_iv (FT_RSRC) const_iv (FT_NUM) 1476 const_iv (FT_RSRC) const_iv (FT_NUM)
1531 }; 1477 };
1532 1478
1554 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1500 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1555 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); 1501 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv));
1556 } 1502 }
1557} 1503}
1558 1504
1505void _gv_clear (SV *gv)
1506 CODE:
1507 assert (SvTYPE (gv) == SVt_PVGV);
1508# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1509 f (GvGP (gv)->gp_form);
1510 f (GvGP (gv)->gp_io);
1511 f (GvGP (gv)->gp_sv);
1512 f (GvGP (gv)->gp_av);
1513 f (GvGP (gv)->gp_hv);
1514 f (GvGP (gv)->gp_cv);
1515 GvCVGEN (gv) = 0;
1516 GvMULTI_off (gv);
1517# undef f
1518
1559void _connect_to_perl () 1519void _connect_to_perl ()
1560 1520
1561void _recalc_want () 1521void _recalc_want ()
1562 1522
1563void _global_reattach () 1523void _global_reattach ()
1611 } 1571 }
1612 1572
1613 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1573 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1614} 1574}
1615 1575
1576void init_anim ()
1577
1578void init_globals ()
1579
1580void init_experience ()
1581
1582void init_attackmess ()
1583
1584void init_dynamic ()
1585
1586void init_block ()
1587
1588void load_settings ()
1589
1590void load_materials ()
1591
1592void init_uuid ()
1593 CODE:
1594 UUID::init ();
1595
1596void init_signals ()
1597
1598void init_commands ()
1599
1600void init_skills ()
1601
1602void init_beforeplay ()
1603
1604void evthread_start (int aiofd)
1605
1616void _post_tick () 1606void cede_to_tick ()
1617 CODE: 1607 CODE:
1618 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); 1608 coroapi::cede_to_tick ();
1619 1609
1620NV till_cede () 1610NV till_tick ()
1621 CODE: 1611 CODE:
1622 RETVAL = coroapi::next_cede - now (); 1612 RETVAL = SvNVX (sv_next_tick) - now ();
1623 OUTPUT: 1613 OUTPUT:
1624 RETVAL 1614 RETVAL
1625 1615
1626NV till_tick () 1616int tick_inhibit ()
1627 CODE: 1617 CODE:
1628 RETVAL = SvNV (sv_next_tick) - now (); 1618 RETVAL = tick_inhibit;
1629 OUTPUT: 1619 OUTPUT:
1630 RETVAL 1620 RETVAL
1631 1621
1622void tick_inhibit_inc ()
1623 CODE:
1624 ++tick_inhibit;
1625
1626void tick_inhibit_dec ()
1627 CODE:
1628 if (!--tick_inhibit)
1629 if (tick_pending)
1630 {
1631 ev_async_send (EV_DEFAULT, &tick_watcher);
1632 coroapi::cede ();
1633 }
1634
1635void server_tick ()
1636 CODE:
1637{
1638 NOW = ev_now (EV_DEFAULT);
1639 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1640 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1641 runtime = SvNVX (sv_runtime);
1642
1643 server_tick ();
1644
1645 NOW = ev_time ();
1646 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1647 runtime += TICK;
1648 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1649}
1650
1632NV floor (NV x) 1651NV floor (NV x)
1633 1652
1634NV ceil (NV x) 1653NV ceil (NV x)
1635 1654
1636NV rndm (...) 1655NV rndm (...)
1656 ALIAS:
1657 rmg_rndm = 1
1637 CODE: 1658 CODE:
1659{
1660 rand_gen &gen = ix ? rmg_rndm : rndm;
1638 switch (items) 1661 switch (items)
1639 { 1662 {
1640 case 0: RETVAL = rndm (); break; 1663 case 0: RETVAL = gen (); break;
1641 case 1: RETVAL = rndm (SvUV (ST (0))); break; 1664 case 1: RETVAL = gen (SvUV (ST (0))); break;
1642 case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break; 1665 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1643 default: croak ("cf::rndm requires none, one or two parameters."); break; 1666 default: croak ("cf::rndm requires none, one or two parameters."); break;
1644 } 1667 }
1668}
1645 OUTPUT: 1669 OUTPUT:
1646 RETVAL 1670 RETVAL
1647 1671
1648NV clamp (NV value, NV min_value, NV max_value) 1672NV clamp (NV value, NV min_value, NV max_value)
1649 CODE: 1673 CODE:
1655 CODE: 1679 CODE:
1656 RETVAL = lerp (value, min_in, max_in, min_out, max_out); 1680 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1657 OUTPUT: 1681 OUTPUT:
1658 RETVAL 1682 RETVAL
1659 1683
1660void cede_to_tick () 1684void weaken (...)
1661 CODE: 1685 PROTOTYPE: @
1662 coroapi::cede_to_tick (); 1686 CODE:
1663 1687 while (items > 0)
1664void server_tick () 1688 sv_rvweaken (ST (--items));
1665 CODE:
1666 NOW = now ();
1667 runtime = SvNVx (sv_runtime);
1668 server_tick ();
1669 1689
1670void 1690void
1671log_backtrace (utf8_string msg) 1691log_backtrace (utf8_string msg)
1672 1692
1673void 1693void
1712 1732
1713void abort () 1733void abort ()
1714 1734
1715void reset_signals () 1735void reset_signals ()
1716 1736
1717void fork_abort (octet_string cause = "cf::fork_abort") 1737void fork_abort (const_octet_string cause = "cf::fork_abort")
1718 1738
1719void cleanup (octet_string cause, bool make_core = false) 1739void cleanup (const_octet_string cause, bool make_core = false)
1720 1740
1721void emergency_save () 1741void emergency_save ()
1722 1742
1723void _exit (int status = EXIT_SUCCESS) 1743void _exit (int status = EXIT_SUCCESS)
1724 1744
1725UV sv_2watcher (SV *w)
1726 CODE:
1727 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1728 OUTPUT:
1729 RETVAL
1730
1731#if _POSIX_MEMLOCK 1745#if _POSIX_MEMLOCK
1732 1746
1733int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1747int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1748 INIT:
1749#if __GLIBC__
1750 mallopt (M_TOP_PAD, 1024 * 1024);
1751 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128);
1752 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1753 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1754#endif
1734 1755
1735int munlockall () 1756int munlockall ()
1736 1757
1737#endif 1758#endif
1759
1760int
1761malloc_trim (IV pad = 0)
1762
1763void
1764mallinfo ()
1765 PPCODE:
1766{
1767#if __GLIBC__
1768 struct mallinfo mai = mallinfo ();
1769 EXTEND (SP, 10*2);
1770 PUSHs (sv_2mortal (newSVpv ("arena" , 0))); PUSHs (sv_2mortal (newSViv (mai.arena)));
1771 PUSHs (sv_2mortal (newSVpv ("ordblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.ordblks)));
1772 PUSHs (sv_2mortal (newSVpv ("smblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.smblks)));
1773 PUSHs (sv_2mortal (newSVpv ("hblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblks)));
1774 PUSHs (sv_2mortal (newSVpv ("hblkhd" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblkhd)));
1775 PUSHs (sv_2mortal (newSVpv ("usmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.usmblks)));
1776 PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks)));
1777 PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks)));
1778 PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks)));
1779 PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost)));
1780#endif
1781 EXTEND (SP, 2*2);
1782 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1783 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1784 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1785}
1738 1786
1739int find_animation (utf8_string text) 1787int find_animation (utf8_string text)
1740 PROTOTYPE: $ 1788 PROTOTYPE: $
1741 1789
1742int random_roll (int min, int max, object *op, int goodbad); 1790int random_roll (int min, int max, object *op, int goodbad);
1780 RETVAL = newSVpv (resist_plus[atnr], 0); 1828 RETVAL = newSVpv (resist_plus[atnr], 0);
1781 else 1829 else
1782 XSRETURN_UNDEF; 1830 XSRETURN_UNDEF;
1783 OUTPUT: RETVAL 1831 OUTPUT: RETVAL
1784 1832
1833UUID
1834uuid_cur ()
1835 CODE:
1836 RETVAL = UUID::cur;
1837 OUTPUT:
1838 RETVAL
1839
1840UUID
1841uuid_gen ()
1842 CODE:
1843 RETVAL = UUID::gen ();
1844 OUTPUT:
1845 RETVAL
1846
1847val64
1848uuid_seq (UUID uuid)
1849 CODE:
1850 RETVAL = uuid.seq;
1851 OUTPUT:
1852 RETVAL
1853
1854UUID
1855uuid_str (val64 seq)
1856 CODE:
1857 RETVAL.seq = seq;
1858 OUTPUT:
1859 RETVAL
1860
1861void
1862coin_names ()
1863 PPCODE:
1864 EXTEND (SP, NUM_COINS);
1865 for (int i = 0; i < NUM_COINS; ++i)
1866 PUSHs (sv_2mortal (newSVpv (coins [i], 0)));
1867
1868void
1869coin_archetypes ()
1870 PPCODE:
1871 EXTEND (SP, NUM_COINS);
1872 for (int i = 0; i < NUM_COINS; ++i)
1873 PUSHs (sv_2mortal (to_sv (archetype::find (coins [i]))));
1874
1785bool 1875bool
1786load_resource_file (octet_string filename) 1876load_resource_file_ (octet_string filename)
1877
1878void
1879fix_weight ()
1787 1880
1788MODULE = cf PACKAGE = cf::attachable 1881MODULE = cf PACKAGE = cf::attachable
1789 1882
1790int 1883int
1791valid (SV *obj) 1884valid (SV *obj)
1855object *actives (U32 index) 1948object *actives (U32 index)
1856 CODE: 1949 CODE:
1857 RETVAL = index < actives.size () ? actives [index] : 0; 1950 RETVAL = index < actives.size () ? actives [index] : 0;
1858 OUTPUT: RETVAL 1951 OUTPUT: RETVAL
1859 1952
1953int mortals_size ()
1954 CODE:
1955 RETVAL = attachable::mortals.size ();
1956 OUTPUT: RETVAL
1957
1860const char *slot_use_name (U32 slot) 1958const char *slot_use_name (U32 slot)
1861 ALIAS: 1959 ALIAS:
1862 slot_nonuse_name = 1 1960 slot_nonuse_name = 1
1863 CODE: 1961 CODE:
1864{ 1962{
1885void 1983void
1886inv (object *obj) 1984inv (object *obj)
1887 PROTOTYPE: $ 1985 PROTOTYPE: $
1888 PPCODE: 1986 PPCODE:
1889{ 1987{
1890 object *o;
1891 for (o = obj->inv; o; o = o->below) 1988 for (object *o = obj->inv; o; o = o->below)
1892 XPUSHs (sv_2mortal (to_sv (o))); 1989 XPUSHs (sv_2mortal (to_sv (o)));
1893} 1990}
1894 1991
1895void 1992void
1896set_animation (object *op, int idx) 1993set_animation (object *op, int idx)
1928 2025
1929int need_identify (object *obj); 2026int need_identify (object *obj);
1930 2027
1931int apply_shop_mat (object *shop_mat, object *op); 2028int apply_shop_mat (object *shop_mat, object *op);
1932 2029
1933int move_player (object *op, int dir)
1934 CODE:
1935 RETVAL = move_player (op, dir);
1936 OUTPUT:
1937 RETVAL
1938
1939int move (object *op, int dir, object *originator = op) 2030int move (object *op, int dir, object *originator = op)
1940 CODE: 2031 CODE:
1941 RETVAL = move_ob (op, dir, originator); 2032 RETVAL = move_ob (op, dir, originator);
1942 OUTPUT: 2033 OUTPUT:
1943 RETVAL 2034 RETVAL
1950 CODE: 2041 CODE:
1951 player_apply_below (op); 2042 player_apply_below (op);
1952 2043
1953int cast_heal (object *op, object *caster, object *spell, int dir = 0) 2044int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1954 2045
1955object *cf_object_present_archname_inside (object *op, utf8_string whatstr)
1956
1957int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1958
1959int cf_object_change_map (object *op, int x, int y, maptile *map)
1960
1961#//TODO
1962object *clone_ (object *op, int recursive = 0)
1963 CODE:
1964 if (recursive)
1965 RETVAL = object_create_clone (op);
1966 else
1967 {
1968 RETVAL = object::create ();
1969 op->copy_to (RETVAL);
1970 }
1971 OUTPUT: RETVAL
1972
1973int pay_item (object *op, object *buyer) 2046int pay_item (object *op, object *buyer)
1974 CODE: 2047 CODE:
1975 RETVAL = pay_for_item (op, buyer); 2048 RETVAL = pay_for_item (op, buyer);
1976 OUTPUT: RETVAL 2049 OUTPUT: RETVAL
1977 2050
2011 2084
2012void drop (object *who, object *op) 2085void drop (object *who, object *op)
2013 2086
2014void pick_up (object *who, object *op) 2087void pick_up (object *who, object *op)
2015 2088
2016int cf_object_teleport (object *op, maptile *map, int x, int y)
2017
2018void update_object (object *op, int action) 2089void update_object (object *op, int action)
2019 2090
2020object *cf_create_object_by_name (utf8_string name)
2021
2022void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2091void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0)
2023 2092
2024void player_lvl_adj (object *who, object *skill = 0) 2093void player_lvl_adj (object *who, object *skill = 0)
2025 2094
2026int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2095int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2037 2106
2038void handle_apply_yield (object *op); 2107void handle_apply_yield (object *op);
2039 2108
2040 2109
2041MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2110MODULE = cf PACKAGE = cf::object PREFIX = cf_
2042
2043object *cf_insert_ob_in_ob (object *ob, object *where)
2044 2111
2045# no clean way to get an object from an archetype - stupid idiotic 2112# no clean way to get an object from an archetype - stupid idiotic
2046# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2113# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2047 2114
2048object *new (utf8_string archetype = 0) 2115object *new (utf8_string archetype = 0)
2057# TODO: nuke 2124# TODO: nuke
2058object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2125object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
2059 PROTOTYPE: $$$$$$ 2126 PROTOTYPE: $$$$$$
2060 CODE: 2127 CODE:
2061{ 2128{
2062 int unused_type; 2129 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2063 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
2064} 2130}
2065 2131
2066const_utf8_string get_ob_key_value (object *op, utf8_string key) 2132shstr
2133object::kv_get (shstr key)
2067 2134
2068bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2135void
2136object::kv_del (shstr key)
2137
2138void
2139object::kv_set (shstr key, shstr value)
2069 2140
2070object *get_nearest_player (object *ob) 2141object *get_nearest_player (object *ob)
2071 ALIAS: nearest_player = 0 2142 ALIAS: nearest_player = 0
2072 PREINIT: 2143 PREINIT:
2073 extern object *get_nearest_player (object *); 2144 extern object *get_nearest_player (object *);
2075void rangevector (object *ob, object *other, int flags = 0) 2146void rangevector (object *ob, object *other, int flags = 0)
2076 PROTOTYPE: $$;$ 2147 PROTOTYPE: $$;$
2077 PPCODE: 2148 PPCODE:
2078{ 2149{
2079 rv_vector rv; 2150 rv_vector rv;
2151
2152 PUTBACK;
2080 get_rangevector (ob, other, &rv, flags); 2153 get_rangevector (ob, other, &rv, flags);
2154 SPAGAIN;
2155
2081 EXTEND (SP, 5); 2156 EXTEND (SP, 5);
2082 PUSHs (newSVuv (rv.distance)); 2157 PUSHs (newSVuv (rv.distance));
2083 PUSHs (newSViv (rv.distance_x)); 2158 PUSHs (newSViv (rv.distance_x));
2084 PUSHs (newSViv (rv.distance_y)); 2159 PUSHs (newSViv (rv.distance_y));
2085 PUSHs (newSViv (rv.direction)); 2160 PUSHs (newSViv (rv.direction));
2086 PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); 2161 PUSHs (to_sv (rv.part));
2087} 2162}
2088 2163
2089bool on_same_map_as (object *ob, object *other) 2164bool on_same_map_as (object *ob, object *other)
2090 CODE: 2165 CODE:
2091 RETVAL = on_same_map (ob, other); 2166 RETVAL = on_same_map (ob, other);
2095base_name (object *op, int plural = op->nrof > 1) 2170base_name (object *op, int plural = op->nrof > 1)
2096 CODE: 2171 CODE:
2097 RETVAL = query_base_name (op, plural); 2172 RETVAL = query_base_name (op, plural);
2098 OUTPUT: RETVAL 2173 OUTPUT: RETVAL
2099 2174
2100object *decrease_ob_nr (object *op, unsigned long i) 2175# return the tail of an object, excluding itself
2176void
2177tail (object *op)
2178 PPCODE:
2179 while ((op = op->more))
2180 XPUSHs (sv_2mortal (to_sv (op)));
2101 2181
2102MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 2182MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
2103 2183
2104player *player (object *op) 2184player *player (object *op)
2105 CODE: 2185 CODE:
2106 RETVAL = op->contr; 2186 RETVAL = op->contr;
2107 OUTPUT: RETVAL 2187 OUTPUT: RETVAL
2108 2188
2189bool move_player (object *op, int dir)
2190
2109void check_score (object *op) 2191void check_score (object *op)
2110 2192
2111void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2193void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2112 CODE: 2194 CODE:
2113 new_draw_info (flags, 0, op, txt); 2195 new_draw_info (flags, 0, op, txt);
2114 2196
2115void kill_player (object *op) 2197void kill_player (object *op)
2116 2198
2199void esrv_send_item (object *pl, object *item)
2200
2117void esrv_update_item (object *op, int what, object *item) 2201void esrv_update_item (object *pl, int what, object *item)
2118 C_ARGS: what, op, item 2202 C_ARGS: what, pl, item
2203
2204void esrv_del_item (object *pl, int tag)
2205 C_ARGS: pl->contr, tag
2119 2206
2120int command_summon (object *op, utf8_string params) 2207int command_summon (object *op, utf8_string params)
2121 2208
2122int command_arrest (object *op, utf8_string params) 2209int command_arrest (object *op, utf8_string params)
2123 2210
2144 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2231 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2145 pl->orig_stats = pl->ob->stats; 2232 pl->orig_stats = pl->ob->stats;
2146 2233
2147void clear_los (player *pl) 2234void clear_los (player *pl)
2148 2235
2149void cf_player_move (player *pl, int dir)
2150
2151bool 2236bool
2152cell_visible (player *pl, int dx, int dy) 2237cell_visible (player *pl, int dx, int dy)
2153 CODE: 2238 CODE:
2154 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2239 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2155 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]; 2240 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2];
2161 CODE: 2246 CODE:
2162{ 2247{
2163 STRLEN len; 2248 STRLEN len;
2164 char *buf = SvPVbyte (packet, len); 2249 char *buf = SvPVbyte (packet, len);
2165 2250
2251 if (len > MAXSOCKBUF)
2252 pl->failmsg ("[packet too long for client]");
2166 if (pl->ns) 2253 else if (pl->ns)
2167 pl->ns->send_packet (buf, len); 2254 pl->ns->send_packet (buf, len);
2168} 2255}
2169
2170int
2171listening (player *pl, int new_value = -1)
2172 CODE:
2173 RETVAL = pl->listening;
2174 if (new_value >= 0)
2175 pl->listening = new_value;
2176 OUTPUT:
2177 RETVAL
2178 2256
2179void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) 2257void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0)
2180 PROTOTYPE: $;$$$ 2258 PROTOTYPE: $;$$$
2181 PPCODE: 2259 PPCODE:
2182 if (GIMME_V != G_VOID) 2260 if (GIMME_V != G_VOID)
2207 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); 2285 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END);
2208 OUTPUT: RETVAL 2286 OUTPUT: RETVAL
2209 2287
2210SV *registry (maptile *map) 2288SV *registry (maptile *map)
2211 2289
2290void
2291find_tagged_objects (maptile *map, utf8_string tag = 0)
2292 PPCODE:
2293{
2294 if (!map->spaces)
2295 XSRETURN_EMPTY;
2296
2297 if (tag)
2298 {
2299 shstr_cmp tag_ (tag);
2300
2301 for (mapspace *ms = map->spaces + map->size (); ms-- > map->spaces; )
2302 for (object *op = ms->bot; op; op = op->above)
2303 if (op->tag == tag_)
2304 XPUSHs (sv_2mortal (to_sv (op)));
2305 }
2306 else
2307 {
2308 for (mapspace *ms = map->spaces + map->size (); ms-- > map->spaces; )
2309 for (object *op = ms->bot; op; op = op->above)
2310 if (op->tag)
2311 XPUSHs (sv_2mortal (to_sv (op)));
2312 }
2313}
2314
2212INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | 2315INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h |
2213 2316
2214void 2317void
2215maptile::instantiate () 2318maptile::instantiate ()
2216 2319
2312} 2415}
2313 2416
2314void 2417void
2315maptile::create_region_treasure () 2418maptile::create_region_treasure ()
2316 CODE: 2419 CODE:
2317{
2318 object *op = object::create ();
2319 op->type = FLOOR;
2320 op->map = THIS;
2321
2322 for (int x = 0; x < THIS->width; ++x) 2420 for (int x = 0; x < THIS->width; ++x)
2323 for (int y = 0; y < THIS->height; ++y) 2421 for (int y = 0; y < THIS->height; ++y)
2324 { 2422 {
2325 region *rgn = THIS->region (x, y); 2423 region *rgn = THIS->region (x, y);
2326 2424
2327 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D 2425 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2426 if (object *op = THIS->at (x, y).top)
2328 if (rgn->treasure && rndm () < rgn->treasure_density) 2427 if (rgn->treasure && rndm () < rgn->treasure_density)
2329 {
2330 op->x = x;
2331 op->y = y;
2332 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2428 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2333 }
2334 } 2429 }
2335
2336 op->destroy ();
2337}
2338 2430
2339int out_of_map (maptile *map, int x, int y) 2431int out_of_map (maptile *map, int x, int y)
2340 2432
2341void 2433void
2342trigger (maptile *map, long connection, bool state = true) 2434trigger (maptile *map, long connection, bool state = true)
2347get_connection (maptile *map, long connection) 2439get_connection (maptile *map, long connection)
2348 PPCODE: 2440 PPCODE:
2349 oblinkpt *obp = get_connection_links (map, connection); 2441 oblinkpt *obp = get_connection_links (map, connection);
2350 if (obp) 2442 if (obp)
2351 for (objectlink *ol = obp->link; ol; ol = ol->next) 2443 for (objectlink *ol = obp->link; ol; ol = ol->next)
2352 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); 2444 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2353
2354object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags)
2355
2356object *cf_map_insert_object (maptile *where, object* op, int x, int y)
2357
2358object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2359 C_ARGS: str, map, nx, ny
2360 2445
2361void 2446void
2362get_map_flags (maptile *map, int x, int y) 2447get_map_flags (maptile *map, int x, int y)
2363 PPCODE: 2448 PPCODE:
2364{ 2449{
2365 maptile *nmap = 0; 2450 maptile *nmap = 0;
2366 I16 nx = 0, ny = 0; 2451 I16 nx = 0, ny = 0;
2452
2453 PUTBACK;
2367 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2454 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2455 SPAGAIN;
2368 2456
2369 EXTEND (SP, 4); 2457 EXTEND (SP, 4);
2370 PUSHs (sv_2mortal (newSViv (flags))); 2458 PUSHs (sv_2mortal (newSViv (flags)));
2371 2459
2372 if (GIMME_V == G_ARRAY) 2460 if (GIMME_V == G_ARRAY)
2373 { 2461 {
2374 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); 2462 PUSHs (sv_2mortal (to_sv (nmap)));
2375 PUSHs (sv_2mortal (newSViv (nx))); 2463 PUSHs (sv_2mortal (newSViv (nx)));
2376 PUSHs (sv_2mortal (newSViv (ny))); 2464 PUSHs (sv_2mortal (newSViv (ny)));
2377 } 2465 }
2378} 2466}
2379 2467
2468mapspace *
2469ms (maptile *map, unsigned int x, unsigned int y)
2470 PROTOTYPE: $$$
2471 CODE:
2472{
2473 maptile *nmap = 0;
2474 I16 nx, ny;
2475
2476 PUTBACK;
2477 get_map_flags (map, &nmap, x, y, &nx, &ny);
2478 SPAGAIN;
2479
2480 if (!nmap)
2481 XSRETURN_UNDEF;
2482
2483 RETVAL = &nmap->at (nx, ny);
2484}
2485 OUTPUT:
2486 RETVAL
2487
2380void 2488void
2381at (maptile *map, unsigned int x, unsigned int y) 2489at (maptile *map, unsigned int x, unsigned int y)
2382 PROTOTYPE: $$$ 2490 PROTOTYPE: $$$
2383 PPCODE: 2491 PPCODE:
2384{ 2492{
2385 object *o;
2386 maptile *nmap = 0; 2493 maptile *nmap = 0;
2387 I16 nx, ny; 2494 I16 nx, ny;
2388 2495
2496 PUTBACK;
2389 get_map_flags (map, &nmap, x, y, &nx, &ny); 2497 get_map_flags (map, &nmap, x, y, &nx, &ny);
2498 SPAGAIN;
2390 2499
2391 if (nmap) 2500 if (nmap)
2392 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) 2501 for (object *o = nmap->at (nx, ny).bot; o; o = o->above)
2393 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 2502 XPUSHs (sv_2mortal (to_sv (o)));
2394} 2503}
2395 2504
2396SV * 2505SV *
2397bot_at (maptile *obj, unsigned int x, unsigned int y) 2506bot_at (maptile *obj, unsigned int x, unsigned int y)
2398 PROTOTYPE: $$$ 2507 PROTOTYPE: $$$
2407 INIT: 2516 INIT:
2408 if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; 2517 if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF;
2409 CODE: 2518 CODE:
2410 switch (ix) 2519 switch (ix)
2411 { 2520 {
2412 case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; 2521 case 0: RETVAL = to_sv (GET_MAP_OB (obj, x, y)); break;
2413 case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; 2522 case 1: RETVAL = to_sv (GET_MAP_TOP (obj, x, y)); break;
2414 case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break; 2523 case 2: RETVAL = newSVuv (GET_MAP_FLAGS (obj, x, y)); break;
2415 case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break; 2524 case 3: RETVAL = newSViv (GET_MAP_LIGHT (obj, x, y)); break;
2416 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; 2525 case 4: RETVAL = newSVuv (GET_MAP_MOVE_BLOCK (obj, x, y)); break;
2417 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; 2526 case 5: RETVAL = newSVuv (GET_MAP_MOVE_SLOW (obj, x, y)); break;
2418 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; 2527 case 6: RETVAL = newSVuv (GET_MAP_MOVE_ON (obj, x, y)); break;
2419 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2528 case 7: RETVAL = newSVuv (GET_MAP_MOVE_OFF (obj, x, y)); break;
2420 } 2529 }
2421 OUTPUT: RETVAL 2530 OUTPUT: RETVAL
2422 2531
2423void fix_walls (maptile *map, int x, int y) 2532void fix_walls (maptile *map, int x, int y)
2424 2533
2510 RETVAL = self->generate_random_map (&rmp); 2619 RETVAL = self->generate_random_map (&rmp);
2511} 2620}
2512 OUTPUT: 2621 OUTPUT:
2513 RETVAL 2622 RETVAL
2514 2623
2624MODULE = cf PACKAGE = cf::mapspace
2625
2626INCLUDE: $PERL $srcdir/genacc mapspace ../include/map.h |
2627
2515MODULE = cf PACKAGE = cf::arch 2628MODULE = cf PACKAGE = cf::arch
2516
2517archetype *find (utf8_string name)
2518 CODE:
2519 RETVAL = archetype::find (name);
2520 OUTPUT:
2521 RETVAL
2522 2629
2523int archetypes_size () 2630int archetypes_size ()
2524 CODE: 2631 CODE:
2525 RETVAL = archetypes.size (); 2632 RETVAL = archetypes.size ();
2526 OUTPUT: RETVAL 2633 OUTPUT: RETVAL
2611 CODE: 2718 CODE:
2612{ 2719{
2613 STRLEN len; 2720 STRLEN len;
2614 char *buf = SvPVbyte (packet, len); 2721 char *buf = SvPVbyte (packet, len);
2615 2722
2723 if (len > MAXSOCKBUF)
2724 {
2725 // ugly
2726 if (THIS->pl)
2727 THIS->pl->failmsg ("[packet too long for client]");
2728 }
2729 else
2616 THIS->send_packet (buf, len); 2730 THIS->send_packet (buf, len);
2617} 2731}
2618 2732
2619faceidx 2733faceidx
2620client::need_face (utf8_string name, int pri = 0) 2734client::need_face (utf8_string name, int pri = 0)
2621 CODE: 2735 CODE:
2720 } 2834 }
2721} 2835}
2722 2836
2723int get_data_size (faceidx idx, int faceset = 0) 2837int get_data_size (faceidx idx, int faceset = 0)
2724 CODE: 2838 CODE:
2725 facedata *d = face_data (idx, faceset); assert (d); 2839 facedata *d = face_data (idx, faceset);
2840 if (!d) XSRETURN_UNDEF;
2726 RETVAL = d->data.size (); 2841 RETVAL = d->data.size ();
2727 OUTPUT: 2842 OUTPUT:
2728 RETVAL 2843 RETVAL
2729 2844
2730SV *get_chksum (faceidx idx, int faceset = 0) 2845SV *get_chksum (faceidx idx, int faceset = 0)
2731 CODE: 2846 CODE:
2732 facedata *d = face_data (idx, faceset); assert (d); 2847 facedata *d = face_data (idx, faceset);
2848 if (!d) XSRETURN_UNDEF;
2733 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); 2849 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2850 OUTPUT:
2851 RETVAL
2852
2853SV *get_data (faceidx idx, int faceset = 0)
2854 CODE:
2855 facedata *d = face_data (idx, faceset);
2856 if (!d) XSRETURN_UNDEF;
2857 RETVAL = newSVpvn (d->data.data (), d->data.length ());
2734 OUTPUT: 2858 OUTPUT:
2735 RETVAL 2859 RETVAL
2736 2860
2737void invalidate (faceidx idx) 2861void invalidate (faceidx idx)
2738 CODE: 2862 CODE:
2784void invalidate_all () 2908void invalidate_all ()
2785 CODE: 2909 CODE:
2786 for_all_clients (ns) 2910 for_all_clients (ns)
2787 ns->anims_sent.reset (); 2911 ns->anims_sent.reset ();
2788 2912
2913MODULE = cf PACKAGE = cf::object::freezer
2914
2915INCLUDE: $PERL $srcdir/genacc object_freezer ../include/cfperl.h |
2916
2917SV *
2918new (char *klass)
2919 CODE:
2920 RETVAL = newSVptr (new object_freezer, gv_stashpv ("cf::object::freezer", 1));
2921 OUTPUT: RETVAL
2922
2923void
2924DESTROY (SV *sv)
2925 CODE:
2926 object_freezer *self;
2927 sv_to (sv, self);
2928 delete self;
2929
2930MODULE = cf PACKAGE = cf::object::thawer
2931
2932INCLUDE: $PERL $srcdir/genacc object_thawer ../include/cfperl.h |
2933
2934SV *
2935new_from_file (char *klass, octet_string path)
2936 CODE:
2937 object_thawer *f = new object_thawer (path);
2938 if (!*f)
2939 {
2940 delete f;
2941 XSRETURN_UNDEF;
2942 }
2943 RETVAL = newSVptr (f, gv_stashpv ("cf::object::thawer", 1));
2944 OUTPUT: RETVAL
2945
2946void
2947DESTROY (SV *sv)
2948 CODE:
2949 object_thawer *self;
2950 sv_to (sv, self);
2951 delete self;
2952
2953void
2954extract_tags (object_thawer *self)
2955 PPCODE:
2956 while (self->kw != KW_EOF)
2957 {
2958 PUTBACK;
2959 coroapi::cede_to_tick ();
2960 SPAGAIN;
2961
2962 if (self->kw == KW_tag)
2963 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2964
2965 self->skip ();
2966 }
2967

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines