From f15430905a30601191b9bbe0885c86a1e0611661 Mon Sep 17 00:00:00 2001 From: eukos Date: Sun, 13 Sep 2015 22:59:08 +0200 Subject: [PATCH] Added fallback conchars, palette and on-the-fly colormap generation --- Makefile | 4 ++ engine/draw.c | 176 ++++++++++++++++++++++------------------------ engine/host.c | 135 ++++++++++++++++++++++++++--------- engine/wad.c | 7 +- renderer/d_scan.c | 5 -- 5 files changed, 196 insertions(+), 131 deletions(-) diff --git a/Makefile b/Makefile index 186edcb..244095a 100644 --- a/Makefile +++ b/Makefile @@ -126,6 +126,7 @@ NGUNIX_OBJS = \ $(BUILDDIR)/console.o \ $(BUILDDIR)/crc.o \ $(BUILDDIR)/cvar.o \ + $(BUILDDIR)/draw_fallback.o \ $(BUILDDIR)/draw.o \ $(BUILDDIR)/d_edge.o \ $(BUILDDIR)/d_fill.o \ @@ -371,6 +372,9 @@ $(BUILDDIR)/crc.o : $(MOUNT_DIR)/crc.c $(BUILDDIR)/cvar.o : $(MOUNT_DIR)/cvar.c $(DO_CC) +$(BUILDDIR)/draw_fallback.o : $(MOUNT_DIR)/draw_fallback.c + $(DO_CC) -O2 + $(BUILDDIR)/draw.o : $(MOUNT_DIR)/draw.c $(DO_CC) -O2 diff --git a/engine/draw.c b/engine/draw.c index 7e88dab..64e4cf6 100644 --- a/engine/draw.c +++ b/engine/draw.c @@ -71,7 +71,18 @@ int menu_numcachepics; qpic_t *Draw_PicFromWad (char *name) { - return W_GetLumpName (name); + qpic_t *image = W_GetLumpName (name); + + if(image) + return image; + else + { + image = malloc(1); + image->width = 1; + image->height = 1; + image->data[0] = 255; + return image; + } } @@ -320,24 +331,37 @@ qpic_t *Draw_CachePic (char *path) // load the pic from disk // COM_LoadCacheFile (path, &pic->cache); - dat = (qpic_t *)pic->cache.data; + if (!dat) { Con_Printf ("Draw_CachePic: failed to load %s\n", path); return NULL; } + + // leilei - quick palette translation if (rmap_ready){ int bah; for (bah = 0; bah < dat->width*dat->height; bah++) dat->data[bah] = coltranslate[dat->data[bah]]; - } + } // leilei - quick palette translation - +#if 0 + printf("DUMPING IMAGE %s START:\n===================", path); + int bah2, bah3, bah4 = 0; + for (bah2 = 0; bah2 < dat->height; bah2++) + { + for (bah3 = 0; bah3 < dat->width; bah3++){ + printf("%i,", dat->data[bah4]); + bah4++; + } + printf("\n"); + } + printf("===================\nDUMPING IMAGE %s END\n", path); +#endif SwapPic (dat); - return dat; } extern byte *host_colormap_nofb; @@ -439,7 +463,7 @@ void IdnitColorColormaps (void) { cropped = malloc((levels+256)*256); lump_p = cropped; -Con_Printf ("\n ohhhh "); + // shaded levels for (l=0;lvalue; - - // TODO: Feed 'ese -// fogcolr = 0; -// fogcolg = 0; -// fogcolb = 0; -// fogthick= 100; // thickness of fog (100 = opaque, 50 = half... ok well you get it) fogthik = fogthick * 0.01; - PALBRIGHTS = 0; -// Con_Printf ("Fog generating with %f %f %f %f", fogthick, fogcolr, fogcolg, fogcolb); - colmap = host_fogmap; + + colmap = host_fogmap; for (l=COLORLEVELS; l>0; l--) - { + { frac = 2 - 2*(float)l/(COLORLEVELS) ; frac2 = RANGE - RANGE/(float)l/(COLORLEVELS); farc = 1 - ((frac / 2 ) * fogthik); if (farc < 0) - farc = 0; - for (c=0 ; c<256-PALBRIGHTS ; c++) - { - red = ((int)((float)host_basepal[c*3] * farc) + (fogcolr / 2 * frac* fogthik)); - green = ((int)((float)host_basepal[c*3+1] * farc) + (fogcolg / 2 * frac* fogthik)); - blue = ((int)((float)host_basepal[c*3+2] * farc) + (fogcolb / 2 * frac* fogthik)); + farc = 0; + + for (c=0 ; c<256; c++) + { + red = ((int)((float)host_basepal[c*3] * farc) + (fogcolr / 2 * frac* fogthik)); + green = ((int)((float)host_basepal[c*3+1] * farc) + (fogcolg / 2 * frac* fogthik)); + blue = ((int)((float)host_basepal[c*3+2] * farc) + (fogcolb / 2 * frac* fogthik)); if (red>255)red=255; if (green>255)green=255; if (blue>255)blue=255; @@ -1445,14 +1461,11 @@ void FogTableRefresh (void) if (green<0)green=0; if (blue<0)blue=0; if (!ugly) *colmap++ = FindColor18(red,green,blue); - else - *colmap++ = BestColor(red,green,blue, 0, 254); - } - } - SetFogMap(); // set the static. -}; - - + else *colmap++ = BestColor(red,green,blue, 0, 254); + } + } + SetFogMap(); // set the static. +} // auto-regenning water tables // compared to transtable, findcolor is super fast but actually @@ -1564,13 +1577,20 @@ void RemapMapTableGet (void) remapmap[l] = 56; } +extern byte gfx_fallback_conchars[]; +extern byte gfx_fallback_disc[]; +extern byte gfx_fallback_backtile[]; + void Draw_Init (void) { - int i, j, l, c, r; + int i, j, l, c, r; draw_chars = W_GetLumpName ("conchars"); - draw_disc = W_GetLumpName ("disc"); - draw_backtile = W_GetLumpName ("backtile"); + draw_disc = Draw_PicFromWad ("disc"); + draw_backtile = Draw_PicFromWad ("backtile"); + + if(!draw_chars) + draw_chars = gfx_fallback_conchars; r_rectdesc.width = draw_backtile->width; r_rectdesc.height = draw_backtile->height; @@ -2043,19 +2063,14 @@ void Draw_PicCropped (int x, int y, qpic_t *pic) } if (y+pic->height > vid.height) - { height = vid.height-y; - } else if (y < 0) - { height = pic->height+y; - } else - { height = pic->height; - } source = pic->data; + if (y < 0) { source += (pic->width * (-y)); @@ -2067,19 +2082,16 @@ void Draw_PicCropped (int x, int y, qpic_t *pic) byte *dest = vid.buffer + y * vid.rowbytes + x; if (pic->width & 7) { // General - for (v = 0; v < height; v++) + for (v = 0; v < height; v++) + { + for (u = 0; u < pic->width; u++) { - for (u = 0; u < pic->width; u++) - { - if ((tbyte = source[u]) != TRANSPARENT_COLOR) - { - dest[u] = tbyte; - } - } - dest += vid.rowbytes; - source += pic->width; + if ((tbyte = source[u]) != TRANSPARENT_COLOR) + dest[u] = tbyte; } - + dest += vid.rowbytes; + source += pic->width; + } } else { // Unwound @@ -2144,22 +2156,14 @@ void Draw_PicCropped_Scaled (int x, int y, qpic_t *pic) } if (y >= vid.vconheight || y+pic->height < 0) - { // Totally off screen return; - } if (y+pic->height > vid.vconheight) - { height = vid.vconheight-y; - } else if (y < 0) - { height = pic->height+y; - } else - { height = pic->height; - } source = pic->data; if (y < 0) @@ -2171,26 +2175,21 @@ void Draw_PicCropped_Scaled (int x, int y, qpic_t *pic) vmax = height * vid.height / (float)vid.vconheight; umax = pic->width * vid.width / (float)vid.vconwidth; - { + byte *dest = vid.buffer + (y * vid.height/vid.vconheight) * vid.rowbytes + (x * vid.width / vid.vconwidth); - for (v = 0; v < vmax; v++) + for (v = 0; v < vmax; v++) + { + for (u = 0; u < umax; u++) { - for (u = 0; u < umax; u++) - { - s = u * vid.vconwidth / vid.width - + (v * vid.vconheight / vid.height) * pic->width; - if ((tbyte = source[s]) != TRANSPARENT_COLOR) - { - dest[u] = tbyte; - } - + s = u * vid.vconwidth / vid.width + + (v * vid.vconheight / vid.height) * pic->width; + + if ((tbyte = source[s]) != TRANSPARENT_COLOR) + dest[u] = tbyte; } - - dest += vid.rowbytes; - } + dest += vid.rowbytes; } - } @@ -2773,26 +2772,19 @@ void Draw_FadeScreen (void) t = (y & 1) << 1; for (x=0 ; xvalue)])]; - } + if (mycol < 15) + pbuf[x] = menumap[pbuf[x]][mycol]; // new menu tint + else if (mycol == 17) + pbuf[x] = transTable[pbuf[x]][0]; // alpha blend a black + else if (mycol == 18) + pbuf[x] = transTable[42+rand()&5][ (pbuf[x])]; + else if (mycol == 19) + pbuf[x] = transTable[pbuf[x+rand()&5]][ (pbuf[x+(rand()&(int)temp2->value)])]; else { - // stupid v1.08 look: - - if ((x & 3) != t) - pbuf[x] = 0; + if ((x & 3) != t) + pbuf[x] = 0; } } } diff --git a/engine/host.c b/engine/host.c index 63c95a0..ac168f7 100644 --- a/engine/host.c +++ b/engine/host.c @@ -1115,49 +1115,120 @@ void ColormapForceLoad (void) host_colormap = fileinfo->data; } -int translate_bsp; -int translate_mdl; -int translate_gfx; -int translate_spr; +/* sample a 24-bit RGB value to one of the colours on the existing 8-bit palette */ +unsigned char Convert_24_to_8(const unsigned char palette[768], const int rgb[3]) +{ + int i, j; + int best_index = -1; + int best_dist = 0; + + for (i = 0; i < 256; i++) + { + int dist = 0; + + for (j = 0; j < 3; j++) + { + /* note that we could use RGB luminosity bias for greater accuracy, but quake's colormap apparently didn't do this */ + int d = abs(rgb[j] - palette[i*3+j]); + dist += d * d; + } + + if (best_index == -1 || dist < best_dist) + { + best_index = i; + best_dist = dist; + } + } + + return (unsigned char)best_index; +} + +void Colormap_Generate(const unsigned char palette[768], unsigned char out_colormap[16384]) +{ + int num_fullbrights = 32; /* the last 32 colours will be full bright */ + int x, y, i; + + for (x = 0; x < 256; x++) + { + for (y = 0; y < 64; y++) + { + if (x < 256 - num_fullbrights) + { + int rgb[3]; + + for (i = 0; i < 3; i++) + { + rgb[i] = (palette[x*3+i] * (63 - y) + 16) >> 5; /* divide by 32, rounding to nearest integer */ + if (rgb[i] > 255) + rgb[i] = 255; + } + + out_colormap[y*256+x] = Convert_24_to_8(palette, rgb); + } + else + { + /* this colour is a fullbright, just keep the original colour */ + out_colormap[y*256+x] = x; + } + } + } +} + +int translate_bsp; +int translate_mdl; +int translate_gfx; +int translate_spr; byte colorthis; +extern byte gfx_fallback_palette[]; + void Palette_Init (void) { loadedfile_t *fileinfo; overbrights = 1; -#ifdef EGAHACK - - fileinfo = COM_LoadHunkFile ("gfx/palette.lmp"); - if (!fileinfo) - Sys_Error ("[ERROR] Couldn't load gfx/palette.lmp"); - host_basepal = fileinfo->data; - host_origpal = fileinfo->data; - host_otherpal = fileinfo->data; - - host_basepal = (unsigned char *)ega_palette; // go EGA! - -#else - fileinfo = COM_LoadHunkFile ("gfx/palette.lmp"); - if (!fileinfo) - Sys_Error ("[ERROR] Couldn't load gfx/palette.lmp"); - + fileinfo = COM_LoadHunkFile ("gfx/palette.lmp"); + if (!fileinfo) + { + Con_Printf("[CLIENT] Using builtin 8bit palette...\n"); + host_basepal = gfx_fallback_palette; + host_otherpal = gfx_fallback_palette; + } + else + { host_basepal = fileinfo->data; host_otherpal = fileinfo->data; + + /*printf("DUMPING PALETTE START:\n===================\n"); + int bah2; + for (bah2 = 0; bah2 < fileinfo->filelen; bah2++) + { + printf("%i,", fileinfo->data[bah2]); + } + printf("\n===================\nDUMPING PALETTE END\n");*/ + } -#endif - if(COM_CheckParm ("-beta")){ + + if(COM_CheckParm ("-beta")){ + host_colormap = malloc(16384); + // leilei - variable our fullbright counts if available + host_fullbrights = 256-host_colormap[16384]; + } + else + { + fileinfo = COM_LoadHunkFile ("gfx/colormap.lmp"); + + if (!fileinfo){ + Con_Printf("[CLIENT] gfx/colormap.lmp missing, generating... "); host_colormap = malloc(16384); - // leilei - variable our fullbright counts if available - host_fullbrights = 256-host_colormap[16384]; + Colormap_Generate(host_basepal, host_colormap); + host_colormap_red = host_colormap; + host_colormap_green = host_colormap; + host_colormap_blue = host_colormap; + Con_Printf("[DONE]\n"); } else { - fileinfo = COM_LoadHunkFile ("gfx/colormap.lmp"); - - if (!fileinfo) - Sys_Error ("[ERROR] Couldnf't load gfx/colormap.lmp"); - host_colormap = fileinfo->data; fileinfo = COM_LoadHunkFile ("gfx/colormap.lmp"); host_colormap_red = fileinfo->data; @@ -1165,10 +1236,10 @@ void Palette_Init (void) host_colormap_green = fileinfo->data; fileinfo = COM_LoadHunkFile ("gfx/colormap.lmp"); host_colormap_blue = fileinfo->data; - - // leilei - variable our fullbright counts if available - host_fullbrights = 256-host_colormap[16384]; } + // leilei - variable our fullbright counts if available + host_fullbrights = 256-host_colormap[16384]; + } if (COM_CheckParm ("-fakegl")) { diff --git a/engine/wad.c b/engine/wad.c index e85f1e2..58fdbe5 100644 --- a/engine/wad.c +++ b/engine/wad.c @@ -76,9 +76,12 @@ void W_LoadWadFile (char *filename) fileinfo = COM_LoadHunkFile (filename); if (!fileinfo) - Sys_Error ("W_LoadWadFile: couldn't load %s\n\nAre you sure you are running this engine with \na valid game dataset? Check your working target\ndirectory to ensure that it is correct.", filename); - wad_base = fileinfo->data; // 2001-09-12 Returning information about loaded file by Maddes + { + Con_Printf("[WAD] Couldn't load WAD2 %s, ignoring...", filename); + return; + } + wad_base = fileinfo->data; // 2001-09-12 Returning information about loaded file by Maddes header = (wadinfo_t *)wad_base; if (header->identification[0] != 'W' diff --git a/renderer/d_scan.c b/renderer/d_scan.c index 975b8f9..4e53cb1 100644 --- a/renderer/d_scan.c +++ b/renderer/d_scan.c @@ -1097,11 +1097,6 @@ void D_DrawSpans16_C (espan_t *pspan) //qbism up it from 8 to 16. This + unroll } while ((pspan = pspan->pnext) != NULL); } - - - - - void D_DrawSpansBlank (espan_t *pspan) //Blank version { int count, spancount;