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.
This commit is contained in:
swagtoy 2024-06-28 01:31:37 -04:00
parent b8959a0bac
commit b2792e59f7
11 changed files with 62 additions and 3 deletions

@ -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

@ -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)

@ -142,13 +142,14 @@ class ClientEnvironment : public Environment
const std::set<std::string> &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<std::string> 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;

@ -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) {}

@ -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);

@ -249,6 +249,7 @@ class GenericCAO : public ClientActiveObject
}
void updateLight(u32 day_night_ratio) override;
void updateSceneShadows() override;
void setNodeLight(const video::SColor &light);

@ -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")) {

@ -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);
}
}

@ -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 = "";

@ -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);

@ -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);