cleaned things up a bit, looks good to start implementing the rpg mechs

This commit is contained in:
2024-11-25 21:37:28 -06:00
parent de55029356
commit 4914ec6168
21 changed files with 121 additions and 57 deletions

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,13 +8,12 @@
using namespace Dawn;
TextureLoader::TextureLoader(const std::string &name) :
TextureLoader::TextureLoader(const std::string name) :
AssetLoader(name),
loader(name + ".texture"),
loader(name),
state(TextureLoaderLoadState::INITIAL)
{
sharedTexture = std::make_shared<Texture>();
weakTexture = sharedTexture;
texture = std::make_shared<Texture>();
}
void TextureLoader::updateAsync() {
@@ -114,34 +113,35 @@ void TextureLoader::updateSync() {
if(this->state != TextureLoaderLoadState::ASYNC_DONE) return;
this->state = TextureLoaderLoadState::SYNC_LOADING;
assertNotNull(this->sharedTexture, "Texture is null!");
assertNotNull(this->texture, "Texture is null!");
assertNotNull(this->data, "Texture data is null!");
// Setup Texture
this->sharedTexture->setSize(
this->texture->setSize(
this->width,
this->height,
this->format,
TextureDataFormat::UNSIGNED_BYTE
);
this->sharedTexture->buffer(this->data);
this->texture->buffer(this->data);
// Free data buffer
delete[] this->data;
this->data = nullptr;
// Leat go of the held pointer
this->sharedTexture = nullptr;
// Hand off and call done
this->state = TextureLoaderLoadState::SYNC_DONE;
this->loaded = true;
}
std::shared_ptr<Texture> TextureLoader::getTexture() {
return this->texture;
}
TextureLoader::~TextureLoader() {
if(this->data != nullptr) {
delete[] this->data;
this->data = nullptr;
}
this->sharedTexture = nullptr;
this->texture = nullptr;
}

View File

@@ -30,22 +30,27 @@ namespace Dawn {
enum TextureWrapMode wrapY;
enum TextureFilterMode filterMin;
enum TextureFilterMode filterMag;
std::shared_ptr<Texture> texture;
public:
std::shared_ptr<Texture> sharedTexture;
std::weak_ptr<Texture> weakTexture;
/**
* Constructs a texture asset loader. You should instead use the parent
* asset managers' abstracted load method
*
* @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;
/**
* Get the texture asset.
*
* @return Texture asset.
*/
std::shared_ptr<Texture> getTexture();
/**
* Dispose / Cleanup the texture asset. Will also dispose the underlying
* texture itself.

View File

@@ -8,9 +8,9 @@
using namespace Dawn;
TrueTypeLoader::TrueTypeLoader(const std::string &name) :
TrueTypeLoader::TrueTypeLoader(const std::string name) :
AssetLoader(name),
loader(name + ".ttf")
loader(name)
{
// Init the font.
auto ret = FT_Init_FreeType(&fontLibrary);

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;