Skip to content

Commit

Permalink
TopMenubar/WaterCfg: fixed frozen waves (basic/+refl/+refra) after un…
Browse files Browse the repository at this point in the history
…checking 'Waves'
  • Loading branch information
ohlidalp committed Sep 1, 2024
1 parent dc33d4c commit 6c53409
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
7 changes: 5 additions & 2 deletions source/main/gfx/IWater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {};

Expand Down
23 changes: 19 additions & 4 deletions source/main/gfx/Water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/main/gfx/Water.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion source/main/gui/panels/GUI_TopMenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6c53409

Please sign in to comment.