Add document for compressed network values
This commit is contained in:
parent
194d7d6419
commit
d8edde34da
@ -88,7 +88,7 @@ private:
|
||||
/** Time left till attachment expires. */
|
||||
int16_t m_ticks_left;
|
||||
|
||||
/** For parachutes only, rounded down to 2 digits for network. */
|
||||
/** For parachutes only, stored in cm/s for networking. */
|
||||
int16_t m_initial_speed;
|
||||
|
||||
/** For zoom-in animation */
|
||||
|
@ -444,7 +444,7 @@ bool Flyable::updateAndDelete(int ticks)
|
||||
|
||||
if(m_has_hit_something) return true;
|
||||
|
||||
// Round down values in network for better synchronization
|
||||
// Round values in network for better synchronization
|
||||
if (NetworkConfig::get()->roundValuesNow())
|
||||
CompressNetworkBody::compress(m_body.get(), m_motion_state.get());
|
||||
// Save the compressed values if done in client
|
||||
|
@ -29,7 +29,8 @@ namespace CompressNetworkBody
|
||||
{
|
||||
using namespace MiniGLM;
|
||||
// ------------------------------------------------------------------------
|
||||
inline void setRoundedDownValues(float x, float y, float z,
|
||||
/** Set body and motion state of bullet object with compressed values. */
|
||||
inline void setCompressedValues(float x, float y, float z,
|
||||
uint32_t compressed_q,
|
||||
short lvx, short lvy, short lvz,
|
||||
short avx, short avy, short avz,
|
||||
@ -49,8 +50,15 @@ namespace CompressNetworkBody
|
||||
body->setInterpolationLinearVelocity(lv);
|
||||
body->setInterpolationAngularVelocity(av);
|
||||
body->updateInertiaTensor();
|
||||
} // setRoundedDownValues
|
||||
} // setCompressedValues
|
||||
// ------------------------------------------------------------------------
|
||||
/** Compress transformation and velocities of bullet object, it will
|
||||
* call MiniGLM::compressQuaternion for compress quaternion of
|
||||
* transformation and convert linear and angular velocities to half floats
|
||||
* it can be used by client to locally round values to make sure client
|
||||
* and server have similar state when saving state if you don't provoide
|
||||
* bns.
|
||||
*/
|
||||
inline void compress(btRigidBody* body, btMotionState* ms,
|
||||
BareNetworkString* bns = NULL)
|
||||
{
|
||||
@ -65,9 +73,9 @@ namespace CompressNetworkBody
|
||||
short avx = toFloat16(body->getAngularVelocity().x());
|
||||
short avy = toFloat16(body->getAngularVelocity().y());
|
||||
short avz = toFloat16(body->getAngularVelocity().z());
|
||||
setRoundedDownValues(x, y, z, compressed_q, lvx, lvy, lvz, avx, avy,
|
||||
setCompressedValues(x, y, z, compressed_q, lvx, lvy, lvz, avx, avy,
|
||||
avz, body, ms);
|
||||
// if bns is null, it's locally compress (for rounding down values)
|
||||
// if bns is null, it's locally compress (for rounding values)
|
||||
if (!bns)
|
||||
return;
|
||||
|
||||
@ -76,6 +84,7 @@ namespace CompressNetworkBody
|
||||
.addUInt16(avx).addUInt16(avy).addUInt16(avz);
|
||||
} // compress
|
||||
// ------------------------------------------------------------------------
|
||||
/* Called during rewind when restoring data from game state. */
|
||||
inline void decompress(const BareNetworkString* bns,
|
||||
btRigidBody* body, btMotionState* ms)
|
||||
{
|
||||
@ -89,7 +98,7 @@ namespace CompressNetworkBody
|
||||
short avx = bns->getUInt16();
|
||||
short avy = bns->getUInt16();
|
||||
short avz = bns->getUInt16();
|
||||
setRoundedDownValues(x, y, z, compressed_q, lvx, lvy, lvz, avx, avy,
|
||||
setCompressedValues(x, y, z, compressed_q, lvx, lvy, lvz, avx, avy,
|
||||
avz, body, ms);
|
||||
} // decompress
|
||||
};
|
||||
|
@ -633,7 +633,7 @@ void PhysicalObject::update(float dt)
|
||||
{
|
||||
if (!m_is_dynamic) return;
|
||||
|
||||
// Round down values in network for better synchronization
|
||||
// Round values in network for better synchronization
|
||||
if (NetworkConfig::get()->roundValuesNow())
|
||||
CompressNetworkBody::compress(m_body, m_motion_state);
|
||||
|
||||
|
@ -568,6 +568,12 @@ namespace MiniGLM
|
||||
return compressVector3(tangent) | 1 << 30;
|
||||
} // quickTangent
|
||||
// ------------------------------------------------------------------------
|
||||
/** Round and save compressed values (optionally) btTransform.
|
||||
* It will round with 2 digits with min / max +/- 2^23 / 100 for origin in
|
||||
* btTransform and call compressQuaternion above to compress the rotation
|
||||
* part, if compressed_data is provided, 3 24 bits and 1 32 bits of
|
||||
* compressed data will be written in an int[4] array.
|
||||
*/
|
||||
inline void compressbtTransform(btTransform& cur_t,
|
||||
int* compressed_data = NULL)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user