From 50c993437678ea91dd02e0809426449906e46626 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 29 Dec 2012 17:02:07 +0000 Subject: [PATCH 1/7] Bringing minor improvements from Cubiquity's PolyVox into the main branch. --- library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/Interpolation.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h index 2053c351..77dac7a4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h @@ -40,12 +40,12 @@ namespace PolyVox inline int32_t roundTowardsNegInf(float r) { - return (r > 0.0) ? static_cast(r) : static_cast(r - 1.0f); + return (r >= 0.0) ? static_cast(r) : static_cast(r - 1.0f); } inline int32_t roundToNearestInteger(float r) { - return (r > 0.0) ? static_cast(r + 0.5f) : static_cast(r - 0.5f); + return (r >= 0.0) ? static_cast(r + 0.5f) : static_cast(r - 0.5f); } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/Interpolation.h b/library/PolyVoxCore/include/PolyVoxCore/Interpolation.h index 5c76fe47..09c063c9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Interpolation.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Interpolation.h @@ -36,7 +36,7 @@ namespace PolyVox assert((x >= 0.0f) && (x <= 1.0f)); //Interpolate along X - Type v0_1 = v0 + x * (v1 - v0); + Type v0_1 = (v1 - v0) * x + v0; return v0_1; } From 2b70f81a9a7937b3bd964528cbda1ee818d121de Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 29 Dec 2012 20:32:21 +0000 Subject: [PATCH 2/7] Added missing .cpp file... thought I did this already?! --- .../PolyVoxCore/source/Impl/ErrorHandling.cpp | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 library/PolyVoxCore/source/Impl/ErrorHandling.cpp diff --git a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp new file mode 100644 index 00000000..bc7dc2c5 --- /dev/null +++ b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp @@ -0,0 +1,71 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#include "PolyVoxCore/Impl/ErrorHandling.h" + +#ifndef POLYVOX_THROW_ENABLED + namespace PolyVox + { + void defaultThrowHandler(std::exception& e, const char* file, int line) + { + std::cerr << std::endl << std::endl; \ + std::cerr << " PolyVox exception thrown!" << std::endl; \ + std::cerr << " =========================" << std::endl; \ + std::cerr << " PolyVox has tried to throw an exception but it was built without support" << std::endl; \ + std::cerr << " for exceptions. In this scenario PolyVox will call a 'throw handler'" << std::endl; \ + std::cerr << " and this message is being printed by the default throw handler." << std::endl << std::endl; \ + + std::cerr << " If you don't want to enable exceptions then you should try to determine why" << std::endl; \ + std::cerr << " this exception was thrown and make sure it doesn't happen again. If it was" << std::endl; \ + std::cerr << " due to something like an invalid argument to a function then you should be" << std::endl; \ + std::cerr << " able to fix it quite easily by validating parameters as appropriate. More" << std::endl; \ + std::cerr << " complex exception scenarios (out of memory, etc) might be harder to fix and" << std::endl; \ + std::cerr << " you should replace this default handler with something which is more" << std::endl; \ + std::cerr << " meaningful to your users." << std::endl << std::endl; \ + + std::cerr << " Exception details" << std::endl; \ + std::cerr << " -----------------" << std::endl; \ + std::cerr << " Line: " << line << std::endl; \ + std::cerr << " File: " << file << std::endl; \ + std::cerr << " Message: " << e.what() << std::endl << std::endl; \ + + POLYVOX_HALT(); \ + } + + ThrowHandler& getThrowHandlerInstance() + { + static ThrowHandler s_fThrowHandler = &defaultThrowHandler; + return s_fThrowHandler; + } + + ThrowHandler getThrowHandler() + { + return getThrowHandlerInstance(); + } + + void setThrowHandler(ThrowHandler fNewHandler) + { + getThrowHandlerInstance() = fNewHandler; + } + } +#endif From 5be6a8ba440cd15d5eb61838007dc0ab75a638e7 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 29 Dec 2012 20:41:23 +0000 Subject: [PATCH 3/7] Updated default compiler capabilities as used by Visual Studio - these are subject to change further. --- .../include/PolyVoxCore/Impl/CompilerCapabilities.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h index 325b5ed1..2d10b5ff 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h @@ -9,12 +9,12 @@ #ifndef __PolyVox_CompilerCapabilities_H__ #define __PolyVox_CompilerCapabilities_H__ -//#undef HAS_CXX11_CONSTEXPR +//#define HAS_CXX11_CONSTEXPR -//#undef HAS_CXX11_STATIC_ASSERT +#define HAS_CXX11_STATIC_ASSERT -//#undef HAS_CXX11_CSTDINT_H +#define HAS_CXX11_CSTDINT_H -//#undef HAS_CXX11_SHARED_PTR +#define HAS_CXX11_SHARED_PTR #endif From 161835f42bc7b77f3139587adf2e52c0c5eb6f5a Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 29 Dec 2012 22:26:21 +0100 Subject: [PATCH 4/7] Boost is no longer needed if is not found. --- library/PolyVoxCore/CMakeLists.txt | 1 + .../include/PolyVoxCore/Impl/CompilerCapabilities.h | 4 ++-- .../PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h | 13 ++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index f5cb490c..3fd14b8e 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -107,6 +107,7 @@ SET(IMPL_INC_FILES include/PolyVoxCore/Impl/AStarPathfinderImpl.h include/PolyVoxCore/Impl/Block.h include/PolyVoxCore/Impl/Block.inl + include/PolyVoxCore/Impl/CompilerCapabilities.h include/PolyVoxCore/Impl/ErrorHandling.h include/PolyVoxCore/Impl/MarchingCubesTables.h include/PolyVoxCore/Impl/RandomUnitVectors.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h index 2d10b5ff..2bbf6fda 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h @@ -11,9 +11,9 @@ //#define HAS_CXX11_CONSTEXPR -#define HAS_CXX11_STATIC_ASSERT +//#define HAS_CXX11_STATIC_ASSERT -#define HAS_CXX11_CSTDINT_H +//#define HAS_CXX11_CSTDINT_H #define HAS_CXX11_SHARED_PTR diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h index 3724efe4..4500207e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h @@ -101,13 +101,12 @@ freely, subject to the following restrictions: #if defined(HAS_CXX11_CSTDINT_H) #include #else - #include - using boost::int8_t; - using boost::int16_t; - using boost::int32_t; - using boost::uint8_t; - using boost::uint16_t; - using boost::uint32_t; + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; #endif #if defined(HAS_CXX11_SHARED_PTR) From 9273094ebd9e44bf1f5eb1d1187c8978d9962b06 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 29 Dec 2012 22:56:15 +0100 Subject: [PATCH 5/7] Added config.h to control exceptions and asserts. --- library/PolyVoxCore/CMakeLists.txt | 1 + .../include/PolyVoxCore/Impl/Config.h | 30 +++++++++++++++++++ .../include/PolyVoxCore/Impl/ErrorHandling.h | 5 ++-- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 3fd14b8e..b0304218 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -108,6 +108,7 @@ SET(IMPL_INC_FILES include/PolyVoxCore/Impl/Block.h include/PolyVoxCore/Impl/Block.inl include/PolyVoxCore/Impl/CompilerCapabilities.h + include/PolyVoxCore/Impl/Config.h include/PolyVoxCore/Impl/ErrorHandling.h include/PolyVoxCore/Impl/MarchingCubesTables.h include/PolyVoxCore/Impl/RandomUnitVectors.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h new file mode 100644 index 00000000..e97e27af --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h @@ -0,0 +1,30 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_Config_H__ +#define __PolyVox_Config_H__ + +#define POLYVOX_ASSERTS_ENABLED +#define POLYVOX_THROW_ENABLED + +#endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index d3ef8b49..8d434c9a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -24,13 +24,12 @@ freely, subject to the following restrictions: #ifndef __PolyVox_ErrorHandling_H__ #define __PolyVox_ErrorHandling_H__ +#include "PolyVoxCore/Impl/Config.h" + #include //For std::exit #include //For std::cerr #include -#define POLYVOX_ASSERTS_ENABLED -//#define POLYVOX_THROW_ENABLED - #if defined(_MSC_VER) #define POLYVOX_HALT() __debugbreak() #else From 0c78d97ba5ee55cb35a54e4d31cff97e5f66a88b Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 29 Dec 2012 23:16:29 +0100 Subject: [PATCH 6/7] Better defaults for compiler capabilities. --- .../PolyVoxCore/Impl/CompilerCapabilities.h | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h index 2bbf6fda..074c3555 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h @@ -1,20 +1,23 @@ /* - * This file provides the default compiler capabilities for for Visual Studio. - * On other compilers CMake will detect which features are available and create - * a file like this. - * - * To Enable these features in Visual Studio, define the variables in this file. -*/ + * This file describes the capabilities of the C++ compiler and is used to determine which features to enable in PolyVox. + * It assumes that if the compiler is from VS2008 or earlier then no C++11 is present, otherwise it assumes full support + * is present. + * + * Not that this file is usually overwritten by CMake which does careful tests of the true compiler capabilities. However, + * we provide this default file so that CMake is not actually required for users of PolyVox and they can instead just drop + * PolyVox code into their project/makefile if they prefer. + */ #ifndef __PolyVox_CompilerCapabilities_H__ #define __PolyVox_CompilerCapabilities_H__ -//#define HAS_CXX11_CONSTEXPR - -//#define HAS_CXX11_STATIC_ASSERT - -//#define HAS_CXX11_CSTDINT_H - -#define HAS_CXX11_SHARED_PTR +// If we are not using Visual Studio (or we are but it +// is a recent version) then assume support for these. +#if !defined(_MSC_VER) || (_MSC_VER >= 1600) + #define HAS_CXX11_CONSTEXPR + #define HAS_CXX11_STATIC_ASSERT + #define HAS_CXX11_CSTDINT_H + #define HAS_CXX11_SHARED_PTR +#endif #endif From d5b03cdbc3ccbfc28d0e0fa971602d2b588b3627 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 29 Dec 2012 23:29:28 +0100 Subject: [PATCH 7/7] Made use of POLYVOX_THROW where appropriate. --- .../PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl | 4 +++- library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl | 4 +++- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 6 ++++-- library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl | 8 +++++--- .../PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl | 4 +++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl index 26c5c398..f01bff38 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/ErrorHandling.h" + namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// @@ -159,7 +161,7 @@ namespace PolyVox if((openNodes.empty()) || (openNodes.getFirst() != endNode)) { //In this case we failed to find a valid path. - throw std::runtime_error("No path found"); + POLYVOX_THROW(std::runtime_error, "No path found"); } else { diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 8927816c..cb597236 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -21,7 +21,9 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/ErrorHandling.h" #include "PolyVoxCore/Impl/Utility.h" + #include "PolyVoxCore/Vector.h" #include @@ -130,7 +132,7 @@ namespace PolyVox //Release mode validation if(!isPowerOf2(uSideLength)) { - throw std::invalid_argument("Block side length must be a power of two."); + POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); } //Compute the side length diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index c78abd20..fc476908 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/ErrorHandling.h" + //Included here rather than in the .h because it refers to LargeVolume (avoids forward declaration) #include "PolyVoxCore/ConstVolumeProxy.h" @@ -471,11 +473,11 @@ namespace PolyVox //Release mode validation if(uBlockSideLength == 0) { - throw std::invalid_argument("Block side length cannot be zero."); + POLYVOX_THROW(std::invalid_argument, "Block side length cannot be zero."); } if(!isPowerOf2(uBlockSideLength)) { - throw std::invalid_argument("Block side length must be a power of two."); + POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); } m_uTimestamper = 0; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 62b48b4a..a818d70b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/ErrorHandling.h" + namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// @@ -253,15 +255,15 @@ namespace PolyVox //Release mode validation if(uBlockSideLength < 8) { - throw std::invalid_argument("Block side length should be at least 8"); + POLYVOX_THROW(std::invalid_argument, "Block side length should be at least 8"); } if(uBlockSideLength > 256) { - throw std::invalid_argument("Block side length should not be more than 256"); + POLYVOX_THROW(std::invalid_argument, "Block side length should not be more than 256"); } if(!isPowerOf2(uBlockSideLength)) { - throw std::invalid_argument("Block side length must be a power of two."); + POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); } this->m_regValidRegion = regValidRegion; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl index 03e8c687..e603ff81 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/ErrorHandling.h" + namespace PolyVox { template @@ -109,7 +111,7 @@ namespace PolyVox //Release mode validation if(!isPowerOf2(uSideLength)) { - throw std::invalid_argument("Block side length must be a power of two."); + POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); } //Compute the side length