📄 registex.cpp
字号:
#include "header.h"
#include "LODutil.h"
#include "..\..\3Dlib\texture.h"
#include "streamio.h"
struct recordPtr {
char name[TEXTURE_NAME_SIZE];
int id;
recordPtr *next;
};
union {
int i;
char c[4];
} IntChar;
int saveRecordHeader (CFileIO& myfile, char *rec);
int SearchTexture (char *name);
char buffer[1024];
int currenttexid;
recordPtr *TextureList, *CurrentTexture;
void main (int argc, char *argv[])
{
puts ("\nRegisTex v1.0 by Erick Jap\n");
if (argc < 2) {
puts ("Usage: RegisTex fltlistfile [options]");
puts ("options:");
puts ("-s --> Input is an flt file not file list");
puts ("-otexlistfile --> texlistfile is output file (Default is texture.lst)");
puts ("-i --> Insert texture into the existing list");
exit (1);
}
char infile[80], outfile[80], curfile[80];
char desc[GL_MAX_DESCRIPTION];
strcpy (infile, argv[1]);
strcpy (outfile, "texture.lst");
GLint i;
GLint insertflag = 0;
GLint inputflag = 0;
for (i=2;i < argc;i++) {
if (argv[i][0] == '-') {
if (argv[i][1] == 'o' || argv[i][1] == 'O') {
strcpy ((char *) outfile, (const char *) &(argv[i][2]));
}
else if (argv[i][1] == 'i' || argv[i][1] == 'I') insertflag = 1;
else if (argv[i][1] == 's' || argv[i][1] == 'S') inputflag = 1;
}
}
currenttexid = 0;
TextureList = 0;
CFileIO myfile;
CStreamIO myfile1;
if (insertflag) {
if (myfile.openread (outfile)) {
currenttexid = myfile.read_int();
while (1) {
i = myfile.read_int ();
if (i == -1) break;
if (currenttexid < i) currenttexid = i;
recordPtr *curTexture = (recordPtr *) glAllocateMemory (sizeof(recordPtr));
if (!curTexture) {
puts ("Fatal Error!! Can not allocate memory!\n");
exit (1);
}
myfile.readdata (curTexture -> name, TEXTURE_NAME_SIZE);
curTexture -> id = i;
curTexture -> next = 0;
if (TextureList) {
CurrentTexture -> next = curTexture;
CurrentTexture = curTexture;
}
else TextureList = CurrentTexture = curTexture;
}
myfile.closefile();
}
}
if (!myfile.openwrite (outfile, 1)) {
printf ("Can not open output file %s\n", outfile);
exit (1);
}
if (inputflag) {
if (!myfile.openread (infile)) {
printf ("Can not open input file %s\n", infile);
exit (1);
}
while (!myfile.eof()) {
char *record = getRecord (myfile);
if (!record) exit (1);
swapRecord (record);
saveRecordHeader (myfile, record);
glReleaseMemory ((char *) record);
}
myfile.closefile();
}
else {
if (!myfile1.openread (infile)) {
printf ("Can not open input file %s\n", infile);
exit (1);
}
lodPtr *lod;
int index, lodindex, lodflag;
while (!myfile1.eof()) {
if (myfile1.read ("%d", &index) == -1) break;
if (myfile1.read ("%s", curfile) == -1) break;
readObjectDescription (desc, myfile1);
lodflag = getLODData (curfile, &lod);
lodindex = 0;
while (lod) {
if (!myfile.openread (lod -> name)) {
printf ("Can not open input file %s\n", lod -> name);
exit (1);
}
if (lodflag > 1) printf ("\tProcessing LOD #%d (%s)\n", lodindex++, lod -> name);
while (!myfile.eof()) {
char *record = getRecord (myfile);
if (!record) exit (1);
swapRecord (record);
saveRecordHeader (myfile, record);
glReleaseMemory ((char *) record);
}
myfile.closefile();
lodPtr *lod1 = lod;
lod = lod -> next;
glReleaseMemory ((char *) lod1);
}
}
myfile1.closefile();
}
myfile.moveoutfileptr (); // write a dummy total textures
IntChar.i = currenttexid;
myfile.writedata (IntChar.c, 4);
while (TextureList) {
recordPtr *curTexture = TextureList;
TextureList = TextureList -> next;
IntChar.i = curTexture -> id;
myfile.writedata (IntChar.c, 4);
curTexture -> name[TEXTURE_NAME_SIZE-1] = '\0';
myfile.writedata (curTexture -> name, TEXTURE_NAME_SIZE);
glReleaseMemory ((char *) curTexture);
}
IntChar.i = -1;
myfile.writedata (IntChar.c, 4);
myfile.closefile(1);
puts ("Done");
}
int saveRecordHeader (CFileIO& myfile, char *rec)
{
short *srec = (short *) rec;
short rectype = *srec++;
short reclen = *srec++;
switch (rectype) {
case OPCODE_TEXTURE_REFERENCE_RECORD:
{
flt_TexturePatternRecord *tex;
tex = (flt_TexturePatternRecord *) rec;
int i = getUnixFilename (tex -> filename);
if (SearchTexture (&(tex -> filename[i]))) {
recordPtr *curTexture = (recordPtr *) glAllocateMemory (sizeof(recordPtr));
if (!curTexture) {
puts ("Fatal Error!! Can not allocate memory!\n");
exit (1);
}
strncpy (curTexture -> name, &(tex -> filename[i]), TEXTURE_NAME_SIZE);
curTexture -> id = currenttexid++;
curTexture -> next = 0;
if (TextureList) {
CurrentTexture -> next = curTexture;
CurrentTexture = curTexture;
}
else TextureList = CurrentTexture = curTexture;
}
}
return 1;
}
return 0;
}
int SearchTexture (char *name)
{
recordPtr *curTexture = TextureList;
while (curTexture) {
if (!strcmp (curTexture -> name, name)) return 0;
curTexture = curTexture -> next;
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -