Open 3D Engine EMotionFX Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
MCore::TCompressedFloat< StorageType > Class Template Reference

#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
 

Detailed Description

template<class StorageType>
class MCore::TCompressedFloat< StorageType >

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.

Constructor & Destructor Documentation

◆ TCompressedFloat() [1/3]

template<class StorageType >
MCORE_INLINE TCompressedFloat::TCompressedFloat ( )

Default constructor. This leaves the member uninitialized, so if you get the uncompressed version, the result is unknown.

◆ TCompressedFloat() [2/3]

template<class StorageType >
MCORE_INLINE TCompressedFloat::TCompressedFloat ( float  value,
float  minValue,
float  maxValue 
)

Constructor. Create a compressed float from an uncompressed one.

Parameters
valueThe floating point value you want to compress.
minValueThe minimum possible value of the uncompressed floating point value.
maxValueThe maximum possible value of the uncompressed floating point value.

◆ TCompressedFloat() [3/3]

template<class StorageType >
MCORE_INLINE TCompressedFloat::TCompressedFloat ( StorageType  value)

Constructor. Create a compressed float.

Parameters
valueThe compessed floating point value.

Member Function Documentation

◆ FromFloat()

template<class StorageType >
MCORE_INLINE void TCompressedFloat::FromFloat ( float  value,
float  minValue,
float  maxValue 
)

Create a compressed float from an uncompressed one.

Parameters
valueThe floating point value you want to compress.
minValueThe minimum possible value of the uncompressed floating point value.
maxValueThe maximum possible value of the uncompressed floating point value.

◆ ToFloat()

template<class StorageType >
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.

Parameters
minValueThe minimum possible value of the uncompressed floating point value.
maxValueThe maximum possible value of the uncompressed floating point value.
Returns
The uncompressed version of this floating point value.

◆ UnCompress()

template<class StorageType >
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.

Parameters
outputThe uncompressed floating point value to store the result in.
minValueThe minimum possible value of the uncompressed floating point value.
maxValueThe maximum possible value of the uncompressed floating point value.

Member Data Documentation

◆ m_value

template<class StorageType >
StorageType MCore::TCompressedFloat< StorageType >::m_value

The compressed/packed value.


The documentation for this class was generated from the following files: