////////////////////////////////////////////////////////////////////////// // initialiseResources void CsPackageLoader::initialiseResources() { // Create all resources, and add them to the parent package. for( BcU32 ResourceIdx = 0; ResourceIdx < Header_.TotalResources_; ++ResourceIdx ) { CsPackageResourceHeader& ResourceHeader = pResourceHeaders_[ ResourceIdx ]; // Grab name and type. BcName Name( getString( ResourceHeader.Name_ ) ); BcName Type( getString( ResourceHeader.Type_ ) ); // Allocate resource, and signal ready. CsResourceRef<> Handle; if( CsCore::pImpl()->internalCreateResource( Name, Type, ResourceIdx, pPackage_, Handle ) ) { // Initialise. Handle->initialise(); // Add to package. pPackage_->addResource( Handle ); // Tell it the file is ready (TODO: DEPRECATE). Handle->fileReady(); } } }
////////////////////////////////////////////////////////////////////////// // internalRequestResource BcBool CsCore::internalRequestResource( const BcName& Name, const BcName& Type, CsResourceRef<>& Handle ) { #if PSY_SERVER // Attempt to import on request if need be. BcPath FileName = getResourceFullName( Name, Type ); if( shouldImportResource( FileName, BcFalse ) ) { if( internalImportResource( FileName, Handle, NULL, BcFalse ) ) { return Handle.isValid(); } } #endif // Try to find resource, if we can't, allocate a new one and put into create list. if( internalFindResource( Name, Type, Handle ) == BcFalse ) { // Only request if we have a name. if( Name.isValid() ) { // Create a file reader for resource (using full name!) CsFile* pFile = createFileReader( getResourceFullName( Name, Type ) ); // Allocate resource. Handle = allocResource( Name, Type, pFile ); if( Handle.isValid() ) { // Call default initialiser. Handle->initialise(); // Acquire (callback from load will release). Handle->acquire(); // Trigger a file load. if( pFile->load( CsFileReadyDelegate::bind< CsResource, &CsResource::delegateFileReady >( (CsResource*)Handle ), CsFileChunkDelegate::bind< CsResource, &CsResource::delegateFileChunkReady >( (CsResource*)Handle ) ) ) { // Put into create list. if( Handle.isValid() ) { BcScopedLock< BcMutex > Lock( ContainerLock_ ); CreateResources_.push_back( Handle ); } } else { BcPrintf( "CsCore::requestResource: Failed to load %s (%s).\n", (*Name).c_str(), pFile->getName().c_str() ); // Release (callback from load won't happen on failure). Handle->release(); Handle = NULL; } } else { BcPrintf( "CsCore::requestResource: Failed to create %s (%s).\n", (*Name).c_str(), pFile->getName().c_str() ); Handle = NULL; } } else { BcPrintf( "CsCore::requestResource: Resource name invalid.\n" ); Handle = NULL; } } return Handle.isValid(); }