#include <CompressedFloat.h>
Public Types | |
enum | { CONVERT_VALUE = (1 << (sizeof(StorageType) << 3)) - 1 } |
Public Member Functions | |
MCORE_INLINE | TCompressedFloat () |
MCORE_INLINE | TCompressedFloat (float value, float minValue, float maxValue) |
MCORE_INLINE | TCompressedFloat (StorageType value) |
MCORE_INLINE void | FromFloat (float value, float minValue, float maxValue) |
MCORE_INLINE void | UnCompress (float *output, float minValue, float maxValue) const |
MCORE_INLINE float | ToFloat (float minValue, float maxValue) const |
Public Attributes | |
StorageType | m_value |
The compressed / packed float class. The class can automatically compresses a float of type 'float' into a float that represents this value inside the 'StorageType' type. An example would be a floating point value (float=float) compressed into a CompressedFloat that stores the value as 8-bit byte. This would reduce the float size from 4 bytes into 1 byte, at the trade of a bit loss in precision and CPU overhead for uncompression into a float again. When used with care, the CPU overhead and precision loss are negligible. During both compression and uncompression you also have to specify the range (minimum and maximum possible values) of the value you want to compress/decompress. If you are dealing with normalized values, the minimum value would be 0, and the maximum value would be +1. When uncompressing (converting back to a float) you have to be sure you use the same minimum and maximum values as when you used to compress it! This is very important! The bigger the range, the more precision loss. There is however no performance impact linked to the range.
MCORE_INLINE TCompressedFloat::TCompressedFloat | ( | ) |
Default constructor. This leaves the member uninitialized, so if you get the uncompressed version, the result is unknown.
MCORE_INLINE TCompressedFloat::TCompressedFloat | ( | float | value, |
float | minValue, | ||
float | maxValue | ||
) |
Constructor. Create a compressed float from an uncompressed one.
value | The floating point value you want to compress. |
minValue | The minimum possible value of the uncompressed floating point value. |
maxValue | The maximum possible value of the uncompressed floating point value. |
MCORE_INLINE TCompressedFloat::TCompressedFloat | ( | StorageType | value | ) |
Constructor. Create a compressed float.
value | The compessed floating point value. |
MCORE_INLINE void TCompressedFloat::FromFloat | ( | float | value, |
float | minValue, | ||
float | maxValue | ||
) |
Create a compressed float from an uncompressed one.
value | The floating point value you want to compress. |
minValue | The minimum possible value of the uncompressed floating point value. |
maxValue | The maximum possible value of the uncompressed floating point value. |
MCORE_INLINE float TCompressedFloat::ToFloat | ( | float | minValue, |
float | maxValue | ||
) | const |
Uncompress this compressed floating point value into an uncompressed float. Please note that the minimum and maximum values you specify are the same as when you created this compressed floating point value or when you for the last time called the FromFloat method.
minValue | The minimum possible value of the uncompressed floating point value. |
maxValue | The maximum possible value of the uncompressed floating point value. |
MCORE_INLINE void TCompressedFloat::UnCompress | ( | float * | output, |
float | minValue, | ||
float | maxValue | ||
) | const |
Uncompress this compressed floating point value into an uncompressed float. Please note that the minimum and maximum values you specify are the same as when you created this compressed floating point value or when you for the last time called the FromFloat method.
output | The uncompressed floating point value to store the result in. |
minValue | The minimum possible value of the uncompressed floating point value. |
maxValue | The maximum possible value of the uncompressed floating point value. |
StorageType MCore::TCompressedFloat< StorageType >::m_value |
The compressed/packed value.