/* viDOOM - level editor for DOOM Copyright (C) 2000 Ian Cowburn (ianc@noddybox.demon.co.uk) 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; either version 2 of the License, or (at your option) any later version. 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------- Stores lists of the graphical information from the WADs */ static const char rcs_id[]="$Id$"; #include "config.h" #include "globals.h" #include #include "texture.h" #include "wad.h" #include "mem.h" #include "gfx.h" #include "platgui.h" #include "gui.h" #include "vstring.h" PLAT_IMG_PICKLIST *flat_picklist=NULL; PLAT_IMG_PICKLIST *texture_picklist=NULL; /* The height and width of a texture are actually stored along with the texture name */ #define TXTNUMWID 8 #define TXTHEIGHT 10 #define TXTWIDTH 20 #define TXTMALLOC 31 /* ---------------------------------------- PRIVATE FUNCTIONS */ static int CmpText(const void *a,const void *b) { const PLAT_IMG_PICKLIST *p1,*p2; p1=a; p2=b; return(StrCaseCmp(p1->text,p2->text)); } static Byte *GetMemShort(Byte *p,Short *s) { *s=(Short)(*p++); *s|=((Short)(*p++))<<8; return(p); } static Byte *GetMemLong(Byte *p,Long *l) { *l=(Long)(*p++); *l|=((Long)(*p++))<<8; *l|=((Long)(*p++))<<16; *l|=((Long)(*p++))<<24; return(p); } static Byte *GetName(Byte *p,char *s) { int f; for(f=0;f<8;f++) *s++=*p++; *s=0; return(p); } static void BMPlot(int x,int y,int c,GFX_BITMAP *bm) { if ((x>=0)&&(xw)&&(y>=0)&&(yh)) *(bm->data+(x)+(y*bm->w))=c; } static void DecodeLump(Byte *lump, int ox, int oy, GFX_BITMAP *bm) { Short lw,lh,lox,loy; Byte *base; Byte *col; Long off; int x,y,f; Byte cno; base=lump; lump=GetMemShort(lump,&lw); lump=GetMemShort(lump,&lh); lump=GetMemShort(lump,&lox); lump=GetMemShort(lump,&loy); lox=MAX(lox,0); loy=MAX(loy,0); for(x=0;xw=MIN(w,MAX_GFXBM_W); t_ent=GetMemShort(t_ent,&h); bm->h=MIN(h,MAX_GFXBM_H); /* Once we have the width and height, return if the actual image is not to be loaded */ if (!load_textures) return(NULL); /* Skip over always zero fields */ t_ent+=4; /* The bitmap is filled with the transparent colour */ memset(bm->data,243,w*h); /* Get no of patches that make up this texture */ t_ent=GetMemShort(t_ent,&no); /* Read each patch and add to the texture */ for(f=0;fw); sprintf(texture_picklist[*i].text+TXTHEIGHT, "%*.*d",TXTNUMWID,TXTNUMWID,bm->h); (*i)++; } } /* ------------------------------ EXPORTED FUNCTIONS */ void ReadWADFlats(void) { WadDir *wd; Iterator i; int found; int done; GFX_BITMAP bm; Byte *pal; int no; int ip; int f; if (!(pal=GetLump("PLAYPAL",NULL))) GFX_exit(EXIT_FAILURE,"There MUST be a PLAYPAL lump in the WADs!!\n"); if (flat_picklist) { ip=0; while(flat_picklist[ip].text) { Release(flat_picklist[ip].text); if (flat_picklist[ip].img) GFX_destroy_image(flat_picklist[ip].img); } Release(flat_picklist); } /* Get number of flats (Naughty.. Means we read through dir twice...) */ i=GetWadDir(); found=FALSE; done=FALSE; no=0; while((i)&&(!done)) { wd=IteratorData(i); if (!found) found=!StrCaseCmp(wd->name,"F_START"); else if (!(done=!StrCaseCmp(wd->name,"F_END"))) if (wd->size==0x1000) no++; i=IteratorNext(i); } IteratorClear(i); flat_picklist=Grab(sizeof(PLAT_IMG_PICKLIST)*(no+1)); flat_picklist[no].text=NULL; flat_picklist[no].img=NULL; /* Palette and size for bitmap */ bm.w=64; bm.h=64; for(f=0;f<256;f++) { int r,g,b; r=(int)(pal[f*3]*gfx_brighten); g=(int)(pal[f*3+1]*gfx_brighten); b=(int)(pal[f*3+2]*gfx_brighten); r=MIN(255,r); g=MIN(255,g); b=MIN(255,b); bm.pal[f]=V_RGB(r,g,b); } /* Load in the names and graphics */ i=GetWadDir(); found=FALSE; done=FALSE; ip=0; while((i)&&(!done)) { wd=IteratorData(i); if (!found) found=!StrCaseCmp(wd->name,"F_START"); else if (!(done=!StrCaseCmp(wd->name,"F_END"))) if (wd->size==0x1000) { flat_picklist[ip].text=Strdup(wd->name); if (load_flats) { /* GFX_BITMAP and DOOM flats are actually in the same format */ if (!(bm.data=GetLump(wd->name,NULL))) GFX_exit(EXIT_FAILURE, "Failed to load flat %s\n",wd->name); flat_picklist[ip].img=GFX_create_image(&bm); Release(bm.data); } else flat_picklist[ip].img=NULL; GuiDrawInfoBox((load_flats ? "Please wait. Reading flat graphics": "Please wait. Reading flat names"), GUI_CENTRE,GUI_CENTRE,TRUE, "Flat %s|%d%% complete", wd->name,ip*100/no); GFX_redraw(); ip++; } i=IteratorNext(i); } IteratorClear(i); Release(pal); /* Sort the list if requested */ if (sort_flats) qsort(flat_picklist,no-1,sizeof(PLAT_IMG_PICKLIST),CmpText); /* Set the client indexes */ for(f=0;f