mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-27 17:28:41 +00:00
Move values the mainmenu caches to dedicated files (#14433)
This commit is contained in:
parent
bb6782ca58
commit
6c6e48f006
16 changed files with 142 additions and 132 deletions
|
@ -356,11 +356,10 @@ void set_default_settings()
|
|||
settings->setDefault("contentdb_flag_blacklist", "nonfree, desktop_default");
|
||||
#endif
|
||||
|
||||
settings->setDefault("update_information_url", "https://www.minetest.net/release_info.json");
|
||||
#if ENABLE_UPDATE_CHECKER
|
||||
settings->setDefault("update_last_checked", "");
|
||||
settings->setDefault("update_information_url", "https://www.minetest.net/release_info.json");
|
||||
#else
|
||||
settings->setDefault("update_last_checked", "disabled");
|
||||
settings->setDefault("update_information_url", "");
|
||||
#endif
|
||||
|
||||
// Server
|
||||
|
|
|
@ -369,6 +369,8 @@ void GUIEngine::run()
|
|||
#endif
|
||||
}
|
||||
|
||||
m_script->beforeClose();
|
||||
|
||||
RenderingEngine::autosaveScreensizeAndCo(initial_screen_size, initial_window_maximized);
|
||||
}
|
||||
|
||||
|
|
|
@ -1080,44 +1080,6 @@ int ModApiMainMenu::l_do_async_callback(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// this is intentionally a global and not part of MainMenuScripting or such
|
||||
namespace {
|
||||
std::unordered_map<std::string, std::string> once_values;
|
||||
std::mutex once_mutex;
|
||||
}
|
||||
|
||||
int ModApiMainMenu::l_set_once(lua_State *L)
|
||||
{
|
||||
std::string key = readParam<std::string>(L, 1);
|
||||
if (lua_isnil(L, 2))
|
||||
return 0;
|
||||
std::string value = readParam<std::string>(L, 2);
|
||||
|
||||
{
|
||||
MutexAutoLock lock(once_mutex);
|
||||
once_values[key] = value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ModApiMainMenu::l_get_once(lua_State *L)
|
||||
{
|
||||
std::string key = readParam<std::string>(L, 1);
|
||||
|
||||
{
|
||||
MutexAutoLock lock(once_mutex);
|
||||
auto it = once_values.find(key);
|
||||
if (it == once_values.end())
|
||||
lua_pushnil(L);
|
||||
else
|
||||
lua_pushstring(L, it->second.c_str());
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ModApiMainMenu::Initialize(lua_State *L, int top)
|
||||
{
|
||||
|
@ -1170,8 +1132,6 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
|
|||
API_FCT(open_dir);
|
||||
API_FCT(share_file);
|
||||
API_FCT(do_async_callback);
|
||||
API_FCT(set_once);
|
||||
API_FCT(get_once);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -166,10 +166,6 @@ private:
|
|||
|
||||
static int l_share_file(lua_State *L);
|
||||
|
||||
static int l_set_once(lua_State *L);
|
||||
|
||||
static int l_get_once(lua_State *L);
|
||||
|
||||
// async
|
||||
static int l_do_async_callback(lua_State *L);
|
||||
|
||||
|
|
|
@ -58,7 +58,6 @@ MainMenuScripting::MainMenuScripting(GUIEngine* guiengine):
|
|||
infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void MainMenuScripting::initializeModApi(lua_State *L, int top)
|
||||
{
|
||||
registerLuaClasses(L, top);
|
||||
|
@ -79,20 +78,31 @@ void MainMenuScripting::initializeModApi(lua_State *L, int top)
|
|||
asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void MainMenuScripting::registerLuaClasses(lua_State *L, int top)
|
||||
{
|
||||
LuaSettings::Register(L);
|
||||
MainMenuSoundHandle::Register(L);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void MainMenuScripting::beforeClose()
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "on_before_close");
|
||||
|
||||
PCALL_RES(lua_pcall(L, 0, 0, error_handler));
|
||||
|
||||
lua_pop(L, 2); // Pop core, error handler
|
||||
}
|
||||
|
||||
void MainMenuScripting::step()
|
||||
{
|
||||
asyncEngine.step(getStack());
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u32 MainMenuScripting::queueAsync(std::string &&serialized_func,
|
||||
std::string &&serialized_param)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,9 @@ public:
|
|||
// Global step handler to pass back async events
|
||||
void step();
|
||||
|
||||
// Calls core.on_before_close()
|
||||
void beforeClose();
|
||||
|
||||
// Pass async events from engine to async threads
|
||||
u32 queueAsync(std::string &&serialized_func,
|
||||
std::string &&serialized_param);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue