diff --git a/src/osgEarth/EarthManipulator b/src/osgEarth/EarthManipulator index fc8d0fee5b..12993728b8 100644 --- a/src/osgEarth/EarthManipulator +++ b/src/osgEarth/EarthManipulator @@ -16,8 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see */ -#ifndef OSGEARTHUTIL_EARTHMANIPULATOR -#define OSGEARTHUTIL_EARTHMANIPULATOR +#pragma once #include #include @@ -330,14 +329,12 @@ namespace osgEarth { namespace Util int modkey_mask =0L, const ActionOptions& options =ActionOptions() ); - void bindPinch( ActionType action, const ActionOptions& =ActionOptions() ); void bindTwist( ActionType action, const ActionOptions& =ActionOptions() ); - void bindMultiDrag( ActionType action, const ActionOptions& =ActionOptions() ); @@ -352,11 +349,8 @@ namespace osgEarth { namespace Util * 1.0 = default; < 1.0 = less sensitive; > 1.0 = more sensitive. */ void setMouseSensitivity( double value ) { _mouse_sens = value; } - - /** - * Gets the overall mouse sensitivity scale factor. Default = 1.0. - */ double getMouseSensitivity() const { return _mouse_sens; } + double& mouseSensitivity() { return _mouse_sens; } /** * Sets an overall touch sensitivity factor. @@ -366,11 +360,8 @@ namespace osgEarth { namespace Util * 0.005 = default; < 0.005 = less sensitive; > 0.005 = more sensitive. */ void setTouchSensitivity( double value ) { _touch_sens = value; } - - /** - * Gets the overall touch sensitivity scale factor. Default = 1.0. - */ double getTouchSensitivity() const { return _touch_sens; } + double& touchSensitivity() { return _touch_sens; } /** * Sets the keyboard action sensitivity factor. This applies to navigation actions @@ -383,11 +374,8 @@ namespace osgEarth { namespace Util * 1.0 = default; < 1.0 = less sensitive; > 1.0 = more sensitive. */ void setKeyboardSensitivity( double value ) { _keyboard_sens = value; } - - /** - * Gets the keyboard action sensitivity scale factor. Default = 1.0. - */ double getKeyboardSensitivity() const { return _keyboard_sens; } + double& keyboardSensitivity() { return _keyboard_sens; } /** * Sets the scroll-wheel sensitivity factor. This applies to navigation actions @@ -400,11 +388,8 @@ namespace osgEarth { namespace Util * 1.0 = default; < 1.0 = less sensitive; > 1.0 = more sensitive. */ void setScrollSensitivity( double value ) { _scroll_sens = value; } - - /** - * Gets the scroll wheel sensetivity scale factor. Default = 1.0. - */ double getScrollSensitivity() const { return _scroll_sens; } + double& scrollSensitivity() { return _scroll_sens; } /** * When set to true, prevents simultaneous control of pitch and azimuth. @@ -416,24 +401,16 @@ namespace osgEarth { namespace Util * Default = false. */ void setSingleAxisRotation( bool value ) { _single_axis_rotation = value; } - - /** - * Gets whether simultaneous control over pitch and azimuth is disabled. - * Default = false. - */ bool getSingleAxisRotation() const { return _single_axis_rotation; } + bool& singleAxisRotation() { return _single_axis_rotation; } /** * Sets whether to lock in a camera heading when performing panning operations (i.e., * changing the focal point). */ void setLockAzimuthWhilePanning( bool value ) { _lock_azim_while_panning = value; } - - /** - * Gets true if the manipulator should lock in a camera heading when performing panning - * operations (i.e. changing the focal point.) - */ bool getLockAzimuthWhilePanning() const { return _lock_azim_while_panning; } + bool& lockAzimuthWhilePanning() { return _lock_azim_while_panning; } /** * Sets the minimum and maximum allowable local camera pitch, in degrees. @@ -474,6 +451,7 @@ namespace osgEarth { namespace Util /** Mode used for tethering to a node. */ void setTetherMode( TetherMode value ) { _tether_mode = value; } TetherMode getTetherMode() const { return _tether_mode; } + TetherMode& tetherMode() { return _tether_mode; } /** Access to the list of Actions that will automatically break a tether */ ActionTypeVector& getBreakTetherActions() { return _breakTetherActions; } @@ -496,23 +474,29 @@ namespace osgEarth { namespace Util /** Whether to automatically adjust an orthographic camera so that it "tracks" the last known FOV and Aspect Ratio. */ bool getOrthoTracksPerspective() const { return _orthoTracksPerspective; } void setOrthoTracksPerspective(bool value) { _orthoTracksPerspective = value; } + bool& orthoTracksPerspective() { return _orthoTracksPerspective; } /** Whether or not to keep the camera from going through the terrain surface */ bool getTerrainAvoidanceEnabled() const { return _terrainAvoidanceEnabled; } void setTerrainAvoidanceEnabled( bool value ) { _terrainAvoidanceEnabled = value; } + bool& terrainAvoidanceEnabled() { return _terrainAvoidanceEnabled; } /** Minimum range for terrain avoidance checks in world coordinates */ double getTerrainAvoidanceMinimumDistance() const {return _terrainAvoidanceMinDistance; } void setTerrainAvoidanceMinimumDistance(double minDistance) { _terrainAvoidanceMinDistance = minDistance; } + double& terrainAvoidanceMinimumDistance() { return _terrainAvoidanceMinDistance; } void setThrowingEnabled(bool throwingEnabled) { _throwingEnabled = throwingEnabled; } bool getThrowingEnabled () const { return _throwingEnabled; } + bool& throwingEnabled() { return _throwingEnabled; } void setThrowDecayRate(double throwDecayRate) { _throwDecayRate = osg::clampBetween(throwDecayRate, 0.0, 1.0); } double getThrowDecayRate () const { return _throwDecayRate; } + double& throwDecayRate() { return _throwDecayRate; } void setZoomToMouse(bool value) { _zoomToMouse = value; } bool getZoomToMouse() const { return _zoomToMouse; } + bool& zoomToMouse() { return _zoomToMouse; } private: @@ -1051,5 +1035,3 @@ namespace osgEarth { namespace Util }; } } - -#endif // OSGEARTHUTIL_EARTHMANIPULATOR diff --git a/src/osgEarth/Math b/src/osgEarth/Math index 8c119c04ee..fe4f6a1ce6 100644 --- a/src/osgEarth/Math +++ b/src/osgEarth/Math @@ -566,6 +566,15 @@ namespace osgEarth return seed; } + // https://github.com/matteo65/mzHash64 (Public Domain) + inline std::size_t hash_string(const std::string& input, std::size_t seed = 0) { + auto hash = seed ^ 0xD45E69F901E72147L; + auto len = input.length(); + for(std::size_t i=0; i> 2); + return hash; + }; + /** * Utilities to manipulate a projection matrix. * These functions will automatically handle standard OGL versus Reverse-Z diff --git a/src/osgEarth/PagedNode.cpp b/src/osgEarth/PagedNode.cpp index f9d8a4e548..1ad108942a 100644 --- a/src/osgEarth/PagedNode.cpp +++ b/src/osgEarth/PagedNode.cpp @@ -424,7 +424,7 @@ PagingManager::update() { scoped_lock_if lock(_mergeMutex, _threadsafe); unsigned count = 0u; - while (!_mergeQueue.empty() && count++ < 64u) //_mergesPerFrame) + while (!_mergeQueue.empty() && count++ < _mergesPerFrame) { toMerge.emplace_back(_mergeQueue.front()); _mergeQueue.pop(); diff --git a/src/osgEarthImGui/CameraGUI b/src/osgEarthImGui/CameraGUI index 82acd00d01..a8bf849660 100644 --- a/src/osgEarthImGui/CameraGUI +++ b/src/osgEarthImGui/CameraGUI @@ -30,51 +30,34 @@ namespace osgEarth */ struct CameraGUI : public ImGuiPanel { - bool _first; - bool _singleAxisRotation; - bool _lockAzimuthWhilePanning; - bool _arcViewpointTransitions; - bool _terrainAvoidanceEnabled; - bool _throwing; - float _throwDecayRate; - bool _zoomToMouse; double _vfov, _ar, _zn, _zf; + EarthManipulator::Settings* _settings = nullptr; + Config _loadConf; CameraGUI() : ImGuiPanel("Camera"), - _first(true), _vfov(30), _ar(1), _zn(1), _zf(100) { - EarthManipulator::Settings d; - _singleAxisRotation = d.getSingleAxisRotation(); - _lockAzimuthWhilePanning = d.getLockAzimuthWhilePanning(); - _arcViewpointTransitions = d.getArcViewpointTransitions(); - _terrainAvoidanceEnabled = d.getTerrainAvoidanceEnabled(); - _throwing = d.getThrowingEnabled(); - _throwDecayRate = d.getThrowDecayRate(); - _zoomToMouse = d.getZoomToMouse(); + //nop } void load(const Config& conf) override { - conf.get("SingleAxisRotation", _singleAxisRotation); - conf.get("LockAzimuthWhilePanning", _lockAzimuthWhilePanning); - conf.get("ArcViewpointTransitions", _arcViewpointTransitions); - conf.get("TerrainAvoidance", _terrainAvoidanceEnabled); - conf.get("Throwing", _throwing); - conf.get("ThrowingDecay", _throwDecayRate); - conf.get("ZoomToMouse", _zoomToMouse); + // remember, the settings come in one at a time so we have to use merge + _loadConf.merge(conf); } void save(Config& conf) override { - conf.set("SingleAxisRotation", _singleAxisRotation); - conf.set("LockAzimuthWhilePanning", _lockAzimuthWhilePanning); - conf.set("ArcViewpointTransitions", _arcViewpointTransitions); - conf.set("TerrainAvoidance", _terrainAvoidanceEnabled); - conf.set("Throwing", _throwing); - conf.set("ThrowingDecay", _throwDecayRate); - conf.set("ZoomToMouse", _zoomToMouse); + if (_settings) + { + conf.set("SingleAxisRotation", _settings->singleAxisRotation()); + conf.set("LockAzimuthWhilePanning", _settings->lockAzimuthWhilePanning()); + conf.set("TerrainAvoidance", _settings->terrainAvoidanceEnabled()); + conf.set("Throwing", _settings->throwingEnabled()); + conf.set("ThrowingDecay", _settings->throwDecayRate()); + conf.set("ZoomToMouse", _settings->zoomToMouse()); + } } void draw(osg::RenderInfo& ri) @@ -82,18 +65,31 @@ namespace osgEarth if (!isVisible()) return; - EarthManipulator* man = dynamic_cast(view(ri)->getCameraManipulator()); - - EarthManipulator::Settings* s = nullptr; - + auto* man = dynamic_cast(view(ri)->getCameraManipulator()); if (man) - s = man->getSettings(); + { + _settings = man->getSettings(); + if (_settings && !_loadConf.empty()) + { + _loadConf.get("SingleAxisRotation", _settings->singleAxisRotation()); + _loadConf.get("LockAzimuthWhilePanning", _settings->lockAzimuthWhilePanning()); + _loadConf.get("TerrainAvoidance", _settings->terrainAvoidanceEnabled()); + _loadConf.get("Throwing", _settings->throwingEnabled()); + _loadConf.get("ThrowingDecay", _settings->throwDecayRate()); + _loadConf.get("ZoomToMouse", _settings->zoomToMouse()); + _loadConf = {}; + } + } - ImGui::Begin(name(), visible()); + if (!_settings) { - //if (ImGui::Checkbox("Single axis continuous rotation", &_singleAxisRotation) || _first) - // s->setSingleAxisRotation(_singleAxisRotation), dirtySettings(); + ImGui::TextColored(ImVec4(1, 0, 0, 1), "No earth manipulator"); + ImGui::End(); + return; + } + ImGui::Begin(name(), visible()); + { if (ImGuiLTable::Begin("CameraGUI")) { osg::Matrix pm = camera(ri)->getProjectionMatrix(); @@ -110,27 +106,24 @@ namespace osgEarth camera(ri)->setProjectionMatrix(pm); } - if (s) + if (_settings) { - if (ImGuiLTable::Checkbox("Lock azimuth", &_lockAzimuthWhilePanning) || _first) - s->setLockAzimuthWhilePanning(_lockAzimuthWhilePanning), dirtySettings(); - - if (ImGuiLTable::Checkbox("Arc transitions", &_arcViewpointTransitions) || _first) - s->setArcViewpointTransitions(_arcViewpointTransitions), dirtySettings(); + if (ImGuiLTable::Checkbox("Lock azimuth", &_settings->lockAzimuthWhilePanning())) + dirtySettings(); - if (ImGuiLTable::Checkbox("Avoid terrain", &_terrainAvoidanceEnabled) || _first) - s->setTerrainAvoidanceEnabled(_terrainAvoidanceEnabled), dirtySettings(); + if (ImGuiLTable::Checkbox("Avoid terrain", &_settings->terrainAvoidanceEnabled())) + dirtySettings(); - if (ImGuiLTable::Checkbox("Zoom to mouse", &_zoomToMouse) || _first) - s->setZoomToMouse(_zoomToMouse), dirtySettings(); + if (ImGuiLTable::Checkbox("Zoom to mouse", &_settings->zoomToMouse())) + dirtySettings(); - if (ImGuiLTable::Checkbox("Throwing", &_throwing) || _first) - s->setThrowingEnabled(_throwing), dirtySettings(); + if (ImGuiLTable::Checkbox("Throwing", &_settings->throwingEnabled())) + dirtySettings(); - if (_throwing || _first) + if (_settings->getThrowingEnabled()) { - if (ImGuiLTable::SliderFloat("Decay", &_throwDecayRate, 0.02f, 0.3f) || _first) - s->setThrowDecayRate(_throwDecayRate), dirtySettings(); + if (ImGuiLTable::SliderDouble("Decay", &_settings->throwDecayRate(), 0.0f, 0.3f)) + dirtySettings(); } } @@ -154,9 +147,7 @@ namespace osgEarth double vfov, ar, n, f; ProjectionMatrix::getPerspective(ref_proj, vfov, ar, n, f); ProjectionMatrix::setPerspective(new_proj, vfov * rangeScale, ar, n, f); - - if (s) - s->setOrthoTracksPerspective(true); + _settings->setOrthoTracksPerspective(true); } else { @@ -170,9 +161,7 @@ namespace osgEarth H = (R - L) * rangeScale / 2; L = M - H, R = M + H; ProjectionMatrix::setOrtho(new_proj, L, R, B, T, N, F); - - if (s) - s->setOrthoTracksPerspective(false); + _settings->setOrthoTracksPerspective(false); } camera(ri)->setProjectionMatrix(new_proj); @@ -216,7 +205,6 @@ namespace osgEarth } } - _first = false; ImGui::End(); } }; diff --git a/src/osgEarthImGui/ImGuiEventHandler.cpp b/src/osgEarthImGui/ImGuiEventHandler.cpp index f30d9d8c46..4b64b32b46 100644 --- a/src/osgEarthImGui/ImGuiEventHandler.cpp +++ b/src/osgEarthImGui/ImGuiEventHandler.cpp @@ -23,6 +23,13 @@ using namespace osgEarth; +#include "ImGuiPanel" +void ImGuiPanel::dirtySettings() +{ + if (ImGui::GetCurrentContext()) + ImGui::MarkIniSettingsDirty(); +} + namespace { struct PreDrawOp : public osg::Camera::DrawCallback diff --git a/src/osgEarthImGui/ImGuiPanel b/src/osgEarthImGui/ImGuiPanel index dd2e2bf739..cf6802a8c5 100644 --- a/src/osgEarthImGui/ImGuiPanel +++ b/src/osgEarthImGui/ImGuiPanel @@ -178,10 +178,10 @@ namespace osgEarth save(conf); } - void dirtySettings() - { - // nop - settings save automatically - } + static void dirtySettings(); + //{ + // // nop - settings save automatically + //} //! whether the visibility changed (and resets the flag) bool visibilityChanged() { diff --git a/src/osgEarthImGui/SystemGUI b/src/osgEarthImGui/SystemGUI index e103cdb344..e1689f1511 100644 --- a/src/osgEarthImGui/SystemGUI +++ b/src/osgEarthImGui/SystemGUI @@ -198,6 +198,8 @@ namespace osgEarth if (ImGuiLTable::SliderFloat("Font Scale", &ImGui::GetIO().FontGlobalScale, 0.5f, 2.0f)) dirtySettings(); + //ImGuiLTable::Text("Dirty timer", "%.1f", ImGui::GetCurrentContext()->SettingsDirtyTimer); // ::GetIO().IniSavingRate); + ImGuiLTable::End(); } diff --git a/src/osgEarthImGui/TerrainGUI b/src/osgEarthImGui/TerrainGUI index 23bfd19814..fab3ad6e6f 100644 --- a/src/osgEarthImGui/TerrainGUI +++ b/src/osgEarthImGui/TerrainGUI @@ -88,9 +88,16 @@ namespace osgEarth if (ImGuiLTable::Begin("terraingui")) { - ImGuiLTable::Text("Resident Tiles", "%u (%s)", - engine->getNumResidentTiles(), - engine->getNode()->getName().c_str()); + ImGuiLTable::Text("Resident Tiles", "%u", + engine->getNumResidentTiles());// , + //engine->getNode()->getName().c_str()); + + int minResident = options.getMinResidentTiles(); + if (ImGuiLTable::SliderInt("Resident Cache Size", &minResident, 0, 5000)) + { + options.setMinResidentTiles(minResident); + engine->dirtyTerrainOptions(); + } static bool terrain_visible = true; static osg::ref_ptr visible_cb; @@ -130,10 +137,10 @@ namespace osgEarth if (options.getLODMethod() == LODMethod::SCREEN_SPACE) { - float tilePixelSize = options.getTilePixelSize(); - if (ImGuiLTable::SliderFloat(" Pixels/tile:", &tilePixelSize, 64.0f, 1024.0f)) + float tileImagePixelSize = options.getTilePixelSize(); + if (ImGuiLTable::SliderFloat(" Tile image size", &tileImagePixelSize, 64.0f, 1024.0f)) { - options.setTilePixelSize(tilePixelSize); + options.setTilePixelSize(tileImagePixelSize); engine->dirtyTerrainOptions(); } }