DEADSOFTWARE

menu: fix menus with disabled assertions
[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 walswp[256];
166 static byte walani[256];
167 static image anip[ANIT][5];
168 static byte anic[ANIT];
169 static image horiz;
171 /* Texture cache */
173 // https://blackpawn.com/texts/lightmaps/
174 static node *R_node_alloc (node *p, int w, int h) {
175 assert(p);
176 assert(w > 0);
177 assert(h > 0);
178 if (p->left) {
179 assert(p->right);
180 node *n = R_node_alloc(p->left, w, h);
181 return n ? n : R_node_alloc(p->right, w, h);
182 } else {
183 int pw = p->r - p->l + 1;
184 int ph = p->b - p->t + 1;
185 if (p->leaf || pw < w || ph < h) {
186 return NULL;
187 } else if (pw == w && ph == h) {
188 p->leaf = 1;
189 return p;
190 } else {
191 p->left = malloc(sizeof(node));
192 p->right = malloc(sizeof(node));
193 if (pw - w > ph - h) {
194 *p->left = (node) {
195 .up = p,
196 .l = p->l,
197 .t = p->t,
198 .r = p->l + w - 1,
199 .b = p->b
200 };
201 *p->right = (node) {
202 .up = p,
203 .l = p->l + w,
204 .t = p->t,
205 .r = p->r,
206 .b = p->b
207 };
208 } else {
209 *p->left = (node) {
210 .up = p,
211 .l = p->l,
212 .t = p->t,
213 .r = p->r,
214 .b = p->t + h - 1
215 };
216 *p->right = (node) {
217 .up = p,
218 .l = p->l,
219 .t = p->t + h,
220 .r = p->r,
221 .b = p->b
222 };
224 return R_node_alloc(p->left, w, h);
229 static int R_node_have_leaf (node *n) {
230 return n && (n->leaf || R_node_have_leaf(n->left) || R_node_have_leaf(n->right));
233 static void R_node_free_recursive (node *n) {
234 if (n) {
235 R_node_free_recursive(n->left);
236 R_node_free_recursive(n->right);
237 free(n);
241 static void R_node_free (node *n) {
242 if (n) {
243 //logo("free node %p {%i:%i:%i:%i}\n", n, n->l, n->t, n->r, n->b);
244 assert(n->leaf);
245 assert(n->left == NULL);
246 assert(n->right == NULL);
247 n->leaf = 0;
248 n->base = NULL;
249 node *p = n->up;
250 while (p != NULL) {
251 assert(p->leaf == 0);
252 assert(p->left);
253 assert(p->right);
254 if (R_node_have_leaf(p) == 0) {
255 R_node_free_recursive(p->left);
256 p->left = NULL;
257 R_node_free_recursive(p->right);
258 p->right = NULL;
259 p = p->up;
260 } else {
261 p = NULL;
267 static void R_cache_get_max_texture_size (int *w, int *h) {
268 GLint size = 0;
269 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
270 size = min(max(size, 0), 512); // more can be buggy on older hardware
271 *w = size;
272 *h = size;
275 static void R_gl_bind_texture (GLuint id) {
276 if (id != lastTexture) {
277 glBindTexture(GL_TEXTURE_2D, id);
281 static cache *R_cache_new (void) {
282 int w, h;
283 GLuint id;
284 cache *c = NULL;
285 R_cache_get_max_texture_size(&w, &h);
286 if (w && h) {
287 glGenTextures(1, &id);
288 if (id) {
289 R_gl_bind_texture(id);
290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
292 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
293 c = malloc(sizeof(cache));
294 if (c != NULL) {
295 *c = (cache) {
296 .id = id,
297 .root.r = w - 1,
298 .root.b = h - 1
299 };
300 } else {
301 glDeleteTextures(1, &id);
305 //logo("new cache %p\n", c);
306 return c;
309 static void R_cache_free (cache *root, int freetexture) {
310 cache *next;
311 cache *c = root;
312 while (c != NULL) {
313 next = c->next;
314 R_node_free_recursive(c->root.left);
315 R_node_free_recursive(c->root.right);
316 if (freetexture && c->id != 0) {
317 glDeleteTextures(1, &c->id);
319 free(c);
320 c = next;
324 static node *R_cache_alloc (cache *root, int w, int h) {
325 assert(root);
326 assert(w > 0 && h > 0);
327 node *n = NULL;
328 cache *p = NULL;
329 cache *c = root;
330 int maxw, maxh;
331 R_cache_get_max_texture_size(&maxw, &maxh);
332 if (w <= maxw && h <= maxh) {
333 while (c && !n) {
334 n = R_node_alloc(&c->root, w, h);
335 if (n) {
336 assert(n->leaf);
337 n->base = c;
339 p = c;
340 c = c->next;
342 if (!n) {
343 c = R_cache_new();
344 if (c) {
345 p->next = c;
346 n = R_node_alloc(&c->root, w, h);
347 if (n) {
348 assert(n->leaf);
349 n->base = c;
354 if (n) {
355 //logo("new node %p {%i:%i:%i:%i}\n", n, n->l, n->t, n->r, n->b);
356 } else {
357 logo("new node failed {%i:%i}\n", w, h);
359 return n;
362 static void R_cache_update (node *n, const void *data, int x, int y, int w, int h) {
363 assert(n);
364 assert(n->leaf);
365 assert(n->base);
366 assert(data);
367 assert(x >= 0);
368 assert(y >= 0);
369 assert(n->l + x + w - 1 <= n->r);
370 assert(n->t + y + h - 1 <= n->b);
371 R_gl_bind_texture(n->base->id);
372 glTexSubImage2D(GL_TEXTURE_2D, 0, n->l + x, n->t + y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data);
375 /* Generic helpers */
377 static void R_init_playpal (void) {
378 int i;
379 byte *vgapal = M_lock(F_getresid("PLAYPAL"));
380 for (i = 0; i < 256; i++) {
381 playpal[i] = (rgb) {
382 .r = vgapal[i * 3 + 0] * 255 / 63,
383 .g = vgapal[i * 3 + 1] * 255 / 63,
384 .b = vgapal[i * 3 + 2] * 255 / 63,
385 };
386 bright[i] = ((int)vgapal[i * 3 + 0] + vgapal[i * 3 + 1] + vgapal[i * 3 + 2]) * 8 / (63 * 3);
388 M_unlock(vgapal);
391 static vgaimg *R_getvga (int id) {
392 int loaded = M_was_locked(id);
393 vgaimg *v = M_lock(id);
394 if (v != NULL && !loaded) {
395 v->w = short2host(v->w);
396 v->h = short2host(v->h);
397 v->x = short2host(v->x);
398 v->y = short2host(v->y);
400 return v;
403 static rgba *R_extract_flame_spr (vgaimg *v) {
404 static const byte flametab[16] = {
405 0xBC, 0xBA, 0xB8, 0xB6, 0xB4, 0xB2, 0xB0, 0xD5,
406 0xD6, 0xD7, 0xA1, 0xA0, 0xE3, 0xE2, 0xE1, 0xE0
407 };
408 int i, j;
409 rgba *s = malloc(v->w * v->h * sizeof(rgba));
410 if (s != NULL) {
411 for (j = 0; j < v->h; j++) {
412 for (i = 0; i < v->w; i++) {
413 int k = j * v->w + i;
414 byte c = v->data[k] + bright[DEFAULT_SKY_COLOR];
415 s[k] = (rgba) {
416 .r = playpal[flametab[c]].r,
417 .g = playpal[flametab[c]].g,
418 .b = playpal[flametab[c]].b,
419 .a = v->data[k] == VGA_TRANSPARENT_COLOR ? 0x00 : 0xFF,
420 };
424 return s;
427 static rgba *R_extract_smoke_spr (vgaimg *v) {
428 int i, j;
429 rgba *s = malloc(v->w * v->h * sizeof(rgba));
430 if (s != NULL) {
431 for (j = 0; j < v->h; j++) {
432 for (i = 0; i < v->w; i++) {
433 int k = j * v->w + i;
434 byte c = ((v->data[k] + bright[DEFAULT_SKY_COLOR]) + 0x60) ^ 0x0F;
435 byte a = 0xFF - ((int)playpal[c].r + playpal[c].g + playpal[c].b) / 3;
436 s[k] = (rgba) {
437 .r = playpal[c].r,
438 .g = playpal[c].g,
439 .b = playpal[c].b,
440 .a = v->data[k] == VGA_TRANSPARENT_COLOR ? 0x00 : a,
441 };
445 return s;
448 static rgba *R_extract_mask_spr (vgaimg *v) {
449 int i, j;
450 rgba *s = malloc(v->w * v->h * sizeof(rgba));
451 if (s != NULL) {
452 for (j = 0; j < v->h; j++) {
453 for (i = 0; i < v->w; i++) {
454 int k = j * v->w + i;
455 byte c = v->data[k];
456 if (c >= 0x70 && c <= 0x7F) {
457 byte mask = c - 0x70;
458 mask = 0xFF - ((mask << 4) | mask);
459 s[k] = (rgba) {
460 .r = mask,
461 .g = mask,
462 .b = mask,
463 .a = 0xFF,
464 };
465 } else {
466 s[k] = (rgba) {
467 .r = 0,
468 .g = 0,
469 .b = 0,
470 .a = 0,
471 };
476 return s;
479 static rgba *R_extract_rgba_spr (vgaimg *v) {
480 int i, j;
481 rgba *s = malloc(v->w * v->h * sizeof(rgba));
482 if (s != NULL) {
483 for (j = 0; j < v->h; j++) {
484 for (i = 0; i < v->w; i++) {
485 int k = j * v->w + i;
486 byte c = v->data[k];
487 s[k] = (rgba) {
488 .r = playpal[c].r,
489 .g = playpal[c].g,
490 .b = playpal[c].b,
491 .a = c == VGA_TRANSPARENT_COLOR ? 0x00 : 0xFF,
492 };
496 return s;
499 /* OpenGL helpers */
501 static image R_gl_create_image (const rgba *buf, int w, int h) {
502 node *n = R_cache_alloc(root, w, h);
503 if (n) {
504 R_cache_update(n, buf, 0, 0, w, h);
506 return (image) {
507 .n = n,
508 .w = w,
509 .h = h,
510 .res = -1
511 };
514 static image R_gl_get_special_image (int id, rgba *(*fn)(vgaimg*)) {
515 image img;
516 //char name[8];
517 //F_getresname(name, id);
518 //logo("load image: %.8s\n", name);
519 vgaimg *v = R_getvga(id);
520 if (v != NULL) {
521 rgba *buf = (*fn)(v);
522 img = R_gl_create_image(buf, v->w, v->h);
523 img.x = v->x;
524 img.y = v->y;
525 img.res = id;
526 M_unlock(v);
527 free(buf);
528 } else {
529 img = (image) {
530 .res = id
531 };
533 return img;
536 static image R_gl_getimage (int id) {
537 return R_gl_get_special_image(id, &R_extract_rgba_spr);
540 static image R_gl_loadimage (const char name[8]) {
541 return R_gl_getimage(F_getresid(name));
544 static image R_gl_get_special_spr (const char n[4], int s, int d, rgba *(*fn)(vgaimg*)) {
545 return R_gl_get_special_image(F_getsprid(n, s, d, NULL), fn);
548 static void R_gl_free_image (image *img) {
549 if (img->n != NULL && img->res >= 0) {
550 R_node_free(img->n);
552 img->n = NULL;
553 img->res = -1;
556 static void R_gl_quad_vetexes (int x, int y, int w, int h) {
557 glVertex2i(x + w, y);
558 glVertex2i(x, y);
559 glVertex2i(x, y + h);
560 glVertex2i(x + w, y + h);
563 static void R_gl_draw_quad (int x, int y, int w, int h) {
564 glBegin(GL_QUADS);
565 R_gl_quad_vetexes(x, y, w, h);
566 glEnd();
569 static void R_gl_draw_textured (image *img, int x, int y, int w, int h, int flip) {
570 if (img->n) {
571 GLfloat nw = img->n->base->root.r + 1;
572 GLfloat nh = img->n->base->root.b + 1;
573 GLfloat ax = (flip ? img->n->l : img->n->r + 1) / nw;
574 GLfloat bx = (flip ? img->n->r + 1 : img->n->l) / nh;
575 GLfloat ay = (img->n->t) / nw;
576 GLfloat by = (img->n->b + 1) / nh;
577 R_gl_bind_texture(img->n->base->id);
578 glEnable(GL_TEXTURE_2D);
579 glBegin(GL_QUADS);
580 glTexCoord2f(ax, ay); glVertex2i(x + w, y);
581 glTexCoord2f(bx, ay); glVertex2i(x, y);
582 glTexCoord2f(bx, by); glVertex2i(x, y + h);
583 glTexCoord2f(ax, by); glVertex2i(x + w, y + h);
584 glEnd();
585 } else {
586 glColor3ub(255, 0, 0);
587 glDisable(GL_BLEND);
588 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
589 glDisable(GL_TEXTURE_2D);
590 R_gl_draw_quad(x, y, w, h);
594 /* fit image into rectangle without applying offset and transparency */
595 static void R_gl_draw_image_ext (image *img, int x, int y, int w, int h) {
596 glDisable(GL_BLEND);
597 glColor3ub(255, 255, 255);
598 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
599 R_gl_draw_textured(img, x, y, w, h, 0);
602 /* draw sprite with offset and coloring */
603 static void R_gl_draw_image_color (image *img, int x, int y, int flip) {
604 int xx = flip ? x - img->w + img->x : x - img->x;
605 glEnable(GL_BLEND);
606 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
607 R_gl_draw_textured(img, xx, y - img->y, img->w, img->h, flip);
610 /* draw sprite with offset */
611 static void R_gl_draw_image (image *img, int x, int y, int flip) {
612 glColor3ub(255, 255, 255);
613 R_gl_draw_image_color(img, x, y, flip);
616 static void R_gl_set_color (byte c) {
617 glColor3ub(playpal[c].r, playpal[c].g, playpal[c].b);
620 static void R_gl_setclip (int x, int y, int w, int h) {
621 glScissor(x * screen_scale, (SCRH - h - y) * screen_scale, w * screen_scale, h * screen_scale);
624 static void R_gl_setmatrix (void) {
625 SCRW = screen_width / screen_scale;
626 SCRH = screen_height / screen_scale;
627 glScissor(0, 0, screen_width, screen_height);
628 glViewport(0, 0, screen_width, screen_height);
629 glMatrixMode(GL_PROJECTION);
630 glLoadIdentity();
631 glOrtho(0, SCRW, SCRH, 0, 0, 1);
632 glMatrixMode(GL_MODELVIEW);
633 glLoadIdentity();
636 /* --- Misc --- */
638 static image Z_getspr (const char n[4], int s, int d, char *dir) {
639 int h = F_getsprid(n, s, d, dir);
640 return R_gl_getimage(h);
643 static image *Z_get_char_image (image *img, int ch) {
644 image *p = NULL;
645 ch = cp866_toupper(ch);
646 if (ch > 32 && ch < 160) {
647 p = &img[ch - '!'];
649 return p;
652 static int Z_get_char_width_generic (image *img, int off, int ch) {
653 image *p = Z_get_char_image(img, ch);
654 return p == NULL ? off : p->w - 1;
657 static int Z_putch_generic (image *img, int off, int ch) {
658 image *p = Z_get_char_image(img, ch);
659 int w = p == NULL ? off : p->w - 1;
660 if (p != NULL && p->n != NULL) {
661 R_gl_draw_image(p, prx, pry, 0);
663 prx += w;
664 return w;
667 static int Z_get_string_width_generic (image *img, int off, const char *fmt, va_list ap) {
668 int i, w, ww;
669 char buf[80];
670 vsprintf(buf, fmt, ap);
671 for (i = w = ww = 0; buf[i]; ++i) {
672 switch (buf[i]) {
673 case '\n':
674 case '\r':
675 ww = max(w, ww);
676 w = 0;
677 break;
678 default:
679 w += Z_get_char_width_generic(img, off, (byte)buf[i]);
682 return max(w, ww);
685 static int Z_printf_generic (image *img, int off, const char *fmt, va_list ap) {
686 int i, w, ww;
687 char buf[80];
688 vsprintf(buf, fmt, ap);
689 for (i = w = ww = 0; buf[i]; ++i) {
690 switch (buf[i]) {
691 case '\n':
692 pry += off + 1;
693 case '\r':
694 w = max(w, ww);
695 prx = 0;
696 w = 0;
697 break;
698 default:
699 w += Z_putch_generic(img, off, (byte)buf[i]);
702 return w;
705 static void Z_gotoxy (int x, int y) {
706 prx = x;
707 pry = y;
710 static int Z_get_big_string_width (const char *fmt, ...) {
711 va_list a;
712 va_start(a, fmt);
713 int w = Z_get_string_width_generic(bfh, 12, fmt, a);
714 va_end(a);
715 return w;
718 static int Z_printbf (const char *fmt, ...) {
719 va_list a;
720 va_start(a, fmt);
721 int w = Z_printf_generic(bfh, 12, fmt, a);
722 va_end(a);
723 return w;
726 static int Z_get_small_string_width (const char *fmt, ...) {
727 va_list a;
728 va_start(a, fmt);
729 int w = Z_get_string_width_generic(sfh, 7, fmt, a);
730 va_end(a);
731 return w;
734 static int Z_printsf (const char *fmt, ...) {
735 va_list a;
736 va_start(a, fmt);
737 int w =Z_printf_generic(sfh, 7, fmt, a);
738 va_end(a);
739 return w;
742 static void Z_printhf (const char *fmt, ...) {
743 int i, c;
744 char buf[80];
745 va_list a;
746 va_start(a, fmt);
747 vsprintf(buf, fmt, a);
748 va_end(a);
749 for (i = 0; buf[i]; ++i) {
750 switch (buf[i]) {
751 case '0':
752 case '1':
753 case '2':
754 case '3':
755 case '4':
756 case '5':
757 case '6':
758 case '7':
759 case '8':
760 case '9':
761 c = buf[i] - '0';
762 break;
763 case '-':
764 c = 10;
765 break;
766 case '%':
767 c = 11;
768 break;
769 case '\n':
770 pry += 19;
771 case '\r':
772 c = -1;
773 prx = 0;
774 break;
775 default:
776 c = -1;
777 break;
779 if (c >= 0) {
780 R_gl_draw_image(&sth[c], prx, pry, 0);
782 prx += 14;
786 /* --- Menu --- */
788 static image *PL_getspr (int s, int d, int msk) {
789 int i = (s - 'A') * 2 + d;
790 return msk ? &plr_msk[i] : &plr_spr[i];
793 #define SCROLLER_MIDDLE 10
794 #define TEXTFIELD_MIDDLE 2
796 static void get_entry_size (const menu_t *m, int i, int *w, int *h) {
797 assert(m != NULL);
798 assert(i >= 0);
799 assert(w != NULL);
800 assert(h != NULL);
801 int x = 0;
802 int y = 0;
803 int type = 0;
804 menu_msg_t msg;
805 msg.type = GM_GETENTRY;
806 if (GM_send(m, i, &msg)) {
807 type = msg.integer.i;
808 switch (type) {
809 case GM_BUTTON:
810 case GM_SCROLLER:
811 case GM_TEXTFIELD:
812 case GM_TEXTFIELD_BUTTON:
813 msg.type = GM_GETCAPTION;
814 if (GM_send(m, i, &msg)) {
815 x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
817 break;
818 case GM_SMALL_BUTTON:
819 msg.type = GM_GETCAPTION;
820 if (GM_send(m, i, &msg)) {
821 x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s);
823 break;
824 default:
825 assert(0);
827 switch (type) {
828 case GM_BUTTON:
829 msg.type = GM_GETSTR;
830 if (GM_send(m, i, &msg)) {
831 x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
833 y = 16;
834 break;
835 case GM_SMALL_BUTTON:
836 msg.type = GM_GETSTR;
837 if (GM_send(m, i, &msg)) {
838 x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
840 y = 12;
841 break;
842 case GM_SCROLLER:
843 x += (SCROLLER_MIDDLE + 2) * 8;
844 y = 16;
845 break;
846 case GM_TEXTFIELD:
847 case GM_TEXTFIELD_BUTTON:
848 msg.type = GM_GETSTR;
849 if (GM_send(m, i, &msg)) {
850 x += (msg.string.maxlen + 2) * 8;
851 } else {
852 x += (TEXTFIELD_MIDDLE + 2) * 8;
854 y = 16;
855 break;
856 default:
857 assert(0);
860 *w = x;
861 *h = y;
864 static void get_menu_size (const menu_t *m, int *w, int *h) {
865 assert(m != NULL);
866 assert(w != NULL);
867 assert(h != NULL);
868 int i, n, x, y, xx, yy, type;
869 menu_msg_t msg;
870 msg.type = GM_QUERY;
871 if (GM_send_this(m, &msg)) {
872 n = msg.integer.b;
873 type = msg.integer.s;
874 x = 0;
875 y = 0;
876 msg.type = GM_GETTITLE;
877 if (GM_send_this(m, &msg)) {
878 switch (type) {
879 case GM_BIG: x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s); break;
880 case GM_SMALL: x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s); break;
881 default: assert(0);
884 for (i = 0; i < n; i++) {
885 get_entry_size(m, i, &xx, &yy);
886 x = max(x, xx);
887 y += yy;
889 *w = x;
890 *h = y;
891 } else {
892 *w = 0;
893 *h = 0;
897 static int GM_draw (void) {
898 int i, j, n, x, y, xoff, yoff, cur, w, type, recv;
899 const menu_t *m = GM_get();
900 menu_msg_t msg;
901 if (m != NULL) {
902 get_menu_size(m, &x, &y);
903 x = SCRW / 2 - x / 2;
904 y = SCRH / 2 - y / 2;
905 // --- title ---
906 msg.type = GM_QUERY;
907 if (GM_send_this(m, &msg)) {
908 cur = msg.integer.i;
909 n = msg.integer.a;
910 type = msg.integer.s;
911 msg.type = GM_GETTITLE;
912 if (GM_send_this(m, &msg)) {
913 Z_gotoxy(x, y - 10);
914 switch (type) {
915 case GM_SMALL: yoff = 8; Z_printsf("%.*s", msg.string.maxlen, msg.string.s); break;
916 case GM_BIG: yoff = 20; Z_printbf("%.*s", msg.string.maxlen, msg.string.s); break;
917 default: assert(0);
919 } else {
920 yoff = 0;
922 for (i = 0; i < n; i++) {
923 msg.type = GM_GETENTRY;
924 if (GM_send(m, i, &msg)) {
925 type = msg.integer.i;
926 if (i == cur) {
927 if (type == GM_SMALL_BUTTON) {
928 Z_gotoxy(x - 8, y + yoff);
929 Z_printsf(">");
930 } else {
931 R_gl_draw_image(&msklh[(gm_tm / 6) & 1], x - 25, y + yoff - 8, 0);
934 msg.type = GM_GETCAPTION;
935 if (GM_send(m, i, &msg)) {
936 Z_gotoxy(x, y + yoff);
937 if (type == GM_SMALL_BUTTON) {
938 xoff = Z_printsf("%.*s", msg.string.maxlen, msg.string.s);
939 } else {
940 xoff = Z_printbf("%.*s", msg.string.maxlen, msg.string.s);
942 } else {
943 xoff = 0;
945 switch (type) {
946 case GM_BUTTON:
947 case GM_SMALL_BUTTON:
948 msg.type = GM_GETSTR;
949 if (GM_send(m, i, &msg)) {
950 Z_gotoxy(x + xoff, y + yoff);
951 if (type == GM_SMALL_BUTTON) {
952 Z_printsf("%.*s", msg.string.maxlen, msg.string.s);
953 } else {
954 Z_printbf("%.*s", msg.string.maxlen, msg.string.s);
957 yoff += type == GM_BUTTON ? 16 : 12;
958 break;
959 case GM_TEXTFIELD:
960 case GM_TEXTFIELD_BUTTON:
961 yoff += 9;
962 msg.type = GM_GETSTR;
963 recv = GM_send(m, i, &msg);
964 w = recv ? msg.string.maxlen : TEXTFIELD_MIDDLE;
965 R_gl_draw_image(&mslotl, x + xoff, y + yoff, 0);
966 for (j = 1; j <= w; j++) {
967 R_gl_draw_image(&mslotm, x + xoff + j * 8, y + yoff, 0);
969 R_gl_draw_image(&mslotr, x + xoff + j * 8, y + yoff, 0);
970 Z_gotoxy(x + xoff + 4, y + yoff - 7);
971 if (input && i == cur) {
972 Z_printsf("%.*s_", imax, ibuf);
973 } else if (recv) {
974 Z_printsf("%.*s", msg.string.maxlen, msg.string.s);
976 yoff += 7;
977 break;
978 case GM_SCROLLER:
979 R_gl_draw_image(&mbarl, x + xoff, y + yoff, 0);
980 for (j = 1; j < SCROLLER_MIDDLE; j++) {
981 R_gl_draw_image(&mbarm, x + xoff + j * 8, y + yoff, 0);
983 R_gl_draw_image(&mbarr, x + xoff + j * 8, y + yoff, 0);
984 msg.type = GM_GETINT;
985 if (GM_send(m, i, &msg)) {
986 int lev = (msg.integer.i - msg.integer.a) * ((SCROLLER_MIDDLE - 2) * 8) / msg.integer.b;
987 R_gl_draw_image(&mbaro, x + xoff + lev + 8, y + yoff, 0);
989 yoff += 16;
990 break;
991 default:
992 assert(0);
998 return m != NULL;
1001 /* --- View --- */
1003 static void R_draw_fld (byte *fld, int minx, int miny, int maxx, int maxy, int fg) {
1004 int i, j;
1005 assert(minx >= 0 && minx <= FLDW);
1006 assert(miny >= 0 && miny <= FLDH);
1007 assert(maxx >= 0 && maxx <= FLDW);
1008 assert(maxy >= 0 && maxy <= FLDH);
1009 for (j = miny; j < maxy; j++) {
1010 for (i = minx; i < maxx; i++) {
1011 byte id = fld[j * FLDW + i];
1012 if (id != 0) {
1013 if (walp[id].res < 0) {
1014 if (fg) {
1015 switch (R_get_special_id(id)) {
1016 case 1:
1017 glColor4ub(0, 0, 255, 127);
1018 break;
1019 case 2:
1020 glColor4ub(0, 127, 0, 127);
1021 break;
1022 case 3:
1023 glColor4ub(127, 0, 0, 127);
1024 break;
1025 default:
1026 glColor4ub(0, 0, 0, 127);
1027 break;
1029 glEnable(GL_BLEND);
1030 glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1031 glDisable(GL_TEXTURE_2D);
1032 R_gl_draw_quad(i * CELW, j * CELW, CELW, CELH);
1034 } else {
1035 R_gl_draw_image(&walp[id], i * CELW, j * CELH, 0);
1042 static void R_draw_dots (void) {
1043 int i;
1044 glDisable(GL_BLEND);
1045 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1046 glDisable(GL_TEXTURE_2D);
1047 glBegin(GL_QUADS);
1048 for (i = 0; i < MAXDOT; i++) {
1049 if (dot[i].t != 0) {
1050 R_gl_set_color(dot[i].c);
1051 R_gl_quad_vetexes(dot[i].o.x, dot[i].o.y, 1, 1);
1054 glEnd();
1057 static void R_draw_items (void) {
1058 int i, s;
1059 for (i = 0; i < MAXITEM; ++i) {
1060 s = -1;
1061 if (it[i].t && it[i].s >= 0) {
1062 switch (it[i].t & 0x7FFF) {
1063 case I_ARM1:
1064 s = it[i].s / 9 + 18;
1065 break;
1066 case I_ARM2:
1067 s = it[i].s / 9 + 20;
1068 break;
1069 case I_MEGA:
1070 s = it[i].s / 2 + 22;
1071 break;
1072 case I_INVL:
1073 s = it[i].s / 2 + 26;
1074 break;
1075 case I_SUPER:
1076 case I_RTORCH:
1077 case I_GTORCH:
1078 case I_BTORCH:
1079 s = it[i].s / 2 + (it[i].t - I_SUPER) * 4 + 35;
1080 break;
1081 case I_GOR1: case I_FCAN:
1082 s = it[i].s / 2 + (it[i].t - I_GOR1) * 3 + 51;
1083 break;
1084 case I_AQUA:
1085 s = 30;
1086 break;
1087 case I_SUIT:
1088 s = 34;
1089 break;
1090 case I_KEYR:
1091 case I_KEYG:
1092 case I_KEYB:
1093 s = (it[i].t & 0x7FFF) - I_KEYR + 31;
1094 break;
1095 case I_GUN2:
1096 s = 57;
1097 break;
1098 default:
1099 s = (it[i].t & 0x7FFF) - 1;
1102 if (s >= 0) {
1103 R_gl_draw_image(&item_spr[s], it[i].o.x, it[i].o.y, item_sprd[s]);
1108 static int standspr (player_t *p) {
1109 if (p->f & PLF_UP) {
1110 return 'X';
1111 } else if (p->f & PLF_DOWN) {
1112 return 'Z';
1113 } else {
1114 return 'E';
1118 static int wpnspr (player_t *p) {
1119 if (p->f & PLF_UP) {
1120 return 'C';
1121 } else if(p->f & PLF_DOWN) {
1122 return 'E';
1123 } else {
1124 return 'A';
1128 static void R_draw_player (player_t *p) {
1129 enum {STAND, GO, DIE, SLOP, DEAD, MESS, OUT, FALL}; // copypasted from player.c!
1130 static const int wytab[] = {-1, -2, -1, 0};
1131 int s = 'A';
1132 int w = 0;
1133 int wx = 0;
1134 int wy = 0;
1135 switch (p->st) {
1136 case STAND:
1137 if (p->f & PLF_FIRE) {
1138 s = standspr(p) + 1;
1139 w = wpnspr(p) + 1;
1140 } else if (p->pain) {
1141 s = 'G';
1142 w = 'A';
1143 wx = p->d ? 2 : -2;
1144 wy = 1;
1145 } else {
1146 s = standspr(p);
1147 w = wpnspr(p);
1149 break;
1150 case DEAD:
1151 s = 'N';
1152 break;
1153 case MESS:
1154 s = 'W';
1155 break;
1156 case GO:
1157 if (p->pain) {
1158 s = 'G';
1159 w = 'A';
1160 wx = p->d ? 2 : -2;
1161 wy = 1;
1162 } else {
1163 s = plr_goanim[p->s / 8];
1164 w = (p->f & PLF_FIRE) ? 'B' : 'A';
1165 wx = p->d ? 2 : -2;
1166 wy = 1 + wytab[s - 'A'];
1168 break;
1169 case DIE:
1170 s = plr_dieanim[p->s];
1171 break;
1172 case SLOP:
1173 s = plr_slopanim[p->s];
1174 break;
1175 case OUT:
1176 s = 0;
1177 break;
1179 if (p->wpn == 0) {
1180 w = 0;
1182 if (w) {
1183 R_gl_draw_image(&plr_wpn[(int)p->wpn][w -'A'], p->o.x + wx, p->o.y + wy, p->d);
1185 if (s) {
1186 R_gl_draw_image(&plr_spr[(s - 'A') * 2 + p->d], p->o.x, p->o.y, plr_sprd[(s - 'A') * 2 + p->d]);
1187 R_gl_set_color(p->color + PLAYER_COLOR_OFFSET);
1188 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]);
1192 static void R_draw_monsters (void) {
1193 enum {SLEEP, GO, RUN, CLIMB, DIE, DEAD, ATTACK, SHOOT, PAIN, WAIT, REVIVE, RUNOUT}; // copypasted from monster.c!
1194 int i;
1195 for (i = 0; i < MAXMN; i++) {
1196 if (mn[i].t != MN_NONE) {
1197 int x = mn[i].o.x;
1198 int y = mn[i].o.y;
1199 if (mn[i].t < MN__LAST) {
1200 if ((mn[i].t != MN_SOUL && mn[i].t != MN_PAIN) || mn[i].st != DEAD) {
1201 int ap = mn[i].ap[mn[i].ac];
1202 int d = (ap - 'A') * 2 + mn[i].d;
1203 int dir = mn_sprd[mn[i].t - 1][d];
1204 if (mn[i].t == MN_MAN && (ap == 'E' || ap == 'F')) {
1205 R_gl_draw_image(&mn_sgun[ap - 'E'], x, y, mn[i].d);
1207 R_gl_draw_image(&mn_spr[mn[i].t - 1][d], x, y, dir);
1208 if (mn[i].t == MN_MAN) {
1209 R_gl_set_color(MANCOLOR + PLAYER_COLOR_OFFSET);
1210 R_gl_draw_image_color(&mn_man_msk[d], x, y, dir);
1213 if (mn[i].t == MN_VILE && mn[i].st == SHOOT) {
1214 R_gl_draw_image(&mn_fspr[mn[i].ac / 3], mn[i].tx, mn[i].ty, 0);
1216 } else if (mn[i].t == MN_PL_DEAD || mn[i].t == MN_PL_MESS) {
1217 int type = mn[i].t - MN_PL_DEAD;
1218 R_gl_draw_image(&pl_spr[type], x, y, 0);
1219 R_gl_set_color(mn[i].d);
1220 R_gl_draw_image_color(&pl_msk[type], x, y, 0);
1226 static void R_draw_weapons (void) {
1227 enum {NONE, ROCKET, PLASMA, APLASMA, BALL1, BALL2, BALL7, BFGBALL, BFGHIT, MANF, REVF, FIRE}; // copypasted from weapons.c!
1228 int i, s, d, x, y;
1229 for (i = 0; i < MAXWPN; ++i) {
1230 s = -1;
1231 d = 0;
1232 switch (wp[i].t) {
1233 case REVF:
1234 case ROCKET:
1235 d = wp[i].s;
1236 if (d < 2) {
1237 d = wp[i].o.xv > 0 ? 1 : 0;
1238 x = abs(wp[i].o.xv);
1239 y = wp[i].o.yv;
1240 s = 0;
1241 if (y < 0) {
1242 if (-y >= x) {
1243 s = 30;
1245 } else if (y > 0) {
1246 if (y >= x / 2) {
1247 s = 31;
1250 } else {
1251 s = (d - 2) / 2 + 1;
1252 d = 0;
1254 break;
1255 case MANF:
1256 s=wp[i].s;
1257 if (s >= 2) {
1258 s /= 2;
1259 break;
1261 case PLASMA:
1262 case APLASMA:
1263 case BALL1:
1264 case BALL7:
1265 case BALL2:
1266 s = wp[i].s;
1267 if (s >= 2) {
1268 s = s / 2 + 1;
1270 switch (wp[i].t) {
1271 case PLASMA:
1272 s += 4;
1273 break;
1274 case APLASMA:
1275 s += 11;
1276 break;
1277 case BALL1:
1278 s += 32;
1279 break;
1280 case BALL2:
1281 s += 42;
1282 break;
1283 case BALL7:
1284 s += 37;
1285 d = wp[i].o.xv >= 0 ? 1 : 0;
1286 break;
1287 case MANF:
1288 s += 47;
1289 d= wp[i].o.xv>=0 ? 1 : 0;
1290 break;
1292 break;
1293 case BFGBALL:
1294 s = wp[i].s;
1295 if (s >= 2) {
1296 s = s / 2 + 1;
1298 s += 18;
1299 break;
1300 case BFGHIT:
1301 s = wp[i].s / 2 + 26;
1302 break;
1304 if (s >= 0) {
1305 R_gl_draw_image(&wp_spr[s * 2 + d], wp[i].o.x, wp[i].o.y, wp_sprd[s * 2 + d]);
1310 static void R_draw_smoke (void) {
1311 int i, s;
1312 for (i = 0; i < MAXSMOK; ++i) {
1313 if (sm[i].t) {
1314 switch (sm[i].s) {
1315 case 0:
1316 s = sm[i].t;
1317 if (s >= (SMSN - 1) * 3) {
1318 s = 0;
1319 } else {
1320 s = SMSN - 1 - s / 3;
1322 R_gl_draw_image(&smk_spr[s], sm[i].x >> 8, (sm[i].y >> 8) + 1, 0);
1323 break;
1324 case 1:
1325 s = sm[i].t;
1326 if (s >= FLSN - 1) {
1327 s = 0;
1328 } else {
1329 s = FLSN - 1 - s;
1331 R_gl_draw_image(&smk_fspr[s], sm[i].x >> 8, (sm[i].y >> 8) + 1, 0);
1332 break;
1338 static void R_draw_effects (void) {
1339 enum {NONE, TFOG, IFOG, BUBL}; // copypasted from fx.c
1340 int i, s;
1341 glPointSize(screen_scale);
1342 for (i = 0; i < MAXFX; ++i) {
1343 switch (fx[i].t) {
1344 case TFOG:
1345 s = fx[i].s / 2;
1346 R_gl_draw_image(&fx_spr[s], fx[i].x, fx[i].y, fx_sprd[s]);
1347 break;
1348 case IFOG:
1349 s = fx[i].s / 2 + 10;
1350 R_gl_draw_image(&fx_spr[s], fx[i].x, fx[i].y, fx_sprd[s]);
1351 break;
1352 case BUBL:
1353 glDisable(GL_BLEND);
1354 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1355 glDisable(GL_TEXTURE_2D);
1356 R_gl_set_color(0xC0 + fx[i].s);
1357 R_gl_draw_quad(fx[i].x >> 8, fx[i].y >> 8, 1, 1);
1358 break;
1363 static int get_pu_st (int t) {
1364 if (t >= PL_FLASH) {
1365 return 1;
1366 } else if((t / 9) & 1) {
1367 return 0;
1368 } else {
1369 return 1;
1373 static void R_draw_view (int x, int y, int w, int h, int camx, int camy) {
1374 glPushMatrix();
1375 R_gl_setclip(x, y, w, h);
1376 glTranslatef(x, y, 0);
1377 if (w_horiz && horiz.n != NULL) {
1378 R_gl_draw_image_ext(&horiz, 0, 0, w, h);
1379 if (sky_type == 2 && lt_time < 0) {
1380 image *tanderbolt = &ltn[lt_type][lt_time < -5 ? 0 : 1];
1381 if (!lt_side) {
1382 R_gl_draw_image(tanderbolt, 0, lt_ypos, 0);
1383 } else {
1384 R_gl_draw_image(tanderbolt, w - 1, lt_ypos, 1);
1387 } else {
1388 glDisable(GL_BLEND);
1389 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1390 glDisable(GL_TEXTURE_2D);
1391 R_gl_set_color(DEFAULT_SKY_COLOR);
1392 R_gl_draw_quad(0, 0, w, h);
1394 int maxx = min((camx + w) / CELW + 1, FLDW);
1395 int maxy = min((camy + h) / CELH + 1, FLDH);
1396 int minx = max((camx - max_wall_width) / CELW, 0);
1397 int miny = max((camy - max_wall_height) / CELH, 0);
1398 glTranslatef(-camx, -camy, 0);
1399 R_draw_fld((byte*)fldb, minx, miny, maxx, maxy, 0);
1400 R_draw_dots();
1401 R_draw_items();
1402 R_draw_player(&pl1);
1403 if (_2pl) {
1404 R_draw_player(&pl2);
1406 R_draw_monsters();
1407 R_draw_weapons();
1408 R_draw_smoke();
1409 R_draw_effects();
1410 R_draw_fld((byte*)fldf, minx, miny, maxx, maxy, 1);
1411 glTranslatef(camx, camy, 0);
1412 if (sky_type == 2 && (lt_time == -4 || lt_time == -2)) {
1413 glColor4ub(255, 255, 255, 255);
1414 glEnable(GL_BLEND);
1415 glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1416 glDisable(GL_TEXTURE_2D);
1417 R_gl_draw_quad(0, 0, w, h);
1419 glPopMatrix();
1422 static void R_draw_player_view (player_t *p, int x, int y, int w, int h) {
1423 p->looky = min(max(p->looky, -SCRH / 4), SCRH / 4); // TODO remove writeback
1424 int st = stone.w;
1425 int cw = w - st;
1426 int cx = min(max(p->o.x, cw / 2), FLDW * CELW - cw / 2);
1427 int cy = min(max(p->o.y - 12 + p->looky, h / 2), FLDH * CELH - h / 2);
1428 int camx = max(cx - cw / 2, 0);
1429 int camy = max(cy - h / 2, 0);
1430 glPushMatrix();
1431 R_draw_view(x, y + 1, cw, h - 2, camx, camy);
1432 glTranslatef(x, y, 0);
1433 if (p->invl) {
1434 if (get_pu_st(p->invl)) {
1435 glEnable(GL_BLEND);
1436 glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
1437 glDisable(GL_TEXTURE_2D);
1438 glColor4ub(191, 191, 191, 255);
1439 R_gl_draw_quad(0, 0, cw, h);
1441 } else {
1442 if (p->suit && get_pu_st(p->suit)) {
1443 glEnable(GL_BLEND);
1444 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1445 glDisable(GL_TEXTURE_2D);
1446 glColor4ub(0, 255, 0, 192);
1447 R_gl_draw_quad(0, 0, cw, h);
1449 int f = min(max(p->pain * 3, 0), 255);
1450 if (f > 0) {
1451 glEnable(GL_BLEND);
1452 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1453 glDisable(GL_TEXTURE_2D);
1454 glColor4ub(255, 0, 0, f);
1455 R_gl_draw_quad(0, 0, cw, h);
1458 R_gl_setclip(x, y, w, h);
1459 glTranslatef(-x + cw, 0, 0);
1460 R_gl_draw_image(&stone, 0, 0, 0);
1461 int i = stone.h;
1462 while (i < h) {
1463 R_gl_draw_image(&stone2, 0, i, 0);
1464 i += stone2.h;
1466 if (p->drawst & PL_DRAWAIR) {
1467 if (p->air < PL_AIR) {
1468 int a = min(max(p->air, 0), MAXAIR) * 100 / MAXAIR;
1469 glDisable(GL_BLEND);
1470 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1471 glDisable(GL_TEXTURE_2D);
1472 R_gl_set_color(0xC8);
1473 R_gl_draw_quad(10, 49, a, 2);
1476 if (p->drawst & PL_DRAWLIFE) {
1477 Z_gotoxy(10, 7);
1478 Z_printhf("%3d%%", p->life);
1480 if (p->drawst & PL_DRAWARMOR) {
1481 Z_gotoxy(10, 7 + 19);
1482 Z_printhf("%3d%%", p->armor);
1484 if (p->drawst & PL_DRAWWPN) {
1485 switch(p->wpn) {
1486 case 2:
1487 case 5:
1488 i = p->ammo;
1489 break;
1490 case 3:
1491 case 4:
1492 case 9:
1493 i = p->shel;
1494 break;
1495 case 6:
1496 i = p->rock;
1497 break;
1498 case 7:
1499 case 8:
1500 i = p->cell;
1501 break;
1502 case 10:
1503 i = p->fuel;
1504 break;
1505 default:
1506 i = -1;
1507 break;
1509 // weapon
1510 if (p->wpn >= 0) {
1511 R_gl_draw_image(&sth[12 + p->wpn], st - 88, 58 + 19, 0);
1513 // ammo
1514 if (p->wpn >= 2) {
1515 Z_gotoxy(st - 10 - 5 * 14, 58 + 2);
1516 Z_printhf("%5d", i);
1519 if (p->drawst & PL_DRAWFRAG && g_dm) {
1520 Z_gotoxy(st - 5 - 5 * 14, 77 + 5);
1521 Z_printhf("%5d", p->frag);
1523 if (p->drawst & PL_DRAWKEYS) {
1524 int x, k, n;
1525 for (k = p->keys >> 4, n = 0, x = st - 75; n < 3; n++, k >>= 1, x += 9) {
1526 if (k & 1) {
1527 R_gl_draw_image(&keys[n], x, 91, 0);
1531 if (p->drawst & PL_DRAWLIVES && !_2pl) {
1532 Z_gotoxy(st - 35, 17);
1533 Z_printhf("%d", p->lives);
1535 glPopMatrix();
1538 /* --- Game --- */
1540 static void pl_info (player_t *p, int x, int y) {
1541 dword t = p->kills * 10920 / g_time;
1542 Z_gotoxy(x + 25, y); Z_printbf("KILLS");
1543 Z_gotoxy(x + 25, y + 15); Z_printbf("KPM");
1544 Z_gotoxy(x + 25, y + 30); Z_printbf("SECRETS %u / %u", p->secrets, sw_secrets);
1545 Z_gotoxy(x + 255, y); Z_printbf("%u", p->kills);
1546 Z_gotoxy(x + 255, y + 15); Z_printbf("%u.%u", t / 10, t % 10);
1549 static void R_draw_intermission (void) {
1550 int cx = SCRW / 2;
1551 word hr, mn, sc, h;
1552 Z_gotoxy(cx - 14*12/2, 20);
1553 Z_printbf("LEVEL COMPLETE");
1554 Z_calc_time(g_time, &hr, &mn, &sc);
1555 Z_gotoxy(cx - 12*12/2, 40);
1556 Z_printbf("TIME %u:%02u:%02u", hr, mn, sc);
1557 h = 40 + SCRH / 10;
1558 if (_2pl) {
1559 Z_gotoxy(cx - 10*12/2, h);
1560 Z_printbf("PLAYER ONE");
1561 h += 20;
1563 pl_info(&pl1, cx - 160, h);
1564 if (_2pl) {
1565 h += 30 + SCRH / 10;
1566 Z_gotoxy(cx - 10*12/2, h);
1567 Z_printbf("PLAYER TWO");
1568 h += 20;
1569 pl_info(&pl2, cx - 160, h);
1573 static void W_act (void) {
1574 int i, a;
1575 if (g_time % 3 == 0) {
1576 for (i = 1; i < max_textures; i++) {
1577 a = walani[i];
1578 if (a != 0) {
1579 anic[a]++;
1580 if (anip[a][anic[a]].res == -1) {
1581 anic[a] = 0;
1583 walp[i] = anip[a][anic[a]];
1589 void R_draw (void) {
1590 W_act();
1591 glClearColor(0, 0, 0, 1);
1592 glClear(GL_COLOR_BUFFER_BIT);
1593 glEnable(GL_SCISSOR_TEST);
1594 R_gl_setmatrix();
1595 switch (g_st) {
1596 case GS_ENDANIM:
1597 case GS_END2ANIM:
1598 case GS_DARKEN:
1599 case GS_BVIDEO:
1600 case GS_EVIDEO:
1601 case GS_END3ANIM:
1602 break;
1603 case GS_TITLE:
1604 R_gl_draw_image_ext(&scrnh[0], 0, 0, SCRW, SCRH);
1605 break;
1606 case GS_INTER:
1607 R_gl_draw_image_ext(&scrnh[1], 0, 0, SCRW, SCRH);
1608 R_draw_intermission();
1609 break;
1610 case GS_ENDSCR:
1611 R_gl_draw_image_ext(&scrnh[2], 0, 0, SCRW, SCRH);
1612 break;
1613 case GS_GAME:
1614 if (_2pl) {
1615 R_draw_player_view(&pl1, 0, 0, SCRW, SCRH / 2);
1616 R_draw_player_view(&pl2, 0, SCRH / 2, SCRW, SCRH / 2);
1617 } else {
1618 R_draw_player_view(&pl1, 0, 0, SCRW, SCRH);
1620 R_gl_setclip(0, 0, SCRW, SCRH);
1621 break;
1623 GM_draw();
1624 Y_swap_buffers();
1627 static void R_alloc (void) {
1628 char s[10];
1629 int i, j, n;
1630 logo("R_alloc: load graphics\n");
1631 /* Game */
1632 scrnh[0] = R_gl_loadimage("TITLEPIC");
1633 scrnh[1] = R_gl_loadimage("INTERPIC");
1634 scrnh[2] = R_gl_loadimage("ENDPIC");
1635 for (i = 0; i < 2; i++) {
1636 sprintf(s, "LTN%c", '1' + i);
1637 for (j = 0; j < 2; j++) {
1638 ltn[i][j] = Z_getspr(s, j, 0, NULL);
1641 /* Smoke */
1642 for (i = 0; i < SMSN; i++) {
1643 smk_spr[i] = R_gl_get_special_spr("SMOK", i, 0, &R_extract_smoke_spr);
1645 for (i = 0; i < FLSN; i++) {
1646 smk_fspr[i] = R_gl_get_special_spr("SMOK", i, 0, &R_extract_flame_spr);
1648 /* Effects */
1649 for (i = 0; i < 10; i++) {
1650 fx_spr[i] = Z_getspr("TFOG", i, 0, fx_sprd + i);
1652 for (; i < 15; i++) {
1653 fx_spr[i] = Z_getspr("IFOG", i - 10, 0, fx_sprd + i);
1655 /* Weapons */
1656 for (i = 0; i < 4; i++) {
1657 wp_spr[i * 2] = Z_getspr("MISL", i, 1, wp_sprd + i * 2);
1658 wp_spr[i * 2 + 1] = Z_getspr("MISL", i, 2, wp_sprd + i * 2 + 1);
1660 for (; i < 6; i++) {
1661 wp_spr[i * 2] = Z_getspr("PLSS", i - 4, 1, wp_sprd + i * 2);
1662 wp_spr[i * 2 + 1] = Z_getspr("PLSS", i - 4, 2, wp_sprd + i * 2 + 1);
1664 for (; i < 11; i++) {
1665 wp_spr[i * 2] = Z_getspr("PLSE", i - 6, 1, wp_sprd + i * 2);
1666 wp_spr[i * 2 + 1] = Z_getspr("PLSE", i - 6, 2, wp_sprd + i * 2 + 1);
1668 for (; i < 13; i++) {
1669 wp_spr[i * 2] = Z_getspr("APLS", i - 11, 1, wp_sprd + i * 2);
1670 wp_spr[i * 2 + 1] = Z_getspr("APLS", i - 11, 2, wp_sprd + i * 2 + 1);
1672 for (; i < 18; i++) {
1673 wp_spr[i * 2] = Z_getspr("APBX", i - 13, 1, wp_sprd + i * 2);
1674 wp_spr[i * 2 + 1] = Z_getspr("APBX", i - 13, 2, wp_sprd + i * 2 + 1);
1676 for(; i < 20; i++) {
1677 wp_spr[i * 2] = Z_getspr("BFS1", i - 18, 1, wp_sprd + i * 2);
1678 wp_spr[i * 2 + 1] = Z_getspr("BFS1", i - 18, 2, wp_sprd + i * 2 + 1);
1680 for (; i < 26; i++) {
1681 wp_spr[i * 2] = Z_getspr("BFE1", i - 20, 1, wp_sprd + i * 2);
1682 wp_spr[i * 2 + 1] = Z_getspr("BFE1", i - 20, 2, wp_sprd + i * 2 + 1);
1684 for (; i < 30; i++) {
1685 wp_spr[i * 2] = Z_getspr("BFE2", i - 26, 1, wp_sprd + i * 2);
1686 wp_spr[i * 2 + 1] = Z_getspr("BFE2", i - 26, 2, wp_sprd + i * 2 + 1);
1688 for (; i < 32; i++) {
1689 wp_spr[i * 2] = Z_getspr("MISL", i - 30 + 4, 1, wp_sprd + i * 2);
1690 wp_spr[i * 2 + 1] = Z_getspr("MISL", i - 30 + 4, 2, wp_sprd + i * 2 + 1);
1692 for (; i < 37; i++) {
1693 wp_spr[i * 2] = Z_getspr("BAL1", i - 32, 1, wp_sprd + i * 2);
1694 wp_spr[i * 2 + 1] = Z_getspr("BAL1", i - 32, 2, wp_sprd + i * 2 + 1);
1696 for (; i < 42; i++) {
1697 wp_spr[i * 2] = Z_getspr("BAL7", i - 37, 1, wp_sprd + i * 2);
1698 wp_spr[i * 2 + 1] = Z_getspr("BAL7", i - 37, 2, wp_sprd + i * 2 + 1);
1700 for (; i < 47; i++) {
1701 wp_spr[i * 2] = Z_getspr("BAL2", i - 42, 1, wp_sprd + i * 2);
1702 wp_spr[i * 2 + 1] = Z_getspr("BAL2", i - 42, 2, wp_sprd + i * 2 + 1);
1704 for (; i < 49; i++) {
1705 wp_spr[i * 2] = Z_getspr("MANF", i - 47, 1, wp_sprd + i * 2);
1706 wp_spr[i * 2 + 1] = Z_getspr("MANF", i - 47, 2, wp_sprd + i * 2 + 1);
1708 /* Items */
1709 static const char snm[18][4] = {
1710 "CLIP", "SHEL", "ROCK", "CELL", "AMMO", "SBOX", "BROK", "CELP",
1711 "STIM", "MEDI", "BPAK",
1712 "CSAW", "SHOT", "SGN2", "MGUN", "LAUN", "PLAS", "BFUG"
1713 };
1714 static const char n4[4][4] = {
1715 "SOUL", "SMRT", "SMGT", "SMBT"
1716 };
1717 static const char n3[2][4] = {
1718 "GOR1", "FCAN"
1719 };
1720 for (i = 0; i < 18; i++) {
1721 item_spr[i] = Z_getspr(snm[i], 0, 0, item_sprd + i);
1723 for (; i < 20; i++) {
1724 item_spr[i] = Z_getspr("ARM1", i - 18, 0, item_sprd + i);
1725 item_spr[i + 2] = Z_getspr("ARM2", i - 18, 0, item_sprd + i);
1727 i+=2;
1728 for (; i < 26; i++) {
1729 item_spr[i] = Z_getspr("MEGA", i - 22, 0, item_sprd + i);
1731 for (; i < 30; i++) {
1732 item_spr[i] = Z_getspr("PINV", i - 26, 0, item_sprd + i);
1734 item_spr[30] = Z_getspr("AQUA", 0, 0, item_sprd + 30);
1735 item_spr[31] = Z_getspr("KEYR", 0, 0, item_sprd + 31);
1736 item_spr[32] = Z_getspr("KEYG", 0, 0, item_sprd + 32);
1737 item_spr[33] = Z_getspr("KEYB", 0, 0, item_sprd + 33);
1738 item_spr[34] = Z_getspr("SUIT", 0, 0, item_sprd + 34);
1739 for (n = 35, j = 0; j < 4; j++) {
1740 for (i = 0; i < 4; i++, n++) {
1741 item_spr[n] = Z_getspr(n4[j], i, 0, item_sprd + n);
1744 for (j = 0; j < 2; j++) {
1745 for (i = 0; i < 3; i++, n++) {
1746 item_spr[n] = Z_getspr(n3[j], i, 0, item_sprd + n);
1749 item_spr[57] = Z_getspr("GUN2", 0, 0, item_sprd + 57);
1750 /* Player */
1751 for (i = 0; i < 27; i++) {
1752 plr_spr[i * 2] = Z_getspr("PLAY", i, 1, plr_sprd + i * 2);
1753 plr_msk[i * 2] = R_gl_get_special_spr("PLAY", i, 1, &R_extract_mask_spr);
1754 plr_spr[i * 2 + 1] = Z_getspr("PLAY", i, 2, plr_sprd + i * 2 + 1);
1755 plr_msk[i * 2 + 1] = R_gl_get_special_spr("PLAY", i, 2, &R_extract_mask_spr);
1757 strncpy(s, "PWPx", 4);
1758 for (i = 1; i < 11; i++) {
1759 s[3] = (i < 10 ? '0' : 'A' - 10) + i;
1760 for (j = 0; j < 6; j++) {
1761 plr_wpn[i][j] = Z_getspr(s, j, 1, NULL);
1764 /* Monsters */
1765 static const char msn[MN_TN][4] = {
1766 "SARG", "TROO", "POSS", "SPOS", "CYBR", "CPOS", "BOSS", "BOS2", "HEAD", "SKUL",
1767 "PAIN", "SPID", "BSPI", "FATT", "SKEL", "VILE", "FISH", "BAR1", "ROBO", "PLAY"
1768 };
1769 static const int mms[MN_TN] = {
1770 14*2, 21*2, 21*2, 21*2, 16*2, 20*2, 15*2, 15*2, 12*2, 11*2,
1771 13*2, 19*2, 16*2, 20*2, 17*2, 29*2, 6*2, 2*2, 17*2, 23*2
1772 };
1773 mn_sgun[0] = Z_getspr("PWP4", 0, 1, NULL);
1774 mn_sgun[1] = Z_getspr("PWP4", 1, 1, NULL);
1775 for (j = 0; j < MN_TN; j++) {
1776 for (i = 0; i < mms[j]; i++) {
1777 mn_spr[j][i] = Z_getspr(msn[j], i / 2, (i & 1) + 1, &mn_sprd[j][i]);
1778 if (j == MN_MAN - 1) {
1779 mn_man_msk[i] = R_gl_get_special_spr(msn[j], i / 2, (i & 1) + 1, &R_extract_mask_spr);
1782 if (j == MN_BARREL - 1) {
1783 for (i = 4; i < 14; i++) {
1784 mn_spr[j][i] = Z_getspr("BEXP", i / 2 - 2, (i & 1) + 1, &mn_sprd[j][i]);
1788 for (i = 0; i < 8; i++) {
1789 mn_fspr[i] = Z_getspr("FIRE", i, 0, NULL);
1791 pl_spr[0] = Z_getspr("PLAY", 'N' - 'A', 0, NULL);
1792 pl_msk[0] = R_gl_get_special_spr("PLAY", 'N' - 'A', 0, &R_extract_mask_spr);
1793 pl_spr[1] = Z_getspr("PLAY", 'W' - 'A', 0, NULL);
1794 pl_msk[1] = R_gl_get_special_spr("PLAY", 'W' - 'A', 0, &R_extract_mask_spr);
1795 /* Misc */
1796 static const char mnm[22][8]={
1797 "STTNUM0", "STTNUM1", "STTNUM2", "STTNUM3", "STTNUM4",
1798 "STTNUM5", "STTNUM6", "STTNUM7", "STTNUM8", "STTNUM9",
1799 "STTMINUS", "STTPRCNT",
1800 "FISTA0", "CSAWA0", "PISTA0", "SHOTA0", "SGN2A0", "MGUNA0", "LAUNA0",
1801 "PLASA0", "BFUGA0", "GUN2A0"
1802 };
1803 stone = R_gl_loadimage("STONE");
1804 stone2 = R_gl_loadimage("STONE2");
1805 keys[0] = R_gl_loadimage("KEYRA0");
1806 keys[1] = R_gl_loadimage("KEYGA0");
1807 keys[2] = R_gl_loadimage("KEYBA0");
1808 for (i = 0; i < 22; i++) {
1809 sth[i] = R_gl_loadimage(mnm[i]);
1811 strcpy(s, "STBF_*");
1812 for (i = '!'; i < 160; i++) {
1813 s[5] = i;
1814 bfh[i - '!'] = R_gl_getimage(F_findres(s));
1816 for (i = '!'; i < 160; i++) {
1817 sprintf(s, "STCFN%03d", i);
1818 sfh[i - '!'] = R_gl_getimage(F_findres(s));
1820 strcpy(s, "WINUM*");
1821 for (i = '0'; i <= '9'; i++) {
1822 s[5] = i;
1823 bfh[i - '!'] = R_gl_loadimage(s);
1825 bfh[':' - '!'] = R_gl_loadimage("WICOLON");
1826 // menu
1827 msklh[0] = R_gl_loadimage("M_SKULL1");
1828 msklh[1] = R_gl_loadimage("M_SKULL2");
1829 mbarl = R_gl_loadimage("M_THERML");
1830 mbarm = R_gl_loadimage("M_THERMM");
1831 mbarr = R_gl_loadimage("M_THERMR");
1832 mbaro = R_gl_loadimage("M_THERMO");
1833 mslotl = R_gl_loadimage("M_LSLEFT");
1834 mslotm = R_gl_loadimage("M_LSCNTR");
1835 mslotr = R_gl_loadimage("M_LSRGHT");
1836 // walls
1837 for (i = 1; i < ANIT; i++) {
1838 for (j = 0; j < 5 && anm[i - 1][j]; j++) {
1839 anip[i][j] = R_gl_loadimage(anm[i - 1][j]);
1841 for(; j < 5; j++) {
1842 anip[i][j] = (image) {
1843 .n = NULL,
1844 .w = 8,
1845 .h = 8,
1846 .res = -1,
1847 };
1852 static void R_reload_textures (void);
1854 void R_set_videomode (int w, int h, int fullscreen) {
1855 assert(w > 0);
1856 assert(h > 0);
1857 int was = Y_videomode_setted();
1858 if (root != NULL) {
1859 R_cache_free(root, 0);
1860 root = NULL;
1862 int res = Y_set_videomode_opengl(w, h, fullscreen);
1863 if (res == 0) {
1864 if (was == 0) {
1865 ERR_failinit("Unable to set video mode\n");
1868 Y_get_videomode(&screen_width, &screen_height);
1869 screen_full = Y_get_fullscreen();
1870 screen_scale = max(1, screen_width / 320);
1871 root = R_cache_new();
1872 assert(root);
1873 R_alloc();
1874 R_reload_textures();
1877 static int video_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) {
1878 static int cur;
1879 static int w, h, fullscreen;
1880 static char buf[16];
1881 static int buflen;
1882 static int vmode;
1883 const videomode_t *v;
1884 enum { VIDEOMODE, FULLSCREEN, APPLY, __NUM__ };
1885 static const simple_menu_t sm = {
1886 GM_BIG, "Video", NULL,
1888 { "Mode: ", NULL },
1889 { "Fullscreen: ", NULL },
1890 { "Apply ", NULL },
1892 };
1893 if (msg->type == GM_ENTER) {
1894 Y_get_videomode(&w, &h);
1895 fullscreen = Y_get_fullscreen();
1896 v = Y_get_videomode_list_opengl(fullscreen);
1897 vmode = 0;
1898 while (vmode < v->n && v->modes[vmode].w != w && v->modes[vmode].h != h) {
1899 vmode += 1;
1901 if (vmode < v->n) {
1902 w = v->modes[vmode].w;
1903 h = v->modes[vmode].h;
1905 snprintf(buf, 16, "%ix%i", w, h);
1906 buflen = strlen(buf);
1907 return 1;
1909 if (i == VIDEOMODE) {
1910 switch (msg->type) {
1911 case GM_GETSTR: return GM_init_str(msg, buf, buflen);
1912 case GM_SELECT:
1913 v = Y_get_videomode_list_opengl(fullscreen);
1914 vmode = vmode + 1 >= v->n ? 0 : vmode + 1;
1915 if (v->n > 0) {
1916 w = v->modes[vmode].w;
1917 h = v->modes[vmode].h;
1918 } else {
1919 Y_get_videomode(&w, &h);
1921 snprintf(buf, 16, "%ix%i", w, h);
1922 buflen = strlen(buf);
1923 return 1;
1925 } else if (i == FULLSCREEN) {
1926 switch (msg->type) {
1927 case GM_GETSTR: return GM_init_str(msg, fullscreen ? "Yes" : "No ", 3);
1928 case GM_SELECT: fullscreen = !fullscreen; return 1;
1930 } else if (i == APPLY) {
1931 switch (msg->type) {
1932 case GM_SELECT: R_set_videomode(w, h, fullscreen); return 1;
1935 return simple_menu_handler(msg, i, __NUM__, &sm, &cur);
1938 static const menu_t video_menu = {
1939 NULL, &video_menu_handler
1940 };
1942 const menu_t *R_menu (void) {
1943 return &video_menu;
1946 const cfg_t *R_args (void) {
1947 static const cfg_t args[] = {
1948 { "fullscr", &init_screen_full, Y_SW_ON },
1949 { "window", &init_screen_full, Y_SW_OFF },
1950 { "width", &init_screen_width, Y_DWORD },
1951 { "height", &init_screen_height, Y_DWORD },
1952 { NULL, NULL, 0 } // end
1953 };
1954 return args;
1957 const cfg_t *R_conf (void) {
1958 static const cfg_t conf[] = {
1959 { "sky", &w_horiz, Y_SW_ON },
1960 { "fullscreen", &screen_full, Y_SW_ON },
1961 { "screen_width", &screen_width, Y_DWORD },
1962 { "screen_height", &screen_height, Y_DWORD },
1963 { NULL, NULL, 0 } // end
1964 };
1965 return conf;
1968 void R_init (void) {
1969 logo("R_init: intialize opengl render\n");
1970 R_init_playpal();
1971 init_screen_width = init_screen_width > 0 ? init_screen_width : screen_width;
1972 init_screen_height = init_screen_height > 0 ? init_screen_height : screen_height;
1973 init_screen_full = init_screen_full != 0xFF ? init_screen_full : screen_full;
1974 R_set_videomode(init_screen_width, init_screen_height, init_screen_full);
1977 void R_done (void) {
1978 R_cache_free(root, 1);
1979 Y_unset_videomode();
1980 root = NULL;
1983 void R_get_name (int n, char s[8]) {
1984 assert(n >= 0 && n < 256);
1985 if (walp[n].res == -1) {
1986 memset(s, 0, 8);
1987 } else if (walp[n].res == -2) {
1988 memcpy(s, "_WATER_", 8);
1989 s[7] = '0' + (intptr_t)walp[n].n - 1;
1990 } else if (walani[n] > 0) {
1991 memcpy(s, anm[walani[n] - 1][0], 8);
1992 } else {
1993 F_getresname(s, walp[n].res & 0x7FFF);
1997 static short getani (char n[8]) {
1998 short i = 0;
1999 while (i < ANIT - 1 && strncasecmp(n, anm[i][0], 8) != 0) {
2000 i++;
2002 return i < ANIT - 1 ? i + 1 : 0;
2005 int R_get_special_id (int n) {
2006 assert(n >= 0 && n <= 256);
2007 return walp[n].res == -2 ? (intptr_t)walp[n].n : -1;
2010 static void R_reload_textures (void) {
2011 int i;
2012 char s[8];
2013 for (i = 0; i < max_textures; i++) {
2014 R_get_name(i, s);
2015 if (walp[i].res >= 0) {
2016 walp[i] = R_gl_getimage(walp[i].res);
2019 if (horiz.n) {
2020 horiz = R_gl_getimage(horiz.res);
2024 void R_begin_load (void) {
2025 int i;
2026 for (i = 0; i < 256; i++) {
2027 if (walp[i].n != NULL && walp[i].res >= 0 && walani[i] == 0) {
2028 R_gl_free_image(&walp[i]);
2030 memset(&walp[i], 0, sizeof(image));
2031 walp[i].res = -1;
2032 walswp[i] = i;
2033 walani[i] = 0;
2035 memset(anic, 0, sizeof(anic));
2036 max_wall_width = 0;
2037 max_wall_height = 0;
2038 max_textures = 1;
2041 void R_load (char s[8]) {
2042 assert(max_textures < 256);
2043 if (!s[0]) {
2044 walp[max_textures] = (image) {
2045 .n = NULL,
2046 .x = 0,
2047 .y = 0,
2048 .w = 0,
2049 .h = 0,
2050 .res = -1,
2051 };
2052 } else if (strncasecmp(s, "_WATER_", 7) == 0) {
2053 walp[max_textures] = (image) {
2054 .n = (void*)((intptr_t)s[7] - '0' + 1),
2055 .x = 0,
2056 .y = 0,
2057 .w = 8,
2058 .h = 8,
2059 .res = -2,
2060 };
2061 } else {
2062 walp[max_textures] = R_gl_loadimage(s);
2063 if (s[0] == 'S' && s[1] == 'W' && s[4] == '_') {
2064 walswp[max_textures] = 0;
2066 walani[max_textures] = getani(s);
2068 max_wall_width = max(max_wall_width, walp[max_textures].w);
2069 max_wall_height = max(max_wall_height, walp[max_textures].h);
2070 max_textures++;
2073 void R_end_load (void) {
2074 int i, j, k, g;
2075 char s[8];
2076 j = max_textures;
2077 for (i = 1; i < 256 && j < 256; i++) {
2078 if (walswp[i] == 0) {
2079 R_get_name(i, s);
2080 s[5] ^= 1;
2081 g = F_getresid(s);
2082 k = 1;
2083 while (k < 256 && walp[k].res != g) {
2084 k += 1;
2086 if (k >= 256) {
2087 k = j;
2088 j += 1;
2089 max_textures += 1;
2090 walp[k] = R_gl_getimage(g);
2091 walf[k] = walf[i];
2093 walswp[i] = k;
2094 walswp[k] = i;
2099 void R_loadsky (int sky) {
2100 char s[6];
2101 strcpy(s, "RSKYx");
2102 s[4] = '0' + sky;
2103 R_gl_free_image(&horiz);
2104 horiz = R_gl_loadimage(s);
2107 void R_switch_texture (int x, int y) {
2108 assert(x >= 0 && x < FLDW);
2109 assert(y >= 0 && y < FLDH);
2110 fldb[y][x] = walswp[fldb[y][x]];
2113 int R_get_swp (int n) {
2114 assert(n >= 0 && n < 256);
2115 return walswp[n];