]> git.lizzy.rs Git - minetest.git/blobdiff - src/game.cpp
Biome API: Enable biome generation to lower world limit
[minetest.git] / src / game.cpp
index 6bddfe90542dd2cc9cb676add83ad9acd06cc14d..903e4f85c58cf5cafd3ffce27454326e993a8459 100644 (file)
@@ -87,11 +87,11 @@ struct TextDestNodeMetadata : public TextDest {
                std::string ntext = wide_to_narrow(text);
                infostream << "Submitting 'text' field of node at (" << m_p.X << ","
                           << m_p.Y << "," << m_p.Z << "): " << ntext << std::endl;
-               std::map<std::string, std::string> fields;
+               StringMap fields;
                fields["text"] = ntext;
                m_client->sendNodemetaFields(m_p, "", fields);
        }
-       void gotText(std::map<std::string, std::string> fields)
+       void gotText(const StringMap &fields)
        {
                m_client->sendNodemetaFields(m_p, "", fields);
        }
@@ -111,7 +111,7 @@ struct TextDestPlayerInventory : public TextDest {
                m_client = client;
                m_formname = formname;
        }
-       void gotText(std::map<std::string, std::string> fields)
+       void gotText(const StringMap &fields)
        {
                m_client->sendInventoryFields(m_formname, fields);
        }
@@ -138,7 +138,7 @@ struct LocalFormspecHandler : public TextDest {
                errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
        }
 
-       void gotText(std::map<std::string, std::string> fields)
+       void gotText(const StringMap &fields)
        {
                if (m_formname == "MT_PAUSE_MENU") {
                        if (fields.find("btn_sound") != fields.end()) {
@@ -180,9 +180,9 @@ struct LocalFormspecHandler : public TextDest {
 
                        if ((fields.find("btn_send") != fields.end()) ||
                                        (fields.find("quit") != fields.end())) {
-                               if (fields.find("f_text") != fields.end()) {
-                                       m_client->typeChatMessage(narrow_to_wide(fields["f_text"]));
-                               }
+                               StringMap::const_iterator it = fields.find("f_text");
+                               if (it != fields.end())
+                                       m_client->typeChatMessage(narrow_to_wide(it->second));
 
                                return;
                        }
@@ -210,12 +210,14 @@ struct LocalFormspecHandler : public TextDest {
                        return;
                }
 
-               errorstream << "LocalFormspecHandler::gotText unhandled >" << m_formname << "< event" << std::endl;
-               int i = 0;
+               errorstream << "LocalFormspecHandler::gotText unhandled >"
+                       << m_formname << "< event" << std::endl;
 
-               for (std::map<std::string, std::string>::iterator iter = fields.begin();
-                               iter != fields.end(); iter++) {
-                       errorstream << "\t" << i << ": " << iter->first << "=" << iter->second << std::endl;
+               int i = 0;
+               StringMap::const_iterator it;
+               for (it = fields.begin(); it != fields.end(); ++it) {
+                       errorstream << "\t" << i << ": " << it->first
+                               << "=" << it->second << std::endl;
                        i++;
                }
        }
@@ -1134,7 +1136,7 @@ static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
        os              << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;"
                        << wide_to_narrow(wstrgettext("Exit to OS"))   << "]"
                        << "textarea[7.5,0.25;3.9,6.25;;" << control_text << ";]"
-                       << "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME "\n"
+                       << "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME_C "\n"
                        << g_build_info << "\n"
                        << "path_user = " << wrap_rows(porting::path_user, 20)
                        << "\n;]";
@@ -1146,7 +1148,8 @@ static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
        LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
 
        create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device,  fs_src, txt_dst, NULL);
-       (*cur_formspec)->setFocus(L"btn_continue");
+       std::string con("btn_continue");
+       (*cur_formspec)->setFocus(con);
        (*cur_formspec)->doPause = true;
 }
 
@@ -1618,6 +1621,11 @@ class Game
        bool m_cache_enable_fog;
        f32  m_cache_mouse_sensitivity;
        f32  m_repeat_right_click_time;
+
+#ifdef __ANDROID__
+       bool m_cache_hold_aux1;
+#endif
+
 };
 
 Game::Game() :
@@ -1651,6 +1659,11 @@ Game::Game() :
        m_repeat_right_click_time         = g_settings->getFloat("repeat_rightclick_time");
 
        m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
+
+#ifdef __ANDROID__
+       m_cache_hold_aux1 = false;      // This is initialised properly later
+#endif
+
 }
 
 
@@ -1757,6 +1770,11 @@ void Game::run()
 
        set_light_table(g_settings->getFloat("display_gamma"));
 
