… | |
… | |
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 | |
79 | static f_plug_api gethook = cfapi_get_hooks; |
78 | static f_plug_api gethook = cfapi_get_hooks; |
80 | static f_plug_api object_set_property = cfapi_object_set_property; |
|
|
81 | static f_plug_api object_insert = cfapi_object_insert; |
79 | static f_plug_api object_insert = cfapi_object_insert; |
82 | |
80 | |
83 | static PerlInterpreter *perl; |
81 | static PerlInterpreter *perl; |
84 | |
82 | |
85 | double runtime; |
83 | tstamp NOW, runtime; |
86 | |
84 | |
87 | global gbl_ev; |
85 | global gbl_ev; |
88 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
86 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
89 | static SV *sv_runtime, *sv_next_tick; |
87 | static 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 | |
|
|
251 | void |
|
|
252 | attachable::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 | |
239 | attachable & |
263 | attachable & |
240 | attachable::operator =(const attachable &src) |
264 | attachable::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 | |
|
|
273 | template<typename T> |
|
|
274 | static bool |
|
|
275 | find_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 |
|
|
290 | void |
|
|
291 | find_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 | |
251 | static SV * |
309 | static 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 | |
|
|
401 | static inline SV * |
|
|
402 | newSVpv_utf8 (const char *s) |
|
|
403 | { |
|
|
404 | SV *sv = newSVpv (s, 0); |
|
|
405 | SvUTF8_on (sv); |
|
|
406 | return sv; |
|
|
407 | } |
|
|
408 | |
|
|
409 | static inline SV * |
|
|
410 | newSVpvn_utf8 (const char *s, STRLEN l) |
|
|
411 | { |
|
|
412 | SV *sv = newSVpvn (s, l); |
|
|
413 | SvUTF8_on (sv); |
|
|
414 | return sv; |
|
|
415 | } |
|
|
416 | |
340 | inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; } |
417 | inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; } |
341 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
418 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
342 | inline SV *to_sv (bool v) { return newSViv (v); } |
419 | inline SV *to_sv (bool v) { return newSViv (v); } |
343 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
420 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
344 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
421 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
345 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
422 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
… | |
… | |
355 | inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
432 | inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
356 | inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
433 | inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
357 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
434 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
358 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
435 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
359 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
436 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
|
|
437 | inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
360 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
438 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
361 | inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); } |
|
|
362 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
439 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
363 | |
440 | |
364 | inline SV *to_sv (object & v) { return to_sv (&v); } |
441 | inline SV *to_sv (object & v) { return to_sv (&v); } |
365 | inline SV *to_sv (living & v) { return to_sv (&v); } |
442 | inline 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 | |
377 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
454 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } |
378 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
455 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
379 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
456 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
380 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
457 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
381 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
458 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
382 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
459 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
… | |
… | |
392 | inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
469 | inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
393 | inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
470 | inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
394 | inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
471 | inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
395 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
472 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
396 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
473 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
|
|
474 | inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } |
397 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
475 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
398 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
476 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
399 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
|
|
400 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
477 | inline 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)]; } |
403 | inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
480 | inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
404 | |
481 | |
… | |
… | |
887 | } |
964 | } |
888 | |
965 | |
889 | SV * |
966 | SV * |
890 | cfperl_result (int idx) |
967 | cfperl_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 | |
|
|
1021 | void |
|
|
1022 | cfperl_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 | |
|
|
1033 | int |
|
|
1034 | cfperl_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 | |
944 | maptile * |
1048 | maptile * |
945 | maptile::find_sync (const char *path, maptile *origin) |
1049 | maptile::find_sync (const char *path, maptile *origin) |
946 | { |
1050 | { |
… | |
… | |
1032 | |
1136 | |
1033 | struct EventAPI *watcher_base::GEventAPI; |
1137 | struct EventAPI *watcher_base::GEventAPI; |
1034 | struct CoroAPI *coroapi::GCoroAPI; |
1138 | struct CoroAPI *coroapi::GCoroAPI; |
1035 | |
1139 | |
1036 | int coroapi::cede_counter; |
1140 | int coroapi::cede_counter; |
1037 | double (*coroapi::time)(); |
|
|
1038 | double coroapi::next_cede; |
1141 | tstamp coroapi::next_cede; |
1039 | |
1142 | |
1040 | void coroapi::do_cede_to_tick () |
1143 | void 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[] = { |
… | |
… | |
1461 | |
1564 | |
1462 | for_all_objects (op) |
1565 | for_all_objects (op) |
1463 | op->reattach (); |
1566 | op->reattach (); |
1464 | } |
1567 | } |
1465 | |
1568 | |
1466 | void _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 |
1569 | # support function for map-world.ext |
1471 | void _quantise (SV *data_sv, SV *plt_sv) |
1570 | void _quantise (SV *data_sv, SV *plt_sv) |
1472 | CODE: |
1571 | CODE: |
1473 | { |
1572 | { |
1474 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
1573 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
… | |
… | |
1506 | len -= 3; |
1605 | len -= 3; |
1507 | } |
1606 | } |
1508 | |
1607 | |
1509 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
1608 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
1510 | } |
1609 | } |
|
|
1610 | |
|
|
1611 | void _post_tick () |
|
|
1612 | CODE: |
|
|
1613 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
|
|
1614 | |
|
|
1615 | NV till_cede () |
|
|
1616 | CODE: |
|
|
1617 | RETVAL = coroapi::next_cede - now (); |
|
|
1618 | OUTPUT: |
|
|
1619 | RETVAL |
|
|
1620 | |
|
|
1621 | NV till_tick () |
|
|
1622 | CODE: |
|
|
1623 | RETVAL = SvNV (sv_next_tick) - now (); |
|
|
1624 | OUTPUT: |
|
|
1625 | RETVAL |
1511 | |
1626 | |
1512 | NV floor (NV x) |
1627 | NV floor (NV x) |
1513 | |
1628 | |
1514 | NV ceil (NV x) |
1629 | NV ceil (NV x) |
1515 | |
1630 | |
… | |
… | |
1541 | CODE: |
1656 | CODE: |
1542 | coroapi::cede_to_tick (); |
1657 | coroapi::cede_to_tick (); |
1543 | |
1658 | |
1544 | void server_tick () |
1659 | void server_tick () |
1545 | CODE: |
1660 | CODE: |
|
|
1661 | NOW = now (); |
1546 | runtime = SvNVx (sv_runtime); |
1662 | runtime = SvNVx (sv_runtime); |
1547 | server_tick (); |
1663 | server_tick (); |
1548 | |
1664 | |
1549 | void |
1665 | void |
1550 | log_backtrace (utf8_string msg) |
1666 | log_backtrace (utf8_string msg) |
… | |
… | |
1767 | PROTOTYPE: $ |
1883 | PROTOTYPE: $ |
1768 | CODE: |
1884 | CODE: |
1769 | RETVAL = op->head_ (); |
1885 | RETVAL = op->head_ (); |
1770 | OUTPUT: RETVAL |
1886 | OUTPUT: RETVAL |
1771 | |
1887 | |
1772 | int is_head (object *op) |
|
|
1773 | PROTOTYPE: $ |
|
|
1774 | CODE: |
|
|
1775 | RETVAL = op->head_ () == op; |
|
|
1776 | OUTPUT: RETVAL |
|
|
1777 | |
|
|
1778 | void |
1888 | void |
1779 | inv (object *obj) |
1889 | inv (object *obj) |
1780 | PROTOTYPE: $ |
1890 | PROTOTYPE: $ |
1781 | PPCODE: |
1891 | PPCODE: |
1782 | { |
1892 | { |
… | |
… | |
1926 | |
2036 | |
1927 | void add_button_link (object *button, maptile *map, int connected); |
2037 | void add_button_link (object *button, maptile *map, int connected); |
1928 | |
2038 | |
1929 | void remove_button_link (object *op); |
2039 | void remove_button_link (object *op); |
1930 | |
2040 | |
|
|
2041 | void handle_apply_yield (object *op); |
|
|
2042 | |
1931 | |
2043 | |
1932 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2044 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1933 | |
2045 | |
1934 | object *cf_insert_ob_in_ob (object *ob, object *where) |
2046 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1935 | |
2047 | |
… | |
… | |
1937 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2049 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
1938 | |
2050 | |
1939 | object *new (utf8_string archetype = 0) |
2051 | object *new (utf8_string archetype = 0) |
1940 | PROTOTYPE: ;$ |
2052 | PROTOTYPE: ;$ |
1941 | CODE: |
2053 | CODE: |
1942 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
2054 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
1943 | OUTPUT: |
2055 | OUTPUT: |
1944 | RETVAL |
2056 | RETVAL |
1945 | |
2057 | |
|
|
2058 | object *find_object (U32 tag) |
|
|
2059 | |
|
|
2060 | # TODO: nuke |
1946 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
2061 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
1947 | PROTOTYPE: $$$$$$ |
2062 | PROTOTYPE: $$$$$$ |
1948 | CODE: |
2063 | CODE: |
1949 | { |
2064 | { |
1950 | int unused_type; |
2065 | int unused_type; |
1951 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
2066 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1952 | } |
2067 | } |
1953 | |
|
|
1954 | player *contr (object *op) |
|
|
1955 | CODE: |
|
|
1956 | RETVAL = op->contr; |
|
|
1957 | OUTPUT: RETVAL |
|
|
1958 | |
2068 | |
1959 | const_utf8_string get_ob_key_value (object *op, utf8_string key) |
2069 | const_utf8_string get_ob_key_value (object *op, utf8_string key) |
1960 | |
2070 | |
1961 | bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) |
2071 | bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) |
1962 | |
2072 | |
… | |
… | |
2008 | void kill_player (object *op) |
2118 | void kill_player (object *op) |
2009 | |
2119 | |
2010 | void esrv_update_item (object *op, int what, object *item) |
2120 | void esrv_update_item (object *op, int what, object *item) |
2011 | C_ARGS: what, op, item |
2121 | C_ARGS: what, op, item |
2012 | |
2122 | |
2013 | void clear_los (object *op) |
|
|
2014 | |
|
|
2015 | int command_summon (object *op, utf8_string params) |
2123 | int command_summon (object *op, utf8_string params) |
2016 | |
2124 | |
2017 | int command_arrest (object *op, utf8_string params) |
2125 | int command_arrest (object *op, utf8_string params) |
2018 | |
2126 | |
2019 | |
2127 | |
… | |
… | |
2036 | CODE: |
2144 | CODE: |
2037 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
2145 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
2038 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2146 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2039 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2147 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2040 | pl->orig_stats = pl->ob->stats; |
2148 | pl->orig_stats = pl->ob->stats; |
|
|
2149 | |
|
|
2150 | void clear_los (player *pl) |
2041 | |
2151 | |
2042 | void cf_player_move (player *pl, int dir) |
2152 | void cf_player_move (player *pl, int dir) |
2043 | |
2153 | |
2044 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2154 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2045 | |
2155 | |
… | |
… | |
2188 | palette = SvRV (palette); |
2298 | palette = SvRV (palette); |
2189 | |
2299 | |
2190 | STRLEN idxlen; |
2300 | STRLEN idxlen; |
2191 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2301 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2192 | |
2302 | |
2193 | region **regionmap = (region **)malloc ( |
2303 | 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 ()); |
2304 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2196 | |
2305 | |
2197 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2306 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2198 | regionmap [i] = region::find ( |
2307 | regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2199 | SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
|
|
2200 | |
2308 | |
2201 | for (int y = 0; y < THIS->height; ++y) |
2309 | for (int y = 0; y < THIS->height; ++y) |
2202 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2310 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2203 | |
2311 | |
2204 | sfree (THIS->regions, THIS->size ()); |
2312 | sfree (THIS->regions, THIS->size ()); |
2205 | free (THIS->regionmap); |
2313 | delete [] THIS->regionmap; |
2206 | |
2314 | |
2207 | THIS->regions = regions; |
2315 | THIS->regions = regions; |
2208 | THIS->regionmap = regionmap; |
2316 | THIS->regionmap = regionmap; |
2209 | } |
2317 | } |
2210 | |
2318 | |
… | |
… | |
2417 | CODE: |
2525 | CODE: |
2418 | RETVAL = archetype::find (name); |
2526 | RETVAL = archetype::find (name); |
2419 | OUTPUT: |
2527 | OUTPUT: |
2420 | RETVAL |
2528 | RETVAL |
2421 | |
2529 | |
2422 | archetype *first() |
2530 | int archetypes_size () |
2423 | PROTOTYPE: |
2531 | CODE: |
2424 | CODE: |
|
|
2425 | RETVAL = first_archetype; |
2532 | RETVAL = archetypes.size (); |
2426 | OUTPUT: RETVAL |
2533 | OUTPUT: RETVAL |
|
|
2534 | |
|
|
2535 | archetype *archetypes (U32 index) |
|
|
2536 | CODE: |
|
|
2537 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
|
|
2538 | OUTPUT: RETVAL |
2427 | |
2539 | |
2428 | object *instantiate (archetype *arch) |
2540 | object *instantiate (archetype *arch) |
2429 | CODE: |
2541 | CODE: |
2430 | RETVAL = arch_to_object (arch); |
2542 | RETVAL = arch_to_object (arch); |
2431 | OUTPUT: |
2543 | OUTPUT: |
… | |
… | |
2508 | STRLEN len; |
2620 | STRLEN len; |
2509 | char *buf = SvPVbyte (packet, len); |
2621 | char *buf = SvPVbyte (packet, len); |
2510 | |
2622 | |
2511 | THIS->send_packet (buf, len); |
2623 | THIS->send_packet (buf, len); |
2512 | } |
2624 | } |
|
|
2625 | |
|
|
2626 | faceidx |
|
|
2627 | client::find_face (utf8_string name, faceidx defidx = 0) |
|
|
2628 | CODE: |
|
|
2629 | RETVAL = face_find (name, defidx); |
|
|
2630 | THIS->send_face (RETVAL); |
|
|
2631 | THIS->flush_fx (); |
|
|
2632 | OUTPUT: |
|
|
2633 | RETVAL |
2513 | |
2634 | |
2514 | MODULE = cf PACKAGE = cf::face PREFIX = face_ |
2635 | MODULE = cf PACKAGE = cf::face PREFIX = face_ |
2515 | |
2636 | |
2516 | #INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | |
2637 | #INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | |
2517 | |
2638 | |
… | |
… | |
2533 | if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; |
2654 | if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; |
2534 | if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; |
2655 | if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; |
2535 | } |
2656 | } |
2536 | OUTPUT: RETVAL |
2657 | OUTPUT: RETVAL |
2537 | |
2658 | |
2538 | void set (faceidx idx, int visibility, int magicmap) |
2659 | void set_type (faceidx idx, int value) |
2539 | CODE: |
2660 | ALIAS: |
2540 | faceinfo *f = face_info (idx); |
2661 | set_type = 0 |
2541 | assert (f); |
2662 | set_visibility = 1 |
2542 | f->visibility = visibility; |
2663 | set_magicmap = 2 |
2543 | f->magicmap = magicmap; |
2664 | set_smooth = 3 |
2544 | |
2665 | set_smoothlevel = 4 |
2545 | void set_smooth (faceidx idx, faceidx smooth, int smoothlevel) |
|
|
2546 | CODE: |
2666 | CODE: |
2547 | faceinfo *f = face_info (idx); assert (f); |
2667 | faceinfo *f = face_info (idx); assert (f); |
2548 | f->smooth = smooth; |
2668 | switch (ix) |
2549 | f->smoothlevel = smoothlevel; |
2669 | { |
|
|
2670 | case 0: f->type = value; break; |
|
|
2671 | case 1: f->visibility = value; break; |
|
|
2672 | case 2: f->magicmap = value; break; |
|
|
2673 | case 3: f->smooth = value; break; |
|
|
2674 | case 4: f->smoothlevel = value; break; |
|
|
2675 | } |
2550 | |
2676 | |
2551 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2677 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2552 | CODE: |
2678 | CODE: |
2553 | { |
2679 | { |
2554 | facedata *d = face_data (idx, faceset); |
2680 | faceinfo *f = face_info (idx); assert (f); |
2555 | assert (d); |
2681 | facedata *d = &(faceset ? f->data64 : f->data32); |
2556 | sv_to (data, d->data); |
2682 | sv_to (data, d->data); |
2557 | STRLEN clen; |
2683 | STRLEN clen; |
2558 | char *cdata = SvPVbyte (chksum, clen); |
2684 | char *cdata = SvPVbyte (chksum, clen); |
2559 | clen = min (CHKSUM_SIZE, clen); |
2685 | clen = min (CHKSUM_SIZE, clen); |
2560 | |
2686 | |
… | |
… | |
2570 | ns->force_newmap = true; |
2696 | ns->force_newmap = true; |
2571 | } |
2697 | } |
2572 | } |
2698 | } |
2573 | } |
2699 | } |
2574 | |
2700 | |
|
|
2701 | int get_data_size (faceidx idx, int faceset = 0) |
|
|
2702 | CODE: |
|
|
2703 | facedata *d = face_data (idx, faceset); assert (d); |
|
|
2704 | RETVAL = d->data.size (); |
|
|
2705 | OUTPUT: |
|
|
2706 | RETVAL |
|
|
2707 | |
|
|
2708 | SV *get_chksum (faceidx idx, int faceset = 0) |
|
|
2709 | CODE: |
|
|
2710 | facedata *d = face_data (idx, faceset); assert (d); |
|
|
2711 | RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); |
|
|
2712 | OUTPUT: |
|
|
2713 | RETVAL |
|
|
2714 | |
2575 | void invalidate (faceidx idx) |
2715 | void invalidate (faceidx idx) |
2576 | CODE: |
2716 | CODE: |
2577 | for_all_clients (ns) |
2717 | for_all_clients (ns) |
2578 | { |
2718 | { |
2579 | ns->faces_sent [idx] = false; |
2719 | ns->faces_sent [idx] = false; |