forked from Mirrorlandia_minetest/minetest
Codestyle cleanup (main.cpp)
This commit is contained in:
parent
32ab6c2a32
commit
a7d49da217
186
src/main.cpp
186
src/main.cpp
@ -252,14 +252,12 @@ public:
|
||||
/*
|
||||
React to nothing here if a menu is active
|
||||
*/
|
||||
if(noMenuActive() == false)
|
||||
{
|
||||
if (noMenuActive() == false) {
|
||||
return g_menumgr.preprocessEvent(event);
|
||||
}
|
||||
|
||||
// Remember whether each key is down or up
|
||||
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
|
||||
{
|
||||
if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
|
||||
if (event.KeyInput.PressedDown) {
|
||||
keyIsDown.set(event.KeyInput);
|
||||
keyWasDown.set(event.KeyInput);
|
||||
@ -268,44 +266,34 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
|
||||
{
|
||||
if(noMenuActive() == false)
|
||||
{
|
||||
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
|
||||
if (noMenuActive() == false) {
|
||||
left_active = false;
|
||||
middle_active = false;
|
||||
right_active = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
left_active = event.MouseInput.isLeftPressed();
|
||||
middle_active = event.MouseInput.isMiddlePressed();
|
||||
right_active = event.MouseInput.isRightPressed();
|
||||
|
||||
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
|
||||
{
|
||||
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
|
||||
leftclicked = true;
|
||||
}
|
||||
if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
|
||||
{
|
||||
if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) {
|
||||
rightclicked = true;
|
||||
}
|
||||
if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
|
||||
{
|
||||
if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
|
||||
leftreleased = true;
|
||||
}
|
||||
if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
|
||||
{
|
||||
if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) {
|
||||
rightreleased = true;
|
||||
}
|
||||
if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
|
||||
{
|
||||
if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
|
||||
mouse_wheel += event.MouseInput.Wheel;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(event.EventType == irr::EET_LOG_TEXT_EVENT)
|
||||
{
|
||||
if (event.EventType == irr::EET_LOG_TEXT_EVENT) {
|
||||
dstream << "Irrlicht log: " << event.LogEvent.Text << std::endl;
|
||||
return true;
|
||||
}
|
||||
@ -544,8 +532,7 @@ public:
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if(counter1 < 0.0)
|
||||
{
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_jump"));
|
||||
}
|
||||
@ -553,8 +540,7 @@ public:
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if(counter1 < 0.0)
|
||||
{
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_special1"));
|
||||
}
|
||||
@ -562,8 +548,7 @@ public:
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if(counter1 < 0.0)
|
||||
{
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_forward"));
|
||||
}
|
||||
@ -571,8 +556,7 @@ public:
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if(counter1 < 0.0)
|
||||
{
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_left"));
|
||||
}
|
||||
@ -580,8 +564,7 @@ public:
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if(counter1 < 0.0)
|
||||
{
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 20);
|
||||
mousespeed = v2s32(Rand(-20, 20), Rand(-15, 20));
|
||||
}
|
||||
@ -589,8 +572,7 @@ public:
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if(counter1 < 0.0)
|
||||
{
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 30);
|
||||
leftdown = !leftdown;
|
||||
if (leftdown)
|
||||
@ -602,8 +584,7 @@ public:
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if(counter1 < 0.0)
|
||||
{
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 15);
|
||||
rightdown = !rightdown;
|
||||
if (rightdown)
|
||||
@ -648,8 +629,7 @@ void SpeedTests()
|
||||
infostream << "The following test should take around 20ms." << std::endl;
|
||||
TimeTaker timer("Testing std::string speed");
|
||||
const u32 jj = 10000;
|
||||
for(u32 j=0; j<jj; j++)
|
||||
{
|
||||
for(u32 j = 0; j < jj; j++) {
|
||||
tempstring = "";
|
||||
tempstring2 = "";
|
||||
const u32 ii = 10;
|
||||
@ -725,13 +705,11 @@ void SpeedTests()
|
||||
|
||||
u32 dtime = timer.stop();
|
||||
u32 per_ms = n / dtime;
|
||||
infostream<<"Done. "<<dtime<<"ms, "
|
||||
<<per_ms<<"/ms"<<std::endl;
|
||||
infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void print_worldspecs(const std::vector<WorldSpec> &worldspecs,
|
||||
std::ostream &os)
|
||||
static void print_worldspecs(const std::vector<WorldSpec> &worldspecs, std::ostream &os)
|
||||
{
|
||||
for(u32 i = 0; i < worldspecs.size(); i++) {
|
||||
std::string name = worldspecs[i].name;
|
||||
@ -817,18 +795,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
|
||||
|
||||
if(ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1"))
|
||||
{
|
||||
if (ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1")) {
|
||||
dstream << _("Allowed options:") << std::endl;
|
||||
for(std::map<std::string, ValueSpec>::iterator
|
||||
i = allowed_options.begin();
|
||||
i != allowed_options.end(); ++i)
|
||||
{
|
||||
i != allowed_options.end(); ++i) {
|
||||
std::ostringstream os1(std::ios::binary);
|
||||
os1 << " --"<<i->first;
|
||||
if(i->second.type == VALUETYPE_FLAG)
|
||||
{}
|
||||
else
|
||||
if (i->second.type == VALUETYPE_FLAG) {
|
||||
} else
|
||||
os1 << _(" <value>");
|
||||
dstream << padStringRight(os1.str(), 24);
|
||||
|
||||
@ -840,8 +815,7 @@ int main(int argc, char *argv[])
|
||||
return cmd_args.getFlag("help") ? 0 : 1;
|
||||
}
|
||||
|
||||
if(cmd_args.getFlag("version"))
|
||||
{
|
||||
if (cmd_args.getFlag("version")) {
|
||||
#ifdef SERVER
|
||||
dstream << "minetestserver " << minetest_version_hash << std::endl;
|
||||
#else
|
||||
@ -895,8 +869,7 @@ int main(int argc, char *argv[])
|
||||
BEGIN_DEBUG_EXCEPTION_HANDLER
|
||||
|
||||
// List gameids if requested
|
||||
if(cmd_args.exists("gameid") && cmd_args.get("gameid") == "list")
|
||||
{
|
||||
if (cmd_args.exists("gameid") && cmd_args.get("gameid") == "list") {
|
||||
std::set<std::string> gameids = getAvailableGameIds();
|
||||
for(std::set<std::string>::const_iterator i = gameids.begin();
|
||||
i != gameids.end(); i++)
|
||||
@ -913,10 +886,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Print startup message
|
||||
infostream<<PROJECT_NAME<<
|
||||
" "<<_("with")<<" SER_FMT_VER_HIGHEST_READ="<<(int)SER_FMT_VER_HIGHEST_READ
|
||||
<<", "<<minetest_build_info
|
||||
<<std::endl;
|
||||
infostream<<PROJECT_NAME << " "<< _("with") << " SER_FMT_VER_HIGHEST_READ="
|
||||
<< (int)SER_FMT_VER_HIGHEST_READ << ", " << minetest_build_info << std::endl;
|
||||
|
||||
/*
|
||||
Basic initialization
|
||||
@ -936,19 +907,15 @@ int main(int argc, char *argv[])
|
||||
// Path of configuration file in use
|
||||
g_settings_path = "";
|
||||
|
||||
if(cmd_args.exists("config"))
|
||||
{
|
||||
if (cmd_args.exists("config")) {
|
||||
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
|
||||
if(r == false)
|
||||
{
|
||||
if (r == false) {
|
||||
errorstream << "Could not read configuration from \""
|
||||
<< cmd_args.get("config") << "\"" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
g_settings_path = cmd_args.get("config");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::vector<std::string> filenames;
|
||||
filenames.push_back(porting::path_user +
|
||||
DIR_DELIM + "minetest.conf");
|
||||
@ -962,11 +929,9 @@ int main(int argc, char *argv[])
|
||||
DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
|
||||
#endif
|
||||
|
||||
for(u32 i=0; i<filenames.size(); i++)
|
||||
{
|
||||
for(u32 i = 0; i < filenames.size(); i++) {
|
||||
bool r = g_settings->readConfigFile(filenames[i].c_str());
|
||||
if(r)
|
||||
{
|
||||
if (r) {
|
||||
g_settings_path = filenames[i];
|
||||
break;
|
||||
}
|
||||
@ -993,7 +958,8 @@ int main(int argc, char *argv[])
|
||||
if (loglevel == 0) //no logging
|
||||
logfile = "";
|
||||
else if (loglevel > 0 && loglevel <= LMT_NUM_VALUES)
|
||||
log_add_output_maxlev(&main_dstream_no_stderr_log_out, (LogMessageLevel)(loglevel - 1));
|
||||
log_add_output_maxlev(&main_dstream_no_stderr_log_out,
|
||||
(LogMessageLevel)(loglevel - 1));
|
||||
|
||||
if (logfile != "")
|
||||
debugstreams_init(false, logfile.c_str());
|
||||
@ -1014,14 +980,15 @@ int main(int argc, char *argv[])
|
||||
*/
|
||||
|
||||
if ((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
|
||||
|| cmd_args.getFlag("enable-unittests") == true)
|
||||
{
|
||||
|| cmd_args.getFlag("enable-unittests") == true) {
|
||||
run_tests();
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),g_settings->get("language"),argc,argv);
|
||||
init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),
|
||||
g_settings->get("language"), argc, argv);
|
||||
#else
|
||||
init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),g_settings->get("language"));
|
||||
init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),
|
||||
g_settings->get("language"));
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -1060,8 +1027,8 @@ int main(int argc, char *argv[])
|
||||
commanded_world.substr(commanded_world.size() - worldmt.size())
|
||||
== worldmt) {
|
||||
dstream << _("Supplied world.mt file - stripping it off.") << std::endl;
|
||||
commanded_world = commanded_world.substr(
|
||||
0, commanded_world.size()-worldmt.size());
|
||||
commanded_world = commanded_world.substr(0,
|
||||
commanded_world.size() - worldmt.size());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1128,10 +1095,7 @@ int main(int argc, char *argv[])
|
||||
world_path = commanded_world;
|
||||
infostream << "Using commanded world path [" << world_path << "]"
|
||||
<< std::endl;
|
||||
}
|
||||
// No world was specified; try to select it automatically
|
||||
else
|
||||
{
|
||||
} else { // No world was specified; try to select it automatically
|
||||
// Get information about available worlds
|
||||
std::vector<WorldSpec> worldspecs = getAvailableWorlds();
|
||||
// If a world name was specified, select it
|
||||
@ -1183,22 +1147,16 @@ int main(int argc, char *argv[])
|
||||
SubgameSpec gamespec;
|
||||
verbosestream << _("Determining gameid/gamespec") << std::endl;
|
||||
// If world doesn't exist
|
||||
if(!getWorldExists(world_path))
|
||||
{
|
||||
if (!getWorldExists(world_path)) {
|
||||
// Try to take gamespec from command line
|
||||
if (commanded_gamespec.isValid()) {
|
||||
gamespec = commanded_gamespec;
|
||||
infostream << "Using commanded gameid [" << gamespec.id << "]" << std::endl;
|
||||
}
|
||||
// Otherwise we will be using "minetest"
|
||||
else{
|
||||
} else { // Otherwise we will be using "minetest"
|
||||
gamespec = findSubgame(g_settings->get("default_game"));
|
||||
infostream << "Using default gameid [" << gamespec.id << "]" << std::endl;
|
||||
}
|
||||
}
|
||||
// World exists
|
||||
else
|
||||
{
|
||||
} else { // World exists
|
||||
std::string world_gameid = getWorldGameId(world_path, is_legacy_world);
|
||||
// If commanded to use a gameid, do so
|
||||
if (commanded_gamespec.isValid()) {
|
||||
@ -1250,7 +1208,8 @@ int main(int argc, char *argv[])
|
||||
if (cmd_args.exists("migrate")) {
|
||||
std::string migrate_to = cmd_args.get("migrate");
|
||||
Settings world_mt;
|
||||
bool success = world_mt.readConfigFile((world_path + DIR_DELIM + "world.mt").c_str());
|
||||
bool success = world_mt.readConfigFile((world_path + DIR_DELIM
|
||||
+ "world.mt").c_str());
|
||||
if (!success) {
|
||||
errorstream << "Cannot read world.mt" << std::endl;
|
||||
return 1;
|
||||
@ -1263,7 +1222,8 @@ int main(int argc, char *argv[])
|
||||
std::string backend = world_mt.get("backend");
|
||||
Database *new_db;
|
||||
if (backend == migrate_to) {
|
||||
errorstream << "Cannot migrate: new backend is same as the old one" << std::endl;
|
||||
errorstream << "Cannot migrate: new backend is same"
|
||||
<<" as the old one" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (migrate_to == "sqlite3")
|
||||
@ -1277,7 +1237,8 @@ int main(int argc, char *argv[])
|
||||
new_db = new Database_Redis(&(ServerMap&)server.getMap(), world_path);
|
||||
#endif
|
||||
else {
|
||||
errorstream << "Migration to " << migrate_to << " is not supported" << std::endl;
|
||||
errorstream << "Migration to " << migrate_to
|
||||
<< " is not supported" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1286,7 +1247,7 @@ int main(int argc, char *argv[])
|
||||
old_map.listAllLoadableBlocks(blocks);
|
||||
int count = 0;
|
||||
new_db->beginSave();
|
||||
for (std::list<v3s16>::iterator i = blocks.begin(); i != blocks.end(); ++i) {
|
||||
for (std::list<v3s16>::iterator i = blocks.begin(); i != blocks.end(); i++) {
|
||||
MapBlock *block = old_map.loadBlock(*i);
|
||||
new_db->saveBlock(block);
|
||||
MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z));
|
||||
@ -1377,10 +1338,9 @@ int main(int argc, char *argv[])
|
||||
else if (driverstring == "ogles2")
|
||||
driverType = video::EDT_OGLES2;
|
||||
#endif
|
||||
else
|
||||
{
|
||||
else {
|
||||
errorstream << "WARNING: Invalid video_driver specified; defaulting "
|
||||
"to opengl"<<std::endl;
|
||||
<< "to opengl" << std::endl;
|
||||
driverType = video::EDT_OPENGL;
|
||||
}
|
||||
|
||||
@ -1537,7 +1497,8 @@ int main(int argc, char *argv[])
|
||||
font_path = g_settings->get(fallback + "font_path");
|
||||
u32 font_shadow = g_settings->getU16(fallback + "font_shadow");
|
||||
u32 font_shadow_alpha = g_settings->getU16(fallback + "font_shadow_alpha");
|
||||
font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size, true, true, font_shadow, font_shadow_alpha);
|
||||
font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size,
|
||||
true, true, font_shadow, font_shadow_alpha);
|
||||
} else {
|
||||
font = guienv->getFont(font_path.c_str());
|
||||
}
|
||||
@ -1548,7 +1509,7 @@ int main(int argc, char *argv[])
|
||||
skin->setFont(font);
|
||||
else
|
||||
errorstream << "WARNING: Font file was not found."
|
||||
" Using default font."<<std::endl;
|
||||
<< " Using default font." << std::endl;
|
||||
// If font was not found, this will get us one
|
||||
font = skin->getFont();
|
||||
assert(font);
|
||||
@ -1556,10 +1517,7 @@ int main(int argc, char *argv[])
|
||||
u32 text_height = font->getDimension(L"Hello, world!").Height;
|
||||
infostream << "text_height=" << text_height << std::endl;
|
||||
|
||||
//skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
|
||||
skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
|
||||
//skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(0,0,0,0));
|
||||
//skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(0,0,0,0));
|
||||
skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 0, 0, 0));
|
||||
skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0));
|
||||
skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 100, 50));
|
||||
@ -1644,8 +1602,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
Loop quits when menu returns proper parameters.
|
||||
*/
|
||||
while(kill == false)
|
||||
{
|
||||
while (kill == false) {
|
||||
// If skip_main_menu, only go through here once
|
||||
if (skip_main_menu && !first_loop) {
|
||||
kill = true;
|
||||
@ -1687,13 +1644,11 @@ int main(int argc, char *argv[])
|
||||
//TODO find within worldspecs and set config
|
||||
}
|
||||
|
||||
if(skip_main_menu == false)
|
||||
{
|
||||
if (skip_main_menu == false) {
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
|
||||
infostream << "Waiting for other menus" << std::endl;
|
||||
while(device->run() && kill == false)
|
||||
{
|
||||
while (device->run() && kill == false) {
|
||||
if (noMenuActive())
|
||||
break;
|
||||
driver->beginScene(true, true,
|
||||
@ -1706,7 +1661,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
infostream << "Waited for other menus" << std::endl;
|
||||
|
||||
GUIEngine* temp = new GUIEngine(device, guiroot, &g_menumgr,smgr,&menudata,kill);
|
||||
GUIEngine* temp = new GUIEngine(device, guiroot,
|
||||
&g_menumgr, smgr, &menudata, kill);
|
||||
|
||||
delete temp;
|
||||
//once finished you'll never end up here
|
||||
@ -1759,9 +1715,7 @@ int main(int argc, char *argv[])
|
||||
current_password = "";
|
||||
current_address = "";
|
||||
current_port = myrand_range(49152, 65535);
|
||||
}
|
||||
else if (address != "")
|
||||
{
|
||||
} else if (address != "") {
|
||||
ServerListSpec server;
|
||||
server["name"] = menudata.servername;
|
||||
server["address"] = menudata.address;
|
||||
@ -1779,8 +1733,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// If local game
|
||||
if(current_address == "")
|
||||
{
|
||||
if (current_address == "") {
|
||||
if (menudata.selected_world == -1) {
|
||||
error_message = wgettext("No world selected and no address "
|
||||
"provided. Nothing to do.");
|
||||
@ -1819,8 +1772,7 @@ int main(int argc, char *argv[])
|
||||
// Break out of menu-game loop to shut down cleanly
|
||||
if (device->run() == false || kill == true) {
|
||||
if (g_settings_path != "") {
|
||||
g_settings->updateConfigFile(
|
||||
g_settings_path.c_str());
|
||||
g_settings->updateConfigFile(g_settings_path.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1864,8 +1816,7 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
// If no main menu, show error and exit
|
||||
if(skip_main_menu)
|
||||
{
|
||||
if (skip_main_menu) {
|
||||
if (error_message != L"") {
|
||||
verbosestream << "error_message = "
|
||||
<< wide_to_narrow(error_message) << std::endl;
|
||||
@ -1920,6 +1871,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
debugstreams_deinit();
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user