/** * Copyright (c) 2021 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "../libs.h" #include "types/common.h" #include "loaders/font.h" #include "loaders/scaledtexture.h" #include "loaders/shader.h" #include "loaders/texture.h" #include "asset.h" // Constants extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[]; /** * Initialize the asset manager * * @param manager Manager to initialize. */ void assetManagerInit(assetmanager_t *manager); /** * Gets the progress of the asset manager as a representation of 0-1 as a % that * has loaded. * * @param manager Manager to check the state of. * @return The progress percent as a representation of 0-1 */ float assetManagerProgressGet(assetmanager_t *manager); /** * Gets the progress of the assets for only those held by a specific holder. * * @param manager Manager to get the progress from * @param hold Holder to get the items progress from. * @return The percentage (0-1) of the loaded assets. */ float assetManagerProgressGetForHolder( assetmanager_t *manager, assetmanagerowner_t hold ); /** * Creates a holder for a given asset manager. Asset holders are kept track of * so that those who requests assets are responsible for those who free them. It * also ensures only the assets that are actually necessary are kept loaded in * memory at all times. * * @param man Asset manager in question * @return An asset manager owner ID. */ assetmanagerowner_t assetManagerHolderCreate(assetmanager_t *man); /** * Release a previously reserved asset manager holder. This will (in turn) cause * all of the assets that manager was holding to also be released. * * @param man Asset manager holder to release for. * @param hold Holder to release. */ void assetManagerHolderRelease(assetmanager_t *man, assetmanagerowner_t hold); /** * Disposes all assets that are not currently held (released assets). This can * only happen from the main thread due to synchronous assets such as Textures. * * @param man Manager to dispose. */ void assetManagerDisposeReleased(assetmanager_t *man); /** * Completely dispose an asset manager. This will also completely dispose all * of the assets that this asset manager is holding. * * @param man Asset manager to dispose */ void assetManagerDispose(assetmanager_t *man); /** * Begin asynchronously loading all of the assets * * @param manager Manager to begin async loading. */ void assetManagerStart(assetmanager_t *manager); /** Private Thread that is executed asynchronously */ int32_t _assetManagerThread(thread_t *thread); /** * Synchronously tick the asset manager. Some assets require some form of sync * operations, such as buffering to the GPU, so make sure this is called at a * good time for that task, such as right at the end of a frame. * * @param manager Manager to synchronously tick. */ void assetManagerUpdate(assetmanager_t *manager);