Fixed bug with VN scrolling
This commit is contained in:
		| @@ -12,7 +12,38 @@ TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) : | |||||||
|   Asset(assMan, name), |   Asset(assMan, name), | ||||||
|   loader(name + ".truetype") |   loader(name + ".truetype") | ||||||
| { | { | ||||||
|  |   this->locks.onLockRemoved = [&](usagelockid_t id){ | ||||||
|  |     auto texture = this->textureByLock[id]; | ||||||
|  |  | ||||||
|  |     assertNotNull(texture); | ||||||
|  |  | ||||||
|  |     std::vector<usagelockid_t> &lbt = this->locksByTexture[texture]; | ||||||
|  |     auto it0 = std::find(lbt.begin(), lbt.end(), id); | ||||||
|  |     assertTrue(it0 != lbt.end()); | ||||||
|  |     lbt.erase(it0); | ||||||
|  |  | ||||||
|  |     auto it1 = this->textureByLock.find(id); | ||||||
|  |     assertTrue(it1 != this->textureByLock.end()); | ||||||
|  |     this->textureByLock.erase(it1); | ||||||
|  |  | ||||||
|  |     if(lbt.empty()) {       | ||||||
|  |       auto it2 = locksByTexture.find(texture); | ||||||
|  |       assertTrue(it2 != locksByTexture.end()); | ||||||
|  |       locksByTexture.erase(it2); | ||||||
|  |        | ||||||
|  |       auto it3 = textureByStyle.begin(); | ||||||
|  |       while(it3 != textureByStyle.end()) { | ||||||
|  |         if(it3->second == texture) it3 = textureByStyle.erase(it3); | ||||||
|  |         ++it3; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       auto it4 = std::find(textures.begin(), textures.end(), texture); | ||||||
|  |       assertTrue(it4 != textures.end()); | ||||||
|  |       textures.erase(it4); | ||||||
|  |  | ||||||
|  |       delete texture; | ||||||
|  |     } | ||||||
|  |   }; | ||||||
| } | } | ||||||
|  |  | ||||||
| void TrueTypeAsset::updateSync() { | void TrueTypeAsset::updateSync() { | ||||||
| @@ -161,8 +192,9 @@ usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) { | |||||||
|     texture = it->second; |     texture = it->second; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   auto lock = texture->locks.createLock(); |   auto lock = this->locks.createLock(); | ||||||
|   this->textureByLock[lock] = texture; |   this->textureByLock[lock] = texture; | ||||||
|  |   this->locksByTexture[texture].push_back(lock); | ||||||
|   return lock; |   return lock; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -173,10 +205,7 @@ TrueTypeFaceTexture * TrueTypeAsset::getTexture(usagelockid_t id) { | |||||||
| } | } | ||||||
|  |  | ||||||
| void TrueTypeAsset::unlock(usagelockid_t id) { | void TrueTypeAsset::unlock(usagelockid_t id) { | ||||||
|   auto it = this->textureByLock.find(id); |   this->locks.removeLock(id); | ||||||
|   assertTrue(it != this->textureByLock.end()); |  | ||||||
|   it->second->locks.removeLock(id); |  | ||||||
|   this->textureByLock.erase(it); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| TrueTypeAsset::~TrueTypeAsset() { | TrueTypeAsset::~TrueTypeAsset() { | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ | |||||||
| #include "../AssetLoader.hpp" | #include "../AssetLoader.hpp" | ||||||
| #include "util/flag.hpp" | #include "util/flag.hpp" | ||||||
| #include "display/font/truetype/TrueTypeFaceTexture.hpp" | #include "display/font/truetype/TrueTypeFaceTexture.hpp" | ||||||
|  | #include "util/UsageLock.hpp" | ||||||
|  |  | ||||||
| namespace Dawn { | namespace Dawn { | ||||||
|   enum TrueTypeAssetState { |   enum TrueTypeAssetState { | ||||||
| @@ -30,6 +31,7 @@ namespace Dawn { | |||||||
|  |  | ||||||
|   class TrueTypeAsset : public Asset { |   class TrueTypeAsset : public Asset { | ||||||
|     protected: |     protected: | ||||||
|  |       UsageLock locks; | ||||||
|       AssetLoader loader; |       AssetLoader loader; | ||||||
|       FT_Library fontLibrary; |       FT_Library fontLibrary; | ||||||
|       enum TrueTypeAssetState state = TRUE_TYPE_ASSET_STATE_INITIAL; |       enum TrueTypeAssetState state = TRUE_TYPE_ASSET_STATE_INITIAL; | ||||||
| @@ -37,6 +39,7 @@ namespace Dawn { | |||||||
|       std::vector<TrueTypeFaceTexture*> textures; |       std::vector<TrueTypeFaceTexture*> textures; | ||||||
|       std::map<usagelockid_t, TrueTypeFaceTexture*> textureByLock; |       std::map<usagelockid_t, TrueTypeFaceTexture*> textureByLock; | ||||||
|       std::map<struct TrueTypeFaceTextureStyle, TrueTypeFaceTexture*> textureByStyle; |       std::map<struct TrueTypeFaceTextureStyle, TrueTypeFaceTexture*> textureByStyle; | ||||||
|  |       std::map<TrueTypeFaceTexture*, std::vector<usagelockid_t>> locksByTexture; | ||||||
|  |  | ||||||
|     public: |     public: | ||||||
|       TrueTypeAsset(AssetManager *assMan, std::string name); |       TrueTypeAsset(AssetManager *assMan, std::string name); | ||||||
|   | |||||||
| @@ -15,10 +15,6 @@ TrueTypeFaceTexture::TrueTypeFaceTexture( | |||||||
|  |  | ||||||
|   this->face = face; |   this->face = face; | ||||||
|   this->style = style; |   this->style = style; | ||||||
|    |  | ||||||
|   this->locks.onEmpty = [&]() { |  | ||||||
|     assertUnreachable(); |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   // Set freetype font size prior to baking. |   // Set freetype font size prior to baking. | ||||||
|   if(FT_Set_Pixel_Sizes(face, 0, style.fontSize)) { |   if(FT_Set_Pixel_Sizes(face, 0, style.fontSize)) { | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ | |||||||
| #include "display/font/truetype/TrueTypeShared.hpp" | #include "display/font/truetype/TrueTypeShared.hpp" | ||||||
| #include "util/mathutils.hpp" | #include "util/mathutils.hpp" | ||||||
| #include "display/Texture.hpp" | #include "display/Texture.hpp" | ||||||
| #include "util/UsageLock.hpp" |  | ||||||
|  |  | ||||||
| namespace Dawn { | namespace Dawn { | ||||||
|   class TrueTypeAsset; |   class TrueTypeAsset; | ||||||
| @@ -34,7 +33,6 @@ namespace Dawn { | |||||||
|       FT_Face face; |       FT_Face face; | ||||||
|       std::map<FT_ULong, struct TrueTypeCharacter> characterData; |       std::map<FT_ULong, struct TrueTypeCharacter> characterData; | ||||||
|       struct TrueTypeFaceTextureStyle style; |       struct TrueTypeFaceTextureStyle style; | ||||||
|       UsageLock locks; |  | ||||||
|       Texture texture; |       Texture texture; | ||||||
|  |  | ||||||
|       /** |       /** | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ void VNTextboxScroller::onStart() { | |||||||
|     this->timeCharacter = 0; |     this->timeCharacter = 0; | ||||||
|     this->label->quadStart = 0; |     this->label->quadStart = 0; | ||||||
|     this->label->quadCount = 0; |     this->label->quadCount = 0; | ||||||
|  |     this->label->textOffset = glm::vec2(); | ||||||
|     this->readyToClose = false; |     this->readyToClose = false; | ||||||
|   }; |   }; | ||||||
|   x(); |   x(); | ||||||
|   | |||||||
| @@ -7,13 +7,18 @@ | |||||||
|  |  | ||||||
| using namespace Dawn; | using namespace Dawn; | ||||||
|  |  | ||||||
| UsageLock::UsageLock() { | UsageLock::UsageLock() : UsageLock(&this->internalPool) { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | UsageLock::UsageLock(usagelockid_t *lockPool) { | ||||||
|  |   assertNotNull(lockPool); | ||||||
|  |   this->pool = lockPool; | ||||||
|   this->onEmpty = []() {}; |   this->onEmpty = []() {}; | ||||||
|   this->onFirstLock = []() {}; |   this->onFirstLock = []() {}; | ||||||
| } | } | ||||||
|  |  | ||||||
| usagelockid_t UsageLock::createLock() { | usagelockid_t UsageLock::createLock() { | ||||||
|   usagelockid_t lock = this->nextLock++; |   usagelockid_t lock = (*this->pool)++; | ||||||
|   this->locks.push_back(lock); |   this->locks.push_back(lock); | ||||||
|   if(this->locks.size() == 1) this->onFirstLock(); |   if(this->locks.size() == 1) this->onFirstLock(); | ||||||
|   return lock; |   return lock; | ||||||
| @@ -23,5 +28,6 @@ void UsageLock::removeLock(usagelockid_t lock) { | |||||||
|   auto it = std::find(this->locks.begin(), this->locks.end(), lock); |   auto it = std::find(this->locks.begin(), this->locks.end(), lock); | ||||||
|   if(it == this->locks.end()) return; |   if(it == this->locks.end()) return; | ||||||
|   this->locks.erase(it); |   this->locks.erase(it); | ||||||
|  |   this->onLockRemoved(lock); | ||||||
|   if(this->locks.size() == 0) this->onEmpty(); |   if(this->locks.size() == 0) this->onEmpty(); | ||||||
| } | } | ||||||
| @@ -10,18 +10,27 @@ namespace Dawn { | |||||||
|  |  | ||||||
|   class UsageLock { |   class UsageLock { | ||||||
|     protected: |     protected: | ||||||
|       usagelockid_t nextLock = 0; |       usagelockid_t internalPool = 0; | ||||||
|  |       usagelockid_t *pool = nullptr; | ||||||
|       std::vector<usagelockid_t> locks; |       std::vector<usagelockid_t> locks; | ||||||
|  |  | ||||||
|     public: |     public: | ||||||
|       std::function<void()> onEmpty; |       std::function<void()> onEmpty; | ||||||
|       std::function<void()> onFirstLock; |       std::function<void()> onFirstLock; | ||||||
|  |       std::function<void(usagelockid_t)> onLockRemoved; | ||||||
|  |  | ||||||
|       /** |       /** | ||||||
|        * Construct a new usage lock object. |        * Construct a new usage lock object. | ||||||
|        */ |        */ | ||||||
|       UsageLock(); |       UsageLock(); | ||||||
|  |  | ||||||
|  |       /** | ||||||
|  |        * Construct a new Usage Lock object | ||||||
|  |        *  | ||||||
|  |        * @param lockPool Pool that will be used to create locks. | ||||||
|  |        */ | ||||||
|  |       UsageLock(usagelockid_t *lockPool); | ||||||
|  |  | ||||||
|       /** |       /** | ||||||
|        * Creates a new lock. |        * Creates a new lock. | ||||||
|        *  |        *  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user