|
|
1 | #ifdef _WIN32 |
|
|
2 | # include <malloc.h> |
|
|
3 | #endif |
|
|
4 | |
1 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
2 | #include "perl.h" |
6 | #include "perl.h" |
3 | #include "XSUB.h" |
7 | #include "XSUB.h" |
4 | |
8 | |
5 | #include <string.h> |
9 | #include <string.h> |
… | |
… | |
13 | |
17 | |
14 | #include <pango/pango.h> |
18 | #include <pango/pango.h> |
15 | #include <pango/pangofc-fontmap.h> |
19 | #include <pango/pangofc-fontmap.h> |
16 | #include <pango/pangoft2.h> |
20 | #include <pango/pangoft2.h> |
17 | |
21 | |
|
|
22 | #ifndef _WIN32 |
18 | #include <sys/types.h> |
23 | # include <sys/types.h> |
19 | #include <sys/socket.h> |
24 | # include <sys/socket.h> |
20 | #include <netinet/in.h> |
25 | # include <netinet/in.h> |
21 | #include <netinet/tcp.h> |
26 | # include <netinet/tcp.h> |
22 | |
|
|
23 | #include <inttypes.h> |
27 | # include <inttypes.h> |
|
|
28 | #else |
|
|
29 | typedef unsigned char uint8_t; |
|
|
30 | typedef unsigned short uint16_t; |
|
|
31 | typedef unsigned int uint32_t; |
|
|
32 | typedef signed char int8_t; |
|
|
33 | typedef signed short int16_t; |
|
|
34 | typedef signed int int32_t; |
|
|
35 | #endif |
24 | |
36 | |
25 | #define FOW_DARKNESS 32 |
37 | #define FOW_DARKNESS 32 |
26 | |
38 | |
27 | #define MAP_EXTEND_X 32 |
39 | #define MAP_EXTEND_X 32 |
28 | #define MAP_EXTEND_Y 512 |
40 | #define MAP_EXTEND_Y 512 |
… | |
… | |
47 | { |
59 | { |
48 | /* use a random scale factor to account for unknown descenders, 0.8 works |
60 | /* use a random scale factor to account for unknown descenders, 0.8 works |
49 | * reasonably well with bitstream vera |
61 | * reasonably well with bitstream vera |
50 | */ |
62 | */ |
51 | PangoFontDescription *font = pango_context_get_font_description (context); |
63 | PangoFontDescription *font = pango_context_get_font_description (context); |
52 | pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10)); |
64 | |
|
|
65 | int height = self->base_height * (PANGO_SCALE * 8 / 10); |
|
|
66 | |
|
|
67 | if (pango_font_description_get_size (font) != height) |
|
|
68 | { |
|
|
69 | pango_font_description_set_absolute_size (font, height); |
|
|
70 | pango_layout_context_changed (self->pl); |
|
|
71 | } |
53 | } |
72 | } |
54 | |
73 | |
55 | static void |
74 | static void |
56 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
75 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
57 | { |
76 | { |
… | |
… | |
61 | |
80 | |
62 | *w = (*w + 3) & ~3; |
81 | *w = (*w + 3) & ~3; |
63 | if (!*w) *w = 1; |
82 | if (!*w) *w = 1; |
64 | if (!*h) *h = 1; |
83 | if (!*h) *h = 1; |
65 | } |
84 | } |
|
|
85 | |
|
|
86 | typedef uint16_t mapface; |
66 | |
87 | |
67 | typedef struct { |
88 | typedef struct { |
68 | GLint name; |
89 | GLint name; |
69 | int w, h; |
90 | int w, h; |
70 | float s, t; |
91 | float s, t; |
71 | } mapface; |
92 | uint8_t r, g, b, a; |
|
|
93 | } maptex; |
72 | |
94 | |
73 | typedef struct { |
95 | typedef struct { |
74 | int16_t darkness; |
96 | int16_t darkness; |
75 | uint16_t face[3]; |
97 | mapface face[3]; |
76 | } mapcell; |
98 | } mapcell; |
77 | |
99 | |
78 | typedef struct { |
100 | typedef struct { |
79 | int32_t c0, c1; |
101 | int32_t c0, c1; |
80 | mapcell *col; |
102 | mapcell *col; |
81 | } maprow; |
103 | } maprow; |
82 | |
104 | |
83 | typedef struct map { |
105 | typedef struct map { |
84 | int x, y, w, h; |
106 | int x, y, w, h; |
85 | int vx, vy; |
107 | int ox, oy; /* offset to virtual global coordinate system */ |
86 | int faces; |
108 | int faces; |
87 | mapface *face; |
109 | mapface *face; |
88 | |
110 | |
|
|
111 | int texs; |
|
|
112 | maptex *tex; |
|
|
113 | |
89 | uint32_t rows; |
114 | int32_t rows; |
90 | maprow *row; |
115 | maprow *row; |
91 | } *CFClient__Map; |
116 | } *CFClient__Map; |
92 | |
117 | |
93 | static char * |
118 | static char * |
94 | prepend (char *ptr, int sze, int inc) |
119 | prepend (char *ptr, int sze, int inc) |
… | |
… | |
113 | } |
138 | } |
114 | |
139 | |
115 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
140 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
116 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
141 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
117 | |
142 | |
|
|
143 | static maprow * |
|
|
144 | map_get_row (CFClient__Map self, int y) |
|
|
145 | { |
|
|
146 | if (0 > y) |
|
|
147 | { |
|
|
148 | int extend = - y + MAP_EXTEND_Y; |
|
|
149 | Prepend (maprow, self->row, self->rows, extend); |
|
|
150 | |
|
|
151 | self->rows += extend; |
|
|
152 | self->y += extend; |
|
|
153 | y += extend; |
|
|
154 | } |
|
|
155 | else if (y >= self->rows) |
|
|
156 | { |
|
|
157 | int extend = y - self->rows + MAP_EXTEND_Y; |
|
|
158 | Append (maprow, self->row, self->rows, extend); |
|
|
159 | self->rows += extend; |
|
|
160 | } |
|
|
161 | |
|
|
162 | return self->row + y; |
|
|
163 | } |
|
|
164 | |
|
|
165 | static mapcell * |
|
|
166 | row_get_cell (maprow *row, int x) |
|
|
167 | { |
|
|
168 | if (!row->col) |
|
|
169 | { |
|
|
170 | Newz (0, row->col, MAP_EXTEND_X, mapcell); |
|
|
171 | row->c0 = x - MAP_EXTEND_X / 4; |
|
|
172 | row->c1 = row->c0 + MAP_EXTEND_X; |
|
|
173 | } |
|
|
174 | |
|
|
175 | if (row->c0 > x) |
|
|
176 | { |
|
|
177 | int extend = row->c0 - x + MAP_EXTEND_X; |
|
|
178 | Prepend (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
179 | row->c0 -= extend; |
|
|
180 | } |
|
|
181 | else if (x >= row->c1) |
|
|
182 | { |
|
|
183 | int extend = x - row->c1 + MAP_EXTEND_X; |
|
|
184 | Append (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
185 | row->c1 += extend; |
|
|
186 | } |
|
|
187 | |
|
|
188 | return row->col + (x - row->c0); |
|
|
189 | } |
|
|
190 | |
|
|
191 | static mapcell * |
|
|
192 | map_get_cell (CFClient__Map self, int x, int y) |
|
|
193 | { |
|
|
194 | return row_get_cell (map_get_row (self, y), x); |
|
|
195 | } |
|
|
196 | |
118 | static void |
197 | static void |
119 | map_clear (CFClient__Map self) |
198 | map_clear (CFClient__Map self) |
120 | { |
199 | { |
121 | int r; |
200 | int r; |
122 | |
201 | |
… | |
… | |
125 | |
204 | |
126 | Safefree (self->row); |
205 | Safefree (self->row); |
127 | |
206 | |
128 | self->x = 0; |
207 | self->x = 0; |
129 | self->y = 0; |
208 | self->y = 0; |
130 | self->vx = 0; |
209 | self->ox = 0; |
131 | self->vy = 0; |
210 | self->oy = 0; |
132 | self->row = 0; |
211 | self->row = 0; |
133 | self->rows = 0; |
212 | self->rows = 0; |
134 | } |
213 | } |
135 | |
214 | |
136 | static void |
215 | static void |
137 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
216 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
138 | { |
217 | { |
139 | int x, y; |
218 | int x, y; |
|
|
219 | maprow *row; |
140 | |
220 | |
141 | for (y = y0; y < y0 + h; y++) |
221 | for (y = y0; y < y0 + h; y++) |
142 | if (y >= 0) |
222 | if (y >= 0) |
143 | { |
223 | { |
144 | if (y >= self->rows) |
224 | if (y >= self->rows) |
145 | break; |
225 | break; |
146 | |
226 | |
147 | maprow *row = self->row + y; |
227 | row = self->row + y; |
148 | |
228 | |
149 | for (x = x0; x < x0 + w; x++) |
229 | for (x = x0; x < x0 + w; x++) |
150 | if (x >= row->c0) |
230 | if (x >= row->c0) |
151 | { |
231 | { |
152 | if (x >= row->c1) |
232 | if (x >= row->c1) |
… | |
… | |
161 | |
241 | |
162 | PROTOTYPES: ENABLE |
242 | PROTOTYPES: ENABLE |
163 | |
243 | |
164 | BOOT: |
244 | BOOT: |
165 | { |
245 | { |
|
|
246 | HV *stash = gv_stashpv ("CFClient", 1); |
|
|
247 | static const struct { |
|
|
248 | const char *name; |
|
|
249 | IV iv; |
|
|
250 | } *civ, const_iv[] = { |
|
|
251 | # define const_iv(name) { # name, (IV)name } |
|
|
252 | const_iv (SDL_ACTIVEEVENT), |
|
|
253 | const_iv (SDL_KEYDOWN), |
|
|
254 | const_iv (SDL_KEYUP), |
|
|
255 | const_iv (SDL_MOUSEMOTION), |
|
|
256 | const_iv (SDL_MOUSEBUTTONDOWN), |
|
|
257 | const_iv (SDL_MOUSEBUTTONUP), |
|
|
258 | const_iv (SDL_JOYAXISMOTION), |
|
|
259 | const_iv (SDL_JOYBALLMOTION), |
|
|
260 | const_iv (SDL_JOYHATMOTION), |
|
|
261 | const_iv (SDL_JOYBUTTONDOWN), |
|
|
262 | const_iv (SDL_JOYBUTTONUP), |
|
|
263 | const_iv (SDL_QUIT), |
|
|
264 | const_iv (SDL_SYSWMEVENT), |
|
|
265 | const_iv (SDL_EVENT_RESERVEDA), |
|
|
266 | const_iv (SDL_EVENT_RESERVEDB), |
|
|
267 | const_iv (SDL_VIDEORESIZE), |
|
|
268 | const_iv (SDL_VIDEOEXPOSE), |
|
|
269 | const_iv (SDL_USEREVENT), |
|
|
270 | const_iv (SDLK_KP0), |
|
|
271 | const_iv (SDLK_KP1), |
|
|
272 | const_iv (SDLK_KP2), |
|
|
273 | const_iv (SDLK_KP3), |
|
|
274 | const_iv (SDLK_KP4), |
|
|
275 | const_iv (SDLK_KP5), |
|
|
276 | const_iv (SDLK_KP6), |
|
|
277 | const_iv (SDLK_KP7), |
|
|
278 | const_iv (SDLK_KP8), |
|
|
279 | const_iv (SDLK_KP9), |
|
|
280 | const_iv (SDLK_KP_PERIOD), |
|
|
281 | const_iv (SDLK_KP_DIVIDE), |
|
|
282 | const_iv (SDLK_KP_MULTIPLY), |
|
|
283 | const_iv (SDLK_KP_MINUS), |
|
|
284 | const_iv (SDLK_KP_PLUS), |
|
|
285 | const_iv (SDLK_KP_ENTER), |
|
|
286 | const_iv (SDLK_KP_EQUALS), |
|
|
287 | const_iv (SDLK_UP), |
|
|
288 | const_iv (SDLK_DOWN), |
|
|
289 | const_iv (SDLK_RIGHT), |
|
|
290 | const_iv (SDLK_LEFT), |
|
|
291 | const_iv (SDLK_INSERT), |
|
|
292 | const_iv (SDLK_HOME), |
|
|
293 | const_iv (SDLK_END), |
|
|
294 | const_iv (SDLK_PAGEUP), |
|
|
295 | const_iv (SDLK_PAGEDOWN), |
|
|
296 | const_iv (SDLK_F1), |
|
|
297 | const_iv (SDLK_F2), |
|
|
298 | const_iv (SDLK_F3), |
|
|
299 | const_iv (SDLK_F4), |
|
|
300 | const_iv (SDLK_F5), |
|
|
301 | const_iv (SDLK_F6), |
|
|
302 | const_iv (SDLK_F7), |
|
|
303 | const_iv (SDLK_F8), |
|
|
304 | const_iv (SDLK_F9), |
|
|
305 | const_iv (SDLK_F10), |
|
|
306 | const_iv (SDLK_F11), |
|
|
307 | const_iv (SDLK_F12), |
|
|
308 | const_iv (SDLK_F13), |
|
|
309 | const_iv (SDLK_F14), |
|
|
310 | const_iv (SDLK_F15), |
|
|
311 | const_iv (SDLK_NUMLOCK), |
|
|
312 | const_iv (SDLK_CAPSLOCK), |
|
|
313 | const_iv (SDLK_SCROLLOCK), |
|
|
314 | const_iv (SDLK_RSHIFT), |
|
|
315 | const_iv (SDLK_LSHIFT), |
|
|
316 | const_iv (SDLK_RCTRL), |
|
|
317 | const_iv (SDLK_LCTRL), |
|
|
318 | const_iv (SDLK_RALT), |
|
|
319 | const_iv (SDLK_LALT), |
|
|
320 | const_iv (SDLK_RMETA), |
|
|
321 | const_iv (SDLK_LMETA), |
|
|
322 | const_iv (SDLK_LSUPER), |
|
|
323 | const_iv (SDLK_RSUPER), |
|
|
324 | const_iv (SDLK_MODE), |
|
|
325 | const_iv (SDLK_COMPOSE), |
|
|
326 | const_iv (SDLK_HELP), |
|
|
327 | const_iv (SDLK_PRINT), |
|
|
328 | const_iv (SDLK_SYSREQ), |
|
|
329 | const_iv (SDLK_BREAK), |
|
|
330 | const_iv (SDLK_MENU), |
|
|
331 | const_iv (SDLK_POWER), |
|
|
332 | const_iv (SDLK_EURO), |
|
|
333 | const_iv (SDLK_UNDO), |
|
|
334 | const_iv (KMOD_NONE), |
|
|
335 | const_iv (KMOD_LSHIFT), |
|
|
336 | const_iv (KMOD_RSHIFT), |
|
|
337 | const_iv (KMOD_LCTRL), |
|
|
338 | const_iv (KMOD_RCTRL), |
|
|
339 | const_iv (KMOD_LALT), |
|
|
340 | const_iv (KMOD_RALT), |
|
|
341 | const_iv (KMOD_LMETA), |
|
|
342 | const_iv (KMOD_RMETA), |
|
|
343 | const_iv (KMOD_NUM), |
|
|
344 | const_iv (KMOD_CAPS), |
|
|
345 | const_iv (KMOD_MODE), |
|
|
346 | const_iv (KMOD_CTRL), |
|
|
347 | const_iv (KMOD_SHIFT), |
|
|
348 | const_iv (KMOD_ALT), |
|
|
349 | const_iv (KMOD_META) |
|
|
350 | # undef const_iv |
|
|
351 | }; |
|
|
352 | |
|
|
353 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
354 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
355 | |
166 | fontmap = pango_ft2_font_map_new (); |
356 | fontmap = pango_ft2_font_map_new (); |
167 | pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0); |
357 | pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0); |
168 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
358 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
169 | } |
359 | } |
|
|
360 | |
|
|
361 | int |
|
|
362 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) |
|
|
363 | |
|
|
364 | void |
|
|
365 | SDL_Quit () |
|
|
366 | |
|
|
367 | void |
|
|
368 | SDL_ListModes () |
|
|
369 | PPCODE: |
|
|
370 | { |
|
|
371 | SDL_Rect **m; |
|
|
372 | |
|
|
373 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5); |
|
|
374 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5); |
|
|
375 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5); |
|
|
376 | SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1); |
|
|
377 | |
|
|
378 | SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); |
|
|
379 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
|
|
380 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
|
|
381 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
|
|
382 | |
|
|
383 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
|
|
384 | SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); |
|
|
385 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 0); |
|
|
386 | |
|
|
387 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
|
|
388 | |
|
|
389 | if (m && m != (SDL_Rect **)-1) |
|
|
390 | while (*m) |
|
|
391 | { |
|
|
392 | AV *av = newAV (); |
|
|
393 | av_push (av, newSViv ((*m)->w)); |
|
|
394 | av_push (av, newSViv ((*m)->h)); |
|
|
395 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
396 | |
|
|
397 | ++m; |
|
|
398 | } |
|
|
399 | } |
|
|
400 | |
|
|
401 | int |
|
|
402 | SDL_SetVideoMode (int w, int h, int fullscreen) |
|
|
403 | CODE: |
|
|
404 | RETVAL = !!SDL_SetVideoMode ( |
|
|
405 | w, h, 0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0) |
|
|
406 | ); |
|
|
407 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
|
|
408 | OUTPUT: |
|
|
409 | RETVAL |
170 | |
410 | |
171 | void |
411 | void |
172 | lowdelay (int fd, int val = 1) |
412 | lowdelay (int fd, int val = 1) |
173 | CODE: |
413 | CODE: |
|
|
414 | #ifndef _WIN32 |
174 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
415 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
|
|
416 | #endif |
175 | |
417 | |
176 | char * |
418 | char * |
177 | gl_version () |
419 | gl_version () |
178 | CODE: |
420 | CODE: |
179 | RETVAL = (char *)glGetString (GL_VERSION); |
421 | RETVAL = (char *)glGetString (GL_VERSION); |
… | |
… | |
216 | SDL_RWops *rw = ix |
458 | SDL_RWops *rw = ix |
217 | ? SDL_RWFromFile (image, "r") |
459 | ? SDL_RWFromFile (image, "r") |
218 | : SDL_RWFromConstMem (image, image_len); |
460 | : SDL_RWFromConstMem (image, image_len); |
219 | |
461 | |
220 | if (!rw) |
462 | if (!rw) |
221 | croak ("load_image: unable to open file"); |
463 | croak ("load_image: %s", SDL_GetError ()); |
222 | |
464 | |
223 | surface = IMG_Load_RW (rw, 1); |
465 | surface = IMG_Load_RW (rw, 1); |
224 | if (!surface) |
466 | if (!surface) |
225 | croak ("load_image: unable to read file"); |
467 | croak ("load_image: %s", SDL_GetError ()); |
226 | |
468 | |
227 | fmt.palette = NULL; |
469 | fmt.palette = NULL; |
228 | fmt.BitsPerPixel = 32; |
470 | fmt.BitsPerPixel = 32; |
229 | fmt.BytesPerPixel = 4; |
471 | fmt.BytesPerPixel = 4; |
|
|
472 | #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
230 | fmt.Rmask = 0x000000ff; |
473 | fmt.Rmask = 0x000000ff; |
231 | fmt.Gmask = 0x0000ff00; |
474 | fmt.Gmask = 0x0000ff00; |
232 | fmt.Bmask = 0x00ff0000; |
475 | fmt.Bmask = 0x00ff0000; |
233 | fmt.Amask = 0xff000000; |
476 | fmt.Amask = 0xff000000; |
|
|
477 | #else |
|
|
478 | fmt.Rmask = 0xff000000; |
|
|
479 | fmt.Gmask = 0x00ff0000; |
|
|
480 | fmt.Bmask = 0x0000ff00; |
|
|
481 | fmt.Amask = 0x000000ff; |
|
|
482 | #endif |
234 | fmt.Rloss = 0; |
483 | fmt.Rloss = 0; |
235 | fmt.Gloss = 0; |
484 | fmt.Gloss = 0; |
236 | fmt.Bloss = 0; |
485 | fmt.Bloss = 0; |
237 | fmt.Aloss = 0; |
486 | fmt.Aloss = 0; |
238 | fmt.Rshift = 0; |
487 | fmt.Rshift = 0; |
… | |
… | |
242 | fmt.colorkey = 0; |
491 | fmt.colorkey = 0; |
243 | fmt.alpha = 0; |
492 | fmt.alpha = 0; |
244 | |
493 | |
245 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
494 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
246 | |
495 | |
|
|
496 | assert (surface2->pitch == surface2->w * 4); |
|
|
497 | |
247 | EXTEND (SP, 5); |
498 | EXTEND (SP, 5); |
248 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
499 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
249 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
500 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
250 | SDL_LockSurface (surface2); |
501 | SDL_LockSurface (surface2); |
251 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
502 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
252 | SDL_UnlockSurface (surface2); |
503 | SDL_UnlockSurface (surface2); |
253 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
504 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
254 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
505 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
255 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV))); |
506 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
256 | |
507 | |
257 | SDL_FreeSurface (surface); |
508 | SDL_FreeSurface (surface); |
258 | SDL_FreeSurface (surface2); |
509 | SDL_FreeSurface (surface2); |
259 | } |
510 | } |
260 | |
511 | |
261 | void |
512 | void |
|
|
513 | average (int x, int y, uint32_t *data) |
|
|
514 | PPCODE: |
|
|
515 | { |
|
|
516 | uint32_t r = 0, g = 0, b = 0, a = 0; |
|
|
517 | |
|
|
518 | x = y = x * y; |
|
|
519 | |
|
|
520 | while (x--) |
|
|
521 | { |
|
|
522 | uint32_t p = *data++; |
|
|
523 | |
|
|
524 | r += (p ) & 255; |
|
|
525 | g += (p >> 8) & 255; |
|
|
526 | b += (p >> 16) & 255; |
|
|
527 | a += (p >> 24) & 255; |
|
|
528 | } |
|
|
529 | |
|
|
530 | EXTEND (SP, 4); |
|
|
531 | PUSHs (sv_2mortal (newSViv (r / y))); |
|
|
532 | PUSHs (sv_2mortal (newSViv (g / y))); |
|
|
533 | PUSHs (sv_2mortal (newSViv (b / y))); |
|
|
534 | PUSHs (sv_2mortal (newSViv (a / y))); |
|
|
535 | } |
|
|
536 | |
|
|
537 | void |
262 | fatal (char *message) |
538 | fatal (char *message) |
263 | CODE: |
539 | CODE: |
264 | #ifdef WIN32 |
540 | #ifdef _WIN32 |
265 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
541 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
266 | #else |
542 | #else |
267 | fprintf (stderr, "%s\n", message); |
543 | fprintf (stderr, "FATAL: %s\n", message); |
268 | #endif |
544 | #endif |
269 | exit (1); |
545 | exit (1); |
270 | |
546 | |
271 | MODULE = CFClient PACKAGE = CFClient::Layout |
547 | MODULE = CFClient PACKAGE = CFClient::Layout |
272 | |
548 | |
… | |
… | |
303 | STRLEN textlen; |
579 | STRLEN textlen; |
304 | char *text = SvPVutf8 (text_, textlen); |
580 | char *text = SvPVutf8 (text_, textlen); |
305 | |
581 | |
306 | pango_layout_set_markup (self->pl, text, textlen); |
582 | pango_layout_set_markup (self->pl, text, textlen); |
307 | } |
583 | } |
|
|
584 | |
|
|
585 | SV * |
|
|
586 | get_text (CFClient::Layout self) |
|
|
587 | CODE: |
|
|
588 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
|
|
589 | SvUTF8_on (RETVAL); |
|
|
590 | OUTPUT: |
|
|
591 | RETVAL |
308 | |
592 | |
309 | void |
593 | void |
310 | set_height (CFClient::Layout self, int base_height) |
594 | set_height (CFClient::Layout self, int base_height) |
311 | CODE: |
595 | CODE: |
312 | self->base_height = base_height; |
596 | self->base_height = base_height; |
… | |
… | |
426 | |
710 | |
427 | CFClient::Map |
711 | CFClient::Map |
428 | new (SV *class, int map_width, int map_height) |
712 | new (SV *class, int map_width, int map_height) |
429 | CODE: |
713 | CODE: |
430 | New (0, RETVAL, 1, struct map); |
714 | New (0, RETVAL, 1, struct map); |
431 | RETVAL->x = 0; |
715 | RETVAL->x = 0; |
432 | RETVAL->y = 0; |
716 | RETVAL->y = 0; |
433 | RETVAL->w = map_width; |
717 | RETVAL->w = map_width; |
434 | RETVAL->h = map_height; |
718 | RETVAL->h = map_height; |
435 | RETVAL->vx = 0; |
719 | RETVAL->ox = 0; |
436 | RETVAL->vy = 0; |
720 | RETVAL->oy = 0; |
437 | RETVAL->faces = 8192; |
721 | RETVAL->faces = 8192; |
438 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
722 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
|
|
723 | RETVAL->texs = 8192; |
|
|
724 | Newz (0, RETVAL->tex, RETVAL->texs, maptex); |
439 | RETVAL->rows = 0; |
725 | RETVAL->rows = 0; |
440 | RETVAL->row = 0; |
726 | RETVAL->row = 0; |
441 | OUTPUT: |
727 | OUTPUT: |
442 | RETVAL |
728 | RETVAL |
443 | |
729 | |
… | |
… | |
454 | clear (CFClient::Map self) |
740 | clear (CFClient::Map self) |
455 | CODE: |
741 | CODE: |
456 | map_clear (self); |
742 | map_clear (self); |
457 | |
743 | |
458 | void |
744 | void |
459 | set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t) |
745 | set_face (CFClient::Map self, int face, int texid) |
460 | CODE: |
746 | CODE: |
461 | { |
747 | { |
462 | while (self->faces < face) |
748 | while (self->faces <= face) |
463 | { |
749 | { |
464 | Append (mapface, self->face, self->faces, self->faces); |
750 | Append (mapface, self->face, self->faces, self->faces); |
465 | self->faces *= 2; |
751 | self->faces *= 2; |
466 | } |
752 | } |
467 | |
753 | |
468 | self->face [face].name = name; |
|
|
469 | self->face [face].w = w; |
754 | self->face [face] = texid; |
470 | self->face [face].h = h; |
|
|
471 | self->face [face].s = s; |
|
|
472 | self->face [face].t = t; |
|
|
473 | } |
755 | } |
|
|
756 | |
|
|
757 | void |
|
|
758 | set_texture (CFClient::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
|
|
759 | CODE: |
|
|
760 | { |
|
|
761 | while (self->texs <= texid) |
|
|
762 | { |
|
|
763 | Append (maptex, self->tex, self->texs, self->texs); |
|
|
764 | self->texs *= 2; |
|
|
765 | } |
|
|
766 | |
|
|
767 | { |
|
|
768 | maptex *tex = self->tex + texid; |
|
|
769 | |
|
|
770 | tex->name = name; |
|
|
771 | tex->w = w; |
|
|
772 | tex->h = h; |
|
|
773 | tex->s = s; |
|
|
774 | tex->t = t; |
|
|
775 | tex->r = r; |
|
|
776 | tex->g = g; |
|
|
777 | tex->b = b; |
|
|
778 | tex->a = a; |
|
|
779 | } |
|
|
780 | } |
|
|
781 | |
|
|
782 | int |
|
|
783 | ox (CFClient::Map self) |
|
|
784 | ALIAS: |
|
|
785 | oy = 1 |
|
|
786 | CODE: |
|
|
787 | switch (ix) |
|
|
788 | { |
|
|
789 | case 0: RETVAL = self->ox; break; |
|
|
790 | case 1: RETVAL = self->oy; break; |
|
|
791 | } |
|
|
792 | OUTPUT: |
|
|
793 | RETVAL |
474 | |
794 | |
475 | void |
795 | void |
476 | scroll (CFClient::Map self, int dx, int dy) |
796 | scroll (CFClient::Map self, int dx, int dy) |
477 | CODE: |
797 | CODE: |
478 | { |
798 | { |
… | |
… | |
484 | if (dy > 0) |
804 | if (dy > 0) |
485 | map_blank (self, self->x, self->y, self->w, dy - 1); |
805 | map_blank (self, self->x, self->y, self->w, dy - 1); |
486 | else if (dy < 0) |
806 | else if (dy < 0) |
487 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
807 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
488 | |
808 | |
489 | self->x += dx; |
809 | self->ox += dx; self->x += dx; |
490 | self->y += dy; |
810 | self->oy += dy; self->y += dy; |
491 | |
811 | |
492 | while (self->y < 0) |
812 | while (self->y < 0) |
493 | { |
813 | { |
494 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
814 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
495 | |
815 | |
… | |
… | |
502 | map1a_update (CFClient::Map self, SV *data_) |
822 | map1a_update (CFClient::Map self, SV *data_) |
503 | CODE: |
823 | CODE: |
504 | { |
824 | { |
505 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
825 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
506 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
826 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
507 | |
827 | mapcell *cell; |
|
|
828 | int x, y, flags; |
|
|
829 | |
508 | while (data < data_end) |
830 | while (data < data_end) |
509 | { |
831 | { |
510 | int flags = (data [0] << 8) + data [1]; data += 2; |
832 | flags = (data [0] << 8) + data [1]; data += 2; |
511 | |
833 | |
512 | int x = ((flags >> 10) & 63) + self->x; |
834 | x = ((flags >> 10) & 63) + self->x; |
513 | int y = ((flags >> 4) & 63) + self->y; |
835 | y = ((flags >> 4) & 63) + self->y; |
514 | |
836 | |
515 | while (y >= self->rows) |
837 | cell = map_get_cell (self, x, y); |
516 | { |
|
|
517 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
|
|
518 | |
|
|
519 | self->rows += MAP_EXTEND_Y; |
|
|
520 | } |
|
|
521 | |
|
|
522 | maprow *row = self->row + y; |
|
|
523 | |
|
|
524 | if (!row->col) |
|
|
525 | { |
|
|
526 | Newz (0, row->col, MAP_EXTEND_X, mapcell); |
|
|
527 | row->c0 = self->x - MAP_EXTEND_X / 4; |
|
|
528 | row->c1 = row->c0 + MAP_EXTEND_X; |
|
|
529 | } |
|
|
530 | |
|
|
531 | if (row->c0 > x) |
|
|
532 | { |
|
|
533 | int extend = row->c0 - x + MAP_EXTEND_X; |
|
|
534 | Prepend (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
535 | row->c0 -= extend; |
|
|
536 | } |
|
|
537 | else if (x >= row->c1) |
|
|
538 | { |
|
|
539 | int extend = x - row->c1 + MAP_EXTEND_X; |
|
|
540 | Append (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
541 | row->c1 += extend; |
|
|
542 | } |
|
|
543 | |
|
|
544 | assert (y >= 0); |
|
|
545 | assert (y < self->rows); |
|
|
546 | assert (x >= row->c0); |
|
|
547 | assert (x < row->c1); |
|
|
548 | mapcell *cell = row->col + (x - row->c0); |
|
|
549 | |
838 | |
550 | if (flags & 15) |
839 | if (flags & 15) |
551 | { |
840 | { |
552 | if (cell->darkness < 0 && x < self->w && y < self->h) |
841 | if (cell->darkness < 0) |
553 | { |
842 | { |
554 | cell->darkness = 0; |
843 | cell->darkness = 0; |
555 | cell->face [0] = 0; |
844 | cell->face [0] = 0; |
556 | cell->face [1] = 0; |
845 | cell->face [1] = 0; |
557 | cell->face [2] = 0; |
846 | cell->face [2] = 0; |
558 | } |
847 | } |
559 | |
848 | |
560 | cell->darkness = flags & 8 ? *data++ : 255; |
849 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
850 | |
|
|
851 | //TODO: don't trust server data to be in-range(!) |
561 | |
852 | |
562 | if (flags & 4) |
853 | if (flags & 4) |
563 | { |
854 | { |
564 | cell->face [0] = (data [0] << 8) + data [1]; data += 2; |
855 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
565 | } |
856 | } |
566 | |
857 | |
567 | if (flags & 2) |
858 | if (flags & 2) |
568 | { |
859 | { |
569 | cell->face [1] = (data [0] << 8) + data [1]; data += 2; |
860 | cell->face [1] = self->face [(data [0] << 8) + data [1]]; data += 2; |
570 | } |
861 | } |
571 | |
862 | |
572 | if (flags & 1) |
863 | if (flags & 1) |
573 | { |
864 | { |
574 | cell->face [2] = (data [0] << 8) + data [1]; data += 2; |
865 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
575 | } |
866 | } |
576 | } |
867 | } |
577 | else |
868 | else |
578 | cell->darkness = -1; |
869 | cell->darkness = -1; |
579 | } |
870 | } |
580 | } |
871 | } |
581 | |
872 | |
|
|
873 | SV * |
|
|
874 | mapmap (CFClient::Map self, int w, int h) |
|
|
875 | CODE: |
|
|
876 | { |
|
|
877 | int x0, x1, x; |
|
|
878 | int y0, y1, y; |
|
|
879 | int z; |
|
|
880 | SV *map_sv = newSV (w * h * sizeof (uint32_t)); |
|
|
881 | uint32_t *map = (uint32_t *)SvPVX (map_sv); |
|
|
882 | |
|
|
883 | SvPOK_only (map_sv); |
|
|
884 | SvCUR_set (map_sv, w * h * sizeof (uint32_t)); |
|
|
885 | |
|
|
886 | x0 = self->x - w / 2; x1 = x0 + w; |
|
|
887 | y0 = self->y - h / 2; y1 = y0 + h; |
|
|
888 | |
|
|
889 | for (y = y0; y < y1; y++) |
|
|
890 | { |
|
|
891 | maprow *row = 0 <= y && y < self->rows |
|
|
892 | ? self->row + y |
|
|
893 | : 0; |
|
|
894 | |
|
|
895 | for (x = x0; x < x1; x++) |
|
|
896 | { |
|
|
897 | int r = 32, g = 32, b = 32, a = 192; |
|
|
898 | |
|
|
899 | if (row && row->c0 <= x && x < row->c1) |
|
|
900 | { |
|
|
901 | mapcell *cell = row->col + (x - row->c0); |
|
|
902 | |
|
|
903 | for (z = 0; z <= 0; z++) |
|
|
904 | { |
|
|
905 | mapface face = cell->face [z]; |
|
|
906 | |
|
|
907 | if (face) |
|
|
908 | { |
|
|
909 | maptex tex = self->tex [face]; |
|
|
910 | int a0 = 255 - tex.a; |
|
|
911 | int a1 = tex.a; |
|
|
912 | |
|
|
913 | r = (r * a0 + tex.r * a1) / 255; |
|
|
914 | g = (g * a0 + tex.g * a1) / 255; |
|
|
915 | b = (b * a0 + tex.b * a1) / 255; |
|
|
916 | a = (a * a0 + tex.a * a1) / 255; |
|
|
917 | } |
|
|
918 | } |
|
|
919 | } |
|
|
920 | |
|
|
921 | *map++ = (r ) |
|
|
922 | | (g << 8) |
|
|
923 | | (b << 16) |
|
|
924 | | (a << 24); |
|
|
925 | } |
|
|
926 | } |
|
|
927 | |
|
|
928 | RETVAL = map_sv; |
|
|
929 | } |
|
|
930 | OUTPUT: |
|
|
931 | RETVAL |
|
|
932 | |
582 | void |
933 | void |
583 | draw (CFClient::Map self, int x0, int y0, int sw, int sh) |
934 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
584 | PPCODE: |
935 | PPCODE: |
585 | { |
936 | { |
|
|
937 | int vx, vy; |
|
|
938 | int x, y, z; |
|
|
939 | int last_name; |
|
|
940 | mapface face; |
586 | int sw4 = (sw + 3) & ~3; |
941 | int sw4 = (sw + 3) & ~3; |
587 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
942 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
588 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
943 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
589 | |
944 | |
|
|
945 | memset (darkness, 255, sw4 * sh); |
590 | SvPOK_only (darkness_sv); |
946 | SvPOK_only (darkness_sv); |
591 | SvCUR_set (darkness_sv, sw4 * sh); |
947 | SvCUR_set (darkness_sv, sw4 * sh); |
592 | |
948 | |
|
|
949 | vx = self->x + (self->w - sw) / 2 - shift_x; |
|
|
950 | vy = self->y + (self->h - sh) / 2 - shift_y; |
|
|
951 | |
|
|
952 | /* |
593 | int vx = self->vx = self->w >= sw |
953 | int vx = self->vx = self->w >= sw |
594 | ? self->x + (self->w - sw) / 2 |
954 | ? self->x + (self->w - sw) / 2 |
595 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
955 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
596 | |
956 | |
597 | int vy = self->vy = self->h >= sh |
957 | int vy = self->vy = self->h >= sh |
598 | ? self->y + (self->h - sh) / 2 |
958 | ? self->y + (self->h - sh) / 2 |
599 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
959 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
960 | */ |
600 | |
961 | |
601 | glColor4ub (255, 255, 255, 255); |
962 | glColor4ub (255, 255, 255, 255); |
602 | |
963 | |
603 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
964 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
604 | glEnable (GL_BLEND); |
965 | glEnable (GL_BLEND); |
605 | glEnable (GL_TEXTURE_2D); |
966 | glEnable (GL_TEXTURE_2D); |
606 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
967 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
607 | |
968 | |
608 | int x, y, z; |
|
|
609 | |
|
|
610 | int last_name = 0; |
|
|
611 | |
|
|
612 | glBegin (GL_QUADS); |
969 | glBegin (GL_QUADS); |
|
|
970 | |
|
|
971 | last_name = 0; |
613 | |
972 | |
614 | for (z = 0; z < 3; z++) |
973 | for (z = 0; z < 3; z++) |
615 | for (y = 0; y < sh; y++) |
974 | for (y = 0; y < sh; y++) |
616 | if (0 <= y + vy && y + vy < self->rows) |
975 | if (0 <= y + vy && y + vy < self->rows) |
617 | { |
976 | { |
… | |
… | |
624 | |
983 | |
625 | darkness[y * sw4 + x] = cell->darkness < 0 |
984 | darkness[y * sw4 + x] = cell->darkness < 0 |
626 | ? 255 - FOW_DARKNESS |
985 | ? 255 - FOW_DARKNESS |
627 | : 255 - cell->darkness; |
986 | : 255 - cell->darkness; |
628 | |
987 | |
629 | uint16_t face = cell->face [z]; |
988 | face = cell->face [z]; |
630 | |
989 | |
631 | if (face) |
990 | if (face) |
632 | { |
991 | { |
633 | mapface tex = self->face [face]; |
992 | maptex tex = self->tex [face]; |
634 | |
993 | |
635 | int px = (x + 1) * 32 - tex.w; |
994 | int px = (x + 1) * 32 - tex.w; |
636 | int py = (y + 1) * 32 - tex.h; |
995 | int py = (y + 1) * 32 - tex.h; |
637 | |
996 | |
638 | if (last_name != tex.name) |
997 | if (last_name != tex.name) |
… | |
… | |
660 | PUSHs (sv_2mortal (newSViv (sw4))); |
1019 | PUSHs (sv_2mortal (newSViv (sw4))); |
661 | PUSHs (sv_2mortal (newSViv (sh))); |
1020 | PUSHs (sv_2mortal (newSViv (sh))); |
662 | PUSHs (darkness_sv); |
1021 | PUSHs (darkness_sv); |
663 | } |
1022 | } |
664 | |
1023 | |
|
|
1024 | SV * |
|
|
1025 | get_rect (CFClient::Map self, int x0, int y0, int w, int h) |
|
|
1026 | CODE: |
|
|
1027 | { |
|
|
1028 | int x, y, x1, y1; |
|
|
1029 | SV *data_sv = newSV (w * h * 7 + 5); |
|
|
1030 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
|
|
1031 | |
|
|
1032 | *data++ = 0; /* version 0 format */ |
|
|
1033 | *data++ = w >> 8; *data++ = w; |
|
|
1034 | *data++ = h >> 8; *data++ = h; |
|
|
1035 | |
|
|
1036 | // we need to do this 'cause we don't keep an absolute coord system for rows |
|
|
1037 | // TODO: treat rows as we treat |
|
|
1038 | map_get_row (self, y0 + self->y - self->oy);//D |
|
|
1039 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
|
|
1040 | |
|
|
1041 | x0 += self->x - self->ox; |
|
|
1042 | y0 += self->y - self->oy; |
|
|
1043 | |
|
|
1044 | x1 = x0 + w; |
|
|
1045 | y1 = y0 + h; |
|
|
1046 | |
|
|
1047 | for (y = y0; y < y1; y++) |
|
|
1048 | { |
|
|
1049 | maprow *row = 0 <= y && y < self->rows |
|
|
1050 | ? self->row + y |
|
|
1051 | : 0; |
|
|
1052 | |
|
|
1053 | for (x = x0; x < x1; x++) |
|
|
1054 | { |
|
|
1055 | if (row && row->c0 <= x && x < row->c1) |
|
|
1056 | { |
|
|
1057 | mapcell *cell = row->col + (x - row->c0); |
|
|
1058 | uint8_t flags = 0; |
|
|
1059 | |
|
|
1060 | if (cell->face [0]) flags |= 1; |
|
|
1061 | if (cell->face [1]) flags |= 2; |
|
|
1062 | if (cell->face [2]) flags |= 4; |
|
|
1063 | |
|
|
1064 | *data++ = flags; |
|
|
1065 | |
|
|
1066 | if (flags & 1) |
|
|
1067 | { |
|
|
1068 | *data++ = cell->face [0] >> 8; |
|
|
1069 | *data++ = cell->face [0]; |
|
|
1070 | } |
|
|
1071 | |
|
|
1072 | if (flags & 2) |
|
|
1073 | { |
|
|
1074 | *data++ = cell->face [1] >> 8; |
|
|
1075 | *data++ = cell->face [1]; |
|
|
1076 | } |
|
|
1077 | |
|
|
1078 | if (flags & 4) |
|
|
1079 | { |
|
|
1080 | *data++ = cell->face [2] >> 8; |
|
|
1081 | *data++ = cell->face [2]; |
|
|
1082 | } |
|
|
1083 | } |
|
|
1084 | else |
|
|
1085 | *data++ = 0; |
|
|
1086 | } |
|
|
1087 | } |
|
|
1088 | |
|
|
1089 | SvPOK_only (data_sv); |
|
|
1090 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
|
|
1091 | RETVAL = data_sv; |
|
|
1092 | } |
|
|
1093 | OUTPUT: |
|
|
1094 | RETVAL |
|
|
1095 | |
|
|
1096 | void |
|
|
1097 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
|
|
1098 | PPCODE: |
|
|
1099 | { |
|
|
1100 | int x, y, z; |
|
|
1101 | int w, h; |
|
|
1102 | int x1, y1; |
|
|
1103 | |
|
|
1104 | if (*data++ != 0) |
|
|
1105 | return; /* version mismatch */ |
|
|
1106 | |
|
|
1107 | w = *data++ << 8; w |= *data++; |
|
|
1108 | h = *data++ << 8; h |= *data++; |
|
|
1109 | |
|
|
1110 | // we need to do this 'cause we don't keep an absolute coord system for rows |
|
|
1111 | // TODO: treat rows as we treat |
|
|
1112 | map_get_row (self, y0 + self->y - self->oy);//D |
|
|
1113 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
|
|
1114 | |
|
|
1115 | x0 += self->x - self->ox; |
|
|
1116 | y0 += self->y - self->oy; |
|
|
1117 | |
|
|
1118 | x1 = x0 + w; |
|
|
1119 | y1 = y0 + h; |
|
|
1120 | |
|
|
1121 | for (y = y0; y < y1; y++) |
|
|
1122 | { |
|
|
1123 | maprow *row = map_get_row (self, y); |
|
|
1124 | |
|
|
1125 | for (x = x0; x < x1; x++) |
|
|
1126 | { |
|
|
1127 | uint8_t flags = *data++; |
|
|
1128 | |
|
|
1129 | if (flags) |
|
|
1130 | { |
|
|
1131 | mapface face[3] = { 0, 0, 0 }; |
|
|
1132 | |
|
|
1133 | mapcell *cell = row_get_cell (row, x); |
|
|
1134 | |
|
|
1135 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
|
|
1136 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
|
|
1137 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
|
|
1138 | |
|
|
1139 | if (cell->darkness <= 0) |
|
|
1140 | { |
|
|
1141 | cell->darkness = -1; |
|
|
1142 | |
|
|
1143 | for (z = 0; z <= 2; z++) |
|
|
1144 | { |
|
|
1145 | cell->face[z] = face[z]; |
|
|
1146 | |
|
|
1147 | if (face[z] && (face[z] >= self->texs || !self->tex[face [z]].name)) |
|
|
1148 | XPUSHs (sv_2mortal (newSViv (face[z]))); |
|
|
1149 | } |
|
|
1150 | } |
|
|
1151 | } |
|
|
1152 | } |
|
|
1153 | } |
|
|
1154 | } |
|
|
1155 | |