bit of cleanup

This commit is contained in:
2024-11-25 20:04:31 -06:00
parent aefbe17786
commit 274c96bb64
37 changed files with 128 additions and 122 deletions

View File

@@ -60,7 +60,9 @@ int32_t assetDataLoaderArchiveClose(struct archive *a, void *d) {
// // // // // // // // // // // // // // // // // // // // // // // // // // //
AssetDataLoader::AssetDataLoader(std::string fileName) : fileName(fileName) {
AssetDataLoader::AssetDataLoader(const std::string &fileName) :
fileName(fileName)
{
assertTrue(
fileName.size() > 0,
"IAssetDataLoader::IAssetDataLoader: fileName must be greater than 0"
@@ -68,13 +70,16 @@ AssetDataLoader::AssetDataLoader(std::string fileName) : fileName(fileName) {
}
size_t AssetDataLoader::getSize() {
assertTrue(this->assetArchiveEntry != nullptr, "AssetDataLoader::getSize: Entry is NULL!");
assertTrue(archive_entry_size_is_set(assetArchiveEntry), "assetGetSize: Entry size is not set!");
assertTrue(this->assetArchiveEntry != nullptr, "Entry is NULL!");
assertTrue(
archive_entry_size_is_set(assetArchiveEntry),
"Entry size is not set!"
);
return archive_entry_size(assetArchiveEntry);
}
size_t AssetDataLoader::getPosition() {
assertNotNull(this->assetArchiveFile, "AssetDataLoader::getPosition: File is not open!");
assertNotNull(this->assetArchiveFile, "File is not open!");
return this->position;
}
@@ -123,8 +128,10 @@ void AssetDataLoader::open() {
position = 0;
// Iterate over each file to find the one for this asset loader.
while(archive_read_next_header(assetArchive, &assetArchiveEntry) == ARCHIVE_OK) {
const char_t *headerFile = (char_t*)archive_entry_pathname(assetArchiveEntry);
while(archive_read_next_header(assetArchive, &assetArchiveEntry)==ARCHIVE_OK){
const char_t *headerFile = (char_t*)archive_entry_pathname(
assetArchiveEntry
);
if(std::string(headerFile) == this->fileName) return;
int32_t ret = archive_read_data_skip(assetArchive);
assertTrue(ret == ARCHIVE_OK, "Failed to skip data!");
@@ -151,11 +158,11 @@ int32_t AssetDataLoader::close() {
return res;
}
size_t AssetDataLoader::read(uint8_t *buffer, size_t size) {
size_t AssetDataLoader::read(uint8_t *buffer, const size_t &size) {
assertNotNull(buffer, "Buffer is NULL!");
assertTrue(size > 0, "Size must be greater than 0!");
assertNotNull(this->assetArchive, "assetRead: Archive is NULL!");
assertNotNull(this->assetArchiveEntry, "assetRead: Entry is NULL!");
assertNotNull(this->assetArchive, "Archive is NULL!");
assertNotNull(this->assetArchiveEntry, "Entry is NULL!");
ssize_t read = archive_read_data(this->assetArchive, buffer, size);
this->position += read;
@@ -164,8 +171,8 @@ size_t AssetDataLoader::read(uint8_t *buffer, size_t size) {
assertUnreachable(archive_error_string(this->assetArchive));
}
assertTrue(read != ARCHIVE_RETRY, "assetRead: Failed to read data (RETRY)!");
assertTrue(read != ARCHIVE_WARN, "assetRead: Failed to read data (WARN)!");
assertTrue(read != ARCHIVE_RETRY, "Failed to read data (RETRY)!");
assertTrue(read != ARCHIVE_WARN, "Failed to read data (WARN)!");
return read;
}
@@ -185,17 +192,19 @@ size_t AssetDataLoader::readUntil(
return i;
}
size_t AssetDataLoader::skip(size_t n) {
assertTrue(n >= 0, "AssetDataLoader::skip: Byte count must be greater than 0.");
size_t AssetDataLoader::skip(const size_t &n) {
assertTrue(n >= 0, "Byte count must be greater than 0.");
assertTrue(n < (this->getSize() - this->position), "Cannot skip past EOF!");
uint8_t dumpBuffer[ASSET_LOADER_BUFFER_SIZE];
size_t skipped = 0;
size_t n2, n3;
while(n != 0) {
size_t n2, n3, n4;
n4 = n;
while(n4 != 0) {
n2 = Math::min<size_t>(n, ASSET_LOADER_BUFFER_SIZE);
n3 = this->read(dumpBuffer, n2);
assertTrue(n3 == n2, "AssetDataLoader::skip: Failed to skip bytes!");
n -= n3;
assertTrue(n3 == n2, "Failed to skip bytes!");
n4 -= n3;
}
return skipped;

View File

@@ -88,7 +88,7 @@ namespace Dawn {
*
* @param fileName File name of the asset that is to be loaded.
*/
AssetDataLoader(std::string filename);
AssetDataLoader(const std::string &filename);
/**
* Get the size of the asset.
@@ -134,7 +134,7 @@ namespace Dawn {
* @param size Length of the data buffer (How many bytes to read).
* @return The count of bytes read.
*/
size_t read(uint8_t *buffer, size_t size);
size_t read(uint8_t *buffer, const size_t &size);
/**
* Reads bytes from the buffer until a given delimiter is found. Returned
@@ -157,7 +157,7 @@ namespace Dawn {
* @param n Count of bytes to progress the read head by.
* @return Count of bytes progressed.
*/
size_t skip(size_t n);
size_t skip(const size_t &n);
/**
* Rewind the read head to the beginning of the file.

View File

@@ -8,7 +8,7 @@
using namespace Dawn;
AssetLoader::AssetLoader(const std::string name) : name(name) {
AssetLoader::AssetLoader(const std::string &name) : name(name) {
assertTrue(name.size() > 0, "Asset::Asset: Name cannot be empty");
}

View File

@@ -17,7 +17,7 @@ namespace Dawn {
*
* @param name Name of the asset.
*/
AssetLoader(const std::string name);
AssetLoader(const std::string &name);
/**
* Virtual function that will be called by the asset manager on a

View File

@@ -26,7 +26,7 @@ void AssetManager::update() {
}
}
void AssetManager::removeExisting(const std::string filename) {
void AssetManager::removeExisting(const std::string &filename) {
auto existing = std::find_if(
pendingAssetLoaders.begin(), pendingAssetLoaders.end(),
[&](auto &loader) {
@@ -52,7 +52,7 @@ bool_t AssetManager::isEverythingLoaded() {
return pendingAssetLoaders.size() == 0;
}
bool_t AssetManager::isLoaded(const std::string filename) {
bool_t AssetManager::isLoaded(const std::string &filename) {
auto existing = this->getExisting<AssetLoader>(filename);
if(existing) return existing->loaded;
return false;

View File

@@ -20,7 +20,7 @@ namespace Dawn {
* @return The asset loader if it exists, otherwise nullptr.
*/
template<class T>
std::shared_ptr<T> getExisting(const std::string filename) {
std::shared_ptr<T> getExisting(const std::string &filename) {
auto existing = std::find_if(
pendingAssetLoaders.begin(), pendingAssetLoaders.end(),
[&](auto &loader) {
@@ -47,7 +47,7 @@ namespace Dawn {
*
* @param filename The filename of the asset to remove.
*/
void removeExisting(const std::string filename);
void removeExisting(const std::string &filename);
public:
/**
@@ -74,7 +74,7 @@ namespace Dawn {
* @param filename The filename of the asset to check.
* @return True if the asset has been loaded.
*/
bool_t isLoaded(const std::string filename);
bool_t isLoaded(const std::string &filename);
/**
* Returns the asset loader for the given asset.
@@ -83,7 +83,7 @@ namespace Dawn {
* @return The asset loader for the given asset.
*/
template<class T>
std::shared_ptr<T> get(const std::string filename) {
std::shared_ptr<T> get(const std::string &filename) {
auto existing = this->getExisting<T>(filename);
if(existing) return existing;

View File

@@ -7,7 +7,7 @@
using namespace Dawn;
JSONLoader::JSONLoader(const std::string name) :
JSONLoader::JSONLoader(const std::string &name) :
AssetLoader(name),
loader(name),
state(JSONLoaderState::INITIAL)

View File

@@ -25,7 +25,7 @@ namespace Dawn {
public:
json data;
JSONLoader(const std::string name);
JSONLoader(const std::string &name);
void updateSync() override;
void updateAsync() override;
~JSONLoader();

View File

@@ -8,7 +8,7 @@
using namespace Dawn;
TextureLoader::TextureLoader(const std::string name) :
TextureLoader::TextureLoader(const std::string &name) :
AssetLoader(name),
loader(name + ".texture"),
state(TextureLoaderLoadState::INITIAL)

View File

@@ -41,7 +41,7 @@ namespace Dawn {
*
* @param name File name asset to load, omitting the extension.
*/
TextureLoader(const std::string name);
TextureLoader(const std::string &name);
void updateSync() override;
void updateAsync() override;

View File

@@ -8,7 +8,7 @@
using namespace Dawn;
TrueTypeLoader::TrueTypeLoader(const std::string name) :
TrueTypeLoader::TrueTypeLoader(const std::string &name) :
AssetLoader(name),
loader(name + ".ttf")
{

View File

@@ -33,7 +33,7 @@ namespace Dawn {
*
* @param name File name asset to load, omitting the extension.
*/
TrueTypeLoader(const std::string name);
TrueTypeLoader(const std::string &name);
void updateSync() override;
void updateAsync() override;