mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 05:24:35 +02:00
cleanup
This commit is contained in:
parent
10f7eae7a0
commit
2066dbcec7
2 changed files with 1 additions and 99 deletions
|
@ -10,7 +10,7 @@
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// TODO:
|
// TODO:
|
||||||
// * iterator to enumerate the set values?
|
// * consider adding iterator to enumerate the properties that have been set?
|
||||||
|
|
||||||
#ifndef hifi_PropertyFlags_h
|
#ifndef hifi_PropertyFlags_h
|
||||||
#define hifi_PropertyFlags_h
|
#define hifi_PropertyFlags_h
|
||||||
|
@ -143,7 +143,6 @@ template<typename Enum> inline bool PropertyFlags<Enum>::getHasProperty(Enum fla
|
||||||
const int BITS_PER_BYTE = 8;
|
const int BITS_PER_BYTE = 8;
|
||||||
|
|
||||||
template<typename Enum> inline QByteArray PropertyFlags<Enum>::encode() {
|
template<typename Enum> inline QByteArray PropertyFlags<Enum>::encode() {
|
||||||
const bool debug = false;
|
|
||||||
QByteArray output;
|
QByteArray output;
|
||||||
|
|
||||||
if (_maxFlag < _minFlag) {
|
if (_maxFlag < _minFlag) {
|
||||||
|
@ -151,77 +150,31 @@ template<typename Enum> inline QByteArray PropertyFlags<Enum>::encode() {
|
||||||
return output; // no flags... nothing to encode
|
return output; // no flags... nothing to encode
|
||||||
}
|
}
|
||||||
|
|
||||||
outputBufferBits((const unsigned char*)output.constData(), output.size());
|
|
||||||
|
|
||||||
if (debug) qDebug() << "PropertyFlags<Enum>::encode()";
|
|
||||||
|
|
||||||
// we should size the array to the correct size.
|
// we should size the array to the correct size.
|
||||||
int lengthInBytes = (_maxFlag / (BITS_PER_BYTE - 1)) + 1;
|
int lengthInBytes = (_maxFlag / (BITS_PER_BYTE - 1)) + 1;
|
||||||
|
|
||||||
if (debug) qDebug() << " lengthInBytes=" << lengthInBytes;
|
|
||||||
|
|
||||||
output.fill(0, lengthInBytes);
|
output.fill(0, lengthInBytes);
|
||||||
|
|
||||||
if (debug) outputBufferBits((const unsigned char*)output.constData(), output.size());
|
|
||||||
|
|
||||||
// next pack the number of header bits in, the first N-1 to be set to 1, the last to be set to 0
|
// next pack the number of header bits in, the first N-1 to be set to 1, the last to be set to 0
|
||||||
for(int i = 0; i < lengthInBytes; i++) {
|
for(int i = 0; i < lengthInBytes; i++) {
|
||||||
int outputIndex = i;
|
int outputIndex = i;
|
||||||
if (debug) qDebug() << "outputIndex:" << outputIndex;
|
|
||||||
int bitValue = (i < (lengthInBytes - 1) ? 1 : 0);
|
int bitValue = (i < (lengthInBytes - 1) ? 1 : 0);
|
||||||
|
|
||||||
if (debug) qDebug() << " length code bit["<< outputIndex << "]=" << bitValue;
|
|
||||||
|
|
||||||
char original = output.at(outputIndex / BITS_PER_BYTE);
|
char original = output.at(outputIndex / BITS_PER_BYTE);
|
||||||
int shiftBy = BITS_PER_BYTE - ((outputIndex % BITS_PER_BYTE) + 1);
|
int shiftBy = BITS_PER_BYTE - ((outputIndex % BITS_PER_BYTE) + 1);
|
||||||
char thisBit = ( bitValue << shiftBy);
|
char thisBit = ( bitValue << shiftBy);
|
||||||
|
|
||||||
if (debug) {
|
|
||||||
qDebug() << "bitValue:" << bitValue;
|
|
||||||
qDebug() << "shiftBy:" << shiftBy;
|
|
||||||
qDebug() << "original:";
|
|
||||||
outputBits(original);
|
|
||||||
|
|
||||||
qDebug() << "thisBit:";
|
|
||||||
outputBits(thisBit);
|
|
||||||
}
|
|
||||||
|
|
||||||
output[i / BITS_PER_BYTE] = (original | thisBit);
|
output[i / BITS_PER_BYTE] = (original | thisBit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) outputBufferBits((const unsigned char*)output.constData(), output.size());
|
|
||||||
|
|
||||||
// finally pack the the actual bits from the bit array
|
// finally pack the the actual bits from the bit array
|
||||||
for(int i = lengthInBytes; i < (lengthInBytes + _maxFlag + 1); i++) {
|
for(int i = lengthInBytes; i < (lengthInBytes + _maxFlag + 1); i++) {
|
||||||
int flagIndex = i - lengthInBytes;
|
int flagIndex = i - lengthInBytes;
|
||||||
int outputIndex = i;
|
int outputIndex = i;
|
||||||
if (debug) qDebug() << "flagIndex:" << flagIndex;
|
|
||||||
if (debug) qDebug() << "outputIndex:" << outputIndex;
|
|
||||||
|
|
||||||
|
|
||||||
int bitValue = ( _flags[flagIndex] ? 1 : 0);
|
int bitValue = ( _flags[flagIndex] ? 1 : 0);
|
||||||
|
|
||||||
if (debug) qDebug() << " encode bit["<<outputIndex<<"] = flags bit["<< flagIndex << "]=" << bitValue;
|
|
||||||
|
|
||||||
char original = output.at(outputIndex / BITS_PER_BYTE);
|
char original = output.at(outputIndex / BITS_PER_BYTE);
|
||||||
int shiftBy = BITS_PER_BYTE - ((outputIndex % BITS_PER_BYTE) + 1);
|
int shiftBy = BITS_PER_BYTE - ((outputIndex % BITS_PER_BYTE) + 1);
|
||||||
char thisBit = ( bitValue << shiftBy);
|
char thisBit = ( bitValue << shiftBy);
|
||||||
|
|
||||||
if (debug) {
|
|
||||||
qDebug() << "bitValue:" << bitValue;
|
|
||||||
qDebug() << "shiftBy:" << shiftBy;
|
|
||||||
qDebug() << "original:";
|
|
||||||
outputBits(original);
|
|
||||||
|
|
||||||
qDebug() << "thisBit:";
|
|
||||||
outputBits(thisBit);
|
|
||||||
}
|
|
||||||
|
|
||||||
output[i / BITS_PER_BYTE] = (original | thisBit);
|
output[i / BITS_PER_BYTE] = (original | thisBit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) outputBufferBits((const unsigned char*)output.constData(), output.size());
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,51 +414,5 @@ template<typename Enum> inline void PropertyFlags<Enum>::shinkIfNeeded() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
|
||||||
|
|
||||||
BitArr.resize(8*byteArr.count());
|
|
||||||
for(int i=0; i<byteArr.count(); ++i)
|
|
||||||
for(int b=0; b<8; ++b)
|
|
||||||
bitArr.setBit(i*8+b, byteArr.at(i)&(1<<b));
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Enum>
|
|
||||||
class QFlags
|
|
||||||
{
|
|
||||||
typedef void **Zero;
|
|
||||||
int i;
|
|
||||||
public:
|
|
||||||
typedef Enum enum_type;
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags(const QFlags &f) : i(f.i) {}
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags(Enum f) : i(f) {}
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags(Zero = 0) : i(0) {}
|
|
||||||
inline QFlags(QFlag f) : i(f) {}
|
|
||||||
|
|
||||||
inline QFlags &operator=(const QFlags &f) { i = f.i; return *this; }
|
|
||||||
inline QFlags &operator&=(int mask) { i &= mask; return *this; }
|
|
||||||
inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
|
|
||||||
inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
|
|
||||||
inline QFlags &operator|=(Enum f) { i |= f; return *this; }
|
|
||||||
inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
|
|
||||||
inline QFlags &operator^=(Enum f) { i ^= f; return *this; }
|
|
||||||
|
|
||||||
Q_DECL_CONSTEXPR inline operator int() const { return i; }
|
|
||||||
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags operator|(QFlags f) const { return QFlags(Enum(i | f.i)); }
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const { return QFlags(Enum(i | f)); }
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags operator^(QFlags f) const { return QFlags(Enum(i ^ f.i)); }
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags operator^(Enum f) const { return QFlags(Enum(i ^ f)); }
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const { return QFlags(Enum(i & mask)); }
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const { return QFlags(Enum(i & mask)); }
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags operator&(Enum f) const { return QFlags(Enum(i & f)); }
|
|
||||||
Q_DECL_CONSTEXPR inline QFlags operator~() const { return QFlags(Enum(~i)); }
|
|
||||||
|
|
||||||
Q_DECL_CONSTEXPR inline bool operator!() const { return !i; }
|
|
||||||
|
|
||||||
inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
|
|
||||||
};
|
|
||||||
|
|
||||||
***/
|
|
||||||
|
|
||||||
#endif // hifi_PropertyFlags_h
|
#endif // hifi_PropertyFlags_h
|
||||||
|
|
||||||
|
|
|
@ -352,13 +352,8 @@ void OctreeTests::propertyFlagsTests() {
|
||||||
qDebug() << "propsB... encoded=";
|
qDebug() << "propsB... encoded=";
|
||||||
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
|
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
|
||||||
|
|
||||||
qDebug() << "propsB...";
|
|
||||||
propsB.debugDumpBits();
|
|
||||||
|
|
||||||
qDebug() << "ParticlePropertyFlags propsC = ~propsB;";
|
qDebug() << "ParticlePropertyFlags propsC = ~propsB;";
|
||||||
ParticlePropertyFlags propsC = ~propsB;
|
ParticlePropertyFlags propsC = ~propsB;
|
||||||
qDebug() << "propsC...";
|
|
||||||
propsC.debugDumpBits();
|
|
||||||
|
|
||||||
qDebug() << "propsC.getHasProperty(PARTICLE_PROP_VISIBLE)" << (propsC.getHasProperty(PARTICLE_PROP_VISIBLE))
|
qDebug() << "propsC.getHasProperty(PARTICLE_PROP_VISIBLE)" << (propsC.getHasProperty(PARTICLE_PROP_VISIBLE))
|
||||||
<< "{ expect false }";
|
<< "{ expect false }";
|
||||||
|
|
Loading…
Reference in a new issue