DEADSOFTWARE

config: read config and args by renders
[flatwaifu.git] / src / gl / render.c
1 #include "glob.h"
2 #include "render.h"
3 #include "system.h"
4 #include "files.h"
5 #include "memory.h"
6 #include "misc.h"
7 #include "error.h"
9 #include "menu.h"
10 #include "game.h"
11 #include "dots.h"
12 #include "items.h"
14 #include "sound.h" // snd_vol
15 #include "music.h" // mus_vol
17 #include "fx.h"
18 #include "player.h"
19 #include "monster.h"
20 #include "weapons.h"
21 #include "smoke.h"
22 #include "view.h"
23 #include "switch.h" // sw_secrets
25 #include "cp866.h"
27 #ifdef __APPLE__
28 # include <OpenGL/gl.h>
29 #else
30 # include <GL/gl.h>
31 #endif
32 #include <stdarg.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <assert.h>
37 #define VGA_TRANSPARENT_COLOR 0
38 #define DEFAULT_SKY_COLOR 0x97
39 #define MANCOLOR 0xD0
40 #define PLAYER_COLOR_OFFSET 7
41 #define MAXAIR 1091
42 #define ANIT 5
43 #define PL_FLASH 90
45 #pragma pack(1)
46 typedef struct vgaimg {
47 word w, h;
48 short x, y;
49 byte data[];
50 } vgaimg;
52 typedef struct rgb {
53 byte r, g, b;
54 } rgb;
56 typedef struct rgba {
57 byte r, g, b, a;
58 } rgba;
59 #pragma pack()
61 typedef struct node {
62 struct cache *base;
63 struct node *left, *right;
64 struct node *up;
65 int l, t, r, b;
66 int leaf;
67 } node;
69 typedef struct cache {
70 struct cache *next;
71 struct node root;
72 GLuint id;
73 } cache;
75 typedef struct image {
76 node *n;
77 GLint x, y;
78 GLuint w, h;
79 int res;
80 } image;
82 /* Render Specific */
83 static int SCRW;
84 static int SCRH;
85 static float screen_scale;
86 static int screen_width = 320;
87 static int screen_height = 200;
88 static byte screen_full = 0;
89 static int init_screen_width = 0;
90 static int init_screen_height = 0;
91 static byte init_screen_full = 0xFF;
92 static rgb playpal[256];
93 static byte bright[256];
94 static GLuint lastTexture;
95 static cache *root;
97 /* Game */
98 static image scrnh[3]; // TITLEPIC INTERPIC ENDPIC
99 static image ltn[2][2];
101 /* Smoke */
102 static image smk_spr[SMSN];
103 static image smk_fspr[FLSN];
105 /* Effects */
106 static image fx_spr[15];
107 static char fx_sprd[15];
109 /* Weapons */
110 static image wp_spr[49*2];
111 static char wp_sprd[49*2];
113 /* Items */
114 static image item_spr[58];
115 static char item_sprd[58];
117 /* Player */
118 static image plr_spr[27*2];
119 static image plr_msk[27*2];
120 static char plr_sprd[27*2];
121 static image plr_wpn[11][6];
123 /* Monsters */
124 static image pl_spr[2];
125 static image pl_msk[2];
126 static image mn_spr[MN_TN][29*2];
127 static image mn_man_msk[29*2];
128 static char mn_sprd[MN_TN][29*2];
129 static image mn_fspr[8];
130 static image mn_sgun[2];
132 /* Misc */
133 static image sth[22];
134 static image bfh[160 - '!'];
135 static image sfh[160 - '!'];
136 static image stone;
137 static image stone2;
138 static image keys[3];
139 static int prx = 0;
140 static int pry = 0;
142 /* Menu */
143 static int gm_tm;
144 static image msklh[2];
145 static image mbarl;
146 static image mbarm;
147 static image mbarr;
148 static image mbaro;
149 static image mslotl;
150 static image mslotm;
151 static image mslotr;
153 /* Map */
154 static const char *anm[ANIT - 1][5] = {
155 {"WALL22_1", "WALL23_1", "WALL23_2", NULL, NULL},
156 {"WALL58_1", "WALL58_2", "WALL58_3", NULL, NULL},
157 {"W73A_1", "W73A_2", NULL, NULL, NULL},
158 {"RP2_1", "RP2_2", "RP2_3", "RP2_4", NULL}
159 };
160 static byte w_horiz = 1;
161 static int max_wall_width;
162 static int max_wall_height;
163 static int max_textures;
164 static image walp[256];
165 static byte walani[256];
166 static image anip[ANIT][5];
167 static byte anic[ANIT];
168 static image horiz;
170 /* Texture cache */
172 // https://blackpawn.com/texts/lightmaps/
173 static node *R_node_alloc (node *p, int w, int h) {
174 assert(p);
175 assert(w > 0);
176 assert(h > 0);
177 if (p->left) {
178 assert(p->right);
179 node *n = R_node_alloc(p->left, w, h);
180 return n ? n : R_node_alloc(p->right, w, h);
181 } else {
182 int pw = p->r - p->l + 1;
183 int ph = p->b - p->t + 1;
184 if (p->leaf || pw < w || ph < h) {
185 return NULL;
186 } else if (pw == w && ph == h) {
187 p->leaf = 1;
188 return p;
189 } else {
190 p->left = malloc(sizeof(node));
191 p->right = malloc(sizeof(node));
192 if (pw - w > ph - h) {
193 *p->left = (node) {
194 .up = p,
195 .l = p->l,
196 .t = p->t,
197 .r = p->l + w - 1,
198 .b = p->b
199 };
200 *p->right = (node) {
201 .up = p,
202 .l = p->l + w,
203 .t = p->t,
204 .r = p->r,
205 .b = p->b
206 };
207 } else {
208 *p->left = (node) {
209 .up = p,
210 .l = p->l,
211 .t = p->t,
212 .r = p->r,
213 .b = p->t + h - 1
214 };
215 *p->right = (node) {
216 .up = p,
217 .l = p->l,
218 .t = p->t + h,
219 .r = p->r,
220 .b = p->b
221 };
223 return R_node_alloc(p->left, w, h);
228 static int R_node_have_leaf (node *n) {
229 return n && (n->leaf || R_node_have_leaf(n->left) || R_node_have_leaf(n->right));
232 static void R_node_free_recursive (node *n) {
233 if (n) {
234 R_node_free_recursive(n->left);
235 R_node_free_recursive(n->right);
236 free(n);
240 static void R_node_free (node *n) {
241 if (n) {
242 //logo("free node %p {%i:%i:%i:%i}\n", n, n->l, n->t, n->r, n->b);
243 assert(n->leaf);
244 assert(n->left == NULL);
245 assert(n->right == NULL);
246 n->leaf = 0;
247 n->base = NULL;
248 node *p = n->up;
249 while (p != NULL) {
250 assert(p->leaf == 0);
251 assert(p->left);
252 assert(p->right);
253 if (R_node_have_leaf(p) == 0) {
254 R_node_free_recursive(p->left);
255 p->left = NULL;
256 R_node_free_recursive(p->right);
257 p->right = NULL;
258 p = p->up;
259 } else {
260 p = NULL;
266 static void R_cache_get_max_texture_size (int *w, int *h) {
267 GLint size = 0;
268 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
269 size = min(max(size, 0), 512); // more can be buggy on older hardware
270 *w = size;
271 *h = size;
274 static void R_gl_bind_texture (GLuint id) {
275 if (id != lastTexture) {
276 glBindTexture(GL_TEXTURE_2D, id);
280 static cache *R_cache_new (void) {
281 int w, h;
282 GLuint id;
283 cache *c = NULL;
284 R_cache_get_max_texture_size(&w, &h);
285 if (w && h) {
286 glGenTextures(1, &id);
287 if (id) {
288 R_gl_bind_texture(id);
289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
291 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
292 c = malloc(sizeof(cache));
293 if (c != NULL) {
294 *c = (cache) {
295 .id = id,
296 .root.r = w - 1,
297 .root.b = h - 1
298 };
299 } else {
300 glDeleteTextures(1, &id);
304 //logo("new cache %p\n", c);
305 return c;
308 static void R_cache_free (cache *root, int freetexture) {
309 cache *next;
310 cache *c = root;
311 while (c != NULL) {
312 next = c->next;
313 R_node_free_recursive(c->root.left);
314 R_node_free_recursive(c->root.right);
315 if (freetexture && c->id != 0) {
316 glDeleteTextures(1, &c->id);
318 free(c);
319 c = next;
323 static node *R_cache_alloc (cache *root, int w, int h) {
324 assert(root);
325 assert(w > 0 && h > 0);
326 node *n = NULL;
327 cache *p = NULL;
328 cache *c = root;
329 int maxw, maxh;
330 R_cache_get_max_texture_size(&maxw, &maxh);
331 if (w <= maxw && h <= maxh) {
332 while (c && !n) {
333 n = R_node_alloc(&c->root, w, h);
334 if (n) {
335 assert(n->leaf);
336 n->base = c;
338 p = c;
339 c = c->next;
341 if (!n) {
342 c = R_cache_new();
343 if (c) {
344 p->next = c;
345 n = R_node_alloc(&c->root, w, h);
346 if (n) {
347 assert(n->leaf);
348 n->base = c;
353 if (n) {
354 //logo("new node %p {%i:%i:%i:%i}\n", n, n->l, n->t, n->r, n->b);
355 } else {
356 logo("new node failed {%i:%i}\n", w, h);
358 return n;
361 static void R_cache_update (node *n, const void *data, int x, int y, int w, int h) {
362 assert(n);
363 assert(n->leaf);
364 assert(n->base);
365 assert(data);
366 assert(x >= 0);
367 assert(y >= 0);
368 assert(n->l + x + w - 1 <= n->r);
369 assert(n->t + y + h - 1 <= n->b);
370 R_gl_bind_texture(n->base->id);
371 glTexSubImage2D(GL_TEXTURE_2D, 0, n->l + x, n->t + y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data);
374 /* Generic helpers */
376 static void R_init_playpal (void) {
377 int i;
378 byte *vgapal = M_lock(F_getresid("PLAYPAL"));
379 for (i = 0; i < 256; i++) {
380 playpal[i] = (rgb) {
381 .r = vgapal[i * 3 + 0] * 255 / 63,
382 .g = vgapal[i * 3 + 1] * 255 / 63,
383 .b = vgapal[i * 3 + 2] * 255 / 63,
384 };
385 bright[i] = ((int)vgapal[i * 3 + 0] + vgapal[i * 3 + 1] + vgapal[i * 3 + 2]) * 8 / (63 * 3);
387 M_unlock(vgapal);
390 static vgaimg *R_getvga (int id) {
391 int loaded = M_was_locked(id);
392 vgaimg *v = M_lock(id);
393 if (v != NULL && !loaded) {
394 v->w = short2host(v->w);
395 v->h = short2host(v->h);
396 v->x = short2host(v->x);
397 v->y = short2host(v->y);
399 return v;
402 static rgba *R_extract_flame_spr (vgaimg *v) {
403 static const byte flametab[16] = {
404 0xBC, 0xBA, 0xB8, 0xB6, 0xB4, 0xB2, 0xB0, 0xD5,
405 0xD6, 0xD7, 0xA1, 0xA0, 0xE3, 0xE2, 0xE1, 0xE0
406 };
407 int i, j;
408 rgba *s = malloc(v->w * v->h * sizeof(rgba));
409 if (s != NULL) {
410 for (j = 0; j < v->h; j++) {
411 for (i = 0; i < v->w; i++) {
412 int k = j * v->w + i;
413 byte c = v->data[k] + bright[DEFAULT_SKY_COLOR];
414 s[k] = (rgba) {
415 .r = playpal[flametab[c]].r,
416 .g = playpal[flametab[c]].g,
417 .b = playpal[flametab[c]].b,
418 .a = v->data[k] == VGA_TRANSPARENT_COLOR ? 0x00 : 0xFF,
419 };
423 return s;
426 static rgba *R_extract_smoke_spr (vgaimg *v) {
427 int i, j;
428 rgba *s = malloc(v->w * v->h * sizeof(rgba));
429 if (s != NULL) {
430 for (j = 0; j < v->h; j++) {
431 for (i = 0; i < v->w; i++) {
432 int k = j * v->w + i;
433 byte c = ((v->data[k] + bright[DEFAULT_SKY_COLOR]) + 0x60) ^ 0x0F;
434 byte a = 0xFF - ((int)playpal[c].r + playpal[c].g + playpal[c].b) / 3;
435 s[k] = (rgba) {
436 .r = playpal[c].r,
437 .g = playpal[c].g,
438 .b = playpal[c].b,
439 .a = v->data[k] == VGA_TRANSPARENT_COLOR ? 0x00 : a,
440 };
444 return s;
447 static rgba *R_extract_mask_spr (vgaimg *v) {
448 int i, j;
449 rgba *s = malloc(v->w * v->h * sizeof(rgba));
450 if (s != NULL) {
451 for (j = 0; j < v->h; j++) {
452 for (i = 0; i < v->w; i++) {
453 int k = j * v->w + i;
454 byte c = v->data[k];
455 if (c >= 0x70 && c <= 0x7F) {
456 byte mask = c - 0x70;
457 mask = 0xFF - ((mask << 4) | mask);
458 s[k] = (rgba) {
459 .r = mask,
460 .g = mask,
461 .b = mask,
462 .a = 0xFF,
463 };
464 } else {
465 s[k] = (rgba) {
466 .r = 0,
467 .g = 0,
468 .b = 0,
469 .a = 0,
470 };
475 return s;
478 static rgba *R_extract_rgba_spr (vgaimg *v) {
479 int i, j;
480 rgba *s = malloc(v->w * v->h * sizeof(rgba));
481 if (s != NULL) {
482 for (j = 0; j < v->h; j++) {
483 for (i = 0; i < v->w; i++) {
484 int k = j * v->w + i;
485 byte c = v->data[k];
486 s[k] = (rgba) {
487 .r = playpal[c].r,
488 .g = playpal[c].g,
489 .b = playpal[c].b,
490 .a = c == VGA_TRANSPARENT_COLOR ? 0x00 : 0xFF,
491 };
495 return s;
498 /* OpenGL helpers */
500 static image R_gl_create_image (const rgba *buf, int w, int h) {
501 node *n = R_cache_alloc(root, w, h);
502 if (n) {
503 R_cache_update(n, buf, 0, 0, w, h);
505 return (image) {
506 .n = n,
507 .w = w,
508 .h = h,
509 .res = -1
510 };
513 static image R_gl_get_special_image (int id, rgba *(*fn)(vgaimg*)) {
514 image img;
515 //char name[8];
516 //F_getresname(name, id);
517 //logo("load image: %.8s\n", name);
518 vgaimg *v = R_getvga(id);
519 if (v != NULL) {
520 rgba *buf = (*fn)(v);
521 img = R_gl_create_image(buf, v->w, v->h);
522 img.x = v->x;
523 img.y = v->y;
524 img.res = id;
525 M_unlock(v);
526 free(buf);
527 } else {
528 img = (image) {
529 .res = id
530 };
532 return img;
535 static image R_gl_getimage (int id) {
536 return R_gl_get_special_image(id, &R_extract_rgba_spr);
539 static image R_gl_loadimage (const char name[8]) {
540 return R_gl_getimage(F_getresid(name));
543 static image R_gl_get_special_spr (const char n[4], int s, int d, rgba *(*fn)(vgaimg*)) {
544 return R_gl_get_special_image(F_getsprid(n, s, d), fn);
547 static void R_gl_free_image (image *img) {
548 if (img->n != NULL && img->res >= 0) {
549 R_node_free(img->n);
551 img->n = NULL;
552 img->res = -1;
555 static void R_gl_quad_vetexes (int x, int y, int w, int h) {
556 glVertex2i(x + w, y);
557 glVertex2i(x, y);
558 glVertex2i(x, y + h);
559 glVertex2i(x + w, y + h);
562 static void R_gl_draw_quad (int x, int y, int w, int h) {
563 glBegin(GL_QUADS);
564 R_gl_quad_vetexes(x, y, w, h);
565 glEnd();
568 static void R_gl_draw_textured (image *img, int x, int y, int w, int h, int flip) {
569 if (img->n) {
570 GLfloat nw = img->n->base->root.r + 1;
571 GLfloat nh = img->n->base->root.b + 1;
572 GLfloat ax = (flip ? img->n->l : img->n->r + 1) / nw;
573 GLfloat bx = (flip ? img->n->r + 1 : img->n->l) / nh;
574 GLfloat ay = (img->n->t) / nw;
575 GLfloat by = (img->n->b + 1) / nh;
576 R_gl_bind_texture(img->n->base->id);
577 glEnable(GL_TEXTURE_2D);
578 glBegin(GL_QUADS);
579 glTexCoord2f(ax, ay); glVertex2i(x + w, y);
580 glTexCoord2f(bx, ay); glVertex2i(x, y);
581 glTexCoord2f(bx, by); glVertex2i(x, y + h);
582 glTexCoord2f(ax, by); glVertex2i(x + w, y + h);
583 glEnd();
584 } else {
585 glColor3ub(255, 0, 0);
586 glDisable(GL_BLEND);
587 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
588 glDisable(GL_TEXTURE_2D);
589 R_gl_draw_quad(x, y, w, h);
593 /* fit image into rectangle without applying offset and transparency */
594 static void R_gl_draw_image_ext (image *img, int x, int y, int w, int h) {
595 glDisable(GL_BLEND);
596 glColor3ub(255, 255, 255);
597 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
598 R_gl_draw_textured(img, x, y, w, h, 0);
601 /* draw sprite with offset and coloring */
602 static void R_gl_draw_image_color (image *img, int x, int y, int flip) {
603 int xx = flip ? x - img->w + img->x : x - img->x;
604 glEnable(GL_BLEND);
605 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
606 R_gl_draw_textured(img, xx, y - img->y, img->w, img->h, flip);
609 /* draw sprite with offset */
610 static void R_gl_draw_image (image *img, int x, int y, int flip) {
611 glColor3ub(255, 255, 255);
612 R_gl_draw_image_color(img, x, y, flip);
615 static void R_gl_set_color (byte c) {
616 glColor3ub(playpal[c].r, playpal[c].g, playpal[c].b);
619 static void R_gl_setclip (int x, int y, int w, int h) {
620 glScissor(x * screen_scale, (SCRH - h - y) * screen_scale, w * screen_scale, h * screen_scale);
623 static void R_gl_setmatrix (void) {
624 SCRW = screen_width / screen_scale;
625 SCRH = screen_height / screen_scale;
626 glScissor(0, 0, screen_width, screen_height);
627 glViewport(0, 0, screen_width, screen_height);
628 glMatrixMode(GL_PROJECTION);
629 glLoadIdentity();
630 glOrtho(0, SCRW, SCRH, 0, 0, 1);
631 glMatrixMode(GL_MODELVIEW);
632 glLoadIdentity();
635 /* --- Misc --- */
637 static image Z_getspr (const char n[4], int s, int d, char *dir) {
638 int h = F_getsprid(n, s, d);
639 if (dir != NULL) {
640 *dir = (h & 0x8000) ? 1 : 0;
642 return R_gl_getimage(h);
645 static image *Z_get_char_image (image *img, int ch) {
646 image *p = NULL;
647 ch = cp866_toupper(ch);
648 if (ch > 32 && ch < 160) {
649 p = &img[ch - '!'];
651 return p;
654 static int Z_get_char_width_generic (image *img, int off, int ch) {
655 image *p = Z_get_char_image(img, ch);
656 return p == NULL ? off : p->w - 1;
659 static int Z_putch_generic (image *img, int off, int ch) {
660 image *p = Z_get_char_image(img, ch);
661 int w = p == NULL ? off : p->w - 1;
662 if (p != NULL && p->n != NULL) {
663 R_gl_draw_image(p, prx, pry, 0);
665 prx += w;
666 return w;
669 static int Z_get_string_width_generic (image *img, int off, const char *fmt, va_list ap) {
670 int i, w, ww;
671 char buf[80];
672 vsprintf(buf, fmt, ap);
673 for (i = w = ww = 0; buf[i]; ++i) {
674 switch (buf[i]) {
675 case '\n':
676 case '\r':
677 ww = max(w, ww);
678 w = 0;
679 break;
680 default:
681 w += Z_get_char_width_generic(img, off, (byte)buf[i]);
684 return max(w, ww);
687 static int Z_printf_generic (image *img, int off, const char *fmt, va_list ap) {
688 int i, w, ww;
689 char buf[80];
690 vsprintf(buf, fmt, ap);
691 for (i = w = ww = 0; buf[i]; ++i) {
692 switch (buf[i]) {
693 case '\n':
694 pry += off + 1;
695 case '\r':
696 w = max(w, ww);
697 prx = 0;
698 w = 0;
699 break;
700 default:
701 w += Z_putch_generic(img, off, (byte)buf[i]);
704 return w;
707 static void Z_gotoxy (int x, int y) {
708 prx = x;
709 pry = y;
712 static int Z_get_big_string_width (const char *fmt, ...) {
713 va_list a;
714 va_start(a, fmt);
715 int w = Z_get_string_width_generic(bfh, 12, fmt, a);
716 va_end(a);
717 return w;
720 static int Z_printbf (const char *fmt, ...) {
721 va_list a;
722 va_start(a, fmt);
723 int w = Z_printf_generic(bfh, 12, fmt, a);
724 va_end(a);
725 return w;
728 static int Z_get_small_string_width (const char *fmt, ...) {
729 va_list a;
730 va_start(a, fmt);
731 int w = Z_get_string_width_generic(sfh, 7, fmt, a);
732 va_end(a);
733 return w;
736 static int Z_printsf (const char *fmt, ...) {
737 va_list a;
738 va_start(a, fmt);
739 int w =Z_printf_generic(sfh, 7, fmt, a);
740 va_end(a);
741 return w;
744 static void Z_printhf (const char *fmt, ...) {
745 int i, c;
746 char buf[80];
747 va_list a;
748 va_start(a, fmt);
749 vsprintf(buf, fmt, a);
750 va_end(a);
751 for (i = 0; buf[i]; ++i) {
752 switch (buf[i]) {
753 case '0':
754 case '1':
755 case '2':
756 case '3':
757 case '4':
758 case '5':
759 case '6':
760 case '7':
761 case '8':
762 case '9':
763 c = buf[i] - '0';
764 break;
765 case '-':
766 c = 10;
767 break;
768 case '%':
769 c = 11;
770 break;
771 case '\n':
772 pry += 19;
773 case '\r':
774 c = -1;
775 prx = 0;
776 break;
777 default:
778 c = -1;
779 break;
781 if (c >= 0) {
782 R_gl_draw_image(&sth[c], prx, pry, 0);
784 prx += 14;
788 /* --- Menu --- */
790 static image *PL_getspr (int s, int d, int msk) {
791 int i = (s - 'A') * 2 + d;
792 return msk ? &plr_msk[i] : &plr_spr[i];
795 #define SCROLLER_MIDDLE 10
796 #define TEXTFIELD_MIDDLE 2
798 static void get_entry_size (const menu_t *m, int i, int *w, int *h) {
799 assert(m != NULL);
800 assert(i >= 0);
801 assert(w != NULL);
802 assert(h != NULL);
803 int x = 0;
804 int y = 0;
805 int type = 0;
806 menu_msg_t msg;
807 msg.type = GM_GETENTRY;
808 assert(GM_send(m, i, &msg));
809 type = msg.integer.i;
810 switch (type) {
811 case GM_BUTTON:
812 case GM_SCROLLER:
813 case GM_TEXTFIELD:
814 case GM_TEXTFIELD_BUTTON:
815 msg.type = GM_GETCAPTION;
816 if (GM_send(m, i, &msg)) {
817 x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
819 break;
820 case GM_SMALL_BUTTON:
821 msg.type = GM_GETCAPTION;
822 if (GM_send(m, i, &msg)) {
823 x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s);
825 break;
826 default:
827 assert(0);
829 switch (type) {
830 case GM_BUTTON:
831 msg.type = GM_GETSTR;
832 if (GM_send(m, i, &msg)) {
833 x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
835 y = 16;
836 break;
837 case GM_SMALL_BUTTON:
838 msg.type = GM_GETSTR;
839 if (GM_send(m, i, &msg)) {
840 x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
842 y = 12;
843 break;
844 case GM_SCROLLER:
845 x += (SCROLLER_MIDDLE + 2) * 8;
846 y = 16;
847 break;
848 case GM_TEXTFIELD:
849 case GM_TEXTFIELD_BUTTON:
850 msg.type = GM_GETSTR;
851 if (GM_send(m, i, &msg)) {
852 x += (msg.string.maxlen + 2) * 8;
853 } else {
854 x += (TEXTFIELD_MIDDLE + 2) * 8;
856 y = 16;
857 break;
858 default:
859 assert(0);
861 *w = x;
862 *h = y;
865 static void get_menu_size (const menu_t *m, int *w, int *h) {
866 assert(m != NULL);
867 assert(w != NULL);
868 assert(h != NULL);
869 int i, n, x, y, xx, yy, type;
870 menu_msg_t msg;
871 msg.type = GM_QUERY;
872 if (GM_send_this(m, &msg)) {
873 n = msg.integer.b;
874 type = msg.integer.s;
875 x = 0;
876 y = 0;
877 msg.type = GM_GETTITLE;
878 if (GM_send_this(m, &msg)) {
879 switch (type) {
880 case GM_BIG: x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s); break;
881 case GM_SMALL: x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s); break;
882 default: assert(0);
885 for (i = 0; i < n; i++) {
886 get_entry_size(m, i, &xx, &yy);
887 x = max(x, xx);
888 y += yy;
890 *w = x;
891 *h = y;
892 } else {
893 *w = 0;
894 *h = 0;
898 static int GM_draw (void) {
899 int i, j, n, x, y, xoff, yoff, cur, w, type, recv;
900 const menu_t *m = GM_get();
901 menu_msg_t msg;
902 if (m != NULL) {
903 get_menu_size(m, &x, &y);
904 x = SCRW / 2 - x / 2;
905 y = SCRH / 2 - y / 2;
906 // --- title ---
907 msg.type = GM_QUERY;
908 if (GM_send_this(m, &msg)) {
909 cur = msg.integer.i;
910 n = msg.integer.a;
911 type = msg.integer.s;
912 msg.type = GM_GETTITLE;
913 if (GM_send_this(m, &msg)) {
914 Z_gotoxy(x, y - 10);
915 switch (type) {
916 case GM_SMALL: yoff = 8; Z_printsf("%.*s", msg.string.maxlen, msg.string.s); break;
917 case GM_BIG: yoff = 20; Z_printbf("%.*s", msg.string.maxlen, msg.string.s); break;
918 default: assert(0);
920 } else {
921 yoff = 0;
923 for (i = 0; i < n; i++) {
924 msg.type = GM_GETENTRY;
925 if (GM_send(m, i, &msg)) {
926 type = msg.integer.i;
927 if (i == cur) {
928 if (type == GM_SMALL_BUTTON) {
929 Z_gotoxy(x - 8, y + yoff);
930 Z_printsf(">");
931 } else {
932 R_gl_draw_image(&msklh[(gm_tm / 6) & 1], x - 25, y + yoff - 8, 0);
935 msg.type = GM_GETCAPTION;
936 if (GM_send(m, i, &msg)) {
937 Z_gotoxy(x, y + yoff);
938 if (type == GM_SMALL_BUTTON) {
939 xoff = Z_printsf("%.*s", msg.string.maxlen, msg.string.s);
940 } else {
941 xoff = Z_printbf("%.*s", msg.string.maxlen, msg.string.s);
943 } else {
944 xoff = 0;
946 switch (type) {
947 case GM_BUTTON:
948 case GM_SMALL_BUTTON:
949 msg.type = GM_GETSTR;
950 if (GM_send(m, i, &msg)) {
951 Z_gotoxy(x + xoff, y + yoff);
952 if (type == GM_SMALL_BUTTON) {
953 Z_printsf("%.*s", msg.string.maxlen, msg.string.s);
954 } else {
955 Z_printbf("%.*s", msg.string.maxlen, msg.string.s);
958 yoff += type == GM_BUTTON ? 16 : 12;
959 break;
960 case GM_TEXTFIELD:
961 case GM_TEXTFIELD_BUTTON:
962 yoff += 9;
963 msg.type = GM_GETSTR;
964 recv = GM_send(m, i, &msg);
965 w = recv ? msg.string.maxlen : TEXTFIELD_MIDDLE;
966 R_gl_draw_image(&mslotl, x + xoff, y + yoff, 0);
967 for (j = 1; j <= w; j++) {
968 R_gl_draw_image(&mslotm, x + xoff + j * 8, y + yoff, 0);
970 R_gl_draw_image(&mslotr, x + xoff + j * 8, y + yoff, 0);
971 Z_gotoxy(x + xoff + 4, y + yoff - 7);
972 if (input && i == cur) {
973 Z_printsf("%.*s_", imax, ibuf);
974 } else if (recv) {
975 Z_printsf("%.*s", msg.string.maxlen, msg.string.s);
977 yoff += 7;
978 break;
979 case GM_SCROLLER:
980 R_gl_draw_image(&mbarl, x + xoff, y + yoff, 0);
981 for (j = 1; j < SCROLLER_MIDDLE; j++) {
982 R_gl_draw_image(&mbarm, x + xoff + j * 8, y + yoff, 0);
984 R_gl_draw_image(&mbarr, x + xoff + j * 8, y + yoff, 0);
985 msg.type = GM_GETINT;
986 if (GM_send(m, i, &msg)) {
987 int lev = (msg.integer.i - msg.integer.a) * ((SCROLLER_MIDDLE - 2) * 8) / msg.integer.b;
988 R_gl_draw_image(&mbaro, x + xoff + lev + 8, y + yoff, 0);
990 yoff += 16;
991 break;
992 default:
993 assert(0);
999 return m != NULL;
1002 /* --- View --- */
1004 static void R_draw_fld (byte *fld, int minx, int miny, int maxx, int maxy, int fg) {
1005 int i, j;
1006 assert(minx >= 0 && minx <= FLDW);
1007 assert(miny >= 0 && miny <= FLDH);
1008 assert(maxx >= 0 && maxx <= FLDW);
1009 assert(maxy >= 0 && maxy <= FLDH);
1010 for (j = miny; j < maxy; j++) {
1011 for (i = minx; i < maxx; i++) {
1012 byte id = fld[j * FLDW + i];
1013 if (id != 0) {
1014 if (walp[id].res < 0) {
1015 if (fg) {
1016 switch (R_get_special_id(id)) {
1017 case 1:
1018 glColor4ub(0, 0, 255, 127);
1019 break;
1020 case 2:
1021 glColor4ub(0, 127, 0, 127);
1022 break;
1023 case 3:
1024 glColor4ub(127, 0, 0, 127);
1025 break;
1026 default:
1027 glColor4ub(0, 0, 0, 127);
1028 break;
1030 glEnable(GL_BLEND);
1031 glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1032 glDisable(GL_TEXTURE_2D);
1033 R_gl_draw_quad(i * CELW, j * CELW, CELW, CELH);
1035 } else {
1036 R_gl_draw_image(&walp[id], i * CELW, j * CELH, 0);
1043 static void R_draw_dots (void) {
1044 int i;
1045 glDisable(GL_BLEND);
1046 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1047 glDisable(GL_TEXTURE_2D);
1048 glBegin(GL_QUADS);
1049 for (i = 0; i < MAXDOT; i++) {
1050 if (dot[i].t != 0) {
1051 R_gl_set_color(dot[i].c);
1052 R_gl_quad_vetexes(dot[i].o.x, dot[i].o.y, 1, 1);
1055 glEnd();
1058 static void R_draw_items (void) {
1059 int i, s;
1060 for (i = 0; i < MAXITEM; ++i) {
1061 s = -1;
1062 if (it[i].t && it[i].s >= 0) {
1063 switch (it[i].t & 0x7FFF) {
1064 case I_ARM1:
1065 s = it[i].s / 9 + 18;
1066 break;
1067 case I_ARM2:
1068 s = it[i].s / 9 + 20;
1069 break;
1070 case I_MEGA:
1071 s = it[i].s / 2 + 22;
1072 break;
1073 case I_INVL:
1074 s = it[i].s / 2 + 26;
1075 break;
1076 case I_SUPER:
1077 case I_RTORCH:
1078 case I_GTORCH:
1079 case I_BTORCH:
1080 s = it[i].s / 2 + (it[i].t - I_SUPER) * 4 + 35;
1081 break;
1082 case I_GOR1: case I_FCAN:
1083 s = it[i].s / 2 + (it[i].t - I_GOR1) * 3 + 51;
1084 break;
1085 case I_AQUA:
1086 s = 30;
1087 break;
1088 case I_SUIT:
1089 s = 34;
1090 break;
1091 case I_KEYR:
1092 case I_KEYG:
1093 case I_KEYB:
1094 s = (it[i].t & 0x7FFF) - I_KEYR + 31;
1095 break;
1096 case I_GUN2:
1097 s = 57;
1098 break;
1099 default:
1100 s = (it[i].t & 0x7FFF) - 1;
1103 if (s >= 0) {
1104 R_gl_draw_image(&item_spr[s], it[i].o.x, it[i].o.y, item_sprd[s]);
1109 static int standspr (player_t *p) {
1110 if (p->f & PLF_UP) {
1111 return 'X';
1112 } else if (p->f & PLF_DOWN) {
1113 return 'Z';
1114 } else {
1115 return 'E';
1119 static int wpnspr (player_t *p) {
1120 if (p->f & PLF_UP) {
1121 return 'C';
1122 } else if(p->f & PLF_DOWN) {
1123 return 'E';
1124 } else {
1125 return 'A';
1129 static void R_draw_player (player_t *p) {
1130 enum {STAND, GO, DIE, SLOP, DEAD, MESS, OUT, FALL}; // copypasted from player.c!
1131 static const int wytab[] = {-1, -2, -1, 0};
1132 int s = 'A';
1133 int w = 0;
1134 int wx = 0;
1135 int wy = 0;
1136 switch (p->st) {
1137 case STAND:
1138 if (p->f & PLF_FIRE) {
1139 s = standspr(p) + 1;
1140 w = wpnspr(p) + 1;
1141 } else if (p->pain) {
1142 s = 'G';
1143 w = 'A';
1144 wx = p->d ? 2 : -2;
1145 wy = 1;
1146 } else {
1147 s = standspr(p);
1148 w = wpnspr(p);
1150 break;
1151 case DEAD:
1152 s = 'N';
1153 break;
1154 case MESS:
1155 s = 'W';
1156 break;
1157 case GO:
1158 if (p->pain) {
1159 s = 'G';
1160 w = 'A';
1161 wx = p->d ? 2 : -2;
1162 wy = 1;
1163 } else {
1164 s = plr_goanim[p->s / 8];
1165 w = (p->f & PLF_FIRE) ? 'B' : 'A';
1166 wx = p->d ? 2 : -2;
1167 wy = 1 + wytab[s - 'A'];
1169 break;
1170 case DIE:
1171 s = plr_dieanim[p->s];
1172 break;
1173 case SLOP:
1174 s = plr_slopanim[p->s];
1175 break;
1176 case OUT:
1177 s = 0;
1178 break;
1180 if (p->wpn == 0) {
1181 w = 0;
1183 if (w) {
1184 R_gl_draw_image(&plr_wpn[(int)p->wpn][w -'A'], p->o.x + wx, p->o.y + wy, p->d);
1186 if (s) {
1187 R_gl_draw_image(&plr_spr[(s - 'A') * 2 + p->d], p->o.x, p->o.y, plr_sprd[(s - 'A') * 2 + p->d]);
1188 R_gl_set_color(p->color + PLAYER_COLOR_OFFSET);
1189 R_gl_draw_image_color(&plr_msk[(s - 'A') * 2 + p->d], p->o.x, p->o.y, plr_sprd[(s - 'A') * 2 + p->d]);
1193 static void R_draw_monsters (void) {
1194 enum {SLEEP, GO, RUN, CLIMB, DIE, DEAD, ATTACK, SHOOT, PAIN, WAIT, REVIVE, RUNOUT}; // copypasted from monster.c!
1195 int i;
1196 for (i = 0; i < MAXMN; i++) {
1197 if (mn[i].t != MN_NONE) {
1198 int x = mn[i].o.x;
1199 int y = mn[i].o.y;
1200 if (mn[i].t < MN__LAST) {
1201 if ((mn[i].t != MN_SOUL && mn[i].t != MN_PAIN) || mn[i].st != DEAD) {
1202 int ap = mn[i].ap[mn[i].ac];
1203 int d = (ap - 'A') * 2 + mn[i].d;
1204 int dir = mn_sprd[mn[i].t - 1][d];
1205 if (mn[i].t == MN_MAN && (ap == 'E' || ap == 'F')) {
1206 R_gl_draw_image(&mn_sgun[ap - 'E'], x, y, mn[i].d);
1208 R_gl_draw_image(&mn_spr[mn[i].t - 1][d], x, y, dir);
1209 if (mn[i].t == MN_MAN) {
1210 R_gl_set_color(MANCOLOR + PLAYER_COLOR_OFFSET);
1211 R_gl_draw_image_color(&mn_man_msk[d], x, y, dir);
1214 if (mn[i].t == MN_VILE && mn[i].st == SHOOT) {
1215 R_gl_draw_image(&mn_fspr[mn[i].ac / 3], mn[i].tx, mn[i].ty, 0);
1217 } else if (mn[i].t == MN_PL_DEAD || mn[i].t == MN_PL_MESS) {
1218 int type = mn[i].t - MN_PL_DEAD;
1219 R_gl_draw_image(&pl_spr[type], x, y, 0);
1220 R_gl_set_color(mn[i].d);
1221 R_gl_draw_image_color(&pl_msk[type], x, y, 0);
1227 static void R_draw_weapons (void) {
1228 enum {NONE, ROCKET, PLASMA, APLASMA, BALL1, BALL2, BALL7, BFGBALL, BFGHIT, MANF, REVF, FIRE}; // copypasted from weapons.c!
1229 int i, s, d, x, y;
1230 for (i = 0; i < MAXWPN; ++i) {
1231 s = -1;
1232 d = 0;
1233 switch (wp[i].t) {
1234 case REVF:
1235 case ROCKET:
1236 d = wp[i].s;
1237 if (d < 2) {
1238 d = wp[i].o.xv > 0 ? 1 : 0;
1239 x = abs(wp[i].o.xv);
1240 y = wp[i].o.yv;
1241 s = 0;
1242 if (y < 0) {
1243 if (-y >= x) {
1244 s = 30;
1246 } else if (y > 0) {
1247 if (y >= x / 2) {
1248 s = 31;
1251 } else {
1252 s = (d - 2) / 2 + 1;
1253 d = 0;
1255 break;
1256 case MANF:
1257 s=wp[i].s;
1258 if (s >= 2) {
1259 s /= 2;
1260 break;
1262 case PLASMA:
1263 case APLASMA:
1264 case BALL1:
1265 case BALL7:
1266 case BALL2:
1267 s = wp[i].s;
1268 if (s >= 2) {
1269 s = s / 2 + 1;
1271 switch (wp[i].t) {
1272 case PLASMA:
1273 s += 4;
1274 break;
1275 case APLASMA:
1276 s += 11;
1277 break;
1278 case BALL1:
1279 s += 32;
1280 break;
1281 case BALL2:
1282 s += 42;
1283 break;
1284 case BALL7:
1285 s += 37;
1286 d = wp[i].o.xv >= 0 ? 1 : 0;
1287 break;
1288 case MANF:
1289 s += 47;
1290 d= wp[i].o.xv>=0 ? 1 : 0;
1291 break;
1293 break;
1294 case BFGBALL:
1295 s = wp[i].s;
1296 if (s >= 2) {
1297 s = s / 2 + 1;
1299 s += 18;
1300 break;
1301 case BFGHIT:
1302 s = wp[i].s / 2 + 26;
1303 break;
1305 if (s >= 0) {
1306 R_gl_draw_image(&wp_spr[s * 2 + d], wp[i].o.x, wp[i].o.y, wp_sprd[s * 2 + d]);
1311 static void R_draw_smoke (void) {
1312 int i, s;
1313 for (i = 0; i < MAXSMOK; ++i) {
1314 if (sm[i].t) {
1315 switch (sm[i].s) {
1316 case 0:
1317 s = sm[i].t;
1318 if (s >= (SMSN - 1) * 3) {
1319 s = 0;
1320 } else {
1321 s = SMSN - 1 - s / 3;
1323 R_gl_draw_image(&smk_spr[s], sm[i].x >> 8, (sm[i].y >> 8) + 1, 0);
1324 break;
1325 case 1:
1326 s = sm[i].t;
1327 if (s >= FLSN - 1) {
1328 s = 0;
1329 } else {
1330 s = FLSN - 1 - s;
1332 R_gl_draw_image(&smk_fspr[s], sm[i].x >> 8, (sm[i].y >> 8) + 1, 0);
1333 break;
1339 static void R_draw_effects (void) {
1340 enum {NONE, TFOG, IFOG, BUBL}; // copypasted from fx.c
1341 int i, s;
1342 glPointSize(screen_scale);
1343 for (i = 0; i < MAXFX; ++i) {
1344 switch (fx[i].t) {
1345 case TFOG:
1346 s = fx[i].s / 2;
1347 R_gl_draw_image(&fx_spr[s], fx[i].x, fx[i].y, fx_sprd[s]);
1348 break;
1349 case IFOG:
1350 s = fx[i].s / 2 + 10;
1351 R_gl_draw_image(&fx_spr[s], fx[i].x, fx[i].y, fx_sprd[s]);
1352 break;
1353 case BUBL:
1354 glDisable(GL_BLEND);
1355 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1356 glDisable(GL_TEXTURE_2D);
1357 R_gl_set_color(0xC0 + fx[i].s);
1358 R_gl_draw_quad(fx[i].x >> 8, fx[i].y >> 8, 1, 1);
1359 break;
1364 static int get_pu_st (int t) {
1365 if (t >= PL_FLASH) {
1366 return 1;
1367 } else if((t / 9) & 1) {
1368 return 0;
1369 } else {
1370 return 1;
1374 static void R_draw_view (int x, int y, int w, int h, int camx, int camy) {
1375 glPushMatrix();
1376 R_gl_setclip(x, y, w, h);
1377 glTranslatef(x, y, 0);
1378 if (w_horiz && horiz.n != NULL) {
1379 R_gl_draw_image_ext(&horiz, 0, 0, w, h);
1380 if (sky_type == 2 && lt_time < 0) {
1381 image *tanderbolt = &ltn[lt_type][lt_time < -5 ? 0 : 1];
1382 if (!lt_side) {
1383 R_gl_draw_image(tanderbolt, 0, lt_ypos, 0);
1384 } else {
1385 R_gl_draw_image(tanderbolt, w - 1, lt_ypos, 1);
1388 } else {
1389 glDisable(GL_BLEND);
1390 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1391 glDisable(GL_TEXTURE_2D);
1392 R_gl_set_color(DEFAULT_SKY_COLOR);
1393 R_gl_draw_quad(0, 0, w, h);
1395 int maxx = min((camx + w) / CELW + 1, FLDW);
1396 int maxy = min((camy + h) / CELH + 1, FLDH);
1397 int minx = max((camx - max_wall_width) / CELW, 0);
1398 int miny = max((camy - max_wall_height) / CELH, 0);
1399 glTranslatef(-camx, -camy, 0);
1400 R_draw_fld((byte*)fldb, minx, miny, maxx, maxy, 0);
1401 R_draw_dots();
1402 R_draw_items();
1403 R_draw_player(&pl1);
1404 if (_2pl) {
1405 R_draw_player(&pl2);
1407 R_draw_monsters();
1408 R_draw_weapons();
1409 R_draw_smoke();
1410 R_draw_effects();
1411 R_draw_fld((byte*)fldf, minx, miny, maxx, maxy, 1);
1412 glTranslatef(camx, camy, 0);
1413 if (sky_type == 2 && (lt_time == -4 || lt_time == -2)) {
1414 glColor4ub(255, 255, 255, 255);
1415 glEnable(GL_BLEND);
1416 glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1417 glDisable(GL_TEXTURE_2D);
1418 R_gl_draw_quad(0, 0, w, h);
1420 glPopMatrix();
1423 static void R_draw_player_view (player_t *p, int x, int y, int w, int h) {
1424 p->looky = min(max(p->looky, -SCRH / 4), SCRH / 4); // TODO remove writeback
1425 int st = stone.w;
1426 int cw = w - st;
1427 int cx = min(max(p->o.x, cw / 2), FLDW * CELW - cw / 2);
1428 int cy = min(max(p->o.y - 12 + p->looky, h / 2), FLDH * CELH - h / 2);
1429 int camx = max(cx - cw / 2, 0);
1430 int camy = max(cy - h / 2, 0);
1431 glPushMatrix();
1432 R_draw_view(x, y + 1, cw, h - 2, camx, camy);
1433 glTranslatef(x, y, 0);
1434 if (p->invl) {
1435 if (get_pu_st(p->invl)) {
1436 glEnable(GL_BLEND);
1437 glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
1438 glDisable(GL_TEXTURE_2D);
1439 glColor4ub(191, 191, 191, 255);
1440 R_gl_draw_quad(0, 0, cw, h);
1442 } else {
1443 if (p->suit && get_pu_st(p->suit)) {
1444 glEnable(GL_BLEND);
1445 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1446 glDisable(GL_TEXTURE_2D);
1447 glColor4ub(0, 255, 0, 192);
1448 R_gl_draw_quad(0, 0, cw, h);
1450 int f = min(max(p->pain * 3, 0), 255);
1451 if (f > 0) {
1452 glEnable(GL_BLEND);
1453 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1454 glDisable(GL_TEXTURE_2D);
1455 glColor4ub(255, 0, 0, f);
1456 R_gl_draw_quad(0, 0, cw, h);
1459 R_gl_setclip(x, y, w, h);
1460 glTranslatef(-x + cw, 0, 0);
1461 R_gl_draw_image(&stone, 0, 0, 0);
1462 int i = stone.h;
1463 while (i < h) {
1464 R_gl_draw_image(&stone2, 0, i, 0);
1465 i += stone2.h;
1467 if (p->drawst & PL_DRAWAIR) {
1468 if (p->air < PL_AIR) {
1469 int a = min(max(p->air, 0), MAXAIR) * 100 / MAXAIR;
1470 glDisable(GL_BLEND);
1471 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1472 glDisable(GL_TEXTURE_2D);
1473 R_gl_set_color(0xC8);
1474 R_gl_draw_quad(10, 49, a, 2);
1477 if (p->drawst & PL_DRAWLIFE) {
1478 Z_gotoxy(10, 7);
1479 Z_printhf("%3d%%", p->life);
1481 if (p->drawst & PL_DRAWARMOR) {
1482 Z_gotoxy(10, 7 + 19);
1483 Z_printhf("%3d%%", p->armor);
1485 if (p->drawst & PL_DRAWWPN) {
1486 switch(p->wpn) {
1487 case 2:
1488 case 5:
1489 i = p->ammo;
1490 break;
1491 case 3:
1492 case 4:
1493 case 9:
1494 i = p->shel;
1495 break;
1496 case 6:
1497 i = p->rock;
1498 break;
1499 case 7:
1500 case 8:
1501 i = p->cell;
1502 break;
1503 case 10:
1504 i = p->fuel;
1505 break;
1506 default:
1507 i = -1;
1508 break;
1510 // weapon
1511 if (p->wpn >= 0) {
1512 R_gl_draw_image(&sth[12 + p->wpn], st - 88, 58 + 19, 0);
1514 // ammo
1515 if (p->wpn >= 2) {
1516 Z_gotoxy(st - 10 - 5 * 14, 58 + 2);
1517 Z_printhf("%5d", i);
1520 if (p->drawst & PL_DRAWFRAG && g_dm) {
1521 Z_gotoxy(st - 5 - 5 * 14, 77 + 5);
1522 Z_printhf("%5d", p->frag);
1524 if (p->drawst & PL_DRAWKEYS) {
1525 int x, k, n;
1526 for (k = p->keys >> 4, n = 0, x = st - 75; n < 3; n++, k >>= 1, x += 9) {
1527 if (k & 1) {
1528 R_gl_draw_image(&keys[n], x, 91, 0);
1532 if (p->drawst & PL_DRAWLIVES && !_2pl) {
1533 Z_gotoxy(st - 35, 17);
1534 Z_printhf("%d", p->lives);
1536 glPopMatrix();
1539 /* --- Game --- */
1541 static void pl_info (player_t *p, int x, int y) {
1542 dword t = p->kills * 10920 / g_time;
1543 Z_gotoxy(x + 25, y); Z_printbf("KILLS");
1544 Z_gotoxy(x + 25, y + 15); Z_printbf("KPM");
1545 Z_gotoxy(x + 25, y + 30); Z_printbf("SECRETS %u / %u", p->secrets, sw_secrets);
1546 Z_gotoxy(x + 255, y); Z_printbf("%u", p->kills);
1547 Z_gotoxy(x + 255, y + 15); Z_printbf("%u.%u", t / 10, t % 10);
1550 static void R_draw_intermission (void) {
1551 int cx = SCRW / 2;
1552 word hr, mn, sc, h;
1553 Z_gotoxy(cx - 14*12/2, 20);
1554 Z_printbf("LEVEL COMPLETE");
1555 Z_calc_time(g_time, &hr, &mn, &sc);
1556 Z_gotoxy(cx - 12*12/2, 40);
1557 Z_printbf("TIME %u:%02u:%02u", hr, mn, sc);
1558 h = 40 + SCRH / 10;
1559 if (_2pl) {
1560 Z_gotoxy(cx - 10*12/2, h);
1561 Z_printbf("PLAYER ONE");
1562 h += 20;
1564 pl_info(&pl1, cx - 160, h);
1565 if (_2pl) {
1566 h += 30 + SCRH / 10;
1567 Z_gotoxy(cx - 10*12/2, h);
1568 Z_printbf("PLAYER TWO");
1569 h += 20;
1570 pl_info(&pl2, cx - 160, h);
1574 static void W_act (void) {
1575 int i, a;
1576 if (g_time % 3 == 0) {
1577 for (i = 1; i < max_textures; i++) {
1578 a = walani[i];
1579 if (a != 0) {
1580 anic[a]++;
1581 if (anip[a][anic[a]].res == -1) {
1582 anic[a] = 0;
1584 walp[i] = anip[a][anic[a]];
1590 void R_draw (void) {
1591 W_act();
1592 glClearColor(0, 0, 0, 1);
1593 glClear(GL_COLOR_BUFFER_BIT);
1594 glEnable(GL_SCISSOR_TEST);
1595 R_gl_setmatrix();
1596 switch (g_st) {
1597 case GS_ENDANIM:
1598 case GS_END2ANIM:
1599 case GS_DARKEN:
1600 case GS_BVIDEO:
1601 case GS_EVIDEO:
1602 case GS_END3ANIM:
1603 break;
1604 case GS_TITLE:
1605 R_gl_draw_image_ext(&scrnh[0], 0, 0, SCRW, SCRH);
1606 break;
1607 case GS_INTER:
1608 R_gl_draw_image_ext(&scrnh[1], 0, 0, SCRW, SCRH);
1609 R_draw_intermission();
1610 break;
1611 case GS_ENDSCR:
1612 R_gl_draw_image_ext(&scrnh[2], 0, 0, SCRW, SCRH);
1613 break;
1614 case GS_GAME:
1615 if (_2pl) {
1616 R_draw_player_view(&pl1, 0, 0, SCRW, SCRH / 2);
1617 R_draw_player_view(&pl2, 0, SCRH / 2, SCRW, SCRH / 2);
1618 } else {
1619 R_draw_player_view(&pl1, 0, 0, SCRW, SCRH);
1621 R_gl_setclip(0, 0, SCRW, SCRH);
1622 break;
1624 GM_draw();
1625 Y_swap_buffers();
1628 static void R_alloc (void) {
1629 char s[10];
1630 int i, j, n;
1631 logo("R_alloc: load graphics\n");
1632 /* Game */
1633 scrnh[0] = R_gl_loadimage("TITLEPIC");
1634 scrnh[1] = R_gl_loadimage("INTERPIC");
1635 scrnh[2] = R_gl_loadimage("ENDPIC");
1636 for (i = 0; i < 2; i++) {
1637 sprintf(s, "LTN%c", '1' + i);
1638 for (j = 0; j < 2; j++) {
1639 ltn[i][j] = Z_getspr(s, j, 0, NULL);
1642 /* Smoke */
1643 for (i = 0; i < SMSN; i++) {
1644 smk_spr[i] = R_gl_get_special_spr("SMOK", i, 0, &R_extract_smoke_spr);
1646 for (i = 0; i < FLSN; i++) {
1647 smk_fspr[i] = R_gl_get_special_spr("SMOK", i, 0, &R_extract_flame_spr);
1649 /* Effects */
1650 for (i = 0; i < 10; i++) {
1651 fx_spr[i] = Z_getspr("TFOG", i, 0, fx_sprd + i);
1653 for (; i < 15; i++) {
1654 fx_spr[i] = Z_getspr("IFOG", i - 10, 0, fx_sprd + i);
1656 /* Weapons */
1657 for (i = 0; i < 4; i++) {
1658 wp_spr[i * 2] = Z_getspr("MISL", i, 1, wp_sprd + i * 2);
1659 wp_spr[i * 2 + 1] = Z_getspr("MISL", i, 2, wp_sprd + i * 2 + 1);
1661 for (; i < 6; i++) {
1662 wp_spr[i * 2] = Z_getspr("PLSS", i - 4, 1, wp_sprd + i * 2);
1663 wp_spr[i * 2 + 1] = Z_getspr("PLSS", i - 4, 2, wp_sprd + i * 2 + 1);
1665 for (; i < 11; i++) {
1666 wp_spr[i * 2] = Z_getspr("PLSE", i - 6, 1, wp_sprd + i * 2);
1667 wp_spr[i * 2 + 1] = Z_getspr("PLSE", i - 6, 2, wp_sprd + i * 2 + 1);
1669 for (; i < 13; i++) {
1670 wp_spr[i * 2] = Z_getspr("APLS", i - 11, 1, wp_sprd + i * 2);
1671 wp_spr[i * 2 + 1] = Z_getspr("APLS", i - 11, 2, wp_sprd + i * 2 + 1);
1673 for (; i < 18; i++) {
1674 wp_spr[i * 2] = Z_getspr("APBX", i - 13, 1, wp_sprd + i * 2);
1675 wp_spr[i * 2 + 1] = Z_getspr("APBX", i - 13, 2, wp_sprd + i * 2 + 1);
1677 for(; i < 20; i++) {
1678 wp_spr[i * 2] = Z_getspr("BFS1", i - 18, 1, wp_sprd + i * 2);
1679 wp_spr[i * 2 + 1] = Z_getspr("BFS1", i - 18, 2, wp_sprd + i * 2 + 1);
1681 for (; i < 26; i++) {
1682 wp_spr[i * 2] = Z_getspr("BFE1", i - 20, 1, wp_sprd + i * 2);
1683 wp_spr[i * 2 + 1] = Z_getspr("BFE1", i - 20, 2, wp_sprd + i * 2 + 1);
1685 for (; i < 30; i++) {
1686 wp_spr[i * 2] = Z_getspr("BFE2", i - 26, 1, wp_sprd + i * 2);
1687 wp_spr[i * 2 + 1] = Z_getspr("BFE2", i - 26, 2, wp_sprd + i * 2 + 1);
1689 for (; i < 32; i++) {
1690 wp_spr[i * 2] = Z_getspr("MISL", i - 30 + 4, 1, wp_sprd + i * 2);
1691 wp_spr[i * 2 + 1] = Z_getspr("MISL", i - 30 + 4, 2, wp_sprd + i * 2 + 1);
1693 for (; i < 37; i++) {
1694 wp_spr[i * 2] = Z_getspr("BAL1", i - 32, 1, wp_sprd + i * 2);
1695 wp_spr[i * 2 + 1] = Z_getspr("BAL1", i - 32, 2, wp_sprd + i * 2 + 1);
1697 for (; i < 42; i++) {
1698 wp_spr[i * 2] = Z_getspr("BAL7", i - 37, 1, wp_sprd + i * 2);
1699 wp_spr[i * 2 + 1] = Z_getspr("BAL7", i - 37, 2, wp_sprd + i * 2 + 1);
1701 for (; i < 47; i++) {
1702 wp_spr[i * 2] = Z_getspr("BAL2", i - 42, 1, wp_sprd + i * 2);
1703 wp_spr[i * 2 + 1] = Z_getspr("BAL2", i - 42, 2, wp_sprd + i * 2 + 1);
1705 for (; i < 49; i++) {
1706 wp_spr[i * 2] = Z_getspr("MANF", i - 47, 1, wp_sprd + i * 2);
1707 wp_spr[i * 2 + 1] = Z_getspr("MANF", i - 47, 2, wp_sprd + i * 2 + 1);
1709 /* Items */
1710 static const char snm[18][4] = {
1711 "CLIP", "SHEL", "ROCK", "CELL", "AMMO", "SBOX", "BROK", "CELP",
1712 "STIM", "MEDI", "BPAK",
1713 "CSAW", "SHOT", "SGN2", "MGUN", "LAUN", "PLAS", "BFUG"
1714 };
1715 static const char n4[4][4] = {
1716 "SOUL", "SMRT", "SMGT", "SMBT"
1717 };
1718 static const char n3[2][4] = {
1719 "GOR1", "FCAN"
1720 };
1721 for (i = 0; i < 18; i++) {
1722 item_spr[i] = Z_getspr(snm[i], 0, 0, item_sprd + i);
1724 for (; i < 20; i++) {
1725 item_spr[i] = Z_getspr("ARM1", i - 18, 0, item_sprd + i);
1726 item_spr[i + 2] = Z_getspr("ARM2", i - 18, 0, item_sprd + i);
1728 i+=2;
1729 for (; i < 26; i++) {
1730 item_spr[i] = Z_getspr("MEGA", i - 22, 0, item_sprd + i);
1732 for (; i < 30; i++) {
1733 item_spr[i] = Z_getspr("PINV", i - 26, 0, item_sprd + i);
1735 item_spr[30] = Z_getspr("AQUA", 0, 0, item_sprd + 30);
1736 item_spr[31] = Z_getspr("KEYR", 0, 0, item_sprd + 31);
1737 item_spr[32] = Z_getspr("KEYG", 0, 0, item_sprd + 32);
1738 item_spr[33] = Z_getspr("KEYB", 0, 0, item_sprd + 33);
1739 item_spr[34] = Z_getspr("SUIT", 0, 0, item_sprd + 34);
1740 for (n = 35, j = 0; j < 4; j++) {
1741 for (i = 0; i < 4; i++, n++) {
1742 item_spr[n] = Z_getspr(n4[j], i, 0, item_sprd + n);
1745 for (j = 0; j < 2; j++) {
1746 for (i = 0; i < 3; i++, n++) {
1747 item_spr[n] = Z_getspr(n3[j], i, 0, item_sprd + n);
1750 item_spr[57] = Z_getspr("GUN2", 0, 0, item_sprd + 57);
1751 /* Player */
1752 for (i = 0; i < 27; i++) {
1753 plr_spr[i * 2] = Z_getspr("PLAY", i, 1, plr_sprd + i * 2);
1754 plr_msk[i * 2] = R_gl_get_special_spr("PLAY", i, 1, &R_extract_mask_spr);
1755 plr_spr[i * 2 + 1] = Z_getspr("PLAY", i, 2, plr_sprd + i * 2 + 1);
1756 plr_msk[i * 2 + 1] = R_gl_get_special_spr("PLAY", i, 2, &R_extract_mask_spr);
1758 strncpy(s, "PWPx", 4);
1759 for (i = 1; i < 11; i++) {
1760 s[3] = (i < 10 ? '0' : 'A' - 10) + i;
1761 for (j = 0; j < 6; j++) {
1762 plr_wpn[i][j] = Z_getspr(s, j, 1, NULL);
1765 /* Monsters */
1766 static const char msn[MN_TN][4] = {
1767 "SARG", "TROO", "POSS", "SPOS", "CYBR", "CPOS", "BOSS", "BOS2", "HEAD", "SKUL",
1768 "PAIN", "SPID", "BSPI", "FATT", "SKEL", "VILE", "FISH", "BAR1", "ROBO", "PLAY"
1769 };
1770 static const int mms[MN_TN] = {
1771 14*2, 21*2, 21*2, 21*2, 16*2, 20*2, 15*2, 15*2, 12*2, 11*2,
1772 13*2, 19*2, 16*2, 20*2, 17*2, 29*2, 6*2, 2*2, 17*2, 23*2
1773 };
1774 mn_sgun[0] = Z_getspr("PWP4", 0, 1, NULL);
1775 mn_sgun[1] = Z_getspr("PWP4", 1, 1, NULL);
1776 for (j = 0; j < MN_TN; j++) {
1777 for (i = 0; i < mms[j]; i++) {
1778 mn_spr[j][i] = Z_getspr(msn[j], i / 2, (i & 1) + 1, &mn_sprd[j][i]);
1779 if (j == MN_MAN - 1) {
1780 mn_man_msk[i] = R_gl_get_special_spr(msn[j], i / 2, (i & 1) + 1, &R_extract_mask_spr);
1783 if (j == MN_BARREL - 1) {
1784 for (i = 4; i < 14; i++) {
1785 mn_spr[j][i] = Z_getspr("BEXP", i / 2 - 2, (i & 1) + 1, &mn_sprd[j][i]);
1789 for (i = 0; i < 8; i++) {
1790 mn_fspr[i] = Z_getspr("FIRE", i, 0, NULL);
1792 pl_spr[0] = Z_getspr("PLAY", 'N' - 'A', 0, NULL);
1793 pl_msk[0] = R_gl_get_special_spr("PLAY", 'N' - 'A', 0, &R_extract_mask_spr);
1794 pl_spr[1] = Z_getspr("PLAY", 'W' - 'A', 0, NULL);
1795 pl_msk[1] = R_gl_get_special_spr("PLAY", 'W' - 'A', 0, &R_extract_mask_spr);
1796 /* Misc */
1797 static const char mnm[22][8]={
1798 "STTNUM0", "STTNUM1", "STTNUM2", "STTNUM3", "STTNUM4",
1799 "STTNUM5", "STTNUM6", "STTNUM7", "STTNUM8", "STTNUM9",
1800 "STTMINUS", "STTPRCNT",
1801 "FISTA0", "CSAWA0", "PISTA0", "SHOTA0", "SGN2A0", "MGUNA0", "LAUNA0",
1802 "PLASA0", "BFUGA0", "GUN2A0"
1803 };
1804 stone = R_gl_loadimage("STONE");
1805 stone2 = R_gl_loadimage("STONE2");
1806 keys[0] = R_gl_loadimage("KEYRA0");
1807 keys[1] = R_gl_loadimage("KEYGA0");
1808 keys[2] = R_gl_loadimage("KEYBA0");
1809 for (i = 0; i < 22; i++) {
1810 sth[i] = R_gl_loadimage(mnm[i]);
1812 strcpy(s, "STBF_*");
1813 for (i = '!'; i < 160; i++) {
1814 s[5] = i;
1815 bfh[i - '!'] = R_gl_getimage(F_findres(s));
1817 for (i = '!'; i < 160; i++) {
1818 sprintf(s, "STCFN%03d", i);
1819 sfh[i - '!'] = R_gl_getimage(F_findres(s));
1821 strcpy(s, "WINUM*");
1822 for (i = '0'; i <= '9'; i++) {
1823 s[5] = i;
1824 bfh[i - '!'] = R_gl_loadimage(s);
1826 bfh[':' - '!'] = R_gl_loadimage("WICOLON");
1827 // menu
1828 msklh[0] = R_gl_loadimage("M_SKULL1");
1829 msklh[1] = R_gl_loadimage("M_SKULL2");
1830 mbarl = R_gl_loadimage("M_THERML");
1831 mbarm = R_gl_loadimage("M_THERMM");
1832 mbarr = R_gl_loadimage("M_THERMR");
1833 mbaro = R_gl_loadimage("M_THERMO");
1834 mslotl = R_gl_loadimage("M_LSLEFT");
1835 mslotm = R_gl_loadimage("M_LSCNTR");
1836 mslotr = R_gl_loadimage("M_LSRGHT");
1837 // walls
1838 for (i = 1; i < ANIT; i++) {
1839 for (j = 0; j < 5 && anm[i - 1][j]; j++) {
1840 anip[i][j] = R_gl_loadimage(anm[i - 1][j]);
1842 for(; j < 5; j++) {
1843 anip[i][j] = (image) {
1844 .n = NULL,
1845 .w = 8,
1846 .h = 8,
1847 .res = -1,
1848 };
1853 static void R_reload_textures (void);
1855 void R_set_videomode (int w, int h, int fullscreen) {
1856 assert(w > 0);
1857 assert(h > 0);
1858 int was = Y_videomode_setted();
1859 if (root != NULL) {
1860 R_cache_free(root, 0);
1861 root = NULL;
1863 int res = Y_set_videomode_opengl(w, h, fullscreen);
1864 if (res == 0) {
1865 if (was == 0) {
1866 ERR_failinit("Unable to set video mode\n");
1869 Y_get_videomode(&screen_width, &screen_height);
1870 screen_full = Y_get_fullscreen();
1871 screen_scale = max(1, screen_width / 320);
1872 root = R_cache_new();
1873 assert(root);
1874 R_alloc();
1875 R_reload_textures();
1878 static int video_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) {
1879 static int cur;
1880 static int w, h, fullscreen;
1881 static char buf[16];
1882 static int buflen;
1883 static int vmode;
1884 const videomode_t *v;
1885 enum { VIDEOMODE, FULLSCREEN, APPLY, __NUM__ };
1886 static const simple_menu_t sm = {
1887 GM_BIG, "Video", NULL,
1889 { "Mode: ", NULL },
1890 { "Fullscreen: ", NULL },
1891 { "Apply ", NULL },
1893 };
1894 if (msg->type == GM_ENTER) {
1895 Y_get_videomode(&w, &h);
1896 fullscreen = Y_get_fullscreen();
1897 v = Y_get_videomode_list_opengl(fullscreen);
1898 vmode = 0;
1899 while (vmode < v->n && v->modes[vmode].w != w && v->modes[vmode].h != h) {
1900 vmode += 1;
1902 if (vmode < v->n) {
1903 w = v->modes[vmode].w;
1904 h = v->modes[vmode].h;
1906 snprintf(buf, 16, "%ix%i", w, h);
1907 buflen = strlen(buf);
1908 return 1;
1910 if (i == VIDEOMODE) {
1911 switch (msg->type) {
1912 case GM_GETSTR: return GM_init_str(msg, buf, buflen);
1913 case GM_SELECT:
1914 v = Y_get_videomode_list_opengl(fullscreen);
1915 vmode = vmode + 1 >= v->n ? 0 : vmode + 1;
1916 if (v->n > 0) {
1917 w = v->modes[vmode].w;
1918 h = v->modes[vmode].h;
1919 } else {
1920 Y_get_videomode(&w, &h);
1922 snprintf(buf, 16, "%ix%i", w, h);
1923 buflen = strlen(buf);
1924 return 1;
1926 } else if (i == FULLSCREEN) {
1927 switch (msg->type) {
1928 case GM_GETSTR: return GM_init_str(msg, fullscreen ? "Yes" : "No ", 3);
1929 case GM_SELECT: fullscreen = !fullscreen; return 1;
1931 } else if (i == APPLY) {
1932 switch (msg->type) {
1933 case GM_SELECT: R_set_videomode(w, h, fullscreen); return 1;
1936 return simple_menu_handler(msg, i, __NUM__, &sm, &cur);
1939 static const menu_t video_menu = {
1940 NULL, &video_menu_handler
1941 };
1943 const menu_t *R_menu (void) {
1944 return &video_menu;
1947 const cfg_t *R_args (void) {
1948 static const cfg_t args[] = {
1949 { "fullscr", &init_screen_full, Y_SW_ON },
1950 { "window", &init_screen_full, Y_SW_OFF },
1951 { "width", &init_screen_width, Y_DWORD },
1952 { "height", &init_screen_height, Y_DWORD },
1953 { NULL, NULL, 0 } // end
1954 };
1955 return args;
1958 const cfg_t *R_conf (void) {
1959 static const cfg_t conf[] = {
1960 { "sky", &w_horiz, Y_SW_ON },
1961 { "fullscreen", &screen_full, Y_SW_ON },
1962 { "screen_width", &screen_width, Y_DWORD },
1963 { "screen_height", &screen_height, Y_DWORD },
1964 { NULL, NULL, 0 } // end
1965 };
1966 return conf;
1969 void R_init (void) {
1970 logo("R_init: intialize opengl render\n");
1971 R_init_playpal();
1972 init_screen_width = init_screen_width > 0 ? init_screen_width : screen_width;
1973 init_screen_height = init_screen_height > 0 ? init_screen_height : screen_height;
1974 init_screen_full = init_screen_full != 0xFF ? init_screen_full : screen_full;
1975 R_set_videomode(init_screen_width, init_screen_height, init_screen_full);
1978 void R_done (void) {
1979 R_cache_free(root, 1);
1980 Y_unset_videomode();
1981 root = NULL;
1984 void R_get_name (int n, char s[8]) {
1985 assert(n >= 0 && n < 256);
1986 if (walp[n].res == -1) {
1987 memset(s, 0, 8);
1988 } else if (walp[n].res == -2) {
1989 memcpy(s, "_WATER_", 8);
1990 s[7] = '0' + (intptr_t)walp[n].n - 1;
1991 } else if (walani[n] > 0) {
1992 memcpy(s, anm[walani[n] - 1][0], 8);
1993 } else {
1994 F_getresname(s, walp[n].res & 0x7FFF);
1998 static short getani (char n[8]) {
1999 short i = 0;
2000 while (i < ANIT - 1 && strncasecmp(n, anm[i][0], 8) != 0) {
2001 i++;
2003 return i < ANIT - 1 ? i + 1 : 0;
2006 int R_get_special_id (int n) {
2007 assert(n >= 0 && n <= 256);
2008 return walp[n].res == -2 ? (intptr_t)walp[n].n : -1;
2011 static void R_reload_textures (void) {
2012 int i;
2013 char s[8];
2014 for (i = 0; i < max_textures; i++) {
2015 R_get_name(i, s);
2016 if (walp[i].res >= 0) {
2017 walp[i] = R_gl_getimage(walp[i].res);
2020 if (horiz.n) {
2021 horiz = R_gl_getimage(horiz.res);
2025 void R_begin_load (void) {
2026 int i;
2027 for (i = 0; i < 256; i++) {
2028 if (walp[i].n != NULL && walp[i].res >= 0 && walani[i] == 0) {
2029 R_gl_free_image(&walp[i]);
2031 memset(&walp[i], 0, sizeof(image));
2032 walp[i].res = -1;
2033 walswp[i] = i;
2034 walani[i] = 0;
2036 memset(anic, 0, sizeof(anic));
2037 max_wall_width = 0;
2038 max_wall_height = 0;
2039 max_textures = 1;
2042 void R_load (char s[8], int f) {
2043 assert(max_textures < 256);
2044 if (!s[0]) {
2045 walp[max_textures] = (image) {
2046 .n = NULL,
2047 .x = 0,
2048 .y = 0,
2049 .w = 0,
2050 .h = 0,
2051 .res = -1,
2052 };
2053 } else if (strncasecmp(s, "_WATER_", 7) == 0) {
2054 walp[max_textures] = (image) {
2055 .n = (void*)((intptr_t)s[7] - '0' + 1),
2056 .x = 0,
2057 .y = 0,
2058 .w = 8,
2059 .h = 8,
2060 .res = -2,
2061 };
2062 } else {
2063 walp[max_textures] = R_gl_loadimage(s);
2064 if (f) {
2065 walp[max_textures].res |= 0x8000;
2067 if (s[0] == 'S' && s[1] == 'W' && s[4] == '_') {
2068 walswp[max_textures] = 0;
2070 walani[max_textures] = getani(s);
2072 max_wall_width = max(max_wall_width, walp[max_textures].w);
2073 max_wall_height = max(max_wall_height, walp[max_textures].h);
2074 max_textures++;
2077 void R_end_load (void) {
2078 int i, j, k, g;
2079 char s[8];
2080 j = max_textures;
2081 for (i = 1; i < 256 && j < 256; i++) {
2082 if (walswp[i] == 0) {
2083 R_get_name(i, s);
2084 s[5] ^= 1;
2085 g = F_getresid(s) | (walp[i].res & 0x8000);
2086 k = 1;
2087 while (k < 256 && walp[k].res != g) {
2088 k += 1;
2090 if (k >= 256) {
2091 k = j;
2092 j += 1;
2093 max_textures += 1;
2094 walp[k] = R_gl_getimage(g);
2095 walf[k] = g & 0x8000 ? 1 : 0;
2097 walswp[i] = k;
2098 walswp[k] = i;
2103 void R_loadsky (int sky) {
2104 char s[6];
2105 strcpy(s, "RSKYx");
2106 s[4] = '0' + sky;
2107 R_gl_free_image(&horiz);
2108 horiz = R_gl_loadimage(s);