Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d2f7ed1

Browse files
committedSep 18, 2024
TopMenubar/WaterCfg: fixed frozen waves (basic/+refl/+refra) after unchecking 'Waves'
1 parent 91c4a01 commit d2f7ed1

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed
 

‎source/main/gfx/IWater.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class IWater //!< Common to classic water (Water.cpp, `class Water`) and HydraX
4545
virtual float GetStaticWaterHeight() = 0; //!< Returns static water level configured in 'terrn2'
4646
virtual void SetStaticWaterHeight(float value) = 0;
4747
virtual void SetWaterBottomHeight(float value) {};
48-
virtual void SetWavesHeight(float value) {};
4948
virtual float CalcWavesHeight(Ogre::Vector3 pos) = 0;
5049
virtual Ogre::Vector3 CalcWavesVelocity(Ogre::Vector3 pos) = 0;
5150
virtual void SetWaterVisible(bool value) = 0;
@@ -60,7 +59,11 @@ class IWater //!< Common to classic water (Water.cpp, `class Water`) and HydraX
6059
virtual void WaterSetSunPositon(Ogre::Vector3 pos) {}
6160
GfxWaterMode GetActiveWaterMode() { return m_active_water_mode; }
6261

63-
// Only used by class Water for SurveyMap texture creation
62+
// Only used by classic water (Water.cpp)
63+
virtual void SetWavesHeight(float value) {};
64+
virtual float GetWavesHeight() { return 0.f; };
65+
66+
// Only used by classic Water for SurveyMap texture creation
6467
virtual void SetForcedCameraTransform(Ogre::Radian fovy, Ogre::Vector3 pos, Ogre::Quaternion rot) {};
6568
virtual void ClearForcedCameraTransform() {};
6669

‎source/main/gfx/Water.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,20 @@ void Water::PrepareWater()
276276
}
277277

278278
// Water plane
279-
m_waterplane_mesh = MeshManager::getSingleton().createPlane("WaterPlane",
280-
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
281-
m_water_plane,
282-
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);
279+
m_waterplane_mesh = MeshManager::getSingleton().createPlane(
280+
"WaterPlane", // name
281+
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, // groupName
282+
m_water_plane, // plane (Ogre::Plane)
283+
m_map_size.x * m_waterplane_mesh_scale, // width
284+
m_map_size.z * m_waterplane_mesh_scale, // height
285+
WAVEREZ, // xsegments
286+
WAVEREZ, // ysegments
287+
true, // normals
288+
1, // numTexCoordSets
289+
50, // xTile
290+
50, // yTile
291+
Vector3::UNIT_Z, // upVector
292+
HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
283293
m_waterplane_entity = App::GetGfxScene()->GetSceneManager()->createEntity("plane", "WaterPlane");
284294

285295
// Water plane material
@@ -493,6 +503,11 @@ void Water::SetWavesHeight(float value)
493503
m_waves_height = value;
494504
}
495505

506+
float Water::GetWavesHeight()
507+
{
508+
return m_waves_height;
509+
}
510+
496511
void Water::SetWaterBottomHeight(float value)
497512
{
498513
m_bottom_height = value;

‎source/main/gfx/Water.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Water : public IWater
4949
void SetStaticWaterHeight(float value) override;
5050
void SetWaterBottomHeight(float value) override;
5151
void SetWavesHeight(float value) override;
52+
float GetWavesHeight() override;
5253
float CalcWavesHeight(Ogre::Vector3 pos) override;
5354
Ogre::Vector3 CalcWavesVelocity(Ogre::Vector3 pos) override;
5455
void SetWaterVisible(bool value) override;

‎source/main/gui/panels/GUI_TopMenubar.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,13 @@ void TopMenubar::Draw(float dt)
661661

662662
if (DrawGCombo(App::gfx_water_mode, _LC("TopMenubar", "Mode"), water_mode_combostring.c_str()))
663663
{
664-
water_waves_height = 0.f;
665664
App::GetGameContext()->PushMessage(Message(MSG_SIM_REINIT_WATER_REQUESTED));
666665
}
667666

668-
DrawGCheckbox(App::gfx_water_waves, _LC("TopMenubar", "Waves"));
667+
if (DrawGCheckbox(App::gfx_water_waves, _LC("TopMenubar", "Waves")))
668+
{
669+
App::GetGameContext()->PushMessage(Message(MSG_SIM_REINIT_WATER_REQUESTED));
670+
}
669671

670672
IWater* iwater = App::GetGameContext()->GetTerrain()->getWater();
671673

@@ -674,6 +676,7 @@ void TopMenubar::Draw(float dt)
674676
&& iwater->GetActiveWaterMode() != GfxWaterMode::NONE
675677
&& RoR::App::gfx_water_waves->getBool())
676678
{
679+
float water_waves_height = iwater->GetWavesHeight();
677680
if(ImGui::SliderFloat(_LC("TopMenubar", "Waves height"), &water_waves_height, 0.f, 4.f, ""))
678681
{
679682
App::GetGameContext()->GetTerrain()->getWater()->SetWavesHeight(water_waves_height);

‎source/main/gui/panels/GUI_TopMenubar.h

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ class TopMenubar
125125

126126
// Water settings menu
127127
std::string water_mode_combostring;
128-
float water_waves_height = 0.f;
129128

130129
private:
131130
bool IsMenuEnabled(TopMenu which);

0 commit comments

Comments
 (0)
Please sign in to comment.