Beispiel #1
0
bool D3D12Shader::Build(const ShaderDescriptor& shaderDesc)
{
    if (IsShaderSourceCode(shaderDesc.sourceType))
        return CompileSource(shaderDesc);
    else
        return LoadBinary(shaderDesc);
}
bool CAnimationManager::LoadAnimation(std::string szFilename, bool bIsXML)
{
	if(bIsXML)
		return LoadXML(szFilename);
	else
		return LoadBinary(szFilename);
}
Beispiel #3
0
int NeuralNet::Load(char *pWeightFile, char *pNormFile, int bunchSize)
{
   // cut off suffix and add '.nbin'
   char pbin_file[1024];
   strcpy(pbin_file, pWeightFile);
   char *pdot = strrchr(pbin_file, '.');
   char *pslash = strrchr(pbin_file, NN_SLASH);   
   if(pdot != 0 && (pslash == 0 || pdot > pslash))
   {
	   *pdot = '\0';
   }
   strcat(pbin_file, ".nbin");

   // load binary if the file exists
   if(LoadBinary(pbin_file, bunchSize) == NN_OK)
   {
      return NN_OK;
   }

   // load ascii otherwise and save it binary 
   int ret = LoadAscii(pWeightFile, pNormFile, bunchSize);
   if(ret == NN_OK)
   {
      SaveBinary(pbin_file);
   }

   return ret; 
}
Beispiel #4
0
BOOL CTwiBootProgDoc::LoadFile(CString FilePath, eFileType Type)
{
    ASSERT(!FilePath.IsEmpty());
    BOOL Res = FALSE;
    switch(Type)
    {
    case ftBinary:
        Res = LoadBinary(FilePath);
        break;
    case ftIntelHex:
        Res = LoadIntelHex(FilePath);
        break;
    default:
        ASSERT(FALSE);
        Res = FALSE;
        break;
    }
    return Res;
}
Beispiel #5
0
static void Parse(lua_State* L, void* userData)
{

    // We currently can't run the GC while parsing because some objects used by
    // the parser are not properly stored in a root location.

    ParseArgs* args = static_cast<ParseArgs*>(userData);

    Input input;
    Input_Initialize(L, &input, args->reader, args->userdata);

    Prototype* prototype = NULL;

    if (Input_PeekByte(&input) == '\033')
    {
        // The data is a pre-compiled binary.
        prototype = LoadBinary(L, &input, args->name);
    }
    else
    {
        prototype = Parse(L, &input, args->name);
    }

    ASSERT(prototype != NULL);
    PushPrototype(L, prototype);

    Table* env = L->globals.table;
    Closure* closure = Closure_Create(L, prototype, env);
    PushClosure(L, closure);

    // Initialize the up values. Typically a top level check won't have any up
    // values, but if the chunk was created using string.dump or a similar method
    // it may. These up values will cease to function once the chunk is loaded.
    for (int i = 0; i < closure->lclosure.numUpValues; ++i)
    {
        closure->lclosure.upValue[i] = UpValue_Create(L);
    }

    // Remove the prototype from the stack.
    ASSERT( (L->stackTop - 2)->object == prototype );
    State_Remove(L, L->stackTop - 2);

}
void CSisCertificateChain::Load (const std::wstring& aName)
{
    try
    {
        LoadText (aName);
        return;
    }
    catch (...)
    {
        try
        {
            LoadBinary (aName);
            return;
        }
        catch (...)
        {
        }
        throw;
    }
}
Beispiel #7
0
bool DumpDSPCode(const u8 *code_be, int size_in_bytes, u32 crc)
{
	char binFile[MAX_PATH];
	char txtFile[MAX_PATH];
	sprintf(binFile, "%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), crc);
	sprintf(txtFile, "%sDSP_UC_%08X.txt", File::GetUserPath(D_DUMPDSP_IDX).c_str(), crc);

	File::IOFile pFile(binFile, "wb");
	if (pFile)
	{
		pFile.WriteBytes(code_be, size_in_bytes);
		pFile.Close();
	}
	else
	{
		PanicAlert("Cant open file (%s) to dump UCode!!", binFile);
		return false;
	}

	// Load the binary back in.
	std::vector<u16> code;
	LoadBinary(binFile, code);

	AssemblerSettings settings;
	settings.show_hex = true;
	settings.show_pc = true;
	settings.ext_separator = '\'';
	settings.decode_names = true;
	settings.decode_registers = true;

	std::string text;
	DSPDisassembler disasm(settings);

	if (!disasm.Disassemble(0, code, 0x0000, text))
		return false;

	return File::WriteStringToFile(true, text, txtFile);
}
Beispiel #8
0
void ReadObjectFile(const char *file, uint32_t show = SHOW_DEFAULT)
{
	size_t size;
	if (char *data = LoadBinary(file, size)) {
		struct ObjFileHeader &hdr = *(struct ObjFileHeader*)data;
		size_t sum = sizeof(hdr) + hdr.sections*sizeof(struct ObjFileSection) +
		hdr.relocs * sizeof(struct ObjFileReloc) + hdr.labels * sizeof(struct ObjFileLabel) +
		hdr.late_evals * sizeof(struct ObjFileLateEval) +
		hdr.map_symbols * sizeof(struct ObjFileMapSymbol) + hdr.stringdata + hdr.bindata;
		if (hdr.id == 0x7836 && sum == size) {
			struct ObjFileSection *aSect = (struct ObjFileSection*)(&hdr + 1);
			struct ObjFileReloc *aReloc = (struct ObjFileReloc*)(aSect + hdr.sections);
			struct ObjFileLabel *aLabels = (struct ObjFileLabel*)(aReloc + hdr.relocs);
			struct ObjFileLateEval *aLateEval = (struct ObjFileLateEval*)(aLabels + hdr.labels);
			struct ObjFileMapSymbol *aMapSyms = (struct ObjFileMapSymbol*)(aLateEval + hdr.late_evals);
			const char *str_orig = (const char*)(aMapSyms + hdr.map_symbols);
			size_t code_start = sum - hdr.bindata, code_curr = code_start;

			// sections
			if (show & SHOW_SECTIONS) {
				int reloc_idx = 0;
				for (int si = 0; si < hdr.sections; si++) {
					struct ObjFileSection &s = aSect[si];
					int16_t f = s.flags;
					const char *tstr = s.type > 0 && s.type < section_type_str ? section_type[s.type] : "error";
					if (f & (1 << ObjFileSection::OFS_MERGED)) {
						printf("Section %d: \"" STRREF_FMT "\": (Merged)",
							   reloc_idx, STRREF_ARG(PoolStr(s.name, str_orig)));
					} else if (f & (1 << ObjFileSection::OFS_DUMMY)) {
						if (f&(1 << ObjFileSection::OFS_FIXED)) {
							printf("Section %d: \"" STRREF_FMT "\": (Dummy [%s], fixed at $%04x)",
								   reloc_idx, STRREF_ARG(PoolStr(s.name, str_orig)), tstr, s.start_address);
						} else {
							printf("Section %d: \"" STRREF_FMT "\": (Dummy [%s], relative)",
								reloc_idx, STRREF_ARG(PoolStr(s.name, str_orig)), tstr);
						}
					} else {
						if (f&(1 << ObjFileSection::OFS_FIXED)) {
							printf("Section %d: \"" STRREF_FMT "\": (Fixed [%s] $%04x, $%x bytes)",
								reloc_idx, STRREF_ARG(PoolStr(s.name, str_orig)), tstr, s.start_address, s.end_address - s.start_address);
						} else {
							printf("Section %d: \"" STRREF_FMT "\": (Relative [%s], $%x bytes, align to $%x)",
								reloc_idx, STRREF_ARG(PoolStr(s.name, str_orig)), tstr, s.end_address - s.start_address, s.align_address);
						}
						strref export_append = PoolStr(s.exp_app, str_orig);
						if (export_append)
							printf("  Export as: \"" STRREF_FMT "\"", STRREF_ARG(export_append));
					}
					if (s.first_group >= 0)
						printf(" grouped with section %d", s.first_group);
					if (s.next_group >= 0)
						printf(" next in group: %d", s.next_group);
					if ((show & SHOW_CODE_RANGE) && s.output_size)
						printf(" code: $%x-$%x", (int)code_curr, (int)(code_curr + s.output_size));
					code_curr += s.output_size;
					printf("\n");
					reloc_idx++;
				}
			}
			
			if (show & SHOW_RELOCS) {
				int curRel = 0;
				for (int si = 0; si < hdr.sections; si++) {
					printf("section %d relocs: %d\n", si, aSect[si].relocs);
					for (int r = 0; r < aSect[si].relocs; r++) {
						struct ObjFileReloc &rs = aReloc[curRel++];
						printf("Reloc: section %d offset $%x base $%x bytes: %d shift: %d\n",
							   rs.target_section, rs.section_offset, rs.base_value, rs.bytes, rs.shift);
					}
				}
			}

			if (show & SHOW_MAP_SYMBOLS) {
				for (int mi = 0; mi < hdr.map_symbols; mi++) {
					struct ObjFileMapSymbol &m = aMapSyms[mi];
					printf("Symbol: \"" STRREF_FMT "\" section: %d value: $%04x%s\n",
						   STRREF_ARG(PoolStr(m.name, str_orig)), m.section, m.value, m.local ? " (local)" : "");
				}
			}

			if (show & SHOW_LABELS) {
				for (int li = 0; li < hdr.labels; li++) {
					struct ObjFileLabel &l = aLabels[li];
					strref name = PoolStr(l.name, str_orig);
					int16_t f = l.flags;
					int external = f & ObjFileLabel::OFL_XDEF;
					printf("Label: " STRREF_FMT " %s base $%x", STRREF_ARG(name), external==ObjFileLabel::OFL_XDEF ? "external" : "protected", l.value);
					if (external!=ObjFileLabel::OFL_XDEF)
						printf(" file %d", external);
					if (f & ObjFileLabel::OFL_CNST)
						printf(" constant");
					if (f & ObjFileLabel::OFL_ADDR)
						printf(" PC rel");
					if (f & ObjFileLabel::OFL_EVAL)
						printf(" evaluated");

					printf(" map index: %d\n", l.mapIndex);
				}
			}

			if (show & SHOW_LATE_EVAL) {
				for (int li = 0; li < hdr.late_evals; ++li) {
					struct ObjFileLateEval &le = aLateEval[li];
					strref name = PoolStr(le.label, str_orig);
					if (le.type == LEType::LET_LABEL) {
						printf("Late eval label: " STRREF_FMT " expression: " STRREF_FMT "\n",
							   STRREF_ARG(name), STRREF_ARG(PoolStr(le.expression, str_orig)));
					} else {
						printf("Late eval section: %d addr: $%04x scope: $%04x target: $%04x expression: " STRREF_FMT " %s\n",
							   le.section, le.address, le.scope, le.target, STRREF_ARG(PoolStr(le.expression, str_orig)),
							   late_type[le.type]);
					}
				}
			}

			if (show & SHOW_CODE_RANGE)
				printf("Code block: $%x - $%x (%d bytes)\n", (int)code_start, (int)size, (int)(size - hdr.bindata));

			// restore previous section
		} else
			printf("Not a valid x65 file\n");
	} else
		printf("Could not open %s\n", file);
}
Beispiel #9
0
bool CRegArchive::LoadVariable(LPCTSTR lpName, __int64& Var)
{
    return LoadBinary(lpName, &Var, 8);
}
Beispiel #10
0
/*
================
idDeclParticle::Parse
================
*/
bool idDeclParticle::Parse( const char* text, const int textLength, bool allowBinaryVersion )
{

	if( cvarSystem->GetCVarBool( "fs_buildresources" ) )
	{
		fileSystem->AddParticlePreload( GetName() );
	}
	
	idLexer src;
	idToken	token;
	
	unsigned int sourceChecksum = 0;
	idStrStatic< MAX_OSPATH > generatedFileName;
	if( allowBinaryVersion )
	{
		// Try to load the generated version of it
		// If successful,
		// - Create an MD5 of the hash of the source
		// - Load the MD5 of the generated, if they differ, create a new generated
		generatedFileName = "generated/particles/";
		generatedFileName.AppendPath( GetName() );
		generatedFileName.SetFileExtension( ".bprt" );
		
		idFileLocal file( fileSystem->OpenFileReadMemory( generatedFileName ) );
		sourceChecksum = MD5_BlockChecksum( text, textLength );
		
		if( binaryLoadParticles.GetBool() && LoadBinary( file, sourceChecksum ) )
		{
			return true;
		}
	}
	
	src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
	src.SetFlags( DECL_LEXER_FLAGS );
	src.SkipUntilString( "{" );
	
	depthHack = 0.0f;
	
	while( 1 )
	{
		if( !src.ReadToken( &token ) )
		{
			break;
		}
		
		if( !token.Icmp( "}" ) )
		{
			break;
		}
		
		if( !token.Icmp( "{" ) )
		{
			if( stages.Num() >= MAX_PARTICLE_STAGES )
			{
				src.Error( "Too many particle stages" );
				MakeDefault();
				return false;
			}
			idParticleStage* stage = ParseParticleStage( src );
			if( !stage )
			{
				src.Warning( "Particle stage parse failed" );
				MakeDefault();
				return false;
			}
			stages.Append( stage );
			continue;
		}
		
		if( !token.Icmp( "depthHack" ) )
		{
			depthHack = src.ParseFloat();
			continue;
		}
		
		src.Warning( "bad token %s", token.c_str() );
		MakeDefault();
		return false;
	}
	
	// don't calculate bounds or write binary files for defaulted ( non-existent ) particles in resource builds
	if( fileSystem->UsingResourceFiles() )
	{
		bounds = idBounds( vec3_origin ).Expand( 8.0f );
		return true;
	}
	//
	// calculate the bounds
	//
	bounds.Clear();
	for( int i = 0; i < stages.Num(); i++ )
	{
		GetStageBounds( stages[i] );
		bounds.AddBounds( stages[i]->bounds );
	}
	
	if( bounds.GetVolume() <= 0.1f )
	{
		bounds = idBounds( vec3_origin ).Expand( 8.0f );
	}
	
	if( allowBinaryVersion && binaryLoadParticles.GetBool() )
	{
		idLib::Printf( "Writing %s\n", generatedFileName.c_str() );
		idFileLocal outputFile( fileSystem->OpenFileWrite( generatedFileName, "fs_basepath" ) );
		WriteBinary( outputFile, sourceChecksum );
	}
	
	return true;
}
Beispiel #11
0
 const std::string LoadString (const std::string& path)
 {
    const auto content = LoadBinary(path);
    return std::string(content.begin(), content.end());
 }
Beispiel #12
0
short ImportWizGUI::LoadSurfer(char *filename, float *Output, char TestOnly)
{
double dblval, dlo, dhi;
FILE *input = NULL;
long fpos, longval, tagid, tagsize;
short error = 0, nx, ny;
char data[4];

if ((input = PROJ_fopen(filename, "rb")) == NULL)
	{
	error = 2;
	goto Cleanup;
	} // if

if (fread(data, 1, 4, input) != 4)
	{
	error = 6;	// read error
	goto Cleanup;
	} // if

if ((strncmp(data, "DSAA", 4) != 0) && (strncmp(data, "DSBB", 4) != 0) && (strncmp(data, "DSRB", 4) != 0))
	{
	error = 6;	// read error
	goto Cleanup;
	} // if

if (data[2] == 'A')			// Version 5 & prior
	Importing->Flags = IMWIZ_SURFER_ASCII;
else if (data[2] == 'B')	// Version 6
	Importing->Flags = IMWIZ_SURFER_BINARY;
else						// Version 7 & later
	Importing->Flags = IMWIZ_SURFER_TAGGED;

switch (Importing->Flags)
	{
	default:
	case IMWIZ_SURFER_ASCII:	// Version 5 & prior
		Importing->ValueFmt = DEM_DATA_FORMAT_FLOAT;
		Importing->ValueBytes = 4;
		break;
	case IMWIZ_SURFER_BINARY:	// Version 6
		Importing->ValueFmt = DEM_DATA_FORMAT_FLOAT;
		Importing->ValueBytes = 4;
		if ((fread(&nx, 2, 1, input) != 1) || (fread(&ny, 2, 1, input) != 1))
			{
			error = 6;	// read error
			goto Cleanup;
			} // if
		Importing->InCols = nx;
		Importing->InRows = ny;
		if ((fread(&dlo, 8, 1, input) != 1) || (fread(&dhi, 8, 1, input) != 1))
			{
			error = 6;	// read error
			goto Cleanup;
			} // if
		Importing->West = dlo;
		Importing->East = dhi;
		if ((fread(&dlo, 8, 1, input) != 1) || (fread(&dhi, 8, 1, input) != 1))
			{
			error = 6;	// read error
			goto Cleanup;
			} // if
		Importing->South = dlo;
		Importing->North = dhi;
		if ((fread(&dlo, 8, 1, input) != 1) || (fread(&dhi, 8, 1, input) != 1))
			{
			error = 6;	// read error
			goto Cleanup;
			} // if
		Importing->TestMin = dlo;
		Importing->TestMax = dhi;
		fpos = ftell(input);
		Importing->HdrSize = fpos;
		Importing->Flags = IMWIZ_SURFER_BINARY;
		Importing->HasNulls = TRUE;
		Importing->NullVal = 1.7014100091878e+038;	// near FLT_MAX, but not quite - don't know where they get this from
		Importing->UseCeiling = TRUE;
		Importing->Ceiling = 1.7014100091878e+038;	// can't get accurate enough NULL value
		if (Importing->InRows != 1)
			Importing->GridSpaceNS = (Importing->North - Importing->South) / (Importing->InRows - 1);
		if (Importing->InCols != 1)
			Importing->GridSpaceWE = fabs((Importing->East - Importing->West) / (Importing->InCols - 1));
		break;
	case IMWIZ_SURFER_TAGGED:	// Version 7 & later
		error = 6;	// set read error return code in case any problems are encountered
		Importing->ValueFmt = DEM_DATA_FORMAT_FLOAT;
		Importing->ValueBytes = 8;
		if (fread(&tagsize, 4, 1, input) != 1)
			goto Cleanup;
		fpos = ftell(input);
		if (fread(&longval, 4, 1, input) != 1)	// get version number
			goto Cleanup;
		fseek(input, fpos + tagsize, SEEK_SET);
		if (fread(&tagid, 4, 1, input) != 1)
			goto Cleanup;
		while ((tagid != 0x44495247) && !feof(input))	// "GRID"
			{
			if (fread(&tagsize, 4, 1, input) != 1)
				goto Cleanup;
			fpos = ftell(input);
			fseek(input, fpos + tagsize, SEEK_SET);
			} // while
		if (tagid == 0x44495247)	// "GRID"
			{
			if (fread(&tagsize, 4, 1, input) != 1)
				goto Cleanup;
			fpos = ftell(input);
			if (fread(&longval, 4, 1, input) != 1)	// nRow
				goto Cleanup;
			Importing->InRows = longval;
			if (fread(&longval, 4, 1, input) != 1)	// nCol
				goto Cleanup;
			Importing->InCols = longval;
			if (fread(&dblval, 8, 1, input) != 1)	// xLL
				goto Cleanup;
			Importing->West = dblval;
			if (fread(&dblval, 8, 1, input) != 1)	// yLL
				goto Cleanup;
			Importing->South = dblval;
			if (fread(&dblval, 8, 1, input) != 1)	// xSize
				goto Cleanup;
			Importing->GridSpaceWE = dblval;
			if (fread(&dblval, 8, 1, input) != 1)	// ySize
				goto Cleanup;
			Importing->GridSpaceNS = dblval;
			if (fread(&dblval, 8, 1, input) != 1)	// zMin
				goto Cleanup;
			Importing->TestMin = dblval;
			if (fread(&dblval, 8, 1, input) != 1)	// zMax
				goto Cleanup;
			Importing->TestMax = dblval;
			if (fread(&dblval, 8, 1, input) != 1)	// Rotation
				goto Cleanup;
			// rotation value not currently used in Surfer, probably wouldn't be supported by us anyways
			if (fread(&dblval, 8, 1, input) != 1)	// BlankValue
				goto Cleanup;
			error = 0;	// clear error flag
			Importing->HasNulls = TRUE;
			Importing->AskNull = TRUE;
			Importing->NullVal = dblval;
			} // if GRID
		break;
	} // switch

Importing->AllowPosE = TRUE;
Importing->NullMethod = IMWIZ_NULL_GE;

Importing->SBound = Importing->South;
Importing->NBound = Importing->SBound + Importing->GridSpaceNS * (Importing->InRows - 1);
Importing->WBound = Importing->West;
Importing->EBound = Importing->WBound + Importing->GridSpaceWE * (Importing->InCols - 1);

if (TestOnly)
	{
	sprintf(Importing->FileInfo, "\r\r\n\r\r\nX range: %.1f  -  %.1f\r\r\nY range: %.1f  -  %.1f\r\r\nZ range: %.1f  -  %.1f",
		Importing->WBound, Importing->EBound, Importing->NBound, Importing->SBound, Importing->TestMin, Importing->TestMax);
	return 0;
	} // if

switch (Importing->Flags)
	{
	default:
	case IMWIZ_SURFER_ASCII:	// Version 5 & prior
		break;
	case IMWIZ_SURFER_BINARY:	// Version 6
		break;
	case IMWIZ_SURFER_TAGGED:	// Version 7 & higher
		if (fread(&tagid, 4, 1, input) != 1)
			{
			error = 6;	// read error
			goto Cleanup;
			} // if
		if (fread(&tagsize, 4, 1, input) != 1)
			{
			error = 6;	// read error
			goto Cleanup;
			} // if
		fpos = ftell(input);
		switch (tagid)
			{
			default:
				break;
			case 0x41544144:	// "DATA"
				Importing->HdrSize = ftell(input);
				LoadBinary(filename, (unsigned char *)Output, TestOnly);
				break;
			} // switch
		fseek(input, fpos + tagsize, SEEK_SET);
		break;
	} // switch

Cleanup:
if (input)
	fclose(input);

return error;

} // ImportWizGUI::LoadSurfer
Beispiel #13
0
/*
====================
idMD5Anim::LoadAnim
====================
*/
bool idMD5Anim::LoadAnim( const char* filename )
{

	idLexer	parser( LEXFL_ALLOWPATHNAMES | LEXFL_NOSTRINGESCAPECHARS | LEXFL_NOSTRINGCONCAT );
	idToken	token;
	
	idStr generatedFileName = "generated/anim/";
	generatedFileName.AppendPath( filename );
	generatedFileName.SetFileExtension( ".bMD5anim" );
	
	// Get the timestamp on the original file, if it's newer than what is stored in binary model, regenerate it
	ID_TIME_T sourceTimeStamp = fileSystem->GetTimestamp( filename );
	
	idFileLocal file( fileSystem->OpenFileReadMemory( generatedFileName ) );
	if( binaryLoadAnim.GetBool() && LoadBinary( file, sourceTimeStamp ) )
	{
		name = filename;
		if( cvarSystem->GetCVarBool( "fs_buildresources" ) )
		{
			// for resource gathering write this anim to the preload file for this map
			fileSystem->AddAnimPreload( name );
		}
		return true;
	}
	
	if( !parser.LoadFile( filename ) )
	{
		return false;
	}
	
	name = filename;
	
	Free();
	
	parser.ExpectTokenString( MD5_VERSION_STRING );
	int version = parser.ParseInt();
	if( version != MD5_VERSION )
	{
		parser.Error( "Invalid version %d.  Should be version %d\n", version, MD5_VERSION );
	}
	
	// skip the commandline
	parser.ExpectTokenString( "commandline" );
	parser.ReadToken( &token );
	
	// parse num frames
	parser.ExpectTokenString( "numFrames" );
	numFrames = parser.ParseInt();
	if( numFrames <= 0 )
	{
		parser.Error( "Invalid number of frames: %d", numFrames );
	}
	
	// parse num joints
	parser.ExpectTokenString( "numJoints" );
	numJoints = parser.ParseInt();
	if( numJoints <= 0 )
	{
		parser.Error( "Invalid number of joints: %d", numJoints );
	}
	
	// parse frame rate
	parser.ExpectTokenString( "frameRate" );
	frameRate = parser.ParseInt();
	if( frameRate < 0 )
	{
		parser.Error( "Invalid frame rate: %d", frameRate );
	}
	
	// parse number of animated components
	parser.ExpectTokenString( "numAnimatedComponents" );
	numAnimatedComponents = parser.ParseInt();
	if( ( numAnimatedComponents < 0 ) || ( numAnimatedComponents > numJoints * 6 ) )
	{
		parser.Error( "Invalid number of animated components: %d", numAnimatedComponents );
	}
	
	// parse the hierarchy
	jointInfo.SetGranularity( 1 );
	jointInfo.SetNum( numJoints );
	parser.ExpectTokenString( "hierarchy" );
	parser.ExpectTokenString( "{" );
	for( int i = 0; i < numJoints; i++ )
	{
		parser.ReadToken( &token );
		jointInfo[ i ].nameIndex = animationLib.JointIndex( token );
		
		// parse parent num
		jointInfo[ i ].parentNum = parser.ParseInt();
		if( jointInfo[ i ].parentNum >= i )
		{
			parser.Error( "Invalid parent num: %d", jointInfo[ i ].parentNum );
		}
		
		if( ( i != 0 ) && ( jointInfo[ i ].parentNum < 0 ) )
		{
			parser.Error( "Animations may have only one root joint" );
		}
		
		// parse anim bits
		jointInfo[ i ].animBits = parser.ParseInt();
		if( jointInfo[ i ].animBits & ~63 )
		{
			parser.Error( "Invalid anim bits: %d", jointInfo[ i ].animBits );
		}
		
		// parse first component
		jointInfo[ i ].firstComponent = parser.ParseInt();
		if( ( numAnimatedComponents > 0 ) && ( ( jointInfo[ i ].firstComponent < 0 ) || ( jointInfo[ i ].firstComponent >= numAnimatedComponents ) ) )
		{
			parser.Error( "Invalid first component: %d", jointInfo[ i ].firstComponent );
		}
	}
	
	parser.ExpectTokenString( "}" );
	
	// parse bounds
	parser.ExpectTokenString( "bounds" );
	parser.ExpectTokenString( "{" );
	bounds.SetGranularity( 1 );
	bounds.SetNum( numFrames );
	for( int i = 0; i < numFrames; i++ )
	{
		parser.Parse1DMatrix( 3, bounds[ i ][ 0 ].ToFloatPtr() );
		parser.Parse1DMatrix( 3, bounds[ i ][ 1 ].ToFloatPtr() );
	}
	parser.ExpectTokenString( "}" );
	
	// parse base frame
	baseFrame.SetGranularity( 1 );
	baseFrame.SetNum( numJoints );
	parser.ExpectTokenString( "baseframe" );
	parser.ExpectTokenString( "{" );
	for( int i = 0; i < numJoints; i++ )
	{
		idCQuat q;
		parser.Parse1DMatrix( 3, baseFrame[ i ].t.ToFloatPtr() );
		parser.Parse1DMatrix( 3, q.ToFloatPtr() );//baseFrame[ i ].q.ToFloatPtr() );
		baseFrame[ i ].q = q.ToQuat();//.w = baseFrame[ i ].q.CalcW();
		baseFrame[ i ].w = 0.0f;
	}
	parser.ExpectTokenString( "}" );
	
	// parse frames
	componentFrames.SetGranularity( 1 );
	componentFrames.SetNum( numAnimatedComponents * numFrames + JOINT_FRAME_PAD );
	componentFrames[numAnimatedComponents * numFrames + JOINT_FRAME_PAD - 1] = 0.0f;
	
	float* componentPtr = componentFrames.Ptr();
	for( int i = 0; i < numFrames; i++ )
	{
		parser.ExpectTokenString( "frame" );
		int num = parser.ParseInt();
		if( num != i )
		{
			parser.Error( "Expected frame number %d", i );
		}
		parser.ExpectTokenString( "{" );
		
		for( int j = 0; j < numAnimatedComponents; j++, componentPtr++ )
		{
			*componentPtr = parser.ParseFloat();
		}
		
		parser.ExpectTokenString( "}" );
	}
	
	// get total move delta
	if( !numAnimatedComponents )
	{
		totaldelta.Zero();
	}
	else
	{
		componentPtr = &componentFrames[ jointInfo[ 0 ].firstComponent ];
		if( jointInfo[ 0 ].animBits & ANIM_TX )
		{
			for( int i = 0; i < numFrames; i++ )
			{
				componentPtr[ numAnimatedComponents * i ] -= baseFrame[ 0 ].t.x;
			}
			totaldelta.x = componentPtr[ numAnimatedComponents * ( numFrames - 1 ) ];
			componentPtr++;
		}
		else
		{
			totaldelta.x = 0.0f;
		}
		if( jointInfo[ 0 ].animBits & ANIM_TY )
		{
			for( int i = 0; i < numFrames; i++ )
			{
				componentPtr[ numAnimatedComponents * i ] -= baseFrame[ 0 ].t.y;
			}
			totaldelta.y = componentPtr[ numAnimatedComponents * ( numFrames - 1 ) ];
			componentPtr++;
		}
		else
		{
			totaldelta.y = 0.0f;
		}
		if( jointInfo[ 0 ].animBits & ANIM_TZ )
		{
			for( int i = 0; i < numFrames; i++ )
			{
				componentPtr[ numAnimatedComponents * i ] -= baseFrame[ 0 ].t.z;
			}
			totaldelta.z = componentPtr[ numAnimatedComponents * ( numFrames - 1 ) ];
		}
		else
		{
			totaldelta.z = 0.0f;
		}
	}
	baseFrame[ 0 ].t.Zero();
	
	// we don't count last frame because it would cause a 1 frame pause at the end
	animLength = ( ( numFrames - 1 ) * 1000 + frameRate - 1 ) / frameRate;
	
	if( binaryLoadAnim.GetBool() )
	{
		idLib::Printf( "Writing %s\n", generatedFileName.c_str() );
		idFileLocal outputFile( fileSystem->OpenFileWrite( generatedFileName, "fs_basepath" ) );
		WriteBinary( outputFile, sourceTimeStamp );
	}
	
	// done
	return true;
}
Beispiel #14
0
void BaseMesh::CreateTeapot(float radius)
{
    LoadBinary("C:\\Data\\Teapot.obj");        //load the teapot from a standard file.  Will do nothing if the file doesn't exist.
    Stretch(radius);                        //stretch to the requested size
}
Beispiel #15
0
static void read_program_from_file(char * filename)
{
  OpenProgramBinaryFromFile(filename, &binary_length, &binary);
  LoadBinary(binary_length, binary);    
}