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); } |
… | |
… | |
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 | |
… | |
… | |
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 ()); |
… | |
… | |
3086 | } |
3101 | } |
3087 | else |
3102 | else |
3088 | anim = &animation::create (name, av_len (av) + 1, facings); |
3103 | anim = &animation::create (name, av_len (av) + 1, facings); |
3089 | |
3104 | |
3090 | for (int i = 0; i < anim->num_animations; ++i) |
3105 | for (int i = 0; i < anim->num_animations; ++i) |
3091 | 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))); |
3092 | } |
3107 | } |
3093 | OUTPUT: RETVAL |
3108 | OUTPUT: RETVAL |
3094 | |
3109 | |
3095 | void invalidate_all () |
3110 | void invalidate_all () |
3096 | CODE: |
3111 | CODE: |