From b2792e59f735376889de310d844efeac49a7649a Mon Sep 17 00:00:00 2001 From: swagtoy Date: Fri, 28 Jun 2024 01:31:37 -0400 Subject: [PATCH] Reload graphics & dynamic shadows You can force reload graphics by showing the verbose debug page (press F5 a few times). It might be better to bind it to a specific keybind, but this was easier to implement and didn't require taking up another keybind. --- builtin/client/pause_menu.lua | 1 + src/client/clientenvironment.cpp | 6 ++++++ src/client/clientenvironment.h | 6 ++++-- src/client/clientobject.h | 1 + src/client/content_cao.cpp | 13 +++++++++++++ src/client/content_cao.h | 1 + src/client/game.cpp | 18 ++++++++++++++++++ src/client/render/factory.cpp | 2 +- src/gui/mainmenumanager.h | 7 +++++++ src/script/lua_api/l_client.cpp | 7 +++++++ src/script/lua_api/l_client.h | 3 +++ 11 files changed, 62 insertions(+), 3 deletions(-) diff --git a/builtin/client/pause_menu.lua b/builtin/client/pause_menu.lua index 8908954f8..7d2481ded 100644 --- a/builtin/client/pause_menu.lua +++ b/builtin/client/pause_menu.lua @@ -218,6 +218,7 @@ core.register_on_formspec_input(function(formname, fields) dialogdata.components = nil dialogdata.rightscroll = 0 core.show_settings() + core.reload_graphics() return true end end diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 7e1676ffe..7d38b538c 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -273,6 +273,9 @@ void ClientEnvironment::step(float dtime) auto cb_state = [this, dtime, update_lighting, day_night_ratio] (ClientActiveObject *cao) { // Step object cao->step(dtime, this); + + if (m_update_shadows) + cao->updateSceneShadows(); if (update_lighting) cao->updateLight(day_night_ratio); @@ -296,6 +299,9 @@ void ClientEnvironment::step(float dtime) ++i; } } + + if (m_update_shadows) + m_update_shadows = false; } void ClientEnvironment::addSimpleObject(ClientSimpleObject *simple) diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index bdb8b9726..8f6e4350b 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -142,13 +142,14 @@ class ClientEnvironment : public Environment const std::set &getPlayerNames() { return m_player_names; } void addPlayerName(const std::string &name) { m_player_names.insert(name); } void removePlayerName(const std::string &name) { m_player_names.erase(name); } - void updateCameraOffset(const v3s16 &camera_offset) - { m_camera_offset = camera_offset; } + void updateCameraOffset(const v3s16 &camera_offset) { m_camera_offset = camera_offset; } + void requestUpdateShadows() { m_update_shadows = true; } v3s16 getCameraOffset() const { return m_camera_offset; } void updateFrameTime(bool is_paused); u64 getFrameTime() const { return m_frame_time; } u64 getFrameTimeDelta() const { return m_frame_dtime; } + private: ClientMap *m_map; @@ -162,6 +163,7 @@ class ClientEnvironment : public Environment IntervalLimiter m_active_object_light_update_interval; std::set m_player_names; v3s16 m_camera_offset; + bool m_update_shadows = false; u64 m_frame_time = 0; u64 m_frame_dtime = 0; u64 m_frame_time_pause_accumulator = 0; diff --git a/src/client/clientobject.h b/src/client/clientobject.h index f63681313..83ef1e346 100644 --- a/src/client/clientobject.h +++ b/src/client/clientobject.h @@ -62,6 +62,7 @@ class ClientActiveObject : public ActiveObject virtual void updateAttachments() {}; virtual bool doShowSelectionBox() { return true; } + virtual void updateSceneShadows() {} // Step object in time virtual void step(float dtime, ClientEnvironment *env) {} diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 0044cc16e..e0207719a 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -604,6 +604,17 @@ void GenericCAO::removeFromScene(bool permanent) m_client->getMinimap()->removeMarker(&m_marker); } +void GenericCAO::updateSceneShadows() +{ + if (scene::ISceneNode *node = getSceneNode()) { + if (m_matrixnode) + node->setParent(m_matrixnode); + + if (auto shadow = RenderingEngine::get_shadow_renderer()) + shadow->addNodeToShadowList(node); + } +} + void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) { m_smgr = smgr; @@ -833,6 +844,8 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) if (m_reset_textures_timer < 0) updateTextures(m_current_texture_modifier); + + if (scene::ISceneNode *node = getSceneNode()) { if (m_matrixnode) node->setParent(m_matrixnode); diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 7fdcb73da..8e3a507bb 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -249,6 +249,7 @@ class GenericCAO : public ClientActiveObject } void updateLight(u32 day_night_ratio) override; + void updateSceneShadows() override; void setNodeLight(const video::SColor &light); diff --git a/src/client/game.cpp b/src/client/game.cpp index 2fa1e2fb3..8cbfc59e2 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -739,6 +739,7 @@ class Game { void updateCameraOrientation(CameraOrientation *cam, float dtime); void updatePlayerControl(const CameraOrientation &cam); void updatePauseState(); + void reloadGraphics(); void step(f32 dtime); void processClientEvents(CameraOrientation *cam); void updateCamera(f32 dtime); @@ -1126,6 +1127,12 @@ bool Game::startup(bool *kill, return true; } +inline void Game::reloadGraphics() +{ + m_rendering_engine->initialize(client, hud); + client->getEnv().requestUpdateShadows(); + +} void Game::run() { @@ -1802,6 +1809,8 @@ bool Game::getServerContent(bool *aborted) } + + /****************************************************************************/ /**************************************************************************** Run @@ -1865,9 +1874,15 @@ inline bool Game::handleCallbacks() if (g_gamecallback->unpause_requested) { m_is_paused = false; + m_rendering_engine->initialize(client, hud); g_gamecallback->unpause_requested = false; } + if (g_gamecallback->reload_graphics_requested) { + reloadGraphics(); + g_gamecallback->reload_graphics_requested = false; + } + if (g_gamecallback->show_settings_requested) { if (client->modsLoaded()) { @@ -1911,7 +1926,9 @@ void Game::updateDebugState() 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(); @@ -2523,6 +2540,7 @@ void Game::toggleDebug() } else if (!m_game_ui->m_flags.show_profiler_graph && !draw_control->show_wireframe) { if (has_basic_debug) m_game_ui->m_flags.show_basic_debug = true; + reloadGraphics(); 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")) { diff --git a/src/client/render/factory.cpp b/src/client/render/factory.cpp index 2e9d5eb5f..dbb33e9f3 100644 --- a/src/client/render/factory.cpp +++ b/src/client/render/factory.cpp @@ -82,4 +82,4 @@ void createPipeline(const std::string &stereo_mode, IrrlichtDevice *device, Clie // fallback to plain renderer errorstream << "Invalid rendering mode: " << stereo_mode << std::endl; populatePlainPipeline(result.pipeline, client); -} \ No newline at end of file +} diff --git a/src/gui/mainmenumanager.h b/src/gui/mainmenumanager.h index 06c8d22c2..08c5a9242 100644 --- a/src/gui/mainmenumanager.h +++ b/src/gui/mainmenumanager.h @@ -35,6 +35,7 @@ class IGameCallback virtual void changePassword() = 0; virtual void changeVolume() = 0; virtual void unpause() = 0; + virtual void reloadGraphics() = 0; virtual void showSettings() = 0; virtual void showOpenURLDialog(const std::string &url) = 0; virtual void signalKeyConfigChange() = 0; @@ -154,6 +155,11 @@ class MainGameCallback : public IGameCallback unpause_requested = true; } + void reloadGraphics() override + { + reload_graphics_requested = true; + } + void showSettings() override { show_settings_requested = true; @@ -165,6 +171,7 @@ class MainGameCallback : public IGameCallback bool keyconfig_requested = false; bool shutdown_requested = false; bool unpause_requested = false; + bool reload_graphics_requested = false; bool show_settings_requested = false; bool keyconfig_changed = false; std::string show_open_url_dialog = ""; diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 9d6cdf383..110426ad6 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -196,6 +196,12 @@ int ModApiClient::l_exit_to_os(lua_State *L) return 1; } +int ModApiClient::l_reload_graphics(lua_State *L) +{ + g_gamecallback->reloadGraphics(); + return 1; +} + int ModApiClient::l_key_config(lua_State *L) { g_gamecallback->keyConfig(); @@ -392,6 +398,7 @@ void ModApiClient::Initialize(lua_State *L, int top) API_FCT(disconnect); API_FCT(unpause); API_FCT(exit_to_os); + API_FCT(reload_graphics); API_FCT(key_config); API_FCT(get_meta); API_FCT(get_server_info); diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index 7f93d66ce..b26faa5a4 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -57,6 +57,9 @@ class ModApiClient : public ModApiBase // exit_to_os() static int l_exit_to_os(lua_State *L); + // reload_graphics() + static int l_reload_graphics(lua_State *L); + // key_config() static int l_key_config(lua_State *L);