… | |
… | |
6 | #include <stdio.h> |
6 | #include <stdio.h> |
7 | |
7 | |
8 | #include <SDL.h> |
8 | #include <SDL.h> |
9 | #include <SDL_image.h> |
9 | #include <SDL_image.h> |
10 | #include <SDL_opengl.h> |
10 | #include <SDL_opengl.h> |
|
|
11 | |
|
|
12 | #include <glib/gmacros.h> |
11 | |
13 | |
12 | #include <pango/pango.h> |
14 | #include <pango/pango.h> |
13 | #include <pango/pangofc-fontmap.h> |
15 | #include <pango/pangofc-fontmap.h> |
14 | #include <pango/pangoft2.h> |
16 | #include <pango/pangoft2.h> |
15 | |
17 | |
16 | #include <sys/types.h> |
18 | #include <sys/types.h> |
17 | #include <sys/socket.h> |
19 | #include <sys/socket.h> |
18 | #include <netinet/in.h> |
20 | #include <netinet/in.h> |
19 | #include <netinet/tcp.h> |
21 | #include <netinet/tcp.h> |
20 | |
22 | |
|
|
23 | #include <inttypes.h> |
|
|
24 | |
|
|
25 | #define FOW_DARKNESS 32 |
|
|
26 | |
|
|
27 | #define MAP_EXTEND_X 32 |
|
|
28 | #define MAP_EXTEND_Y 512 |
|
|
29 | |
21 | static PangoContext *context; |
30 | static PangoContext *context; |
22 | static PangoFontMap *fontmap; |
31 | static PangoFontMap *fontmap; |
23 | |
32 | |
24 | typedef struct cf_layout { |
33 | typedef struct cf_layout { |
25 | PangoLayout *pl; |
34 | PangoLayout *pl; |
… | |
… | |
28 | |
37 | |
29 | static void |
38 | static void |
30 | substitute_func (FcPattern *pattern, gpointer data) |
39 | substitute_func (FcPattern *pattern, gpointer data) |
31 | { |
40 | { |
32 | FcPatternAddBool (pattern, FC_HINTING , 1); |
41 | FcPatternAddBool (pattern, FC_HINTING , 1); |
33 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
42 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
34 | } |
43 | } |
35 | |
44 | |
36 | static void |
45 | static void |
37 | layout_update (CFClient__Layout self) |
46 | layout_update (CFClient__Layout self) |
38 | { |
47 | { |
… | |
… | |
51 | pango_layout_get_pixel_size (self->pl, w, h); |
60 | pango_layout_get_pixel_size (self->pl, w, h); |
52 | |
61 | |
53 | *w = (*w + 3) & ~3; |
62 | *w = (*w + 3) & ~3; |
54 | if (!*w) *w = 1; |
63 | if (!*w) *w = 1; |
55 | if (!*h) *h = 1; |
64 | if (!*h) *h = 1; |
|
|
65 | } |
|
|
66 | |
|
|
67 | typedef struct { |
|
|
68 | GLint name; |
|
|
69 | int w, h; |
|
|
70 | float s, t; |
|
|
71 | uint8_t r, g, b, a; |
|
|
72 | } mapface; |
|
|
73 | |
|
|
74 | typedef struct { |
|
|
75 | int16_t darkness; |
|
|
76 | uint16_t face[3]; |
|
|
77 | } mapcell; |
|
|
78 | |
|
|
79 | typedef struct { |
|
|
80 | int32_t c0, c1; |
|
|
81 | mapcell *col; |
|
|
82 | } maprow; |
|
|
83 | |
|
|
84 | typedef struct map { |
|
|
85 | int x, y, w, h; |
|
|
86 | int vx, vy; |
|
|
87 | int faces; |
|
|
88 | mapface *face; |
|
|
89 | |
|
|
90 | uint32_t rows; |
|
|
91 | maprow *row; |
|
|
92 | } *CFClient__Map; |
|
|
93 | |
|
|
94 | static char * |
|
|
95 | prepend (char *ptr, int sze, int inc) |
|
|
96 | { |
|
|
97 | char *p; |
|
|
98 | |
|
|
99 | New (0, p, sze + inc, char); |
|
|
100 | Zero (p, inc, char); |
|
|
101 | Move (ptr, p + inc, sze, char); |
|
|
102 | Safefree (ptr); |
|
|
103 | |
|
|
104 | return p; |
|
|
105 | } |
|
|
106 | |
|
|
107 | static char * |
|
|
108 | append (char *ptr, int sze, int inc) |
|
|
109 | { |
|
|
110 | Renew (ptr, sze + inc, char); |
|
|
111 | Zero (ptr + sze, inc, char); |
|
|
112 | |
|
|
113 | return ptr; |
|
|
114 | } |
|
|
115 | |
|
|
116 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
|
|
117 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
|
|
118 | |
|
|
119 | static void |
|
|
120 | map_clear (CFClient__Map self) |
|
|
121 | { |
|
|
122 | int r; |
|
|
123 | |
|
|
124 | for (r = 0; r < self->rows; r++) |
|
|
125 | Safefree (self->row[r].col); |
|
|
126 | |
|
|
127 | Safefree (self->row); |
|
|
128 | |
|
|
129 | self->x = 0; |
|
|
130 | self->y = 0; |
|
|
131 | self->vx = 0; |
|
|
132 | self->vy = 0; |
|
|
133 | self->row = 0; |
|
|
134 | self->rows = 0; |
|
|
135 | } |
|
|
136 | |
|
|
137 | static void |
|
|
138 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
|
|
139 | { |
|
|
140 | int x, y; |
|
|
141 | |
|
|
142 | for (y = y0; y < y0 + h; y++) |
|
|
143 | if (y >= 0) |
|
|
144 | { |
|
|
145 | if (y >= self->rows) |
|
|
146 | break; |
|
|
147 | |
|
|
148 | maprow *row = self->row + y; |
|
|
149 | |
|
|
150 | for (x = x0; x < x0 + w; x++) |
|
|
151 | if (x >= row->c0) |
|
|
152 | { |
|
|
153 | if (x >= row->c1) |
|
|
154 | break; |
|
|
155 | |
|
|
156 | row->col[x - row->c0].darkness = -1; |
|
|
157 | } |
|
|
158 | } |
56 | } |
159 | } |
57 | |
160 | |
58 | MODULE = CFClient PACKAGE = CFClient |
161 | MODULE = CFClient PACKAGE = CFClient |
59 | |
162 | |
60 | PROTOTYPES: ENABLE |
163 | PROTOTYPES: ENABLE |
… | |
… | |
140 | fmt.colorkey = 0; |
243 | fmt.colorkey = 0; |
141 | fmt.alpha = 0; |
244 | fmt.alpha = 0; |
142 | |
245 | |
143 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
246 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
144 | |
247 | |
|
|
248 | assert (surface2->pitch == surface2->w * 4); |
|
|
249 | |
145 | EXTEND (SP, 5); |
250 | EXTEND (SP, 5); |
146 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
251 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
147 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
252 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
148 | SDL_LockSurface (surface2); |
253 | SDL_LockSurface (surface2); |
149 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
254 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
… | |
… | |
155 | SDL_FreeSurface (surface); |
260 | SDL_FreeSurface (surface); |
156 | SDL_FreeSurface (surface2); |
261 | SDL_FreeSurface (surface2); |
157 | } |
262 | } |
158 | |
263 | |
159 | void |
264 | void |
|
|
265 | average (int x, int y, uint32_t *data) |
|
|
266 | PPCODE: |
|
|
267 | { |
|
|
268 | // only good for x * y < 32768 |
|
|
269 | uint32_t r = 0, g = 0, b = 0, a = 0; |
|
|
270 | |
|
|
271 | x = y = x * y; |
|
|
272 | |
|
|
273 | assert (x < 32768); |
|
|
274 | |
|
|
275 | while (x--) |
|
|
276 | { |
|
|
277 | uint32_t p = *data++; |
|
|
278 | |
|
|
279 | r += (p ) & 255; |
|
|
280 | g += (p >> 8) & 255; |
|
|
281 | b += (p >> 16) & 255; |
|
|
282 | a += (p >> 24) & 255; |
|
|
283 | } |
|
|
284 | |
|
|
285 | EXTEND (SP, 4); |
|
|
286 | PUSHs (sv_2mortal (newSViv (r * 255 / y))); |
|
|
287 | PUSHs (sv_2mortal (newSViv (g * 255 / y))); |
|
|
288 | PUSHs (sv_2mortal (newSViv (b * 255 / y))); |
|
|
289 | PUSHs (sv_2mortal (newSViv (a * 255 / y))); |
|
|
290 | } |
|
|
291 | |
|
|
292 | void |
160 | fatal (char *message) |
293 | fatal (char *message) |
161 | CODE: |
294 | CODE: |
162 | #ifdef WIN32 |
295 | #ifdef WIN32 |
163 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
296 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
164 | #else |
297 | #else |
… | |
… | |
183 | CODE: |
316 | CODE: |
184 | g_object_unref (self->pl); |
317 | g_object_unref (self->pl); |
185 | Safefree (self); |
318 | Safefree (self); |
186 | |
319 | |
187 | void |
320 | void |
|
|
321 | set_text (CFClient::Layout self, SV *text_) |
|
|
322 | CODE: |
|
|
323 | { |
|
|
324 | STRLEN textlen; |
|
|
325 | char *text = SvPVutf8 (text_, textlen); |
|
|
326 | |
|
|
327 | pango_layout_set_text (self->pl, text, textlen); |
|
|
328 | } |
|
|
329 | |
|
|
330 | void |
188 | set_markup (CFClient::Layout self, SV *text_) |
331 | set_markup (CFClient::Layout self, SV *text_) |
189 | CODE: |
332 | CODE: |
190 | { |
333 | { |
191 | STRLEN textlen; |
334 | STRLEN textlen; |
192 | char *text = SvPVutf8 (text_, textlen); |
335 | char *text = SvPVutf8 (text_, textlen); |
… | |
… | |
237 | PPCODE: |
380 | PPCODE: |
238 | { |
381 | { |
239 | PangoRectangle strong_pos; |
382 | PangoRectangle strong_pos; |
240 | layout_update (self); |
383 | layout_update (self); |
241 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
384 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
|
|
385 | |
242 | EXTEND (SP, 3); |
386 | EXTEND (SP, 3); |
243 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
387 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
244 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
388 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
245 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
389 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
246 | } |
390 | } |
… | |
… | |
278 | } |
422 | } |
279 | |
423 | |
280 | MODULE = CFClient PACKAGE = CFClient::Texture |
424 | MODULE = CFClient PACKAGE = CFClient::Texture |
281 | |
425 | |
282 | void |
426 | void |
283 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
427 | draw_quad (SV *self, float x, float y, float w = 0, float h = 0) |
284 | PROTOTYPE: $$$;$$ |
428 | PROTOTYPE: $$$;$$ |
285 | CODE: |
429 | CODE: |
286 | { |
430 | { |
287 | HV *hv = (HV *)SvRV (self); |
431 | HV *hv = (HV *)SvRV (self); |
288 | double s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
432 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
289 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
433 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
290 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
434 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
|
|
435 | int wrap_mode = SvIV (*hv_fetch (hv, "wrap_mode", 9, 1)); |
291 | |
436 | |
292 | if (items < 5) |
437 | if (items < 5) |
293 | { |
438 | { |
294 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
439 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
295 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
440 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
296 | } |
441 | } |
297 | |
442 | |
298 | glBindTexture (GL_TEXTURE_2D, name); |
443 | glBindTexture (GL_TEXTURE_2D, name); |
|
|
444 | if (wrap_mode) { |
|
|
445 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
|
|
446 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
|
|
447 | } |
299 | glBegin (GL_QUADS); |
448 | glBegin (GL_QUADS); |
300 | glTexCoord2d (0, 0); glVertex2d (x , y ); |
449 | glTexCoord2f (0, 0); glVertex2f (x , y ); |
301 | glTexCoord2d (0, t); glVertex2d (x , y + h); |
450 | glTexCoord2f (0, t); glVertex2f (x , y + h); |
302 | glTexCoord2d (s, t); glVertex2d (x + w, y + h); |
451 | glTexCoord2f (s, t); glVertex2f (x + w, y + h); |
303 | glTexCoord2d (s, 0); glVertex2d (x + w, y ); |
452 | glTexCoord2f (s, 0); glVertex2f (x + w, y ); |
304 | glEnd (); |
453 | glEnd (); |
305 | } |
454 | } |
|
|
455 | |
|
|
456 | MODULE = CFClient PACKAGE = CFClient::Map |
|
|
457 | |
|
|
458 | CFClient::Map |
|
|
459 | new (SV *class, int map_width, int map_height) |
|
|
460 | CODE: |
|
|
461 | New (0, RETVAL, 1, struct map); |
|
|
462 | RETVAL->x = 0; |
|
|
463 | RETVAL->y = 0; |
|
|
464 | RETVAL->w = map_width; |
|
|
465 | RETVAL->h = map_height; |
|
|
466 | RETVAL->vx = 0; |
|
|
467 | RETVAL->vy = 0; |
|
|
468 | RETVAL->faces = 8192; |
|
|
469 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
|
|
470 | RETVAL->rows = 0; |
|
|
471 | RETVAL->row = 0; |
|
|
472 | OUTPUT: |
|
|
473 | RETVAL |
|
|
474 | |
|
|
475 | void |
|
|
476 | DESTROY (CFClient::Map self) |
|
|
477 | CODE: |
|
|
478 | { |
|
|
479 | map_clear (self); |
|
|
480 | Safefree (self->face); |
|
|
481 | Safefree (self); |
|
|
482 | } |
|
|
483 | |
|
|
484 | void |
|
|
485 | clear (CFClient::Map self) |
|
|
486 | CODE: |
|
|
487 | map_clear (self); |
|
|
488 | |
|
|
489 | void |
|
|
490 | set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
|
|
491 | CODE: |
|
|
492 | { |
|
|
493 | while (self->faces < face) |
|
|
494 | { |
|
|
495 | Append (mapface, self->face, self->faces, self->faces); |
|
|
496 | self->faces *= 2; |
|
|
497 | } |
|
|
498 | |
|
|
499 | mapface *f = self->face + face; |
|
|
500 | |
|
|
501 | f->name = name; |
|
|
502 | f->w = w; |
|
|
503 | f->h = h; |
|
|
504 | f->s = s; |
|
|
505 | f->t = t; |
|
|
506 | f->r = r; |
|
|
507 | f->g = g; |
|
|
508 | f->b = b; |
|
|
509 | f->a = a; |
|
|
510 | } |
|
|
511 | |
|
|
512 | void |
|
|
513 | scroll (CFClient::Map self, int dx, int dy) |
|
|
514 | CODE: |
|
|
515 | { |
|
|
516 | if (dx > 0) |
|
|
517 | map_blank (self, self->x, self->y, dx - 1, self->h); |
|
|
518 | else if (dx < 0) |
|
|
519 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
|
|
520 | |
|
|
521 | if (dy > 0) |
|
|
522 | map_blank (self, self->x, self->y, self->w, dy - 1); |
|
|
523 | else if (dy < 0) |
|
|
524 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
|
|
525 | |
|
|
526 | self->x += dx; |
|
|
527 | self->y += dy; |
|
|
528 | |
|
|
529 | while (self->y < 0) |
|
|
530 | { |
|
|
531 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
|
|
532 | |
|
|
533 | self->rows += MAP_EXTEND_Y; |
|
|
534 | self->y += MAP_EXTEND_Y; |
|
|
535 | } |
|
|
536 | } |
|
|
537 | |
|
|
538 | void |
|
|
539 | map1a_update (CFClient::Map self, SV *data_) |
|
|
540 | CODE: |
|
|
541 | { |
|
|
542 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
|
|
543 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
|
|
544 | |
|
|
545 | while (data < data_end) |
|
|
546 | { |
|
|
547 | int flags = (data [0] << 8) + data [1]; data += 2; |
|
|
548 | |
|
|
549 | int x = ((flags >> 10) & 63) + self->x; |
|
|
550 | int y = ((flags >> 4) & 63) + self->y; |
|
|
551 | |
|
|
552 | while (y >= self->rows) |
|
|
553 | { |
|
|
554 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
|
|
555 | |
|
|
556 | self->rows += MAP_EXTEND_Y; |
|
|
557 | } |
|
|
558 | |
|
|
559 | maprow *row = self->row + y; |
|
|
560 | |
|
|
561 | if (!row->col) |
|
|
562 | { |
|
|
563 | Newz (0, row->col, MAP_EXTEND_X, mapcell); |
|
|
564 | row->c0 = self->x - MAP_EXTEND_X / 4; |
|
|
565 | row->c1 = row->c0 + MAP_EXTEND_X; |
|
|
566 | } |
|
|
567 | |
|
|
568 | if (row->c0 > x) |
|
|
569 | { |
|
|
570 | int extend = row->c0 - x + MAP_EXTEND_X; |
|
|
571 | Prepend (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
572 | row->c0 -= extend; |
|
|
573 | } |
|
|
574 | else if (x >= row->c1) |
|
|
575 | { |
|
|
576 | int extend = x - row->c1 + MAP_EXTEND_X; |
|
|
577 | Append (mapcell, row->col, row->c1 - row->c0, extend); |
|
|
578 | row->c1 += extend; |
|
|
579 | } |
|
|
580 | |
|
|
581 | assert (y >= 0); |
|
|
582 | assert (y < self->rows); |
|
|
583 | assert (x >= row->c0); |
|
|
584 | assert (x < row->c1); |
|
|
585 | mapcell *cell = row->col + (x - row->c0); |
|
|
586 | |
|
|
587 | if (flags & 15) |
|
|
588 | { |
|
|
589 | if (cell->darkness < 0 && x < self->w && y < self->h) |
|
|
590 | { |
|
|
591 | cell->darkness = 0; |
|
|
592 | cell->face [0] = 0; |
|
|
593 | cell->face [1] = 0; |
|
|
594 | cell->face [2] = 0; |
|
|
595 | } |
|
|
596 | |
|
|
597 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
598 | |
|
|
599 | if (flags & 4) |
|
|
600 | { |
|
|
601 | cell->face [0] = (data [0] << 8) + data [1]; data += 2; |
|
|
602 | } |
|
|
603 | |
|
|
604 | if (flags & 2) |
|
|
605 | { |
|
|
606 | cell->face [1] = (data [0] << 8) + data [1]; data += 2; |
|
|
607 | } |
|
|
608 | |
|
|
609 | if (flags & 1) |
|
|
610 | { |
|
|
611 | cell->face [2] = (data [0] << 8) + data [1]; data += 2; |
|
|
612 | } |
|
|
613 | } |
|
|
614 | else |
|
|
615 | cell->darkness = -1; |
|
|
616 | } |
|
|
617 | } |
|
|
618 | |
|
|
619 | void |
|
|
620 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
|
|
621 | PPCODE: |
|
|
622 | { |
|
|
623 | int sw4 = (sw + 3) & ~3; |
|
|
624 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
|
|
625 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
|
|
626 | |
|
|
627 | SvPOK_only (darkness_sv); |
|
|
628 | SvCUR_set (darkness_sv, sw4 * sh); |
|
|
629 | |
|
|
630 | int vx = self->x + (self->w - sw) / 2 - shift_x; |
|
|
631 | int vy = self->y + (self->h - sh) / 2 - shift_y; |
|
|
632 | |
|
|
633 | if (0) |
|
|
634 | { |
|
|
635 | int vx = self->vx = self->w >= sw |
|
|
636 | ? self->x + (self->w - sw) / 2 |
|
|
637 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
|
|
638 | |
|
|
639 | int vy = self->vy = self->h >= sh |
|
|
640 | ? self->y + (self->h - sh) / 2 |
|
|
641 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
642 | } |
|
|
643 | |
|
|
644 | glColor4ub (255, 255, 255, 255); |
|
|
645 | |
|
|
646 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
647 | glEnable (GL_BLEND); |
|
|
648 | glEnable (GL_TEXTURE_2D); |
|
|
649 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
650 | |
|
|
651 | int x, y, z; |
|
|
652 | |
|
|
653 | int last_name = 0; |
|
|
654 | |
|
|
655 | glBegin (GL_QUADS); |
|
|
656 | |
|
|
657 | for (z = 0; z < 3; z++) |
|
|
658 | for (y = 0; y < sh; y++) |
|
|
659 | if (0 <= y + vy && y + vy < self->rows) |
|
|
660 | { |
|
|
661 | maprow *row = self->row + (y + vy); |
|
|
662 | |
|
|
663 | for (x = 0; x < sw; x++) |
|
|
664 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
665 | { |
|
|
666 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
667 | |
|
|
668 | darkness[y * sw4 + x] = cell->darkness < 0 |
|
|
669 | ? 255 - FOW_DARKNESS |
|
|
670 | : 255 - cell->darkness; |
|
|
671 | |
|
|
672 | uint16_t face = cell->face [z]; |
|
|
673 | |
|
|
674 | if (face) |
|
|
675 | { |
|
|
676 | mapface tex = self->face [face]; |
|
|
677 | |
|
|
678 | int px = (x + 1) * 32 - tex.w; |
|
|
679 | int py = (y + 1) * 32 - tex.h; |
|
|
680 | |
|
|
681 | if (last_name != tex.name) |
|
|
682 | { |
|
|
683 | glEnd (); |
|
|
684 | last_name = tex.name; |
|
|
685 | glBindTexture (GL_TEXTURE_2D, last_name); |
|
|
686 | glBegin (GL_QUADS); |
|
|
687 | } |
|
|
688 | |
|
|
689 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
690 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
691 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
692 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
693 | } |
|
|
694 | } |
|
|
695 | } |
|
|
696 | |
|
|
697 | glEnd (); |
|
|
698 | |
|
|
699 | glDisable (GL_TEXTURE_2D); |
|
|
700 | glDisable (GL_BLEND); |
|
|
701 | |
|
|
702 | EXTEND (SP, 3); |
|
|
703 | PUSHs (sv_2mortal (newSViv (sw4))); |
|
|
704 | PUSHs (sv_2mortal (newSViv (sh))); |
|
|
705 | PUSHs (darkness_sv); |
|
|
706 | } |
|
|
707 | |