1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Refactor texturepaths.cpp and SourceImageCache

This commit is contained in:
cx384 2024-03-17 15:04:40 +01:00 committed by sfan5
parent 6ac053bbaa
commit 673d2499e8
3 changed files with 80 additions and 128 deletions

View file

@ -23,10 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string>
#include "settings.h"
// This file is only for internal generation/modification of images.
// Use texturesource.h instead to handle textures.
// This file is only used for internal generation of images.
// Use texturesource.h to handle textures.
// A cache used for storing source images.
// (A "source image" is an unmodified image directly taken from the filesystem.)
// Does not contain modified images.
class SourceImageCache {
public:
~SourceImageCache();
@ -35,16 +37,13 @@ public:
video::IImage* get(const std::string &name);
// Primarily fetches from cache, secondarily tries to read from filesystem
// Primarily fetches from cache, secondarily tries to read from filesystem.
video::IImage *getOrLoad(const std::string &name);
private:
std::map<std::string, video::IImage*> m_images;
};
/*
* Generates and caches images.
* The image name defines the image by filename and texture modifiers.
*/
// Generates images using texture modifiers, and caches source images.
struct ImageSource {
/*! Generates an image from a full string like
* "stone.png^mineral_coal.png^[crack:1:0".
@ -53,8 +52,8 @@ struct ImageSource {
*/
video::IImage* generateImage(std::string_view name, std::set<std::string> &source_image_names);
// To add self made images.
void insertImage(const std::string &name, video::IImage *img, bool prefer_local);
// Insert a source image into the cache without touching the filesystem.
void insertSourceImage(const std::string &name, video::IImage *img, bool prefer_local);
// TODO should probably be moved elsewhere
static video::SColor getImageAverageColor(const video::IImage &image);
@ -69,9 +68,10 @@ struct ImageSource {
private:
// Generate image based on a string like "stone.png" or "[crack:1:0".
// if baseimg is NULL, it is created. Otherwise stuff is made on it.
// source_image_names is important to determine when to flush the image from a cache (dynamic media)
bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg, std::set<std::string> &source_image_names);
// If baseimg is NULL, it is created. Otherwise stuff is made on it.
// source_image_names is important to determine when to flush the image from a cache (dynamic media).
bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg,
std::set<std::string> &source_image_names);
// Cached settings needed for making textures from meshes
bool m_setting_mipmap;