1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix modstore/favourites hang by adding asynchronous lua job support

This commit is contained in:
sapier 2013-11-26 18:15:31 +01:00
parent b08d7558de
commit 2e66aca357
27 changed files with 2271 additions and 559 deletions

View file

@ -85,6 +85,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "database-leveldb.h"
#endif
#if USE_CURL
#include "curl.h"
#endif
/*
Settings.
These are loaded from the config file.
@ -309,7 +313,7 @@ public:
{
return keyIsDown[keyCode];
}
// Checks whether a key was down and resets the state
bool WasKeyDown(const KeyPress &keyCode)
{
@ -361,7 +365,7 @@ public:
private:
IrrlichtDevice *m_device;
// The current state of keys
KeyList keyIsDown;
// Whether a key has been pressed or not
@ -405,7 +409,7 @@ public:
{
return m_receiver->right_active;
}
virtual bool getLeftClicked()
{
return m_receiver->leftclicked;
@ -656,7 +660,7 @@ void SpeedTests()
}
}
}
infostream<<"All of the following tests should take around 100ms each."
<<std::endl;
@ -668,7 +672,7 @@ void SpeedTests()
tempf += 0.001;
}
}
{
TimeTaker timer("Testing floating-point vector speed");
@ -682,7 +686,7 @@ void SpeedTests()
{
TimeTaker timer("Testing std::map speed");
std::map<v2s16, f32> map1;
tempf = -324;
const s16 ii=300;
@ -702,7 +706,7 @@ void SpeedTests()
{
infostream<<"Around 5000/ms should do well here."<<std::endl;
TimeTaker timer("Testing mutex speed");
JMutex m;
m.Init();
u32 n = 0;
@ -753,7 +757,7 @@ int main(int argc, char *argv[])
/*
Parse command line
*/
// List all allowed options
std::map<std::string, ValueSpec> allowed_options;
allowed_options.insert(std::make_pair("help", ValueSpec(VALUETYPE_FLAG,
@ -806,7 +810,7 @@ int main(int argc, char *argv[])
#endif
Settings cmd_args;
bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
if(ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1"))
@ -843,11 +847,11 @@ int main(int argc, char *argv[])
dstream<<"Build info: "<<minetest_build_info<<std::endl;
return 0;
}
/*
Low-level initialization
*/
// If trace is enabled, enable logging of certain things
if(cmd_args.getFlag("trace")){
dstream<<_("Enabling trace level debug output")<<std::endl;
@ -865,7 +869,7 @@ int main(int argc, char *argv[])
porting::signal_handler_init();
bool &kill = *porting::signal_handler_killstatus();
porting::initializePaths();
// Create user data directory
@ -880,7 +884,7 @@ int main(int argc, char *argv[])
// Debug handler
BEGIN_DEBUG_EXCEPTION_HANDLER
// List gameids if requested
if(cmd_args.exists("gameid") && cmd_args.get("gameid") == "list")
{
@ -890,7 +894,7 @@ int main(int argc, char *argv[])
dstream<<(*i)<<std::endl;
return 0;
}
// List worlds if requested
if(cmd_args.exists("world") && cmd_args.get("world") == "list"){
dstream<<_("Available worlds:")<<std::endl;
@ -904,25 +908,25 @@ int main(int argc, char *argv[])
" "<<_("with")<<" SER_FMT_VER_HIGHEST_READ="<<(int)SER_FMT_VER_HIGHEST_READ
<<", "<<minetest_build_info
<<std::endl;
/*
Basic initialization
*/
// Initialize default settings
set_default_settings(g_settings);
// Initialize sockets
sockets_init();
atexit(sockets_cleanup);
/*
Read config file
*/
// Path of configuration file in use
g_settings_path = "";
if(cmd_args.exists("config"))
{
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
@ -958,12 +962,12 @@ int main(int argc, char *argv[])
break;
}
}
// If no path found, use the first one (menu creates the file)
if(g_settings_path == "")
g_settings_path = filenames[0];
}
// Initialize debug streams
#define DEBUGFILE "debug.txt"
#if RUN_IN_PLACE
@ -973,7 +977,7 @@ int main(int argc, char *argv[])
#endif
if(cmd_args.exists("logfile"))
logfile = cmd_args.get("logfile");
log_remove_output(&main_dstream_no_stderr_log_out);
int loglevel = g_settings->getS32("debug_log_level");
@ -986,13 +990,18 @@ int main(int argc, char *argv[])
debugstreams_init(false, logfile.c_str());
else
debugstreams_init(false, NULL);
infostream<<"logfile = "<<logfile<<std::endl;
// Initialize random seed
srand(time(0));
mysrand(time(0));
#if USE_CURL
CURLcode res = curl_global_init(CURL_GLOBAL_DEFAULT);
assert(res == CURLE_OK);
#endif
/*
Run unit tests
*/
@ -1020,7 +1029,7 @@ int main(int argc, char *argv[])
port = g_settings->getU16("port");
if(port == 0)
port = 30000;
// World directory
std::string commanded_world = "";
if(cmd_args.exists("world"))
@ -1031,12 +1040,12 @@ int main(int argc, char *argv[])
commanded_world = cmd_args.get("nonopt0");
else if(g_settings->exists("map-dir"))
commanded_world = g_settings->get("map-dir");
// World name
std::string commanded_worldname = "";
if(cmd_args.exists("worldname"))
commanded_worldname = cmd_args.get("worldname");
// Strip world.mt from commanded_world
{
std::string worldmt = "world.mt";
@ -1048,7 +1057,7 @@ int main(int argc, char *argv[])
0, commanded_world.size()-worldmt.size());
}
}
// If a world name was specified, convert it to a path
if(commanded_worldname != ""){
// Get information about available worlds
@ -1268,7 +1277,7 @@ int main(int argc, char *argv[])
}
server.start(port);
// Run server
dedicated_server_loop(server, kill);
@ -1280,17 +1289,17 @@ int main(int argc, char *argv[])
/*
More parameters
*/
std::string address = g_settings->get("address");
if(commanded_world != "")
address = "";
else if(cmd_args.exists("address"))
address = cmd_args.get("address");
std::string playername = g_settings->get("name");
if(cmd_args.exists("name"))
playername = cmd_args.get("name");
bool skip_main_menu = cmd_args.getFlag("go");
/*
@ -1298,7 +1307,7 @@ int main(int argc, char *argv[])
*/
// Resolution selection
bool fullscreen = g_settings->getBool("fullscreen");
u16 screenW = g_settings->getU16("screenW");
u16 screenH = g_settings->getU16("screenH");
@ -1312,7 +1321,7 @@ int main(int argc, char *argv[])
// Determine driver
video::E_DRIVER_TYPE driverType;
std::string driverstring = g_settings->get("video_driver");
if(driverstring == "null")
@ -1419,7 +1428,7 @@ int main(int argc, char *argv[])
if (device == 0)
return 1; // could not create selected driver.
/*
Continue initialization
*/
@ -1434,10 +1443,10 @@ int main(int argc, char *argv[])
// Create time getter
g_timegetter = new IrrlichtTimeGetter(device);
// Create game callback for menus
g_gamecallback = new MainGameCallback(device);
/*
Speed tests (done after irrlicht is loaded to get timer)
*/
@ -1448,7 +1457,7 @@ int main(int argc, char *argv[])
device->drop();
return 0;
}
device->setResizable(true);
bool random_input = g_settings->getBool("random_input")
@ -1458,7 +1467,7 @@ int main(int argc, char *argv[])
input = new RandomInputHandler();
else
input = new RealInputHandler(device, &receiver);
scene::ISceneManager* smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
@ -1488,7 +1497,7 @@ int main(int argc, char *argv[])
// If font was not found, this will get us one
font = skin->getFont();
assert(font);
u32 text_height = font->getDimension(L"Hello, world!").Height;
infostream<<"text_height="<<text_height<<std::endl;
@ -1556,7 +1565,7 @@ int main(int argc, char *argv[])
Clear everything from the GUIEnvironment
*/
guienv->clear();
/*
We need some kind of a root node to be able to add
custom gui elements directly on the screen.
@ -1564,7 +1573,7 @@ int main(int argc, char *argv[])
*/
guiroot = guienv->addStaticText(L"",
core::rect<s32>(0, 0, 10000, 10000));
SubgameSpec gamespec;
WorldSpec worldspec;
bool simple_singleplayer_mode = false;
@ -1588,13 +1597,13 @@ int main(int argc, char *argv[])
break;
}
first_loop = false;
// Cursor can be non-visible when coming from the game
device->getCursorControl()->setVisible(true);
// Some stuff are left to scene manager when coming from the game
// (map at least?)
smgr->clear();
// Initialize menu data
MainMenuData menudata;
menudata.address = address;
@ -1643,7 +1652,7 @@ int main(int argc, char *argv[])
infostream<<"Waited for other menus"<<std::endl;
GUIEngine* temp = new GUIEngine(device, guiroot, &g_menumgr,smgr,&menudata,kill);
delete temp;
//once finished you'll never end up here
smgr->clear();
@ -1683,7 +1692,7 @@ int main(int argc, char *argv[])
// Break out of menu-game loop to shut down cleanly
if(device->run() == false || kill == true)
break;
current_playername = playername;
current_password = password;
current_address = address;
@ -1705,7 +1714,7 @@ int main(int argc, char *argv[])
server["description"] = menudata.serverdescription;
ServerList::insert(server);
}
// Set world path to selected one
if ((menudata.selected_world >= 0) &&
(menudata.selected_world < (int)worldspecs.size())) {
@ -1713,7 +1722,7 @@ int main(int argc, char *argv[])
infostream<<"Selected world: "<<worldspec.name
<<" ["<<worldspec.path<<"]"<<std::endl;
}
// If local game
if(current_address == "")
{
@ -1828,11 +1837,11 @@ int main(int argc, char *argv[])
#endif
#endif // !SERVER
// Update configuration file
if(g_settings_path != "")
g_settings->updateConfigFile(g_settings_path.c_str());
// Print modified quicktune values
{
bool header_printed = false;
@ -1850,9 +1859,9 @@ int main(int argc, char *argv[])
}
END_DEBUG_EXCEPTION_HANDLER(errorstream)
debugstreams_deinit();
return retval;
}