Fixed bug with VN scrolling

This commit is contained in:
2023-06-18 10:00:28 -07:00
parent 79556955ef
commit 318615c3b4
7 changed files with 56 additions and 14 deletions

View File

@ -12,7 +12,38 @@ TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) :
Asset(assMan, name),
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() {
@ -161,8 +192,9 @@ usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
texture = it->second;
}
auto lock = texture->locks.createLock();
auto lock = this->locks.createLock();
this->textureByLock[lock] = texture;
this->locksByTexture[texture].push_back(lock);
return lock;
}
@ -173,10 +205,7 @@ TrueTypeFaceTexture * TrueTypeAsset::getTexture(usagelockid_t id) {
}
void TrueTypeAsset::unlock(usagelockid_t id) {
auto it = this->textureByLock.find(id);
assertTrue(it != this->textureByLock.end());
it->second->locks.removeLock(id);
this->textureByLock.erase(it);
this->locks.removeLock(id);
}
TrueTypeAsset::~TrueTypeAsset() {

View File

@ -8,6 +8,7 @@
#include "../AssetLoader.hpp"
#include "util/flag.hpp"
#include "display/font/truetype/TrueTypeFaceTexture.hpp"
#include "util/UsageLock.hpp"
namespace Dawn {
enum TrueTypeAssetState {
@ -30,6 +31,7 @@ namespace Dawn {
class TrueTypeAsset : public Asset {
protected:
UsageLock locks;
AssetLoader loader;
FT_Library fontLibrary;
enum TrueTypeAssetState state = TRUE_TYPE_ASSET_STATE_INITIAL;
@ -37,6 +39,7 @@ namespace Dawn {
std::vector<TrueTypeFaceTexture*> textures;
std::map<usagelockid_t, TrueTypeFaceTexture*> textureByLock;
std::map<struct TrueTypeFaceTextureStyle, TrueTypeFaceTexture*> textureByStyle;
std::map<TrueTypeFaceTexture*, std::vector<usagelockid_t>> locksByTexture;
public:
TrueTypeAsset(AssetManager *assMan, std::string name);