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,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * 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 |
7 | * 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 |
8 | * 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 |
9 | * option) any later version. |
9 | * option) any later version. |
… | |
… | |
28 | |
28 | |
29 | #include <cstdarg> |
29 | #include <cstdarg> |
30 | #include <typeinfo> |
30 | #include <typeinfo> |
31 | |
31 | |
32 | #include "global.h" |
32 | #include "global.h" |
33 | #include "loader.h" |
|
|
34 | #include "../random_maps/random_map.h" |
33 | #include "../random_maps/random_map.h" |
35 | #include "evthread.h" |
34 | #include "evthread.h" |
36 | #include "sproto.h" |
35 | #include "sproto.h" |
37 | |
36 | |
38 | #include <unistd.h> |
37 | #include <unistd.h> |
… | |
… | |
96 | *cv_cf_client_send_msg, |
95 | *cv_cf_client_send_msg, |
97 | *cv_cf_tick, |
96 | *cv_cf_tick, |
98 | *cv_cf_match_match; |
97 | *cv_cf_match_match; |
99 | |
98 | |
100 | #ifndef newSVpv_utf8 |
99 | #ifndef newSVpv_utf8 |
101 | static inline SV * |
100 | static SV * |
102 | newSVpv_utf8 (const char *s) |
101 | newSVpv_utf8 (const char *s) |
103 | { |
102 | { |
104 | if (!s) |
103 | if (!s) |
105 | return newSV (0); |
104 | return newSV (0); |
106 | |
105 | |
… | |
… | |
109 | return sv; |
108 | return sv; |
110 | } |
109 | } |
111 | #endif |
110 | #endif |
112 | |
111 | |
113 | #ifndef newSVpvn_utf8 |
112 | #ifndef newSVpvn_utf8 |
114 | static inline SV * |
113 | static SV * |
115 | newSVpvn_utf8 (const char *s, STRLEN l, int utf8) |
114 | newSVpvn_utf8 (const char *s, STRLEN l, int utf8) |
116 | { |
115 | { |
117 | if (!s) |
116 | if (!s) |
118 | return newSV (0); |
117 | return newSV (0); |
119 | |
118 | |
… | |
… | |
123 | SvUTF8_on (sv); |
122 | SvUTF8_on (sv); |
124 | |
123 | |
125 | return sv; |
124 | return sv; |
126 | } |
125 | } |
127 | #endif |
126 | #endif |
|
|
127 | |
|
|
128 | static noinline utf8_string |
|
|
129 | cfSvPVutf8_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 | } |
128 | |
143 | |
129 | // helper cast function, returns super class * or 0 |
144 | // helper cast function, returns super class * or 0 |
130 | template<class super> |
145 | template<class super> |
131 | static super * |
146 | static super * |
132 | is_a (attachable *at) |
147 | is_a (attachable *at) |
… | |
… | |
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 | |
533 | static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } |
548 | static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? cfSvPVutf8_nolen (sv) : 0; } |
534 | static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
549 | static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
535 | static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
550 | static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
536 | static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
551 | static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
537 | static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
552 | static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
538 | static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
553 | static 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 | |
1067 | void |
1082 | void |
1068 | cfperl_send_msg (client *ns, int color, const char *type, const char *msg) |
1083 | cfperl_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 | |
1106 | player * |
1121 | player * |
1107 | player::find (const char *name) |
1122 | player::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 | |
1121 | maptile * |
1136 | maptile * |
1122 | find_style (const char *dirname, const char *stylename, int difficulty) |
1137 | find_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 | |
1138 | maptile * |
1153 | maptile * |
1139 | maptile::find_sync (const char *path, maptile *origin) |
1154 | maptile::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 | |
1154 | maptile * |
1169 | maptile * |
1155 | maptile::find_async (const char *path, maptile *origin, bool load) |
1170 | maptile::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 | |
1193 | void |
1208 | void |
1194 | object::player_goto (const char *path, int x, int y) |
1209 | object::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 | |
1208 | const char * |
1223 | const_utf8_string |
1209 | object::ref () const |
1224 | object::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 | |
1217 | object * |
1232 | object * |
1218 | object::deref (const char *ref) |
1233 | object::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 | |
1237 | void |
1252 | void |
1238 | log_backtrace (const char *msg) |
1253 | log_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 | |
1253 | bool |
1268 | bool |
1254 | is_match_expr (const char *expr) |
1269 | is_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 | |
1259 | bool |
1274 | bool |
1260 | match (const char *expr, object *ob, object *self, object *source, object *originator) |
1275 | match (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 | |
1280 | object * |
1295 | object * |
1281 | match_one (const char *expr, object *ob, object *self, object *source, object *originator) |
1296 | match_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); |
… | |
… | |
2129 | int mortals_size () |
2144 | int mortals_size () |
2130 | CODE: |
2145 | CODE: |
2131 | RETVAL = attachable::mortals.size (); |
2146 | RETVAL = attachable::mortals.size (); |
2132 | OUTPUT: RETVAL |
2147 | OUTPUT: RETVAL |
2133 | |
2148 | |
2134 | const char *slot_use_name (U32 slot) |
2149 | const_utf8_string slot_use_name (U32 slot) |
2135 | ALIAS: |
2150 | ALIAS: |
2136 | slot_nonuse_name = 1 |
2151 | slot_nonuse_name = 1 |
2137 | CODE: |
2152 | CODE: |
2138 | { |
2153 | { |
2139 | if (slot >= NUM_BODY_LOCATIONS) |
2154 | if (slot >= NUM_BODY_LOCATIONS) |
… | |
… | |
2555 | |
2570 | |
2556 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2571 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2557 | { |
2572 | { |
2558 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2573 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2559 | { |
2574 | { |
2560 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2575 | object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); |
2561 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2576 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2562 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2577 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2563 | |
2578 | |
2564 | if (ob->randomitems && !ob->above) |
2579 | if (ob->randomitems && !ob->above) |
2565 | { |
2580 | { |
… | |
… | |
2596 | |
2611 | |
2597 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2612 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2598 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2613 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2599 | |
2614 | |
2600 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2615 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2601 | regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2616 | regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2602 | |
2617 | |
2603 | for (int y = 0; y < THIS->height; ++y) |
2618 | for (int y = 0; y < THIS->height; ++y) |
2604 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2619 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2605 | |
2620 | |
2606 | sfree (THIS->regions, THIS->size ()); |
2621 | sfree (THIS->regions, THIS->size ()); |
… | |
… | |
3002 | sv_to (data, d->data); |
3017 | sv_to (data, d->data); |
3003 | STRLEN clen; |
3018 | STRLEN clen; |
3004 | char *cdata = SvPVbyte (chksum, clen); |
3019 | char *cdata = SvPVbyte (chksum, clen); |
3005 | clen = min (CHKSUM_MAXLEN, clen); |
3020 | clen = min (CHKSUM_MAXLEN, clen); |
3006 | |
3021 | |
|
|
3022 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
|
|
3023 | |
3007 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
3024 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
3008 | { |
3025 | { |
3009 | d->chksum_len = clen; |
3026 | d->chksum_len = clen; |
3010 | memcpy (d->chksum, cdata, clen); |
3027 | memcpy (d->chksum, cdata, clen); |
3011 | |
3028 | |
… | |
… | |
3084 | } |
3101 | } |
3085 | else |
3102 | else |
3086 | anim = &animation::create (name, av_len (av) + 1, facings); |
3103 | anim = &animation::create (name, av_len (av) + 1, facings); |
3087 | |
3104 | |
3088 | for (int i = 0; i < anim->num_animations; ++i) |
3105 | for (int i = 0; i < anim->num_animations; ++i) |
3089 | anim->faces [i] = face_find (SvPVutf8_nolen (*av_fetch (av, i, 1))); |
3106 | anim->faces [i] = face_find (cfSvPVutf8_nolen (*av_fetch (av, i, 1))); |
3090 | } |
3107 | } |
3091 | OUTPUT: RETVAL |
3108 | OUTPUT: RETVAL |
3092 | |
3109 | |
3093 | void invalidate_all () |
3110 | void invalidate_all () |
3094 | CODE: |
3111 | CODE: |