Sunset old state system finally.

This commit is contained in:
2023-11-02 12:36:14 -05:00
parent 62d207d066
commit 239f7b2fb9
32 changed files with 212 additions and 420 deletions

View File

@ -64,7 +64,7 @@ void LanguageAsset::updateAsync() {
this->loaded = true;
}
std::string LanguageAsset::getValue(std::string key) {
std::string LanguageAsset::getValue(const std::string key) {
assertTrue(
this->state == LANGUAGE_ASSET_LOAD_STATE_READY_TO_READ,
"State must be LANGUAGE_ASSET_LOAD_STATE_READY_TO_READ"

View File

@ -31,6 +31,6 @@ namespace Dawn {
LanguageAsset(const std::string name);
void updateSync() override;
void updateAsync() override;
std::string getValue(std::string key);
std::string getValue(const std::string key);
};
}

View File

@ -142,13 +142,15 @@ void TrueTypeAsset::updateAsync() {
// Now we are at the first byte of the first style.
this->state = TRUE_TYPE_ASSET_STATE_ADJUSTING_OFFSETS;
auto itStyle = assetStyles.begin();
while(itStyle != assetStyles.end()) {
(*itStyle).dataOffset = styleListBegin;
styleListBegin += (*itStyle).dataSize;
styleListBegin += 1; // Vertical bar
++itStyle;
}
std::for_each(
assetStyles.begin(),
assetStyles.end(),
[&](struct TrueTypeAssetStyle &style){
style.dataOffset = styleListBegin;
styleListBegin += style.dataSize;
styleListBegin += 1;
}
);
// Init FreeType
this->state = TRUE_TYPE_ASSET_STATE_INIT_FREETYPE;
@ -160,7 +162,7 @@ void TrueTypeAsset::updateAsync() {
this->loaded = true;
}
usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
usagelockid_t TrueTypeAsset::lock(const struct TrueTypeFaceTextureStyle style) {
assertTrue(this->state == TRUE_TYPE_ASSET_STATE_READY, "Asset is not ready");
// Try and find an existing texture that matches this style
@ -214,22 +216,24 @@ usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
return lock;
}
TrueTypeFaceTexture * TrueTypeAsset::getTexture(usagelockid_t id) {
TrueTypeFaceTexture * TrueTypeAsset::getTexture(const usagelockid_t id) {
auto it = this->textureByLock.find(id);
assertTrue(it != this->textureByLock.end(), "Could not find texture");
return it->second;
}
void TrueTypeAsset::unlock(usagelockid_t id) {
void TrueTypeAsset::unlock(const usagelockid_t id) {
this->locks.removeLock(id);
}
TrueTypeAsset::~TrueTypeAsset() {
auto it = this->textures.begin();
while(it != this->textures.end()) {
delete (*it);
it++;
}
std::for_each(
this->textures.begin(),
this->textures.end(),
[](TrueTypeFaceTexture *texture){
delete texture;
}
);
FT_Done_FreeType(this->fontLibrary);
}

View File

@ -55,7 +55,7 @@ namespace Dawn {
* @param style Style to lock.
* @return A unique lock ID for this style.
*/
usagelockid_t lock(struct TrueTypeFaceTextureStyle style);
usagelockid_t lock(const struct TrueTypeFaceTextureStyle style);
/**
* Get a texture by a previous lock ID.
@ -63,14 +63,14 @@ namespace Dawn {
* @param lock Lock to get the texture of.
* @return Matching texture by this ID.
*/
TrueTypeFaceTexture * getTexture(usagelockid_t lock);
TrueTypeFaceTexture * getTexture(const usagelockid_t lock);
/**
* Releases a previously held font lock.
*
* @param lock Lock to release/unlock.
*/
void unlock(usagelockid_t lock);
void unlock(const usagelockid_t lock);
~TrueTypeAsset();
};