⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regisobj.cpp

📁 空战游戏flacon源码
💻 CPP
字号:
#include "header.h"
#include "LODutil.h"
#include "..\..\3Dlib\hobreadr.h"

struct recordPtr {
	char		name[256], desc[GL_MAX_DESCRIPTION];
	int			id;
	int			maxdof, maxswitch, maxslot, maxanim, maxdvtx;
	GLvertex	*SlotOffset;
	int			totallod;
	float		radius;
	lodPtr		*lod;
	recordPtr	*next;
};

union {
	float	f;
	char	c[4];
} FloatChar;

union {
	int		i;
	char	c[4];
} IntChar;

void readObjectDescription (char *str);
int getUnixFilename (char *filename);
void InsertObject (char *name, int index, char *desc);
int objectIDfound (int index);
void insertObjectinList (recordPtr *curObject);

char buffer[1024];
int	currentobjid;
recordPtr *ObjectList;

void main (int argc, char *argv[])
{
	puts ("\nRegisObj v1.0 by Erick Jap\n");
	if (argc < 2) {
		puts ("Usage: RegisObj fltlistfile [options]");
		puts ("options:");
		puts ("-s            --> Input is an flt file not file list");
		puts ("-oobjlistfile --> objlistfile is output file (Default is object.lst)");
		puts ("-i            --> Insert object into the existing list");
		exit (1);
	}

	char infile[80], outfile[80], curfile[80], desc[GL_MAX_DESCRIPTION];
	strcpy (infile, argv[1]);
	strcpy (outfile, "objects.lst");
	GLint i, index;
	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;
		}
	}

	currentobjid = 0;
	ObjectList = 0;	

	CFileIO myfile;
	CStreamIO myfile1;
	if (insertflag) {
		if (myfile.openread (outfile)) {
			currentobjid = myfile.read_int ();
			while (1) {
				i = myfile.read_int ();
				if (i == -1) break;
				recordPtr *curObject = (recordPtr *) glAllocateMemory (sizeof(recordPtr));
				if (!curObject) {
					puts ("Fatal Error!! Can not allocate object memory!\n");
					exit (1);
				}
				if (currentobjid < i) currentobjid = i;
				curObject -> id = i;
				myfile.readdata (curObject -> desc, GL_MAX_DESCRIPTION);
				curObject -> radius = myfile.read_float ();
				curObject -> maxdof = myfile.read_int ();
				curObject -> maxswitch = myfile.read_int ();
				curObject -> maxslot = myfile.read_int ();
				curObject -> maxanim = myfile.read_int ();
				curObject -> maxdvtx = myfile.read_int ();
				curObject -> SlotOffset = 0;
				if (curObject -> maxslot) {
					i = curObject -> maxslot * sizeof (GLvertex);
					curObject -> SlotOffset = (GLvertex *) glAllocateMemory (i);
					if (!curObject -> SlotOffset) {
						puts ("Fatal Error!! Can not allocate slot offset memory!\n");
						exit (1);
					}
					for (i=0; i < curObject -> maxslot; i++) {
						curObject -> SlotOffset[i].x = myfile.read_float ();
						curObject -> SlotOffset[i].y = myfile.read_float ();
						curObject -> SlotOffset[i].z = myfile.read_float ();
					}
				}
				curObject -> totallod = myfile.read_int ();
				i = curObject -> totallod * sizeof (lodPtr);
				curObject -> lod = (lodPtr *) glAllocateMemory (i);
				if (!curObject -> lod) {
					puts ("Fatal Error!! Can not allocate lod memory!\n");
					exit (1);
				}
				lodPtr *lod = curObject -> lod;
				for (i=0; i < curObject -> totallod;i++) {
					lod -> distance = myfile.read_int ();
					lod -> flag = myfile.read_int ();
					myfile.readdata (lod -> name, GL_NAMESIZE);
					lod = lod -> next;
				}
				curObject -> next = 0;
				insertObjectinList (curObject);
			}
			myfile.closefile();
		}
	}

	if (!myfile.openwrite (outfile, 1)) {
		printf ("Can not open output file %s\n", outfile);
		exit (1);
	}

	if (inputflag) {
		printf ("Please enter Object ID --> ");
		scanf ("%d", &index);
		printf ("Please enter Object Description --> ");
		readObjectDescription (desc);
		InsertObject (infile, index, desc);
	}
	else {
		if (!myfile1.openread (infile)) {
			printf ("Can not open input file %s\n", infile);
			exit (1);
		}
		while (!myfile1.eof()) {
			if (myfile1.read ("%d", &index) == -1) break;
			if (myfile1.read ("%s", curfile) == -1) break;
			readObjectDescription (desc, myfile1);
			InsertObject (curfile, index, desc);
		}
		myfile1.closefile();
	}

	currentobjid++;		// objid start at 0
	myfile.moveoutfileptr ();

	IntChar.i = currentobjid;
	myfile.writedata (IntChar.c , 4);

	while (ObjectList) {
		recordPtr *curObject = ObjectList;
		ObjectList = ObjectList -> next;

		IntChar.i = curObject -> id;
		myfile.writedata (IntChar.c , 4);

		myfile.writedata (curObject -> desc, GL_MAX_DESCRIPTION);

		FloatChar.f = curObject -> radius;
		myfile.writedata (FloatChar.c, 4);

		IntChar.i = curObject -> maxdof;
		myfile.writedata (IntChar.c , 4);
		IntChar.i = curObject -> maxswitch;
		myfile.writedata (IntChar.c , 4);
		IntChar.i = curObject -> maxslot;
		myfile.writedata (IntChar.c , 4);
		IntChar.i = curObject -> maxanim;
		myfile.writedata (IntChar.c , 4);
		IntChar.i = curObject -> maxdvtx;
		myfile.writedata (IntChar.c , 4);

		if (curObject -> maxslot) {
			for (i=0; i < curObject -> maxslot; i++) {
				FloatChar.f = curObject -> SlotOffset[i].x;
				myfile.writedata (FloatChar.c, 4);
				FloatChar.f = curObject -> SlotOffset[i].y;
				myfile.writedata (FloatChar.c, 4);
				FloatChar.f = curObject -> SlotOffset[i].z;
				myfile.writedata (FloatChar.c, 4);
			}
		}

		IntChar.i = curObject -> totallod;
		myfile.writedata (IntChar.c , 4);

		lodPtr *lod = curObject -> lod;
		for (i=0; i < curObject -> totallod;i++) {
			IntChar.i = lod -> distance;
			myfile.writedata (IntChar.c , 4);
			IntChar.i = lod -> flag;
			myfile.writedata (IntChar.c , 4);
			myfile.writedata ((char *) lod -> name, GL_NAMESIZE);

			lod = lod -> next;
		}
		lod = curObject -> lod;
		while (lod) {
			lodPtr *lod1 = lod;
			lod = lod -> next;
			glReleaseMemory ((char *) lod1);
		}
		glReleaseMemory ((char *) curObject -> SlotOffset);
		glReleaseMemory ((char *) curObject);
	}

	IntChar.i = -1;
	myfile.writedata (IntChar.c , 4);
	myfile.closefile(1);

	puts ("Done");
}

