From a9c15f85469bfe17d18546277dbc384724058510 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 7 Oct 2011 22:17:39 +0100 Subject: [PATCH 1/3] Changes to type usage for Density and Material classes. --- .../PolyVoxCore/include/PolyVoxCore/Density.h | 20 +++++++++---------- .../include/PolyVoxCore/Material.h | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index da0d14c7..a5e74616 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -42,12 +42,12 @@ namespace PolyVox /// /// \sa Material, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// - template + template class Density { public: Density() : m_uDensity(0) {} - Density(Type uDensity) : m_uDensity(uDensity) {} + Density(DensityType uDensity) : m_uDensity(uDensity) {} bool operator==(const Density& rhs) const throw() { @@ -59,18 +59,18 @@ namespace PolyVox return !(*this == rhs); } - Type getDensity() const throw() { return m_uDensity; } - Type getMaterial() const throw() { return 1; } + DensityType getDensity() const throw() { return m_uDensity; } + uint32_t getMaterial() const throw() { return 1; } - void setDensity(Type uDensity) { m_uDensity = uDensity; } - void setMaterial(Type uMaterial) { assert(false); } //Cannot set material on voxel of type Density + void setDensity(DensityType uDensity) { m_uDensity = uDensity; } + void setMaterial(uint32_t uMaterial) { assert(false); } //Cannot set material on voxel of type Density - static Type getMaxDensity() throw() { return (0x01 << (sizeof(Type) * 8)) - 1; } - static Type getMinDensity() throw() { return 0; } - static Type getThreshold() throw() {return 0x01 << ((sizeof(Type) * 8) - 1);} + static DensityType getMaxDensity() throw() { return (0x01 << (sizeof(DensityType) * 8)) - 1; } + static DensityType getMinDensity() throw() { return 0; } + static DensityType getThreshold() throw() {return 0x01 << ((sizeof(DensityType) * 8) - 1);} private: - Type m_uDensity; + DensityType m_uDensity; }; typedef Density Density8; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 445961b0..09d978e9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -43,12 +43,12 @@ namespace PolyVox /// /// \sa Density, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// - template + template class Material { public: Material() : m_uMaterial(0) {} - Material(Type uMaterial) : m_uMaterial(uMaterial) {} + Material(MaterialType uMaterial) : m_uMaterial(uMaterial) {} bool operator==(const Material& rhs) const throw() { @@ -60,7 +60,7 @@ namespace PolyVox return !(*this == rhs); } - Type getDensity() const throw() + uint32_t getDensity() const throw() { //We don't actually have a density, so make one up based on the material. if(m_uMaterial == 0) @@ -73,17 +73,17 @@ namespace PolyVox } } - Type getMaterial() const throw() { return m_uMaterial; } + MaterialType getMaterial() const throw() { return m_uMaterial; } - void setDensity(Type /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material - void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; } + void setDensity(uint32_t /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material + void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } - static Type getMaxDensity() throw() { return 2; } - static Type getMinDensity() throw() { return 0; } - static Type getThreshold() throw() { return 1; } + static uint32_t getMaxDensity() throw() { return 2; } + static uint32_t getMinDensity() throw() { return 0; } + static uint32_t getThreshold() throw() { return 1; } private: - Type m_uMaterial; + MaterialType m_uMaterial; }; typedef Material Material8; From cf222acd5dfee2849965fb7117d0b50d40d339fa Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 9 Oct 2011 18:45:22 +0100 Subject: [PATCH 2/3] Better way of calculating min and max densities. --- library/PolyVoxCore/include/PolyVoxCore/Density.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index a5e74616..e4fbc6e5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -65,9 +65,9 @@ namespace PolyVox void setDensity(DensityType uDensity) { m_uDensity = uDensity; } void setMaterial(uint32_t uMaterial) { assert(false); } //Cannot set material on voxel of type Density - static DensityType getMaxDensity() throw() { return (0x01 << (sizeof(DensityType) * 8)) - 1; } - static DensityType getMinDensity() throw() { return 0; } - static DensityType getThreshold() throw() {return 0x01 << ((sizeof(DensityType) * 8) - 1);} + static DensityType getMaxDensity() throw() { return (std::numeric_limits::max)(); } + static DensityType getMinDensity() throw() { return (std::numeric_limits::min)(); } + static DensityType getThreshold() throw() { return (std::numeric_limits::max)() / 2; } private: DensityType m_uDensity; From 9f8c8c1da2bcc4037093655ecd934d205c8692ca Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Mon, 10 Oct 2011 17:32:01 +0200 Subject: [PATCH 3/3] Add include for numeric_limits<> --- library/PolyVoxCore/include/PolyVoxCore/Density.h | 1 + 1 file changed, 1 insertion(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index e4fbc6e5..82aab7b4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -27,6 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxImpl/TypeDef.h" #include +#include namespace PolyVox {