Started asset refact
This commit is contained in:
79
archive/asset/assetmanager.h
Normal file
79
archive/asset/assetmanager.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "asset.h"
|
||||
|
||||
#define ASSET_MANAGER_ASSET_COUNT_MAX 32
|
||||
|
||||
#if ASSET_TYPE == wad
|
||||
#else
|
||||
#error "Unsupported ASSET_TYPE"
|
||||
#endif
|
||||
|
||||
static const char_t ASSET_MANAGER_SEARCH_PATHS[][FILENAME_MAX] = {
|
||||
"%s/%s",
|
||||
"%s",
|
||||
"../%s",
|
||||
"../../%s",
|
||||
"data/%s",
|
||||
"../data/%s",
|
||||
};
|
||||
|
||||
#define ASSET_MANAGER_SEARCH_PATHS_COUNT (\
|
||||
sizeof(ASSET_MANAGER_SEARCH_PATHS) / FILENAME_MAX\
|
||||
)
|
||||
|
||||
typedef struct {
|
||||
zip_t *zip;
|
||||
asset_t assets[ASSET_MANAGER_ASSET_COUNT_MAX];
|
||||
char_t systemPath[FILENAME_MAX];
|
||||
uint8_t assetCount;
|
||||
} assetmanager_t;
|
||||
|
||||
extern assetmanager_t ASSET_MANAGER;
|
||||
|
||||
/**
|
||||
* Initializes the asset system.
|
||||
*/
|
||||
errorret_t assetManagerInit(void);
|
||||
|
||||
/**
|
||||
* Update the asset manager. This should be called once per frame.
|
||||
*/
|
||||
void assetManagerUpdate(void);
|
||||
|
||||
/**
|
||||
* Get an asset by filename. This will return NULL if the asset does not exist.
|
||||
* This will not lock the asset, you must do that separately. If you do not
|
||||
* lock the asset there is no guarantee the asset pointer will remain valid.
|
||||
*
|
||||
* @param filename The filename of the asset to get.
|
||||
* @param outAsset The output asset pointer.
|
||||
* @return An error code.
|
||||
*/
|
||||
errorret_t assetManagerGetAsset(const char_t *filename, asset_t **outAsset);
|
||||
|
||||
/**
|
||||
* Gets, locks and loads an asset. This is all blocking so only use if you
|
||||
* really need to.
|
||||
*
|
||||
* @param filename The filename of the asset to get.
|
||||
* @param outAsset The output asset pointer.
|
||||
* @param outRef The output asset reference pointer.
|
||||
* @return An error code if something goes wrong.
|
||||
*/
|
||||
errorret_t assetManagerLoadAsset(
|
||||
const char_t *filename,
|
||||
asset_t **outAsset,
|
||||
ref_t *outRef
|
||||
);
|
||||
|
||||
/**
|
||||
* Disposes/cleans up the asset system.
|
||||
*/
|
||||
void assetManagerDispose(void);
|
||||
Reference in New Issue
Block a user