carb/assets/IAssets.h

File members: carb/assets/IAssets.h

// Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//

#pragma once

#include "../Interface.h"
#include "../Types.h"
#include "../datasource/IDataSource.h"
#include "../tasking/TaskingHelpers.h"
#include "AssetsTypes.h"

namespace carb
{

namespace assets
{

struct IAssets
{
    CARB_PLUGIN_INTERFACE("carb::assets::IAssets", 2, 0)

    Pool(CARB_ABI* createPool)(const char* name);

    void(CARB_ABI* destroyPool)(Pool pool);

    void(CARB_ABI* poolStats)(Pool pool, int& totalAssets, int& assetsLoading);

    Id(CARB_ABI* internalLoadAsset)(carb::datasource::IDataSource* dataSource,
                                    carb::datasource::Connection* connection,
                                    const char* path,
                                    Pool pool,
                                    const Type& assetType,
                                    const LoadParameters* loadParameters,
                                    carb::tasking::Object const* trackers,
                                    size_t numTrackers);

    CARB_DEPRECATED("Use loadAsset<> instead.")
    Id loadAssetEx(carb::datasource::IDataSource* dataSource,
                   carb::datasource::Connection* connection,
                   const char* path,
                   Pool pool,
                   const Type& assetType,
                   const LoadParameters* loadParameters,
                   carb::tasking::Object const* trackers,
                   size_t numTrackers)
    {
        return internalLoadAsset(dataSource, connection, path, pool, assetType, loadParameters, trackers, numTrackers);
    }

    void(CARB_ABI* unloadAsset)(Id assetId);

    void(CARB_ABI* unloadAssets)(Pool pool);

    void(CARB_ABI* yieldForAsset)(Id assetId);

    void(CARB_ABI* yieldForAssets)(Pool pool);

    void(CARB_ABI* subscribeToChangeEvent)(Id assetId, OnChangeEventFn onChangeEvent, void* userData);

    void(CARB_ABI* unsubscribeToChangeEvent)(Id assetId);

    Snapshot(CARB_ABI* acquireSnapshot)(Id assetId, const Type& assetType, Reason& reason);

    void(CARB_ABI* releaseSnapshot)(Snapshot snapshot);

    void*(CARB_ABI* getDataFromSnapshot)(Snapshot snapshot);

    void(CARB_ABI* reloadAnyDirty)(Type assetType);

    void(CARB_ABI* registerAssetTypeEx)(const Type& assetType, const LoaderDesc& desc, const AssetTypeParams& params);

    void(CARB_ABI* unregisterAssetTypeEx)(const Type& assetType);

    template <typename Type>
    Id loadAsset(carb::datasource::IDataSource* dataSource,
                 carb::datasource::Connection* connection,
                 const char* path,
                 Pool pool,
                 carb::tasking::Trackers trackers = carb::tasking::Trackers{});

    template <typename Type>
    Id loadAsset(carb::datasource::IDataSource* dataSource,
                 carb::datasource::Connection* connection,
                 const char* path,
                 Pool pool,
                 const LoadParameters& loadParameters,
                 carb::tasking::Trackers trackers = carb::tasking::Trackers{});

    template <typename Type>
    ScopedSnapshot<Type> takeSnapshot(Id assetId);

    template <typename Type>
    void registerAssetType(const LoaderDesc& loaderDesc, const AssetTypeParams& params = AssetTypeParams::getDefault());

    template <typename Type>
    void unregisterAssetType();
};
} // namespace assets
} // namespace carb

#include "IAssets.inl"