Part one - removed references and smart pointers

This commit is contained in:
2022-11-11 19:08:46 -08:00
parent e892224900
commit e6d475d170
76 changed files with 3899 additions and 3707 deletions

View File

@ -1,64 +1,64 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TextureAsset.hpp"
using namespace Dawn;
TextureAsset::TextureAsset(AssetManager &assetManager, std::string name) :
Asset(assetManager, name),
loader(name + ".texture")
{
this->texture = std::make_shared<Texture>();
}
void TextureAsset::updateSync() {
if(
this->state != 0x03
) return;
this->state = 0x04;
this->texture->setSize(this->width, this->height);
this->texture->buffer(this->colors);
this->state = 0x05;
this->loaded = true;
}
void TextureAsset::updateAsync() {
if(this->state != 0x00) return;
this->state = 0x01;
this->loader.loadRaw(&this->buffer);
this->state = 0x02;
// Parse header data.
char integer[32];
size_t j = 0, i = 0;
while(true) {
auto c = this->buffer[i++];
if(c == '|') {
integer[j] = '\0';
if(this->width == -1) {
this->width = atoi(integer);
if(this->width <= 0) throw "Invalid width";
j = 0;
continue;
} else {
this->height = atoi(integer);
if(this->height <= 0) throw "Invalid height";
break;
}
}
integer[j++] = c;
}
this->colors = (struct Color *)((void *)(this->buffer + i));
this->state = 0x03;
}
TextureAsset::~TextureAsset() {
if(this->buffer != nullptr) {
memoryFree(this->buffer);
}
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TextureAsset.hpp"
using namespace Dawn;
TextureAsset::TextureAsset(AssetManager *assetManager, std::string name) :
Asset(assetManager, name),
loader(name + ".texture"),
texture()
{
}
void TextureAsset::updateSync() {
if(
this->state != 0x03
) return;
this->state = 0x04;
this->texture.setSize(this->width, this->height);
this->texture.buffer(this->colors);
this->state = 0x05;
this->loaded = true;
}
void TextureAsset::updateAsync() {
if(this->state != 0x00) return;
this->state = 0x01;
this->loader.loadRaw(&this->buffer);
this->state = 0x02;
// Parse header data.
char integer[32];
size_t j = 0, i = 0;
while(true) {
auto c = this->buffer[i++];
if(c == '|') {
integer[j] = '\0';
if(this->width == -1) {
this->width = atoi(integer);
assertTrue(this->width > 0);
j = 0;
continue;
} else {
this->height = atoi(integer);
assertTrue(this->height > 0);
break;
}
}
integer[j++] = c;
}
this->colors = (struct Color *)((void *)(this->buffer + i));
this->state = 0x03;
}
TextureAsset::~TextureAsset() {
if(this->buffer != nullptr) {
memoryFree(this->buffer);
}
}

View File

@ -1,29 +1,40 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../Asset.hpp"
#include "../AssetLoader.hpp"
#include "display/Texture.hpp"
namespace Dawn {
class TextureAsset : public Asset {
protected:
AssetLoader loader;
uint8_t *buffer = nullptr;
int32_t width = -1, height = -1;
struct Color *colors;
public:
std::shared_ptr<Texture> texture;
TextureAsset(AssetManager &assetManager, std::string name);
void updateSync() override;
void updateAsync() override;
~TextureAsset();
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../Asset.hpp"
#include "../AssetLoader.hpp"
#include "display/Texture.hpp"
namespace Dawn {
class TextureAsset : public Asset {
protected:
AssetLoader loader;
uint8_t *buffer = nullptr;
int32_t width = -1, height = -1;
struct Color *colors;
public:
Texture texture;
/**
* Constructs a texture asset loader. You should instead use the parent
* asset managers' abstracted load method
*
* @param assetManager Asset manager this asset belongs to.
* @param name File name asset to load, omitting the extension.
*/
TextureAsset(AssetManager *assetManager, std::string name);
void updateSync() override;
void updateAsync() override;
/**
* Dispose / Cleanup the texture asset. Will also dispose the underlying
* texture itself.
*/
~TextureAsset();
};
}

View File

@ -1,76 +1,86 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TrueTypeAsset.hpp"
using namespace Dawn;
TrueTypeAsset::TrueTypeAsset(AssetManager &assMan, std::string name) :
Asset(assMan, name),
loader(name + ".truetype")
{
}
void TrueTypeAsset::updateSync() {
if(this->state != 0x04) return;
this->font.texture.setSize(this->width, this->height);
this->font.texture.buffer(this->pixels);
auto i = this->pixels;
memoryCopy(
this->characterData,
this->font.characterData,
sizeof(truetypechar_t) * TRUETYPE_NUM_CHARS
);
this->state = 0x05;
this->loaded = true;
}
void TrueTypeAsset::updateAsync() {
int32_t fontSize;
size_t i, j;
char intBuffer[32];
char c;
if(this->state != 0x00) return;
this->state = 0x01;
this->loader.loadRaw(&this->buffer);
this->state = 0x02;
// Parse header data.
i = j = 0;
width = -1, height = -1, fontSize = -1;
while(true) {
c = this->buffer[i++];
if(c == '|') {
intBuffer[j] = '\0';
if(width == -1) {
this->width = atoi(intBuffer);
j = 0;
continue;
} else if(height == -1) {
this->height = atoi(intBuffer);
j = 0;
continue;
} else {
fontSize = atoi(intBuffer);
break;
}
}
intBuffer[j++] = c;
}
this->state = 0x03;
this->font.fontSize = fontSize;
this->pixels = (struct Color*)(this->buffer + i);
this->characterData = (truetypechar_t*)(
(uint8_t*)this->pixels + (this->width * this->height * sizeof(struct Color))
);
this->state = 0x04;
}
TrueTypeAsset::~TrueTypeAsset() {
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TrueTypeAsset.hpp"
using namespace Dawn;
TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) :
Asset(assMan, name),
loader(name + ".truetype")
{
}
void TrueTypeAsset::updateSync() {
if(this->state != 0x04) return;
this->font.texture.setSize(this->width, this->height);
this->font.texture.buffer(this->pixels);
auto i = this->pixels;
memoryCopy(
this->characterData,
this->font.characterData,
sizeof(truetypechar_t) * TRUETYPE_NUM_CHARS
);
memoryFree(this->buffer);
this->buffer = nullptr;
this->state = 0x05;
this->loaded = true;
}
void TrueTypeAsset::updateAsync() {
int32_t fontSize;
size_t i, j;
char intBuffer[32];
char c;
if(this->state != 0x00) return;
this->state = 0x01;
this->loader.loadRaw(&this->buffer);
this->state = 0x02;
// Parse header data.
i = j = 0;
width = -1, height = -1, fontSize = -1;
while(true) {
c = this->buffer[i++];
if(c == '|') {
intBuffer[j] = '\0';
if(width == -1) {
this->width = atoi(intBuffer);
assertTrue(this->width > 0);
j = 0;
continue;
} else if(height == -1) {
this->height = atoi(intBuffer);
assertTrue(this->height > 0);
j = 0;
continue;
} else {
fontSize = atoi(intBuffer);
assertTrue(fontSize > 0);
break;
}
}
intBuffer[j++] = c;
}
this->state = 0x03;
this->font.fontSize = fontSize;
this->pixels = (struct Color*)(this->buffer + i);
this->characterData = (truetypechar_t*)(
(uint8_t*)this->pixels + (this->width * this->height * sizeof(struct Color))
);
this->state = 0x04;
}
TrueTypeAsset::~TrueTypeAsset() {
if(this->buffer != nullptr) {
memoryFree(this->buffer);
this->buffer = nullptr;
}
}

View File

@ -1,30 +1,40 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../Asset.hpp"
#include "../AssetLoader.hpp"
#include "display/font/TrueTypeFont.hpp"
namespace Dawn {
class TrueTypeAsset : public Asset {
protected:
AssetLoader loader;
uint8_t *buffer = nullptr;
truetypechar_t *characterData = nullptr;
struct Color *pixels = nullptr;
int32_t width, height;
public:
TrueTypeFont font;
TrueTypeAsset(AssetManager &assMan, std::string name);
void updateSync() override;
void updateAsync() override;
~TrueTypeAsset();
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../Asset.hpp"
#include "../AssetLoader.hpp"
#include "display/font/TrueTypeFont.hpp"
namespace Dawn {
class TrueTypeAsset : public Asset {
protected:
AssetLoader loader;
uint8_t *buffer = nullptr;
truetypechar_t *characterData = nullptr;
struct Color *pixels = nullptr;
int32_t width, height;
public:
TrueTypeFont font;
/**
* Constructs a new True Type Asset. As with all other assets you should
* instead use the AssetManaager.load method.
*
* @param assMan Asset manager that this asset belongs to.
* @param name Filename of this asset.
*/
TrueTypeAsset(AssetManager *assMan, std::string name);
void updateSync() override;
void updateAsync() override;
/**
* Disposes / Cleans up the truetype asset.
*/
~TrueTypeAsset();
};
}