Commit 34e86278 authored by mercury233's avatar mercury233 Committed by GitHub

minor tweaks to ImageManager (#2962)

* update readme

* removeTexture tFields on ClearTexture

* fix textureName

* minor speed optimization
parent 17f3ec4c
...@@ -57,7 +57,6 @@ Xyz materials: ...@@ -57,7 +57,6 @@ Xyz materials:
### Directories: ### Directories:
* pics: .jpg card images(177*254). * pics: .jpg card images(177*254).
* pics\thumbnail: .jpg thumbnail images(44*64).
* script: .lua script files. * script: .lua script files.
* textures: Other image files. * textures: Other image files.
* deck: .ydk deck files. * deck: .ydk deck files.
......
...@@ -65,6 +65,10 @@ void ImageManager::ClearTexture() { ...@@ -65,6 +65,10 @@ void ImageManager::ClearTexture() {
if(tit->second && tit->second != tLoading) if(tit->second && tit->second != tLoading)
driver->removeTexture(tit->second); driver->removeTexture(tit->second);
} }
for(auto tit = tFields.begin(); tit != tFields.end(); ++tit) {
if(tit->second)
driver->removeTexture(tit->second);
}
if(tBigPicture != nullptr) { if(tBigPicture != nullptr) {
driver->removeTexture(tBigPicture); driver->removeTexture(tBigPicture);
tBigPicture = nullptr; tBigPicture = nullptr;
...@@ -72,13 +76,13 @@ void ImageManager::ClearTexture() { ...@@ -72,13 +76,13 @@ void ImageManager::ClearTexture() {
tMap[0].clear(); tMap[0].clear();
tMap[1].clear(); tMap[1].clear();
tThumb.clear(); tThumb.clear();
tFields.clear();
tThumbLoadingMutex.lock(); tThumbLoadingMutex.lock();
tThumbLoading.clear(); tThumbLoading.clear();
while(!tThumbLoadingCodes.empty()) while(!tThumbLoadingCodes.empty())
tThumbLoadingCodes.pop(); tThumbLoadingCodes.pop();
tThumbLoadingThreadRunning = false; tThumbLoadingThreadRunning = false;
tThumbLoadingMutex.unlock(); tThumbLoadingMutex.unlock();
tFields.clear();
} }
void ImageManager::ResizeTexture() { void ImageManager::ResizeTexture() {
irr::s32 imgWidth = CARD_IMG_WIDTH * mainGame->xScale; irr::s32 imgWidth = CARD_IMG_WIDTH * mainGame->xScale;
...@@ -316,10 +320,10 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) { ...@@ -316,10 +320,10 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
return tUnknownThumb; return tUnknownThumb;
auto tit = tThumb.find(code); auto tit = tThumb.find(code);
if(tit == tThumb.end() && !mainGame->gameConf.use_image_load_background_thread) { if(tit == tThumb.end() && !mainGame->gameConf.use_image_load_background_thread) {
char file[256];
mysnprintf(file, "expansions/pics/%d.jpg", code);
int width = CARD_THUMB_WIDTH * mainGame->xScale; int width = CARD_THUMB_WIDTH * mainGame->xScale;
int height = CARD_THUMB_HEIGHT * mainGame->yScale; int height = CARD_THUMB_HEIGHT * mainGame->yScale;
char file[256];
mysnprintf(file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == NULL) { if(img == NULL) {
mysnprintf(file, "pics/%d.jpg", code); mysnprintf(file, "pics/%d.jpg", code);
...@@ -333,9 +337,9 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) { ...@@ -333,9 +337,9 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
auto lit = tThumbLoading.find(code); auto lit = tThumbLoading.find(code);
if(lit != tThumbLoading.end()) { if(lit != tThumbLoading.end()) {
if(lit->second != nullptr) { if(lit->second != nullptr) {
char file[256]; char textureName[256];
mysnprintf(file, "pics/%d.jpg", code); mysnprintf(textureName, "pics/%d.jpg_thumbnail", code); // not an actual file
irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL irr::video::ITexture* texture = driver->addTexture(textureName, lit->second); // textures must be added in the main thread due to OpenGL
lit->second->drop(); lit->second->drop();
tThumb[code] = texture; tThumb[code] = texture;
} else { } else {
...@@ -367,20 +371,22 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) { ...@@ -367,20 +371,22 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
return nullptr; return nullptr;
auto tit = tFields.find(code); auto tit = tFields.find(code);
if(tit == tFields.end()) { if(tit == tFields.end()) {
irr::s32 width = 512 * mainGame->xScale;
irr::s32 height = 512 * mainGame->yScale;
char file[256]; char file[256];
mysnprintf(file, "expansions/pics/field/%d.png", code); mysnprintf(file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == nullptr) { if(img == nullptr) {
mysnprintf(file, "expansions/pics/field/%d.jpg", code); mysnprintf(file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, width, height);
} }
if(img == nullptr) { if(img == nullptr) {
mysnprintf(file, "pics/field/%d.png", code); mysnprintf(file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, width, height);
} }
if(img == nullptr) { if(img == nullptr) {
mysnprintf(file, "pics/field/%d.jpg", code); mysnprintf(file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, width, height);
if(img == nullptr) { if(img == nullptr) {
tFields[code] = nullptr; tFields[code] = nullptr;
return nullptr; return nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment