… | |
… | |
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" |
… | |
… | |
79 | static f_plug_api gethook = cfapi_get_hooks; |
78 | static f_plug_api gethook = cfapi_get_hooks; |
80 | static f_plug_api object_insert = cfapi_object_insert; |
79 | static f_plug_api object_insert = cfapi_object_insert; |
81 | |
80 | |
82 | static PerlInterpreter *perl; |
81 | static PerlInterpreter *perl; |
83 | |
82 | |
84 | double runtime; |
83 | tstamp NOW, runtime; |
85 | |
84 | |
86 | global gbl_ev; |
85 | global gbl_ev; |
87 | 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; |
88 | static SV *sv_runtime, *sv_next_tick; |
87 | static 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]; |
… | |
… | |
233 | delete obj; |
246 | delete obj; |
234 | } |
247 | } |
235 | } |
248 | } |
236 | } |
249 | } |
237 | |
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 | |
238 | attachable & |
263 | attachable & |
239 | attachable::operator =(const attachable &src) |
264 | attachable::operator =(const attachable &src) |
240 | { |
265 | { |
241 | //if (self || cb) |
266 | //if (self || cb) |
242 | //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); |
267 | //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); |
243 | |
268 | |
244 | attach = src.attach; |
269 | attach = src.attach; |
245 | 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 | |
246 | } |
305 | } |
247 | |
306 | |
248 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
307 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
249 | |
308 | |
250 | static SV * |
309 | static SV * |
… | |
… | |
283 | { |
342 | { |
284 | if (!obj) |
343 | if (!obj) |
285 | return &PL_sv_undef; |
344 | return &PL_sv_undef; |
286 | |
345 | |
287 | if (!obj->self) |
346 | if (!obj->self) |
|
|
347 | obj->self = newHV (); |
|
|
348 | |
|
|
349 | if (!SvOBJECT (obj->self)) |
288 | { |
350 | { |
289 | obj->self = newHV (); |
|
|
290 | 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); |
291 | |
352 | |
292 | // 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 |
293 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
355 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
294 | } |
356 | } |
295 | else |
357 | else |
296 | { |
358 | { |
297 | SV *sv = newRV_inc ((SV *)obj->self); |
359 | SV *sv = newRV_inc ((SV *)obj->self); |
… | |
… | |
334 | return SvPTR (sv, klass); |
396 | return SvPTR (sv, klass); |
335 | else |
397 | else |
336 | return 0; |
398 | return 0; |
337 | } |
399 | } |
338 | |
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 | |
339 | 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; } |
340 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
418 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
341 | inline SV *to_sv (bool v) { return newSViv (v); } |
419 | inline SV *to_sv (bool v) { return newSViv (v); } |
342 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
420 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
343 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
421 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
344 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
422 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
… | |
… | |
354 | 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); } |
355 | 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); } |
356 | 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); } |
357 | 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); } |
358 | 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); } |
359 | 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); } |
360 | inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); } |
|
|
361 | 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); } |
362 | |
440 | |
363 | inline SV *to_sv (object & v) { return to_sv (&v); } |
441 | inline SV *to_sv (object & v) { return to_sv (&v); } |
364 | inline SV *to_sv (living & v) { return to_sv (&v); } |
442 | inline SV *to_sv (living & v) { return to_sv (&v); } |
365 | |
443 | |
… | |
… | |
371 | char buf[128]; |
449 | char buf[128]; |
372 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
450 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
373 | return newSVpv (buf, 0); |
451 | return newSVpv (buf, 0); |
374 | } |
452 | } |
375 | |
453 | |
376 | 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; } |
377 | 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; } |
378 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
456 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
379 | 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); } |
380 | 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); } |
381 | 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); } |
… | |
… | |
391 | 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"); } |
392 | 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"); } |
393 | 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"); } |
394 | 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"); } |
395 | 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"); } |
396 | 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"); } |
397 | 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"); } |
398 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
|
|
399 | 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"); } |
400 | |
478 | |
401 | //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)]; } |
402 | 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)); } |
403 | |
481 | |
… | |
… | |
886 | } |
964 | } |
887 | |
965 | |
888 | SV * |
966 | SV * |
889 | cfperl_result (int idx) |
967 | cfperl_result (int idx) |
890 | { |
968 | { |
891 | AV *av = get_av ("cfperl::invoke_results", 0); |
969 | AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
892 | if (!av) |
970 | if (!av) |
893 | return &PL_sv_undef; |
971 | return &PL_sv_undef; |
894 | |
972 | |
895 | SV **sv = av_fetch (av, idx, 0); |
973 | SV **sv = av_fetch (av, idx, 0); |
896 | if (!sv) |
974 | if (!sv) |
… | |
… | |
936 | CALL_BEGIN (2); |
1014 | CALL_BEGIN (2); |
937 | CALL_ARG (book); |
1015 | CALL_ARG (book); |
938 | CALL_ARG (level); |
1016 | CALL_ARG (level); |
939 | CALL_CALL ("ext::books::make_book", G_VOID); |
1017 | CALL_CALL ("ext::books::make_book", G_VOID); |
940 | 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; |
941 | } |
1046 | } |
942 | |
1047 | |
943 | maptile * |
1048 | maptile * |
944 | maptile::find_sync (const char *path, maptile *origin) |
1049 | maptile::find_sync (const char *path, maptile *origin) |
945 | { |
1050 | { |
… | |
… | |
1031 | |
1136 | |
1032 | struct EventAPI *watcher_base::GEventAPI; |
1137 | struct EventAPI *watcher_base::GEventAPI; |
1033 | struct CoroAPI *coroapi::GCoroAPI; |
1138 | struct CoroAPI *coroapi::GCoroAPI; |
1034 | |
1139 | |
1035 | int coroapi::cede_counter; |
1140 | int coroapi::cede_counter; |
1036 | double (*coroapi::time)(); |
|
|
1037 | double coroapi::next_cede; |
1141 | tstamp coroapi::next_cede; |
1038 | |
1142 | |
1039 | void coroapi::do_cede_to_tick () |
1143 | void coroapi::do_cede_to_tick () |
1040 | { |
1144 | { |
1041 | cede_counter = 0; |
1145 | cede_counter = 0; |
1042 | |
1146 | |
… | |
… | |
1173 | |
1277 | |
1174 | _connect_to_perl (); |
1278 | _connect_to_perl (); |
1175 | |
1279 | |
1176 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1280 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1177 | |
1281 | |
1178 | { |
1282 | //{ |
1179 | require_pv ("Time::HiRes"); |
1283 | // require_pv ("Time::HiRes"); |
1180 | |
1284 | // |
1181 | SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
1285 | // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
1182 | if (!svp) croak ("Time::HiRes is required"); |
1286 | // if (!svp) croak ("Time::HiRes is required"); |
1183 | if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); |
1287 | // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); |
1184 | coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); |
1288 | // coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); |
1185 | } |
1289 | //} |
1186 | |
1290 | |
1187 | static const struct { |
1291 | static const struct { |
1188 | const char *name; |
1292 | const char *name; |
1189 | IV iv; |
1293 | IV iv; |
1190 | } *civ, const_iv[] = { |
1294 | } *civ, const_iv[] = { |
… | |
… | |
1460 | |
1564 | |
1461 | for_all_objects (op) |
1565 | for_all_objects (op) |
1462 | op->reattach (); |
1566 | op->reattach (); |
1463 | } |
1567 | } |
1464 | |
1568 | |
1465 | void _post_tick () |
|
|
1466 | CODE: |
|
|
1467 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
|
|
1468 | |
|
|
1469 | # support function for map-world.ext |
1569 | # support function for map-world.ext |
1470 | void _quantise (SV *data_sv, SV *plt_sv) |
1570 | void _quantise (SV *data_sv, SV *plt_sv) |
1471 | CODE: |
1571 | CODE: |
1472 | { |
1572 | { |
1473 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
1573 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
… | |
… | |
1505 | len -= 3; |
1605 | len -= 3; |
1506 | } |
1606 | } |
1507 | |
1607 | |
1508 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
1608 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
1509 | } |
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 |
1510 | |
1626 | |
1511 | NV floor (NV x) |
1627 | NV floor (NV x) |
1512 | |
1628 | |
1513 | NV ceil (NV x) |
1629 | NV ceil (NV x) |
1514 | |
1630 | |
… | |
… | |
1540 | CODE: |
1656 | CODE: |
1541 | coroapi::cede_to_tick (); |
1657 | coroapi::cede_to_tick (); |
1542 | |
1658 | |
1543 | void server_tick () |
1659 | void server_tick () |
1544 | CODE: |
1660 | CODE: |
|
|
1661 | NOW = now (); |
1545 | runtime = SvNVx (sv_runtime); |
1662 | runtime = SvNVx (sv_runtime); |
1546 | server_tick (); |
1663 | server_tick (); |
1547 | |
1664 | |
1548 | void |
1665 | void |
1549 | log_backtrace (utf8_string msg) |
1666 | log_backtrace (utf8_string msg) |
… | |
… | |
1919 | |
2036 | |
1920 | void add_button_link (object *button, maptile *map, int connected); |
2037 | void add_button_link (object *button, maptile *map, int connected); |
1921 | |
2038 | |
1922 | void remove_button_link (object *op); |
2039 | void remove_button_link (object *op); |
1923 | |
2040 | |
|
|
2041 | void handle_apply_yield (object *op); |
|
|
2042 | |
1924 | |
2043 | |
1925 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2044 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1926 | |
2045 | |
1927 | object *cf_insert_ob_in_ob (object *ob, object *where) |
2046 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1928 | |
2047 | |
… | |
… | |
1934 | CODE: |
2053 | CODE: |
1935 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
2054 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
1936 | OUTPUT: |
2055 | OUTPUT: |
1937 | RETVAL |
2056 | RETVAL |
1938 | |
2057 | |
|
|
2058 | object *find_object (U32 tag) |
|
|
2059 | |
1939 | # TODO: nuke |
2060 | # TODO: nuke |
1940 | 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) |
1941 | PROTOTYPE: $$$$$$ |
2062 | PROTOTYPE: $$$$$$ |
1942 | CODE: |
2063 | CODE: |
1943 | { |
2064 | { |
1944 | int unused_type; |
2065 | int unused_type; |
1945 | 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); |
1946 | } |
2067 | } |
1947 | |
|
|
1948 | player *contr (object *op) |
|
|
1949 | CODE: |
|
|
1950 | RETVAL = op->contr; |
|
|
1951 | OUTPUT: RETVAL |
|
|
1952 | |
2068 | |
1953 | 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) |
1954 | |
2070 | |
1955 | 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) |
1956 | |
2072 | |
… | |
… | |
2182 | palette = SvRV (palette); |
2298 | palette = SvRV (palette); |
2183 | |
2299 | |
2184 | STRLEN idxlen; |
2300 | STRLEN idxlen; |
2185 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2301 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2186 | |
2302 | |
2187 | region **regionmap = (region **)malloc ( |
2303 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2188 | (av_len ((AV *)palette) + 1) * sizeof (region *)); |
|
|
2189 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2304 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2190 | |
2305 | |
2191 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2306 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2192 | regionmap [i] = region::find ( |
2307 | regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2193 | SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
|
|
2194 | |
2308 | |
2195 | for (int y = 0; y < THIS->height; ++y) |
2309 | for (int y = 0; y < THIS->height; ++y) |
2196 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2310 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2197 | |
2311 | |
2198 | sfree (THIS->regions, THIS->size ()); |
2312 | sfree (THIS->regions, THIS->size ()); |
2199 | free (THIS->regionmap); |
2313 | delete [] THIS->regionmap; |
2200 | |
2314 | |
2201 | THIS->regions = regions; |
2315 | THIS->regions = regions; |
2202 | THIS->regionmap = regionmap; |
2316 | THIS->regionmap = regionmap; |
2203 | } |
2317 | } |
2204 | |
2318 | |
… | |
… | |
2507 | char *buf = SvPVbyte (packet, len); |
2621 | char *buf = SvPVbyte (packet, len); |
2508 | |
2622 | |
2509 | THIS->send_packet (buf, len); |
2623 | THIS->send_packet (buf, len); |
2510 | } |
2624 | } |
2511 | |
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 |
|
|
2634 | |
2512 | MODULE = cf PACKAGE = cf::face PREFIX = face_ |
2635 | MODULE = cf PACKAGE = cf::face PREFIX = face_ |
2513 | |
2636 | |
2514 | #INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | |
2637 | #INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | |
2515 | |
2638 | |
2516 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2639 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
… | |
… | |
2531 | if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; |
2654 | if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; |
2532 | if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; |
2655 | if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; |
2533 | } |
2656 | } |
2534 | OUTPUT: RETVAL |
2657 | OUTPUT: RETVAL |
2535 | |
2658 | |
2536 | void set (faceidx idx, int visibility, int magicmap) |
2659 | void set_type (faceidx idx, int value) |
2537 | CODE: |
2660 | ALIAS: |
2538 | faceinfo *f = face_info (idx); |
2661 | set_type = 0 |
2539 | assert (f); |
2662 | set_visibility = 1 |
2540 | f->visibility = visibility; |
2663 | set_magicmap = 2 |
2541 | f->magicmap = magicmap; |
2664 | set_smooth = 3 |
2542 | |
2665 | set_smoothlevel = 4 |
2543 | void set_smooth (faceidx idx, faceidx smooth, int smoothlevel) |
|
|
2544 | CODE: |
2666 | CODE: |
2545 | faceinfo *f = face_info (idx); assert (f); |
2667 | faceinfo *f = face_info (idx); assert (f); |
2546 | f->smooth = smooth; |
2668 | switch (ix) |
2547 | 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 | } |
2548 | |
2676 | |
2549 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2677 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2550 | CODE: |
2678 | CODE: |
2551 | { |
2679 | { |
2552 | facedata *d = face_data (idx, faceset); |
2680 | faceinfo *f = face_info (idx); assert (f); |
2553 | assert (d); |
2681 | facedata *d = &(faceset ? f->data64 : f->data32); |
2554 | sv_to (data, d->data); |
2682 | sv_to (data, d->data); |
2555 | STRLEN clen; |
2683 | STRLEN clen; |
2556 | char *cdata = SvPVbyte (chksum, clen); |
2684 | char *cdata = SvPVbyte (chksum, clen); |
2557 | clen = min (CHKSUM_SIZE, clen); |
2685 | clen = min (CHKSUM_SIZE, clen); |
2558 | |
2686 | |
… | |
… | |
2568 | ns->force_newmap = true; |
2696 | ns->force_newmap = true; |
2569 | } |
2697 | } |
2570 | } |
2698 | } |
2571 | } |
2699 | } |
2572 | |
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 | |
2573 | void invalidate (faceidx idx) |
2715 | void invalidate (faceidx idx) |
2574 | CODE: |
2716 | CODE: |
2575 | for_all_clients (ns) |
2717 | for_all_clients (ns) |
2576 | { |
2718 | { |
2577 | ns->faces_sent [idx] = false; |
2719 | ns->faces_sent [idx] = false; |