… | |
… | |
37 | |
37 | |
38 | static void |
38 | static void |
39 | substitute_func (FcPattern *pattern, gpointer data) |
39 | substitute_func (FcPattern *pattern, gpointer data) |
40 | { |
40 | { |
41 | FcPatternAddBool (pattern, FC_HINTING , 1); |
41 | FcPatternAddBool (pattern, FC_HINTING , 1); |
42 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
42 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
43 | } |
43 | } |
44 | |
44 | |
45 | static void |
45 | static void |
46 | layout_update (CFClient__Layout self) |
46 | layout_update (CFClient__Layout self) |
47 | { |
47 | { |
… | |
… | |
62 | *w = (*w + 3) & ~3; |
62 | *w = (*w + 3) & ~3; |
63 | if (!*w) *w = 1; |
63 | if (!*w) *w = 1; |
64 | if (!*h) *h = 1; |
64 | if (!*h) *h = 1; |
65 | } |
65 | } |
66 | |
66 | |
|
|
67 | typedef uint16_t mapface; |
|
|
68 | |
67 | typedef struct { |
69 | typedef struct { |
68 | GLint name; |
70 | GLint name; |
69 | int w, h; |
71 | int w, h; |
70 | float s, t; |
72 | float s, t; |
71 | } mapface; |
73 | uint8_t r, g, b, a; |
|
|
74 | } maptex; |
72 | |
75 | |
73 | typedef struct { |
76 | typedef struct { |
74 | int16_t darkness; |
77 | int16_t darkness; |
75 | uint16_t face[3]; |
78 | mapface face[3]; |
76 | } mapcell; |
79 | } mapcell; |
77 | |
80 | |
78 | typedef struct { |
81 | typedef struct { |
79 | int32_t c0, c1; |
82 | int32_t c0, c1; |
80 | mapcell *col; |
83 | mapcell *col; |
81 | } maprow; |
84 | } maprow; |
82 | |
85 | |
83 | typedef struct map { |
86 | typedef struct map { |
84 | int x, y, w, h; |
87 | int x, y, w, h; |
85 | int vx, vy; |
88 | int ox, oy; /* offset to virtual global coordinate system */ |
86 | int faces; |
89 | int faces; |
87 | mapface *face; |
90 | mapface *face; |
|
|
91 | |
|
|
92 | int texs; |
|
|
93 | maptex *tex; |
88 | |
94 | |
89 | uint32_t rows; |
95 | uint32_t rows; |
90 | maprow *row; |
96 | maprow *row; |
91 | } *CFClient__Map; |
97 | } *CFClient__Map; |
92 | |
98 | |
… | |
… | |
113 | } |
119 | } |
114 | |
120 | |
115 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
121 | #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)) |
122 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
117 | |
123 | |
|
|
124 | static maprow * |
|
|
125 | map_get_row (CFClient__Map self, int y) |
|
|
126 | { |
|
|
127 | if (0 > y) |
|
|
128 | { |
|
|
129 | int extend = - y + MAP_EXTEND_Y; |
|
|
130 | Prepend (maprow, self->row, self->rows, extend); |
|
|
131 | |
|
|
132 | self->rows += extend; |
|
|
133 | self->y += extend; |
|
|
134 | y += extend; |
|
|
135 | } |
|
|
136 | else if (y >= self->rows) |
|
|
137 | { |
|
|
138 | int extend = y - self->rows + MAP_EXTEND_Y; |
|
|
139 | Append (maprow, self->row, self->rows, extend); |
|
|
140 | self->rows += extend; |
|
|
141 | } |
|
|
142 | |
|
|
143 | return self->row + y; |
|
|
144 | } |
|
|
145 | |
|
|
146 | static mapcell * |
|
|
147 | row_get_cell (maprow *row, int x) |
|
|
148 | { |
|
|
149 | if (!row->col) |
|
|
150 | { |
|
|
151 | Newz (0, row->col, MAP_EXTEND_X, mapcell); |
|
|
152 | row->c0 = x - MAP_EXTEND_X / 4; |
|
|
153 | row->c1 = row->c0 + MAP_EXTEND_X; |
|
|
154 | } |
|
|
155 | |
|
|
156 | if (row->c0 > x) |
|
|
157 | { |
|
|
158 | int extend = row->c0 - x + MAP_EXTEND_X; |
|
|
159 | Prepend (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
160 | row->c0 -= extend; |
|
|
161 | } |
|
|
162 | else if (x >= row->c1) |
|
|
163 | { |
|
|
164 | int extend = x - row->c1 + MAP_EXTEND_X; |
|
|
165 | Append (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
166 | row->c1 += extend; |
|
|
167 | } |
|
|
168 | |
|
|
169 | return row->col + (x - row->c0); |
|
|
170 | } |
|
|
171 | |
|
|
172 | static mapcell * |
|
|
173 | map_get_cell (CFClient__Map self, int x, int y) |
|
|
174 | { |
|
|
175 | return row_get_cell (map_get_row (self, y), x); |
|
|
176 | } |
|
|
177 | |
118 | static void |
178 | static void |
119 | map_clear (CFClient__Map self) |
179 | map_clear (CFClient__Map self) |
120 | { |
180 | { |
121 | int r; |
181 | int r; |
122 | |
182 | |
… | |
… | |
125 | |
185 | |
126 | Safefree (self->row); |
186 | Safefree (self->row); |
127 | |
187 | |
128 | self->x = 0; |
188 | self->x = 0; |
129 | self->y = 0; |
189 | self->y = 0; |
130 | self->vx = 0; |
190 | self->ox = 0; |
131 | self->vy = 0; |
191 | self->oy = 0; |
132 | self->row = 0; |
192 | self->row = 0; |
133 | self->rows = 0; |
193 | self->rows = 0; |
134 | } |
194 | } |
135 | |
195 | |
136 | static void |
196 | static void |
… | |
… | |
216 | SDL_RWops *rw = ix |
276 | SDL_RWops *rw = ix |
217 | ? SDL_RWFromFile (image, "r") |
277 | ? SDL_RWFromFile (image, "r") |
218 | : SDL_RWFromConstMem (image, image_len); |
278 | : SDL_RWFromConstMem (image, image_len); |
219 | |
279 | |
220 | if (!rw) |
280 | if (!rw) |
221 | croak ("load_image: unable to open file"); |
281 | croak ("load_image: %s", SDL_GetError ()); |
222 | |
282 | |
223 | surface = IMG_Load_RW (rw, 1); |
283 | surface = IMG_Load_RW (rw, 1); |
224 | if (!surface) |
284 | if (!surface) |
225 | croak ("load_image: unable to read file"); |
285 | croak ("load_image: %s", SDL_GetError ()); |
226 | |
286 | |
227 | fmt.palette = NULL; |
287 | fmt.palette = NULL; |
228 | fmt.BitsPerPixel = 32; |
288 | fmt.BitsPerPixel = 32; |
229 | fmt.BytesPerPixel = 4; |
289 | fmt.BytesPerPixel = 4; |
230 | fmt.Rmask = 0x000000ff; |
290 | fmt.Rmask = 0x000000ff; |
… | |
… | |
242 | fmt.colorkey = 0; |
302 | fmt.colorkey = 0; |
243 | fmt.alpha = 0; |
303 | fmt.alpha = 0; |
244 | |
304 | |
245 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
305 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
246 | |
306 | |
|
|
307 | assert (surface2->pitch == surface2->w * 4); |
|
|
308 | |
247 | EXTEND (SP, 5); |
309 | EXTEND (SP, 5); |
248 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
310 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
249 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
311 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
250 | SDL_LockSurface (surface2); |
312 | SDL_LockSurface (surface2); |
251 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
313 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
… | |
… | |
257 | SDL_FreeSurface (surface); |
319 | SDL_FreeSurface (surface); |
258 | SDL_FreeSurface (surface2); |
320 | SDL_FreeSurface (surface2); |
259 | } |
321 | } |
260 | |
322 | |
261 | void |
323 | void |
|
|
324 | average (int x, int y, uint32_t *data) |
|
|
325 | PPCODE: |
|
|
326 | { |
|
|
327 | uint32_t r = 0, g = 0, b = 0, a = 0; |
|
|
328 | |
|
|
329 | x = y = x * y; |
|
|
330 | |
|
|
331 | while (x--) |
|
|
332 | { |
|
|
333 | uint32_t p = *data++; |
|
|
334 | |
|
|
335 | r += (p ) & 255; |
|
|
336 | g += (p >> 8) & 255; |
|
|
337 | b += (p >> 16) & 255; |
|
|
338 | a += (p >> 24) & 255; |
|
|
339 | } |
|
|
340 | |
|
|
341 | EXTEND (SP, 4); |
|
|
342 | PUSHs (sv_2mortal (newSViv (r / y))); |
|
|
343 | PUSHs (sv_2mortal (newSViv (g / y))); |
|
|
344 | PUSHs (sv_2mortal (newSViv (b / y))); |
|
|
345 | PUSHs (sv_2mortal (newSViv (a / y))); |
|
|
346 | } |
|
|
347 | |
|
|
348 | void |
262 | fatal (char *message) |
349 | fatal (char *message) |
263 | CODE: |
350 | CODE: |
264 | #ifdef WIN32 |
351 | #ifdef WIN32 |
265 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
352 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
266 | #else |
353 | #else |
267 | fprintf (stderr, "%s\n", message); |
354 | fprintf (stderr, "FATAL: %s\n", message); |
268 | #endif |
355 | #endif |
269 | exit (1); |
356 | exit (1); |
270 | |
357 | |
271 | MODULE = CFClient PACKAGE = CFClient::Layout |
358 | MODULE = CFClient PACKAGE = CFClient::Layout |
272 | |
359 | |
… | |
… | |
285 | CODE: |
372 | CODE: |
286 | g_object_unref (self->pl); |
373 | g_object_unref (self->pl); |
287 | Safefree (self); |
374 | Safefree (self); |
288 | |
375 | |
289 | void |
376 | void |
|
|
377 | set_text (CFClient::Layout self, SV *text_) |
|
|
378 | CODE: |
|
|
379 | { |
|
|
380 | STRLEN textlen; |
|
|
381 | char *text = SvPVutf8 (text_, textlen); |
|
|
382 | |
|
|
383 | pango_layout_set_text (self->pl, text, textlen); |
|
|
384 | } |
|
|
385 | |
|
|
386 | void |
290 | set_markup (CFClient::Layout self, SV *text_) |
387 | set_markup (CFClient::Layout self, SV *text_) |
291 | CODE: |
388 | CODE: |
292 | { |
389 | { |
293 | STRLEN textlen; |
390 | STRLEN textlen; |
294 | char *text = SvPVutf8 (text_, textlen); |
391 | char *text = SvPVutf8 (text_, textlen); |
… | |
… | |
381 | } |
478 | } |
382 | |
479 | |
383 | MODULE = CFClient PACKAGE = CFClient::Texture |
480 | MODULE = CFClient PACKAGE = CFClient::Texture |
384 | |
481 | |
385 | void |
482 | void |
386 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
483 | draw_quad (SV *self, float x, float y, float w = 0, float h = 0) |
387 | PROTOTYPE: $$$;$$ |
484 | PROTOTYPE: $$$;$$ |
388 | CODE: |
485 | CODE: |
389 | { |
486 | { |
390 | HV *hv = (HV *)SvRV (self); |
487 | HV *hv = (HV *)SvRV (self); |
391 | double s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
488 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
392 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
489 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
393 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
490 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
|
|
491 | int wrap_mode = SvIV (*hv_fetch (hv, "wrap_mode", 9, 1)); |
394 | |
492 | |
395 | if (items < 5) |
493 | if (items < 5) |
396 | { |
494 | { |
397 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
495 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
398 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
496 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
399 | } |
497 | } |
400 | |
498 | |
401 | glBindTexture (GL_TEXTURE_2D, name); |
499 | glBindTexture (GL_TEXTURE_2D, name); |
|
|
500 | if (wrap_mode) { |
|
|
501 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
|
|
502 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
|
|
503 | } |
402 | glBegin (GL_QUADS); |
504 | glBegin (GL_QUADS); |
403 | glTexCoord2d (0, 0); glVertex2d (x , y ); |
505 | glTexCoord2f (0, 0); glVertex2f (x , y ); |
404 | glTexCoord2d (0, t); glVertex2d (x , y + h); |
506 | glTexCoord2f (0, t); glVertex2f (x , y + h); |
405 | glTexCoord2d (s, t); glVertex2d (x + w, y + h); |
507 | glTexCoord2f (s, t); glVertex2f (x + w, y + h); |
406 | glTexCoord2d (s, 0); glVertex2d (x + w, y ); |
508 | glTexCoord2f (s, 0); glVertex2f (x + w, y ); |
407 | glEnd (); |
509 | glEnd (); |
408 | } |
510 | } |
409 | |
511 | |
410 | MODULE = CFClient PACKAGE = CFClient::Map |
512 | MODULE = CFClient PACKAGE = CFClient::Map |
411 | |
513 | |
412 | CFClient::Map |
514 | CFClient::Map |
413 | new (SV *class, int map_width, int map_height) |
515 | new (SV *class, int map_width, int map_height) |
414 | CODE: |
516 | CODE: |
415 | New (0, RETVAL, 1, struct map); |
517 | New (0, RETVAL, 1, struct map); |
416 | RETVAL->x = 0; |
518 | RETVAL->x = 0; |
417 | RETVAL->y = 0; |
519 | RETVAL->y = 0; |
418 | RETVAL->w = map_width; |
520 | RETVAL->w = map_width; |
419 | RETVAL->h = map_height; |
521 | RETVAL->h = map_height; |
420 | RETVAL->vx = 0; |
522 | RETVAL->ox = 0; |
421 | RETVAL->vy = 0; |
523 | RETVAL->oy = 0; |
422 | RETVAL->faces = 8192; |
524 | RETVAL->faces = 8192; |
423 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
525 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
|
|
526 | RETVAL->texs = 8192; |
|
|
527 | Newz (0, RETVAL->tex, RETVAL->texs, maptex); |
424 | RETVAL->rows = 0; |
528 | RETVAL->rows = 0; |
425 | RETVAL->row = 0; |
529 | RETVAL->row = 0; |
426 | OUTPUT: |
530 | OUTPUT: |
427 | RETVAL |
531 | RETVAL |
428 | |
532 | |
… | |
… | |
439 | clear (CFClient::Map self) |
543 | clear (CFClient::Map self) |
440 | CODE: |
544 | CODE: |
441 | map_clear (self); |
545 | map_clear (self); |
442 | |
546 | |
443 | void |
547 | void |
444 | set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t) |
548 | set_face (CFClient::Map self, int face, int texid) |
445 | CODE: |
549 | CODE: |
446 | { |
550 | { |
447 | while (self->faces < face) |
551 | while (self->faces <= face) |
448 | { |
552 | { |
449 | Append (mapface, self->face, self->faces, self->faces); |
553 | Append (mapface, self->face, self->faces, self->faces); |
450 | self->faces *= 2; |
554 | self->faces *= 2; |
451 | } |
555 | } |
452 | |
556 | |
453 | self->face [face].name = name; |
|
|
454 | self->face [face].w = w; |
557 | self->face [face] = texid; |
455 | self->face [face].h = h; |
558 | } |
456 | self->face [face].s = s; |
559 | |
457 | self->face [face].t = t; |
560 | void |
|
|
561 | 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) |
|
|
562 | CODE: |
|
|
563 | { |
|
|
564 | while (self->texs <= texid) |
|
|
565 | { |
|
|
566 | Append (maptex, self->tex, self->texs, self->texs); |
|
|
567 | self->texs *= 2; |
|
|
568 | } |
|
|
569 | |
|
|
570 | maptex *tex = self->tex + texid; |
|
|
571 | |
|
|
572 | tex->name = name; |
|
|
573 | tex->w = w; |
|
|
574 | tex->h = h; |
|
|
575 | tex->s = s; |
|
|
576 | tex->t = t; |
|
|
577 | tex->r = r; |
|
|
578 | tex->g = g; |
|
|
579 | tex->b = b; |
|
|
580 | tex->a = a; |
458 | } |
581 | } |
459 | |
582 | |
460 | void |
583 | void |
461 | scroll (CFClient::Map self, int dx, int dy) |
584 | scroll (CFClient::Map self, int dx, int dy) |
462 | CODE: |
585 | CODE: |
… | |
… | |
469 | if (dy > 0) |
592 | if (dy > 0) |
470 | map_blank (self, self->x, self->y, self->w, dy - 1); |
593 | map_blank (self, self->x, self->y, self->w, dy - 1); |
471 | else if (dy < 0) |
594 | else if (dy < 0) |
472 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
595 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
473 | |
596 | |
474 | self->x += dx; |
597 | self->x += dx; self->ox += dx; |
475 | self->y += dy; |
598 | self->y += dy; self->oy += dy; |
476 | |
599 | |
477 | while (self->y < 0) |
600 | while (self->y < 0) |
478 | { |
601 | { |
479 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
602 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
480 | |
603 | |
481 | self->rows += MAP_EXTEND_Y; |
604 | self->rows += MAP_EXTEND_Y; |
482 | self->y += MAP_EXTEND_Y; |
605 | self->y += MAP_EXTEND_Y; |
483 | } |
606 | } |
484 | } |
607 | } |
|
|
608 | |
|
|
609 | int |
|
|
610 | ox (CFClient::Map self) |
|
|
611 | ALIAS: |
|
|
612 | oy = 1 |
|
|
613 | CODE: |
|
|
614 | switch (ix) |
|
|
615 | { |
|
|
616 | case 0: RETVAL = self->ox; break; |
|
|
617 | case 1: RETVAL = self->oy; break; |
|
|
618 | } |
|
|
619 | OUTPUT: |
|
|
620 | RETVAL |
485 | |
621 | |
486 | void |
622 | void |
487 | map1a_update (CFClient::Map self, SV *data_) |
623 | map1a_update (CFClient::Map self, SV *data_) |
488 | CODE: |
624 | CODE: |
489 | { |
625 | { |
… | |
… | |
495 | int flags = (data [0] << 8) + data [1]; data += 2; |
631 | int flags = (data [0] << 8) + data [1]; data += 2; |
496 | |
632 | |
497 | int x = ((flags >> 10) & 63) + self->x; |
633 | int x = ((flags >> 10) & 63) + self->x; |
498 | int y = ((flags >> 4) & 63) + self->y; |
634 | int y = ((flags >> 4) & 63) + self->y; |
499 | |
635 | |
500 | while (y >= self->rows) |
636 | mapcell *cell = map_get_cell (self, x, y); |
501 | { |
|
|
502 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
|
|
503 | |
|
|
504 | self->rows += MAP_EXTEND_Y; |
|
|
505 | } |
|
|
506 | |
|
|
507 | maprow *row = self->row + y; |
|
|
508 | |
|
|
509 | if (!row->col) |
|
|
510 | { |
|
|
511 | Newz (0, row->col, MAP_EXTEND_X, mapcell); |
|
|
512 | row->c0 = self->x - MAP_EXTEND_X / 4; |
|
|
513 | row->c1 = row->c0 + MAP_EXTEND_X; |
|
|
514 | } |
|
|
515 | |
|
|
516 | if (row->c0 > x) |
|
|
517 | { |
|
|
518 | int extend = row->c0 - x + MAP_EXTEND_X; |
|
|
519 | Prepend (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
520 | row->c0 -= extend; |
|
|
521 | } |
|
|
522 | else if (x >= row->c1) |
|
|
523 | { |
|
|
524 | int extend = x - row->c1 + MAP_EXTEND_X; |
|
|
525 | Append (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
526 | row->c1 += extend; |
|
|
527 | } |
|
|
528 | |
|
|
529 | assert (y >= 0); |
|
|
530 | assert (y < self->rows); |
|
|
531 | assert (x >= row->c0); |
|
|
532 | assert (x < row->c1); |
|
|
533 | mapcell *cell = row->col + (x - row->c0); |
|
|
534 | |
637 | |
535 | if (flags & 15) |
638 | if (flags & 15) |
536 | { |
639 | { |
537 | if (cell->darkness < 0 && x < self->w && y < self->h) |
640 | if (cell->darkness < 0) // && x < self->w && y < self->h) |
538 | { |
641 | { |
539 | cell->darkness = 0; |
642 | cell->darkness = 0; |
540 | cell->face [0] = 0; |
643 | cell->face [0] = 0; |
541 | cell->face [1] = 0; |
644 | cell->face [1] = 0; |
542 | cell->face [2] = 0; |
645 | cell->face [2] = 0; |
543 | } |
646 | } |
544 | |
647 | |
545 | cell->darkness = flags & 8 ? *data++ : 255; |
648 | cell->darkness = flags & 8 ? *data++ : 255; |
546 | |
649 | |
|
|
650 | //TODO: don't trust server data to be in-range(!) |
|
|
651 | |
547 | if (flags & 4) |
652 | if (flags & 4) |
548 | { |
653 | { |
549 | cell->face [0] = (data [0] << 8) + data [1]; data += 2; |
654 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
550 | } |
655 | } |
551 | |
656 | |
552 | if (flags & 2) |
657 | if (flags & 2) |
553 | { |
658 | { |
554 | cell->face [1] = (data [0] << 8) + data [1]; data += 2; |
659 | cell->face [1] = self->face [(data [0] << 8) + data [1]]; data += 2; |
555 | } |
660 | } |
556 | |
661 | |
557 | if (flags & 1) |
662 | if (flags & 1) |
558 | { |
663 | { |
559 | cell->face [2] = (data [0] << 8) + data [1]; data += 2; |
664 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
560 | } |
665 | } |
561 | } |
666 | } |
562 | else |
667 | else |
563 | cell->darkness = -1; |
668 | cell->darkness = -1; |
564 | } |
669 | } |
565 | } |
670 | } |
566 | |
671 | |
|
|
672 | SV * |
|
|
673 | mapmap (CFClient::Map self, int w, int h) |
|
|
674 | CODE: |
|
|
675 | { |
|
|
676 | int x0, x1, x; |
|
|
677 | int y0, y1, y; |
|
|
678 | int z; |
|
|
679 | SV *map_sv = newSV (w * h * sizeof (uint32_t)); |
|
|
680 | uint32_t *map = (uint32_t *)SvPVX (map_sv); |
|
|
681 | |
|
|
682 | SvPOK_only (map_sv); |
|
|
683 | SvCUR_set (map_sv, w * h * sizeof (uint32_t)); |
|
|
684 | |
|
|
685 | x0 = self->x - w / 2; x1 = x0 + w; |
|
|
686 | y0 = self->y - h / 2; y1 = y0 + h; |
|
|
687 | |
|
|
688 | for (y = y0; y < y1; y++) |
|
|
689 | { |
|
|
690 | maprow *row = 0 <= y && y < self->rows |
|
|
691 | ? self->row + y |
|
|
692 | : 0; |
|
|
693 | |
|
|
694 | for (x = x0; x < x1; x++) |
|
|
695 | { |
|
|
696 | int r = 32, g = 32, b = 32, a = 192; |
|
|
697 | |
|
|
698 | if (row && row->c0 <= x && x < row->c1) |
|
|
699 | { |
|
|
700 | mapcell *cell = row->col + (x - row->c0); |
|
|
701 | |
|
|
702 | for (z = 0; z <= 0; z++) |
|
|
703 | { |
|
|
704 | mapface face = cell->face [z]; |
|
|
705 | |
|
|
706 | if (face) |
|
|
707 | { |
|
|
708 | maptex tex = self->tex [face]; |
|
|
709 | int a0 = 255 - tex.a; |
|
|
710 | int a1 = tex.a; |
|
|
711 | |
|
|
712 | r = (r * a0 + tex.r * a1) / 255; |
|
|
713 | g = (g * a0 + tex.g * a1) / 255; |
|
|
714 | b = (b * a0 + tex.b * a1) / 255; |
|
|
715 | a = (a * a0 + tex.a * a1) / 255; |
|
|
716 | } |
|
|
717 | } |
|
|
718 | } |
|
|
719 | |
|
|
720 | *map++ = (r ) |
|
|
721 | | (g << 8) |
|
|
722 | | (b << 16) |
|
|
723 | | (a << 24); |
|
|
724 | } |
|
|
725 | } |
|
|
726 | |
|
|
727 | RETVAL = map_sv; |
|
|
728 | } |
|
|
729 | OUTPUT: |
|
|
730 | RETVAL |
|
|
731 | |
567 | void |
732 | void |
568 | draw (CFClient::Map self, int x0, int y0, int sw, int sh) |
733 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
569 | PPCODE: |
734 | PPCODE: |
570 | { |
735 | { |
571 | int sw4 = (sw + 3) & ~3; |
736 | int sw4 = (sw + 3) & ~3; |
572 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
737 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
573 | uint8_t *darkness = SvPVX (darkness_sv); |
738 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
574 | |
739 | memset (darkness, 255, sw4 * sh); |
575 | SvPOK_only (darkness_sv); |
740 | SvPOK_only (darkness_sv); |
576 | SvCUR_set (darkness_sv, sw4 * sh); |
741 | SvCUR_set (darkness_sv, sw4 * sh); |
577 | |
742 | |
|
|
743 | int vx = self->x + (self->w - sw) / 2 - shift_x; |
|
|
744 | int vy = self->y + (self->h - sh) / 2 - shift_y; |
|
|
745 | |
|
|
746 | /* |
578 | int vx = self->vx = self->w >= sw |
747 | int vx = self->vx = self->w >= sw |
579 | ? self->x + (self->w - sw) / 2 |
748 | ? self->x + (self->w - sw) / 2 |
580 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
749 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
581 | |
750 | |
582 | int vy = self->vy = self->h >= sh |
751 | int vy = self->vy = self->h >= sh |
583 | ? self->y + (self->h - sh) / 2 |
752 | ? self->y + (self->h - sh) / 2 |
584 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
753 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
754 | */ |
585 | |
755 | |
586 | glColor4ub (255, 255, 255, 255); |
756 | glColor4ub (255, 255, 255, 255); |
587 | |
757 | |
588 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
758 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
589 | glEnable (GL_BLEND); |
759 | glEnable (GL_BLEND); |
… | |
… | |
606 | if (row->c0 <= x + vx && x + vx < row->c1) |
776 | if (row->c0 <= x + vx && x + vx < row->c1) |
607 | { |
777 | { |
608 | mapcell *cell = row->col + (x + vx - row->c0); |
778 | mapcell *cell = row->col + (x + vx - row->c0); |
609 | |
779 | |
610 | darkness[y * sw4 + x] = cell->darkness < 0 |
780 | darkness[y * sw4 + x] = cell->darkness < 0 |
611 | ? 224 |
781 | ? 255 - FOW_DARKNESS |
612 | : 255 - cell->darkness; |
782 | : 255 - cell->darkness; |
613 | |
783 | |
614 | uint16_t face = cell->face [z]; |
784 | mapface face = cell->face [z]; |
615 | |
785 | |
616 | if (face) |
786 | if (face) |
617 | { |
787 | { |
618 | mapface tex = self->face [face]; |
788 | maptex tex = self->tex [face]; |
619 | |
789 | |
620 | int px = (x + 1) * 32 - tex.w; |
790 | int px = (x + 1) * 32 - tex.w; |
621 | int py = (y + 1) * 32 - tex.h; |
791 | int py = (y + 1) * 32 - tex.h; |
622 | |
792 | |
623 | if (last_name != tex.name) |
793 | if (last_name != tex.name) |
… | |
… | |
636 | } |
806 | } |
637 | } |
807 | } |
638 | |
808 | |
639 | glEnd (); |
809 | glEnd (); |
640 | |
810 | |
|
|
811 | glDisable (GL_TEXTURE_2D); |
|
|
812 | glDisable (GL_BLEND); |
|
|
813 | |
641 | EXTEND (SP, 3); |
814 | EXTEND (SP, 3); |
642 | PUSHs (sv_2mortal (newSViv (sw4))); |
815 | PUSHs (sv_2mortal (newSViv (sw4))); |
643 | PUSHs (sv_2mortal (newSViv (sh))); |
816 | PUSHs (sv_2mortal (newSViv (sh))); |
644 | PUSHs (darkness_sv); |
817 | PUSHs (darkness_sv); |
645 | |
|
|
646 | glDisable (GL_TEXTURE_2D); |
|
|
647 | glDisable (GL_BLEND); |
|
|
648 | } |
818 | } |
649 | |
819 | |
|
|
820 | SV * |
|
|
821 | get_rect (CFClient::Map self, int x0, int y0, int w, int h) |
|
|
822 | CODE: |
|
|
823 | { |
|
|
824 | int x, y, x1, y1; |
|
|
825 | SV *data_sv = newSV (w * h * 7 + 5); |
|
|
826 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
|
|
827 | |
|
|
828 | *data++ = 0; /* version 0 format */ |
|
|
829 | *data++ = w >> 8; *data++ = w; |
|
|
830 | *data++ = h >> 8; *data++ = h; |
|
|
831 | |
|
|
832 | // we need to do this 'cause we don't keep an absolute coord system for rows |
|
|
833 | // TODO: treat rows as we treat |
|
|
834 | map_get_row (self, y0 + self->y - self->oy);//D |
|
|
835 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
|
|
836 | |
|
|
837 | x0 += self->x - self->ox; |
|
|
838 | y0 += self->y - self->oy; |
|
|
839 | |
|
|
840 | x1 = x0 + w; |
|
|
841 | y1 = y0 + h; |
|
|
842 | |
|
|
843 | for (y = y0; y < y1; y++) |
|
|
844 | { |
|
|
845 | maprow *row = 0 <= y && y < self->rows |
|
|
846 | ? self->row + y |
|
|
847 | : 0; |
|
|
848 | |
|
|
849 | for (x = x0; x < x1; x++) |
|
|
850 | { |
|
|
851 | if (row && row->c0 <= x && x < row->c1) |
|
|
852 | { |
|
|
853 | mapcell *cell = row->col + (x - row->c0); |
|
|
854 | |
|
|
855 | uint8_t flags = 0; |
|
|
856 | |
|
|
857 | if (cell->face [0]) flags |= 1; |
|
|
858 | if (cell->face [1]) flags |= 2; |
|
|
859 | if (cell->face [2]) flags |= 4; |
|
|
860 | |
|
|
861 | *data++ = flags; |
|
|
862 | |
|
|
863 | if (flags & 1) |
|
|
864 | { |
|
|
865 | *data++ = cell->face [0] >> 8; |
|
|
866 | *data++ = cell->face [0]; |
|
|
867 | } |
|
|
868 | |
|
|
869 | if (flags & 2) |
|
|
870 | { |
|
|
871 | *data++ = cell->face [1] >> 8; |
|
|
872 | *data++ = cell->face [1]; |
|
|
873 | } |
|
|
874 | |
|
|
875 | if (flags & 4) |
|
|
876 | { |
|
|
877 | *data++ = cell->face [2] >> 8; |
|
|
878 | *data++ = cell->face [2]; |
|
|
879 | } |
|
|
880 | } |
|
|
881 | else |
|
|
882 | *data++ = 0; |
|
|
883 | } |
|
|
884 | } |
|
|
885 | |
|
|
886 | SvPOK_only (data_sv); |
|
|
887 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
|
|
888 | RETVAL = data_sv; |
|
|
889 | } |
|
|
890 | OUTPUT: |
|
|
891 | RETVAL |
|
|
892 | |
|
|
893 | void |
|
|
894 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
|
|
895 | PPCODE: |
|
|
896 | { |
|
|
897 | int x, y, z; |
|
|
898 | int x1, y1; |
|
|
899 | |
|
|
900 | if (*data++ != 0) |
|
|
901 | return; /* version mismatch */ |
|
|
902 | |
|
|
903 | int w = *data++ << 8; w |= *data++; |
|
|
904 | int h = *data++ << 8; h |= *data++; |
|
|
905 | |
|
|
906 | // we need to do this 'cause we don't keep an absolute coord system for rows |
|
|
907 | // TODO: treat rows as we treat |
|
|
908 | map_get_row (self, y0 + self->y - self->oy);//D |
|
|
909 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
|
|
910 | |
|
|
911 | x0 += self->x - self->ox; |
|
|
912 | y0 += self->y - self->oy; |
|
|
913 | |
|
|
914 | x1 = x0 + w; |
|
|
915 | y1 = y0 + h; |
|
|
916 | |
|
|
917 | for (y = y0; y < y1; y++) |
|
|
918 | { |
|
|
919 | maprow *row = map_get_row (self, y); |
|
|
920 | |
|
|
921 | for (x = x0; x < x1; x++) |
|
|
922 | { |
|
|
923 | uint8_t flags = *data++; |
|
|
924 | |
|
|
925 | if (flags) |
|
|
926 | { |
|
|
927 | mapface face[3] = { 0, 0, 0 }; |
|
|
928 | |
|
|
929 | mapcell *cell = row_get_cell (row, x); |
|
|
930 | |
|
|
931 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
|
|
932 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
|
|
933 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
|
|
934 | |
|
|
935 | if (cell->darkness <= 0) |
|
|
936 | { |
|
|
937 | cell->darkness = -1; |
|
|
938 | |
|
|
939 | for (z = 0; z <= 2; z++) |
|
|
940 | { |
|
|
941 | cell->face[z] = face[z]; |
|
|
942 | |
|
|
943 | if (face[z] && (face[z] >= self->texs || !self->tex[face [z]].name)) |
|
|
944 | XPUSHs (sv_2mortal (newSViv (face[z]))); |
|
|
945 | } |
|
|
946 | } |
|
|
947 | } |
|
|
948 | } |
|
|
949 | } |
|
|
950 | } |
|
|
951 | |