Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp
Show All 15 Lines | |||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "MessageHandler.h" | #include "MessageHandler.h" | ||||
#include "../CommandProc.h" | #include "../CommandProc.h" | ||||
#include "graphics/GameView.h" | |||||
#include "graphics/LightEnv.h" | #include "graphics/LightEnv.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "graphics/WaterManager.h" | |||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/PostprocManager.h" | #include "renderer/PostprocManager.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/SkyManager.h" | #include "renderer/SkyManager.h" | ||||
#include "renderer/WaterManager.h" | |||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
namespace AtlasMessage { | namespace AtlasMessage { | ||||
sEnvironmentSettings GetSettings() | sEnvironmentSettings GetSettings() | ||||
{ | { | ||||
sEnvironmentSettings s; | sEnvironmentSettings s; | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | ||||
ENSURE(cmpWaterManager); | ENSURE(cmpWaterManager); | ||||
s.waterheight = cmpWaterManager->GetExactWaterLevel(0, 0) / (65536.f * HEIGHT_SCALE); | s.waterheight = cmpWaterManager->GetExactWaterLevel(0, 0) / (65536.f * HEIGHT_SCALE); | ||||
WaterManager* wm = g_Renderer.GetWaterManager(); | const WaterManager* wm = &g_Game->GetView()->GetWaterManager(); | ||||
s.watertype = wm->m_WaterType; | s.watertype = wm->GetWaterType(); | ||||
s.waterwaviness = wm->m_Waviness; | s.waterwaviness = wm->m_Waviness; | ||||
s.watermurkiness = wm->m_Murkiness; | s.watermurkiness = wm->m_Murkiness; | ||||
s.windangle = wm->m_WindAngle; | s.windangle = wm->m_WindAngle; | ||||
// CColor colors | // CColor colors | ||||
#define COLOR(A, B) A = Color((int)(B.r*255), (int)(B.g*255), (int)(B.b*255)) | #define COLOR(A, B) A = Color((int)(B.r*255), (int)(B.g*255), (int)(B.b*255)) | ||||
COLOR(s.watercolor, wm->m_WaterColor); | COLOR(s.watercolor, wm->m_WaterColor); | ||||
COLOR(s.watertint, wm->m_WaterTint); | COLOR(s.watertint, wm->m_WaterTint); | ||||
Show All 36 Lines | |||||
void SetSettings(const sEnvironmentSettings& s) | void SetSettings(const sEnvironmentSettings& s) | ||||
{ | { | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | ||||
ENSURE(cmpWaterManager); | ENSURE(cmpWaterManager); | ||||
cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(s.waterheight * (65536.f * HEIGHT_SCALE))); | cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(s.waterheight * (65536.f * HEIGHT_SCALE))); | ||||
WaterManager* wm = g_Renderer.GetWaterManager(); | WaterManager* wm = &g_Game->GetView()->GetMutableWaterManager(); | ||||
wm->m_Waviness = s.waterwaviness; | wm->m_Waviness = s.waterwaviness; | ||||
wm->m_Murkiness = s.watermurkiness; | wm->m_Murkiness = s.watermurkiness; | ||||
wm->m_WindAngle = s.windangle; | wm->m_WindAngle = s.windangle; | ||||
if (wm->m_WaterType != *s.watertype) | wm->SetWaterType(*s.watertype); | ||||
{ | |||||
wm->m_WaterType = *s.watertype; | |||||
wm->ReloadWaterNormalTextures(); | |||||
} | |||||
#define COLOR(A, B) B = CColor(A->r/255.f, A->g/255.f, A->b/255.f, 1.f) | #define COLOR(A, B) B = CColor(A->r/255.f, A->g/255.f, A->b/255.f, 1.f) | ||||
COLOR(s.watercolor, wm->m_WaterColor); | COLOR(s.watercolor, wm->m_WaterColor); | ||||
COLOR(s.watertint, wm->m_WaterTint); | COLOR(s.watertint, wm->m_WaterTint); | ||||
#undef COLOR | #undef COLOR | ||||
g_LightEnv.SetRotation(s.sunrotation); | g_LightEnv.SetRotation(s.sunrotation); | ||||
g_LightEnv.SetElevation(s.sunelevation); | g_LightEnv.SetElevation(s.sunelevation); | ||||
Show All 17 Lines | #undef COLOR | ||||
g_LightEnv.m_Bloom = s.bloom; | g_LightEnv.m_Bloom = s.bloom; | ||||
#define COLOR(A, B) B = RGBColor(A->r/255.f, A->g/255.f, A->b/255.f) | #define COLOR(A, B) B = RGBColor(A->r/255.f, A->g/255.f, A->b/255.f) | ||||
COLOR(s.suncolor, g_LightEnv.m_SunColor); | COLOR(s.suncolor, g_LightEnv.m_SunColor); | ||||
g_LightEnv.m_SunColor *= s.sunoverbrightness; | g_LightEnv.m_SunColor *= s.sunoverbrightness; | ||||
COLOR(s.ambientcolor, g_LightEnv.m_AmbientColor); | COLOR(s.ambientcolor, g_LightEnv.m_AmbientColor); | ||||
COLOR(s.fogcolor, g_LightEnv.m_FogColor); | COLOR(s.fogcolor, g_LightEnv.m_FogColor); | ||||
#undef COLOR | #undef COLOR | ||||
cmpWaterManager->RecomputeWaterData(); | |||||
} | } | ||||
BEGIN_COMMAND(SetEnvironmentSettings) | BEGIN_COMMAND(SetEnvironmentSettings) | ||||
{ | { | ||||
sEnvironmentSettings m_OldSettings, m_NewSettings; | sEnvironmentSettings m_OldSettings, m_NewSettings; | ||||
void Do() | void Do() | ||||
{ | { | ||||
Show All 23 Lines | |||||
{ | { | ||||
void Do() | void Do() | ||||
{ | { | ||||
Redo(); | Redo(); | ||||
} | } | ||||
void Redo() | void Redo() | ||||
{ | { | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | // Hack to trigger a recomputation. | ||||
ENSURE(cmpWaterManager); | float height = g_Game->GetView()->GetMutableWaterManager().GetWaterHeight(); | ||||
g_Game->GetView()->GetMutableWaterManager().SetWaterHeight(height + 1.f); | |||||
cmpWaterManager->RecomputeWaterData(); | g_Game->GetView()->GetMutableWaterManager().SetWaterHeight(height); | ||||
g_Game->GetView()->GetMutableWaterManager().RecomputeWaterDataIfNeeded(); | |||||
} | } | ||||
void Undo() | void Undo() | ||||
{ | { | ||||
Redo(); | Redo(); | ||||
} | } | ||||
}; | }; | ||||
Show All 26 Lines | BEGIN_COMMAND(PickWaterHeight) | ||||
} | } | ||||
void SetWaterHeight(entity_pos_t height) | void SetWaterHeight(entity_pos_t height) | ||||
{ | { | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | ||||
ENSURE(cmpWaterManager); | ENSURE(cmpWaterManager); | ||||
cmpWaterManager->SetWaterLevel(height); | cmpWaterManager->SetWaterLevel(height); | ||||
cmpWaterManager->RecomputeWaterData(); | |||||
} | } | ||||
}; | }; | ||||
END_COMMAND(PickWaterHeight) | END_COMMAND(PickWaterHeight) | ||||
QUERYHANDLER(GetEnvironmentSettings) | QUERYHANDLER(GetEnvironmentSettings) | ||||
{ | { | ||||
msg->settings = GetSettings(); | msg->settings = GetSettings(); | ||||
Show All 16 Lines |
Wildfire Games · Phabricator