Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added water options to 'TopMenubar/Settings' menu. #3142

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/angelscript/Script2Game/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ enum MsgType
MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED, //!< Request revealing of hidden networked actor; used internally by top menubar. Params: 'instance_id' (int)
MSG_SIM_SCRIPT_EVENT_TRIGGERED, //!< Internal notification about triggering a script event, DO NOT PUSH MANUALLY.
MSG_SIM_SCRIPT_CALLBACK_QUEUED, //!< Internal notification about triggering a script event, DO NOT PUSH MANUALLY.
MSG_SIM_REINIT_WATER_REQUESTED, //!< Request restarting water subsystem based on cvar 'gfx_water_mode'. Use with caution.
// GUI
MSG_GUI_OPEN_MENU_REQUESTED,
MSG_GUI_CLOSE_MENU_REQUESTED,
Expand Down
4 changes: 1 addition & 3 deletions resources/hydrax/HydraxDefault.hdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ Components=Foam|Depth|Smooth|Caustics|Underwater|UnderwaterReflections
<size>Rtt_Quality_URDepth=0x0
<size>Rtt_Quality_GPUNormalMap=0x0

#Module options
Module=ProjectedGridVertex

#ProjectedGrid (PG) Module options
<float>PG_ChoopyStrength=0.375
<bool>PG_ChoppyWaves=true
<int>PG_Complexity=200
Expand Down
1 change: 1 addition & 0 deletions source/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ const char* MsgTypeToString(MsgType type)
case MSG_SIM_ADD_FREEFORCE_REQUESTED : return "MSG_SIM_ADD_FREEFORCE_REQUESTED";
case MSG_SIM_MODIFY_FREEFORCE_REQUESTED : return "MSG_SIM_MODIFY_FREEFORCE_REQUESTED";
case MSG_SIM_REMOVE_FREEFORCE_REQUESTED : return "MSG_SIM_REMOVE_FREEFORCE_REQUESTED";
case MSG_EDI_REINIT_WATER_REQUESTED : return "MSG_EDI_REINIT_WATER_REQUESTED";

case MSG_GUI_OPEN_MENU_REQUESTED : return "MSG_GUI_OPEN_MENU_REQUESTED";
case MSG_GUI_CLOSE_MENU_REQUESTED : return "MSG_GUI_CLOSE_MENU_REQUESTED";
Expand Down
1 change: 1 addition & 0 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ enum MsgType
MSG_EDI_CREATE_PROJECT_REQUESTED, //!< Payload = RoR::CreateProjectRequest* (owner)
MSG_EDI_MODIFY_PROJECT_REQUESTED, //!< Payload = RoR::UpdateProjectRequest* (owner)
MSG_EDI_DELETE_PROJECT_REQUESTED, //!< Payload = RoR::CacheEntryPtr* (owner)
MSG_EDI_REINIT_WATER_REQUESTED,
};

const char* MsgTypeToString(MsgType type);
Expand Down
18 changes: 11 additions & 7 deletions source/main/gfx/DustPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,19 @@ void DustPool::update()
}
else if (types[i] == DUST_RIPPLE)
{
positions[i].y = RoR::App::GetGameContext()->GetTerrain()->getWater()->GetStaticWaterHeight() - 0.02;
sns[i]->setPosition(positions[i]);
// Make sure water wasn't disabled in Top menubar - if yes, just drop the particle.
if (RoR::App::GetGameContext()->GetTerrain()->getWater())
{
positions[i].y = RoR::App::GetGameContext()->GetTerrain()->getWater()->GetStaticWaterHeight() - 0.02;
sns[i]->setPosition(positions[i]);

col.a = vel * 0.04;
col.b = 0.9;
col.g = 0.9;
col.r = 0.9;
col.a = vel * 0.04;
col.b = 0.9;
col.g = 0.9;
col.r = 0.9;

emit->setTimeToLive(vel * 0.04 / 0.1);
emit->setTimeToLive(vel * 0.04 / 0.1);
}
}

emit->setColour(col);
Expand Down
54 changes: 49 additions & 5 deletions source/main/gfx/HydraxWater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace Ogre;
using namespace RoR;

// HydraxWater
HydraxWater::HydraxWater(float water_height, Ogre::String conf_file):
HydraxWater::HydraxWater(float water_height, Ogre::TerrainGroup* terrain_grp, Ogre::String conf_file):
waternoise(0)
, mHydrax(0)
, waterHeight(water_height)
Expand All @@ -46,6 +46,15 @@ HydraxWater::HydraxWater(float water_height, Ogre::String conf_file):
App::GetCameraManager()->GetCamera()->setNearClipDistance(0.1f);

