mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 23:33:26 +02:00
Get rid of the log calls entirely; use the same code that we use for the ID
streamer.
This commit is contained in:
parent
37382304f7
commit
fd2893bf6d
1 changed files with 12 additions and 8 deletions
|
@ -47,11 +47,19 @@ IDStreamer::IDStreamer(Bitstream& stream) :
|
|||
_bits(1) {
|
||||
}
|
||||
|
||||
void IDStreamer::setBitsFromValue(int value) {
|
||||
_bits = 1;
|
||||
while (value >= (1 << _bits) - 1) {
|
||||
_bits++;
|
||||
static int getBitsForHighestValue(int highestValue) {
|
||||
// if this turns out to be a bottleneck, there are fancier ways to do it (get the position of the highest set bit):
|
||||
// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
|
||||
int bits = 0;
|
||||
while (highestValue != 0) {
|
||||
bits++;
|
||||
highestValue >>= 1;
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
void IDStreamer::setBitsFromValue(int value) {
|
||||
_bits = getBitsForHighestValue(value + 1);
|
||||
}
|
||||
|
||||
IDStreamer& IDStreamer::operator<<(int value) {
|
||||
|
@ -719,10 +727,6 @@ Bitstream& Bitstream::operator<(const TypeStreamer* streamer) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
static int getBitsForHighestValue(int highestValue) {
|
||||
return (highestValue == 0) ? 0 : 1 + (int)(log((double)highestValue) / log(2.0));
|
||||
}
|
||||
|
||||
Bitstream& Bitstream::operator>(TypeReader& reader) {
|
||||
QByteArray typeName;
|
||||
*this >> typeName;
|
||||
|
|
Loading…
Reference in a new issue