47 lines
1.4 KiB
C
47 lines
1.4 KiB
C
#ifndef _fencer_assets_h
|
|
#define _fencer_assets_h
|
|
|
|
#include "vmath.h"
|
|
#include "asset.h"
|
|
#include <cjson/cJSON.h>
|
|
|
|
typedef void(*AssetDestructor)(void*);
|
|
|
|
// Prepare asset management.
|
|
// Other asset management functions are invalid until assets_init is called.
|
|
void assets_init();
|
|
// Clean up and shut down assets management.
|
|
void assets_clean();
|
|
// Clear all loaded assets
|
|
void assets_reset();
|
|
// Submit an object to be managed as an asset. If the destructor is NULL, free will be used.
|
|
// Returns zero if asset could not be stored.
|
|
asset_id store_asset(Asset drop);
|
|
// Get an asset already submitted to the asset manager.
|
|
// Returns 0 if asset does not exist.
|
|
void* get_asset(asset_id id);
|
|
// Get an asset id, returns 0 if no such asset exists.
|
|
asset_id get_asset_id(void* asset);
|
|
// Free an asset managed by the asset manager using it's destructor, or free(..) if NULL.
|
|
void free_asset(asset_id id);
|
|
// load a file's contents into json
|
|
cJSON* load_json_from_file(const char* filepath);
|
|
// Get the length of a cJSON array
|
|
size_t json_array_len(cJSON* array);
|
|
static inline
|
|
Vector json_array_to_vector(cJSON* array) {
|
|
return (Vector) {
|
|
cJSON_GetArrayItem(array, 0)->valuedouble,
|
|
cJSON_GetArrayItem(array, 1)->valuedouble,
|
|
};
|
|
}
|
|
static inline
|
|
IVector json_array_to_ivector(cJSON* array) {
|
|
return (IVector) {
|
|
cJSON_GetArrayItem(array, 0)->valueint,
|
|
cJSON_GetArrayItem(array, 1)->valueint
|
|
};
|
|
}
|
|
|
|
#endif // !_fencer_assets_h
|