InitHydrax();

//Apply depth technique to the terrain
TerrainGroup::TerrainIterator ti = terrain_grp->getTerrainIterator();
while (ti.hasMoreElements())
{
Ogre::Terrain* t = ti.getNext()->instance;
MaterialPtr ptr = t->getMaterial();
mHydrax->getMaterialManager()->addDepthTechnique(ptr->createTechnique());
}
}

HydraxWater::~HydraxWater()
Expand Down Expand Up @@ -74,14 +83,14 @@ void HydraxWater::InitHydrax()

mHydrax->loadCfg(CurrentConfigFile);

// Choose shader language based on renderer (HLSL=0, CG=1, GLSL=2)
// Choose shader language based on renderer
if (Root::getSingleton().getRenderSystem()->getName() == "Direct3D9 Rendering Subsystem" || Root::getSingleton().getRenderSystem()->getName() == "Direct3D11 Rendering Subsystem")
{
mHydrax->setShaderMode(static_cast<Hydrax::MaterialManager::ShaderMode>(0));
mHydrax->setShaderMode(Hydrax::MaterialManager::SM_HLSL);
}
else
{
mHydrax->setShaderMode(static_cast<Hydrax::MaterialManager::ShaderMode>(2));
mHydrax->setShaderMode(Hydrax::MaterialManager::SM_GLSL);
}

mHydrax->create();
Expand Down Expand Up @@ -143,7 +152,7 @@ Vector3 HydraxWater::CalcWavesVelocity(Vector3 pos)
return Vector3(0, 0, 0); //TODO
}

void HydraxWater::WaterSetSunPosition(Ogre::Vector3 pos)
void HydraxWater::SetWaterSunPosition(Ogre::Vector3 pos)
{
if (mHydrax)
mHydrax->setSunPosition(pos);
Expand All @@ -158,3 +167,38 @@ void HydraxWater::FrameStepWater(float dt)
this->UpdateWater();
}

void HydraxWater::SetWaterColor(Ogre::ColourValue color)
{
if (mHydrax)
mHydrax->setWaterColor(Ogre::Vector3(color.r, color.g, color.b));
}

void HydraxWater::SetWaterGridOptions(Hydrax::Module::ProjectedGrid::Options options)
{
// Assert on Debug, minimize damage on Release
Hydrax::Module::Module* module = mHydrax->getModule();
ROR_ASSERT(module);
if (!module)
{
LOG("[RoR] ERROR - cannot set hydrax water grid options, hydrax not running correctly.");
return;
}

Hydrax::Module::ProjectedGrid* pgrid = static_cast<Hydrax::Module::ProjectedGrid*>(module);
pgrid->setOptions(options);
}

Hydrax::Module::ProjectedGrid::Options HydraxWater::GetWaterGridOptions()
{
// Assert on Debug, minimize damage on Release
Hydrax::Module::Module* module = mHydrax->getModule();
ROR_ASSERT(module);
if (!module)
{
LOG("[RoR] ERROR - cannot get hydrax water grid options, hydrax not running correctly.");
return Hydrax::Module::ProjectedGrid::Options();
}

Hydrax::Module::ProjectedGrid* pgrid = static_cast<Hydrax::Module::ProjectedGrid*>(module);
return pgrid->getOptions();
}
10 changes: 6 additions & 4 deletions source/main/gfx/HydraxWater.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ProjectedGrid.h"

#include <Ogre.h>
#include <OgreTerrainGroup.h>