void readObjectDescription (char *str)
{
	int		i;
	char	c;
	char	*savestr = str;
	while (1) {
		scanf ("%c", &c);
		if (c != ' ' && c != '\t') {
			*str++ = c;
			break;
		}
	}
	if (savestr[0] == '\n') {
		strcpy (savestr, "No Description");
		return;
	}
	gets (str);
	savestr[GL_MAX_DESCRIPTION-1] = '\0';
	for (i=0; i < GL_MAX_DESCRIPTION; i++) {
		if (savestr[i] == '\n') savestr[i] = '\0';
		if (savestr[i] == '\0') break;
	}
	if (savestr[0] == '\0') strcpy (savestr, "No Description");
}

int objectIDfound (int index) 
{
	if (ObjectList) {
		recordPtr *curObject = ObjectList;
		while (curObject) {
			if (curObject -> id == index) return 1;
			curObject = curObject -> next;
		}
	}
	return 0;
}

void insertObjectinList (recordPtr *curObject) 
{
	recordPtr *cur1, *cur2;
	cur1 = ObjectList;
	cur2 = 0;
	while (cur1) {
		if (curObject -> id < cur1 -> id) {
			curObject -> next = cur1;
			break;
		}
		cur2 = cur1;
		cur1 = cur1 -> next;
	}
	if (cur2) cur2 -> next = curObject;
	else ObjectList = curObject;
}

void InsertObject (char *name, int index, char *desc)
{
	if (objectIDfound (index)) {
		printf ("%s objectID (%d) already exists in the list!\n", 
							name, index);
		exit (1);
	}

	recordPtr *curObject = (recordPtr *) glAllocateMemory (sizeof(recordPtr));
	if (!curObject) {
		puts ("Fatal Error!! Can not allocate object memory!\n");
		exit (1);
	}
	if (currentobjid < index) currentobjid = index;
	curObject -> next = 0;
	curObject -> id = index;
	curObject -> maxdof = 0;
	curObject -> maxswitch = 0;
	curObject -> maxslot = 0;
	curObject -> maxanim = 0;
	curObject -> maxdvtx = 0;
	curObject -> SlotOffset = 0;
	curObject -> radius = (GLfloat) 0.0;
	strcpy (curObject -> desc, desc);

	CHOBReader		hob;
	GLObjectData	*data;
	lodPtr *lod;
	GLint	i;
	curObject -> totallod = getLODData (name, &lod);
	curObject -> lod = lod;
	for (i=0; i< curObject -> totallod; i++) {
		glConcatFileExtension ((GLbyte *) lod -> name, (GLbyte *) lod -> name, (GLbyte *) "HOB");
		data = hob.readHOB ((GLbyte *) lod -> name);
		if (!data) {
			printf ("Can not read %s!\n", lod -> name);
			exit (1);
		}
		if (curObject -> radius < data -> objectRadius)
			curObject -> radius = data -> objectRadius;
		if (curObject -> maxdof < data -> TotalDOF)
			curObject -> maxdof = data -> TotalDOF;
		if (curObject -> maxswitch < data -> TotalSwitch)
			curObject -> maxswitch = data -> TotalSwitch;
		if (curObject -> maxslot < data -> TotalObjectSlot) {
			curObject -> maxslot = data -> TotalObjectSlot;
			glReleaseMemory (curObject -> SlotOffset);
			GLint slot;
			slot = curObject -> maxslot * sizeof (GLvertex);
			curObject -> SlotOffset = (GLvertex *) glAllocateMemory (slot);
			if (!curObject -> SlotOffset) {
				puts ("Fatal Error!! Can not allocate slot offset memory!\n");
				exit (1);
			}
			for (slot=0; slot < curObject -> maxslot; slot++) {
				curObject -> SlotOffset[slot] = data -> Slotptr[slot].objectCenter;
			}
		}
		if (curObject -> maxanim < data -> objectAnimation -> TotalAnsData)
			curObject -> maxanim = data -> objectAnimation -> TotalAnsData;
		if (curObject -> maxdvtx < data -> TotalDynamicVertex)
			curObject -> maxdvtx = data -> TotalDynamicVertex;
		glRemoveObjectData (data);
		lod = lod -> next;
	}
	insertObjectinList (curObject);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -