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.216 by root, Mon May 28 21:28:36 2007 UTC vs.
Revision 1.241 by root, Sat Jul 28 12:02:58 2007 UTC

3 * 3 *
4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 it 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * 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, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * 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 along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include "autoconf.h" 24#include "autoconf.h"
75# define newSVval64 newSVnv 74# define newSVval64 newSVnv
76# define SvVAL64 SvNV 75# define SvVAL64 SvNV
77#endif 76#endif
78 77
79static f_plug_api gethook = cfapi_get_hooks; 78static f_plug_api gethook = cfapi_get_hooks;
80static f_plug_api object_set_property = cfapi_object_set_property;
81static f_plug_api object_insert = cfapi_object_insert; 79static f_plug_api object_insert = cfapi_object_insert;
82 80
83static PerlInterpreter *perl; 81static PerlInterpreter *perl;
84 82
85double runtime; 83tstamp NOW, runtime;
86 84
87global gbl_ev; 85global gbl_ev;
88static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 86static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
89static SV *sv_runtime, *sv_next_tick; 87static SV *sv_runtime, *sv_next_tick;
90 88
202 { 200 {
203 if (i >= mortals.size ()) 201 if (i >= mortals.size ())
204 { 202 {
205 i = 0; 203 i = 0;
206 204
207 if (mortals.size () > 1000) 205 if (mortals.size () >= 512)
206 {
207 static int last_mortalcount;
208 if (mortals.size () != last_mortalcount)
209 {
210 last_mortalcount = mortals.size ();
208 LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); 211 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ());
212
213 if (0)
214 {
215 for (int j = 0; j < mortals.size (); ++j)//D
216 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
217 fprintf (stderr, "\n");//D
218 }
219 }
220 }
209 221
210 break; 222 break;
211 } 223 }
212 224
213 attachable *obj = mortals [i]; 225 attachable *obj = mortals [i];
234 delete obj; 246 delete obj;
235 } 247 }
236 } 248 }
237} 249}
238 250
251void
252attachable::set_key (const char *key, const char *value)
253{
254 if (!self)
255 self = newHV ();
256
257 if (value)
258 hv_store (self, key, strlen (key), newSVpv (value, 0), 0);
259 else
260 hv_delete (self, key, strlen (key), G_DISCARD);
261}
262
239attachable & 263attachable &
240attachable::operator =(const attachable &src) 264attachable::operator =(const attachable &src)
241{ 265{
242 //if (self || cb) 266 //if (self || cb)
243 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); 267 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
244 268
245 attach = src.attach; 269 attach = src.attach;
246 return *this; 270 return *this;
271}
272
273template<typename T>
274static bool
275find_backref (void *ptr, T *obj)
276{
277 char *s = (char *)obj;
278 while (s < (char *)obj + sizeof (T))
279 {
280 if (ptr == *(void **)s)
281 return true;
282
283 s += sizeof (void *); // assume natural alignment
284 }
285
286 return false;
287}
288
289// for debugging, find "live" objects containing this ptr
290void
291find_backref (void *ptr)
292{
293 for_all_objects (op)
294 if (find_backref (ptr, op))
295 fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name);
296
297 for_all_players (pl)
298 if (find_backref (ptr, pl))
299 fprintf (stderr, "P %p\n", pl);
300
301 for_all_clients (ns)
302 if (find_backref (ptr, ns))
303 fprintf (stderr, "C %p\n", ns);
304
247} 305}
248 306
249////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 307//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
250 308
251static SV * 309static SV *
284{ 342{
285 if (!obj) 343 if (!obj)
286 return &PL_sv_undef; 344 return &PL_sv_undef;
287 345
288 if (!obj->self) 346 if (!obj->self)
347 obj->self = newHV ();
348
349 if (!SvOBJECT (obj->self))
289 { 350 {
290 obj->self = newHV ();
291 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 351 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
292 352
293 // now bless the object _once_ 353 // now bless the object _once_
354 //TODO: create a class registry with c++ type<=>perl name<=>stash and use it here and elsewhere
294 return sv_bless (newRV_inc ((SV *)obj->self), stash); 355 return sv_bless (newRV_inc ((SV *)obj->self), stash);
295 } 356 }
296 else 357 else
297 { 358 {
298 SV *sv = newRV_inc ((SV *)obj->self); 359 SV *sv = newRV_inc ((SV *)obj->self);
335 return SvPTR (sv, klass); 396 return SvPTR (sv, klass);
336 else 397 else
337 return 0; 398 return 0;
338} 399}
339 400
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
340inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; } 417inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; }
341inline SV *to_sv (const char * v) { return newSVpv (v, 0); } 418inline SV *to_sv (const char * v) { return newSVpv (v, 0); }
342inline SV *to_sv (bool v) { return newSViv (v); } 419inline SV *to_sv (bool v) { return newSViv (v); }
343inline SV *to_sv ( signed char v) { return newSViv (v); } 420inline SV *to_sv ( signed char v) { return newSViv (v); }
344inline SV *to_sv (unsigned char v) { return newSViv (v); } 421inline SV *to_sv (unsigned char v) { return newSViv (v); }
345inline SV *to_sv ( signed short v) { return newSViv (v); } 422inline SV *to_sv ( signed short v) { return newSViv (v); }
355inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 432inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
356inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 433inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
357inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 434inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
358inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 435inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
359inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 436inline 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); }
360inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 438inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
361inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); }
362inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 439inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
363 440
364inline SV *to_sv (object & v) { return to_sv (&v); } 441inline SV *to_sv (object & v) { return to_sv (&v); }
365inline SV *to_sv (living & v) { return to_sv (&v); } 442inline SV *to_sv (living & v) { return to_sv (&v); }
366 443
372 char buf[128]; 449 char buf[128];
373 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); 450 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
374 return newSVpv (buf, 0); 451 return newSVpv (buf, 0);
375} 452}
376 453
377inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 454inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; }
378inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 455inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
379inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 456inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
380inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 457inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
381inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 458inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
382inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 459inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
392inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 469inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
393inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 470inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
394inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 471inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
395inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 472inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
396inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 473inline 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"); }
397inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 475inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
398inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 476inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
399inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
400inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 477inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
401 478
402//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 479//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
403inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 480inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
404 481
887} 964}
888 965
889SV * 966SV *
890cfperl_result (int idx) 967cfperl_result (int idx)
891{ 968{
892 AV *av = get_av ("cfperl::invoke_results", 0); 969 AV *av = get_av ("cf::INVOKE_RESULTS", 0);
893 if (!av) 970 if (!av)
894 return &PL_sv_undef; 971 return &PL_sv_undef;
895 972
896 SV **sv = av_fetch (av, idx, 0); 973 SV **sv = av_fetch (av, idx, 0);
897 if (!sv) 974 if (!sv)
937 CALL_BEGIN (2); 1014 CALL_BEGIN (2);
938 CALL_ARG (book); 1015 CALL_ARG (book);
939 CALL_ARG (level); 1016 CALL_ARG (level);
940 CALL_CALL ("ext::books::make_book", G_VOID); 1017 CALL_CALL ("ext::books::make_book", G_VOID);
941 CALL_END; 1018 CALL_END;
1019}
1020
1021void
1022cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
1023{
1024 CALL_BEGIN (4);
1025 CALL_ARG (ns);
1026 CALL_ARG (type);
1027 CALL_ARG_SV (newSVpv_utf8 (msg));
1028 CALL_ARG (color);
1029 CALL_CALL ("cf::client::send_msg", G_VOID);
1030 CALL_END;
1031}
1032
1033int
1034cfperl_can_merge (object *ob1, object *ob2)
1035{
1036 int can;
1037
1038 CALL_BEGIN (2);
1039 CALL_ARG (ob1);
1040 CALL_ARG (ob2);
1041 CALL_CALL ("cf::_can_merge", G_SCALAR);
1042 can = count && SvTRUE (TOPs);
1043 CALL_END;
1044
1045 return can;
942} 1046}
943 1047
944maptile * 1048maptile *
945maptile::find_sync (const char *path, maptile *origin) 1049maptile::find_sync (const char *path, maptile *origin)
946{ 1050{
1032 1136
1033struct EventAPI *watcher_base::GEventAPI; 1137struct EventAPI *watcher_base::GEventAPI;
1034struct CoroAPI *coroapi::GCoroAPI; 1138struct CoroAPI *coroapi::GCoroAPI;
1035 1139
1036int coroapi::cede_counter; 1140int coroapi::cede_counter;
1037double (*coroapi::time)();
1038double coroapi::next_cede; 1141tstamp coroapi::next_cede;
1039 1142
1040void coroapi::do_cede_to_tick () 1143void coroapi::do_cede_to_tick ()
1041{ 1144{
1042 cede_counter = 0; 1145 cede_counter = 0;
1043 1146
1174 1277
1175 _connect_to_perl (); 1278 _connect_to_perl ();
1176 1279
1177 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1280 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1178 1281
1179 { 1282 //{
1180 require_pv ("Time::HiRes"); 1283 // require_pv ("Time::HiRes");
1181 1284 //
1182 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); 1285 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1183 if (!svp) croak ("Time::HiRes is required"); 1286 // if (!svp) croak ("Time::HiRes is required");
1184 if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); 1287 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1185 coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); 1288 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1186 } 1289 //}
1187 1290
1188 static const struct { 1291 static const struct {
1189 const char *name; 1292 const char *name;
1190 IV iv; 1293 IV iv;
1191 } *civ, const_iv[] = { 1294 } *civ, const_iv[] = {
1281 1384
1282 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) 1385 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED)
1283 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) 1386 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN)
1284 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD) 1387 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD)
1285 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE) 1388 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE)
1389 const_iv (NDI_ALL) const_iv (NDI_DEF) const_iv (NDI_REPLY) const_iv (NDI_CLIENT_MASK)
1286 const_iv (NDI_ALL) 1390 const_iv (NDI_NOCREATE)
1287 1391
1288 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1392 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1289 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1393 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1290 1394
1291 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1395 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1418 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1522 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1419 1523
1420 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) 1524 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1421 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) 1525 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1422 const_iv (GT_MINIMAL) 1526 const_iv (GT_MINIMAL)
1527
1528 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND)
1529 const_iv (FT_RSRC) const_iv (FT_NUM)
1423 }; 1530 };
1424 1531
1425 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1532 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1426 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1533 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1427 1534
1461 1568
1462 for_all_objects (op) 1569 for_all_objects (op)
1463 op->reattach (); 1570 op->reattach ();
1464} 1571}
1465 1572
1466void _post_tick ()
1467 CODE:
1468 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1469
1470# support function for map-world.ext 1573# support function for map-world.ext
1471void _quantise (SV *data_sv, SV *plt_sv) 1574void _quantise (SV *data_sv, SV *plt_sv)
1472 CODE: 1575 CODE:
1473{ 1576{
1474 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) 1577 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1506 len -= 3; 1609 len -= 3;
1507 } 1610 }
1508 1611
1509 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1612 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1510} 1613}
1614
1615void _post_tick ()
1616 CODE:
1617 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1618
1619NV till_cede ()
1620 CODE:
1621 RETVAL = coroapi::next_cede - now ();
1622 OUTPUT:
1623 RETVAL
1624
1625NV till_tick ()
1626 CODE:
1627 RETVAL = SvNV (sv_next_tick) - now ();
1628 OUTPUT:
1629 RETVAL
1511 1630
1512NV floor (NV x) 1631NV floor (NV x)
1513 1632
1514NV ceil (NV x) 1633NV ceil (NV x)
1515 1634
1541 CODE: 1660 CODE:
1542 coroapi::cede_to_tick (); 1661 coroapi::cede_to_tick ();
1543 1662
1544void server_tick () 1663void server_tick ()
1545 CODE: 1664 CODE:
1665 NOW = now ();
1546 runtime = SvNVx (sv_runtime); 1666 runtime = SvNVx (sv_runtime);
1547 server_tick (); 1667 server_tick ();
1548 1668
1549void 1669void
1550log_backtrace (utf8_string msg) 1670log_backtrace (utf8_string msg)
1557octet_string path_combine (octet_string base, octet_string path) 1677octet_string path_combine (octet_string base, octet_string path)
1558 PROTOTYPE: $$ 1678 PROTOTYPE: $$
1559 1679
1560octet_string path_combine_and_normalize (octet_string base, octet_string path) 1680octet_string path_combine_and_normalize (octet_string base, octet_string path)
1561 PROTOTYPE: $$ 1681 PROTOTYPE: $$
1562
1563const_octet_string
1564get_maps_directory (octet_string path)
1565 PROTOTYPE: $
1566 ALIAS: maps_directory = 0
1567 CODE:
1568 RETVAL = create_pathname (path);
1569 OUTPUT: RETVAL
1570 1682
1571void 1683void
1572sub_generation_inc () 1684sub_generation_inc ()
1573 CODE: 1685 CODE:
1574 PL_sub_generation++; 1686 PL_sub_generation++;
1767 PROTOTYPE: $ 1879 PROTOTYPE: $
1768 CODE: 1880 CODE:
1769 RETVAL = op->head_ (); 1881 RETVAL = op->head_ ();
1770 OUTPUT: RETVAL 1882 OUTPUT: RETVAL
1771 1883
1772int is_head (object *op)
1773 PROTOTYPE: $
1774 CODE:
1775 RETVAL = op->head_ () == op;
1776 OUTPUT: RETVAL
1777
1778void 1884void
1779inv (object *obj) 1885inv (object *obj)
1780 PROTOTYPE: $ 1886 PROTOTYPE: $
1781 PPCODE: 1887 PPCODE:
1782{ 1888{
1926 2032
1927void add_button_link (object *button, maptile *map, int connected); 2033void add_button_link (object *button, maptile *map, int connected);
1928 2034
1929void remove_button_link (object *op); 2035void remove_button_link (object *op);
1930 2036
2037void handle_apply_yield (object *op);
2038
1931 2039
1932MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2040MODULE = cf PACKAGE = cf::object PREFIX = cf_
1933 2041
1934object *cf_insert_ob_in_ob (object *ob, object *where) 2042object *cf_insert_ob_in_ob (object *ob, object *where)
1935 2043
1937# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2045# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1938 2046
1939object *new (utf8_string archetype = 0) 2047object *new (utf8_string archetype = 0)
1940 PROTOTYPE: ;$ 2048 PROTOTYPE: ;$
1941 CODE: 2049 CODE:
1942 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 2050 RETVAL = archetype ? get_archetype (archetype) : object::create ();
1943 OUTPUT: 2051 OUTPUT:
1944 RETVAL 2052 RETVAL
1945 2053
2054object *find_object (U32 tag)
2055
2056# TODO: nuke
1946object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2057object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1947 PROTOTYPE: $$$$$$ 2058 PROTOTYPE: $$$$$$
1948 CODE: 2059 CODE:
1949{ 2060{
1950 int unused_type; 2061 int unused_type;
1951 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 2062 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1952} 2063}
1953
1954player *contr (object *op)
1955 CODE:
1956 RETVAL = op->contr;
1957 OUTPUT: RETVAL
1958 2064
1959const_utf8_string get_ob_key_value (object *op, utf8_string key) 2065const_utf8_string get_ob_key_value (object *op, utf8_string key)
1960 2066
1961bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2067bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
1962 2068
2008void kill_player (object *op) 2114void kill_player (object *op)
2009 2115
2010void esrv_update_item (object *op, int what, object *item) 2116void esrv_update_item (object *op, int what, object *item)
2011 C_ARGS: what, op, item 2117 C_ARGS: what, op, item
2012 2118
2013void clear_los (object *op)
2014
2015int command_summon (object *op, utf8_string params) 2119int command_summon (object *op, utf8_string params)
2016 2120
2017int command_arrest (object *op, utf8_string params) 2121int command_arrest (object *op, utf8_string params)
2018 2122
2019 2123
2037 pl->ob->stats.hp = pl->ob->stats.maxhp; 2141 pl->ob->stats.hp = pl->ob->stats.maxhp;
2038 pl->ob->stats.sp = pl->ob->stats.maxsp; 2142 pl->ob->stats.sp = pl->ob->stats.maxsp;
2039 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2143 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2040 pl->orig_stats = pl->ob->stats; 2144 pl->orig_stats = pl->ob->stats;
2041 2145
2146void clear_los (player *pl)
2147
2042void cf_player_move (player *pl, int dir) 2148void cf_player_move (player *pl, int dir)
2043
2044void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2045 2149
2046bool 2150bool
2047cell_visible (player *pl, int dx, int dy) 2151cell_visible (player *pl, int dx, int dy)
2048 CODE: 2152 CODE:
2049 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2153 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2188 palette = SvRV (palette); 2292 palette = SvRV (palette);
2189 2293
2190 STRLEN idxlen; 2294 STRLEN idxlen;
2191 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2295 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2192 2296
2193 region **regionmap = (region **)malloc ( 2297 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2194 (av_len ((AV *)palette) + 1) * sizeof (region *));
2195 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2298 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2196 2299
2197 for (int i = av_len ((AV *)palette) + 1; i--; ) 2300 for (int i = av_len ((AV *)palette) + 1; i--; )
2198 regionmap [i] = region::find ( 2301 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2199 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2200 2302
2201 for (int y = 0; y < THIS->height; ++y) 2303 for (int y = 0; y < THIS->height; ++y)
2202 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2304 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2203 2305
2204 sfree (THIS->regions, THIS->size ()); 2306 sfree (THIS->regions, THIS->size ());
2205 free (THIS->regionmap); 2307 delete [] THIS->regionmap;
2206 2308
2207 THIS->regions = regions; 2309 THIS->regions = regions;
2208 THIS->regionmap = regionmap; 2310 THIS->regionmap = regionmap;
2209} 2311}
2210 2312
2230 } 2332 }
2231 } 2333 }
2232 2334
2233 op->destroy (); 2335 op->destroy ();
2234} 2336}
2235
2236void play_sound_map (maptile *map, int x, int y, int sound_num)
2237 2337
2238int out_of_map (maptile *map, int x, int y) 2338int out_of_map (maptile *map, int x, int y)
2239 2339
2240void 2340void
2241trigger (maptile *map, long connection, bool state = true) 2341trigger (maptile *map, long connection, bool state = true)
2417 CODE: 2517 CODE:
2418 RETVAL = archetype::find (name); 2518 RETVAL = archetype::find (name);
2419 OUTPUT: 2519 OUTPUT:
2420 RETVAL 2520 RETVAL
2421 2521
2422archetype *first() 2522int archetypes_size ()
2423 PROTOTYPE: 2523 CODE:
2424 CODE:
2425 RETVAL = first_archetype; 2524 RETVAL = archetypes.size ();
2426 OUTPUT: RETVAL 2525 OUTPUT: RETVAL
2526
2527archetype *archetypes (U32 index)
2528 CODE:
2529 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2530 OUTPUT: RETVAL
2427 2531
2428object *instantiate (archetype *arch) 2532object *instantiate (archetype *arch)
2429 CODE: 2533 CODE:
2430 RETVAL = arch_to_object (arch); 2534 RETVAL = arch_to_object (arch);
2431 OUTPUT: 2535 OUTPUT:
2508 STRLEN len; 2612 STRLEN len;
2509 char *buf = SvPVbyte (packet, len); 2613 char *buf = SvPVbyte (packet, len);
2510 2614
2511 THIS->send_packet (buf, len); 2615 THIS->send_packet (buf, len);
2512} 2616}
2617
2618faceidx
2619client::need_face (utf8_string name, int pri = 0)
2620 CODE:
2621 RETVAL = face_find (name, 0);
2622 if (RETVAL)
2623 {
2624 THIS->send_face (RETVAL, pri);
2625 THIS->flush_fx ();
2626 }
2627 OUTPUT:
2628 RETVAL
2629
2630int
2631client::fx_want (int idx, int value = -1)
2632 CODE:
2633 if (0 < idx && idx < FT_NUM)
2634 {
2635 RETVAL = THIS->fx_want [idx];
2636 if (items > 2)
2637 THIS->fx_want [idx] = value;
2638 }
2639 else
2640 RETVAL = 0;
2641 OUTPUT:
2642 RETVAL
2643
2644MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2645
2646faceidx sound_find (utf8_string name)
2647
2648void sound_set (utf8_string str, faceidx face)
2649
2650# dire hack
2651void old_sound_index (int idx, faceidx face)
2652 CODE:
2653 extern faceidx old_sound_index [SOUND_CAST_SPELL_0];
2654 old_sound_index [idx] = face;
2513 2655
2514MODULE = cf PACKAGE = cf::face PREFIX = face_ 2656MODULE = cf PACKAGE = cf::face PREFIX = face_
2515 2657
2516#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | 2658#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2517 2659
2533 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2675 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2534 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2676 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2535} 2677}
2536 OUTPUT: RETVAL 2678 OUTPUT: RETVAL
2537 2679
2538void set (faceidx idx, int visibility, int magicmap) 2680void set_type (faceidx idx, int value)
2539 CODE: 2681 ALIAS:
2540 faceinfo *f = face_info (idx); 2682 set_type = 0
2541 assert (f); 2683 set_visibility = 1
2542 f->visibility = visibility; 2684 set_magicmap = 2
2543 f->magicmap = magicmap; 2685 set_smooth = 3
2544 2686 set_smoothlevel = 4
2545void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2546 CODE: 2687 CODE:
2547 faceinfo *f = face_info (idx); assert (f); 2688 faceinfo *f = face_info (idx); assert (f);
2548 f->smooth = smooth; 2689 switch (ix)
2549 f->smoothlevel = smoothlevel; 2690 {
2691 case 0: f->type = value; break;
2692 case 1: f->visibility = value; break;
2693 case 2: f->magicmap = value; break;
2694 case 3: f->smooth = value; break;
2695 case 4: f->smoothlevel = value; break;
2696 }
2550 2697
2551void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2698void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2552 CODE: 2699 CODE:
2553{ 2700{
2554 facedata *d = face_data (idx, faceset); 2701 faceinfo *f = face_info (idx); assert (f);
2555 assert (d); 2702 facedata *d = &(faceset ? f->data64 : f->data32);
2556 sv_to (data, d->data); 2703 sv_to (data, d->data);
2557 STRLEN clen; 2704 STRLEN clen;
2558 char *cdata = SvPVbyte (chksum, clen); 2705 char *cdata = SvPVbyte (chksum, clen);
2559 clen = min (CHKSUM_SIZE, clen); 2706 clen = min (CHKSUM_SIZE, clen);
2560 2707
2570 ns->force_newmap = true; 2717 ns->force_newmap = true;
2571 } 2718 }
2572 } 2719 }
2573} 2720}
2574 2721
2722int get_data_size (faceidx idx, int faceset = 0)
2723 CODE:
2724 facedata *d = face_data (idx, faceset); assert (d);
2725 RETVAL = d->data.size ();
2726 OUTPUT:
2727 RETVAL
2728
2729SV *get_chksum (faceidx idx, int faceset = 0)
2730 CODE:
2731 facedata *d = face_data (idx, faceset); assert (d);
2732 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2733 OUTPUT:
2734 RETVAL
2735
2575void invalidate (faceidx idx) 2736void invalidate (faceidx idx)
2576 CODE: 2737 CODE:
2577 for_all_clients (ns) 2738 for_all_clients (ns)
2578 { 2739 {
2579 ns->faces_sent [idx] = false; 2740 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines