From b67853d4abe989ff4d2a27f796c1bf447cc2f084 Mon Sep 17 00:00:00 2001 From: Erik Ogenvik Date: Sat, 31 Oct 2020 21:43:05 +0100 Subject: [PATCH] Remove obsolete lighting and apply formatting. --- src/components/ogre/World.cpp | 1 - .../ogre/terrain/GeometryUpdateTask.cpp | 8 +- .../ogre/terrain/GeometryUpdateTask.h | 4 +- src/components/ogre/terrain/HeightMap.h | 84 +++++++------ .../ogre/terrain/HeightMapFlatSegment.h | 21 ++-- .../ogre/terrain/IHeightMapSegment.h | 14 +-- src/components/ogre/terrain/ITerrainAdapter.h | 7 +- .../ogre/terrain/ITerrainObserver.h | 16 +-- .../ogre/terrain/ITerrainPageBridge.h | 29 +++-- src/components/ogre/terrain/Map.cpp | 2 +- src/components/ogre/terrain/OgreImage.h | 13 +- .../CameraFocusedGrid2DPageStrategy.cpp | 67 +++++------ .../CameraFocusedGrid2DPageStrategy.h | 30 ++--- .../ogre/terrain/OgreTerrain/EmberTerrain.h | 22 ++-- .../terrain/OgreTerrain/EmberTerrainGroup.h | 17 +-- .../terrain/OgreTerrain/OgreTerrainDefiner.h | 14 +-- .../terrain/OgreTerrain/OgreTerrainObserver.h | 12 +- .../OgreTerrain/OgreTerrainPageBridge.cpp | 21 ++-- .../OgreTerrain/OgreTerrainPageBridge.h | 15 +-- .../OgreTerrain/OgreTerrainPageProvider.h | 15 ++- src/components/ogre/terrain/PlantInstance.h | 18 +-- .../ogre/terrain/PlantQueryTask.cpp | 1 - src/components/ogre/terrain/PlantQueryTask.h | 1 - src/components/ogre/terrain/Segment.h | 15 +-- src/components/ogre/terrain/SegmentHolder.h | 16 ++- src/components/ogre/terrain/SegmentManager.h | 16 +-- src/components/ogre/terrain/TerrainArea.h | 8 +- .../ogre/terrain/TerrainAreaParser.cpp | 15 +-- src/components/ogre/terrain/TerrainDefPoint.h | 12 +- src/components/ogre/terrain/TerrainEditor.h | 34 +++--- .../ogre/terrain/TerrainEditorOverlay.h | 38 +++--- .../ogre/terrain/TerrainHandler.cpp | 50 ++++---- src/components/ogre/terrain/TerrainHandler.h | 14 --- src/components/ogre/terrain/TerrainInfo.h | 18 ++- .../TerrainMaterialCompilationTask.cpp | 14 +-- .../terrain/TerrainMaterialCompilationTask.h | 11 +- .../ogre/terrain/TerrainModTranslator.cpp | 6 +- src/components/ogre/terrain/TerrainPage.h | 29 +++-- .../ogre/terrain/TerrainPageCreationTask.cpp | 8 +- .../ogre/terrain/TerrainPageCreationTask.h | 4 +- .../ogre/terrain/TerrainPageGeometry.cpp | 2 +- .../ogre/terrain/TerrainPageGeometry.h | 14 +-- .../ogre/terrain/TerrainPageSurface.h | 25 ++-- .../ogre/terrain/TerrainPageSurfaceLayer.cpp | 2 +- .../ogre/terrain/TerrainPageSurfaceLayer.h | 39 +++--- src/components/ogre/terrain/TerrainParser.h | 20 ++-- .../ogre/terrain/TerrainShaderUpdateTask.cpp | 14 +-- .../ogre/terrain/TerrainShaderUpdateTask.h | 45 +++---- src/components/ogre/terrain/Types.h | 111 ++++++++++-------- src/components/ogre/terrain/WFImage.cpp | 18 +-- .../terrain/XMLLayerDefinitionSerializer.cpp | 2 +- .../terrain/XMLLayerDefinitionSerializer.h | 8 +- .../ogre/terrain/foliage/ClusterPopulator.cpp | 82 +++++-------- .../ogre/terrain/foliage/Vegetation.h | 16 +-- .../techniques/OnePixelMaterialGenerator.cpp | 17 +-- .../ogre/terrain/techniques/Shader.h | 38 +++--- .../ogre/terrain/techniques/ShaderPass.h | 26 ++-- .../techniques/ShaderPassBlendMapBatch.h | 18 ++- 58 files changed, 542 insertions(+), 695 deletions(-) diff --git a/src/components/ogre/World.cpp b/src/components/ogre/World.cpp index 93916fe719..e73bc42b29 100644 --- a/src/components/ogre/World.cpp +++ b/src/components/ogre/World.cpp @@ -116,7 +116,6 @@ World::World(Eris::View& view, mScene->addRenderingTechnique("forest", std::make_unique(*mEnvironment->getForest())); mScene->addRenderingTechnique("projectile", std::make_unique(mScene->getSceneManager())); - mTerrainManager->getHandler().setLightning(mEnvironment.get()); //set the background colour to black mViewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0)); diff --git a/src/components/ogre/terrain/GeometryUpdateTask.cpp b/src/components/ogre/terrain/GeometryUpdateTask.cpp index 21217469d7..f57884ba7a 100644 --- a/src/components/ogre/terrain/GeometryUpdateTask.cpp +++ b/src/components/ogre/terrain/GeometryUpdateTask.cpp @@ -38,15 +38,13 @@ GeometryUpdateTask::GeometryUpdateTask(BridgeBoundGeometryPtrVector pages, TerrainHandler& handler, std::vector shaders, HeightMapBufferProvider& heightMapBufferProvider, - HeightMap& heightMap, - const WFMath::Vector<3>& lightDirection) : + HeightMap& heightMap) : mGeometry(std::move(pages)), mAreas(std::move(areas)), mHandler(handler), mShaders(std::move(shaders)), mHeightMapBufferProvider(heightMapBufferProvider), - mHeightMap(heightMap), - mLightDirection(lightDirection) { + mHeightMap(heightMap) { } @@ -64,7 +62,7 @@ void GeometryUpdateTask::executeTaskInBackgroundThread(Tasks::TaskExecutionConte GeometryPtrVector geometries; geometries.push_back(geometry); - context.executeTask(std::make_unique(geometries, mShaders, mAreas, mHandler.EventLayerUpdated, mHandler.EventTerrainMaterialRecompiled, mLightDirection)); + context.executeTask(std::make_unique(geometries, mShaders, mAreas, mHandler.EventLayerUpdated, mHandler.EventTerrainMaterialRecompiled)); } context.executeTask(std::make_unique(mHeightMapBufferProvider, mHeightMap, segments)); diff --git a/src/components/ogre/terrain/GeometryUpdateTask.h b/src/components/ogre/terrain/GeometryUpdateTask.h index 1e082d349d..c77f6e0a19 100644 --- a/src/components/ogre/terrain/GeometryUpdateTask.h +++ b/src/components/ogre/terrain/GeometryUpdateTask.h @@ -44,8 +44,7 @@ class GeometryUpdateTask : public Tasks::TemplateNamedTask { TerrainHandler& handler, std::vector shaders, HeightMapBufferProvider& heightMapBufferProvider, - HeightMap& heightMap, - const WFMath::Vector<3>& lightDirection); + HeightMap& heightMap); ~GeometryUpdateTask() override = default; @@ -63,7 +62,6 @@ class GeometryUpdateTask : public Tasks::TemplateNamedTask { HeightMap& mHeightMap; std::set mPages; std::set mBridgesToNotify; - const WFMath::Vector<3> mLightDirection; }; diff --git a/src/components/ogre/terrain/HeightMap.h b/src/components/ogre/terrain/HeightMap.h index b8e0f530a9..6a78fded19 100644 --- a/src/components/ogre/terrain/HeightMap.h +++ b/src/components/ogre/terrain/HeightMap.h @@ -23,18 +23,15 @@ #include #include -namespace WFMath -{ - template class Vector; +namespace WFMath { +template +class Vector; } -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { struct IHeightMapSegment; @@ -44,25 +41,24 @@ struct IHeightMapSegment; * This class is safe for threading, in contrast to the Mercator::Terrain class which primarily provides height map features. * The whole reason for this class existing is basically Mercator not being thread safe. We want to be able to update the Mercator terrain in a background thread, but at the same time be able to provide real time height checking functionality for other subsystems in Ember which are running in the main thread. */ -class HeightMap -{ +class HeightMap { public: - /** - * @brief STL map to store sparse array of Segment pointers. - */ - typedef std::unordered_map> Segmentcolumn; - - /** - * @brief STL map to store sparse array of Segment pointer columns. - */ - typedef std::unordered_map Segmentstore; - - /** - * @Ctor. - * @param defaultLevel The default level of the terrain, if no valid segment can be found for a requested location. - * @param segmentResolution The resolution of one segment, in world units. - */ + /** + * @brief STL map to store sparse array of Segment pointers. + */ + typedef std::unordered_map> Segmentcolumn; + + /** + * @brief STL map to store sparse array of Segment pointer columns. + */ + typedef std::unordered_map Segmentstore; + + /** + * @Ctor. + * @param defaultLevel The default level of the terrain, if no valid segment can be found for a requested location. + * @param segmentResolution The resolution of one segment, in world units. + */ explicit HeightMap(float defaultLevel, int segmentResolution = 64); /** @@ -96,35 +92,35 @@ class HeightMap * @param y The y location, in world units. * @returns The height at the location. */ - float getHeight(float x, float y) const; + float getHeight(float x, float y) const; - /** - * @brief Gets the height and normal at the location. - * This calculates slopes and provides a precise height. It's therefore more time consuming than getHeight(). + /** + * @brief Gets the height and normal at the location. + * This calculates slopes and provides a precise height. It's therefore more time consuming than getHeight(). * @param x The x location, in world units. * @param y The y location, in world units. * @param height The height will be stored here. * @param normal The normal will be stored here. * @returns True if a segment was found. - */ - bool getHeightAndNormal(float x, float y, float& height, WFMath::Vector<3>& normal) const; + */ + bool getHeightAndNormal(float x, float y, float& height, WFMath::Vector<3>& normal) const; - /** - * @brief Performs a fast copy of the raw height data for the supplied area. - * @param xMin Minimum x coord of the area. - * @param xMax Maximum x coord of the area. - * @param yMin Minimum y coord of the area. - * @param yMax Maximum y coord of the area. - * @param heights A vector into which heigh data will be placed. This should preferably already have a capacity reserved. - */ - void blitHeights(int xMin, int xMax, int yMin, int yMax, std::vector& heights) const; + /** + * @brief Performs a fast copy of the raw height data for the supplied area. + * @param xMin Minimum x coord of the area. + * @param xMax Maximum x coord of the area. + * @param yMin Minimum y coord of the area. + * @param yMax Maximum y coord of the area. + * @param heights A vector into which heigh data will be placed. This should preferably already have a capacity reserved. + */ + void blitHeights(int xMin, int xMax, int yMin, int yMax, std::vector& heights) const; private: - /** - * @brief A sparse map of height map segments. - */ + /** + * @brief A sparse map of height map segments. + */ Segmentstore mSegments; /** diff --git a/src/components/ogre/terrain/HeightMapFlatSegment.h b/src/components/ogre/terrain/HeightMapFlatSegment.h index a9060948d5..bc7344651d 100644 --- a/src/components/ogre/terrain/HeightMapFlatSegment.h +++ b/src/components/ogre/terrain/HeightMapFlatSegment.h @@ -21,23 +21,20 @@ #include "IHeightMapSegment.h" -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { /** * @author Erik Ogenvik * @brief Represents one segment (mapped to a Mercator::Segment) in the height map which is completely flat. * To save space we only need one single height, and don't need to allocate memory for a height map buffer. */ -class HeightMapFlatSegment : public IHeightMapSegment -{ +class HeightMapFlatSegment : public IHeightMapSegment { public: explicit HeightMapFlatSegment(float height); + ~HeightMapFlatSegment() override; /** @@ -50,14 +47,14 @@ class HeightMapFlatSegment : public IHeightMapSegment */ float getHeight(int x, int y) const override; - /** - * @brief Gets the height and normal at the location. - * This calculates slopes and provides a precise height. It's therefore more time consuming than getHeight(). + /** + * @brief Gets the height and normal at the location. + * This calculates slopes and provides a precise height. It's therefore more time consuming than getHeight(). * @param x The x location, in world units. * @param y The y location, in world units. * @param height The height will be stored here. * @param normal The normal will be stored here. - */ + */ void getHeightAndNormal(float x, float y, float& height, WFMath::Vector<3>& normal) const override; diff --git a/src/components/ogre/terrain/IHeightMapSegment.h b/src/components/ogre/terrain/IHeightMapSegment.h index 9e515cbbfb..aaef1c52bc 100644 --- a/src/components/ogre/terrain/IHeightMapSegment.h +++ b/src/components/ogre/terrain/IHeightMapSegment.h @@ -21,9 +21,9 @@ #include "Types.h" -namespace WFMath -{ - template class Vector; +namespace WFMath { +template +class Vector; } namespace Ember { @@ -48,14 +48,14 @@ struct IHeightMapSegment { */ virtual float getHeight(int x, int y) const = 0; - /** - * @brief Gets the height and normal at the location. - * This calculates slopes and provides a precise height. It's therefore more time consuming than getHeight(). + /** + * @brief Gets the height and normal at the location. + * This calculates slopes and provides a precise height. It's therefore more time consuming than getHeight(). * @param x The x location, in world units. * @param y The y location, in world units. * @param height The height will be stored here. * @param normal The normal will be stored here. - */ + */ virtual void getHeightAndNormal(float x, float y, float& height, WFMath::Vector<3>& normal) const = 0; }; } diff --git a/src/components/ogre/terrain/ITerrainAdapter.h b/src/components/ogre/terrain/ITerrainAdapter.h index f802b83323..0ce0ce180c 100644 --- a/src/components/ogre/terrain/ITerrainAdapter.h +++ b/src/components/ogre/terrain/ITerrainAdapter.h @@ -39,6 +39,7 @@ struct IPageDataProvider; namespace Terrain { class TerrainManager; + struct ITerrainObserver; @@ -49,8 +50,7 @@ Thus, if you have a feature which requires some kind of interfacing with the ter @author Erik Ogenvik */ -struct ITerrainAdapter -{ +struct ITerrainAdapter { virtual ~ITerrainAdapter() = default; @@ -81,6 +81,7 @@ struct ITerrainAdapter * @return True if terrain exists at the position. */ virtual bool getHeightAt(Ogre::Real x, Ogre::Real z, float& height) = 0; + /** * @brief Sets the main camera used. * @@ -95,7 +96,7 @@ struct ITerrainAdapter * Call this when the terrain has been set up and you want to show it. */ virtual void loadScene() = 0; - + /** * @brief Resets the whole terrain, removing any loaded pages. */ diff --git a/src/components/ogre/terrain/ITerrainObserver.h b/src/components/ogre/terrain/ITerrainObserver.h index acd1d573b0..5a28d46ece 100644 --- a/src/components/ogre/terrain/ITerrainObserver.h +++ b/src/components/ogre/terrain/ITerrainObserver.h @@ -31,27 +31,23 @@ template struct TRect; } -namespace WFMath -{ +namespace WFMath { template class AxisBox; } -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { /** * Listener interface for an terrain observer, which is observes a particular terrain area. * @author Erik Ogenvik */ -struct ITerrainObserver -{ +struct ITerrainObserver { virtual ~ITerrainObserver() = default; + /** * @brief Instructs the observer to observe a certain area. * @param area The area to observe. diff --git a/src/components/ogre/terrain/ITerrainPageBridge.h b/src/components/ogre/terrain/ITerrainPageBridge.h index 538f771ea4..65452c65e3 100644 --- a/src/components/ogre/terrain/ITerrainPageBridge.h +++ b/src/components/ogre/terrain/ITerrainPageBridge.h @@ -28,6 +28,7 @@ namespace OgreView { namespace Terrain { class TerrainPage; + class TerrainPageGeometry; /** @@ -39,32 +40,33 @@ It's up to the scene manager specific adapter code to provide concrete instances @author Erik Ogenvik */ -class ITerrainPageBridge -{ -friend class TerrainPage; +class ITerrainPageBridge { + friend class TerrainPage; + public: /** * @brief Ctor. */ ITerrainPageBridge() : mTerrainPage(nullptr) {} + /** * @brief Dtor. */ virtual ~ITerrainPageBridge() = default; - - + + /** * @brief Updates the Ogre mesh after changes to the underlying heightdata. * * Call this when the heightdata has changed and you want the Ogre representation to be updated to reflect this. */ virtual void updateTerrain(TerrainPageGeometry& geometry) = 0; - + /** * @brief Notifies class in the Ogre side about the page being ready (after being created or modified). */ virtual void terrainPageReady() = 0; - + /** * @brief Accessor to the terrain page this bridge is bound to. * @return A pointer to the terrain page, or null if no page yet has been bound. @@ -82,7 +84,7 @@ friend class TerrainPage; * Call this when the TerrainPage to which this bridge is connected to is destroyed. If not, you run the risk of segfaults since the bridge will still keep a pointer to the now deleted TerrainPage. */ void unbindFromTerrainPage(); - + /** * @brief Returns true if the page is shown. * @@ -102,18 +104,15 @@ friend class TerrainPage; }; -inline void ITerrainPageBridge::bindToTerrainPage(TerrainPage* terrainPage) -{ +inline void ITerrainPageBridge::bindToTerrainPage(TerrainPage* terrainPage) { mTerrainPage = terrainPage; } -inline void ITerrainPageBridge::unbindFromTerrainPage() -{ +inline void ITerrainPageBridge::unbindFromTerrainPage() { mTerrainPage = nullptr; } - -inline TerrainPage* ITerrainPageBridge::getTerrainPage() const -{ + +inline TerrainPage* ITerrainPageBridge::getTerrainPage() const { return mTerrainPage; } diff --git a/src/components/ogre/terrain/Map.cpp b/src/components/ogre/terrain/Map.cpp index 0d77474d7d..ca8dac7a94 100644 --- a/src/components/ogre/terrain/Map.cpp +++ b/src/components/ogre/terrain/Map.cpp @@ -117,7 +117,7 @@ void Map::setResolution(float metersPerPixel) { } float Map::getResolutionMeters() const { - return (float)mTexturePixelSize * mMetersPerPixel; + return (float) mTexturePixelSize * mMetersPerPixel; } MapView& Map::getView() { diff --git a/src/components/ogre/terrain/OgreImage.h b/src/components/ogre/terrain/OgreImage.h index 1ebf28f67b..102d306db7 100644 --- a/src/components/ogre/terrain/OgreImage.h +++ b/src/components/ogre/terrain/OgreImage.h @@ -22,22 +22,19 @@ #include "Image.h" -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { class WFImage; -class OgreImage : public Image -{ +class OgreImage : public Image { public: explicit OgreImage(std::unique_ptr buffer); void blit(const OgreImage& imageToBlit, unsigned int destinationChannel, int widthOffset, int heightOffset) override; + void blit(const WFImage& imageToBlit, unsigned int destinationChannel, int widthOffset, int heightOffset) override; }; diff --git a/src/components/ogre/terrain/OgreTerrain/CameraFocusedGrid2DPageStrategy.cpp b/src/components/ogre/terrain/OgreTerrain/CameraFocusedGrid2DPageStrategy.cpp index f2ba074907..623380eb1f 100644 --- a/src/components/ogre/terrain/OgreTerrain/CameraFocusedGrid2DPageStrategy.cpp +++ b/src/components/ogre/terrain/OgreTerrain/CameraFocusedGrid2DPageStrategy.cpp @@ -26,22 +26,17 @@ using namespace Ogre; -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { CameraFocusedGrid2DPageStrategy::CameraFocusedGrid2DPageStrategy(Ogre::PageManager* manager) -: Ogre::Grid2DPageStrategy(manager) -{ + : Ogre::Grid2DPageStrategy(manager) { } CameraFocusedGrid2DPageStrategy::~CameraFocusedGrid2DPageStrategy() = default; -void CameraFocusedGrid2DPageStrategy::notifyCamera(Camera* cam, PagedWorldSection* section) -{ +void CameraFocusedGrid2DPageStrategy::notifyCamera(Camera* cam, PagedWorldSection* section) { auto* stratData = dynamic_cast(section->getStrategyData()); const Vector3& pos = cam->getDerivedPosition(); @@ -55,10 +50,10 @@ void CameraFocusedGrid2DPageStrategy::notifyCamera(Camera* cam, PagedWorldSectio Real loadRadius = stratData->getLoadRadiusInCells(); Real holdRadius = stratData->getHoldRadiusInCells(); // scan the whole Hold range - Real fxmin = (Real)x - holdRadius; - Real fxmax = (Real)x + holdRadius; - Real fymin = (Real)y - holdRadius; - Real fymax = (Real)y + holdRadius; + Real fxmin = (Real) x - holdRadius; + Real fxmax = (Real) x + holdRadius; + Real fymin = (Real) y - holdRadius; + Real fymax = (Real) y + holdRadius; int32 xmin = stratData->getCellRangeMinX(); int32 xmax = stratData->getCellRangeMaxX(); @@ -66,33 +61,28 @@ void CameraFocusedGrid2DPageStrategy::notifyCamera(Camera* cam, PagedWorldSectio int32 ymax = stratData->getCellRangeMaxY(); // Round UP max, round DOWN min - xmin = fxmin < xmin ? xmin : (int32)floor(fxmin); - xmax = fxmax > xmax ? xmax : (int32)ceil(fxmax); - ymin = fymin < ymin ? ymin : (int32)floor(fymin); - ymax = fymax > ymax ? ymax : (int32)ceil(fymax); + xmin = fxmin < xmin ? xmin : (int32) floor(fxmin); + xmax = fxmax > xmax ? xmax : (int32) ceil(fxmax); + ymin = fymin < ymin ? ymin : (int32) floor(fymin); + ymax = fymax > ymax ? ymax : (int32) ceil(fymax); // the inner, active load range - fxmin = (Real)x - loadRadius; - fxmax = (Real)x + loadRadius; - fymin = (Real)y - loadRadius; - fymax = (Real)y + loadRadius; + fxmin = (Real) x - loadRadius; + fxmax = (Real) x + loadRadius; + fymin = (Real) y - loadRadius; + fymax = (Real) y + loadRadius; // Round UP max, round DOWN min - int32 loadxmin = fxmin < xmin ? xmin : (int32)floor(fxmin); - int32 loadxmax = fxmax > xmax ? xmax : (int32)ceil(fxmax); - int32 loadymin = fymin < ymin ? ymin : (int32)floor(fymin); - int32 loadymax = fymax > ymax ? ymax : (int32)ceil(fymax); - - for (int32 cy = ymin; cy <= ymax; ++cy) - { - for (int32 cx = xmin; cx <= xmax; ++cx) - { + int32 loadxmin = fxmin < xmin ? xmin : (int32) floor(fxmin); + int32 loadxmax = fxmax > xmax ? xmax : (int32) ceil(fxmax); + int32 loadymin = fymin < ymin ? ymin : (int32) floor(fymin); + int32 loadymax = fymax > ymax ? ymax : (int32) ceil(fymax); + + for (int32 cy = ymin; cy <= ymax; ++cy) { + for (int32 cx = xmin; cx <= xmax; ++cx) { PageID pageID = stratData->calculatePageID(cx, cy); - if (cx >= loadxmin && cx <= loadxmax && cy >= loadymin && cy <= loadymax) - { + if (cx >= loadxmin && cx <= loadxmax && cy >= loadymin && cy <= loadymax) { // in the 'load' range, request it section->loadPage(pageID); - } - else - { + } else { // in the outer 'hold' range, keep it but don't actively load section->holdPage(pageID); } @@ -101,12 +91,9 @@ void CameraFocusedGrid2DPageStrategy::notifyCamera(Camera* cam, PagedWorldSectio } - - } -void CameraFocusedGrid2DPageStrategy::loadNearestPages(const Vector2& gridpos, PagedWorldSection* section) -{ +void CameraFocusedGrid2DPageStrategy::loadNearestPages(const Vector2& gridpos, PagedWorldSection* section) { //Get all pages that are within 100 meters and load them instantly. std::set pagesToLoad; diff --git a/src/components/ogre/terrain/OgreTerrain/CameraFocusedGrid2DPageStrategy.h b/src/components/ogre/terrain/OgreTerrain/CameraFocusedGrid2DPageStrategy.h index 9cf3dad02c..04d94e46e6 100644 --- a/src/components/ogre/terrain/OgreTerrain/CameraFocusedGrid2DPageStrategy.h +++ b/src/components/ogre/terrain/OgreTerrain/CameraFocusedGrid2DPageStrategy.h @@ -21,12 +21,9 @@ #include -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { /** * @brief Loads pages near the camera first. @@ -35,25 +32,24 @@ namespace Terrain * with the only difference being that pages that are close to the camera are loaded * first (which is what you would want in most cases). */ -class CameraFocusedGrid2DPageStrategy : public Ogre::Grid2DPageStrategy -{ +class CameraFocusedGrid2DPageStrategy : public Ogre::Grid2DPageStrategy { public: explicit CameraFocusedGrid2DPageStrategy(Ogre::PageManager* manager); ~CameraFocusedGrid2DPageStrategy() override; - void notifyCamera(Ogre::Camera* cam, Ogre::PagedWorldSection* section) override; + void notifyCamera(Ogre::Camera* cam, Ogre::PagedWorldSection* section) override; protected: - /** - * @brief Loads the pages nearest to the camera. - * - * This is done by sampling the pages at the position of the camera as well as in 100 meters out. - * @param gridpos The grid position of the camera. - * @param section - */ - void loadNearestPages(const Ogre::Vector2& gridpos, Ogre::PagedWorldSection* section); + /** + * @brief Loads the pages nearest to the camera. + * + * This is done by sampling the pages at the position of the camera as well as in 100 meters out. + * @param gridpos The grid position of the camera. + * @param section + */ + void loadNearestPages(const Ogre::Vector2& gridpos, Ogre::PagedWorldSection* section); }; diff --git a/src/components/ogre/terrain/OgreTerrain/EmberTerrain.h b/src/components/ogre/terrain/OgreTerrain/EmberTerrain.h index 30decc6350..915516b9ef 100644 --- a/src/components/ogre/terrain/OgreTerrain/EmberTerrain.h +++ b/src/components/ogre/terrain/OgreTerrain/EmberTerrain.h @@ -26,12 +26,9 @@ #include #include -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { /** * @brief Mainly used to override the default behaviour of Ogre::Terrain. @@ -39,8 +36,7 @@ namespace Terrain * This to better fit the way we handle materials (since we don't use the default materials * as generated by the Ogre::Terrain classes). */ -class EmberTerrain: public Ogre::Terrain -{ +class EmberTerrain : public Ogre::Terrain { public: /** @@ -69,8 +65,11 @@ class EmberTerrain: public Ogre::Terrain const IPageDataProvider::OgreIndex& getIndex() const; bool canHandleRequest(const Ogre::WorkQueue::Request* req, const Ogre::WorkQueue* srcQ) override; + Ogre::WorkQueue::Response* handleRequest(const Ogre::WorkQueue::Request* req, const Ogre::WorkQueue* srcQ) override; + bool canHandleResponse(const Ogre::WorkQueue::Response* res, const Ogre::WorkQueue* srcQ) override; + void handleResponse(const Ogre::WorkQueue::Response* res, const Ogre::WorkQueue* srcQ) override; /** @@ -88,13 +87,12 @@ class EmberTerrain: public Ogre::Terrain static const Ogre::uint16 WORKQUEUE_GEOMETRY_UPDATE_REQUEST; - struct GeometryUpdateRequest - { + struct GeometryUpdateRequest { EmberTerrain* terrain; std::shared_ptr> heightData; + //Rect dirtyRect; - friend std::ostream& operator<<(std::ostream& o, const GeometryUpdateRequest& r) - { return o; } + friend std::ostream& operator<<(std::ostream& o, const GeometryUpdateRequest& r) { return o; } }; /** diff --git a/src/components/ogre/terrain/OgreTerrain/EmberTerrainGroup.h b/src/components/ogre/terrain/OgreTerrain/EmberTerrainGroup.h index a0ca4db470..259b522451 100644 --- a/src/components/ogre/terrain/OgreTerrain/EmberTerrainGroup.h +++ b/src/components/ogre/terrain/OgreTerrain/EmberTerrainGroup.h @@ -22,28 +22,24 @@ #include #include -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { struct IPageDataProvider; -namespace Terrain -{ +namespace Terrain { /** * @brief Creates EmberTerrain instances instead of Ogre::Terrain. * * Make sure you call setPageDataProvider(). */ -class EmberTerrainGroup: public Ogre::TerrainGroup -{ +class EmberTerrainGroup : public Ogre::TerrainGroup { public: EmberTerrainGroup(Ogre::SceneManager* sm, - Ogre::uint16 terrainSize, + Ogre::uint16 terrainSize, sigc::signal&>& terrainShownSignal, sigc::signal&>& terrainAreaUpdatedSignal, - Ogre::TerrainMaterialGeneratorPtr materialGenerator); + Ogre::TerrainMaterialGeneratorPtr materialGenerator); ~EmberTerrainGroup() override; @@ -62,7 +58,6 @@ class EmberTerrainGroup: public Ogre::TerrainGroup void handleResponse(const Ogre::WorkQueue::Response* res, const Ogre::WorkQueue* srcQ) override; - protected: /** diff --git a/src/components/ogre/terrain/OgreTerrain/OgreTerrainDefiner.h b/src/components/ogre/terrain/OgreTerrain/OgreTerrainDefiner.h index 63c27ae905..4de100624b 100644 --- a/src/components/ogre/terrain/OgreTerrain/OgreTerrainDefiner.h +++ b/src/components/ogre/terrain/OgreTerrain/OgreTerrainDefiner.h @@ -21,26 +21,22 @@ #include -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { struct IPageDataProvider; -namespace Terrain -{ +namespace Terrain { /** * @brief Upon request of the paging system, loads and defines terrain pages for subsequent rendering. */ -class OgreTerrainDefiner : public Ogre::TerrainPagedWorldSection::TerrainDefiner -{ +class OgreTerrainDefiner : public Ogre::TerrainPagedWorldSection::TerrainDefiner { public: explicit OgreTerrainDefiner(IPageDataProvider& provider); ~OgreTerrainDefiner() override = default; - void define(Ogre::TerrainGroup *terrainGroup, long x, long y) override; + void define(Ogre::TerrainGroup* terrainGroup, long x, long y) override; private: IPageDataProvider& mProvider; diff --git a/src/components/ogre/terrain/OgreTerrain/OgreTerrainObserver.h b/src/components/ogre/terrain/OgreTerrain/OgreTerrainObserver.h index 743408417e..138f650e9b 100644 --- a/src/components/ogre/terrain/OgreTerrain/OgreTerrainObserver.h +++ b/src/components/ogre/terrain/OgreTerrain/OgreTerrainObserver.h @@ -28,19 +28,15 @@ #include -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { /** * @brief An ITerrainObserver implementation which can be used to observe the Ogre Terrain component. * Instances are managed by OgreTerrainAdapter. */ -class OgreTerrainObserver: public Ember::OgreView::Terrain::ITerrainObserver -{ +class OgreTerrainObserver : public Ember::OgreView::Terrain::ITerrainObserver { public: /** * @brief Usually you should call OgreTerrainAdapter::createObserver to create an instance of this observer. diff --git a/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageBridge.cpp b/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageBridge.cpp index ee799dc2b9..0272160b1d 100644 --- a/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageBridge.cpp +++ b/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageBridge.cpp @@ -26,23 +26,18 @@ #include -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { OgreTerrainPageBridge::OgreTerrainPageBridge(Ogre::TerrainGroup& terrainGroup, IndexType index) : - mTerrainGroup(terrainGroup), mIndex(std::move(index)) -{ + mTerrainGroup(terrainGroup), mIndex(std::move(index)) { } OgreTerrainPageBridge::~OgreTerrainPageBridge() = default; -void OgreTerrainPageBridge::updateTerrain(TerrainPageGeometry& geometry) -{ +void OgreTerrainPageBridge::updateTerrain(TerrainPageGeometry& geometry) { S_LOG_VERBOSE("Updating terrain page height data: [" << mIndex.first << "," << mIndex.second << "]"); //Make a copy of the shared ptr, making sure it can't be deleted by the terrainPageReady() method @@ -57,8 +52,7 @@ void OgreTerrainPageBridge::updateTerrain(TerrainPageGeometry& geometry) } -void OgreTerrainPageBridge::terrainPageReady() -{ +void OgreTerrainPageBridge::terrainPageReady() { S_LOG_INFO("Finished loading or updating terrain page geometry: [" << mIndex.first << "," << mIndex.second << "]"); if (mHeightData) { auto terrain = dynamic_cast(mTerrainGroup.getTerrain(mIndex.first, mIndex.second)); @@ -76,8 +70,7 @@ void OgreTerrainPageBridge::terrainPageReady() mConditionVariable.notify_all(); } -bool OgreTerrainPageBridge::isPageShown() const -{ +bool OgreTerrainPageBridge::isPageShown() const { auto terrain = mTerrainGroup.getTerrain(mIndex.first, mIndex.second); return terrain != nullptr && terrain->isLoaded(); } diff --git a/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageBridge.h b/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageBridge.h index 8e915a0182..d82f968829 100644 --- a/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageBridge.h +++ b/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageBridge.h @@ -25,23 +25,18 @@ #include #include -namespace Ogre -{ +namespace Ogre { class TerrainGroup; } -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { /** * @brief Updates Ogre terrain rendering data based on Mercator-provided data. */ -class OgreTerrainPageBridge : public Ember::OgreView::Terrain::ITerrainPageBridge -{ +class OgreTerrainPageBridge : public Ember::OgreView::Terrain::ITerrainPageBridge { public: typedef std::pair IndexType; diff --git a/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageProvider.h b/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageProvider.h index ac85acb862..10dad44a7f 100644 --- a/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageProvider.h +++ b/src/components/ogre/terrain/OgreTerrain/OgreTerrainPageProvider.h @@ -21,27 +21,26 @@ #include -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { /** * @brief Provides a way for the Ogre paging component to request the loading of new terrain pages. * In this particular case, it only tells the Ogre terrain component that we generate pages procedurally, so it does not try to load them from the disk. */ -class OgreTerrainPageProvider: public Ogre::PageProvider -{ +class OgreTerrainPageProvider : public Ogre::PageProvider { public: OgreTerrainPageProvider(); ~OgreTerrainPageProvider() override; bool prepareProceduralPage(Ogre::Page* page, Ogre::PagedWorldSection* section) override; + bool loadProceduralPage(Ogre::Page* page, Ogre::PagedWorldSection* section) override; + bool unloadProceduralPage(Ogre::Page* page, Ogre::PagedWorldSection* section) override; + bool unprepareProceduralPage(Ogre::Page* page, Ogre::PagedWorldSection* section) override; }; diff --git a/src/components/ogre/terrain/PlantInstance.h b/src/components/ogre/terrain/PlantInstance.h index 3fb10014cf..3f0c94cec2 100644 --- a/src/components/ogre/terrain/PlantInstance.h +++ b/src/components/ogre/terrain/PlantInstance.h @@ -23,13 +23,10 @@ #include #include -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { /** @@ -37,8 +34,7 @@ namespace Terrain * @brief A simple struct for representing one plant instance in a 2d space. * To save space some simplifications are made. The orientation is only stored as a rotation around the vertical axis, and the scale is only stored for a flat plant. */ -class Plant2DInstance -{ +class Plant2DInstance { public: /** * @brief Ctor. @@ -46,8 +42,7 @@ class Plant2DInstance * @param orientation The rotation around the vertical axis for the plant. * @param scale The scale of the plant in width and height. */ - Plant2DInstance(const Ogre::Vector2& positionIn, float orientationIn, const Ogre::Vector2& scaleIn) - { + Plant2DInstance(const Ogre::Vector2& positionIn, float orientationIn, const Ogre::Vector2& scaleIn) { this->position = positionIn; this->orientation = orientationIn; this->scale = scaleIn; @@ -75,8 +70,7 @@ class Plant2DInstance * @brief A simple struct for representing one plant instance in a 3d space. * To save space some simplifications are made. The orientation is only stored as a rotation around the vertical axis, and the scale is only stored for a flat plant. */ -struct PlantInstance -{ +struct PlantInstance { /** * @brief The position of the plant. diff --git a/src/components/ogre/terrain/PlantQueryTask.cpp b/src/components/ogre/terrain/PlantQueryTask.cpp index 0c62270d5e..72d3688d17 100644 --- a/src/components/ogre/terrain/PlantQueryTask.cpp +++ b/src/components/ogre/terrain/PlantQueryTask.cpp @@ -31,7 +31,6 @@ namespace Terrain { PlantQueryTask::PlantQueryTask(SegmentRefPtr segmentRef, Foliage::PlantPopulator& plantPopulator, PlantAreaQuery query, - const Ogre::ColourValue& defaultShadowColour, sigc::slot asyncCallback) : mSegmentRef(std::move(segmentRef)), mPlantPopulator(plantPopulator), diff --git a/src/components/ogre/terrain/PlantQueryTask.h b/src/components/ogre/terrain/PlantQueryTask.h index 9f71dbb684..2542e3fe45 100644 --- a/src/components/ogre/terrain/PlantQueryTask.h +++ b/src/components/ogre/terrain/PlantQueryTask.h @@ -43,7 +43,6 @@ class PlantQueryTask : public Tasks::TemplateNamedTask { PlantQueryTask(SegmentRefPtr segmentRef, Foliage::PlantPopulator& plantPopulator, PlantAreaQuery query, - const Ogre::ColourValue& defaultShadowColour, sigc::slot asyncCallback); ~PlantQueryTask() override; diff --git a/src/components/ogre/terrain/Segment.h b/src/components/ogre/terrain/Segment.h index ecd1c1c8dc..e221b7e9e8 100644 --- a/src/components/ogre/terrain/Segment.h +++ b/src/components/ogre/terrain/Segment.h @@ -22,26 +22,21 @@ #include #include -namespace Mercator -{ +namespace Mercator { class Segment; } -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { /** * @author Erik Ogenvik * @brief Represents a Mercator::Segment instance. * An instance of this wraps around a Mercator::Segment instance. It's main purpose is to provide an abstraction over the underlying Mercator::Segment instance, so that it easier can be handled by the SegmentManager. */ -class Segment -{ +class Segment { public: /** diff --git a/src/components/ogre/terrain/SegmentHolder.h b/src/components/ogre/terrain/SegmentHolder.h index 21b7afcf64..768a8cf8c5 100644 --- a/src/components/ogre/terrain/SegmentHolder.h +++ b/src/components/ogre/terrain/SegmentHolder.h @@ -25,15 +25,13 @@ #include -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { class Segment; + class SegmentManager; /** @@ -43,9 +41,9 @@ class SegmentManager; * These references are counted, so that the holder instance knows how many currently are in use. This is of main use to allow for the SegmentManager to release data from Segments which aren't in use. * This class is internal to the SegmentManager system and shouldn't be used outside of it. */ -class SegmentHolder -{ -friend class SegmentReference; +class SegmentHolder { + friend class SegmentReference; + public: /** diff --git a/src/components/ogre/terrain/SegmentManager.h b/src/components/ogre/terrain/SegmentManager.h index 3f338921df..e4fbff810b 100644 --- a/src/components/ogre/terrain/SegmentManager.h +++ b/src/components/ogre/terrain/SegmentManager.h @@ -26,19 +26,16 @@ #include #include -namespace Mercator -{ +namespace Mercator { class Segment; + class Terrain; } -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { class SegmentHolder; /** @@ -56,8 +53,7 @@ class SegmentHolder; * Whenever an external subsystem needs to access a segment it will need to call the getSegmentReference() method to obtain a reference instance. As long as the reference instance is alive the Segment is considered in use and will not be "collected". * */ -class SegmentManager -{ +class SegmentManager { public: typedef std::unordered_map> IndexColumn; diff --git a/src/components/ogre/terrain/TerrainArea.h b/src/components/ogre/terrain/TerrainArea.h index 3b03d6e792..88af62bf45 100644 --- a/src/components/ogre/terrain/TerrainArea.h +++ b/src/components/ogre/terrain/TerrainArea.h @@ -27,9 +27,8 @@ #include #include -namespace Mercator -{ - class Area; +namespace Mercator { +class Area; } namespace Ember { @@ -46,8 +45,7 @@ The areas are always attached to an entity, and when the entity moves the area m This class acts like a wrapper and controller, binding an instance of EmberEntity and Mercator::Area together. The actual application of the area to the terrain is handled by TerrainHandler, but the logic for parsing the terrain area data from Atlas is contained in this class. @author Erik Ogenvik */ -class TerrainArea : public virtual sigc::trackable -{ +class TerrainArea : public virtual sigc::trackable { public: /** diff --git a/src/components/ogre/terrain/TerrainAreaParser.cpp b/src/components/ogre/terrain/TerrainAreaParser.cpp index 6656f91a58..94e07ae87e 100644 --- a/src/components/ogre/terrain/TerrainAreaParser.cpp +++ b/src/components/ogre/terrain/TerrainAreaParser.cpp @@ -29,16 +29,12 @@ #include "framework/LoggingInstance.h" #include -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { -bool TerrainAreaParser::parseArea(const Atlas::Message::MapType& areaData, WFMath::Polygon<2>& poly, int& layer) -{ +bool TerrainAreaParser::parseArea(const Atlas::Message::MapType& areaData, WFMath::Polygon<2>& poly, int& layer) { //Earlier versions of Cyphesis had all of the shape data directly in the area map attribute, //whereas newer versions have it all stored in a "shape" subentity. We therefore need to check for both @@ -77,8 +73,7 @@ bool TerrainAreaParser::parseArea(const Atlas::Message::MapType& areaData, WFMat return true; } -Atlas::Message::Element TerrainAreaParser::createElement(const WFMath::Polygon<2>& poly, int layer) -{ +Atlas::Message::Element TerrainAreaParser::createElement(const WFMath::Polygon<2>& poly, int layer) { Atlas::Message::MapType map; if (poly.isValid()) { Atlas::Message::Element shapeElement = poly.toAtlas(); diff --git a/src/components/ogre/terrain/TerrainDefPoint.h b/src/components/ogre/terrain/TerrainDefPoint.h index d1a6e1d178..0e784f4b61 100644 --- a/src/components/ogre/terrain/TerrainDefPoint.h +++ b/src/components/ogre/terrain/TerrainDefPoint.h @@ -22,20 +22,16 @@ #include #include "domain/Types.h" -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { /** @brief Defines the height of a special "base point" in the terrain. These base points are then user by Mercator::Terrain for generating the actual terrain. */ -struct TerrainDefPoint -{ +struct TerrainDefPoint { /** The position of the point, in world units. diff --git a/src/components/ogre/terrain/TerrainEditor.h b/src/components/ogre/terrain/TerrainEditor.h index 3f742771f7..8b49788103 100644 --- a/src/components/ogre/terrain/TerrainEditor.h +++ b/src/components/ogre/terrain/TerrainEditor.h @@ -38,13 +38,13 @@ class BasePoint; namespace Ember { class EmberEntity; namespace OgreView { -namespace Camera -{ +namespace Camera { class MainCamera; } namespace Terrain { class TerrainManager; + class TerrainEditorOverlay; /** @@ -56,8 +56,7 @@ class TerrainEditorOverlay; @note Inherits from sigc::trackable because we use an async callback when fetching base points. @author Erik Ogenvik */ -class TerrainEditor : public virtual sigc::trackable -{ +class TerrainEditor : public virtual sigc::trackable { public: /** @@ -66,22 +65,22 @@ class TerrainEditor : public virtual sigc::trackable * @param manager The main terrain manager instance. * @param camera The main camera used by Ember. */ - TerrainEditor(TerrainManager& manager, Camera::MainCamera& camera); + TerrainEditor(TerrainManager& manager, Camera::MainCamera& camera); - /** - * @brief Dtor. - */ - ~TerrainEditor(); + /** + * @brief Dtor. + */ + ~TerrainEditor(); - /** - * @brief Shows the overlay. - */ - void showOverlay(); + /** + * @brief Shows the overlay. + */ + void showOverlay(); - /** - * @brief Hides the overlay. - */ - void hideOverlay(); + /** + * @brief Hides the overlay. + */ + void hideOverlay(); /** * @brief Returns true if the overlay is currently shown. @@ -115,6 +114,7 @@ class TerrainEditor : public virtual sigc::trackable float getFalloff() const; + void setFalloff(float falloff); private: diff --git a/src/components/ogre/terrain/TerrainEditorOverlay.h b/src/components/ogre/terrain/TerrainEditorOverlay.h index 1026a8b7b9..7e039ab656 100644 --- a/src/components/ogre/terrain/TerrainEditorOverlay.h +++ b/src/components/ogre/terrain/TerrainEditorOverlay.h @@ -30,36 +30,36 @@ #include #include -namespace Mercator -{ +namespace Mercator { class Terrain; + class BasePoint; } -namespace Ember -{ +namespace Ember { class EmberEntity; -namespace OgreView -{ -namespace Camera -{ +namespace OgreView { +namespace Camera { class MainCamera; } -namespace Terrain -{ +namespace Terrain { class TerrainEditor; + class TerrainManager; + class BasePointUserObject; + struct TerrainEditBasePointMovement; + class TerrainEditorOverlay; + class TerrainPage; /** * @brief Allows the user to pick base points. */ -class BasePointPickListener: public IWorldPickListener -{ +class BasePointPickListener : public IWorldPickListener { public: explicit BasePointPickListener(TerrainEditorOverlay& overlay); @@ -76,8 +76,7 @@ class BasePointPickListener: public IWorldPickListener BasePointUserObject* mPickedUserObject; }; -class BasePointUserObject -{ +class BasePointUserObject { public: BasePointUserObject(TerrainPosition terrainPosition, const Mercator::BasePoint& basePoint, Ogre::SceneNode* basePointMarkerNode, BulletWorld& bulletWorld); @@ -209,8 +208,7 @@ class BasePointUserObject /** A single editing action. This can affect one or many base points, and can be reversed (uncommitted). */ -struct TerrainEditAction -{ +struct TerrainEditAction { public: typedef std::vector MovementStore; @@ -228,17 +226,16 @@ struct TerrainEditAction /** *A single height movement of a base point. */ -struct TerrainEditBasePointMovement -{ +struct TerrainEditBasePointMovement { public: Ogre::Real mVerticalMovement; TerrainIndex mPosition; }; -class TerrainEditorOverlay: public IInputAdapter, public virtual sigc::trackable -{ +class TerrainEditorOverlay : public IInputAdapter, public virtual sigc::trackable { public: typedef std::map> BasePointStore; + TerrainEditorOverlay(TerrainEditor& editor, Ogre::SceneManager& sceneManager, Ogre::SceneNode& worldSceneNode, TerrainManager& manager, Camera::MainCamera& camera, BasePointStore& basePoints); @@ -338,6 +335,7 @@ class TerrainEditorOverlay: public IInputAdapter, public virtual sigc::trackable bool injectKeyDown(const SDL_Scancode& key) override; bool injectKeyUp(const SDL_Scancode& key) override; + private: typedef std::set BasePointUserObjectSet; typedef std::vector EntityStore; diff --git a/src/components/ogre/terrain/TerrainHandler.cpp b/src/components/ogre/terrain/TerrainHandler.cpp index 9a8f036331..88a51f2dd9 100644 --- a/src/components/ogre/terrain/TerrainHandler.cpp +++ b/src/components/ogre/terrain/TerrainHandler.cpp @@ -101,21 +101,18 @@ class TerrainPageReloadTask : public Tasks::TemplateNamedTask mGeometry; const std::vector mShaders; const WFMath::AxisBox<2> mArea; - const WFMath::Vector<3> mMainLightDirection; public: TerrainPageReloadTask(TerrainHandler& handler, ITerrainPageBridgePtr bridge, std::unique_ptr geometry, std::vector shaders, - const WFMath::AxisBox<2>& area, - const WFMath::Vector<3>& mainLightDirection) : + const WFMath::AxisBox<2>& area) : mHandler(handler), mBridge(std::move(bridge)), mGeometry(std::move(geometry)), mShaders(std::move(shaders)), - mArea(area), - mMainLightDirection(mainLightDirection) { + mArea(area) { } ~TerrainPageReloadTask() override = default; @@ -133,8 +130,7 @@ class TerrainPageReloadTask : public Tasks::TemplateNamedTask(1, eventService)), mHeightMax(std::numeric_limits::min()), mHeightMin(std::numeric_limits::max()), mHasTerrainInfo(false), - mLightning(nullptr), mTerrainEntity(nullptr), mAreaCounter(0), mModCounter(0) { @@ -299,11 +294,7 @@ void TerrainHandler::getPlantsForArea(Foliage::PlantPopulator& populator, PlantA auto yIndex = static_cast(std::floor(wfPos.y() / mTerrain->getResolution())); SegmentRefPtr segmentRef = mSegmentManager->getSegmentReference(xIndex, yIndex); if (segmentRef) { - Ogre::ColourValue defaultShadowColour; - if (mLightning) { - defaultShadowColour = mLightning->getAmbientLightColour(); - } - mTaskQueue->enqueueTask(std::make_unique(segmentRef, populator, query, defaultShadowColour, std::move(asyncCallback))); + mTaskQueue->enqueueTask(std::make_unique(segmentRef, populator, query, std::move(asyncCallback))); } } @@ -336,8 +327,7 @@ void TerrainHandler::updateShaders() { entry.first, entry.second.Areas, EventLayerUpdated, - EventTerrainMaterialRecompiled, - mLightning->getMainLightDirection()) + EventTerrainMaterialRecompiled) ); } mShadersToUpdate.clear(); @@ -356,7 +346,12 @@ void TerrainHandler::updateAllPages() { //Update all shaders on all pages for (auto& entry : mShaderMap) { - mTaskQueue->enqueueTask(std::make_unique(geometry, entry.second.get(), areas, EventLayerUpdated, EventTerrainMaterialRecompiled, mLightning->getMainLightDirection()), 0); + mTaskQueue->enqueueTask(std::make_unique(geometry, + entry.second.get(), + areas, + EventLayerUpdated, + EventTerrainMaterialRecompiled), + 0); } } @@ -409,11 +404,7 @@ void TerrainHandler::setUpTerrainPageAtIndex(const TerrainIndex& index, std::sha S_LOG_VERBOSE("Adding terrain page to TerrainHandler: [" << index.first << "|" << index.second << "]"); - WFMath::Vector<3> sunDirection = WFMath::Vector<3>(0, -1, 0); - if (mLightning) { - sunDirection = mLightning->getMainLightDirection(); - } - if (!mTaskQueue->enqueueTask(std::make_unique(*this, page.get(), bridge, *mHeightMapBufferProvider, *mHeightMap, sunDirection))) { + if (!mTaskQueue->enqueueTask(std::make_unique(*this, page.get(), bridge, *mHeightMapBufferProvider, *mHeightMap))) { //We need to alert the bridge since it's holding up a thread waiting for this call. bridge->terrainPageReady(); } @@ -430,7 +421,11 @@ void TerrainHandler::setUpTerrainPageAtIndex(const TerrainIndex& index, std::sha shaders.push_back(entry.second.get()); } - if (!mTaskQueue->enqueueTask(std::make_unique(*this, bridge, std::move(geometryInstance), std::move(shaders), page->getWorldExtent(), mLightning->getMainLightDirection()))) { + if (!mTaskQueue->enqueueTask(std::make_unique(*this, + bridge, + std::move(geometryInstance), + std::move(shaders), + page->getWorldExtent()))) { //We need to alert the bridge since it's holding up a thread waiting for this call. bridge->terrainPageReady(); } @@ -460,10 +455,6 @@ void TerrainHandler::blitHeights(int xMin, int xMax, int yMin, int yMax, std::ve } -void TerrainHandler::setLightning(ILightning* lightning) { - mLightning = lightning; -} - float TerrainHandler::getDefaultHeight() const { return -12.f; } @@ -510,7 +501,12 @@ void TerrainHandler::reloadTerrain(const std::vector>& areas) for (auto& entry : mShaderMap) { shaders.push_back(entry.second.get()); } - mTaskQueue->enqueueTask(std::make_unique(geometryToUpdate, areas, *this, std::move(shaders), *mHeightMapBufferProvider, *mHeightMap, mLightning->getMainLightDirection())); + mTaskQueue->enqueueTask(std::make_unique(geometryToUpdate, + areas, + *this, + std::move(shaders), + *mHeightMapBufferProvider, + *mHeightMap)); } } } diff --git a/src/components/ogre/terrain/TerrainHandler.h b/src/components/ogre/terrain/TerrainHandler.h index c4d0dbe87e..5907f2c478 100644 --- a/src/components/ogre/terrain/TerrainHandler.h +++ b/src/components/ogre/terrain/TerrainHandler.h @@ -308,13 +308,6 @@ class TerrainHandler : public virtual sigc::trackable, public Ember::IHeightProv */ void getBasePoints(sigc::slot>&>& asyncCallback); - /** - * @brief Sets the lightning instance to use. - * - * @param lightning The lightning instance to use, or null if none should be used. - */ - void setLightning(ILightning* lightning); - /** * @brief Place the plants for the supplied area in the supplied store. * @@ -528,13 +521,6 @@ class TerrainHandler : public virtual sigc::trackable, public Ember::IHeightProv */ bool mHasTerrainInfo; - - /** - * @brief Provides lightning information for the terrain. - */ - ILightning* mLightning; - - /** * @brief A list of the shaders, which will all be used on all Pages. */ diff --git a/src/components/ogre/terrain/TerrainInfo.h b/src/components/ogre/terrain/TerrainInfo.h index 6faa4dab3a..a9ceb4f148 100644 --- a/src/components/ogre/terrain/TerrainInfo.h +++ b/src/components/ogre/terrain/TerrainInfo.h @@ -28,8 +28,7 @@ #include #include -namespace Mercator -{ +namespace Mercator { class BasePoint; } @@ -41,8 +40,7 @@ namespace Terrain { @author Erik Ogenvik Class holding information about the terrain. */ -class TerrainInfo -{ +class TerrainInfo { public: /** @@ -50,12 +48,19 @@ class TerrainInfo * @param pageIndicesSize The size of one page in indices. */ explicit TerrainInfo(int pageIndicesSize); + double getWorldSizeX() const; + double getWorldSizeY() const; - int getTotalNumberOfPagesX() const; + + int getTotalNumberOfPagesX() const; + int getTotalNumberOfPagesY() const; + int getPageOffsetX() const; + int getPageOffsetY() const; + void setPageIndicesSize(int size); /* void setNewXMax(int xMax); @@ -64,8 +69,11 @@ class TerrainInfo void setNewYMin(int yMin);*/ void setBasePoint(const WFMath::Point<2>& position, const Mercator::BasePoint& basepoint); + const WFMath::AxisBox<2>& getWorldSizeInIndices() const; + const WFMath::AxisBox<2>& getWorldSizeInSegments() const; + const WFMath::AxisBox<2>& getWorldSizeInPages() const; private: diff --git a/src/components/ogre/terrain/TerrainMaterialCompilationTask.cpp b/src/components/ogre/terrain/TerrainMaterialCompilationTask.cpp index dc7680e7cd..186b9f5bf4 100644 --- a/src/components/ogre/terrain/TerrainMaterialCompilationTask.cpp +++ b/src/components/ogre/terrain/TerrainMaterialCompilationTask.cpp @@ -32,23 +32,19 @@ namespace OgreView { namespace Terrain { TerrainMaterialCompilationTask::TerrainMaterialCompilationTask(GeometryPtrVector geometry, - sigc::signal& signal, - const WFMath::Vector<3>& lightDirection) : + sigc::signal& signal) : mGeometry(std::move(geometry)), - mSignal(signal), - mLightDirection(lightDirection) { + mSignal(signal) { } TerrainMaterialCompilationTask::TerrainMaterialCompilationTask(TerrainPageGeometryPtr geometry, - sigc::signal& signal, - const WFMath::Vector<3>& lightDirection) : - mSignal(signal), - mLightDirection(lightDirection) { + sigc::signal& signal) : + mSignal(signal) { mGeometry.push_back(std::move(geometry)); } void TerrainMaterialCompilationTask::executeTaskInBackgroundThread(Tasks::TaskExecutionContext& context) { - for (auto & geometry : mGeometry) { + for (auto& geometry : mGeometry) { geometry->repopulate(); TerrainPage& page = geometry->getPage(); auto compilationInstance = page.getSurface()->createSurfaceCompilationInstance(geometry); diff --git a/src/components/ogre/terrain/TerrainMaterialCompilationTask.h b/src/components/ogre/terrain/TerrainMaterialCompilationTask.h index 6507e77566..d31cca28d0 100644 --- a/src/components/ogre/terrain/TerrainMaterialCompilationTask.h +++ b/src/components/ogre/terrain/TerrainMaterialCompilationTask.h @@ -48,8 +48,7 @@ class TerrainMaterialCompilationTask : public Tasks::TemplateNamedTask& signal, - const WFMath::Vector<3>& lightDirection); + sigc::signal& signal); /** * @brief Ctor. @@ -57,8 +56,7 @@ class TerrainMaterialCompilationTask : public Tasks::TemplateNamedTask& signal, - const WFMath::Vector<3>& lightDirection); + sigc::signal& signal); /** * @brief Dtor. @@ -92,11 +90,6 @@ class TerrainMaterialCompilationTask : public Tasks::TemplateNamedTask& mSignal; - /** - * @brief The main light direction. - */ - const WFMath::Vector<3> mLightDirection; - /** * @brief This needs to be called after materials have changed to make sure that Ogre flushes it's material caches. * Failure to do so will result in assert errors during Ogre's rendering. diff --git a/src/components/ogre/terrain/TerrainModTranslator.cpp b/src/components/ogre/terrain/TerrainModTranslator.cpp index 74bc486788..b34b0de07e 100644 --- a/src/components/ogre/terrain/TerrainModTranslator.cpp +++ b/src/components/ogre/terrain/TerrainModTranslator.cpp @@ -54,9 +54,9 @@ class InnerTranslatorImpl : public TerrainModTranslator::InnerTranslator { std::unique_ptr createInstance(const WFMath::Point<3>& pos, const WFMath::Quaternion& orientation) override; - std::unique_ptr clone() const override { - return std::make_unique(*this); - }; + std::unique_ptr clone() const override { + return std::make_unique(*this); + }; const ShapeT<2> mShape; }; diff --git a/src/components/ogre/terrain/TerrainPage.h b/src/components/ogre/terrain/TerrainPage.h index 502721a04b..3819720ce9 100644 --- a/src/components/ogre/terrain/TerrainPage.h +++ b/src/components/ogre/terrain/TerrainPage.h @@ -32,27 +32,28 @@ #include #include -namespace WFMath -{ -template class Vector; +namespace WFMath { +template +class Vector; } -namespace Mercator -{ +namespace Mercator { class Segment; } -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { class TerrainShader; + class TerrainPageSurface; + class TerrainPage; + class TerrainPageSurfaceLayer; + class TerrainPageGeometry; + struct ICompilerTechniqueProvider; /** @@ -68,8 +69,7 @@ struct ICompilerTechniqueProvider; @author Erik Ogenvik */ -class TerrainPage -{ +class TerrainPage { public: /** @@ -191,8 +191,7 @@ class TerrainPage unsigned int getBlendMapScale() const; }; -inline int TerrainPage::getBlendMapSize() const -{ +inline int TerrainPage::getBlendMapSize() const { //While the page size calculates the size in number of vertices, the blend map should use pixel size, which is one less. return (getPageSize() - 1); } diff --git a/src/components/ogre/terrain/TerrainPageCreationTask.cpp b/src/components/ogre/terrain/TerrainPageCreationTask.cpp index 53795dfac5..9336af738d 100644 --- a/src/components/ogre/terrain/TerrainPageCreationTask.cpp +++ b/src/components/ogre/terrain/TerrainPageCreationTask.cpp @@ -36,14 +36,12 @@ namespace Terrain { TerrainPageCreationTask::TerrainPageCreationTask(TerrainHandler& handler, TerrainPage* page, - std::shared_ptr bridge, + std::shared_ptr bridge, HeightMapBufferProvider& heightMapBufferProvider, - HeightMap& heightMap, - const WFMath::Vector<3>& mainLightDirection) : + HeightMap& heightMap) : mTerrainHandler(handler), mPage(page), mBridge(std::move(bridge)), - mMainLightDirection(mainLightDirection), mHeightMapBufferProvider(heightMapBufferProvider), mHeightMap(heightMap) { @@ -69,7 +67,7 @@ void TerrainPageCreationTask::executeTaskInBackgroundThread(Tasks::TaskExecution for (auto& entry : mTerrainHandler.getAllShaders()) { shaders.push_back(entry.second.get()); } - context.executeTask(std::make_unique(std::move(geometry), areas, mTerrainHandler, std::move(shaders), mHeightMapBufferProvider, mHeightMap, mMainLightDirection)); + context.executeTask(std::make_unique(std::move(geometry), areas, mTerrainHandler, std::move(shaders), mHeightMapBufferProvider, mHeightMap)); } diff --git a/src/components/ogre/terrain/TerrainPageCreationTask.h b/src/components/ogre/terrain/TerrainPageCreationTask.h index 499b1005d7..f2ea9b210f 100644 --- a/src/components/ogre/terrain/TerrainPageCreationTask.h +++ b/src/components/ogre/terrain/TerrainPageCreationTask.h @@ -44,8 +44,7 @@ class TerrainPageCreationTask : public Tasks::TemplateNamedTask bridge, HeightMapBufferProvider& heightMapBufferProvider, - HeightMap& heightMap, - const WFMath::Vector<3>& mainLightDirection); + HeightMap& heightMap); ~TerrainPageCreationTask() override = default; @@ -58,7 +57,6 @@ class TerrainPageCreationTask : public Tasks::TemplateNamedTask mBridge; - WFMath::Vector<3> mMainLightDirection; HeightMapBufferProvider& mHeightMapBufferProvider; HeightMap& mHeightMap; diff --git a/src/components/ogre/terrain/TerrainPageGeometry.cpp b/src/components/ogre/terrain/TerrainPageGeometry.cpp index 4f9ea0831e..e2402f350c 100644 --- a/src/components/ogre/terrain/TerrainPageGeometry.cpp +++ b/src/components/ogre/terrain/TerrainPageGeometry.cpp @@ -130,7 +130,7 @@ void TerrainPageGeometry::blitSegmentToOgre(float* ogreHeightData, Mercator::Seg float* dataEnd = ogreHeightData + ogreDataSize; // copy points line-by line - float* destPtr = ogreHeightData + (pageWidth * ( pageWidth - startZ - 1)) + startX; + float* destPtr = ogreHeightData + (pageWidth * (pageWidth - startZ - 1)) + startX; for (int i = 0; i < segmentWidth; ++i) { diff --git a/src/components/ogre/terrain/TerrainPageGeometry.h b/src/components/ogre/terrain/TerrainPageGeometry.h index d726f30ccc..0d8d1a4956 100644 --- a/src/components/ogre/terrain/TerrainPageGeometry.h +++ b/src/components/ogre/terrain/TerrainPageGeometry.h @@ -22,12 +22,12 @@ // #ifndef EMBEROGRETERRAINPAGEGEOMETRY_H #define EMBEROGRETERRAINPAGEGEOMETRY_H + #include #include "Types.h" #include -namespace Mercator -{ +namespace Mercator { class Segment; } @@ -38,8 +38,7 @@ namespace Terrain { /** * @brief Holds a Mercator::Segment instance as well as a index of this segment in local page coords. */ -struct PageSegment -{ +struct PageSegment { /** * @brief The index of this segment within the page. */ @@ -55,6 +54,7 @@ typedef std::vector SegmentVector; class TerrainPage; + class SegmentManager; /** @@ -65,9 +65,9 @@ Each instance of TerrainPage is light weight, and doesn't hold any terrain data. Instead we use an instance of this each time we want to access terrain data. Each instance of this class is meant to be in use a very short time. As soon as it's destroyed the Segments used by it will be returned to the SegmentManager, and optionally have had their memory freed. */ -class TerrainPageGeometry -{ -friend class TerrainPage; +class TerrainPageGeometry { + friend class TerrainPage; + public: /** diff --git a/src/components/ogre/terrain/TerrainPageSurface.h b/src/components/ogre/terrain/TerrainPageSurface.h index 61dfd3b521..555740915a 100644 --- a/src/components/ogre/terrain/TerrainPageSurface.h +++ b/src/components/ogre/terrain/TerrainPageSurface.h @@ -30,36 +30,41 @@ #include -namespace Mercator -{ +namespace Mercator { class Shader; + class Surface; + class Segment; } -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { +namespace Terrain { class TerrainPageSurfaceLayer; + class TerrainPage; + class TerrainPageSurfaceCompiler; + class TerrainPageShadow; + class TerrainPageGeometry; + struct TerrainLayerDefinition; + class TerrainPageSurfaceCompilationInstance; + struct ICompilerTechniqueProvider; /** @author Erik Ogenvik */ -class TerrainPageSurface -{ +class TerrainPageSurface { public: typedef std::map> TerrainPageSurfaceLayerStore; + /** * @brief Ctor. * diff --git a/src/components/ogre/terrain/TerrainPageSurfaceLayer.cpp b/src/components/ogre/terrain/TerrainPageSurfaceLayer.cpp index 3a418afbf8..b8e23e143e 100644 --- a/src/components/ogre/terrain/TerrainPageSurfaceLayer.cpp +++ b/src/components/ogre/terrain/TerrainPageSurfaceLayer.cpp @@ -64,7 +64,7 @@ bool TerrainPageSurfaceLayer::intersects(const TerrainPageGeometry& geometry) co void TerrainPageSurfaceLayer::fillImage(const TerrainPageGeometry& geometry, Image& image, unsigned int channel) const { SegmentVector validSegments = geometry.getValidSegments(); - for (const auto & validSegment : validSegments) { + for (const auto& validSegment : validSegments) { Mercator::Segment* segment = validSegment.segment; if (mShader.checkIntersect(*segment)) { Mercator::Surface* surface = getSurfaceForSegment(segment); diff --git a/src/components/ogre/terrain/TerrainPageSurfaceLayer.h b/src/components/ogre/terrain/TerrainPageSurfaceLayer.h index 30d39e270e..19a6e19b78 100644 --- a/src/components/ogre/terrain/TerrainPageSurfaceLayer.h +++ b/src/components/ogre/terrain/TerrainPageSurfaceLayer.h @@ -25,27 +25,29 @@ #include "../EmberOgrePrerequisites.h" -namespace Mercator -{ +namespace Mercator { class Shader; + class Surface; + class Segment; } -namespace Ogre -{ +namespace Ogre { class Image; } - namespace Ember { namespace OgreView { namespace Terrain { class TerrainPageSurface; + struct TerrainLayerDefinition; + class TerrainPageGeometry; + class Image; /** @@ -55,20 +57,25 @@ class Image; * * @author Erik Ogenvik */ -class TerrainPageSurfaceLayer{ +class TerrainPageSurfaceLayer { public: - TerrainPageSurfaceLayer(TerrainPageSurface& terrainPageSurface, const TerrainLayerDefinition& definition, int surfaceIndex, const Mercator::Shader& shader); + TerrainPageSurfaceLayer(TerrainPageSurface& terrainPageSurface, const TerrainLayerDefinition& definition, int surfaceIndex, const Mercator::Shader& shader); + + virtual ~TerrainPageSurfaceLayer(); - virtual ~TerrainPageSurfaceLayer(); + const std::string& getDiffuseTextureName() const; - const std::string& getDiffuseTextureName() const; - void setDiffuseTextureName(const std::string& textureName); - const std::string& getSpecularTextureName() const; - void setSpecularTextureName(const std::string& textureName); - const std::string& getNormalTextureName() const; - void setNormalTextureName(const std::string& textureName); + void setDiffuseTextureName(const std::string& textureName); - unsigned int getPixelWidth() const; + const std::string& getSpecularTextureName() const; + + void setSpecularTextureName(const std::string& textureName); + + const std::string& getNormalTextureName() const; + + void setNormalTextureName(const std::string& textureName); + + unsigned int getPixelWidth() const; /** * @brief Checks whether this layer intersects the page to which it belongs. @@ -79,9 +86,11 @@ class TerrainPageSurfaceLayer{ bool intersects(const TerrainPageGeometry& geometry) const; int getSurfaceIndex() const; + Mercator::Surface* getSurfaceForSegment(const Mercator::Segment* segment) const; float getScale() const; + void setScale(float scale); const TerrainLayerDefinition& getDefinition() const; diff --git a/src/components/ogre/terrain/TerrainParser.h b/src/components/ogre/terrain/TerrainParser.h index 0f397e8124..4dd885a522 100644 --- a/src/components/ogre/terrain/TerrainParser.h +++ b/src/components/ogre/terrain/TerrainParser.h @@ -22,20 +22,19 @@ #include "Types.h" #include -namespace WFMath -{ -template class Point; + +namespace WFMath { +template +class Point; } -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { class TerrainManager; + struct TerrainDefPoint; /** @@ -45,8 +44,7 @@ struct TerrainDefPoint; @author Erik Ogenvik */ -struct TerrainParser -{ +struct TerrainParser { /** * @brief Extracts terrain updates from the element and updates the terrain. diff --git a/src/components/ogre/terrain/TerrainShaderUpdateTask.cpp b/src/components/ogre/terrain/TerrainShaderUpdateTask.cpp index e082c0f874..4fa6a821a9 100644 --- a/src/components/ogre/terrain/TerrainShaderUpdateTask.cpp +++ b/src/components/ogre/terrain/TerrainShaderUpdateTask.cpp @@ -37,13 +37,11 @@ TerrainShaderUpdateTask::TerrainShaderUpdateTask(GeometryPtrVector geometry, const TerrainShader* shader, AreaStore areas, sigc::signal& signal, - sigc::signal& signalMaterialRecompiled, - const WFMath::Vector<3>& lightDirection) : + sigc::signal& signalMaterialRecompiled) : mGeometry(std::move(geometry)), mAreas(std::move(areas)), mSignal(signal), - mSignalMaterialRecompiled(signalMaterialRecompiled), - mLightDirection(lightDirection) { + mSignalMaterialRecompiled(signalMaterialRecompiled) { mShaders.push_back(shader); } @@ -51,14 +49,12 @@ TerrainShaderUpdateTask::TerrainShaderUpdateTask(GeometryPtrVector geometry, std::vector shaders, AreaStore areas, sigc::signal& signal, - sigc::signal& signalMaterialRecompiled, - const WFMath::Vector<3>& lightDirection) : + sigc::signal& signalMaterialRecompiled) : mGeometry(std::move(geometry)), mShaders(std::move(shaders)), mAreas(std::move(areas)), mSignal(signal), - mSignalMaterialRecompiled(signalMaterialRecompiled), - mLightDirection(lightDirection) { + mSignalMaterialRecompiled(signalMaterialRecompiled) { } TerrainShaderUpdateTask::~TerrainShaderUpdateTask() = default; @@ -83,7 +79,7 @@ void TerrainShaderUpdateTask::executeTaskInBackgroundThread(Tasks::TaskExecution } } - context.executeTask(std::make_unique(updatedPages, mSignalMaterialRecompiled, mLightDirection)); + context.executeTask(std::make_unique(updatedPages, mSignalMaterialRecompiled)); //Release Segment references as soon as we can mGeometry.clear(); } diff --git a/src/components/ogre/terrain/TerrainShaderUpdateTask.h b/src/components/ogre/terrain/TerrainShaderUpdateTask.h index 0da1463b37..72ac7f53fd 100644 --- a/src/components/ogre/terrain/TerrainShaderUpdateTask.h +++ b/src/components/ogre/terrain/TerrainShaderUpdateTask.h @@ -27,22 +27,21 @@ #include #include -namespace WFMath -{ -template class AxisBox; +namespace WFMath { +template +class AxisBox; } -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { class TerrainShader; + class TerrainPage; + class TerrainPageSurfaceCompilationInstance; /** @@ -50,8 +49,7 @@ class TerrainPageSurfaceCompilationInstance; * This will also recompile the terrain page material once the surface has been updated. * @author Erik Ogenvik */ -class TerrainShaderUpdateTask : public Tasks::TemplateNamedTask -{ +class TerrainShaderUpdateTask : public Tasks::TemplateNamedTask { public: /** @@ -64,11 +62,10 @@ class TerrainShaderUpdateTask : public Tasks::TemplateNamedTask& signal, - sigc::signal& signalMaterialRecompiled, - const WFMath::Vector<3>& lightDirection); + const TerrainShader* shader, + AreaStore areas, + sigc::signal& signal, + sigc::signal& signalMaterialRecompiled); /** * @brief Ctor. @@ -80,11 +77,10 @@ class TerrainShaderUpdateTask : public Tasks::TemplateNamedTask shaders, - AreaStore areas, - sigc::signal& signal, - sigc::signal& signalMaterialRecompiled, - const WFMath::Vector<3>& lightDirection); + std::vector shaders, + AreaStore areas, + sigc::signal& signal, + sigc::signal& signalMaterialRecompiled); ~TerrainShaderUpdateTask() override; @@ -112,18 +108,13 @@ class TerrainShaderUpdateTask : public Tasks::TemplateNamedTask& mSignal; + sigc::signal& mSignal; /** * @brief A signal to pass on to the material recompilation task; */ sigc::signal& mSignalMaterialRecompiled; - /** - * @brief The main light direction. - */ - const WFMath::Vector<3> mLightDirection; - }; } diff --git a/src/components/ogre/terrain/Types.h b/src/components/ogre/terrain/Types.h index d8c8b07657..c00ec67492 100644 --- a/src/components/ogre/terrain/Types.h +++ b/src/components/ogre/terrain/Types.h @@ -28,86 +28,93 @@ #include namespace Mercator { - class Area; - class Terrain; - class Shader; - class TerrainMod; +class Area; + +class Terrain; + +class Shader; + +class TerrainMod; } namespace Eris { - class TerrainModTranslator; +class TerrainModTranslator; } -namespace WFMath -{ - template class AxisBox; +namespace WFMath { +template +class AxisBox; } namespace Ember { namespace OgreView { - namespace Terrain { +namespace Terrain { - class TerrainPage; - class TerrainShader; - class TerrainPageSurfaceLayer; - class TerrainPageGeometry; - class Segment; - class ITerrainPageBridge; +class TerrainPage; - /** - @brief Defines the height of a special "base point" in the terrain. - These base points are then user by Mercator::Terrain for generating the actual terrain. - */ - struct TerrainDefPoint; +class TerrainShader; - /** - * @brief A type used for storing changes to areas. We use instances instead of pointers or references since this type will be used in delayed updating, where the originating instance might not any longer be around. - */ - typedef std::vector> AreaStore; +class TerrainPageSurfaceLayer; - /** - * @brief A type used for storing the terrain definition points. - */ - typedef std::vector TerrainDefPointStore; +class TerrainPageGeometry; +class Segment; - /** - * @brief Encapsules a shader update request. - */ - struct ShaderUpdateRequest - { - /** - * @brief A list of areas that have been changed. - * Unless UpdateAll is true, this should be used for determining what geometry needs updating. - */ - AreaStore Areas; - }; +class ITerrainPageBridge; - typedef std::shared_ptr SegmentRefPtr; +/** + @brief Defines the height of a special "base point" in the terrain. + These base points are then user by Mercator::Terrain for generating the actual terrain. + */ +struct TerrainDefPoint; - typedef std::map SegmentRefColumn; +/** + * @brief A type used for storing changes to areas. We use instances instead of pointers or references since this type will be used in delayed updating, where the originating instance might not any longer be around. + */ +typedef std::vector> AreaStore; - typedef std::map SegmentRefStore; +/** + * @brief A type used for storing the terrain definition points. + */ +typedef std::vector TerrainDefPointStore; - typedef std::map AreaShaderstore; - typedef std::map ShaderUpdateSet; +/** + * @brief Encapsules a shader update request. + */ +struct ShaderUpdateRequest { + /** + * @brief A list of areas that have been changed. + * Unless UpdateAll is true, this should be used for determining what geometry needs updating. + */ + AreaStore Areas; +}; - typedef std::unordered_map PageStore; +typedef std::shared_ptr SegmentRefPtr; - typedef std::shared_ptr TerrainPageGeometryPtr; +typedef std::map SegmentRefColumn; - typedef std::vector GeometryPtrVector; +typedef std::map SegmentRefStore; - typedef std::shared_ptr ITerrainPageBridgePtr; +typedef std::map AreaShaderstore; - typedef std::vector> BridgeBoundGeometryPtrVector; +typedef std::map ShaderUpdateSet; - typedef std::map SurfaceLayerStore; +typedef std::unordered_map PageStore; - typedef std::map> ShaderStore; - } +typedef std::shared_ptr TerrainPageGeometryPtr; + +typedef std::vector GeometryPtrVector; + +typedef std::shared_ptr ITerrainPageBridgePtr; + +typedef std::vector> BridgeBoundGeometryPtrVector; + +typedef std::map SurfaceLayerStore; + +typedef std::map> ShaderStore; +} } } diff --git a/src/components/ogre/terrain/WFImage.cpp b/src/components/ogre/terrain/WFImage.cpp index 78ae2af7de..834145eff8 100644 --- a/src/components/ogre/terrain/WFImage.cpp +++ b/src/components/ogre/terrain/WFImage.cpp @@ -20,29 +20,23 @@ #include "WFImage.h" #include "OgreImage.h" -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { WFImage::WFImage(std::unique_ptr buffer) : - Image(std::move(buffer)) -{ + Image(std::move(buffer)) { } -void WFImage::blit(const OgreImage& imageToBlit, unsigned int destinationChannel, int widthOffset, int heightOffset) -{ +void WFImage::blit(const OgreImage& imageToBlit, unsigned int destinationChannel, int widthOffset, int heightOffset) { } -void WFImage::blit(const WFImage& imageToBlit, unsigned int destinationChannel, int widthOffset, int heightOffset) -{ +void WFImage::blit(const WFImage& imageToBlit, unsigned int destinationChannel, int widthOffset, int heightOffset) { } } diff --git a/src/components/ogre/terrain/XMLLayerDefinitionSerializer.cpp b/src/components/ogre/terrain/XMLLayerDefinitionSerializer.cpp index 84c158c4e5..7ac269dacf 100644 --- a/src/components/ogre/terrain/XMLLayerDefinitionSerializer.cpp +++ b/src/components/ogre/terrain/XMLLayerDefinitionSerializer.cpp @@ -79,7 +79,7 @@ std::vector XMLLayerDefinitionSerializer::parseScript(Og definition.mName = smElem->Attribute("name"); definition.mDiffuseTextureName = smElem->Attribute("diffusetexture"); - definition.mNormalMapTextureName = smElem->Attribute("normalmaptexture"); + definition.mNormalMapTextureName = smElem->Attribute("normalmaptexture"); float tileSize; if (smElem->QueryFloatAttribute("tilesize", &tileSize) == TIXML_SUCCESS) { definition.mTileSize = tileSize; diff --git a/src/components/ogre/terrain/XMLLayerDefinitionSerializer.h b/src/components/ogre/terrain/XMLLayerDefinitionSerializer.h index cc2d088b23..2d06e2d9e1 100644 --- a/src/components/ogre/terrain/XMLLayerDefinitionSerializer.h +++ b/src/components/ogre/terrain/XMLLayerDefinitionSerializer.h @@ -33,15 +33,15 @@ namespace OgreView { namespace Terrain { class TerrainLayerDefinitionManager; + /** @author Erik Ogenvik */ -class XMLLayerDefinitionSerializer -{ +class XMLLayerDefinitionSerializer { public: - XMLLayerDefinitionSerializer(); + XMLLayerDefinitionSerializer(); - ~XMLLayerDefinitionSerializer(); + ~XMLLayerDefinitionSerializer(); std::vector parseScript(Ogre::DataStreamPtr& stream); diff --git a/src/components/ogre/terrain/foliage/ClusterPopulator.cpp b/src/components/ogre/terrain/foliage/ClusterPopulator.cpp index 1f1e20a474..3e58420941 100644 --- a/src/components/ogre/terrain/foliage/ClusterPopulator.cpp +++ b/src/components/ogre/terrain/foliage/ClusterPopulator.cpp @@ -19,30 +19,25 @@ #include #include #include -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ +namespace Ember { +namespace OgreView { -namespace Foliage -{ +namespace Terrain { + +namespace Foliage { ClusterPopulator::ClusterPopulator(int layerIndex, std::unique_ptr scaler, size_t plantIndex) : - PlantPopulator(layerIndex, std::move(scaler), plantIndex), - mMinClusterRadius(1.0f), - mMaxClusterRadius(1.0f), - mClusterDistance(1.0f), - mDensity(1.0f), - mFalloff(1.0f), - mThreshold(0) -{ -} - -void ClusterPopulator::populate(PlantAreaQueryResult& result, SegmentRefPtr segmentRef) -{ + PlantPopulator(layerIndex, std::move(scaler), plantIndex), + mMinClusterRadius(1.0f), + mMaxClusterRadius(1.0f), + mClusterDistance(1.0f), + mDensity(1.0f), + mFalloff(1.0f), + mThreshold(0) { +} + +void ClusterPopulator::populate(PlantAreaQueryResult& result, SegmentRefPtr segmentRef) { Mercator::Segment& mercatorSegment = segmentRef->getMercatorSegment(); if (!mercatorSegment.isValid()) { mercatorSegment.populate(); @@ -92,8 +87,7 @@ void ClusterPopulator::populate(PlantAreaQueryResult& result, SegmentRefPtr segm } } -void ClusterPopulator::getClustersForArea(const SegmentRefPtr& segmentRef, const WFMath::AxisBox<2>& area, ClusterStore& store) -{ +void ClusterPopulator::getClustersForArea(const SegmentRefPtr& segmentRef, const WFMath::AxisBox<2>& area, ClusterStore& store) { //Generate clusters for the current page and all surrounding pages and check if any of these are contained or intersect our local area Mercator::Segment& mercatorSegment = segmentRef->getMercatorSegment(); @@ -127,8 +121,7 @@ void ClusterPopulator::populateWithClusters(const SegmentRefPtr& segmentRef, PlantAreaQueryResult& result, const WFMath::AxisBox<2>& area, const ClusterStore& clusters, - const Buffer& combinedCoverage) -{ + const Buffer& combinedCoverage) { for (const auto& cluster : clusters) { populateWithCluster(segmentRef, result, area, cluster, combinedCoverage); } @@ -139,8 +132,7 @@ void ClusterPopulator::populateWithCluster(const SegmentRefPtr& segmentRef, PlantAreaQueryResult& result, const WFMath::AxisBox<2>& area, const WFMath::Ball<2>& cluster, - const Buffer& combinedCoverage) -{ + const Buffer& combinedCoverage) { PlantAreaQueryResult::PlantStore& plants = result.mStore; Mercator::Segment& mercatorSegment = segmentRef->getMercatorSegment(); @@ -167,7 +159,7 @@ void ClusterPopulator::populateWithCluster(const SegmentRefPtr& segmentRef, if (WFMath::Contains(area, pos, true)) { WFMath::Point<2> localPos(pos.x() - mercatorSegment.getXRef(), pos.y() - mercatorSegment.getZRef()); - if (data[((unsigned int)localPos.y() * res) + ((unsigned int)localPos.x())] >= mThreshold) { + if (data[((unsigned int) localPos.y() * res) + ((unsigned int) localPos.x())] >= mThreshold) { mercatorSegment.getHeightAndNormal(localPos.x(), localPos.y(), height, normal); plants.emplace_back(PlantInstance{Ogre::Vector3(pos.x(), height, pos.y()), rotation, scale}); } @@ -175,63 +167,51 @@ void ClusterPopulator::populateWithCluster(const SegmentRefPtr& segmentRef, } } -float ClusterPopulator::getMinClusterRadius() const -{ +float ClusterPopulator::getMinClusterRadius() const { return mMinClusterRadius; } -void ClusterPopulator::setMinClusterRadius(float theValue) -{ +void ClusterPopulator::setMinClusterRadius(float theValue) { mMinClusterRadius = theValue; } -float ClusterPopulator::getMaxClusterRadius() const -{ +float ClusterPopulator::getMaxClusterRadius() const { return mMaxClusterRadius; } -void ClusterPopulator::setMaxClusterRadius(float theValue) -{ +void ClusterPopulator::setMaxClusterRadius(float theValue) { mMaxClusterRadius = theValue; } -float ClusterPopulator::getDensity() const -{ +float ClusterPopulator::getDensity() const { return mDensity; } -void ClusterPopulator::setDensity(float theValue) -{ +void ClusterPopulator::setDensity(float theValue) { mDensity = theValue; } -float ClusterPopulator::getFalloff() const -{ +float ClusterPopulator::getFalloff() const { return mFalloff; } -void ClusterPopulator::setFalloff(float theValue) -{ +void ClusterPopulator::setFalloff(float theValue) { mFalloff = theValue; } -float ClusterPopulator::getClusterDistance() const -{ +float ClusterPopulator::getClusterDistance() const { return mClusterDistance; } -void ClusterPopulator::setClusterDistance(float theValue) -{ +void ClusterPopulator::setClusterDistance(float theValue) { mClusterDistance = theValue; } -void ClusterPopulator::setThreshold(unsigned char theValue) -{ +void ClusterPopulator::setThreshold(unsigned char theValue) { mThreshold = theValue; } -float ClusterPopulator::getTreshold() const -{ +float ClusterPopulator::getTreshold() const { return mThreshold; } diff --git a/src/components/ogre/terrain/foliage/Vegetation.h b/src/components/ogre/terrain/foliage/Vegetation.h index 1cae317dc5..45188680b1 100644 --- a/src/components/ogre/terrain/foliage/Vegetation.h +++ b/src/components/ogre/terrain/foliage/Vegetation.h @@ -13,24 +13,20 @@ #include #include -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { struct TerrainFoliageDefinition; struct PlantAreaQueryResult; -namespace Foliage -{ +namespace Foliage { -class Vegetation -{ +class Vegetation { public: Vegetation() = default; + virtual ~Vegetation(); void createPopulator(const TerrainFoliageDefinition& foliageDef, unsigned int surfaceLayerIndex); diff --git a/src/components/ogre/terrain/techniques/OnePixelMaterialGenerator.cpp b/src/components/ogre/terrain/techniques/OnePixelMaterialGenerator.cpp index ee0fb457b3..1bb0af3348 100644 --- a/src/components/ogre/terrain/techniques/OnePixelMaterialGenerator.cpp +++ b/src/components/ogre/terrain/techniques/OnePixelMaterialGenerator.cpp @@ -25,23 +25,18 @@ #include #include -namespace Ember -{ -namespace OgreView -{ -namespace Terrain -{ -namespace Techniques -{ -void OnePixelMaterialGenerator::loadResource(Ogre::Resource* resource) -{ +namespace Ember { +namespace OgreView { +namespace Terrain { +namespace Techniques { +void OnePixelMaterialGenerator::loadResource(Ogre::Resource* resource) { auto* texture = static_cast(resource); static Ogre::uchar data[3] = {0xFF, 0x7F, 0x7F}; Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data, 3, false, true)); Ogre::Image image; - image.loadRawData(stream, 1,1,1, Ogre::PF_R8G8B8); + image.loadRawData(stream, 1, 1, 1, Ogre::PF_R8G8B8); Ogre::ConstImagePtrList images({&image}); texture->_loadImages(images); diff --git a/src/components/ogre/terrain/techniques/Shader.h b/src/components/ogre/terrain/techniques/Shader.h index a00febaaf3..a4a2653956 100644 --- a/src/components/ogre/terrain/techniques/Shader.h +++ b/src/components/ogre/terrain/techniques/Shader.h @@ -23,16 +23,12 @@ #include "Base.h" #include "components/ogre/OgreIncludes.h" -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { -namespace Techniques -{ +namespace Techniques { class ShaderPass; @@ -44,8 +40,7 @@ class ShaderPass; * This technique will use shaders for drawing the terrain. The blend map for the different layers will be combined into one combined texture, where each channel represents one layer. * */ -class Shader : public Base -{ +class Shader : public Base { public: /** @@ -58,24 +53,25 @@ class Shader : public Base */ static const std::string COMPOSITE_MAP_ALIAS; - /** - * @brief Ctor. - * @param includeShadows If true, shadows will be used. - * @param geometry The geometry to operate on. - * @param terrainPageSurfaces The surfaces to generate a rendering technique for. - * @param terrainPageShadow An optional shadow. - * @param sceneManager The scene manager which will hold the terrain. + /** + * @brief Ctor. + * @param includeShadows If true, shadows will be used. + * @param geometry The geometry to operate on. + * @param terrainPageSurfaces The surfaces to generate a rendering technique for. + * @param terrainPageShadow An optional shadow. + * @param sceneManager The scene manager which will hold the terrain. * @param useNormalMapping Whether to use normal mapping. - */ + */ Shader(bool includeShadows, const TerrainPageGeometryPtr& geometry, const SurfaceLayerStore& terrainPageSurfaces, Ogre::SceneManager& sceneManager, bool useNormalMapping = false); /** * @brief Dtor. */ - ~Shader() override; + ~Shader() override; + + bool prepareMaterial() override; - bool prepareMaterial() override; - bool compileMaterial(Ogre::MaterialPtr material, std::set& managedTextures) const override; + bool compileMaterial(Ogre::MaterialPtr material, std::set& managedTextures) const override; bool compileCompositeMapMaterial(Ogre::MaterialPtr material, std::set& managedTextures) const override; diff --git a/src/components/ogre/terrain/techniques/ShaderPass.h b/src/components/ogre/terrain/techniques/ShaderPass.h index d5caa29d19..5d406b0f9a 100644 --- a/src/components/ogre/terrain/techniques/ShaderPass.h +++ b/src/components/ogre/terrain/techniques/ShaderPass.h @@ -26,34 +26,36 @@ #include #include -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { class TerrainPage; + class TerrainPageSurfaceLayer; + class TerrainPageGeometry; + class TerrainPageShadow; -namespace Techniques -{ +namespace Techniques { class ShaderPassBlendMapBatch; typedef std::vector LayerStore; -class ShaderPass -{ +class ShaderPass { public: -friend class ShaderPassBlendMapBatch; + friend class ShaderPassBlendMapBatch; + ShaderPass(Ogre::SceneManager& sceneManager, int blendMapPixelWidth, const WFMath::Point<2>& position, bool useNormalMapping = false); + virtual ~ShaderPass(); virtual void addLayer(const TerrainPageGeometry& geometry, const TerrainPageSurfaceLayer* layer); + virtual void setBaseLayer(const TerrainPageSurfaceLayer* layer); + void addShadowLayer(); virtual bool hasRoomForLayer(const TerrainPageSurfaceLayer* layer); @@ -72,9 +74,11 @@ friend class ShaderPassBlendMapBatch; protected: ShaderPassBlendMapBatch* getCurrentBatch(); + virtual std::unique_ptr createNewBatch(); unsigned int getBlendMapPixelWidth() const; + Ogre::TexturePtr getCombinedBlendMapTexture(size_t passIndex, size_t batchIndex, std::set& managedTextures) const; float mScales[16]; diff --git a/src/components/ogre/terrain/techniques/ShaderPassBlendMapBatch.h b/src/components/ogre/terrain/techniques/ShaderPassBlendMapBatch.h index e40f815962..d2f5a0d74d 100644 --- a/src/components/ogre/terrain/techniques/ShaderPassBlendMapBatch.h +++ b/src/components/ogre/terrain/techniques/ShaderPassBlendMapBatch.h @@ -24,19 +24,16 @@ #include #include -namespace Ember -{ -namespace OgreView -{ +namespace Ember { +namespace OgreView { -namespace Terrain -{ +namespace Terrain { class TerrainPageGeometry; + class TerrainPageSurfaceLayer; -namespace Techniques -{ +namespace Techniques { class ShaderPass; @@ -46,10 +43,10 @@ typedef std::vector LayerStore; * @brief A helper for the Shader technique. Combines several blend map textures into batches and sets the appropriate pass parameters. * @author Erik Ogenvik */ -class ShaderPassBlendMapBatch -{ +class ShaderPassBlendMapBatch { public: ShaderPassBlendMapBatch(ShaderPass& shaderPass, unsigned int imageSize); + virtual ~ShaderPassBlendMapBatch(); void addLayer(const TerrainPageGeometry& geometry, const TerrainPageSurfaceLayer* layer); @@ -71,6 +68,7 @@ class ShaderPassBlendMapBatch std::vector mSyncedTextures; void assignCombinedBlendMapTexture(Ogre::TexturePtr texture); + void addBlendMap(const TerrainPageGeometry& geometry, const TerrainPageSurfaceLayer* layer, unsigned int channel); };