Starting refactor now.

This commit is contained in:
2023-11-01 22:03:16 -05:00
parent c5cfc31436
commit d530210bed
18 changed files with 133 additions and 229 deletions

View File

@ -13,7 +13,6 @@ namespace Dawn {
public:
AssetManager *assetManager;
std::string name;
uint8_t state = 0x00;
bool_t loaded = false;
Event<> eventLoaded;
StateEvent<> event2Loaded;

View File

@ -7,12 +7,6 @@
#include "Asset.hpp"
#include "util/array.hpp"
#include "assets/AudioAsset.hpp"
#include "assets/LanguageAsset.hpp"
#include "assets/TextureAsset.hpp"
#include "assets/TilesetAsset.hpp"
#include "assets/TrueTypeAsset.hpp"
namespace Dawn {
class AssetManager {
private:

View File

@ -4,9 +4,7 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp"
#define ASSET_LOADER_BUFFER_SIZE 32768

View File

@ -15,62 +15,65 @@ AudioAsset::AudioAsset(AssetManager *man, std::string name) :
}
void AudioAsset::updateSync() {
if(this->state != 0x07) return;
if(this->state != AUDIO_ASSET_LOAD_STATE_DATA_READ) return;
// THIS WILL DEFINITELY CHANGE
this->state = 0x08;
this->state = AUDIO_ASSET_LOAD_STATE_COMPLETE;
this->loaded = true;
}
void AudioAsset::updateAsync() {
if(this->state != 0x00) return;
if(this->state != AUDIO_ASSET_LOAD_STATE_INITIAL) return;
char *start, *end;
char buffer[1024];
// Open asset for reading
this->state = 0x01;
this->state = AUDIO_ASSET_LOAD_STATE_OPENING;
this->loader.open();
// Parse header data.
this->state = 0x02;
this->state = AUDIO_ASSET_LOAD_STATE_READING_HEADER;
this->loader.read((uint8_t *)buffer, 1024);
// Channel count
this->state = 0x03;
this->state = AUDIO_ASSET_LOAD_STATE_READING_CHANNEL_COUNT;
start = buffer;
end = strchr(start, '|');
*end = '\0';
this->channelCount = atoi(start);
assertTrue(this->channelCount > 0, "AudioAsset::updateAsync: Channel count must be greater than 0");
assertTrue(this->channelCount > 0, "Channel count must be greater than 0");
// Sample Rate
this->state = 0x04;
this->state = AUDIO_ASSET_LOAD_STATE_READING_SAMPLE_RATE;
start = end + 1;
end = strchr(start, '|');
*end = '\0';
this->sampleRate = (uint32_t)strtoul(start, NULL, 10);
assertTrue(this->sampleRate > 0, "AudioAsset::updateAsync: Sample rate must be greater than 0");
assertTrue(this->sampleRate > 0, "Sample rate must be greater than 0");
// Number of samples per channel
this->state = 0x05;
this->state = AUDIO_ASSET_LOAD_STATE_READING_SAMPLES_PER_CHANNEL;
start = end + 1;
end = strchr(start, '|');
*end = '\0';
this->samplesPerChannel = atoi(start);
assertTrue(this->samplesPerChannel > 0, "AudioAsset::updateAsync: Samples per channel must be greater than 0");
assertTrue(
this->samplesPerChannel > 0,
"Samples per channel must be greater than 0"
);
// Total Data Length
this->state = 0x06;
this->state = AUDIO_ASSET_LOAD_STATE_READING_DATA_LENGTH;
start = end + 1;
end = strchr(start, '|');
*end = '\0';
this->bufferSize = (size_t)atoll(start);
assertTrue(this->bufferSize > 0, "AudioAsset::updateAsync: Buffer size must be greater than 0");
assertTrue(this->bufferSize > 0, "Buffer size must be greater than 0");
// Determine frame size
this->frameSize = sizeof(int16_t) * this->channelCount;
// Indicated start of data
this->state = 0x07;
this->state = AUDIO_ASSET_LOAD_STATE_DATA_READ;
this->bufferStart = end - buffer;
}

View File

@ -10,10 +10,22 @@
namespace Dawn {
class AudioSource;
enum AudioAssetLoadState {
AUDIO_ASSET_LOAD_STATE_INITIAL,
AUDIO_ASSET_LOAD_STATE_OPENING,
AUDIO_ASSET_LOAD_STATE_READING_HEADER,
AUDIO_ASSET_LOAD_STATE_READING_CHANNEL_COUNT,
AUDIO_ASSET_LOAD_STATE_READING_SAMPLE_RATE,
AUDIO_ASSET_LOAD_STATE_READING_SAMPLES_PER_CHANNEL,
AUDIO_ASSET_LOAD_STATE_READING_DATA_LENGTH,
AUDIO_ASSET_LOAD_STATE_DATA_READ,
AUDIO_ASSET_LOAD_STATE_COMPLETE
};
class AudioAsset : public Asset {
protected:
AssetLoader loader;
uint8_t state = 0x00;
enum AudioAssetLoadState state = AUDIO_ASSET_LOAD_STATE_INITIAL;
int32_t channelCount;
uint32_t sampleRate;

View File

@ -9,6 +9,5 @@ target_sources(${DAWN_TARGET_NAME}
AudioAsset.cpp
LanguageAsset.cpp
TextureAsset.cpp
TilesetAsset.cpp
TrueTypeAsset.cpp
)

View File

@ -20,8 +20,8 @@ void LanguageAsset::updateSync() {
void LanguageAsset::updateAsync() {
assertTrue(
this->state == LANGUAGE_ASSET_LOAD_STATE_NOT_LOADING,
"LanguageAsset::updateAsync: State must be NOT_LOADING"
this->state == LANGUAGE_ASSET_LOAD_STATE_INITIAL,
"State must be initial"
);
// Open Asset
@ -67,10 +67,13 @@ void LanguageAsset::updateAsync() {
std::string LanguageAsset::getValue(std::string key) {
assertTrue(
this->state == LANGUAGE_ASSET_LOAD_STATE_READY_TO_READ,
"LanguageAsset::getValue: State must be LANGUAGE_ASSET_LOAD_STATE_READY_TO_READ"
"State must be LANGUAGE_ASSET_LOAD_STATE_READY_TO_READ"
);
assertMapHasKey(this->values, key, "Key does not exist");
assertTrue(
this->values[key].begin >= 0 && this->values[key].length > 0,
"Value is invalid"
);
assertMapHasKey(this->values, key, "LanguageAsset::getValue: Key does not exist");
assertTrue(this->values[key].begin >= 0 && this->values[key].length > 0, "LanguageAsset::getValue: Value is invalid");
// Get the positions
struct AssetLanguageValue value = this->values[key];
@ -80,4 +83,4 @@ std::string LanguageAsset::getValue(std::string key) {
buffer[value.length] = '\0';
return std::string((char *)buffer, value.length + 1);
}
}

View File

@ -14,7 +14,7 @@ namespace Dawn {
};
enum LangageAssetLoadState {
LANGUAGE_ASSET_LOAD_STATE_NOT_LOADING,
LANGUAGE_ASSET_LOAD_STATE_INITIAL,
LANGUAGE_ASSET_LOAD_STATE_OPENING,
LANGUAGE_ASSET_LOAD_STATE_CREATING_BUFFER,
LANGUAGE_ASSET_LOAD_STATE_READY_TO_READ
@ -23,16 +23,14 @@ namespace Dawn {
class LanguageAsset : public Asset {
protected:
AssetLoader loader;
enum LangageAssetLoadState state = LANGUAGE_ASSET_LOAD_STATE_NOT_LOADING;
enum LangageAssetLoadState state = LANGUAGE_ASSET_LOAD_STATE_INITIAL;
std::map<std::string, struct AssetLanguageValue> values;
uint8_t buffer[1024];
public:
LanguageAsset(AssetManager *man, std::string name);
void updateSync() override;
void updateAsync() override;
std::string getValue(std::string key);
};
}
}

View File

@ -15,14 +15,12 @@ TextureAsset::TextureAsset(AssetManager *assetManager, std::string name) :
}
void TextureAsset::updateSync() {
if(
this->state != 0x03
) return;
if(this->state != TEXTURE_ASSET_LOAD_STATE_SYNC_HANDOFF) return;
this->state = 0x04;
this->texture.setSize(this->width, this->height, this->format, TEXTURE_DATA_FORMAT_UNSIGNED_BYTE);
this->state = TEXTURE_ASSET_LOAD_STATE_BUFFERING_TEXTURE;
this->texture.setSize(
this->width, this->height, this->format, TEXTURE_DATA_FORMAT_UNSIGNED_BYTE
);
this->texture.buffer(this->colors);
this->texture.wrapModeX = this->wrapModeX;
@ -30,23 +28,25 @@ void TextureAsset::updateSync() {
this->texture.filterModeMin = this->filterModeMin;
this->texture.filterModeMag = this->filterModeMag;
this->state = 0x05;
this->state = TEXTURE_ASSET_LOAD_STATE_COMPLETE;
this->loaded = true;
}
void TextureAsset::updateAsync() {
if(this->state != 0x00) return;
this->state = 0x01;
if(this->state != TEXTURE_ASSET_LOAD_STATE_INITIAL) return;
this->state = TEXTURE_ASSET_LOAD_STATE_OPENING;
this->loader.open();
this->buffer = (uint8_t*)memoryAllocate(this->loader.getSize());
this->buffer = memoryAllocate<uint8_t>(this->loader.getSize());
this->loader.read(this->buffer, this->loader.getSize());
this->loader.close();
this->state = 0x02;
this->state = TEXTURE_ASSET_LOAD_STATE_PARSING_HEADER;
// Parse header data.
char integer[256];
size_t j = 0, i = 0;
enum TextureAssetHeaderParseState parseState = TEXTURE_ASSET_HEADER_PARSE_STATE_VERSION;
enum TextureAssetHeaderParseState parseState =
TEXTURE_ASSET_HEADER_PARSE_STATE_VERSION
;
while(true) {
if(parseState == TEXTURE_ASSET_HEADER_PARSE_STATE_END) break;
@ -61,7 +61,7 @@ void TextureAsset::updateAsync() {
switch(parseState) {
case TEXTURE_ASSET_HEADER_PARSE_STATE_VERSION: {
auto compared = strcmp(integer, "DT_2.00");
assertTrue(compared == 0, "TextureAsset::updateAsync: Invalid version");
assertTrue(compared == 0, "Invalid version");
j = 0;
parseState = TEXTURE_ASSET_HEADER_PARSE_STATE_WIDTH;
break;
@ -69,7 +69,7 @@ void TextureAsset::updateAsync() {
case TEXTURE_ASSET_HEADER_PARSE_STATE_WIDTH: {
this->width = atoi(integer);
assertTrue(this->width > 0, "TextureAsset::updateAsync: Invalid width");
assertTrue(this->width > 0, "Invalid width");
j = 0;
parseState = TEXTURE_ASSET_HEADER_PARSE_STATE_HEIGHT;
break;
@ -77,7 +77,7 @@ void TextureAsset::updateAsync() {
case TEXTURE_ASSET_HEADER_PARSE_STATE_HEIGHT: {
this->height = atoi(integer);
assertTrue(this->height > 0, "TextureAsset::updateAsync: Invalid height");
assertTrue(this->height > 0, "Invalid height");
j = 0;
parseState = TEXTURE_ASSET_HEADER_PARSE_STATE_FORMAT;
break;
@ -119,12 +119,12 @@ void TextureAsset::updateAsync() {
}
default:
assertUnreachable("TextureAsset::updateAsync: Invalid parse state");
assertUnreachable("Invalid parse state");
}
}
this->colors = (uint8_t*)((void *)(this->buffer + i));
this->state = 0x03;
this->state = TEXTURE_ASSET_LOAD_STATE_SYNC_HANDOFF;
}
TextureAsset::~TextureAsset() {
@ -132,4 +132,4 @@ TextureAsset::~TextureAsset() {
memoryFree(this->buffer);
this->buffer = nullptr;
}
}
}

View File

@ -21,12 +21,22 @@ namespace Dawn {
TEXTURE_ASSET_HEADER_PARSE_STATE_END
};
enum TextureAssetLoadState {
TEXTURE_ASSET_LOAD_STATE_INITIAL,
TEXTURE_ASSET_LOAD_STATE_OPENING,
TEXTURE_ASSET_LOAD_STATE_PARSING_HEADER,
TEXTURE_ASSET_LOAD_STATE_SYNC_HANDOFF,
TEXTURE_ASSET_LOAD_STATE_BUFFERING_TEXTURE,
TEXTURE_ASSET_LOAD_STATE_COMPLETE,
};
class TextureAsset : public Asset {
protected:
AssetLoader loader;
uint8_t *buffer = nullptr;
int32_t width = -1, height = -1;
uint8_t *colors;
enum TextureAssetLoadState state = TEXTURE_ASSET_LOAD_STATE_INITIAL;
enum TextureFormat format;
enum TextureWrapMode wrapModeX;
enum TextureWrapMode wrapModeY;
@ -54,4 +64,4 @@ namespace Dawn {
*/
~TextureAsset();
};
}
}

View File

@ -1,102 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TilesetAsset.hpp"
using namespace Dawn;
TilesetAsset::TilesetAsset(AssetManager *assMan, std::string name) :
Asset(assMan, name),
loader(name + ".tileset"),
tileset()
{
}
void TilesetAsset::updateSync() {
}
void TilesetAsset::updateAsync() {
assertTrue(this->state == 0x00, "TilesetAsset::updateAsync: Initial state should be 0x00");
this->state = 0x01;
this->loader.open();
uint8_t *buffer = (uint8_t*)memoryAllocate(this->loader.getSize());
this->loader.read(buffer, this->loader.getSize());
this->loader.close();
this->state = 0x02;
char *strCurrent = (char *)buffer;
char *strNext, *strSubCurrent;
// Read cols and rows
strNext = strchr(strCurrent, '|');
*strNext = '\0';
this->tileset.columns = atoi(strCurrent);
this->state = 0x03;
assertTrue(this->tileset.columns > 0, "TilesetAsset::updateAsync: Count of columns needs to be greater than 0");
strCurrent = strNext+1;
strNext = strchr(strCurrent, '|');
*strNext = '\0';
this->tileset.rows = atoi(strCurrent);
this->state = 0x04;
assertTrue(this->tileset.rows > 0, "TilesetAsset::updateAsync: Count of rows needs to be greater than 0");
strCurrent = strNext+1;
strNext = strchr(strCurrent, '|');
*strNext = '\0';
this->tileset.divX = atoi(strCurrent);
this->state = 0x05;
assertTrue(this->tileset.divX > 0, "TilesetAsset::updateAsync: divX needs to be greater than 0");
strCurrent = strNext+1;
strNext = strchr(strCurrent, '|');
*strNext = '\0';
this->tileset.divY = atoi(strCurrent);
this->state = 0x06;
assertTrue(this->tileset.divY > 0, "TilesetAsset::updateAsync: divY needs to be greater than 0");
// Begin reading tiles.
int32_t done = 0;
int32_t count = this->tileset.columns * this->tileset.rows;
while(done < count) {
struct Tile tile;
strCurrent = strNext+1;
strNext = strchr(strCurrent, '|');
// Parse ux0
strSubCurrent = strchr(strCurrent, ',');
*strSubCurrent = '\0';
tile.uv0.x = atof(strCurrent);
// Parse ux1
strCurrent = strSubCurrent+1;
strSubCurrent = strchr(strCurrent, ',');
*strSubCurrent = '\0';
tile.uv1.x = atof(strCurrent);
// Parse uy0
strCurrent = strSubCurrent+1;
strSubCurrent = strchr(strCurrent, ',');
*strSubCurrent = '\0';
tile.uv0.y = atof(strCurrent);
// Parse uy1
strCurrent = strSubCurrent+1;
*strNext = '\0';
tile.uv1.y = atof(strCurrent);
// Next.
this->tileset.tiles.push_back(tile);
done++;
}
this->state = 0x07;
this->loaded = true;
memoryFree(buffer);
}

View File

@ -1,31 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../Asset.hpp"
#include "asset/AssetLoader.hpp"
#include "display/Tileset.hpp"
namespace Dawn {
class TilesetAsset : public Asset {
protected:
AssetLoader loader;
uint8_t state = 0x00;
public:
struct TilesetGrid tileset;
/**
* Creates a new TilesetAsset Loader.
*
* @param assMan Asset Manager this tileset asset belongs to.
* @param name Tileset asset name.
*/
TilesetAsset(AssetManager *assMan, std::string name);
void updateSync() override;
void updateAsync() override;
};
}

View File

@ -5,6 +5,7 @@
#include "TrueTypeAsset.hpp"
#include "asset/AssetManager.hpp"
#include "util/memory.hpp"
using namespace Dawn;
@ -15,20 +16,20 @@ TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) :
this->locks.onLockRemoved = [&](usagelockid_t id){
auto texture = this->textureByLock[id];
assertNotNull(texture, "TrueTypeAsset::TrueTypeAsset: Texture cannot be null");
assertNotNull(texture, "Texture cannot be null");
std::vector<usagelockid_t> &lbt = this->locksByTexture[texture];
auto it0 = std::find(lbt.begin(), lbt.end(), id);
assertTrue(it0 != lbt.end(), "TrueTypeAsset::TrueTypeAsset: Could not remove locksByTexture[texture]");
assertTrue(it0 != lbt.end(), "Could not remove locksByTexture[texture]");
lbt.erase(it0);
auto it1 = this->textureByLock.find(id);
assertTrue(it1 != this->textureByLock.end(), "TrueTypeAsset::TrueTypeAsset: Could not remove textureByLock");
assertTrue(it1 != this->textureByLock.end(), "Could not remove textureByLock");
this->textureByLock.erase(it1);
if(lbt.empty()) {
auto it2 = locksByTexture.find(texture);
assertTrue(it2 != locksByTexture.end(), "TrueTypeAsset::TrueTypeAsset: Could not remove locksByTexture");
assertTrue(it2 != locksByTexture.end(), "Could not remove locksByTexture");
locksByTexture.erase(it2);
auto it3 = textureByStyle.begin();
@ -38,7 +39,7 @@ TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) :
}
auto it4 = std::find(textures.begin(), textures.end(), texture);
assertTrue(it4 != textures.end(), "TrueTypeAsset::TrueTypeAsset: Could not remove textureByStyle");
assertTrue(it4 != textures.end(), "Could not remove textureByStyle");
textures.erase(it4);
delete texture;
@ -61,40 +62,49 @@ void TrueTypeAsset::updateAsync() {
uint8_t buffer[64];
this->loader.rewind();
size_t read = this->loader.read(buffer, sizeof(char) * 6);
assertTrue(read == (6 * sizeof(char)), "TrueTypeAsset::updateAsync: Could not read header");
assertTrue(read == (6 * sizeof(char)), "Could not read header");
buffer[6] = '\0';
// Confirm "DE_TTF"
assertTrue(std::string((char *)buffer) == "DE_TTF", "TrueTypeAsset::updateAsync: Header is invalid (Missing DE_TTF)");
assertTrue(
std::string((char *)buffer) == "DE_TTF",
"Header is invalid (Missing DE_TTF)"
);
// Vertical bar
this->loader.read(buffer, 1);
assertTrue(buffer[0] == '|', "TrueTypeAsset::updateAsync: Header is invalid (Missing first vertical bar)");
assertTrue(
buffer[0] == '|',
"Header is invalid (Missing first vertical bar)"
);
// Read version
this->state = TRUE_TYPE_ASSET_STATE_VALIDATE_VERSION;
read = this->loader.read(buffer, sizeof(char) * 5);
assertTrue(buffer[0] == '3', "TrueTypeAsset::updateAsync: Version is invalid 3");
assertTrue(buffer[1] == '.', "TrueTypeAsset::updateAsync: Version is invalid .");
assertTrue(buffer[2] == '0', "TrueTypeAsset::updateAsync: Version is invalid 0(1)");
assertTrue(buffer[3] == '0', "TrueTypeAsset::updateAsync: Version is invalid 0(2)");
assertTrue(buffer[4] == '|', "TrueTypeAsset::updateAsync: Version is invalid (Missing second vertical bar)");
assertTrue(buffer[0] == '3', "Version is invalid 3");
assertTrue(buffer[1] == '.', "Version is invalid .");
assertTrue(buffer[2] == '0', "Version is invalid 0(1)");
assertTrue(buffer[3] == '0', "Version is invalid 0(2)");
assertTrue(
buffer[4] == '|',
"Version is invalid (Missing second vertical bar)"
);
// Read the count of font styles / variants.
size_t styleListBegin = this->loader.getPosition();
this->state = TRUE_TYPE_ASSET_STATE_READ_VARIANT_COUNT;
read = this->loader.read(buffer, 64);
assertTrue(read > 0, "TrueTypeAsset::updateAsync: Could not read variant count");
assertTrue(read > 0, "Could not read variant count");
// Get position of vertical bar.
size_t i = 0;
while(buffer[i] != '|' && i < 64) i++;
assertTrue(buffer[i] == '|', "TrueTypeAsset::updateAsync: Could not find vertical bar");
assertTrue(buffer[i] == '|', "Could not find vertical bar");
styleListBegin += i + 1;
buffer[i] = '\0';
int32_t count = atoi((char *)buffer);
assertTrue(count > 0, "TrueTypeAsset::updateAsync: Invalid variant count");
assertTrue(count > 0, "Invalid variant count");
// Now begin parsing each font style.
this->state = TRUE_TYPE_ASSET_STATE_READ_VARIANT;
@ -105,7 +115,7 @@ void TrueTypeAsset::updateAsync() {
// Buffer
this->loader.setPosition(styleListBegin);
read = this->loader.read(buffer, 32);
assertTrue(read == 32, "TrueTypeAsset::updateAsync: Could not read variant");
assertTrue(read == 32, "Could not read variant");
// Read style
i = 0;
@ -117,7 +127,7 @@ void TrueTypeAsset::updateAsync() {
// Buffer
this->loader.setPosition(styleListBegin);
read = this->loader.read(buffer, 32);
assertTrue(read == 32, "TrueTypeAsset::updateAsync: Could not read variant style");
assertTrue(read == 32, "Could not read variant style");
// Read length
i = 0;
@ -143,7 +153,7 @@ void TrueTypeAsset::updateAsync() {
// Init FreeType
this->state = TRUE_TYPE_ASSET_STATE_INIT_FREETYPE;
int32_t ret = FT_Init_FreeType(&fontLibrary);
assertTrue(ret == 0, "TrueTypeAsset::updateAsync: Could not init FreeType");
assertTrue(ret == 0, "Could not init FreeType");
// Done parsing!
this->state = TRUE_TYPE_ASSET_STATE_READY;
@ -151,7 +161,7 @@ void TrueTypeAsset::updateAsync() {
}
usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
assertTrue(this->state == TRUE_TYPE_ASSET_STATE_READY, "TrueTypeAsset::lock: Asset is not ready");
assertTrue(this->state == TRUE_TYPE_ASSET_STATE_READY, "Asset is not ready");
// Try and find an existing texture that matches this style
auto it = this->textureByStyle.find(style);
@ -159,27 +169,35 @@ usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
if(it == this->textureByStyle.end()) {
// Does not exist, Find asset style
auto itAssetStyle = this->assetStyles.begin();
while(itAssetStyle != this->assetStyles.end()) {
if((*itAssetStyle).style == style.style) {
// Found
break;
auto itAssetStyle = std::find_if(
assetStyles.begin(),
assetStyles.end(),
[&](const struct TrueTypeAssetStyle &assetStyle) {
return assetStyle.style == style.style;
}
++itAssetStyle;
}
assertTrue(itAssetStyle != this->assetStyles.end(), "TrueTypeAsset::lock: Could not find asset style");
);
assertTrue(
itAssetStyle != this->assetStyles.end(),
"Could not find asset style"
);
// Create and read buffer.
uint8_t *dataBuffer = (uint8_t*)memoryAllocate(sizeof(uint8_t) * itAssetStyle->dataSize);
uint8_t *dataBuffer = memoryAllocate<uint8_t>(itAssetStyle->dataSize);
this->loader.rewind();
this->loader.setPosition(itAssetStyle->dataOffset);
auto read = this->loader.read(dataBuffer, itAssetStyle->dataSize);
assertTrue(read == itAssetStyle->dataSize, "TrueTypeAsset::lock: Could not read data");
assertTrue(read == itAssetStyle->dataSize, "Could not read data");
// Create the face
FT_Face face;
auto ret = FT_New_Memory_Face(this->fontLibrary, (FT_Byte*)dataBuffer, itAssetStyle->dataSize, 0, &face);
assertTrue(ret == 0, "TrueTypeAsset::lock: Could not create face");
auto ret = FT_New_Memory_Face(
this->fontLibrary,
(FT_Byte*)dataBuffer,
itAssetStyle->dataSize,
0,
&face
);
assertTrue(ret == 0, "Could not create face");
texture = new TrueTypeFaceTexture(face, style);
memoryFree(dataBuffer);
@ -198,7 +216,7 @@ usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
TrueTypeFaceTexture * TrueTypeAsset::getTexture(usagelockid_t id) {
auto it = this->textureByLock.find(id);
assertTrue(it != this->textureByLock.end(), "TrueTypeAsset::getTexture: Could not find texture");
assertTrue(it != this->textureByLock.end(), "Could not find texture");
return it->second;
}
@ -214,4 +232,4 @@ TrueTypeAsset::~TrueTypeAsset() {
}
FT_Done_FreeType(this->fontLibrary);
}
}

View File

@ -72,4 +72,4 @@ namespace Dawn {
~TrueTypeAsset();
};
}
}

View File

@ -5,7 +5,7 @@
#pragma once
#include "state/StateEvent.hpp"
#include "asset/AssetManager.hpp"
#include "asset/assets/LanguageAsset.hpp"
namespace Dawn {
class DawnGame;

View File

@ -34,7 +34,10 @@ static void * memoryCallRealloc(void *p, size_t newSize) {
* @param size Size of the array you wish to buffer.
* @return Pointer to the space in memory to use.
*/
void * memoryAllocate(const size_t size);
template<typename T>
T * memoryAllocate(const size_t size) {
return (T*)memoryCallMalloc(size * sizeof(T));
}
/**
* Allocate space in memory, where all values are set to 0 (in binary space).

View File

@ -73,7 +73,7 @@ void Texture::setSize(
}
void Texture::fill(struct Color color) {
struct Color *pixels = (struct Color *)memoryAllocate(
auto pixels = memoryAllocate<struct Color>(
sizeof(struct Color) * this->width * this->height
);
this->buffer(pixels);
@ -81,7 +81,7 @@ void Texture::fill(struct Color color) {
}
void Texture::fill(uint8_t color) {
uint8_t *pixels = (uint8_t *)memoryAllocate(
auto pixels = memoryAllocate<uint8_t>(
sizeof(uint8_t) * this->width * this->height
);
this->buffer(pixels);