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.219 by elmex, Thu Jun 7 19:03:25 2007 UTC vs.
Revision 1.227 by root, Tue Jul 10 16:24:00 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"
79static f_plug_api gethook = cfapi_get_hooks; 78static f_plug_api gethook = cfapi_get_hooks;
80static f_plug_api object_insert = cfapi_object_insert; 79static f_plug_api object_insert = cfapi_object_insert;
81 80
82static PerlInterpreter *perl; 81static PerlInterpreter *perl;
83 82
84double runtime; 83tstamp NOW, runtime;
85 84
86global gbl_ev; 85global gbl_ev;
87static 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;
88static SV *sv_runtime, *sv_next_tick; 87static SV *sv_runtime, *sv_next_tick;
89 88
201 { 200 {
202 if (i >= mortals.size ()) 201 if (i >= mortals.size ())
203 { 202 {
204 i = 0; 203 i = 0;
205 204
206 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 ();
207 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 }
208 221
209 break; 222 break;
210 } 223 }
211 224
212 attachable *obj = mortals [i]; 225 attachable *obj = mortals [i];
243 256
244 attach = src.attach; 257 attach = src.attach;
245 return *this; 258 return *this;
246} 259}
247 260
261template<typename T>
262static bool
263find_backref (void *ptr, T *obj)
264{
265 char *s = (char *)obj;
266 while (s < (char *)obj + sizeof (T))
267 {
268 if (ptr == *(void **)s)
269 return true;
270
271 s += sizeof (void *); // assume natural alignment
272 }
273
274 return false;
275}
276
277// for debugging, find "live" objects containing this ptr
278void
279find_backref (void *ptr)
280{
281 for_all_objects (op)
282 if (find_backref (ptr, op))
283 fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name);
284
285 for_all_players (pl)
286 if (find_backref (ptr, pl))
287 fprintf (stderr, "P %p\n", pl);
288
289 for_all_clients (ns)
290 if (find_backref (ptr, ns))
291 fprintf (stderr, "C %p\n", ns);
292
293}
294
248////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 295//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
249 296
250static SV * 297static SV *
251newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 298newSVptr (void *ptr, HV *stash, HV *hv = newHV ())
252{ 299{
334 return SvPTR (sv, klass); 381 return SvPTR (sv, klass);
335 else 382 else
336 return 0; 383 return 0;
337} 384}
338 385
386static inline SV *
387newSVpv_utf8 (const char *s)
388{
389 SV *sv = newSVpv (s, 0);
390 SvUTF8_on (sv);
391 return sv;
392}
393
394static inline SV *
395newSVpvn_utf8 (const char *s, STRLEN l)
396{
397 SV *sv = newSVpvn (s, l);
398 SvUTF8_on (sv);
399 return sv;
400}
401
339inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; } 402inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; }
340inline SV *to_sv (const char * v) { return newSVpv (v, 0); } 403inline SV *to_sv (const char * v) { return newSVpv (v, 0); }
341inline SV *to_sv (bool v) { return newSViv (v); } 404inline SV *to_sv (bool v) { return newSViv (v); }
342inline SV *to_sv ( signed char v) { return newSViv (v); } 405inline SV *to_sv ( signed char v) { return newSViv (v); }
343inline SV *to_sv (unsigned char v) { return newSViv (v); } 406inline SV *to_sv (unsigned char v) { return newSViv (v); }
344inline SV *to_sv ( signed short v) { return newSViv (v); } 407inline SV *to_sv ( signed short v) { return newSViv (v); }
371 char buf[128]; 434 char buf[128];
372 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); 435 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
373 return newSVpv (buf, 0); 436 return newSVpv (buf, 0);
374} 437}
375 438
376inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 439inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; }
377inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 440inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
378inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 441inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
379inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 442inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
380inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 443inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
381inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 444inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
938 CALL_ARG (level); 1001 CALL_ARG (level);
939 CALL_CALL ("ext::books::make_book", G_VOID); 1002 CALL_CALL ("ext::books::make_book", G_VOID);
940 CALL_END; 1003 CALL_END;
941} 1004}
942 1005
1006void
1007cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
1008{
1009 CALL_BEGIN (4);
1010 CALL_ARG (ns);
1011 CALL_ARG (color);
1012 CALL_ARG (type);
1013 CALL_ARG_SV (newSVpv_utf8 (msg));
1014 CALL_CALL ("cf::client::send_msg", G_VOID);
1015 CALL_END;
1016}
1017
943maptile * 1018maptile *
944maptile::find_sync (const char *path, maptile *origin) 1019maptile::find_sync (const char *path, maptile *origin)
945{ 1020{
946 CALL_BEGIN (2); 1021 CALL_BEGIN (2);
947 CALL_ARG (path); 1022 CALL_ARG (path);
1031 1106
1032struct EventAPI *watcher_base::GEventAPI; 1107struct EventAPI *watcher_base::GEventAPI;
1033struct CoroAPI *coroapi::GCoroAPI; 1108struct CoroAPI *coroapi::GCoroAPI;
1034 1109
1035int coroapi::cede_counter; 1110int coroapi::cede_counter;
1036double (*coroapi::time)();
1037double coroapi::next_cede; 1111tstamp coroapi::next_cede;
1038 1112
1039void coroapi::do_cede_to_tick () 1113void coroapi::do_cede_to_tick ()
1040{ 1114{
1041 cede_counter = 0; 1115 cede_counter = 0;
1042 1116
1173 1247
1174 _connect_to_perl (); 1248 _connect_to_perl ();
1175 1249
1176 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1250 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1177 1251
1178 { 1252 //{
1179 require_pv ("Time::HiRes"); 1253 // require_pv ("Time::HiRes");
1180 1254 //
1181 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); 1255 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1182 if (!svp) croak ("Time::HiRes is required"); 1256 // if (!svp) croak ("Time::HiRes is required");
1183 if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); 1257 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1184 coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); 1258 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1185 } 1259 //}
1186 1260
1187 static const struct { 1261 static const struct {
1188 const char *name; 1262 const char *name;
1189 IV iv; 1263 IV iv;
1190 } *civ, const_iv[] = { 1264 } *civ, const_iv[] = {
1540 CODE: 1614 CODE:
1541 coroapi::cede_to_tick (); 1615 coroapi::cede_to_tick ();
1542 1616
1543void server_tick () 1617void server_tick ()
1544 CODE: 1618 CODE:
1619 NOW = now ();
1545 runtime = SvNVx (sv_runtime); 1620 runtime = SvNVx (sv_runtime);
1546 server_tick (); 1621 server_tick ();
1547 1622
1548void 1623void
1549log_backtrace (utf8_string msg) 1624log_backtrace (utf8_string msg)
1934 CODE: 2009 CODE:
1935 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2010 RETVAL = archetype ? get_archetype (archetype) : object::create ();
1936 OUTPUT: 2011 OUTPUT:
1937 RETVAL 2012 RETVAL
1938 2013
2014object *find_object (U32 tag)
2015
1939# TODO: nuke 2016# TODO: nuke
1940object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2017object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1941 PROTOTYPE: $$$$$$ 2018 PROTOTYPE: $$$$$$
1942 CODE: 2019 CODE:
1943{ 2020{
1944 int unused_type; 2021 int unused_type;
1945 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 2022 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1946} 2023}
1947
1948player *contr (object *op)
1949 CODE:
1950 RETVAL = op->contr;
1951 OUTPUT: RETVAL
1952 2024
1953const_utf8_string get_ob_key_value (object *op, utf8_string key) 2025const_utf8_string get_ob_key_value (object *op, utf8_string key)
1954 2026
1955bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2027bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
1956 2028
2531 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2603 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2532 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2604 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2533} 2605}
2534 OUTPUT: RETVAL 2606 OUTPUT: RETVAL
2535 2607
2536void set (faceidx idx, int visibility, int magicmap) 2608void set_type (faceidx idx, int value)
2609 ALIAS:
2610 set_type = 0
2611 set_visibility = 1
2612 set_magicmap = 2
2613 set_smooth = 3
2614 set_smoothlevel = 4
2537 CODE: 2615 CODE:
2538 faceinfo *f = face_info (idx); 2616 faceinfo *f = face_info (idx);
2539 assert (f); 2617 assert (f);
2540 f->visibility = visibility; 2618 switch (ix)
2541 f->magicmap = magicmap; 2619 {
2542 2620 case 0: f->type = value; break;
2543void set_smooth (faceidx idx, faceidx smooth, int smoothlevel) 2621 case 1: f->visibility = value; break;
2544 CODE: 2622 case 2: f->magicmap = value; break;
2545 faceinfo *f = face_info (idx); assert (f); 2623 case 3: f->smooth = value; break;
2546 f->smooth = smooth; 2624 case 4: f->smoothlevel = value; break;
2547 f->smoothlevel = smoothlevel; 2625 }
2548 2626
2549void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2627void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2550 CODE: 2628 CODE:
2551{ 2629{
2552 facedata *d = face_data (idx, faceset); 2630 facedata *d = face_data (idx, faceset);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines