コード例 #1
0
ファイル: SysJobWorker.cpp プロジェクト: Dezzles/Psybrus
//////////////////////////////////////////////////////////////////////////
// execute
//virtual
void SysJobWorker::execute()
{
	// Enter loop.
	while( Active_ )
	{
		PSY_PROFILER_SECTION( SysJobWorker_BeginWait_Profile, "SysJobWorker_BeginWait" );

		// Wait till we are told to resume.
		{
			std::unique_lock< std::mutex > ResumeLock( ResumeMutex_ );
			ResumeEvent_.wait( ResumeLock, [ this ]{ return pCurrentJob_ != NULL; } );
		}

		PSY_PROFILER_SECTION( SysJobWorker_EndWait_Profile, "SysJobWorker_EndWait" );

		if( Active_ == BcTrue )
		{
			BcAssertMsg( pCurrentJob_ != NULL, "No job has been given!" );
		}

		BcAssertMsg( HaveJob_ == BcTrue, "SysJobWorker: We have a job pointer set, but haven't got it via giveJob." );

		// Start timing the job.
#if !PSY_PRODUCTION
		BcTimer Timer;
		Timer.mark();
#endif
		// Execute our job.
		pCurrentJob_->internalExecute();

#if !PSY_PRODUCTION
		// Add time spent to our total.
		const BcU32 TimeWorkingUS = static_cast< BcU32 >( Timer.time() * 1000000.0f );;
		TimeWorkingUS_ += TimeWorkingUS;
		JobsExecuted_++;
#endif			
		// No job now, clean up.
		delete pCurrentJob_;
		pCurrentJob_ = NULL;
		HaveJob_ = BcFalse;
			
		// Signal job queue parent to schedule.
		pParent_->schedule();
	}
}
コード例 #2
0
ファイル: CsPackageImporter.cpp プロジェクト: Psybrus/Psybrus
//////////////////////////////////////////////////////////////////////////
// import
BcBool CsPackageImporter::import( const BcName& Name )
{
	Name_ = Name;
	BcPath Path = CsCore::pImpl()->getPackageImportPath( Name );
	PSY_LOGSCOPEDCATEGORY( "Import" );
	PSY_LOG( "Importing %s...\n", (*Path).c_str() );

	PSY_LOGSCOPEDINDENT;

	BcTimer TotalTimer;
	TotalTimer.mark();

	// Store source file info.
	FsStats Stats;
	if( FsCore::pImpl()->fileStats( (*Path).c_str(), Stats ) )
	{
		Header_.SourceFileStatsHash_ = BcHash( reinterpret_cast< BcU8* >( &Stats ), sizeof( Stats ) );
	}
	else
	{
		Header_.SourceFileStatsHash_ = 0;
	}

	beginImport();
	Header_.SourceFile_ = addString( (*Path).c_str() );
	endImport();

	Json::Value Root;
	if( loadJsonFile( (*Path).c_str(), Root ) )
	{
		// Add as dependency.
		beginImport();
		addDependency( (*Path).c_str() );

		// Get resource list.
		Json::Value Resources( Root.get( "resources", Json::Value( Json::arrayValue ) ) );

		// Add all package cross refs.
		addAllPackageCrossRefs( Resources );

		// Set resource id to zero.
		ResourceIds_.store( 0 );

		// Import everything.
		for( const auto& ResourceObject : Resources )
		{
			addImport( ResourceObject, BcFalse );
		}
		endImport();

		// Sort importers.
		std::sort( Resources_.begin(), Resources_.end() );

		// Iterate over all resources and import (import calls can append to the list)
		size_t CurrResourceIdx = 0;
		while( CurrResourceIdx < Resources_.size() )
		{
			// Grab first resource in the list.
			auto ResourceEntry = std::move( Resources_[ CurrResourceIdx++ ] );
			
			// Import resource.
			BcTimer ResourceTimer;
			ResourceTimer.mark();
			try
			{
				PSY_LOGSCOPEDINDENT;
				beginImport();

				if( importResource( 
					std::move( ResourceEntry.Importer_ ), 
					ResourceEntry.Resource_ ) )
				{
					PSY_LOG( "SUCCEEDED: Time: %.2f seconds.\n", ResourceTimer.time() );
				}
				else
				{
					PSY_LOG( "FAILED: Time: %.2f seconds.\n", ResourceTimer.time() );
 					BcBreakpoint;
					endImport();
					return BcFalse;
				}

				endImport();
			}
			catch( CsImportException ImportException )
			{
				PSY_LOG( "FAILED: Time: %.2f seconds.\n", ResourceTimer.time() );
				PSY_LOG( "ERROR: in file %s:\n%s\n", ImportException.file().c_str(), ImportException.what() );	
				endImport();
				return BcFalse;
			}
		}

		// Save and return.
		BcPath PackedPackage( CsCore::pImpl()->getPackagePackedPath( Name ) );
		BcBool SaveSuccess = save( PackedPackage );

		if( SaveSuccess )
		{
			PSY_LOG( "SUCCEEDED: Time: %.2f seconds.\n", TotalTimer.time() );

			// Write out dependencies.
			std::string OutputDependencies = *CsCore::pImpl()->getPackageIntermediatePath( Name ) + "/deps.json";
			CsSerialiserPackageObjectCodec ObjectCodec( nullptr, (BcU32)bcRFF_ALL, (BcU32)bcRFF_TRANSIENT, 0 );
			SeJsonWriter Writer( &ObjectCodec );
			Writer << Dependencies_;
			Writer.save( OutputDependencies.c_str() );
		}
		else
		{
			PSY_LOG( "FAILED: Time: %.2f seconds.\n", TotalTimer.time() );
			BcBreakpoint;
		}

		return SaveSuccess;
	}
	
	return BcFalse;
}