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.342 by root, Fri Dec 18 03:49:46 2009 UTC vs.
Revision 1.346 by root, Sat Jan 16 17:41:01 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)
529 SV *sv = to_sv (static_cast<dynbuf *> (v)); 543 SV *sv = to_sv (static_cast<dynbuf *> (v));
530 SvUTF8_on (sv); 544 SvUTF8_on (sv);
531 return sv; 545 return sv;
532} 546}
533 547
534static 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; }
535static 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; }
536static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 550static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
537static 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); }
538static 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); }
539static 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); }
1064 CALL_CALL ("ext::books::make_book", G_VOID); 1078 CALL_CALL ("ext::books::make_book", G_VOID);
1065 CALL_END; 1079 CALL_END;
1066} 1080}
1067 1081
1068void 1082void
1069cfperl_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)
1070{ 1084{
1071 CALL_BEGIN (4); 1085 CALL_BEGIN (4);
1072 CALL_ARG (ns); 1086 CALL_ARG (ns);
1073 CALL_ARG (type); 1087 CALL_ARG (type);
1074 CALL_ARG_SV (newSVpv_utf8 (msg)); 1088 CALL_ARG_SV (newSVpv_utf8 (msg));
1103 CALL_CALL ("cf::mapscript::activate", G_VOID); 1117 CALL_CALL ("cf::mapscript::activate", G_VOID);
1104 CALL_END; 1118 CALL_END;
1105} 1119}
1106 1120
1107player * 1121player *
1108player::find (const char *name) 1122player::find (const_utf8_string name)
1109{ 1123{
1110 CALL_BEGIN (1); 1124 CALL_BEGIN (1);
1111 CALL_ARG (name); 1125 CALL_ARG (name);
1112 CALL_CALL ("cf::player::find", G_SCALAR); 1126 CALL_CALL ("cf::player::find", G_SCALAR);
1113 1127
1118 1132
1119 return retval; 1133 return retval;
1120} 1134}
1121 1135
1122maptile * 1136maptile *
1123find_style (const char *dirname, const char *stylename, int difficulty) 1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty)
1124{ 1138{
1125 CALL_BEGIN (3); 1139 CALL_BEGIN (3);
1126 CALL_ARG (dirname); 1140 CALL_ARG (dirname);
1127 CALL_ARG (stylename); 1141 CALL_ARG (stylename);
1128 CALL_ARG (difficulty); 1142 CALL_ARG (difficulty);
1135 1149
1136 return retval; 1150 return retval;
1137} 1151}
1138 1152
1139maptile * 1153maptile *
1140maptile::find_sync (const char *path, maptile *origin) 1154maptile::find_sync (const_utf8_string path, maptile *origin)
1141{ 1155{
1142 CALL_BEGIN (2); 1156 CALL_BEGIN (2);
1143 CALL_ARG (path); 1157 CALL_ARG (path);
1144 CALL_ARG (origin); 1158 CALL_ARG (origin);
1145 CALL_CALL ("cf::map::find_sync", G_SCALAR); 1159 CALL_CALL ("cf::map::find_sync", G_SCALAR);
1151 1165
1152 return retval; 1166 return retval;
1153} 1167}
1154 1168
1155maptile * 1169maptile *
1156maptile::find_async (const char *path, maptile *origin, bool load) 1170maptile::find_async (const_utf8_string path, maptile *origin, bool load)
1157{ 1171{
1158 CALL_BEGIN (3); 1172 CALL_BEGIN (3);
1159 CALL_ARG (path); 1173 CALL_ARG (path);
1160 CALL_ARG (origin); 1174 CALL_ARG (origin);
1161 CALL_ARG (load); 1175 CALL_ARG (load);
1190 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1204 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
1191 CALL_END; 1205 CALL_END;
1192} 1206}
1193 1207
1194void 1208void
1195object::player_goto (const char *path, int x, int y) 1209object::player_goto (const_utf8_string path, int x, int y)
1196{ 1210{
1197 if (type != PLAYER) 1211 if (type != PLAYER)
1198 return; 1212 return;
1199 1213
1200 CALL_BEGIN (4); 1214 CALL_BEGIN (4);
1204 CALL_ARG (y); 1218 CALL_ARG (y);
1205 CALL_CALL ("cf::object::player::goto", G_VOID); 1219 CALL_CALL ("cf::object::player::goto", G_VOID);
1206 CALL_END; 1220 CALL_END;
1207} 1221}
1208 1222
1209const char * 1223const_utf8_string
1210object::ref () const 1224object::ref () const
1211{ 1225{
1212 if (type == PLAYER) 1226 if (type == PLAYER)
1213 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);
1214 else 1228 else
1215 return 0; 1229 return 0;
1216} 1230}
1217 1231
1218object * 1232object *
1219object::deref (const char *ref) 1233object::deref (const_utf8_string ref)
1220{ 1234{
1221 object *retval = 0; 1235 object *retval = 0;
1222 1236
1223 if (ref) 1237 if (ref)
1224 { 1238 {
1234 1248
1235 return retval; 1249 return retval;
1236} 1250}
1237 1251
1238void 1252void
1239log_backtrace (const char *msg) 1253log_backtrace (const_utf8_string msg)
1240{ 1254{
1241#if HAVE_BACKTRACE 1255#if HAVE_BACKTRACE
1242 void *addr [20]; 1256 void *addr [20];
1243 int size = backtrace (addr, 20); 1257 int size = backtrace (addr, 20);
1244 1258
1250 CALL_END; 1264 CALL_END;
1251#endif 1265#endif
1252} 1266}
1253 1267
1254bool 1268bool
1255is_match_expr (const char *expr) 1269is_match_expr (const_utf8_string expr)
1256{ 1270{
1257 return !strncmp (expr, "match ", sizeof ("match ") - 1); 1271 return !strncmp (expr, "match ", sizeof ("match ") - 1);
1258} 1272}
1259 1273
1260bool 1274bool
1261match (const char *expr, object *ob, object *self, object *source, object *originator) 1275match (const_utf8_string expr, object *ob, object *self, object *source, object *originator)
1262{ 1276{
1263 if (!strncmp (expr, "match ", sizeof ("match ") - 1)) 1277 if (!strncmp (expr, "match ", sizeof ("match ") - 1))
1264 expr += sizeof ("match ") - 1; 1278 expr += sizeof ("match ") - 1;
1265 1279
1266 CALL_BEGIN (5); 1280 CALL_BEGIN (5);
1277 1291
1278 return matched; 1292 return matched;
1279} 1293}
1280 1294
1281object * 1295object *
1282match_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)
1283{ 1297{
1284 if (!strncmp (expr, "match ", sizeof ("match ") - 1)) 1298 if (!strncmp (expr, "match ", sizeof ("match ") - 1))
1285 expr += sizeof ("match ") - 1; 1299 expr += sizeof ("match ") - 1;
1286 1300
1287 CALL_BEGIN (5); 1301 CALL_BEGIN (5);
2130int mortals_size () 2144int mortals_size ()
2131 CODE: 2145 CODE:
2132 RETVAL = attachable::mortals.size (); 2146 RETVAL = attachable::mortals.size ();
2133 OUTPUT: RETVAL 2147 OUTPUT: RETVAL
2134 2148
2135const char *slot_use_name (U32 slot) 2149const_utf8_string slot_use_name (U32 slot)
2136 ALIAS: 2150 ALIAS:
2137 slot_nonuse_name = 1 2151 slot_nonuse_name = 1
2138 CODE: 2152 CODE:
2139{ 2153{
2140 if (slot >= NUM_BODY_LOCATIONS) 2154 if (slot >= NUM_BODY_LOCATIONS)
2556 2570
2557 if (IN_RANGE_EXC (offs, 0, idxlen)) 2571 if (IN_RANGE_EXC (offs, 0, idxlen))
2558 { 2572 {
2559 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2573 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2560 { 2574 {
2561 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2575 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2562 ob->flag [FLAG_NO_MAP_SAVE] = true; 2576 ob->flag [FLAG_NO_MAP_SAVE] = true;
2563 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2577 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2564 2578
2565 if (ob->randomitems && !ob->above) 2579 if (ob->randomitems && !ob->above)
2566 { 2580 {
2597 2611
2598 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2612 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2599 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2613 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2600 2614
2601 for (int i = av_len ((AV *)palette) + 1; i--; ) 2615 for (int i = av_len ((AV *)palette) + 1; i--; )
2602 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)));
2603 2617
2604 for (int y = 0; y < THIS->height; ++y) 2618 for (int y = 0; y < THIS->height; ++y)
2605 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2619 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2606 2620
2607 sfree (THIS->regions, THIS->size ()); 2621 sfree (THIS->regions, THIS->size ());
3003 sv_to (data, d->data); 3017 sv_to (data, d->data);
3004 STRLEN clen; 3018 STRLEN clen;
3005 char *cdata = SvPVbyte (chksum, clen); 3019 char *cdata = SvPVbyte (chksum, clen);
3006 clen = min (CHKSUM_MAXLEN, clen); 3020 clen = min (CHKSUM_MAXLEN, clen);
3007 3021
3022 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
3023
3008 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 3024 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
3009 { 3025 {
3010 d->chksum_len = clen; 3026 d->chksum_len = clen;
3011 memcpy (d->chksum, cdata, clen); 3027 memcpy (d->chksum, cdata, clen);
3012 3028
3085 } 3101 }
3086 else 3102 else
3087 anim = &animation::create (name, av_len (av) + 1, facings); 3103 anim = &animation::create (name, av_len (av) + 1, facings);
3088 3104
3089 for (int i = 0; i < anim->num_animations; ++i) 3105 for (int i = 0; i < anim->num_animations; ++i)
3090 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)));
3091} 3107}
3092 OUTPUT: RETVAL 3108 OUTPUT: RETVAL
3093 3109
3094void invalidate_all () 3110void invalidate_all ()
3095 CODE: 3111 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines