Use hex values for 24bit compression

This commit is contained in:
Benau 2019-03-25 23:46:18 +08:00
parent 4670c9a5e9
commit 220f5e6e4c
3 changed files with 11 additions and 11 deletions

View File

@ -37,18 +37,18 @@ void NetworkString::unitTesting()
s.setSynchronous(false);
assert(!s.isSynchronous());
// 24bit saving, min -8388608, max 8388607
int min = -8388608;
// 24bit saving, min (-2^23) -0x800000, max (2^23 - 1) 0x7fffff
int min = -0x800000;
BareNetworkString smin;
smin.addInt24(min);
min = smin.getInt24();
assert(min == -8388608);
assert(min == -0x800000);
int max = 8388607;
int max = 0x7fffff;
BareNetworkString smax;
smax.addInt24(max);
max = smax.getInt24();
assert(max == 8388607);
assert(max == 0x7fffff);
// Check log message format
BareNetworkString slog(28);

View File

@ -254,7 +254,7 @@ public:
/** Adds signed 24 bit integer. */
BareNetworkString& addInt24(const int value)
{
uint32_t combined = (uint32_t)value & 16777215;
uint32_t combined = (uint32_t)value & 0xffffff;
m_buffer.push_back((combined >> 16) & 0xff);
m_buffer.push_back((combined >> 8) & 0xff);
m_buffer.push_back(combined & 0xff);
@ -348,8 +348,8 @@ public:
inline int getInt24() const
{
uint32_t combined = get<uint32_t, 3>();
if (combined & 8388608)
return (16777216 - (int)combined) * -1;
if (combined & 0x800000)
return (0x1000000 - (int)combined) * -1;
else
return (int)combined;
}

View File

@ -574,9 +574,9 @@ namespace MiniGLM
int x = (int)(cur_t.getOrigin().x() * 100.0f);
int y = (int)(cur_t.getOrigin().y() * 100.0f);
int z = (int)(cur_t.getOrigin().z() * 100.0f);
x = core::clamp(x, -8388608, 8388607);
y = core::clamp(y, -8388608, 8388607);
z = core::clamp(z, -8388608, 8388607);
x = core::clamp(x, -0x800000, 0x7fffff);
y = core::clamp(y, -0x800000, 0x7fffff);
z = core::clamp(z, -0x800000, 0x7fffff);
uint32_t compressed_q = compressQuaternion(cur_t.getRotation());
cur_t.setOrigin(btVector3(
(float)x / 100.0f,