22 Dec 2007
This commit is contained in:
parent
71cebb95ba
commit
1d7fe10f27
|
@ -10,16 +10,14 @@ DDS Converter 2.1
|
|||
3. SC_ParseToken вылетает при парсинге сейв-файла
|
||||
4. где-то бьется буффер при -dev 6
|
||||
|
||||
создание wadlib:
|
||||
1. придумать синтаксис
|
||||
|
||||
Текущие задачи:
|
||||
1. ввести новые типы для вадов OK
|
||||
2. имлементировать таблицу для их поиска внутри вада OK
|
||||
3. Имплементировать FS_SearchLump в FS_Search OK
|
||||
4. Создать wadlib с поддержкой компрессии лумпов OK
|
||||
5. высвободить память, выделенную в FS_OpenWad3 в imglib OK
|
||||
6. Тест на различные типы файлов, документация
|
||||
6. Тест на различные типы файлов, документация OK
|
||||
7. Еще раз пересмотреть типы файлов для wadlib
|
||||
7. подключить звуковой кодер к roqlib
|
||||
8. Имплементация save-restore для физики
|
||||
9. Избавиться от оригинальной партиклевой системы
|
||||
|
@ -29,12 +27,12 @@ DDS Converter 2.1
|
|||
//==================================================
|
||||
// то, что уже готово
|
||||
//==================================================
|
||||
+поддержка всех типов для вадов тщательно оттестирована
|
||||
+запущена в строй wadlib
|
||||
+добавлена поддержка ВСЕХ существующих типов внутри вадов
|
||||
+добавлена поддержка wad-файлов
|
||||
+наконец-то добавлена аппаратная гамма
|
||||
+наконец-то добавлена аппаратная гамма-коррекция
|
||||
+добавлена загрузка мипмапов для всех типов текстур
|
||||
+пофикшен баг с загрузкой мипмпов
|
||||
+пофикшен баг с загрузкой мипмапов
|
||||
+collision tree теперь сохраняется в lump
|
||||
+исправлены баги в parselib.c
|
||||
+доделан кастомный парсинг исходников для qcclib
|
||||
|
|
156
common/wadlib.c
156
common/wadlib.c
|
@ -13,6 +13,7 @@ dwadinfo_t wadfile; // main header
|
|||
int wadheader;
|
||||
int numlumps = 0;
|
||||
bool compress_lumps = false;
|
||||
bool allow_compression = false;
|
||||
file_t *handle = NULL;
|
||||
|
||||
void Wad3_NewWad( void )
|
||||
|
@ -25,21 +26,66 @@ void Wad3_NewWad( void )
|
|||
numlumps = 0;
|
||||
}
|
||||
|
||||
int Lump_GetFileType( const char *name, byte *buf )
|
||||
{
|
||||
const char *ext = FS_FileExtension( name );
|
||||
|
||||
if(!buf) return TYPE_NONE;
|
||||
|
||||
switch(LittleLong(*(uint *)buf))
|
||||
{
|
||||
case IDSPRITEHEADER: return TYPE_SPRITE;
|
||||
case IDSTUDIOHEADER: return TYPE_STUDIO;
|
||||
case DDSHEADER: return TYPE_MIPDDS;
|
||||
}
|
||||
|
||||
// otherwise get file type by extension
|
||||
if(!com.stricmp( ext, "tga" )) return TYPE_MIPTGA;
|
||||
else if(!com.stricmp( ext, "mip" ))
|
||||
{
|
||||
if(wadheader == IDWAD3HEADER)
|
||||
return TYPE_MIPTEX2; // half-life texture
|
||||
return TYPE_MIPTEX; // quake1 texture
|
||||
}
|
||||
else if(!com.stricmp( ext, "lmp" )) return TYPE_QPIC; // hud pics
|
||||
else if(!com.stricmp( ext, "pal" )) return TYPE_QPAL; // palette
|
||||
else if(!com.stricmp( ext, "wav" )) return TYPE_SOUND; // wav sound
|
||||
else if(!com.stricmp( ext, "txt" )) return TYPE_SCRIPT; // text file
|
||||
else if(!com.stricmp( ext, "dat" )) return TYPE_VPROGS; // qc progs
|
||||
else if(!com.stricmp( ext, "raw" )) return TYPE_RAW; // raw data
|
||||
else if(!com.stricmp( ext, "ent" )) return TYPE_ENTFILE; // ents file
|
||||
|
||||
// no compares found
|
||||
return TYPE_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
AddLump
|
||||
===============
|
||||
*/
|
||||
void Wad3_AddLump( const char *name, void *buffer, int length, int type, bool compress )
|
||||
void Wad3_AddLump( const char *name, bool compress )
|
||||
{
|
||||
dlumpinfo_t *info;
|
||||
int ofs;
|
||||
byte *buffer;
|
||||
int ofs, type, length;
|
||||
|
||||
if(!buffer || type == TYPE_NONE)
|
||||
Msg("Add lump %s\n", name );
|
||||
|
||||
// we can load file from another wad
|
||||
buffer = FS_LoadFile( name, &length );
|
||||
type = Lump_GetFileType( name, buffer );
|
||||
|
||||
if(!buffer)
|
||||
{
|
||||
MsgWarn("Wad3_AddLump: file %s not found\n", name );
|
||||
return;
|
||||
}
|
||||
if(type == TYPE_NONE)
|
||||
{
|
||||
MsgWarn("Wad3_AddLump: file %s have unsupported type\n", name );
|
||||
return;
|
||||
}
|
||||
|
||||
FS_FileBase( (char *)name, lumpname );
|
||||
if(strlen(lumpname) > WAD3_NAMELEN)
|
||||
|
@ -75,37 +121,10 @@ void Wad3_AddLump( const char *name, void *buffer, int length, int type, bool co
|
|||
info->size = info->disksize = LittleLong( length );
|
||||
FS_Write( handle, buffer, length ); // just write file
|
||||
}
|
||||
Mem_Free( buffer );
|
||||
MsgDev(D_NOTE, "AddLump: %s, size %d\n", info->name, info->disksize );
|
||||
}
|
||||
|
||||
int Lump_GetFileType( const char *name, byte *buf )
|
||||
{
|
||||
const char *ext = FS_FileExtension( name );
|
||||
|
||||
if(!buf) return TYPE_NONE;
|
||||
|
||||
switch(LittleLong(*(uint *)buf))
|
||||
{
|
||||
case IDSPRITEHEADER: return TYPE_SPRITE;
|
||||
case IDSTUDIOHEADER: return TYPE_STUDIO;
|
||||
case DDSHEADER: return TYPE_MIPDDS;
|
||||
}
|
||||
|
||||
// otherwise get file type by extension
|
||||
if(!com.stricmp( ext, "tga" )) return TYPE_MIPTGA;
|
||||
else if(!com.stricmp( ext, "mip" )) return TYPE_MIPTEX; // quake1 texture
|
||||
else if(!com.stricmp( ext, "tex" )) return TYPE_MIPTEX2; // half-life texture
|
||||
else if(!com.stricmp( ext, "lmp" )) return TYPE_QPIC; // hud pics
|
||||
else if(!com.stricmp( ext, "pal" )) return TYPE_QPAL; // palette
|
||||
else if(!com.stricmp( ext, "wav" )) return TYPE_SOUND; // wav sound
|
||||
else if(!com.stricmp( ext, "txt" )) return TYPE_SCRIPT; // text file
|
||||
else if(!com.stricmp( ext, "dat" )) return TYPE_VPROGS; // qc progs
|
||||
else if(!com.stricmp( ext, "raw" )) return TYPE_RAW; // raw data
|
||||
|
||||
// no compares found
|
||||
return TYPE_NONE;
|
||||
}
|
||||
|
||||
void Cmd_WadName( void )
|
||||
{
|
||||
com.strncpy( wadoutname, Com_GetToken(false), sizeof(wadoutname));
|
||||
|
@ -116,28 +135,57 @@ void Cmd_WadType( void )
|
|||
{
|
||||
Com_GetToken( false );
|
||||
|
||||
if (Com_MatchToken( "wad3")) wadheader = IDWAD3HEADER;
|
||||
else if (Com_MatchToken( "wad2")) wadheader = IDWAD2HEADER;
|
||||
if(Com_MatchToken( "Quake1") || Com_MatchToken( "Q1"))
|
||||
{
|
||||
wadheader = IDWAD2HEADER;
|
||||
}
|
||||
else if(Com_MatchToken( "Half-Life") || Com_MatchToken( "Hl1"))
|
||||
{
|
||||
wadheader = IDWAD3HEADER;
|
||||
}
|
||||
else if(Com_MatchToken( "Xash3D"))
|
||||
{
|
||||
wadheader = IDWAD4HEADER;
|
||||
}
|
||||
else wadheader = IDWAD3HEADER; // default
|
||||
}
|
||||
|
||||
void Cmd_AddLump( void )
|
||||
{
|
||||
int depth = 0;
|
||||
char filename[MAX_SYSPATH];
|
||||
byte *buf;
|
||||
size_t filesize;
|
||||
bool compress = false;
|
||||
|
||||
Com_GetToken( false );
|
||||
com.strncpy( filename, com_token, sizeof(filename));
|
||||
if(Com_TryToken()) compress = true;
|
||||
if( compress_lumps ) compress = true;
|
||||
|
||||
Msg("loadfile %s\n", filename );
|
||||
// we can load file from another wad ;)
|
||||
buf = FS_LoadFile( filename, &filesize );
|
||||
Wad3_AddLump( filename, buf, filesize, Lump_GetFileType( filename, buf ), compress );
|
||||
if( allow_compression )
|
||||
{
|
||||
if(Com_TryToken()) compress = true;
|
||||
if(compress_lumps) compress = true;
|
||||
}
|
||||
|
||||
Wad3_AddLump( filename, compress );
|
||||
}
|
||||
|
||||
void Cmd_AddLumps( void )
|
||||
{
|
||||
int i, compress = false;
|
||||
search_t *t;
|
||||
|
||||
Com_GetToken( false );
|
||||
t = FS_Search( com_token, true );
|
||||
if(!t) return;
|
||||
|
||||
if( allow_compression )
|
||||
{
|
||||
if(Com_TryToken()) compress = true;
|
||||
if(compress_lumps) compress = true;
|
||||
}
|
||||
|
||||
for(i = 0; i < t->numfilenames; i++)
|
||||
{
|
||||
Wad3_AddLump( t->filenames[i], compress );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -149,7 +197,8 @@ syntax: "$compression"
|
|||
*/
|
||||
void Cmd_WadCompress( void )
|
||||
{
|
||||
compress_lumps = true;
|
||||
if( allow_compression )
|
||||
compress_lumps = true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -167,11 +216,13 @@ void Cmd_WadUnknown( void )
|
|||
|
||||
void ResetWADInfo( void )
|
||||
{
|
||||
FS_FileBase(gs_mapname, wadoutname );//kill path and ext
|
||||
FS_DefaultExtension( wadoutname, ".wad" );//set new ext
|
||||
FS_FileBase( gs_mapname, wadoutname ); // kill path and ext
|
||||
FS_DefaultExtension( wadoutname, ".wad" ); // set new ext
|
||||
|
||||
memset (&wadheader, 0, sizeof(wadheader));
|
||||
wadheader = IDWAD3HEADER;
|
||||
compress_lumps = false;
|
||||
allow_compression = false;
|
||||
numlumps = 0;
|
||||
handle = NULL;
|
||||
}
|
||||
|
@ -193,17 +244,18 @@ bool ParseWADfileScript( void )
|
|||
else if (Com_MatchToken( "$wadtype" )) Cmd_WadType();
|
||||
else if (Com_MatchToken( "$compression" )) Cmd_WadCompress();
|
||||
else if (Com_MatchToken( "$addlump" )) Cmd_AddLump();
|
||||
else if (Com_MatchToken( "$addlumps" )) Cmd_AddLumps();
|
||||
else if (!Com_ValidScript( QC_WADLIB )) return false;
|
||||
else Cmd_WadUnknown();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WriteWADFile( void )
|
||||
bool WriteWADFile( void )
|
||||
{
|
||||
int ofs;
|
||||
|
||||
if(!handle) return;
|
||||
if(!handle) return false;
|
||||
|
||||
// write the lumpingo
|
||||
ofs = FS_Tell( handle );
|
||||
|
@ -217,12 +269,8 @@ void WriteWADFile( void )
|
|||
FS_Seek( handle, 0, SEEK_SET );
|
||||
FS_Write( handle, &wadfile, sizeof(wadfile));
|
||||
FS_Close( handle );
|
||||
}
|
||||
|
||||
void ClearWADfile( void )
|
||||
{
|
||||
compress_lumps = false;
|
||||
handle = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BuildCurrentWAD( const char *name )
|
||||
|
@ -237,9 +285,7 @@ bool BuildCurrentWAD( const char *name )
|
|||
{
|
||||
if(!ParseWADfileScript())
|
||||
return false;
|
||||
WriteWADFile();
|
||||
ClearWADfile();
|
||||
return true;
|
||||
return WriteWADFile();
|
||||
}
|
||||
|
||||
Msg("%s not found\n", gs_mapname );
|
||||
|
|
|
@ -1021,6 +1021,9 @@ static bool FS_AddWad3File( const char *filename )
|
|||
case IDWAD3HEADER:
|
||||
com_strncpy( type, "Half-Life", 16 );
|
||||
break;
|
||||
case IDWAD4HEADER:
|
||||
com_strncpy( type, "Xash3D", 16 );
|
||||
break;
|
||||
default:
|
||||
MsgDev(D_ERROR, "FS_AddWad3File: %s have invalid ident\n", filename );
|
||||
FS_Close( file );
|
||||
|
@ -1752,6 +1755,7 @@ wadtype_t wad_types[] =
|
|||
{"mdl", TYPE_STUDIO }, // studio model
|
||||
{"spr", TYPE_SPRITE }, // sprite
|
||||
{"wav", TYPE_SOUND }, // sound
|
||||
{"ent", TYPE_ENTFILE}, // ents description
|
||||
{NULL, TYPE_NONE }
|
||||
};
|
||||
|
||||
|
@ -2638,7 +2642,9 @@ static search_t *_FS_Search(const char *pattern, int caseinsensitive, int quiet
|
|||
{
|
||||
if(SC_FilterToken(lumpname, w->lumps[i].name, !caseinsensitive ))
|
||||
{
|
||||
stringlistappend(&resultlist, w->lumps[i].name);
|
||||
com_strncpy(temp, w->lumps[i].name, sizeof(temp));
|
||||
FS_DefaultExtension( temp, va(".%s", type->ext )); // make ext
|
||||
stringlistappend(&resultlist, temp );
|
||||
break; // found, compare to next lump
|
||||
}
|
||||
}
|
||||
|
|
|
@ -587,15 +587,8 @@ bool LoadMIP( char *name, char *buffer, int filesize )
|
|||
// detect rendermode
|
||||
if( name[0] == '{' )
|
||||
{
|
||||
// note: i trying determine transparent miptex by last color in palette
|
||||
// e.g. valve used in their textures blue color (0,0,255)
|
||||
// other cases for red (255,0,0) ang green (0,255,0) colors,
|
||||
// otherwise - it will use decal palette with ugly results. ughgrrr..
|
||||
if(pal[255*3+0] == 0 && pal[255*3+1] == 0 && pal[255*3+2] == 255 && pal[255*3+3] == 0)
|
||||
rendermode = LUMP_TRANSPARENT;
|
||||
else if(pal[255*3+0] == 0 && pal[255*3+1] == 255 && pal[255*3+2] == 0 && pal[255*3+3] == 0)
|
||||
rendermode = LUMP_TRANSPARENT;
|
||||
else if(pal[255*3+0] == 255 && pal[255*3+1] == 0 && pal[255*3+2] == 0 && pal[255*3+3] == 0)
|
||||
// qlumpy used this color for transparent textures, otherwise it's decals
|
||||
if(pal[255*3+0] == 0 && pal[255*3+1] == 0 && pal[255*3+2] == 255)
|
||||
rendermode = LUMP_TRANSPARENT;
|
||||
else rendermode = LUMP_DECAL;
|
||||
image_flags |= IMAGE_HAS_ALPHA;
|
||||
|
|
|
@ -297,7 +297,7 @@ void Sys_LookupInstance( void )
|
|||
Sys.app_name = WADLIB;
|
||||
Sys.linked_dll = &common_dll; // pointer to common.dll info
|
||||
com_sprintf(Sys.log_path, "%s/wadlib.log", sys_rootdir ); // same as .exe file
|
||||
com_strcpy(Sys.caption, "Xash3D Pak\\Pk3 maker");
|
||||
com_strcpy(Sys.caption, "Xash3D Wad2\\Wad3 maker");
|
||||
}
|
||||
else if(!com_strcmp(Sys.progname, "credits")) // easter egg
|
||||
{
|
||||
|
|
|
@ -1577,6 +1577,7 @@ typedef struct mip_s
|
|||
#define IDPWADHEADER (('D'<<24)+('A'<<16)+('W'<<8)+'P') // little-endian "PWAD" doom1 game wad
|
||||
#define IDWAD2HEADER (('2'<<24)+('D'<<16)+('A'<<8)+'W') // little-endian "WAD2" quake1 gfx.wad
|
||||
#define IDWAD3HEADER (('3'<<24)+('D'<<16)+('A'<<8)+'W') // little-endian "WAD3" half-life wads
|
||||
#define IDWAD4HEADER (('4'<<24)+('D'<<16)+('A'<<8)+'W') // little-endian "WAD4" Xash3D wad type
|
||||
#define WAD3_NAMELEN 16
|
||||
|
||||
#define CMP_NONE 0 // compression none
|
||||
|
@ -1593,11 +1594,12 @@ typedef struct mip_s
|
|||
#define TYPE_QFONT 70 // half-life font (qfont_t)
|
||||
#define TYPE_MIPDDS 71 // Xash3D dds texture
|
||||
#define TYPE_MIPTGA 72 // Xash3D tga texture
|
||||
#define TYPE_VPROGS 73 // Xash3D QC progs
|
||||
#define TYPE_VPROGS 73 // Xash3D QC compiled progs
|
||||
#define TYPE_SCRIPT 74 // txt script file (e.g. shader)
|
||||
#define TYPE_STUDIO 75 // studio models
|
||||
#define TYPE_SPRITE 76 // normal sprite
|
||||
#define TYPE_SOUND 77 // wav data
|
||||
#define TYPE_ENTFILE 78 // map entities description
|
||||
|
||||
#define QCHAR_WIDTH 16
|
||||
#define QFONT_WIDTH 16 // valve fonts used contant sizes
|
||||
|
|
Reference in New Issue