예제 #1
0
static float newmax(float val, float oldmax)
{
    float m, decade;

    if (val > oldmax) {
        decade = pow(10, floor(log10(val)));
        CHECKMAX(1.0);
        CHECKMAX(2.0);
        CHECKMAX(5.0);
        CHECKMAX(10.0); // should be redundant
    }
    else return oldmax;
}
예제 #2
0
파일: md2.cpp 프로젝트: AresAndy/ufoai
void MD2SkinNum (const byte* buf, const char* fileName, int bufSize, void* userData)
{
	byte* copy = Mem_Dup(byte, buf, bufSize);
	dMD2Model_t* md2 = (dMD2Model_t*)copy;

	MD2HeaderCheck(md2, fileName, bufSize);

	const uint32_t numSkins = LittleLong(md2->num_skins);

	const uint32_t ofsST = LittleLong(md2->ofs_st);
	const uint32_t ofsTris = LittleLong(md2->ofs_tris);
	const uint32_t ofsFrames = LittleLong(md2->ofs_frames);
	const uint32_t ofsGLCmds = LittleLong(md2->ofs_glcmds);
	const uint32_t ofsEnd = LittleLong(md2->ofs_end);
	const uint32_t ofsSkins = LittleLong(md2->ofs_skins);

	uint32_t moveOffset = ofsEnd;
#define CHECKMAX(val) 	if ((val) > ofsSkins && (val) < moveOffset) moveOffset = (val);
	CHECKMAX(ofsST);
	CHECKMAX(ofsTris);
	CHECKMAX(ofsFrames);
	CHECKMAX(ofsGLCmds);
	CHECKMAX(ofsSkins);
#undef CHECKMAX

	Com_Printf("  \\ - skins %i\n", numSkins);
	int newSkins = 0;
	printf("  \\ - new skin number: ");
	fflush(stdout);
	scanf("%i", &newSkins);
	if (newSkins <= 0) {
		Com_Printf("A model must have a skin\n");
		Mem_Free(copy);
		return;
	}
	if (newSkins > MD2_MAX_SKINS) {
		Com_Printf("Only %i skins are allowed\n", MD2_MAX_SKINS);
		Mem_Free(copy);
		return;
	}

	if (newSkins == numSkins) {
		Mem_Free(copy);
		return;
	}

	const int32_t deltaSkins = newSkins - numSkins;
	const int32_t offsetDelta = deltaSkins * MD2_MAX_SKINNAME;
	if (ofsST > ofsSkins)
		md2->ofs_st = LittleLong(ofsST + offsetDelta);
	if (ofsTris > ofsSkins)
		md2->ofs_tris = LittleLong(ofsTris + offsetDelta);
	if (ofsFrames > ofsSkins)
		md2->ofs_frames = LittleLong(ofsFrames + offsetDelta);
	if (ofsGLCmds > ofsSkins)
		md2->ofs_glcmds = LittleLong(ofsGLCmds + offsetDelta);
	md2->ofs_end = LittleLong(ofsEnd + offsetDelta);
	md2->num_skins = LittleLong(newSkins);

	Com_Printf("change to %i skins\n", newSkins);
	if (deltaSkins > 0) {
		copy = (byte*)Mem_ReAlloc(copy, md2->ofs_end);
		md2 = (dMD2Model_t*)copy;
	}

	const int n = ofsEnd - moveOffset;
	byte* from = copy + moveOffset;
	byte* to = from + offsetDelta;
	memmove(to, from, n);

	if (deltaSkins > 0) {
		char*  md2Path = (char*) copy + LittleLong(md2->ofs_skins);
		for (int i = numSkins; i < numSkins + deltaSkins; i++) {
			char* name = md2Path + i * MD2_MAX_SKINNAME;
			memset(name, 0, MD2_MAX_SKINNAME);
			strcpy(name, ".none");
			Com_Printf("  \\ - skin %i: %s\n", i + 1, name);
			printf("  \\ - new skin: ");
			fflush(stdout);
			scanf(va("%%%is", MD2_MAX_SKINNAME), name);
		}
	}
	ScopedFile md2ModelFile;
	FS_OpenFile(fileName, &md2ModelFile, FILE_WRITE);
	if (!md2ModelFile) {
		Com_Printf("Error writing md2 file %s\n", fileName);
		Mem_Free(copy);
		return;
	}
	FS_Write(copy, md2->ofs_end, &md2ModelFile);
	Mem_Free(copy);
}