mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-29 19:55:37 +00:00
Use canonical path names for resource lookup (Font, TextureResource).
Fixes "./../art/file.png" causing duplicates when used in multiple systems, even if it refers to the same file. Remove debug messages for SVGResource and ImageComponent.
This commit is contained in:
parent
1e7ced2c66
commit
b15f3aeec0
|
@ -1,4 +1,5 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
std::string strToUpper(const char* from)
|
std::string strToUpper(const char* from)
|
||||||
{
|
{
|
||||||
|
@ -59,3 +60,11 @@ Eigen::Vector2f roundVector(const Eigen::Vector2f& vec)
|
||||||
ret[1] = round(ret[1]);
|
ret[1] = round(ret[1]);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getCanonicalPath(const std::string& path)
|
||||||
|
{
|
||||||
|
if(boost::filesystem::exists(path))
|
||||||
|
return boost::filesystem::canonical(path).generic_string();
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
|
@ -12,3 +12,5 @@ Eigen::Vector3f roundVector(const Eigen::Vector3f& vec);
|
||||||
Eigen::Vector2f roundVector(const Eigen::Vector2f& vec);
|
Eigen::Vector2f roundVector(const Eigen::Vector2f& vec);
|
||||||
|
|
||||||
float round(float num);
|
float round(float num);
|
||||||
|
|
||||||
|
std::string getCanonicalPath(const std::string& str);
|
|
@ -283,14 +283,11 @@ bool ImageComponent::hasImage()
|
||||||
|
|
||||||
void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties)
|
void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties)
|
||||||
{
|
{
|
||||||
LOG(LogInfo) << " req image [" << view << "." << element << "] (flags: " << properties << ")";
|
|
||||||
|
|
||||||
using namespace ThemeFlags;
|
using namespace ThemeFlags;
|
||||||
|
|
||||||
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "image");
|
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "image");
|
||||||
if(!elem)
|
if(!elem)
|
||||||
{
|
{
|
||||||
LOG(LogInfo) << " (missing)";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,9 @@ void Font::unload(std::shared_ptr<ResourceManager>& rm)
|
||||||
|
|
||||||
std::shared_ptr<Font> Font::get(int size, const std::string& path)
|
std::shared_ptr<Font> Font::get(int size, const std::string& path)
|
||||||
{
|
{
|
||||||
std::pair<std::string, int> def(path.empty() ? getDefaultPath() : path, size);
|
const std::string canonicalPath = getCanonicalPath(path);
|
||||||
|
|
||||||
|
std::pair<std::string, int> def(canonicalPath.empty() ? getDefaultPath() : canonicalPath, size);
|
||||||
auto foundFont = sFontMap.find(def);
|
auto foundFont = sFontMap.find(def);
|
||||||
if(foundFont != sFontMap.end())
|
if(foundFont != sFontMap.end())
|
||||||
{
|
{
|
||||||
|
|
|
@ -69,10 +69,6 @@ void SVGResource::rasterizeAt(size_t width, size_t height)
|
||||||
mLastHeight = height;
|
mLastHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(LogInfo) << "Rasterizing \"" << mPath << "\"...";
|
|
||||||
LOG(LogInfo) << " Original width: " << mSVGImage->width << ", original height: " << mSVGImage->height;
|
|
||||||
LOG(LogInfo) << " width: " << width << ", height: " << height << ", scale: " << height / mSVGImage->height;
|
|
||||||
|
|
||||||
unsigned char* imagePx = (unsigned char*)malloc(width * height * 4);
|
unsigned char* imagePx = (unsigned char*)malloc(width * height * 4);
|
||||||
|
|
||||||
NSVGrasterizer* rast = nsvgCreateRasterizer();
|
NSVGrasterizer* rast = nsvgCreateRasterizer();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include GLHEADER
|
#include GLHEADER
|
||||||
#include "../ImageIO.h"
|
#include "../ImageIO.h"
|
||||||
#include "../Renderer.h"
|
#include "../Renderer.h"
|
||||||
|
#include "../Util.h"
|
||||||
#include "SVGResource.h"
|
#include "SVGResource.h"
|
||||||
|
|
||||||
std::map< TextureResource::TextureKeyType, std::weak_ptr<TextureResource> > TextureResource::sTextureMap;
|
std::map< TextureResource::TextureKeyType, std::weak_ptr<TextureResource> > TextureResource::sTextureMap;
|
||||||
|
@ -102,14 +102,16 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path, b
|
||||||
{
|
{
|
||||||
std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance();
|
std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance();
|
||||||
|
|
||||||
if(path.empty())
|
const std::string canonicalPath = getCanonicalPath(path);
|
||||||
|
|
||||||
|
if(canonicalPath.empty())
|
||||||
{
|
{
|
||||||
std::shared_ptr<TextureResource> tex(new TextureResource("", tile));
|
std::shared_ptr<TextureResource> tex(new TextureResource("", tile));
|
||||||
rm->addReloadable(tex); //make sure we get properly deinitialized even though we do nothing on reinitialization
|
rm->addReloadable(tex); //make sure we get properly deinitialized even though we do nothing on reinitialization
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureKeyType key(path, tile);
|
TextureKeyType key(canonicalPath, tile);
|
||||||
auto foundTexture = sTextureMap.find(key);
|
auto foundTexture = sTextureMap.find(key);
|
||||||
if(foundTexture != sTextureMap.end())
|
if(foundTexture != sTextureMap.end())
|
||||||
{
|
{
|
||||||
|
@ -121,18 +123,18 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path, b
|
||||||
std::shared_ptr<TextureResource> tex;
|
std::shared_ptr<TextureResource> tex;
|
||||||
|
|
||||||
// is it an SVG?
|
// is it an SVG?
|
||||||
if(path.substr(path.size() - 4, std::string::npos) == ".svg")
|
if(key.first.substr(key.first.size() - 4, std::string::npos) == ".svg")
|
||||||
{
|
{
|
||||||
// probably
|
// probably
|
||||||
// don't add it to our map because 2 svgs might be rasterized at different sizes
|
// don't add it to our map because 2 svgs might be rasterized at different sizes
|
||||||
tex = std::shared_ptr<SVGResource>(new SVGResource(path, tile));
|
tex = std::shared_ptr<SVGResource>(new SVGResource(key.first, tile));
|
||||||
sTextureList.push_back(tex); // add it to our list though
|
sTextureList.push_back(tex); // add it to our list though
|
||||||
rm->addReloadable(tex);
|
rm->addReloadable(tex);
|
||||||
tex->reload(rm);
|
tex->reload(rm);
|
||||||
return tex;
|
return tex;
|
||||||
}else{
|
}else{
|
||||||
// normal texture
|
// normal texture
|
||||||
tex = std::shared_ptr<TextureResource>(new TextureResource(path, tile));
|
tex = std::shared_ptr<TextureResource>(new TextureResource(key.first, tile));
|
||||||
sTextureMap[key] = std::weak_ptr<TextureResource>(tex);
|
sTextureMap[key] = std::weak_ptr<TextureResource>(tex);
|
||||||
sTextureList.push_back(tex);
|
sTextureList.push_back(tex);
|
||||||
rm->addReloadable(tex);
|
rm->addReloadable(tex);
|
||||||
|
|
Loading…
Reference in a new issue