namespace RoR {

Expand All @@ -35,7 +36,7 @@ class HydraxWater : public IWater
{
public:

HydraxWater(float waterHeight, Ogre::String configFile = "HydraxDefault.hdx");
HydraxWater(float waterHeight, Ogre::TerrainGroup* terrain_grp, Ogre::String configFile = "HydraxDefault.hdx");
~HydraxWater();

// Interface IWater
Expand All @@ -44,12 +45,13 @@ class HydraxWater : public IWater
float CalcWavesHeight(Ogre::Vector3 pos) override;
Ogre::Vector3 CalcWavesVelocity(Ogre::Vector3 pos) override;
void SetWaterVisible(bool value) override;
void WaterSetSunPosition(Ogre::Vector3) override;
void SetWaterSunPosition(Ogre::Vector3) override;
bool IsUnderWater(Ogre::Vector3 pos) override;
void FrameStepWater(float dt) override;
void UpdateWater() override;

Hydrax::Hydrax* GetHydrax() { return mHydrax; }
void SetWaterColor(Ogre::ColourValue color) override;
Hydrax::Module::ProjectedGrid::Options GetWaterGridOptions() override;
void SetWaterGridOptions(Hydrax::Module::ProjectedGrid::Options options) override;

protected:

Expand Down
23 changes: 19 additions & 4 deletions source/main/gfx/IWater.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@
#pragma once

#include "ForwardDeclarations.h"
#include "ProjectedGrid.h" // HydraX
#include <Ogre.h>

namespace RoR {

/// @addtogroup Gfx
/// @{

class IWater //!< TODO: Mixed gfx+physics (waves) - must be separated ~ only_a_ptr, 02/2018
class IWater //!< Common to classic water (Water.cpp, `class Water`) and HydraX water (HydraxWater.cpp, `class HydraxWater`)
{
public:
IWater()
{
m_active_water_mode = App::gfx_water_mode->getEnum<GfxWaterMode>();
}

virtual ~IWater()
Expand All @@ -43,21 +45,34 @@ class IWater //!< TODO: Mixed gfx+physics (waves) - must be separated ~ only_a_p
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;
virtual void WaterSetSunPosition(Ogre::Vector3) {}
virtual void SetWaterSunPosition(Ogre::Vector3) {}
virtual bool IsUnderWater(Ogre::Vector3 pos) = 0;
virtual void FrameStepWater(float dt) = 0;
virtual void SetReflectionPlaneHeight(float centerheight) {}
virtual void UpdateReflectionPlane(float h) {}
virtual void WaterPrepareShutdown() {}
virtual void UpdateWater() = 0;
virtual void SetWaterColor(Ogre::ColourValue color) {}
virtual void WaterSetSunPositon(Ogre::Vector3 pos) {}
GfxWaterMode GetActiveWaterMode() { return m_active_water_mode; }

// Only used by classic water (Water.cpp)
virtual void SetWavesHeight(float value) {};
virtual float GetWavesHeight() { return 0.f; };

// Only used by class Water for SurveyMap texture creation
// Only used by classic Water for SurveyMap texture creation
virtual void SetForcedCameraTransform(Ogre::Radian fovy, Ogre::Vector3 pos, Ogre::Quaternion rot) {};
virtual void ClearForcedCameraTransform() {};

// Only for HydraX at the moment, but will be unified
virtual Hydrax::Module::ProjectedGrid::Options GetWaterGridOptions() { return Hydrax::Module::ProjectedGrid::Options(); }
virtual void SetWaterGridOptions(Hydrax::Module::ProjectedGrid::Options options) {};

protected:
GfxWaterMode m_active_water_mode; //!< A snapshot of cvar `gfx_water_mode` at the time of water creation - because the cvar can change (i.e. via TopMenubar or scripting, see also `MSG_EDI_REINIT_WATER_REQUESTED`)
};

/// @} // addtogroup Gfx
Expand Down
15 changes: 8 additions & 7 deletions source/main/gfx/SkyXManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ bool SkyXManager::UpdateSkyLight()
// Calculate current color gradients point
float point = (-lightDir.y + 1.0f) / 2.0f;

if (App::GetGameContext()->GetTerrain()->getHydraxManager ())
{
App::GetGameContext()->GetTerrain()->getHydraxManager ()->GetHydrax ()->setWaterColor (mWaterGradient.getColor (point));
App::GetGameContext()->GetTerrain()->getHydraxManager ()->GetHydrax ()->setSunPosition (sunPos*0.1);
}

IWater* iwater = App::GetGameContext()->GetTerrain()->getWater();
if (iwater)
{
Ogre::Vector3 waterCol = mWaterGradient.getColor(point);
iwater->SetWaterColor(Ogre::ColourValue(waterCol.x, waterCol.y, waterCol.z));
iwater->SetWaterSunPosition(sunPos*0.1);
}

mLight0 = App::GetGfxScene()->GetSceneManager()->getLight("Light0");
mLight1 = App::GetGfxScene()->GetSceneManager()->getLight("Light1");
Expand All @@ -105,7 +106,7 @@ bool SkyXManager::UpdateSkyLight()
mLight1->setDirection(lightDir);
if (App::GetGameContext()->GetTerrain()->getWater())
{
App::GetGameContext()->GetTerrain()->getWater()->WaterSetSunPosition(sunPos*0.1);
App::GetGameContext()->GetTerrain()->getWater()->SetWaterSunPosition(sunPos*0.1);
}

//setFadeColour was removed with https://github.com/RigsOfRods/rigs-of-rods/pull/1459
Expand Down
Loading