Inventory: Send dirty lists where appropriate (#8742)
[oweals/minetest.git] / src / client / game.cpp
index f1257072032e0b7653de11678dc5091db8146655..5bf41bcd6efd0bb99ed83bdacc1d92923849f29e 100644 (file)
@@ -599,7 +599,6 @@ struct GameRunData {
        bool dig_instantly;
        bool digging_blocked;
        bool left_punch;
-       bool update_wielded_item_trigger;
        bool reset_jump_timer;
        float nodig_delay_timer;
        float dig_time;
@@ -689,8 +688,8 @@ protected:
        bool handleCallbacks();
        void processQueues();
        void updateProfilers(const RunStats &stats, const FpsControl &draw_times, f32 dtime);
-       void addProfilerGraphs(const RunStats &stats, const FpsControl &draw_times, f32 dtime);
        void updateStats(RunStats *stats, const FpsControl &draw_times, f32 dtime);
+       void updateProfilerGraphs(ProfilerGraph *graph);
 
        // Input related
        void processUserInput(f32 dtime);
@@ -751,7 +750,6 @@ protected:
                        const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
        void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                        const CameraOrientation &cam);
-       void updateProfilerGraphs(ProfilerGraph *graph);
 
        // Misc
        void limitFps(FpsControl *fps_timings, f32 *dtime);
@@ -1019,7 +1017,6 @@ bool Game::startup(bool *kill,
        // Reinit runData
        runData = GameRunData();
        runData.time_from_last_punch = 10.0;
-       runData.update_wielded_item_trigger = true;
 
        m_game_ui->initFlags();
 
@@ -1082,10 +1079,12 @@ void Game::run()
                        previous_screen_size = current_screen_size;
                }
 
-               /* Must be called immediately after a device->run() call because it
-                * uses device->getTimer()->getTime()
-                */
+               // Calculate dtime =
+               //    RenderingEngine::run() from this iteration
+               //  + Sleep time until the wanted FPS are reached
                limitFps(&draw_times, &dtime);
+               
+               // Prepare render data for next iteration
 
                updateStats(&stats, draw_times, dtime);
                updateInteractTimers(dtime);
@@ -1722,7 +1721,8 @@ void Game::processQueues()
 }
 
 
-void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times, f32 dtime)
+void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times,
+               f32 dtime)
 {
        float profiler_print_interval =
                        g_settings->getFloat("profiler_print_interval");
@@ -1730,7 +1730,7 @@ void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times,
 
        if (profiler_print_interval == 0) {
                print_to_log = false;
-               profiler_print_interval = 5;
+               profiler_print_interval = 3;
        }
 
        if (profiler_interval.step(dtime, profiler_print_interval)) {
@@ -1743,25 +1743,14 @@ void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times,
                g_profiler->clear();
        }
 
-       addProfilerGraphs(stats, draw_times, dtime);
-}
-
-
-void Game::addProfilerGraphs(const RunStats &stats,
-               const FpsControl &draw_times, f32 dtime)
-{
-       g_profiler->graphAdd("mainloop_other",
-                       draw_times.busy_time / 1000.0f - stats.drawtime / 1000.0f);
-
-       if (draw_times.sleep_time != 0)
-               g_profiler->graphAdd("mainloop_sleep", draw_times.sleep_time / 1000.0f);
-       g_profiler->graphAdd("mainloop_dtime", dtime);
+       // Update update graphs
+       g_profiler->graphAdd("Time non-rendering [ms]",
+               draw_times.busy_time - stats.drawtime);
 
-       g_profiler->add("Elapsed time", dtime);
-       g_profiler->avg("FPS", 1. / dtime);
+       g_profiler->graphAdd("Sleep [ms]", draw_times.sleep_time);
+       g_profiler->graphAdd("FPS", 1.0f / dtime);
 }
 
-
 void Game::updateStats(RunStats *stats, const FpsControl &draw_times,
                f32 dtime)
 {
@@ -2475,7 +2464,7 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
        }
 
        // autoforward if set: simulate "up" key
-       if (player->getPlayerSettings().continuous_forward) {
+       if (player->getPlayerSettings().continuous_forward && !player->isDead()) {
                control.up = true;
                keypress_bits |= 1U << 0;
        }
@@ -2492,7 +2481,7 @@ inline void Game::step(f32 *dtime)
        bool can_be_and_is_paused =
                        (simple_singleplayer_mode && g_menumgr.pausesGame());
 
-       if (can_be_and_is_paused) {     // This is for a singleplayer server
+       if (can_be_and_is_paused) { // This is for a singleplayer server
                *dtime = 0;             // No time passes
        } else {
                if (server)
@@ -3612,6 +3601,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
 void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                const CameraOrientation &cam)
 {
+       TimeTaker tt_update("Game::updateFrame()");
        LocalPlayer *player = client->getEnv().getLocalPlayer();
 
        /*
@@ -3636,7 +3626,6 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                direct_brightness = time_brightness;
                sunlight_seen = true;
        } else {
-               ScopeProfiler sp(g_profiler, "Detecting background light", SPT_AVG);
                float old_brightness = sky->getBrightness();
                direct_brightness = client->getEnv().getClientMap()
                                .getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS),
@@ -3745,19 +3734,11 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
        if (player->getWieldIndex() != runData.new_playeritem)
                client->setPlayerItem(runData.new_playeritem);
 
-       // Update local inventory if it has changed
-       if (client->getLocalInventoryUpdated()) {
-               //infostream<<"Updating local inventory"<<std::endl;
-               runData.update_wielded_item_trigger = true;
-       }
-
-       if (runData.update_wielded_item_trigger) {
+       if (client->updateWieldedItem()) {
                // Update wielded tool
                ItemStack selected_item, hand_item;
                ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item);
                camera->wield(tool_item);
-
-               runData.update_wielded_item_trigger = false;
        }
 
        /*
@@ -3810,7 +3791,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
        */
        const video::SColor &skycolor = sky->getSkyColor();
 
-       TimeTaker tt_draw("mainloop: draw");
+       TimeTaker tt_draw("Draw scene");
        driver->beginScene(true, true, skycolor);
 
        bool draw_wield_tool = (m_game_ui->m_flags.show_hud &&
@@ -3870,7 +3851,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
        driver->endScene();
 
        stats->drawtime = tt_draw.stop(true);
-       g_profiler->graphAdd("mainloop_draw", stats->drawtime / 1000.0f);
+       g_profiler->avg("Game::updateFrame(): draw scene [ms]", stats->drawtime);
+       g_profiler->graphAdd("Update frame [ms]", tt_update.stop(true));
 }
 
 /* Log times and stuff for visualization */