Roughly planning asset locking
This commit is contained in:
34
src/asset/asset.h
Normal file
34
src/asset/asset.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "assetpaletteimage.h"
|
||||||
|
#include "util/reflist.h"
|
||||||
|
|
||||||
|
#define ASSET_HEADER_SIZE 3
|
||||||
|
#define ASSET_REFERENCE_COUNT_MAX 8
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ASSET_STATE_NOT_LOADED,
|
||||||
|
ASSET_STATE_LOADING,
|
||||||
|
ASSET_STATE_LOADED,
|
||||||
|
ASSET_STATE_ERROR,
|
||||||
|
} assetstate_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ASSET_TYPE_UNKNOWN,
|
||||||
|
ASSET_TYPE_PALETTE_IMAGE,
|
||||||
|
} assettype_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char_t filename[FILENAME_MAX];
|
||||||
|
ref_t refListArray[ASSET_REFERENCE_COUNT_MAX];
|
||||||
|
reflist_t refList;
|
||||||
|
assetstate_t state;
|
||||||
|
assettype_t type;
|
||||||
|
void *data;
|
||||||
|
} asset_t;
|
@@ -9,6 +9,9 @@
|
|||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include <zip.h>
|
#include <zip.h>
|
||||||
#include "display/texture/texture.h"
|
#include "display/texture/texture.h"
|
||||||
|
#include "asset.h"
|
||||||
|
|
||||||
|
#define ASSET_MANAGER_ASSET_COUNT_MAX 256
|
||||||
|
|
||||||
#if ASSET_TYPE == wad
|
#if ASSET_TYPE == wad
|
||||||
#else
|
#else
|
||||||
@@ -31,6 +34,8 @@ static const char_t ASSET_MANAGER_SEARCH_PATHS[][FILENAME_MAX] = {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t nothing;
|
int32_t nothing;
|
||||||
zip_t *zip;
|
zip_t *zip;
|
||||||
|
asset_t assets[ASSET_MANAGER_ASSET_COUNT_MAX];
|
||||||
|
uint8_t assetCount;
|
||||||
} assetmanager_t;
|
} assetmanager_t;
|
||||||
|
|
||||||
extern assetmanager_t ASSET_MANAGER;
|
extern assetmanager_t ASSET_MANAGER;
|
||||||
@@ -40,6 +45,24 @@ extern assetmanager_t ASSET_MANAGER;
|
|||||||
*/
|
*/
|
||||||
errorret_t assetManagerInit(void);
|
errorret_t assetManagerInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets and requests a lock on a given asset. Locking an asset will prevent it
|
||||||
|
* from being unloaded until it is unlocked.
|
||||||
|
*
|
||||||
|
* @param filename The filename of the asset to lock.
|
||||||
|
* @param outRef A pointer to store the locked reference ID in.
|
||||||
|
* @return A pointer to the locked asset, or NULL if the asset could not be
|
||||||
|
*/
|
||||||
|
asset_t * assetManagerLock(const char_t *filename, ref_t *outRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlocks a previously locked asset reference.
|
||||||
|
*
|
||||||
|
* @param asset The asset to unlock the reference from.
|
||||||
|
* @param ref The reference ID to unlock.
|
||||||
|
*/
|
||||||
|
void assetManagerUnlock(const ref_t ref);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes/cleans up the asset system.
|
* Disposes/cleans up the asset system.
|
||||||
*/
|
*/
|
||||||
|
17
src/asset/assetpaletteimage.h
Normal file
17
src/asset/assetpaletteimage.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dusk.h"
|
||||||
|
|
||||||
|
#define ASSET_PALETTE_IMAGE_SIZE_MAX (256*256)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t width;
|
||||||
|
uint32_t height;
|
||||||
|
uint8_t data[ASSET_PALETTE_IMAGE_SIZE_MAX];
|
||||||
|
} assetpaletteimage_t;
|
Reference in New Issue
Block a user