+#ifdef __ANDROID__
+       m_cache_hold_aux1 = g_settings->getBool("fast_move")
+                       && client->checkPrivilege("fast");
+#endif
+
        while (device->run() && !(*kill || g_gamecallback->shutdown_requested)) {
 
                /* Must be called immediately after a device->run() call because it
@@ -1793,7 +1811,7 @@ void Game::run()
                                cam_view.camera_pitch) * cam_smoothing;
                updatePlayerControl(cam_view);
                step(&dtime);
-               processClientEvents(&cam_view, &runData.damage_flash);
+               processClientEvents(&cam_view_target, &runData.damage_flash);
                updateCamera(&flags, draw_times.busy_time, dtime,
                                runData.time_from_last_punch);
                updateSound(dtime);
@@ -2029,7 +2047,7 @@ bool Game::createClient(const std::string &playername,
 
        /* Set window caption
         */
-       std::wstring str = narrow_to_wide(PROJECT_NAME);
+       std::wstring str = narrow_to_wide(PROJECT_NAME_C);
        str += L" [";
        str += driver->getName();
        str += L"]";
@@ -2054,7 +2072,7 @@ bool Game::initGui()
 {
        // First line of debug text
        guitext = guienv->addStaticText(
-                       narrow_to_wide(PROJECT_NAME).c_str(),
+                       narrow_to_wide(PROJECT_NAME_C).c_str(),
                        core::rect<s32>(0, 0, 0, 0),
                        false, false, guiroot);
 
@@ -2181,7 +2199,10 @@ bool Game::connectToServer(const std::string &playername,
                input->clear();
 
                FpsControl fps_control = { 0 };
-               f32 dtime; // in seconds
+               f32 dtime;
+               f32 wait_time = 0; // in seconds
+
+               fps_control.last_time = device->getTimer()->getTime();
 
                while (device->run()) {
 
@@ -2213,6 +2234,14 @@ bool Game::connectToServer(const std::string &playername,
                                break;
                        }
 
+                       wait_time += dtime;
+                       // Only time out if we aren't waiting for the server we started
+                       if ((*address != "") && (wait_time > 10)) {
+                               *error_message = "Connection timed out.";
+                               errorstream << *error_message << std::endl;
+                               break;
+                       }
+
                        // Update status
                        showOverlayMessage(wgettext("Connecting to server..."), dtime, 20);
                }
@@ -2232,6 +2261,8 @@ bool Game::getServerContent(bool *aborted)
        FpsControl fps_control = { 0 };
        f32 dtime; // in seconds
 
+       fps_control.last_time = device->getTimer()->getTime();
+
        while (device->run()) {
 
                limitFps(&fps_control, &dtime);
@@ -2285,14 +2316,14 @@ bool Game::getServerContent(bool *aborted)
                        if ((USE_CURL == 0) ||
                                        (!g_settings->getBool("enable_remote_media_server"))) {
                                float cur = client->getCurRate();
-                               std::string cur_unit = gettext(" KB/s");
+                               std::string cur_unit = gettext("KiB/s");
 
                                if (cur > 900) {
                                        cur /= 1024.0;
-                                       cur_unit = gettext(" MB/s");
+                                       cur_unit = gettext("MiB/s");
                                }
 
-                               message << " ( " << cur << cur_unit << " )";
+                               message << " (" << cur << ' ' << cur_unit << ")";
                        }
 
                        progress = 30 + client->mediaReceiveProgress() * 35 + 0.5;
@@ -2732,8 +2763,14 @@ void Game::toggleFast(float *statustext_time)
        *statustext_time = 0;
        statustext = msg[fast_move];
 
-       if (fast_move && !client->checkPrivilege("fast"))
+       bool has_fast_privs = client->checkPrivilege("fast");
+
+       if (fast_move && !has_fast_privs)
                statustext += L" (note: no 'fast' privilege)";
+
+#ifdef __ANDROID__
+       m_cache_hold_aux1 = fast_move && has_fast_privs;
+#endif
 }
 
 
@@ -2983,15 +3020,12 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
                );
 
 #ifdef ANDROID
-       /* For Android, invert the meaning of holding down the fast button (i.e.
-        * holding down the fast button -- if there is one -- means walk), unless
-        * performing an action, sneaking or jumping.
+       /* For Android, simulate holding down AUX1 (fast move) if the user has
+        * the fast_move setting toggled on. If there is an aux1 key defined for
+        * Android then its meaning is inverted (i.e. holding aux1 means walk and
+        * not fast)
         */
-       const u32 autofast_exludebits =
-                         (1U << 4) | (1U << 6)     // jump, sneak
-                       | (1U << 7) | (1U << 8);    // left state, right state
-
-       if ((keypress_bits & autofast_exludebits) == 0) {
+       if (m_cache_hold_aux1) {
                control.aux1 = control.aux1 ^ true;
                keypress_bits ^= ((u32)(1U << 5));
        }
@@ -4005,7 +4039,7 @@ void Game::updateGui(float *statustext_time, const RunStats &stats,
 
                std::ostringstream os(std::ios_base::binary);
                os << std::fixed
-                  << PROJECT_NAME " " << g_version_hash
+                  << PROJECT_NAME_C " " << g_version_hash
                   << " FPS = " << fps
                   << " (R: range_all=" << draw_control->range_all << ")"
                   << std::setprecision(0)
@@ -4021,7 +4055,7 @@ void Game::updateGui(float *statustext_time, const RunStats &stats,
                guitext->setVisible(true);
        } else if (flags.show_hud || flags.show_chat) {
                std::ostringstream os(std::ios_base::binary);
-               os << PROJECT_NAME " " << g_version_hash;
+               os << PROJECT_NAME_C " " << g_version_hash;
                guitext->setText(narrow_to_wide(os.str()).c_str());
                guitext->setVisible(true);
        } else {
@@ -4137,7 +4171,6 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
        // not using getRealTime is necessary for wine
        device->getTimer()->tick(); // Maker sure device time is up-to-date
        u32 time = device->getTimer()->getTime();
-
        u32 last_time = fps_timings->last_time;
 
        if (time > last_time)  // Make sure time hasn't overflowed
@@ -4255,7 +4288,7 @@ void the_game(bool *kill,
        } catch (SerializationError &e) {
                error_message = std::string("A serialization error occurred:\n")
                                + e.what() + "\n\nThe server is probably "
-                               " running a different version of " PROJECT_NAME ".";
+                               " running a different version of " PROJECT_NAME_C ".";
                errorstream << error_message << std::endl;
        } catch (ServerError &e) {
                error_message = e.what();