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.339 by root, Thu Nov 26 08:08:40 2009 UTC vs.
Revision 1.351 by elmex, Mon Mar 22 18:16:39 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
6 * 5 *
7 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
8 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version. 9 * option) any later version.
29 28
30#include <cstdarg> 29#include <cstdarg>
31#include <typeinfo> 30#include <typeinfo>
32 31
33#include "global.h" 32#include "global.h"
34#include "loader.h"
35#include "../random_maps/random_map.h" 33#include "../random_maps/random_map.h"
36#include "evthread.h" 34#include "evthread.h"
37#include "sproto.h" 35#include "sproto.h"
38 36
39#include <unistd.h> 37#include <unistd.h>
97 *cv_cf_client_send_msg, 95 *cv_cf_client_send_msg,
98 *cv_cf_tick, 96 *cv_cf_tick,
99 *cv_cf_match_match; 97 *cv_cf_match_match;
100 98
101#ifndef newSVpv_utf8 99#ifndef newSVpv_utf8
102static inline SV * 100static SV *
103newSVpv_utf8 (const char *s) 101newSVpv_utf8 (const char *s)
104{ 102{
105 if (!s) 103 if (!s)
106 return newSV (0); 104 return newSV (0);
107 105
110 return sv; 108 return sv;
111} 109}
112#endif 110#endif
113 111
114#ifndef newSVpvn_utf8 112#ifndef newSVpvn_utf8
115static inline SV * 113static SV *
116newSVpvn_utf8 (const char *s, STRLEN l, int utf8) 114newSVpvn_utf8 (const char *s, STRLEN l, int utf8)
117{ 115{
118 if (!s) 116 if (!s)
119 return newSV (0); 117 return newSV (0);
120 118
124 SvUTF8_on (sv); 122 SvUTF8_on (sv);
125 123
126 return sv; 124 return sv;
127} 125}
128#endif 126#endif
127
128static noinline utf8_string
129cfSvPVutf8_nolen (SV *sv)
130{
131 SvGETMAGIC (sv);
132
133 if (SvPOK (sv))
134 {
135 if (!SvUTF8 (sv))
136 sv_utf8_upgrade_nomg (sv);
137
138 return SvPVX (sv);
139 }
140
141 return SvPV_nolen (sv);
142}
129 143
130// helper cast function, returns super class * or 0 144// helper cast function, returns super class * or 0
131template<class super> 145template<class super>
132static super * 146static super *
133is_a (attachable *at) 147is_a (attachable *at)
402 hv_clear ((HV *)sv); 416 hv_clear ((HV *)sv);
403 sv_unmagic (sv, PERL_MAGIC_ext); 417 sv_unmagic (sv, PERL_MAGIC_ext);
404} 418}
405#endif 419#endif
406 420
407static long SvPTR_nc (SV *sv) 421static long
422SvPTR_nc (SV *sv)
408{ 423{
409 sv = SvRV (sv); 424 sv = SvRV (sv);
410 425
411 // very important shortcut 426 // very important shortcut
412 if (expect_true (SvMAGIC (sv) && SvMAGIC (sv)->mg_type == PERL_MAGIC_ext)) 427 if (expect_true (SvMAGIC (sv) && SvMAGIC (sv)->mg_type == PERL_MAGIC_ext))
528 SV *sv = to_sv (static_cast<dynbuf *> (v)); 543 SV *sv = to_sv (static_cast<dynbuf *> (v));
529 SvUTF8_on (sv); 544 SvUTF8_on (sv);
530 return sv; 545 return sv;
531} 546}
532 547
533static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } 548static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? cfSvPVutf8_nolen (sv) : 0; }
534static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 549static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
535static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 550static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
536static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 551static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
537static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 552static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
538static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 553static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
1063 CALL_CALL ("ext::books::make_book", G_VOID); 1078 CALL_CALL ("ext::books::make_book", G_VOID);
1064 CALL_END; 1079 CALL_END;
1065} 1080}
1066 1081
1067void 1082void
1068cfperl_send_msg (client *ns, int color, const char *type, const char *msg) 1083cfperl_send_msg (client *ns, int color, const_utf8_string type, const_utf8_string msg)
1069{ 1084{
1070 CALL_BEGIN (4); 1085 CALL_BEGIN (4);
1071 CALL_ARG (ns); 1086 CALL_ARG (ns);
1072 CALL_ARG (type); 1087 CALL_ARG (type);
1073 CALL_ARG_SV (newSVpv_utf8 (msg)); 1088 CALL_ARG_SV (newSVpv_utf8 (msg));
1102 CALL_CALL ("cf::mapscript::activate", G_VOID); 1117 CALL_CALL ("cf::mapscript::activate", G_VOID);
1103 CALL_END; 1118 CALL_END;
1104} 1119}
1105 1120
1106player * 1121player *
1107player::find (const char *name) 1122player::find (const_utf8_string name)
1108{ 1123{
1109 CALL_BEGIN (1); 1124 CALL_BEGIN (1);
1110 CALL_ARG (name); 1125 CALL_ARG (name);
1111 CALL_CALL ("cf::player::find", G_SCALAR); 1126 CALL_CALL ("cf::player::find", G_SCALAR);
1112 1127
1117 1132
1118 return retval; 1133 return retval;
1119} 1134}
1120 1135
1121maptile * 1136maptile *
1122find_style (const char *dirname, const char *stylename, int difficulty) 1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty)
1123{ 1138{
1124 CALL_BEGIN (3); 1139 CALL_BEGIN (3);
1125 CALL_ARG (dirname); 1140 CALL_ARG (dirname);
1126 CALL_ARG (stylename); 1141 CALL_ARG (stylename);
1127 CALL_ARG (difficulty); 1142 CALL_ARG (difficulty);
1134 1149
1135 return retval; 1150 return retval;
1136} 1151}
1137 1152
1138maptile * 1153maptile *
1139maptile::find_sync (const char *path, maptile *origin) 1154maptile::find_sync (const_utf8_string path, maptile *origin)
1140{ 1155{
1141 CALL_BEGIN (2); 1156 CALL_BEGIN (2);
1142 CALL_ARG (path); 1157 CALL_ARG (path);
1143 CALL_ARG (origin); 1158 CALL_ARG (origin);
1144 CALL_CALL ("cf::map::find_sync", G_SCALAR); 1159 CALL_CALL ("cf::map::find_sync", G_SCALAR);
1150 1165
1151 return retval; 1166 return retval;
1152} 1167}
1153 1168
1154maptile * 1169maptile *
1155maptile::find_async (const char *path, maptile *origin, bool load) 1170maptile::find_async (const_utf8_string path, maptile *origin, bool load)
1156{ 1171{
1157 CALL_BEGIN (3); 1172 CALL_BEGIN (3);
1158 CALL_ARG (path); 1173 CALL_ARG (path);
1159 CALL_ARG (origin); 1174 CALL_ARG (origin);
1160 CALL_ARG (load); 1175 CALL_ARG (load);
1189 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1204 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
1190 CALL_END; 1205 CALL_END;
1191} 1206}
1192 1207
1193void 1208void
1194object::player_goto (const char *path, int x, int y) 1209object::player_goto (const_utf8_string path, int x, int y)
1195{ 1210{
1196 if (type != PLAYER) 1211 if (type != PLAYER)
1197 return; 1212 return;
1198 1213
1199 CALL_BEGIN (4); 1214 CALL_BEGIN (4);
1203 CALL_ARG (y); 1218 CALL_ARG (y);
1204 CALL_CALL ("cf::object::player::goto", G_VOID); 1219 CALL_CALL ("cf::object::player::goto", G_VOID);
1205 CALL_END; 1220 CALL_END;
1206} 1221}
1207 1222
1208const char * 1223const_utf8_string
1209object::ref () const 1224object::ref () const
1210{ 1225{
1211 if (type == PLAYER) 1226 if (type == PLAYER)
1212 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1227 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1213 else 1228 else
1214 return 0; 1229 return 0;
1215} 1230}
1216 1231
1217object * 1232object *
1218object::deref (const char *ref) 1233object::deref (const_utf8_string ref)
1219{ 1234{
1220 object *retval = 0; 1235 object *retval = 0;
1221 1236
1222 if (ref) 1237 if (ref)
1223 { 1238 {
1233 1248
1234 return retval; 1249 return retval;
1235} 1250}
1236 1251
1237void 1252void
1238log_backtrace (const char *msg) 1253log_backtrace (const_utf8_string msg)
1239{ 1254{
1240#if HAVE_BACKTRACE 1255#if HAVE_BACKTRACE
1241 void *addr [20]; 1256 void *addr [20];
1242 int size = backtrace (addr, 20); 1257 int size = backtrace (addr, 20);
1243 1258
1249 CALL_END; 1264 CALL_END;
1250#endif 1265#endif
1251} 1266}
1252 1267
1253bool 1268bool
1254is_match_expr (const char *expr) 1269is_match_expr (const_utf8_string expr)
1255{ 1270{
1256 return !strncmp (expr, "match ", sizeof ("match ") - 1); 1271 return !strncmp (expr, "match ", sizeof ("match ") - 1);
1257} 1272}
1258 1273
1259bool 1274bool
1260match (const char *expr, object *ob, object *self, object *source, object *originator) 1275match (const_utf8_string expr, object *ob, object *self, object *source, object *originator)
1261{ 1276{
1262 if (!strncmp (expr, "match ", sizeof ("match ") - 1)) 1277 if (!strncmp (expr, "match ", sizeof ("match ") - 1))
1263 expr += sizeof ("match ") - 1; 1278 expr += sizeof ("match ") - 1;
1264 1279
1265 CALL_BEGIN (5); 1280 CALL_BEGIN (5);
1276 1291
1277 return matched; 1292 return matched;
1278} 1293}
1279 1294
1280object * 1295object *
1281match_one (const char *expr, object *ob, object *self, object *source, object *originator) 1296match_one (const_utf8_string expr, object *ob, object *self, object *source, object *originator)
1282{ 1297{
1283 if (!strncmp (expr, "match ", sizeof ("match ") - 1)) 1298 if (!strncmp (expr, "match ", sizeof ("match ") - 1))
1284 expr += sizeof ("match ") - 1; 1299 expr += sizeof ("match ") - 1;
1285 1300
1286 CALL_BEGIN (5); 1301 CALL_BEGIN (5);
1505 const_iv (NDI_NOCREATE) const_iv (NDI_CLEAR) const_iv (NDI_VERBATIM) 1520 const_iv (NDI_NOCREATE) const_iv (NDI_CLEAR) const_iv (NDI_VERBATIM)
1506 1521
1507 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1522 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1508 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1523 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1509 1524
1510 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1525 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_LEVEL)
1511 1526
1512 const_iv (SP_RAISE_DEAD) 1527 const_iv (SP_RAISE_DEAD)
1513 const_iv (SP_RUNE) 1528 const_iv (SP_RUNE)
1514 const_iv (SP_MAKE_MARK) 1529 const_iv (SP_MAKE_MARK)
1515 const_iv (SP_BOLT) 1530 const_iv (SP_BOLT)
1807 } 1822 }
1808 1823
1809void server_tick () 1824void server_tick ()
1810 CODE: 1825 CODE:
1811{ 1826{
1827 ev_now_update (EV_DEFAULT);
1812 NOW = ev_now (EV_DEFAULT); 1828 NOW = ev_now (EV_DEFAULT);
1813 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1829 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1814 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1830 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1815 runtime = SvNVX (sv_runtime); 1831 runtime = SvNVX (sv_runtime);
1816 1832
1817 server_tick (); 1833 server_tick ();
1818 1834
1819 NOW = ev_time (); 1835 ev_now_update (EV_DEFAULT);
1836 NOW = ev_now (EV_DEFAULT);
1820 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1837 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1821 runtime += TICK; 1838 runtime += TICK;
1822 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1839 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1823} 1840}
1824 1841
2129int mortals_size () 2146int mortals_size ()
2130 CODE: 2147 CODE:
2131 RETVAL = attachable::mortals.size (); 2148 RETVAL = attachable::mortals.size ();
2132 OUTPUT: RETVAL 2149 OUTPUT: RETVAL
2133 2150
2134const char *slot_use_name (U32 slot) 2151const_utf8_string slot_use_name (U32 slot)
2135 ALIAS: 2152 ALIAS:
2136 slot_nonuse_name = 1 2153 slot_nonuse_name = 1
2137 CODE: 2154 CODE:
2138{ 2155{
2139 if (slot >= NUM_BODY_LOCATIONS) 2156 if (slot >= NUM_BODY_LOCATIONS)
2293 CODE: 2310 CODE:
2294 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2311 RETVAL = archetype ? get_archetype (archetype) : object::create ();
2295 OUTPUT: 2312 OUTPUT:
2296 RETVAL 2313 RETVAL
2297 2314
2315object *generate (utf8_string arch, object *creator)
2316 CODE:
2317 object *obj = get_archetype (arch);
2318 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2319 RETVAL = obj;
2320 OUTPUT:
2321 RETVAL
2322
2298object *find_object (U32 tag) 2323object *find_object (U32 tag)
2324
2325object *find_object_uuid (UUID i)
2299 2326
2300# TODO: nuke 2327# TODO: nuke
2301object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2328object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
2302 PROTOTYPE: $$$$$$ 2329 PROTOTYPE: $$$$$$
2303 CODE: 2330 CODE:
2364 CODE: 2391 CODE:
2365 RETVAL = op->contr; 2392 RETVAL = op->contr;
2366 OUTPUT: RETVAL 2393 OUTPUT: RETVAL
2367 2394
2368bool move_player (object *op, int dir) 2395bool move_player (object *op, int dir)
2369
2370void check_score (object *op)
2371 2396
2372void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2397void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2373 CODE: 2398 CODE:
2374 new_draw_info (flags, 0, op, txt); 2399 new_draw_info (flags, 0, op, txt);
2375 2400
2546 for (int x = 0; x < THIS->width; ++x) 2571 for (int x = 0; x < THIS->width; ++x)
2547 for (int y = 0; y < THIS->height; ++y) 2572 for (int y = 0; y < THIS->height; ++y)
2548 { 2573 {
2549 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2574 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2550 if (op->flag [FLAG_IS_FLOOR]) 2575 if (op->flag [FLAG_IS_FLOOR])
2551 goto skip_space; 2576 goto skip;
2552 2577
2553 { 2578 {
2554 int offs = offset + y * stride + x; 2579 int offs = offset + y * stride + x;
2580
2555 if (IN_RANGE_EXC (offs, 0, idxlen)) 2581 if (IN_RANGE_EXC (offs, 0, idxlen))
2556 { 2582 {
2557 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2583 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2558 { 2584 {
2559 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2585 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2560 ob->flag [FLAG_NO_MAP_SAVE] = true; 2586 ob->flag [FLAG_NO_MAP_SAVE] = true;
2561 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2587 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2562 2588
2563 if (ob->randomitems) 2589 if (ob->randomitems && !ob->above)
2564 { 2590 {
2565 if (!ob->above)
2566 {
2567 ob->create_treasure (ob->randomitems); 2591 ob->create_treasure (ob->randomitems);
2568 2592
2569 for (object *op = ob->above; op; op = op->above) 2593 for (object *op = ob->above; op; op = op->above)
2570 op->flag [FLAG_NO_MAP_SAVE] = true; 2594 op->flag [FLAG_NO_MAP_SAVE] = true;
2571 } 2595 // TODO: if this is a pickable object, then the item
2572 2596 // will at a bit weird - saving inside the player
2573 ob->randomitems = 0; 2597 // will clear the flag, but when the player drops
2598 // it without logging out, it keeps the flag.
2599 // nobody ahs reported this, but this can be rather
2600 // annoying on persistent maps.
2574 } 2601 }
2575 } 2602 }
2576 } 2603 }
2577 } 2604 }
2578 2605
2579 skip_space: ; 2606 skip: ;
2580 } 2607 }
2581} 2608}
2582 2609
2583void 2610void
2584maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) 2611maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2594 2621
2595 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2622 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2596 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2623 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2597 2624
2598 for (int i = av_len ((AV *)palette) + 1; i--; ) 2625 for (int i = av_len ((AV *)palette) + 1; i--; )
2599 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2626 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2600 2627
2601 for (int y = 0; y < THIS->height; ++y) 2628 for (int y = 0; y < THIS->height; ++y)
2602 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2629 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2603 2630
2604 sfree (THIS->regions, THIS->size ()); 2631 sfree (THIS->regions, THIS->size ());
2829archetype *archetypes (U32 index) 2856archetype *archetypes (U32 index)
2830 CODE: 2857 CODE:
2831 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2858 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2832 OUTPUT: RETVAL 2859 OUTPUT: RETVAL
2833 2860
2834object *instantiate (archetype *arch)
2835 CODE:
2836 RETVAL = arch_to_object (arch);
2837 OUTPUT:
2838 RETVAL
2839
2840INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2861INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2841 2862
2842MODULE = cf PACKAGE = cf::party 2863MODULE = cf PACKAGE = cf::party
2843 2864
2844partylist *first () 2865partylist *first ()
3006 sv_to (data, d->data); 3027 sv_to (data, d->data);
3007 STRLEN clen; 3028 STRLEN clen;
3008 char *cdata = SvPVbyte (chksum, clen); 3029 char *cdata = SvPVbyte (chksum, clen);
3009 clen = min (CHKSUM_MAXLEN, clen); 3030 clen = min (CHKSUM_MAXLEN, clen);
3010 3031
3032 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
3033
3011 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 3034 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
3012 { 3035 {
3013 d->chksum_len = clen; 3036 d->chksum_len = clen;
3014 memcpy (d->chksum, cdata, clen); 3037 memcpy (d->chksum, cdata, clen);
3015 3038
3088 } 3111 }
3089 else 3112 else
3090 anim = &animation::create (name, av_len (av) + 1, facings); 3113 anim = &animation::create (name, av_len (av) + 1, facings);
3091 3114
3092 for (int i = 0; i < anim->num_animations; ++i) 3115 for (int i = 0; i < anim->num_animations; ++i)
3093 anim->faces [i] = face_find (SvPVutf8_nolen (*av_fetch (av, i, 1))); 3116 anim->faces [i] = face_find (cfSvPVutf8_nolen (*av_fetch (av, i, 1)));
3094} 3117}
3095 OUTPUT: RETVAL 3118 OUTPUT: RETVAL
3096 3119
3097void invalidate_all () 3120void invalidate_all ()
3098 CODE: 3121 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines