]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/game.cpp
Remove unused ITextSceneNode header (#11476)
[dragonfireclient.git] / src / client / game.cpp
index eb1dbb5a3254bc7c80d894bfe27f741fed6b9c96..85dd8f4bbd9d5f90c9def68cd792bd349375a789 100644 (file)
@@ -609,6 +609,7 @@ struct GameRunData {
        float jump_timer;
        float damage_flash;
        float update_draw_list_timer;
+       float update_shadows_timer;
 
        f32 fog_range;
 
@@ -676,6 +677,7 @@ class Game {
        bool handleCallbacks();
        void processQueues();
        void updateProfilers(const RunStats &stats, const FpsControl &draw_times, f32 dtime);
+       void updateDebugState();
        void updateStats(RunStats *stats, const FpsControl &draw_times, f32 dtime);
        void updateProfilerGraphs(ProfilerGraph *graph);
 
@@ -693,6 +695,7 @@ class Game {
        void toggleFast();
        void toggleNoClip();
        void toggleCinematic();
+       void toggleBlockBounds();
        void toggleAutoforward();
 
        void toggleMinimap(bool shift_pressed);
@@ -738,6 +741,7 @@ class Game {
                        const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
        void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                        const CameraOrientation &cam);
+       void updateShadows();
 
        // Misc
        void limitFps(FpsControl *fps_timings, f32 *dtime);
@@ -1107,6 +1111,7 @@ void Game::run()
                m_game_ui->clearInfoText();
                hud->resizeHotbar();
 
+
                updateProfilers(stats, draw_times, dtime);
                processUserInput(dtime);
                // Update camera before player movement to avoid camera lag of one frame
@@ -1118,10 +1123,11 @@ void Game::run()
                updatePlayerControl(cam_view);
                step(&dtime);
                processClientEvents(&cam_view_target);
+               updateDebugState();
                updateCamera(draw_times.busy_time, dtime);
                updateSound(dtime);
                processPlayerInteraction(dtime, m_game_ui->m_flags.show_hud,
-                       m_game_ui->m_flags.show_debug);
+                       m_game_ui->m_flags.show_basic_debug);
                updateFrame(&graph, &stats, dtime, cam_view);
                updateProfilerGraphs(&graph);
 
@@ -1722,6 +1728,25 @@ void Game::processQueues()
        shader_src->processQueue();
 }
 
+void Game::updateDebugState()
+{
+       bool has_basic_debug = client->checkPrivilege("basic_debug");
+       bool has_debug = client->checkPrivilege("debug");
+
+       if (m_game_ui->m_flags.show_basic_debug) {
+               if (!has_basic_debug) {
+                       m_game_ui->m_flags.show_basic_debug = false;
+               }
+       } else if (m_game_ui->m_flags.show_minimal_debug) {
+               if (has_basic_debug) {
+                       m_game_ui->m_flags.show_basic_debug = true;
+               }
+       }
+       if (!has_basic_debug)
+               hud->disableBlockBounds();
+       if (!has_debug)
+               draw_control->show_wireframe = false;
+}
 
 void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times,
                f32 dtime)
@@ -1934,7 +1959,7 @@ void Game::processKeyInput()
        } else if (wasKeyDown(KeyType::SCREENSHOT)) {
                client->makeScreenshot();
        } else if (wasKeyDown(KeyType::TOGGLE_BLOCK_BOUNDS)) {
-               hud->toggleBlockBounds();
+               toggleBlockBounds();
        } else if (wasKeyDown(KeyType::TOGGLE_HUD)) {
                m_game_ui->toggleHud();
        } else if (wasKeyDown(KeyType::MINIMAP)) {
@@ -2172,6 +2197,15 @@ void Game::toggleCinematic()
                m_game_ui->showTranslatedStatusText("Cinematic mode disabled");
 }
 
