From f0b21cca228475b1b31edf62ed91d23615d70675 Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Sat, 10 Jun 2017 23:02:56 +0200 Subject: [PATCH 1/3] use own inline hash_combine function --- components/sceneutil/lightmanager.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index bc042f7d66..018abeefc6 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -209,13 +209,21 @@ namespace SceneUtil mLights.push_back(l); } + /* similar to the boost::hash_combine */ + template + inline void hash_combine(std::size_t& seed, const T& v) + { + std::hash hasher; + seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2); + } + osg::ref_ptr LightManager::getLightListStateSet(const LightList &lightList, unsigned int frameNum) { + // possible optimization: return a StateSet containing all requested lights plus some extra lights (if a suitable one exists) size_t hash = 0; for (unsigned int i=0; imLightSource->getId() << 1); // or use boost::hash_combine - // original: boost::hash_combine(hash, lightList[i]->mLightSource->getId()); + hash_combine(hash, lightList[i]->mLightSource->getId()); LightStateSetMap& stateSetCache = mStateSetCache[frameNum%2]; From 7c758a629363d3a7b8fcd88fd2d40ab618c2591d Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Sun, 11 Jun 2017 09:23:19 +0200 Subject: [PATCH 2/3] std::stof can not handle comma in us localization and can not handle period in french localization, using std::replace is not a solution, going back to boost::lexical_cast --- components/fallback/fallback.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/fallback/fallback.cpp b/components/fallback/fallback.cpp index 9b058f104e..010e1025c6 100644 --- a/components/fallback/fallback.cpp +++ b/components/fallback/fallback.cpp @@ -1,5 +1,8 @@ #include "fallback.hpp" +#include + + namespace Fallback { bool stob(std::string const& s) { @@ -23,8 +26,9 @@ namespace Fallback std::string fallback=getFallbackString(fall); if(fallback.empty()) return 0; - else - return std::stof(fallback); + else { + return boost::lexical_cast(fallback); + } } int Map::getFallbackInt(const std::string& fall) const { From c6805314c22a1837c03faeb2e3a045936ad1b776 Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Sun, 11 Jun 2017 09:32:30 +0200 Subject: [PATCH 3/3] be explicit about what we are trying to catch instead of catching everything and fixed up formatting use Allman style brackets not K&R style, additional formatting for fallback.cpp which needed some love revert allman formatting changes --- components/fallback/fallback.cpp | 8 +++++--- components/widgets/numericeditbox.cpp | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/components/fallback/fallback.cpp b/components/fallback/fallback.cpp index 010e1025c6..11a577a45c 100644 --- a/components/fallback/fallback.cpp +++ b/components/fallback/fallback.cpp @@ -21,15 +21,16 @@ namespace Fallback } return it->second; } + float Map::getFallbackFloat(const std::string& fall) const { std::string fallback=getFallbackString(fall); if(fallback.empty()) return 0; - else { - return boost::lexical_cast(fallback); - } + else + return boost::lexical_cast(fallback); } + int Map::getFallbackInt(const std::string& fall) const { std::string fallback=getFallbackString(fall); @@ -47,6 +48,7 @@ namespace Fallback else return stob(fallback); } + osg::Vec4f Map::getFallbackColour(const std::string& fall) const { std::string sum=getFallbackString(fall); diff --git a/components/widgets/numericeditbox.cpp b/components/widgets/numericeditbox.cpp index d59deb3787..828a84589b 100644 --- a/components/widgets/numericeditbox.cpp +++ b/components/widgets/numericeditbox.cpp @@ -1,3 +1,5 @@ +#include + #include "numericeditbox.hpp" namespace Gui @@ -36,7 +38,11 @@ namespace Gui setCaption(MyGUI::utility::toString(mValue)); } } - catch (...) + catch (std::invalid_argument) + { + setCaption(MyGUI::utility::toString(mValue)); + } + catch (std::out_of_range) { setCaption(MyGUI::utility::toString(mValue)); }