LCOV - code coverage report
Current view: top level - source/tools/atlas/GameInterface/Handlers - EnvironmentHandlers.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 131 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 60 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2022 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "precompiled.h"
      19             : 
      20             : #include "MessageHandler.h"
      21             : 
      22             : #include "../CommandProc.h"
      23             : 
      24             : #include "graphics/LightEnv.h"
      25             : #include "graphics/Terrain.h"
      26             : #include "maths/MathUtil.h"
      27             : #include "ps/CStr.h"
      28             : #include "ps/Game.h"
      29             : #include "ps/World.h"
      30             : #include "renderer/PostprocManager.h"
      31             : #include "renderer/Renderer.h"
      32             : #include "renderer/SceneRenderer.h"
      33             : #include "renderer/SkyManager.h"
      34             : #include "renderer/WaterManager.h"
      35             : #include "simulation2/Simulation2.h"
      36             : #include "simulation2/components/ICmpWaterManager.h"
      37             : 
      38             : namespace AtlasMessage {
      39             : 
      40           0 : sEnvironmentSettings GetSettings()
      41             : {
      42           0 :     sEnvironmentSettings s;
      43             : 
      44           0 :     CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
      45           0 :     ENSURE(cmpWaterManager);
      46             : 
      47           0 :     s.waterheight = cmpWaterManager->GetExactWaterLevel(0, 0) / (65536.f * HEIGHT_SCALE);
      48             : 
      49           0 :     const WaterManager& waterManager = g_Renderer.GetSceneRenderer().GetWaterManager();
      50           0 :     s.watertype = waterManager.m_WaterType;
      51           0 :     s.waterwaviness = waterManager.m_Waviness;
      52           0 :     s.watermurkiness = waterManager.m_Murkiness;
      53           0 :     s.windangle = waterManager.m_WindAngle;
      54             : 
      55             :     // CColor colors
      56             : #define COLOR(A, B) A = Color((int)(B.r*255), (int)(B.g*255), (int)(B.b*255))
      57           0 :     COLOR(s.watercolor, waterManager.m_WaterColor);
      58           0 :     COLOR(s.watertint, waterManager.m_WaterTint);
      59             : #undef COLOR
      60             : 
      61           0 :     float sunrotation = g_LightEnv.GetRotation();
      62           0 :     if (sunrotation > (float)M_PI)
      63           0 :         sunrotation -= (float)M_PI*2;
      64           0 :     s.sunrotation = sunrotation;
      65           0 :     s.sunelevation = g_LightEnv.GetElevation();
      66             : 
      67           0 :     s.posteffect = g_Renderer.GetPostprocManager().GetPostEffect();
      68             : 
      69           0 :     s.skyset = g_Renderer.GetSceneRenderer().GetSkyManager().GetSkySet();
      70             : 
      71           0 :     s.fogfactor = g_LightEnv.m_FogFactor;
      72           0 :     s.fogmax = g_LightEnv.m_FogMax;
      73             : 
      74           0 :     s.brightness = g_LightEnv.m_Brightness;
      75           0 :     s.contrast = g_LightEnv.m_Contrast;
      76           0 :     s.saturation = g_LightEnv.m_Saturation;
      77           0 :     s.bloom = g_LightEnv.m_Bloom;
      78             : 
      79             :     // RGBColor (CVector3D) colors
      80             : #define COLOR(A, B) A = Color((int)(B.X*255), (int)(B.Y*255), (int)(B.Z*255))
      81           0 :     s.sunoverbrightness = MaxComponent(g_LightEnv.m_SunColor);
      82             :     // clamp color to [0..1] before packing into u8 triplet
      83           0 :     if(s.sunoverbrightness > 1.0f)
      84           0 :         g_LightEnv.m_SunColor *= 1.0/s.sunoverbrightness;   // (there's no operator/=)
      85             :     // no component was above 1.0, so reset scale factor (don't want to darken)
      86             :     else
      87           0 :         s.sunoverbrightness = 1.0f;
      88           0 :     COLOR(s.suncolor, g_LightEnv.m_SunColor);
      89           0 :     COLOR(s.ambientcolor, g_LightEnv.m_AmbientColor);
      90           0 :     COLOR(s.fogcolor, g_LightEnv.m_FogColor);
      91             : #undef COLOR
      92             : 
      93           0 :     return s;
      94             : }
      95             : 
      96           0 : void SetSettings(const sEnvironmentSettings& s)
      97             : {
      98           0 :     CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
      99           0 :     ENSURE(cmpWaterManager);
     100             : 
     101           0 :     cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(s.waterheight * (65536.f * HEIGHT_SCALE)));
     102             : 
     103           0 :     WaterManager& waterManager = g_Renderer.GetSceneRenderer().GetWaterManager();
     104           0 :     waterManager.m_Waviness = s.waterwaviness;
     105           0 :     waterManager.m_Murkiness = s.watermurkiness;
     106           0 :     waterManager.m_WindAngle = s.windangle;
     107           0 :     if (waterManager.m_WaterType != *s.watertype)
     108             :     {
     109           0 :         waterManager.m_WaterType = *s.watertype;
     110           0 :         waterManager.ReloadWaterNormalTextures();
     111             :     }
     112             : 
     113             : #define COLOR(A, B) B = CColor(A->r/255.f, A->g/255.f, A->b/255.f, 1.f)
     114           0 :     COLOR(s.watercolor, waterManager.m_WaterColor);
     115           0 :     COLOR(s.watertint, waterManager.m_WaterTint);
     116             : #undef COLOR
     117             : 
     118           0 :     g_LightEnv.SetRotation(s.sunrotation);
     119           0 :     g_LightEnv.SetElevation(s.sunelevation);
     120             : 
     121           0 :     CStrW posteffect = *s.posteffect;
     122           0 :     if (posteffect.length() == 0)
     123           0 :         posteffect = L"default";
     124           0 :     g_Renderer.GetPostprocManager().SetPostEffect(posteffect);
     125             : 
     126           0 :     CStrW skySet = *s.skyset;
     127           0 :     if (skySet.length() == 0)
     128           0 :         skySet = L"default";
     129           0 :     g_Renderer.GetSceneRenderer().GetSkyManager().SetSkySet(skySet);
     130             : 
     131           0 :     g_LightEnv.m_FogFactor = s.fogfactor;
     132           0 :     g_LightEnv.m_FogMax = s.fogmax;
     133             : 
     134           0 :     g_LightEnv.m_Brightness = s.brightness;
     135           0 :     g_LightEnv.m_Contrast = s.contrast;
     136           0 :     g_LightEnv.m_Saturation = s.saturation;
     137           0 :     g_LightEnv.m_Bloom = s.bloom;
     138             : 
     139             : #define COLOR(A, B) B = RGBColor(A->r/255.f, A->g/255.f, A->b/255.f)
     140           0 :     COLOR(s.suncolor, g_LightEnv.m_SunColor);
     141           0 :     g_LightEnv.m_SunColor *= s.sunoverbrightness;
     142           0 :     COLOR(s.ambientcolor, g_LightEnv.m_AmbientColor);
     143           0 :     COLOR(s.fogcolor, g_LightEnv.m_FogColor);
     144             : #undef COLOR
     145             : 
     146           0 :     cmpWaterManager->RecomputeWaterData();
     147           0 : }
     148             : 
     149           0 : BEGIN_COMMAND(SetEnvironmentSettings)
     150             : {
     151             :     sEnvironmentSettings m_OldSettings, m_NewSettings;
     152             : 
     153           0 :     void Do()
     154             :     {
     155           0 :         m_OldSettings = GetSettings();
     156           0 :         m_NewSettings = msg->settings;
     157           0 :         Redo();
     158           0 :     }
     159             : 
     160           0 :     void Redo()
     161             :     {
     162           0 :         SetSettings(m_NewSettings);
     163           0 :     }
     164             : 
     165           0 :     void Undo()
     166             :     {
     167           0 :         SetSettings(m_OldSettings);
     168           0 :     }
     169             : 
     170           0 :     void MergeIntoPrevious(cSetEnvironmentSettings* prev)
     171             :     {
     172           0 :         prev->m_NewSettings = m_NewSettings;
     173           0 :     }
     174             : };
     175           0 : END_COMMAND(SetEnvironmentSettings)
     176             : 
     177           0 : BEGIN_COMMAND(RecalculateWaterData)
     178             : {
     179           0 :     void Do()
     180             :     {
     181           0 :         Redo();
     182           0 :     }
     183             : 
     184           0 :     void Redo()
     185             :     {
     186           0 :         CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
     187           0 :         ENSURE(cmpWaterManager);
     188             : 
     189           0 :         cmpWaterManager->RecomputeWaterData();
     190           0 :     }
     191             : 
     192           0 :     void Undo()
     193             :     {
     194           0 :         Redo();
     195           0 :     }
     196             : 
     197             : };
     198           0 : END_COMMAND(RecalculateWaterData)
     199             : 
     200           0 : BEGIN_COMMAND(PickWaterHeight)
     201             : {
     202             :     entity_pos_t m_OldWaterHeight, m_NewWaterHeight;
     203             : 
     204           0 :     void Do()
     205             :     {
     206           0 :         CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
     207           0 :         ENSURE(cmpWaterManager);
     208             : 
     209           0 :         CVector3D worldPos = msg->screenPos->GetWorldSpace();
     210           0 :         m_OldWaterHeight = cmpWaterManager->GetWaterLevel(
     211           0 :             entity_pos_t::FromFloat(worldPos.X), entity_pos_t::FromFloat(worldPos.Z));
     212           0 :         m_NewWaterHeight = entity_pos_t::FromFloat(worldPos.Y);
     213           0 :         SetWaterHeight(m_NewWaterHeight);
     214           0 :     }
     215             : 
     216           0 :     void Redo()
     217             :     {
     218           0 :         SetWaterHeight(m_NewWaterHeight);
     219           0 :     }
     220             : 
     221           0 :     void Undo()
     222             :     {
     223           0 :         SetWaterHeight(m_OldWaterHeight);
     224           0 :     }
     225             : 
     226           0 :     void SetWaterHeight(entity_pos_t height)
     227             :     {
     228           0 :         CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
     229           0 :         ENSURE(cmpWaterManager);
     230             : 
     231           0 :         cmpWaterManager->SetWaterLevel(height);
     232           0 :         cmpWaterManager->RecomputeWaterData();
     233           0 :     }
     234             : };
     235           0 : END_COMMAND(PickWaterHeight)
     236             : 
     237             : 
     238           0 : QUERYHANDLER(GetEnvironmentSettings)
     239             : {
     240           0 :     msg->settings = GetSettings();
     241           0 : }
     242             : 
     243           0 : QUERYHANDLER(GetSkySets)
     244             : {
     245           0 :     std::vector<CStrW> skies = g_Renderer.GetSceneRenderer().GetSkyManager().GetSkySets();
     246           0 :     msg->skysets = std::vector<std::wstring>(skies.begin(), skies.end());
     247           0 : }
     248             : 
     249             : 
     250           0 : QUERYHANDLER(GetPostEffects)
     251             : {
     252           0 :     std::vector<CStrW> effects = g_Renderer.GetPostprocManager().GetPostEffects();
     253           0 :     msg->posteffects = std::vector<std::wstring>(effects.begin(), effects.end());
     254           0 : }
     255             : 
     256             : }

Generated by: LCOV version 1.13