+void Game::toggleBlockBounds()
+{
+       if (client->checkPrivilege("basic_debug")) {
+               hud->toggleBlockBounds();
+       } else {
+               m_game_ui->showTranslatedStatusText("Can't show block bounds (need 'basic_debug' privilege)");
+       }
+}
+
 // Autoforward by toggling continuous forward.
 void Game::toggleAutoforward()
 {
@@ -2235,24 +2269,41 @@ void Game::toggleFog()
 
 void Game::toggleDebug()
 {
-       // Initial / 4x toggle: Chat only
-       // 1x toggle: Debug text with chat
+       // Initial: No debug info
+       // 1x toggle: Debug text
        // 2x toggle: Debug text with profiler graph
-       // 3x toggle: Debug text and wireframe
-       if (!m_game_ui->m_flags.show_debug) {
-               m_game_ui->m_flags.show_debug = true;
+       // 3x toggle: Debug text and wireframe (needs "debug" priv)
+       // Next toggle: Back to initial
+       //
+       // The debug text can be in 2 modes: minimal and basic.
+       // * Minimal: Only technical client info that not gameplay-relevant
+       // * Basic: Info that might give gameplay advantage, e.g. pos, angle
+       // Basic mode is used when player has "basic_debug" priv,
+       // otherwise the Minimal mode is used.
+       if (!m_game_ui->m_flags.show_minimal_debug) {
+               m_game_ui->m_flags.show_minimal_debug = true;
+               if (client->checkPrivilege("basic_debug")) {
+                       m_game_ui->m_flags.show_basic_debug = true;
+               }
                m_game_ui->m_flags.show_profiler_graph = false;
                draw_control->show_wireframe = false;
                m_game_ui->showTranslatedStatusText("Debug info shown");
        } else if (!m_game_ui->m_flags.show_profiler_graph && !draw_control->show_wireframe) {
+               if (client->checkPrivilege("basic_debug")) {
+                       m_game_ui->m_flags.show_basic_debug = true;
+               }
                m_game_ui->m_flags.show_profiler_graph = true;
                m_game_ui->showTranslatedStatusText("Profiler graph shown");
        } else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {
+               if (client->checkPrivilege("basic_debug")) {
+                       m_game_ui->m_flags.show_basic_debug = true;
+               }
                m_game_ui->m_flags.show_profiler_graph = false;
                draw_control->show_wireframe = true;
                m_game_ui->showTranslatedStatusText("Wireframe shown");
        } else {
-               m_game_ui->m_flags.show_debug = false;
+               m_game_ui->m_flags.show_minimal_debug = false;
+               m_game_ui->m_flags.show_basic_debug = false;
                m_game_ui->m_flags.show_profiler_graph = false;
                draw_control->show_wireframe = false;
                if (client->checkPrivilege("debug")) {
@@ -3830,14 +3881,31 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                changed much
        */
        runData.update_draw_list_timer += dtime;
+       runData.update_shadows_timer += dtime;
+
+       float update_draw_list_delta = 0.2f;
+       bool draw_list_updated = false;
 
        v3f camera_direction = camera->getDirection();
-       if (runData.update_draw_list_timer >= 0.2
+       if (runData.update_draw_list_timer >= update_draw_list_delta
                        || runData.update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2
                        || m_camera_offset_changed) {
+
                runData.update_draw_list_timer = 0;
                client->getEnv().getClientMap().updateDrawList();
                runData.update_draw_list_last_cam_dir = camera_direction;
+               draw_list_updated = true;
+       }
+
+       if (ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer()) {
+               update_draw_list_delta = shadow->getUpdateDelta();
+
+               if (m_camera_offset_changed ||
+                               (runData.update_shadows_timer > update_draw_list_delta &&
+                               (!draw_list_updated || shadow->getDirectionalLightCount() == 0))) {
+                       runData.update_shadows_timer = 0;
+                       updateShadows();
+               }
        }
 
        m_game_ui->update(*stats, client, draw_control, cam, runData.pointed_old, gui_chat_console, dtime);
@@ -3968,7 +4036,34 @@ inline void Game::updateProfilerGraphs(ProfilerGraph *graph)
        graph->put(values);
 }
 
+/****************************************************************************
+ * Shadows
+ *****************************************************************************/
+void Game::updateShadows()
+{
+       ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer();
+       if (!shadow)
+               return;
+
+       float in_timeofday = fmod(runData.time_of_day_smooth, 1.0f);
+
+       float timeoftheday = fmod(getWickedTimeOfDay(in_timeofday) + 0.75f, 0.5f) + 0.25f;
+       const float offset_constant = 10000.0f;
 
+       v3f light(0.0f, 0.0f, -1.0f);
+       light.rotateXZBy(90);
+       light.rotateXYBy(timeoftheday * 360 - 90);
+       light.rotateYZBy(sky->getSkyBodyOrbitTilt());
+
+       v3f sun_pos = light * offset_constant;
+
+       if (shadow->getDirectionalLightCount() == 0)
+               shadow->addDirectionalLight();
+       shadow->getDirectionalLight().setDirection(sun_pos);
+       shadow->setTimeOfDay(in_timeofday);
+
+       shadow->getDirectionalLight().update_frustum(camera, client);
+}
 
 /****************************************************************************
  Misc