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.194 by root, Mon Apr 23 18:09:57 2007 UTC vs.
Revision 1.220 by root, Sat Jun 9 22:54:03 2007 UTC

1/*****************************************************************************/
2/* CrossFire, A Multiplayer game for the X Window System */
3/*****************************************************************************/
4
5/* 1/*
6 * This code is placed under the GNU General Public Licence (GPL) 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
7 * 3 *
4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
8 * Copyright (C) 2001-2005 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
9 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
10 * 7 *
11 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software; you can redistribute it and/or modify it
12 * it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
13 * the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
14 * (at your option) any later version. 11 * any later version.
15 * 12 *
16 * 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, but
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * GNU General Public License for more details. 16 * for more details.
20 * 17 *
21 * 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 along
22 * along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
24 */ 23 */
24
25#include "autoconf.h"
25 26
26#define PLUGIN_NAME "perl" 27#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 28#define PLUGIN_VERSION "cfperl 0.5"
28 29
29#define CEDES_PER_TICK 5 30#define CEDES_PER_TICK 5
31
32#if HAVE_EXECINFO_H
33# include <execinfo.h>
34#endif
30 35
31#include <plugin_common.h> 36#include <plugin_common.h>
32#include <sounds.h> 37#include <sounds.h>
33#include <cstdarg> 38#include <cstdarg>
34#include <sproto.h> 39#include <sproto.h>
70# define newSVval64 newSVnv 75# define newSVval64 newSVnv
71# define SvVAL64 SvNV 76# define SvVAL64 SvNV
72#endif 77#endif
73 78
74static f_plug_api gethook = cfapi_get_hooks; 79static f_plug_api gethook = cfapi_get_hooks;
75static f_plug_api object_set_property = cfapi_object_set_property;
76static f_plug_api object_insert = cfapi_object_insert; 80static f_plug_api object_insert = cfapi_object_insert;
77 81
78static PerlInterpreter *perl; 82static PerlInterpreter *perl;
79 83
80double runtime; 84tstamp NOW, runtime;
81 85
82global gbl_ev; 86global gbl_ev;
83static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 87static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
84static SV *sv_runtime, *sv_next_tick; 88static SV *sv_runtime, *sv_next_tick;
89
90bitset<NUM_EVENT_TYPES> ev_want_event;
91bitset<NUM_TYPES> ev_want_type;
85 92
86static HV 93static HV
87 *stash_cf, 94 *stash_cf,
88 *stash_cf_object_wrap, 95 *stash_cf_object_wrap,
89 *stash_cf_object_player_wrap, 96 *stash_cf_object_player_wrap,
111 118
112unordered_vector<attachable *> attachable::mortals; 119unordered_vector<attachable *> attachable::mortals;
113 120
114attachable::~attachable () 121attachable::~attachable ()
115{ 122{
116 flags |=0x3300;//D
117 assert (!self); 123 assert (!self);
118 assert (!cb); 124 assert (!cb);
119} 125}
120 126
121int 127int
137 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 143 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
138 SvREFCNT_dec (self); 144 SvREFCNT_dec (self);
139 145
140 // self *must* be null now because thats sv_unmagic's job. 146 // self *must* be null now because thats sv_unmagic's job.
141 assert (!this->self); 147 assert (!this->self);
142 flags |= 0x80; // severed //D
143 } 148 }
144} 149}
145 150
146void 151void
147attachable::optimise () 152attachable::optimise ()
148{ 153{
149 if (self 154 if (self
150 && SvREFCNT (self) == 1 155 && SvREFCNT (self) == 1
151 && !HvTOTALKEYS (self)) 156 && !HvTOTALKEYS (self))
152 flags |= 0x40,//D
153 sever_self (); 157 sever_self ();
154} 158}
155 159
156// check wether the object really is dead 160// check wether the object really is dead
157void 161void
164} 168}
165 169
166void 170void
167attachable::do_destroy () 171attachable::do_destroy ()
168{ 172{
169 invoke (EVENT_ATTACHABLE_DESTROY, DT_END); 173 INVOKE_ATTACHABLE (DESTROY, this);
170 174
171 if (cb) 175 if (cb)
172 { 176 {
173 SvREFCNT_dec (cb); 177 SvREFCNT_dec (cb);
174 cb = 0; 178 cb = 0;
175 } 179 }
176 180
177 if (self)
178 sever_self ();
179
180 flags |= 0x20; //D
181 mortals.push_back (this); 181 mortals.push_back (this);
182} 182}
183 183
184void 184void
185attachable::destroy () 185attachable::destroy ()
187 if (destroyed ()) 187 if (destroyed ())
188 return; 188 return;
189 189
190 flags |= F_DESTROYED; 190 flags |= F_DESTROYED;
191 do_destroy (); 191 do_destroy ();
192 sever_self ();
192} 193}
193 194
194void 195void
195attachable::check_mortals () 196attachable::check_mortals ()
196{ 197{
201 if (i >= mortals.size ()) 202 if (i >= mortals.size ())
202 { 203 {
203 i = 0; 204 i = 0;
204 205
205 if (mortals.size () > 1000) 206 if (mortals.size () > 1000)
206 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); 207 LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ());
207 208
208 break; 209 break;
209 } 210 }
210 211
211 attachable *obj = mortals [i]; 212 attachable *obj = mortals [i];
212 213
213 obj->refcnt_chk (); // unborrow from perl, if necessary 214#if 0
214 215 if (obj->self)//D make this an assert later
215 //if (obj->refcnt > 0 || obj->self)
216 if (obj->refcnt || obj->self)
217 { 216 {
218//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D 217 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
218 obj->sever_self ();
219 }
220#endif
221
222 if (obj->refcnt)
223 {
219 ++i; // further delay freeing 224 ++i; // further delay freeing
220 225
221 if (!(i & 0x3ff)) 226 if (!(i & 0x3ff))
222 break; 227 break;
223 } 228 }
224 else 229 else
225 { 230 {
226 mortals.erase (i); 231 mortals.erase (i);
232 obj->sever_self ();
227 delete obj; 233 delete obj;
228 } 234 }
229 } 235 }
230} 236}
231 237
280 286
281 if (!obj->self) 287 if (!obj->self)
282 { 288 {
283 obj->self = newHV (); 289 obj->self = newHV ();
284 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 290 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
285 obj->flags |= (obj->flags & 0xc0) << 8;
286 obj->flags &= ~0xc0;//D
287 obj->flags |= 0x10;//D
288 291
289 // now bless the object _once_ 292 // now bless the object _once_
290 return sv_bless (newRV_inc ((SV *)obj->self), stash); 293 return sv_bless (newRV_inc ((SV *)obj->self), stash);
291 } 294 }
292 else 295 else
402inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 405inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
403 406
404template<int N> 407template<int N>
405inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 408inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
406 409
407inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
408inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 410inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
409inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 411inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
410inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 412inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
411inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 413inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
412 414
615 perl_construct (perl); 617 perl_construct (perl);
616 618
617 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 619 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
618 620
619 const char *argv[] = { 621 const char *argv[] = {
620 "", 622 settings.argv [0],
621 "-e" 623 "-e"
622 "use Event; use Coro;" // required for bootstrap 624 "use Event; use Coro;" // required for bootstrap
623 "cf->bootstrap;" // required for datadir :*> 625 "cf->bootstrap;" // required for datadir :*>
624 "unshift @INC, cf::datadir ();" 626 "unshift @INC, cf::datadir ();"
625 "require cf;" 627 "require cf;"
653void 655void
654attachable::instantiate () 656attachable::instantiate ()
655{ 657{
656 if (attach) 658 if (attach)
657 { 659 {
658 invoke (EVENT_ATTACHABLE_INSTANTIATE, ARG_STRING (attach), DT_END); 660 INVOKE_ATTACHABLE (INSTANTIATE, this, ARG_STRING (attach));
659 attach = 0; 661 attach = 0;
660 } 662 }
661} 663}
662 664
663void 665void
664attachable::reattach () 666attachable::reattach ()
665{ 667{
666 optimise (); 668 optimise ();
667 //TODO: check for _attachment's, very important for restarts 669 //TODO: check for _attachment's, very important for restarts
668 invoke (EVENT_ATTACHABLE_REATTACH, DT_END); 670 INVOKE_ATTACHABLE (REATTACH, this);
669} 671}
670 672
671static event_klass klass_of[NUM_EVENT_TYPES] = { 673static event_klass klass_of[NUM_EVENT_TYPES] = {
672# define def(type,name) KLASS_ ## type, 674# define def(type,name) KLASS_ ## type,
673# include "eventinc.h" 675# include "eventinc.h"
716} 718}
717 719
718void 720void
719global::gather_callbacks (AV *&callbacks, event_type event) const 721global::gather_callbacks (AV *&callbacks, event_type event) const
720{ 722{
721 ::gather_callbacks (callbacks, cb_object, event); 723 ::gather_callbacks (callbacks, cb_global, event);
722} 724}
723 725
724void 726void
725object::gather_callbacks (AV *&callbacks, event_type event) const 727object::gather_callbacks (AV *&callbacks, event_type event) const
726{ 728{
727 if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) 729 if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type))
728 { 730 {
729 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES]; 731 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES];
730 732
731 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) 733 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV)
732 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); 734 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event);
733 } 735 }
734 736
770{ 772{
771 attachable::gather_callbacks (callbacks, event); 773 attachable::gather_callbacks (callbacks, event);
772 ::gather_callbacks (callbacks, cb_map, event); 774 ::gather_callbacks (callbacks, cb_map, event);
773} 775}
774 776
777void
778_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry)
779{
780 for (int event = 0; event <= AvFILLp (registry); ++event)
781 {
782 SV *cbs_ = AvARRAY (registry)[event];
783
784 // element must be list of callback entries
785 if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV)
786 {
787 AV *cbs = (AV *)SvRV (cbs_);
788
789 // no callback entries, no callbacks to call
790 if (AvFILLp (cbs) >= 0)
791 set.set (event);
792 }
793 }
794}
795
796// very slow and inefficient way to recalculate the global want bitsets
797void
798_recalc_want ()
799{
800 ev_want_event.reset ();
801
802 _recalc_want (ev_want_event, cb_global);
803 _recalc_want (ev_want_event, cb_attachable);
804 _recalc_want (ev_want_event, cb_object);
805 _recalc_want (ev_want_event, cb_client);
806 _recalc_want (ev_want_event, cb_player);
807 _recalc_want (ev_want_event, cb_map);
808
809 ev_want_type.reset ();
810
811 for (int type = 0; type <= AvFILLp (cb_type); ++type)
812 {
813 SV *cbs_ = AvARRAY (cb_type)[type];
814
815 // element must be list of callback entries
816 if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV)
817 {
818 AV *cbs = (AV *)SvRV (cbs_);
819
820 // no callback entries, no callbacks to call
821 if (AvFILLp (cbs) >= 0)
822 ev_want_type.set (type % NUM_TYPES);
823 }
824 }
825}
826
775bool 827bool
776attachable::invoke (event_type event, ...) 828attachable::invoke (event_type event, ...)
777{ 829{
778 data_type dt; 830 data_type dt;
779 va_list ap;
780
781 va_start (ap, event);
782 831
783 // callback call ordering should be: 832 // callback call ordering should be:
784 // 1. per-object callback 833 // 1. per-object callback
785 // 2. per-class object 834 // 2. per-class object
786 // 3. per-type callback 835 // 3. per-type callback
790 gather_callbacks (callbacks, event); 839 gather_callbacks (callbacks, event);
791 840
792 // short-circuit processing if no callbacks found/defined 841 // short-circuit processing if no callbacks found/defined
793 if (!callbacks) 842 if (!callbacks)
794 return 0; 843 return 0;
844
845 va_list ap;
846 va_start (ap, event);
795 847
796 CALL_BEGIN (3); 848 CALL_BEGIN (3);
797 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays 849 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays
798 CALL_ARG_SV (newRV_noinc ((SV *)callbacks)); 850 CALL_ARG_SV (newRV_noinc ((SV *)callbacks));
799 851
876 CALL_ARG (make_core); 928 CALL_ARG (make_core);
877 CALL_CALL ("cf::post_cleanup", G_VOID); 929 CALL_CALL ("cf::post_cleanup", G_VOID);
878 CALL_END; 930 CALL_END;
879} 931}
880 932
933void
934cfperl_make_book (object *book, int level)
935{
936 CALL_BEGIN (2);
937 CALL_ARG (book);
938 CALL_ARG (level);
939 CALL_CALL ("ext::books::make_book", G_VOID);
940 CALL_END;
941}
942
881maptile * 943maptile *
882maptile::find_sync (const char *path, maptile *origin) 944maptile::find_sync (const char *path, maptile *origin)
883{ 945{
884 CALL_BEGIN (2); 946 CALL_BEGIN (2);
885 CALL_ARG (path); 947 CALL_ARG (path);
947 CALL_ARG (exit); 1009 CALL_ARG (exit);
948 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1010 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
949 CALL_END; 1011 CALL_END;
950} 1012}
951 1013
1014void
1015log_backtrace (const char *msg)
1016{
1017#if HAVE_BACKTRACE
1018 void *addr [20];
1019 int size = backtrace (addr, 20);
1020
1021 CALL_BEGIN (size);
1022 CALL_ARG (msg);
1023 for (int i = 0; i < size; ++i)
1024 CALL_ARG ((IV)addr [i]);
1025 CALL_CALL ("cf::_log_backtrace", G_VOID);
1026 CALL_END;
1027#endif
1028}
1029
952///////////////////////////////////////////////////////////////////////////// 1030/////////////////////////////////////////////////////////////////////////////
953 1031
954struct EventAPI *watcher_base::GEventAPI; 1032struct EventAPI *watcher_base::GEventAPI;
955struct CoroAPI *coroapi::GCoroAPI; 1033struct CoroAPI *coroapi::GCoroAPI;
956 1034
957int coroapi::cede_counter; 1035int coroapi::cede_counter;
958double (*coroapi::time)();
959double coroapi::next_cede; 1036tstamp coroapi::next_cede;
960 1037
961void coroapi::do_cede_to_tick () 1038void coroapi::do_cede_to_tick ()
962{ 1039{
963 cede_counter = 0; 1040 cede_counter = 0;
964 1041
1095 1172
1096 _connect_to_perl (); 1173 _connect_to_perl ();
1097 1174
1098 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1175 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1099 1176
1100 { 1177 //{
1101 require_pv ("Time::HiRes"); 1178 // require_pv ("Time::HiRes");
1102 1179 //
1103 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); 1180 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1104 if (!svp) croak ("Time::HiRes is required"); 1181 // if (!svp) croak ("Time::HiRes is required");
1105 if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); 1182 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1106 coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); 1183 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1107 } 1184 //}
1108 1185
1109 static const struct { 1186 static const struct {
1110 const char *name; 1187 const char *name;
1111 IV iv; 1188 IV iv;
1112 } *civ, const_iv[] = { 1189 } *civ, const_iv[] = {
1113# define const_iv(name) { # name, (IV)name }, 1190# define const_iv(name) { # name, (IV)name },
1114 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1191 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1192 const_iv (logBacktrace)
1115 1193
1116 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1194 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1117 1195
1118 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1196 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1119 1197
1120 const_iv (MAX_TIME) 1198 const_iv (MAX_TIME)
1199
1200 const_iv (NUM_BODY_LOCATIONS)
1201 const_iv (body_range) const_iv (body_shield) const_iv (body_combat)
1202 const_iv (body_arm) const_iv (body_torso) const_iv (body_head)
1203 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger)
1204 const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand)
1205 const_iv (body_wrist) const_iv (body_waist)
1121 1206
1122 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) 1207 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE)
1123 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) 1208 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK)
1124 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) 1209 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON)
1125 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) 1210 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR)
1146 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) 1231 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL)
1147 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) 1232 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE)
1148 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) 1233 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE)
1149 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) 1234 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER)
1150 1235
1151 const_iv (NUM_SUBTYPES) 1236 const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES)
1152 1237
1153 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) 1238 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE)
1154 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) 1239 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM)
1155 1240
1156 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) 1241 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY)
1164 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) 1249 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE)
1165 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) 1250 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH)
1166 const_iv (WEAP_BLUD) 1251 const_iv (WEAP_BLUD)
1167 1252
1168 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) 1253 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED)
1169 const_iv (FLAG_WAS_WIZ) const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) 1254 const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD)
1170 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) 1255 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY)
1171 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) 1256 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD)
1172 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) 1257 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE)
1173 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) 1258 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING)
1174 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) 1259 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW)
1201 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1286 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1202 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1287 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1203 1288
1204 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1289 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1205 1290
1291 const_iv (SP_RAISE_DEAD)
1292 const_iv (SP_RUNE)
1293 const_iv (SP_MAKE_MARK)
1294 const_iv (SP_BOLT)
1295 const_iv (SP_BULLET)
1296 const_iv (SP_EXPLOSION)
1297 const_iv (SP_CONE)
1298 const_iv (SP_BOMB)
1299 const_iv (SP_WONDER)
1300 const_iv (SP_SMITE)
1301 const_iv (SP_MAGIC_MISSILE)
1302 const_iv (SP_SUMMON_GOLEM)
1303 const_iv (SP_DIMENSION_DOOR)
1304 const_iv (SP_MAGIC_MAPPING)
1305 const_iv (SP_MAGIC_WALL)
1306 const_iv (SP_DESTRUCTION)
1307 const_iv (SP_PERCEIVE_SELF)
1308 const_iv (SP_WORD_OF_RECALL)
1309 const_iv (SP_INVISIBLE)
1310 const_iv (SP_PROBE)
1311 const_iv (SP_HEALING)
1312 const_iv (SP_CREATE_FOOD)
1313 const_iv (SP_EARTH_TO_DUST)
1314 const_iv (SP_CHANGE_ABILITY)
1315 const_iv (SP_BLESS)
1316 const_iv (SP_CURSE)
1317 const_iv (SP_SUMMON_MONSTER)
1318 const_iv (SP_CHARGING)
1319 const_iv (SP_POLYMORPH)
1320 const_iv (SP_ALCHEMY)
1321 const_iv (SP_REMOVE_CURSE)
1322 const_iv (SP_IDENTIFY)
1323 const_iv (SP_DETECTION)
1324 const_iv (SP_MOOD_CHANGE)
1325 const_iv (SP_MOVING_BALL)
1326 const_iv (SP_SWARM)
1327 const_iv (SP_CHANGE_MANA)
1328 const_iv (SP_DISPEL_RUNE)
1329 const_iv (SP_CREATE_MISSILE)
1330 const_iv (SP_CONSECRATE)
1331 const_iv (SP_ANIMATE_WEAPON)
1332 const_iv (SP_LIGHT)
1333 const_iv (SP_CHANGE_MAP_LIGHT)
1334 const_iv (SP_FAERY_FIRE)
1335 const_iv (SP_CAUSE_DISEASE)
1336 const_iv (SP_AURA)
1337 const_iv (SP_TOWN_PORTAL)
1338 const_iv (SP_PARTY_SPELL)
1339
1206 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) 1340 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC)
1207 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) 1341 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK)
1208 const_iv (F_LOCKED) 1342 const_iv (F_LOCKED)
1209 1343
1210 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) 1344 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL)
1266 1400
1267 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1401 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1268 1402
1269 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) 1403 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM)
1270 1404
1271 const_iv (ST_CHANGE_CLASS)
1272
1273 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1405 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1274 1406
1275 // random map generator 1407 // random map generator
1276 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) 1408 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL)
1277 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) 1409 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL)
1280 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) 1412 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE)
1281 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) 1413 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS)
1282 1414
1283 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1415 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1284 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1416 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1417
1418 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1419 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1420 const_iv (GT_MINIMAL)
1285 }; 1421 };
1286 1422
1287 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1423 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1288 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1424 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1289 1425
1310 } 1446 }
1311} 1447}
1312 1448
1313void _connect_to_perl () 1449void _connect_to_perl ()
1314 1450
1451void _recalc_want ()
1452
1315void _global_reattach () 1453void _global_reattach ()
1316 CODE: 1454 CODE:
1317{ 1455{
1318 // reattach to all attachable objects in the game. 1456 // reattach to all attachable objects in the game.
1319 for_all_clients (ns) 1457 for_all_clients (ns)
1383 default: croak ("cf::rndm requires none, one or two parameters."); break; 1521 default: croak ("cf::rndm requires none, one or two parameters."); break;
1384 } 1522 }
1385 OUTPUT: 1523 OUTPUT:
1386 RETVAL 1524 RETVAL
1387 1525
1526NV clamp (NV value, NV min_value, NV max_value)
1527 CODE:
1528 RETVAL = clamp (value, min_value, max_value);
1529 OUTPUT:
1530 RETVAL
1531
1532NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1533 CODE:
1534 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1535 OUTPUT:
1536 RETVAL
1537
1538void cede_to_tick ()
1539 CODE:
1540 coroapi::cede_to_tick ();
1541
1388void server_tick () 1542void server_tick ()
1389 CODE: 1543 CODE:
1544 NOW = now ();
1390 runtime = SvNVx (sv_runtime); 1545 runtime = SvNVx (sv_runtime);
1391 server_tick (); 1546 server_tick ();
1392 1547
1393void 1548void
1549log_backtrace (utf8_string msg)
1550
1551void
1394LOG (int level, utf8_string msg) 1552LOG (int flags, utf8_string msg)
1395 PROTOTYPE: $$ 1553 PROTOTYPE: $$
1396 C_ARGS: (LogLevel)level, "%s", msg 1554 C_ARGS: flags, "%s", msg
1397 1555
1398octet_string path_combine (octet_string base, octet_string path) 1556octet_string path_combine (octet_string base, octet_string path)
1399 PROTOTYPE: $$ 1557 PROTOTYPE: $$
1400 1558
1401octet_string path_combine_and_normalize (octet_string base, octet_string path) 1559octet_string path_combine_and_normalize (octet_string base, octet_string path)
1438 } 1596 }
1439 OUTPUT: RETVAL 1597 OUTPUT: RETVAL
1440 1598
1441void abort () 1599void abort ()
1442 1600
1601void reset_signals ()
1602
1443void fork_abort (octet_string cause = "cf::fork_abort") 1603void fork_abort (octet_string cause = "cf::fork_abort")
1444 1604
1445void cleanup (octet_string cause, bool make_core = false) 1605void cleanup (octet_string cause, bool make_core = false)
1446 1606
1447void emergency_save () 1607void emergency_save ()
1581object *actives (U32 index) 1741object *actives (U32 index)
1582 CODE: 1742 CODE:
1583 RETVAL = index < actives.size () ? actives [index] : 0; 1743 RETVAL = index < actives.size () ? actives [index] : 0;
1584 OUTPUT: RETVAL 1744 OUTPUT: RETVAL
1585 1745
1746const char *slot_use_name (U32 slot)
1747 ALIAS:
1748 slot_nonuse_name = 1
1749 CODE:
1750{
1751 if (slot >= NUM_BODY_LOCATIONS)
1752 croak ("body slot index out of range");
1753
1754 switch (ix)
1755 {
1756 case 0: RETVAL = body_locations[slot].use_name; break;
1757 case 1: RETVAL = body_locations[slot].nonuse_name; break;
1758 }
1759}
1760 OUTPUT:
1761 RETVAL
1762
1586# missing properties 1763# missing properties
1587 1764
1588object *head (object *op) 1765object *head (object *op)
1589 PROTOTYPE: $ 1766 PROTOTYPE: $
1590 CODE: 1767 CODE:
1591 RETVAL = op->head_ (); 1768 RETVAL = op->head_ ();
1592 OUTPUT: RETVAL
1593
1594int is_head (object *op)
1595 PROTOTYPE: $
1596 CODE:
1597 RETVAL = op->head_ () == op;
1598 OUTPUT: RETVAL 1769 OUTPUT: RETVAL
1599 1770
1600void 1771void
1601inv (object *obj) 1772inv (object *obj)
1602 PROTOTYPE: $ 1773 PROTOTYPE: $
1615int 1786int
1616num_animations (object *op) 1787num_animations (object *op)
1617 CODE: 1788 CODE:
1618 RETVAL = NUM_ANIMATIONS (op); 1789 RETVAL = NUM_ANIMATIONS (op);
1619 OUTPUT: RETVAL 1790 OUTPUT: RETVAL
1791
1792int slot_info (object *op, UV slot, int value = 0)
1793 ALIAS:
1794 slot_used = 1
1795 CODE:
1796{
1797 if (slot >= NUM_BODY_LOCATIONS)
1798 croak ("body slot index out of range");
1799
1800 RETVAL = ix ? op->slot[slot].used : op->slot[slot].info;
1801
1802 if (items > 2)
1803 if (ix)
1804 op->slot[slot].used = value;
1805 else
1806 op->slot[slot].info = value;
1807}
1808 OUTPUT:
1809 RETVAL
1620 1810
1621object *find_best_object_match (object *op, utf8_string match) 1811object *find_best_object_match (object *op, utf8_string match)
1622 1812
1623object *find_marked_object (object *op) 1813object *find_marked_object (object *op)
1624 1814
1740# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1930# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1741 1931
1742object *new (utf8_string archetype = 0) 1932object *new (utf8_string archetype = 0)
1743 PROTOTYPE: ;$ 1933 PROTOTYPE: ;$
1744 CODE: 1934 CODE:
1745 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1935 RETVAL = archetype ? get_archetype (archetype) : object::create ();
1746 OUTPUT: 1936 OUTPUT:
1747 RETVAL 1937 RETVAL
1748 1938
1939# TODO: nuke
1749object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 1940object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1750 PROTOTYPE: $$$$$$ 1941 PROTOTYPE: $$$$$$
1751 CODE: 1942 CODE:
1752{ 1943{
1753 int unused_type; 1944 int unused_type;
1806 1997
1807void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 1998void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1808 CODE: 1999 CODE:
1809 new_draw_info (flags, 0, op, txt); 2000 new_draw_info (flags, 0, op, txt);
1810 2001
1811object *cf_player_send_inventory (object *op)
1812
1813octet_string cf_player_get_ip (object *op)
1814 ALIAS: ip = 0
1815
1816object *cf_player_get_marked_item (object *op)
1817 ALIAS: marked_item = 0
1818
1819void cf_player_set_marked_item (object *op, object *ob)
1820
1821partylist *cf_player_get_party (object *op)
1822 ALIAS: party = 0
1823
1824void cf_player_set_party (object *op, partylist *party)
1825
1826void kill_player (object *op) 2002void kill_player (object *op)
1827 2003
1828void esrv_update_item (object *op, int what, object *item) 2004void esrv_update_item (object *op, int what, object *item)
1829 C_ARGS: what, op, item 2005 C_ARGS: what, op, item
1830
1831void clear_los (object *op)
1832 2006
1833int command_summon (object *op, utf8_string params) 2007int command_summon (object *op, utf8_string params)
1834 2008
1835int command_arrest (object *op, utf8_string params) 2009int command_arrest (object *op, utf8_string params)
1836 2010
1854 CODE: 2028 CODE:
1855 pl->ob->stats.hp = pl->ob->stats.maxhp; 2029 pl->ob->stats.hp = pl->ob->stats.maxhp;
1856 pl->ob->stats.sp = pl->ob->stats.maxsp; 2030 pl->ob->stats.sp = pl->ob->stats.maxsp;
1857 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2031 pl->ob->stats.grace = pl->ob->stats.maxgrace;
1858 pl->orig_stats = pl->ob->stats; 2032 pl->orig_stats = pl->ob->stats;
2033
2034void clear_los (player *pl)
1859 2035
1860void cf_player_move (player *pl, int dir) 2036void cf_player_move (player *pl, int dir)
1861 2037
1862void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2038void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1863 2039
1973 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2149 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1974 { 2150 {
1975 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2151 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1976 ob->flag [FLAG_NO_MAP_SAVE] = true; 2152 ob->flag [FLAG_NO_MAP_SAVE] = true;
1977 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2153 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2154
2155 if (ob->randomitems)
2156 {
2157 if (!ob->above)
2158 {
2159 ob->create_treasure (ob->randomitems);
2160
2161 for (object *op = ob->above; op; op = op->above)
2162 op->flag [FLAG_NO_MAP_SAVE] = true;
2163 }
2164
2165 ob->randomitems = 0;
2166 }
1978 } 2167 }
1979 } 2168 }
1980 } 2169 }
1981 2170
1982 skip_space: ; 2171 skip_space: ;
2202 rmp.decoroptions = decoroptions; 2391 rmp.decoroptions = decoroptions;
2203 rmp.orientation = orientation; 2392 rmp.orientation = orientation;
2204 rmp.origin_y = origin_y; 2393 rmp.origin_y = origin_y;
2205 rmp.origin_x = origin_x; 2394 rmp.origin_x = origin_x;
2206 rmp.random_seed = random_seed; 2395 rmp.random_seed = random_seed;
2207 rmp.total_map_hp = total_map_hp; 2396 rmp.total_map_hp = (uint64_t) total_map_hp;
2208 rmp.map_layout_style = map_layout_style; 2397 rmp.map_layout_style = map_layout_style;
2209 rmp.treasureoptions = treasureoptions; 2398 rmp.treasureoptions = treasureoptions;
2210 rmp.symmetry_used = symmetry_used; 2399 rmp.symmetry_used = symmetry_used;
2211 rmp.region = region; 2400 rmp.region = region;
2212 rmp.custom = custom; 2401 rmp.custom = custom;
2222 CODE: 2411 CODE:
2223 RETVAL = archetype::find (name); 2412 RETVAL = archetype::find (name);
2224 OUTPUT: 2413 OUTPUT:
2225 RETVAL 2414 RETVAL
2226 2415
2227archetype *first() 2416int archetypes_size ()
2228 PROTOTYPE: 2417 CODE:
2229 CODE:
2230 RETVAL = first_archetype; 2418 RETVAL = archetypes.size ();
2419 OUTPUT: RETVAL
2420
2421archetype *archetypes (U32 index)
2422 CODE:
2423 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2424 OUTPUT: RETVAL
2425
2426object *instantiate (archetype *arch)
2427 CODE:
2428 RETVAL = arch_to_object (arch);
2429 OUTPUT:
2231 OUTPUT: RETVAL 2430 RETVAL
2232 2431
2233INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2432INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2234 2433
2235MODULE = cf PACKAGE = cf::party 2434MODULE = cf PACKAGE = cf::party
2236 2435

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines