mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Cache getTextureDirs()
This commit is contained in:
parent
0b9ae73369
commit
55cca34ee9
7 changed files with 37 additions and 59 deletions
|
@ -863,46 +863,17 @@ Game::Game() :
|
|||
m_chat_log_buf(g_logger),
|
||||
m_game_ui(new GameUI())
|
||||
{
|
||||
g_settings->registerChangedCallback("chat_log_level",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("doubletap_jump",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("toggle_sneak_key",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("toggle_aux1_key",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("enable_joysticks",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("enable_fog",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("mouse_sensitivity",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("joystick_frustum_sensitivity",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("repeat_place_time",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("repeat_dig_time",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("noclip",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("free_move",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("fog_start",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("cinematic",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("cinematic_camera_smoothing",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("camera_smoothing",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("invert_mouse",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("enable_hotbar_mouse_wheel",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("invert_hotbar_mouse_wheel",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("pause_on_lost_focus",
|
||||
&settingChangedCallback, this);
|
||||
clearTextureNameCache();
|
||||
|
||||
const char *settings[] = {
|
||||
"chat_log_level", "doubletap_jump", "toggle_sneak_key", "toggle_aux1_key",
|
||||
"enable_joysticks", "enable_fog", "mouse_sensitivity", "joystick_frustum_sensitivity",
|
||||
"repeat_place_time", "repeat_dig_time", "noclip", "free_move", "fog_start",
|
||||
"cinematic", "cinematic_camera_smoothing", "camera_smoothing", "invert_mouse",
|
||||
"enable_hotbar_mouse_wheel", "invert_hotbar_mouse_wheel", "pause_on_lost_focus",
|
||||
};
|
||||
for (auto s : settings)
|
||||
g_settings->registerChangedCallback(s, &settingChangedCallback, this);
|
||||
|
||||
readSettings();
|
||||
}
|
||||
|
@ -4254,11 +4225,6 @@ void the_game(volatile std::sig_atomic_t *kill,
|
|||
{
|
||||
Game game;
|
||||
|
||||
/* Make a copy of the server address because if a local singleplayer server
|
||||
* is created then this is updated and we don't want to change the value
|
||||
* passed to us by the calling function
|
||||
*/
|
||||
|
||||
try {
|
||||
|
||||
if (game.startup(kill, input, rendering_engine, start_data,
|
||||
|
|
|
@ -1113,7 +1113,7 @@ bool ImageSource::generateImagePart(std::string_view part_of_name,
|
|||
<< " for [combine" << std::endl;
|
||||
continue;
|
||||
}
|
||||
infostream << "Adding \"" << filename<< "\" to combined "
|
||||
tracestream << "Adding \"" << filename << "\" to combined "
|
||||
<< pos_base << std::endl;
|
||||
|
||||
video::IImage *img = generateImage(filename, source_image_names);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "texturepaths.h"
|
||||
|
||||
#include "util/container.h"
|
||||
#include "util/thread.h"
|
||||
#include "settings.h"
|
||||
#include "filesys.h"
|
||||
#include "porting.h"
|
||||
|
@ -12,10 +13,13 @@
|
|||
|
||||
// A cache from texture name to texture path
|
||||
static MutexedMap<std::string, std::string> g_texturename_to_path_cache;
|
||||
// Cached result of getTextureDirs()
|
||||
static MutexedVariable<std::vector<std::string>> g_texturedirs_cache;
|
||||
|
||||
void clearTextureNameCache()
|
||||
{
|
||||
g_texturename_to_path_cache.clear();
|
||||
g_texturedirs_cache.set({});
|
||||
}
|
||||
|
||||
// Find out the full path of an image by trying different filename extensions.
|
||||
|
@ -74,24 +78,28 @@ std::string getTexturePath(const std::string &filename, bool *is_base_pack)
|
|||
break;
|
||||
}
|
||||
|
||||
// Check from default data directory i.e. .../minetest/textures/base/pack
|
||||
// Check from default data directory
|
||||
if (fullpath.empty()) {
|
||||
std::string base_path = porting::path_share + DIR_DELIM + "textures"
|
||||
+ DIR_DELIM + "base" + DIR_DELIM + "pack";
|
||||
std::string base_path = porting::path_share + DIR_DELIM "textures"
|
||||
DIR_DELIM "base" DIR_DELIM "pack";
|
||||
// Check all filename extensions. Returns "" if not found.
|
||||
fullpath = getImagePath(base_path + DIR_DELIM + filename);
|
||||
if (is_base_pack && !fullpath.empty())
|
||||
*is_base_pack = true;
|
||||
}
|
||||
|
||||
// Add to cache (also an empty result is cached)
|
||||
// Add to cache (an empty result is cached too)
|
||||
g_texturename_to_path_cache.set(filename, fullpath);
|
||||
|
||||
// Finally return it
|
||||
return fullpath;
|
||||
}
|
||||
|
||||
std::vector<std::string> getTextureDirs()
|
||||
{
|
||||
return fs::GetRecursiveDirs(g_settings->get("texture_path"));
|
||||
std::vector<std::string> ret = g_texturedirs_cache.get();
|
||||
if (ret.empty()) {
|
||||
ret = fs::GetRecursiveDirs(g_settings->get("texture_path"));
|
||||
g_texturedirs_cache.set(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Texture paths get cached and this clears the Cache.
|
||||
// Texture paths get cached and this clears the cache.
|
||||
void clearTextureNameCache();
|
||||
|
||||
// Find out the full path of an image by trying different filename extensions.
|
||||
|
|
|
@ -268,7 +268,6 @@ Server::Server(
|
|||
m_gamespec(gamespec),
|
||||
m_simple_singleplayer_mode(simple_singleplayer_mode),
|
||||
m_dedicated(dedicated),
|
||||
m_async_fatal_error(""),
|
||||
m_con(con::createMTP(CONNECTION_TIMEOUT, m_bind_addr.isIPv6(), this)),
|
||||
m_itemdef(createItemDefManager()),
|
||||
m_nodedef(createNodeDefManager()),
|
||||
|
|
|
@ -105,7 +105,11 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
void clear() { m_values.clear(); }
|
||||
void clear()
|
||||
{
|
||||
MutexAutoLock lock(m_mutex);
|
||||
m_values.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<Key, Value> m_values;
|
||||
|
|
|
@ -15,12 +15,13 @@ template<typename T>
|
|||
class MutexedVariable
|
||||
{
|
||||
public:
|
||||
// default initialization
|
||||
MutexedVariable() {}
|
||||
|
||||
MutexedVariable(const T &value):
|
||||
m_value(value)
|
||||
{}
|
||||
m_value(value) {}
|
||||
MutexedVariable(T &&value):
|
||||
m_value(std::move(value))
|
||||
{}
|
||||
m_value(std::move(value)) {}
|
||||
|
||||
T get()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue