From 6c53409e41453bb807464406513864a120013287 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sun, 1 Sep 2024 17:41:40 +0200 Subject: [PATCH] TopMenubar/WaterCfg: fixed frozen waves (basic/+refl/+refra) after unchecking 'Waves' --- source/main/gfx/IWater.h | 7 +++++-- source/main/gfx/Water.cpp | 23 +++++++++++++++++++---- source/main/gfx/Water.h | 1 + source/main/gui/panels/GUI_TopMenubar.cpp | 7 +++++-- source/main/gui/panels/GUI_TopMenubar.h | 1 - 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/source/main/gfx/IWater.h b/source/main/gfx/IWater.h index 053e71a49e..60cf28fdcf 100644 --- a/source/main/gfx/IWater.h +++ b/source/main/gfx/IWater.h @@ -45,7 +45,6 @@ class IWater //!< Common to classic water (Water.cpp, `class Water`) and HydraX virtual float GetStaticWaterHeight() = 0; //!< Returns static water level configured in 'terrn2' virtual void SetStaticWaterHeight(float value) = 0; virtual void SetWaterBottomHeight(float value) {}; - virtual void SetWavesHeight(float value) {}; virtual float CalcWavesHeight(Ogre::Vector3 pos) = 0; virtual Ogre::Vector3 CalcWavesVelocity(Ogre::Vector3 pos) = 0; virtual void SetWaterVisible(bool value) = 0; @@ -60,7 +59,11 @@ class IWater //!< Common to classic water (Water.cpp, `class Water`) and HydraX virtual void WaterSetSunPositon(Ogre::Vector3 pos) {} GfxWaterMode GetActiveWaterMode() { return m_active_water_mode; } - // Only used by class Water for SurveyMap texture creation + // Only used by classic water (Water.cpp) + virtual void SetWavesHeight(float value) {}; + virtual float GetWavesHeight() { return 0.f; }; + + // Only used by classic Water for SurveyMap texture creation virtual void SetForcedCameraTransform(Ogre::Radian fovy, Ogre::Vector3 pos, Ogre::Quaternion rot) {}; virtual void ClearForcedCameraTransform() {}; diff --git a/source/main/gfx/Water.cpp b/source/main/gfx/Water.cpp index a073198f2b..b465fea3c4 100644 --- a/source/main/gfx/Water.cpp +++ b/source/main/gfx/Water.cpp @@ -276,10 +276,20 @@ void Water::PrepareWater() } // Water plane - m_waterplane_mesh = MeshManager::getSingleton().createPlane("WaterPlane", - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - m_water_plane, - m_map_size.x * m_waterplane_mesh_scale, m_map_size.z * m_waterplane_mesh_scale, WAVEREZ, WAVEREZ, true, 1, 50, 50, Vector3::UNIT_Z, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE); + m_waterplane_mesh = MeshManager::getSingleton().createPlane( + "WaterPlane", // name + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, // groupName + m_water_plane, // plane (Ogre::Plane) + m_map_size.x * m_waterplane_mesh_scale, // width + m_map_size.z * m_waterplane_mesh_scale, // height + WAVEREZ, // xsegments + WAVEREZ, // ysegments + true, // normals + 1, // numTexCoordSets + 50, // xTile + 50, // yTile + Vector3::UNIT_Z, // upVector + HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE); m_waterplane_entity = App::GetGfxScene()->GetSceneManager()->createEntity("plane", "WaterPlane"); // Water plane material @@ -493,6 +503,11 @@ void Water::SetWavesHeight(float value) m_waves_height = value; } +float Water::GetWavesHeight() +{ + return m_waves_height; +} + void Water::SetWaterBottomHeight(float value) { m_bottom_height = value; diff --git a/source/main/gfx/Water.h b/source/main/gfx/Water.h index c7197d1ee5..10a0de26cc 100644 --- a/source/main/gfx/Water.h +++ b/source/main/gfx/Water.h @@ -49,6 +49,7 @@ class Water : public IWater void SetStaticWaterHeight(float value) override; void SetWaterBottomHeight(float value) override; void SetWavesHeight(float value) override; + float GetWavesHeight() override; float CalcWavesHeight(Ogre::Vector3 pos) override; Ogre::Vector3 CalcWavesVelocity(Ogre::Vector3 pos) override; void SetWaterVisible(bool value) override; diff --git a/source/main/gui/panels/GUI_TopMenubar.cpp b/source/main/gui/panels/GUI_TopMenubar.cpp index 268bcc45d4..801b8808d0 100644 --- a/source/main/gui/panels/GUI_TopMenubar.cpp +++ b/source/main/gui/panels/GUI_TopMenubar.cpp @@ -661,11 +661,13 @@ void TopMenubar::Draw(float dt) if (DrawGCombo(App::gfx_water_mode, _LC("TopMenubar", "Mode"), water_mode_combostring.c_str())) { - water_waves_height = 0.f; App::GetGameContext()->PushMessage(Message(MSG_SIM_REINIT_WATER_REQUESTED)); } - DrawGCheckbox(App::gfx_water_waves, _LC("TopMenubar", "Waves")); + if (DrawGCheckbox(App::gfx_water_waves, _LC("TopMenubar", "Waves"))) + { + App::GetGameContext()->PushMessage(Message(MSG_SIM_REINIT_WATER_REQUESTED)); + } IWater* iwater = App::GetGameContext()->GetTerrain()->getWater(); @@ -674,6 +676,7 @@ void TopMenubar::Draw(float dt) && iwater->GetActiveWaterMode() != GfxWaterMode::NONE && RoR::App::gfx_water_waves->getBool()) { + float water_waves_height = iwater->GetWavesHeight(); if(ImGui::SliderFloat(_LC("TopMenubar", "Waves height"), &water_waves_height, 0.f, 4.f, "")) { App::GetGameContext()->GetTerrain()->getWater()->SetWavesHeight(water_waves_height); diff --git a/source/main/gui/panels/GUI_TopMenubar.h b/source/main/gui/panels/GUI_TopMenubar.h index adb337d192..6835d396ff 100644 --- a/source/main/gui/panels/GUI_TopMenubar.h +++ b/source/main/gui/panels/GUI_TopMenubar.h @@ -125,7 +125,6 @@ class TopMenubar // Water settings menu std::string water_mode_combostring; - float water_waves_height = 0.f; private: bool IsMenuEnabled(TopMenu which);