Dawn/src/file/asset.h

88 lines
2.5 KiB
C

/**
* Copyright (c) 2021 Dominic Msters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "../display/font.h"
#if !defined(ASSET_PREFIX)
#error Asset Prefix has not been defined.
#endif
/** Definition of an asset ready to be buffered */
typedef FILE assetbuffer_t;
/**
* Buffer an asset from the file system into memory.
*
* @param assetName Path to the asset to buffer.
* @param buffer Place to buffer the data in to, or NULL to simply read the size
* @return The length (in bytes) of the file.
*/
size_t assetRawLoad(char *assetName, uint8_t *buffer);
/**
* Load a string from an asset into memory.
*
* @param assetName Asset to load
* @return A newly loaded string (malloced into existance.)
*/
char * assetStringLoad(char *assetName);
/**
* Platform-centric method to open a file buffer to an asset.
* @param assetName The asset name to open a buffer for.
* @return Pointer to a buffer, NULL if unsuccessfuil.
*/
assetbuffer_t * assetBufferOpen(char *assetName);
/**
* Closes a previously opened asset buffer.
* @param buffer Buffer to close.
* @return True if successful, otherwise false.
*/
bool assetBufferClose(assetbuffer_t *buffer);
/**
* Read bytes from buffer.
* @param buffer The buffer pointing to an asset.
* @param data Pointer to a ubyte array to buffer data into.
* @param size Length of the data buffer. Represents how many bytes can be read.
* @return The count of bytes read. Complete when less than data array size.
*/
int32_t assetBufferRead(assetbuffer_t *buffer, char *data, size_t size);
/**
* Skip to the end of the buffer, useful to find the length of the buffer.
* @param Buffer The buffer pointing to an asset.
* @return How many bytes were skipped
*/
int32_t assetBufferEnd(assetbuffer_t *buffer);
/**
* Rewinds an asset buffer to the start.
*
* @param buffer Buffer to rewind
* @return 0 if successful, otherwise unsuccessful.
*/
int32_t assetBufferStart(assetbuffer_t *buffer);
/**
* Method to skip n bytes in the buffer
* @param buffer The buffer pointing to an asset.
* @param n Count of bytes to skip.
* @return 0 if successful, otherwise unsuccessful.
*/
int32_t assetBufferSkip(assetbuffer_t *buffer, long n);
/**
* Retreive the current byte position within the asset that the head is at.
*
* @param buffer Buffer to get the position of.
* @return Position (in bytes) that the current seek is at.
*/
size_t assetBufferGetCurrentPosition(assetbuffer_t *buffer);