Esempio n. 1
0
static asset_ptr openAsset(
    AAssetManager *manager,
    const std::string& fileName,
    int mode = AASSET_MODE_STREAMING) {
  return asset_ptr(
    AAssetManager_open(manager, fileName.c_str(), mode),
    AAsset_close);
}
Esempio n. 2
0
bool LocalAssetProvider::RequestAsset(const std::string& asset_id, const std::string& asset_type, request_tag_t tag)
{
    if (!IsValidId(asset_id, asset_type))
        return false;
    
    Foundation::ServiceManagerPtr service_manager = framework_->GetServiceManager();
    boost::shared_ptr<Foundation::AssetServiceInterface> asset_service =
        service_manager->GetService<Foundation::AssetServiceInterface>(Foundation::Service::ST_Asset).lock();
    if (!asset_service)
        return false;
    
    AssetModule::LogDebug("New local asset request: " + asset_id);
    
    // Strip file:
    std::string filepath = asset_dir_ + asset_id.substr(7);
    
    boost::filesystem::path file_path(filepath);
    std::ifstream filestr(file_path.native_directory_string().c_str(), std::ios::in | std::ios::binary);
    if (filestr.good())
    {
        filestr.seekg(0, std::ios::end);
        uint length = filestr.tellg();
        filestr.seekg(0, std::ios::beg);
        
        if (length > 0)
        {
            RexAsset* new_asset = new RexAsset(asset_id, asset_type);
            Foundation::AssetPtr asset_ptr(new_asset);
            
            RexAsset::AssetDataVector& data = new_asset->GetDataInternal();
            data.resize(length);
            filestr.read((char *)&data[0], length);
            filestr.close();
            
            // Store to cache
            asset_service->StoreAsset(asset_ptr);
            // Send asset_ready event as delayed
            Events::AssetReady* event_data = new Events::AssetReady(asset_ptr->GetId(), asset_ptr->GetType(), asset_ptr, tag);
            framework_->GetEventManager()->SendDelayedEvent(event_category_, Events::ASSET_READY, Foundation::EventDataPtr(event_data));
            
            return true;
        }
        else
            filestr.close();
    }
    
    AssetModule::LogInfo("Failed to load local asset " + asset_id.substr(7));
    return false;
}
Esempio n. 3
0
Foundation::AssetPtr UDPAssetProvider::GetIncompleteAsset(const std::string& asset_id, const std::string& asset_type, uint received)
{
    UDPAssetTransfer* transfer = GetTransfer(asset_id);

    if ((transfer) && (transfer->GetReceivedContinuous() >= received))
    {
        // Make new temporary asset for the incomplete data
        RexAsset* new_asset = new RexAsset(transfer->GetAssetId(), GetTypeNameFromAssetType(transfer->GetAssetType()));
        Foundation::AssetPtr asset_ptr(new_asset);

        RexAsset::AssetDataVector& data = new_asset->GetDataInternal();
        data.resize(transfer->GetReceivedContinuous());
        transfer->AssembleData(&data[0]);

        return asset_ptr;
    }

    return Foundation::AssetPtr();
}