Avoid cloud jump when switching between mainmenu and loading screen (#15163)

... by using the same Clouds object for both.
The mainmenu clouds already used shaders before. I had to choose between
both or neither, so now both the mainmenu clouds and the loading screen
clouds use shaders if available.
This commit is contained in:
grorp 2024-09-16 10:16:27 +02:00 committed by GitHub
parent 4aec4fbe6f
commit 47f199e6cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 52 deletions

View File

@ -140,8 +140,10 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
// Create the menu clouds
// This is only global so it can be used by RenderingEngine::draw_load_screen().
assert(!g_menucloudsmgr && !g_menuclouds);
std::unique_ptr<IWritableShaderSource> ssrc(createShaderSource());
ssrc->addShaderConstantSetterFactory(new FogShaderConstantSetterFactory());
g_menucloudsmgr = m_rendering_engine->get_scene_manager()->createNewSceneManager();
g_menuclouds = new Clouds(g_menucloudsmgr, nullptr, -1, rand());
g_menuclouds = new Clouds(g_menucloudsmgr, ssrc.get(), -1, rand());
g_menuclouds->setHeight(100.0f);
g_menuclouds->update(v3f(0, 0, 0), video::SColor(255, 240, 240, 255));
scene::ICameraSceneNode* camera;

View File

@ -28,11 +28,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include <cmath>
// Menu clouds are created later
class Clouds;
Clouds *g_menuclouds = NULL;
scene::ISceneManager *g_menucloudsmgr = NULL;
scene::ISceneManager *g_menucloudsmgr = nullptr;
Clouds *g_menuclouds = nullptr;
// Constant for now
static constexpr const float cloud_size = BS * 64.0f;
@ -49,9 +47,8 @@ Clouds::Clouds(scene::ISceneManager* mgr, IShaderSource *ssrc,
scene::ISceneNode(mgr->getRootSceneNode(), mgr, id),
m_seed(seed)
{
assert(ssrc);
m_enable_shaders = g_settings->getBool("enable_shaders");
// menu clouds use shader-less clouds for simplicity (ssrc == NULL)
m_enable_shaders = m_enable_shaders && ssrc;
m_material.Lighting = false;
m_material.BackfaceCulling = true;

View File

@ -36,11 +36,11 @@ namespace irr::scene
}
// Menu clouds
// The mainmenu and the loading screen use the same Clouds object so that the
// clouds don't jump when switching between the two.
class Clouds;
extern Clouds *g_menuclouds;
// Scene manager used for menu clouds
extern scene::ISceneManager *g_menucloudsmgr;
extern Clouds *g_menuclouds;
class Clouds : public scene::ISceneNode
{

View File

@ -142,10 +142,6 @@ GUIEngine::GUIEngine(JoystickController *joystick,
// create texture source
m_texture_source = std::make_unique<MenuTextureSource>(rendering_engine->get_video_driver());
// create shader source
// (currently only used by clouds)
m_shader_source.reset(createShaderSource());
// create soundmanager
#if USE_SOUND
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) {
@ -296,10 +292,6 @@ void GUIEngine::run()
IrrlichtDevice *device = m_rendering_engine->get_raw_device();
video::IVideoDriver *driver = device->getVideoDriver();
// Always create clouds because they may or may not be
// needed based on the game selected
cloudInit();
unsigned int text_height = g_fontengine->getTextHeight();
// Reset fog color
@ -395,8 +387,6 @@ GUIEngine::~GUIEngine()
m_irr_toplefttext->remove();
m_cloud.clouds.reset();
// delete textures
for (image_definition &texture : m_textures) {
if (texture.texture)
@ -404,26 +394,11 @@ GUIEngine::~GUIEngine()
}
}
/******************************************************************************/
void GUIEngine::cloudInit()
{
m_shader_source->addShaderConstantSetterFactory(
new FogShaderConstantSetterFactory());
m_cloud.clouds = make_irr<Clouds>(m_smgr, m_shader_source.get(), -1, rand());
m_cloud.clouds->setHeight(100.0f);
m_cloud.clouds->update(v3f(0, 0, 0), video::SColor(255,240,240,255));
m_cloud.camera = m_smgr->addCameraSceneNode(0,
v3f(0,0,0), v3f(0, 60, 100));
m_cloud.camera->setFarValue(10000);
}
/******************************************************************************/
void GUIEngine::drawClouds(float dtime)
{
m_cloud.clouds->step(dtime*3);
m_smgr->drawAll();
g_menuclouds->step(dtime * 3);
g_menucloudsmgr->drawAll();
}
/******************************************************************************/

View File

@ -203,8 +203,6 @@ private:
MainMenuData *m_data = nullptr;
/** texture source */
std::unique_ptr<ISimpleTextureSource> m_texture_source;
/** shader source */
std::unique_ptr<IWritableShaderSource> m_shader_source;
/** sound manager */
std::unique_ptr<ISoundManager> m_sound_manager;
@ -279,23 +277,11 @@ private:
/** and text that is in it */
EnrichedString m_toplefttext;
/** initialize cloud subsystem */
void cloudInit();
/** do preprocessing for cloud subsystem */
void drawClouds(float dtime);
/** internam data required for drawing clouds */
struct clouddata {
/** pointer to cloud class */
irr_ptr<Clouds> clouds;
/** camera required for drawing clouds */
scene::ICameraSceneNode *camera = nullptr;
};
/** is drawing of clouds enabled atm */
bool m_clouds_enabled = true;
/** data used to draw clouds */
clouddata m_cloud;
bool m_clouds_enabled = true;
static void fullscreenChangedCallback(const std::string &name, void *data);
};