コード例 #1
0
ファイル: Persist.cpp プロジェクト: victimofleisure/ChordEase
BOOL CPersist::WriteFont(LPCTSTR Section, LPCTSTR Entry, CFont *Font)
{
	LOGFONT	lf;
	DWORD	Size = (Font != NULL && Font->GetSafeHandle() 
		&& Font->GetLogFont(&lf) ? sizeof(LOGFONT) : 0);
	return(WriteBinary(Section, Entry, &lf, Size));
}
コード例 #2
0
ファイル: Settings.cpp プロジェクト: Mateuus/devsrc
void Settings::SaveBinary( LPCTSTR lpctszSection_i, 
                           LPCTSTR lpctszEntry_i, 
                           int* pColumnOrder_i, 
                           const unsigned int uCount_i )
{
    WriteBinary( lpctszSection_i, 
                 lpctszEntry_i, 
                 RCAST( LPBYTE, pColumnOrder_i ), 
                 uCount_i * sizeof( int ));
}
コード例 #3
0
ファイル: LogSegment.cpp プロジェクト: returnString/kyf
bool LogSegment::WriteMessage(offset_t offset, uint8_t* key, uint32_t keyLen, uint8_t* value, uint32_t valueLen)
{
	size_t messageLen = sizeof(offset_t)
		+ (sizeof(uint32_t) * 3) // message length, key length, value length
		+ keyLen
		+ valueLen;

	assert(messageLen < UINT32_MAX);

	if ((m_writePos + messageLen) >= m_file.size)
	{
		return false;
	}

	WriteData(offset);
	WriteData((uint32_t)messageLen);
	WriteBinary(key, keyLen);
	WriteBinary(value, valueLen);
	return true;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: brycekelleher/bsp
// BuildTreeFromMapPolys
static void ProcessModel()
{
	bsptree_t *tree;
	
	Message("Processing model...\n");

	tree = BuildTree();
	
	MarkEmptyLeafs(tree);

	BuildPortals(tree);

	BuildAreas(tree);
#if 1
	extern void BuildAreaModels(bsptree_t *tree);
	BuildAreaModels(tree);
#endif

	WriteBinary(tree);
}
コード例 #5
0
void Labeler::writeModelFile(const string & outputModelFile) {
  std::cout << "Start write model to file: " << outputModelFile << std::endl;
  LStream outf(outputModelFile, "w+");
  m_options.writeModel(outf);
  m_wordAlphabet.writeModel(outf);
  m_charAlphabet.writeModel(outf);
  m_labelAlphabet.writeModel(outf);
  m_featAlphabet.writeModel(outf);
  m_classifier.writeModel(outf);

  int m_tagAlphabets_size = m_tagAlphabets.size();
  WriteBinary(outf, m_tagAlphabets_size);
  for (int idx = 0; idx < m_tagAlphabets_size; idx++) {
    m_tagAlphabets[idx].writeModel(outf);
  }

  WriteString(outf, nullkey);
  WriteString(outf, unknownkey);
  WriteString(outf, seperateKey);
  std::cout << "Model has been written in file: " << outputModelFile << std::endl;
}
コード例 #6
0
void ConfigManager::WriteBinary(const wxString& name,  void* ptr, size_t len)
{
    wxString s((wxChar*)ptr, len);
    WriteBinary(name,  s);
}
コード例 #7
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;
}
コード例 #8
0
ファイル: Persist.cpp プロジェクト: victimofleisure/ChordEase
BOOL CPersist::WriteWndPlacement(LPCTSTR Section, LPCTSTR Name, const WINDOWPLACEMENT& wp)
{
	return(WriteBinary(Section, CString(Name) + WND_PLACE, &wp, sizeof(WINDOWPLACEMENT)));
}
コード例 #9
0
ファイル: Persist.cpp プロジェクト: victimofleisure/ChordEase
BOOL CPersist::WriteDouble(LPCTSTR Section, LPCTSTR Entry, double Value)
{
	return(WriteBinary(Section, Entry, &Value, sizeof(double)));
}
コード例 #10
0
ファイル: Persist.cpp プロジェクト: victimofleisure/ChordEase
BOOL CPersist::WriteFloat(LPCTSTR Section, LPCTSTR Entry, float Value)
{
	return(WriteBinary(Section, Entry, &Value, sizeof(float)));
}
コード例 #11
0
ファイル: Anim.cpp プロジェクト: Yetta1/OpenTechBFG
/*
====================
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;
}