Updating a few more things to state events, will probably stop here for now and revist the trailing things later.
This commit is contained in:
@ -4,9 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "event/Event.hpp"
|
||||
#include "state/State.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class AssetManager;
|
||||
@ -18,6 +16,7 @@ namespace Dawn {
|
||||
uint8_t state = 0x00;
|
||||
bool loaded = false;
|
||||
Event<> eventLoaded;
|
||||
StateEvent<> event2Loaded;
|
||||
|
||||
/**
|
||||
* Create an abstract Asset object.
|
||||
|
@ -28,10 +28,12 @@ void AssetManager::queueLoad(Asset *asset) {
|
||||
}
|
||||
|
||||
void AssetManager::queueUnload(std::vector<Asset*> assets) {
|
||||
std::cout << "Asset list was queued to unload, but is not yet implemented" << std::endl;
|
||||
vectorAppend(&this->assetsToUnload, &assets);
|
||||
}
|
||||
|
||||
void AssetManager::queueUnload(Asset *asset) {
|
||||
std::cout << "Asset was queued to unload, but is not yet implemented" << std::endl;
|
||||
this->assetsToUnload.push_back(asset);
|
||||
}
|
||||
|
||||
@ -64,12 +66,12 @@ void AssetManager::queueSwap(
|
||||
|
||||
void AssetManager::syncTick() {
|
||||
auto it = this->assetsToLoad.begin();
|
||||
// auto it = this->assetsNotLoaded.begin();
|
||||
while(it != this->assetsToLoad.end()) {
|
||||
auto asset = *it;
|
||||
if(asset->loaded) {
|
||||
it = this->assetsToLoad.erase(it);
|
||||
asset->eventLoaded.invoke();
|
||||
asset->event2Loaded.invoke();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -79,12 +81,13 @@ void AssetManager::syncTick() {
|
||||
if(asset->loaded) {
|
||||
it = this->assetsToLoad.erase(it);
|
||||
asset->eventLoaded.invoke();
|
||||
asset->event2Loaded.invoke();
|
||||
continue;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
// auto it = this->assetsNotLoaded.begin();
|
||||
// auto it2 = this->assetsToUnload.begin();
|
||||
// while(it2 != this->assetsToUnload.end()) {
|
||||
// ++it2;
|
||||
|
@ -1,77 +1,76 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AudioAsset.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
AudioAsset::AudioAsset(AssetManager *man, std::string name) :
|
||||
Asset(man, name),
|
||||
loader(name + ".audio")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AudioAsset::updateSync() {
|
||||
if(this->state != 0x07) return;
|
||||
|
||||
// THIS WILL DEFINITELY CHANGE
|
||||
this->state = 0x08;
|
||||
this->loaded = true;
|
||||
this->eventLoaded.invoke();
|
||||
}
|
||||
|
||||
void AudioAsset::updateAsync() {
|
||||
if(this->state != 0x00) return;
|
||||
char *start, *end;
|
||||
char buffer[1024];
|
||||
|
||||
// Open asset for reading
|
||||
this->state = 0x01;
|
||||
this->loader.open();
|
||||
|
||||
// Parse header data.
|
||||
this->state = 0x02;
|
||||
this->loader.read((uint8_t *)buffer, 1024);
|
||||
|
||||
// Channel count
|
||||
this->state = 0x03;
|
||||
start = buffer;
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->channelCount = atoi(start);
|
||||
assertTrue(this->channelCount > 0);
|
||||
|
||||
// Sample Rate
|
||||
this->state = 0x04;
|
||||
start = end + 1;
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->sampleRate = (uint32_t)strtoul(start, NULL, 10);
|
||||
assertTrue(this->sampleRate > 0);
|
||||
|
||||
// Number of samples per channel
|
||||
this->state = 0x05;
|
||||
start = end + 1;
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->samplesPerChannel = atoi(start);
|
||||
assertTrue(this->samplesPerChannel > 0);
|
||||
|
||||
// Total Data Length
|
||||
this->state = 0x06;
|
||||
start = end + 1;
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->bufferSize = (size_t)atoll(start);
|
||||
assertTrue(this->bufferSize > 0);
|
||||
|
||||
// Determine frame size
|
||||
this->frameSize = sizeof(int16_t) * this->channelCount;
|
||||
|
||||
// Indicated start of data
|
||||
this->state = 0x07;
|
||||
this->bufferStart = end - buffer;
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AudioAsset.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
AudioAsset::AudioAsset(AssetManager *man, std::string name) :
|
||||
Asset(man, name),
|
||||
loader(name + ".audio")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AudioAsset::updateSync() {
|
||||
if(this->state != 0x07) return;
|
||||
|
||||
// THIS WILL DEFINITELY CHANGE
|
||||
this->state = 0x08;
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
void AudioAsset::updateAsync() {
|
||||
if(this->state != 0x00) return;
|
||||
char *start, *end;
|
||||
char buffer[1024];
|
||||
|
||||
// Open asset for reading
|
||||
this->state = 0x01;
|
||||
this->loader.open();
|
||||
|
||||
// Parse header data.
|
||||
this->state = 0x02;
|
||||
this->loader.read((uint8_t *)buffer, 1024);
|
||||
|
||||
// Channel count
|
||||
this->state = 0x03;
|
||||
start = buffer;
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->channelCount = atoi(start);
|
||||
assertTrue(this->channelCount > 0);
|
||||
|
||||
// Sample Rate
|
||||
this->state = 0x04;
|
||||
start = end + 1;
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->sampleRate = (uint32_t)strtoul(start, NULL, 10);
|
||||
assertTrue(this->sampleRate > 0);
|
||||
|
||||
// Number of samples per channel
|
||||
this->state = 0x05;
|
||||
start = end + 1;
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->samplesPerChannel = atoi(start);
|
||||
assertTrue(this->samplesPerChannel > 0);
|
||||
|
||||
// Total Data Length
|
||||
this->state = 0x06;
|
||||
start = end + 1;
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->bufferSize = (size_t)atoll(start);
|
||||
assertTrue(this->bufferSize > 0);
|
||||
|
||||
// Determine frame size
|
||||
this->frameSize = sizeof(int16_t) * this->channelCount;
|
||||
|
||||
// Indicated start of data
|
||||
this->state = 0x07;
|
||||
this->bufferStart = end - buffer;
|
||||
}
|
Reference in New Issue
Block a user