コード例 #1
0
ファイル: CsCore.cpp プロジェクト: Dezzles/Psybrus
//////////////////////////////////////////////////////////////////////////
// allocResource
CsResource* CsCore::allocResource( const BcName& Name, const ReClass* Class, BcU32 Index, CsPackage* pPackage )
{
	std::lock_guard< std::recursive_mutex > Lock( ContainerLock_ );

	CsResource* pResource = NULL;
	void* pResourceBuffer = BcMemAlign( Class->getSize() );
	pResource = Class->construct< CsResource >( pResourceBuffer );
	pResource->preInitialise( Name, Index, pPackage );
	
	return pResource;
}
コード例 #2
0
ファイル: CsPackageLoader.cpp プロジェクト: wdmchaft/Psybrus
//////////////////////////////////////////////////////////////////////////
// onHeaderLoaded
void CsPackageLoader::onHeaderLoaded( void* pData, BcSize Size )
{
	// Check we have the right data.
	BcAssert( pData == &Header_ );
	BcAssert( Size == sizeof( Header_ ) );

	// Check the header is valid.
	if( Header_.Magic_ != CsPackageHeader::MAGIC )
	{
		BcPrintf( "CsPackageLoader: Invalid magic number. Not a valid package.\n" );
		HasError_ = BcTrue;
		--PendingCallbackCount_;
		return;
	}

	// Check version number.
	if( Header_.Version_ != CsPackageHeader::VERSION )
	{
		BcPrintf( "CsPackageLoader: Out of date package. Requires reimport.\n" );
		HasError_ = BcTrue;
		--PendingCallbackCount_;
		return;
	}

#if PSY_SERVER
	// Reimport if source file stats changed.
	const BcPath ImportPackage( CsCore::pImpl()->getPackageImportPath( pPackage_->getName() ) );

	FsStats Stats;
	if( FsCore::pImpl()->fileStats( (*ImportPackage).c_str(), Stats ) )
	{
		if( Header_.SourceFileStatsHash_ != BcHash( reinterpret_cast< BcU8* >( &Stats ), sizeof( Stats ) ))
		{
			BcPrintf( "CsPackageLoader: Source file stats have changed.\n" );
			HasError_ = BcTrue;
			--PendingCallbackCount_;
			return;
		}
	}
#endif

	// Allocate all the memory we need up front.
	pPackageData_ = BcMemAlign( Header_.TotalAllocSize_, Header_.MaxAlignment_ );

	// Use this to advance as we need.
	BcU8* pCurrPackageData = reinterpret_cast< BcU8* >( pPackageData_ );
	
	// Loaded header, now markup the string table, chunks & props.
	pStringTable_ = reinterpret_cast< BcChar* >( pCurrPackageData );
	pCurrPackageData += BcCalcAlignment( Header_.StringTableBytes_, Header_.MinAlignment_ );

	pResourceHeaders_ = reinterpret_cast< CsPackageResourceHeader* >( pCurrPackageData );
	pCurrPackageData += BcCalcAlignment( Header_.TotalResources_ * sizeof( CsPackageResourceHeader ), Header_.MinAlignment_ );

	pChunkHeaders_ = reinterpret_cast< CsPackageChunkHeader* >( pCurrPackageData );
	pCurrPackageData += BcCalcAlignment( Header_.TotalChunks_ * sizeof( CsPackageChunkHeader ), Header_.MinAlignment_ );

	pChunkData_ = reinterpret_cast< CsPackageChunkData* >( pCurrPackageData );
	pCurrPackageData += BcCalcAlignment( Header_.TotalChunks_ * sizeof( CsPackageChunkData ), Header_.MinAlignment_ );

	// Clear string table.
	BcMemZero( pStringTable_, Header_.StringTableBytes_ );
	
	// Clear chunk data.
	for( BcU32 Idx = 0; Idx < Header_.TotalChunks_; ++Idx )
	{
		pChunkData_[ Idx ].Status_ = csPCS_NOT_LOADED;	
		pChunkData_[ Idx ].Managed_ = BcFalse;
		pChunkData_[ Idx ].pPackedData_ = NULL;
		pChunkData_[ Idx ].pUnpackedData_ = NULL;
	}

	// Setup file position data.
	BcU32 Bytes = 0;
	
	// Load the string table in.
	++PendingCallbackCount_;
	Bytes = Header_.StringTableBytes_;
	File_.readAsync( DataPosition_, pStringTable_, Bytes, FsFileOpDelegate::bind< CsPackageLoader, &CsPackageLoader::onStringTableLoaded >( this ) );
	DataPosition_ += Bytes;
	
	// Load Resources in.
	++PendingCallbackCount_;
	Bytes = Header_.TotalResources_ * sizeof( CsPackageResourceHeader );
	File_.readAsync( DataPosition_, pResourceHeaders_, Bytes, FsFileOpDelegate::bind< CsPackageLoader, &CsPackageLoader::onResourceHeadersLoaded >( this ) );
	DataPosition_ += Bytes;

	// Load chunks in.
	++PendingCallbackCount_;
	Bytes = Header_.TotalChunks_ * sizeof( CsPackageChunkHeader );
	File_.readAsync( DataPosition_, pChunkHeaders_, Bytes, FsFileOpDelegate::bind< CsPackageLoader, &CsPackageLoader::onChunkHeadersLoaded >( this ) );
	DataPosition_ += Bytes;

	// This callback is complete.
	--PendingCallbackCount_;
}