X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fsoft%2Frender.c;h=c77709c66877c74594ab98b5073b0bf0e66a8069;hb=HEAD;hp=38c3ba7f3bc057bcca8db85497cbe1bc5ef06360;hpb=9f3ca6bf02300e3dc72e3c2085a8e35aa9242678;p=flatwaifu.git diff --git a/src/soft/render.c b/src/soft/render.c index 38c3ba7..174c3ea 100644 --- a/src/soft/render.c +++ b/src/soft/render.c @@ -1,3 +1,21 @@ +/* Copyright (C) 1996-1997 Aleksey Volynskov + * Copyright (C) 2011 Rambo + * Copyright (C) 2020 SovietPony + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License ONLY. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include #include #include #include // abs() @@ -24,7 +42,13 @@ #include "music.h" #include "system.h" -#include "cp866.h" +#include "common/cp866.h" + +#pragma pack(push, 1) +typedef struct rgb_t { + byte r, g, b; +} rgb_t; +#pragma pack(pop) // game static vgaimg *scrnh[3]; // TITLEPIC INTERPIC ENDPIC @@ -60,8 +84,8 @@ static int prx = 0, pry = 0; static vgaimg *msklh[2], *mbarl, *mbarm, *mbarr, *mbaro, *mslotl, *mslotm, *mslotr; // low level static int gammaa = 0; -static char main_pal[256][3]; -static char std_pal[256][3]; +static rgb_t *main_pal; +static byte std_pal[256][3]; static byte gamcor[5][64]={ #include "gamma.dat" }; @@ -72,6 +96,7 @@ static int w_o, w_x, w_y; static vgaimg *walp[256]; static int walh[256]; static byte walani[256]; +static byte walswp[256]; static int anih[ANIT][5]; static byte anic[ANIT]; static int max_textures; @@ -86,10 +111,7 @@ static int init_screen_gammaa = -1; /* --- misc --- */ static void *Z_getspr (char n[4], int s, int d, char *dir) { - int h = F_getsprid(n, s, d); - if (dir) { - *dir = (h & 0x8000) ? 1 : 0; - } + int h = F_getsprid(n, s, d, dir); return V_getvgaimg(h); } @@ -358,58 +380,59 @@ static void get_entry_size (const menu_t *m, int i, int *w, int *h) { int type = 0; menu_msg_t msg; msg.type = GM_GETENTRY; - assert(GM_send(m, i, &msg)); - type = msg.integer.i; - switch (type) { - case GM_BUTTON: - case GM_SCROLLER: - case GM_TEXTFIELD: - case GM_TEXTFIELD_BUTTON: - msg.type = GM_GETCAPTION; - if (GM_send(m, i, &msg)) { - x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s); - } - break; - case GM_SMALL_BUTTON: - msg.type = GM_GETCAPTION; - if (GM_send(m, i, &msg)) { - x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s); - } - break; - default: - assert(0); - } - switch (type) { - case GM_BUTTON: - msg.type = GM_GETSTR; - if (GM_send(m, i, &msg)) { - x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s); - } - y = 16; - break; - case GM_SMALL_BUTTON: - msg.type = GM_GETSTR; - if (GM_send(m, i, &msg)) { - x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s); - } - y = 12; - break; - case GM_SCROLLER: - x += (SCROLLER_MIDDLE + 2) * 8; - y = 16; - break; - case GM_TEXTFIELD: - case GM_TEXTFIELD_BUTTON: - msg.type = GM_GETSTR; - if (GM_send(m, i, &msg)) { - x += (msg.string.maxlen + 2) * 8; - } else { - x += (TEXTFIELD_MIDDLE + 2) * 8; - } - y = 16; - break; - default: - assert(0); + if (GM_send(m, i, &msg)) { + type = msg.integer.i; + switch (type) { + case GM_BUTTON: + case GM_SCROLLER: + case GM_TEXTFIELD: + case GM_TEXTFIELD_BUTTON: + msg.type = GM_GETCAPTION; + if (GM_send(m, i, &msg)) { + x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s); + } + break; + case GM_SMALL_BUTTON: + msg.type = GM_GETCAPTION; + if (GM_send(m, i, &msg)) { + x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s); + } + break; + default: + assert(0); + } + switch (type) { + case GM_BUTTON: + msg.type = GM_GETSTR; + if (GM_send(m, i, &msg)) { + x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s); + } + y = 16; + break; + case GM_SMALL_BUTTON: + msg.type = GM_GETSTR; + if (GM_send(m, i, &msg)) { + x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s); + } + y = 12; + break; + case GM_SCROLLER: + x += (SCROLLER_MIDDLE + 2) * 8; + y = 16; + break; + case GM_TEXTFIELD: + case GM_TEXTFIELD_BUTTON: + msg.type = GM_GETSTR; + if (GM_send(m, i, &msg)) { + x += (msg.string.maxlen + 2) * 8; + } else { + x += (TEXTFIELD_MIDDLE + 2) * 8; + } + y = 16; + break; + default: + assert(0); + } } *w = x; *h = y; @@ -1148,7 +1171,7 @@ void R_draw (void) { void R_alloc (void) { int i, j, n; char s[10]; - logo("R_alloc: загрузка графики\n"); + logo("R_alloc: load graphics\n"); // game scrnh[0] = V_loadvgaimg("TITLEPIC"); scrnh[1] = V_loadvgaimg("INTERPIC"); @@ -1377,13 +1400,13 @@ void R_get_name (int n, char s[8]) { } static short getani (char n[8]) { - if (strncasecmp(n, "WALL22_1", 8) == 0) { + if (cp866_strncasecmp(n, "WALL22_1", 8) == 0) { return 1; - } else if (strncasecmp(n, "WALL58_1", 8) == 0) { + } else if (cp866_strncasecmp(n, "WALL58_1", 8) == 0) { return 2; - } else if (strncasecmp(n, "W73A_1", 8) == 0) { + } else if (cp866_strncasecmp(n, "W73A_1", 8) == 0) { return 3; - } else if (strncasecmp(n, "RP2_1", 8) == 0) { + } else if (cp866_strncasecmp(n, "RP2_1", 8) == 0) { return 4; } else { return 0; @@ -1411,21 +1434,18 @@ void R_begin_load (void) { max_textures = 1; } -void R_load (char s[8], int f) { +void R_load (char s[8]) { assert(max_textures < 256); if (!s[0]) { walh[max_textures] = -1; walp[max_textures] = NULL; } else { - if (strncasecmp(s, "_WATER_", 7) == 0) { + if (cp866_strncasecmp(s, "_WATER_", 7) == 0) { walh[max_textures] = -2; walp[max_textures] = (void*)((intptr_t)s[7] - '0' + 1); } else { walh[max_textures] = F_getresid(s); walp[max_textures] = V_getvgaimg(walh[max_textures]); - if (f) { - walh[max_textures] |= 0x8000; - } if (s[0] == 'S' && s[1] == 'W' && s[4] == '_') { walswp[max_textures] = 0; } @@ -1443,7 +1463,7 @@ void R_end_load (void) { if (walswp[i] == 0) { R_get_name(i, s); s[5] ^= 1; - g = F_getresid(s) | (walh[i] & 0x8000); + g = F_getresid(s); k = 1; while (k < 256 && walh[k] != g) { k += 1; @@ -1453,7 +1473,7 @@ void R_end_load (void) { j += 1; walh[k] = g; walp[k] = V_getvgaimg(g); - walf[k] = g & 0x8000 ? 1 : 0; + walf[k] = walf[i]; } walswp[i] = k; walswp[k] = i; @@ -1474,11 +1494,11 @@ void R_setgamma(int g) { g = g < 0 ? 0 : (g > 4 ? 4 : g); gammaa = g; for (t = 0; t < 256; ++t) { - std_pal[t][0]=gamcor[gammaa][main_pal[t][0]]; - std_pal[t][1]=gamcor[gammaa][main_pal[t][1]]; - std_pal[t][2]=gamcor[gammaa][main_pal[t][2]]; + std_pal[t][0] = gamcor[gammaa][main_pal[t].r]; + std_pal[t][1] = gamcor[gammaa][main_pal[t].g]; + std_pal[t][2] = gamcor[gammaa][main_pal[t].b]; } - Y_set_vga_palette(std_pal); + Y_set_vga_palette(&std_pal[0][0]); } int R_getgamma (void) { @@ -1509,7 +1529,7 @@ void R_toggle_fullscreen (void) { R_setgamma(gammaa); } -static int video_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) { +static int video_menu_handler (menu_msg_t *msg, const menu_t *m, int i) { static int cur; static int w, h, fullscreen; static char buf[16]; @@ -1570,12 +1590,9 @@ static int video_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int return simple_menu_handler(msg, i, __NUM__, &sm, &cur); } -static const menu_t video_menu = { - NULL, &video_menu_handler -}; - const menu_t *R_menu (void) { - return &video_menu; + static const menu_t m = { video_menu_handler }; + return &m; } const cfg_t *R_args (void) { @@ -1602,15 +1619,23 @@ const cfg_t *R_conf (void) { return conf; } +static void *R_load_fixed (char *name, int size) { + int id = F_getresid(name); + if (F_getreslen(id) < size) { + ERR_fatal("invalid %s (%i)", name, F_getreslen(id)); + } + return M_lock(id); +} + void R_init () { int i; logo("R_init: initialize software render\n"); - F_loadres(F_getresid("PLAYPAL"), main_pal, 0, 768); + main_pal = R_load_fixed("PLAYPAL", 256 * 3); + clrmap = R_load_fixed("COLORMAP", 256 * 12); + mixmap = R_load_fixed("MIXMAP", 256 * 256); for (i = 0; i < 256; ++i) { - bright[i] = ((int) main_pal[i][0] + main_pal[i][1] + main_pal[i][2]) * 8 / (63 * 3); + bright[i] = ((int)main_pal[i].r + main_pal[i].g + main_pal[i].b) * 8 / (63 * 3); } - F_loadres(F_getresid("MIXMAP"), mixmap, 0, 0x10000); - F_loadres(F_getresid("COLORMAP"), clrmap, 0, 256*12); SCRW = init_screen_width > 0 ? init_screen_width : SCRW; SCRH = init_screen_height > 0 ? init_screen_height : SCRH; fullscreen = init_screen_full != 0xFF ? init_screen_full : fullscreen; @@ -1628,3 +1653,14 @@ void R_done (void) { pitch = 0; Y_unset_videomode(); } + +void R_switch_texture (int x, int y) { + assert(x >= 0 && x < FLDW); + assert(y >= 0 && y < FLDH); + fldb[y][x] = walswp[fldb[y][x]]; +} + +int R_get_swp (int n) { + assert(n >= 0 && n < 256); + return walswp[n]; +}