Save the uncompressed physics values to objects in server
This commit is contained in:
parent
7538f36bed
commit
05f5663888
@ -599,7 +599,8 @@ BareNetworkString* Flyable::saveState(std::vector<std::string>* ru)
|
||||
ru->push_back(getUniqueIdentity());
|
||||
BareNetworkString *buffer = new BareNetworkString();
|
||||
CompressNetworkBody::compress(m_body->getWorldTransform(),
|
||||
m_body->getLinearVelocity(), m_body->getAngularVelocity(), buffer);
|
||||
m_body->getLinearVelocity(), m_body->getAngularVelocity(), buffer,
|
||||
m_body, m_motion_state);
|
||||
uint16_t hit_and_ticks = (m_has_hit_something ? 1 << 15 : 0) |
|
||||
m_ticks_since_thrown;
|
||||
buffer->addUInt16(hit_and_ticks);
|
||||
|
@ -22,19 +22,40 @@
|
||||
#include "network/network_string.hpp"
|
||||
#include "utils/mini_glm.hpp"
|
||||
|
||||
#include "LinearMath/btMotionState.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
namespace CompressNetworkBody
|
||||
{
|
||||
using namespace MiniGLM;
|
||||
// ------------------------------------------------------------------------
|
||||
inline void compress(const btTransform& t, const Vec3& lv, const Vec3& av,
|
||||
BareNetworkString* bns)
|
||||
inline void compress(btTransform t, const Vec3& lv, const Vec3& av,
|
||||
BareNetworkString* bns, btRigidBody* body,
|
||||
btMotionState* ms)
|
||||
{
|
||||
bns->add(t.getOrigin());
|
||||
bns->addUInt32(compressQuaternion(t.getRotation()));
|
||||
bns->addUInt16(toFloat16(lv.x()))
|
||||
.addUInt16(toFloat16(lv.y())).addUInt16(toFloat16(lv.z()));
|
||||
bns->addUInt16(toFloat16(av.x()))
|
||||
.addUInt16(toFloat16(av.y())).addUInt16(toFloat16(av.z()));
|
||||
uint32_t compressed_q = compressQuaternion(t.getRotation());
|
||||
bns->addUInt32(compressed_q);
|
||||
std::array<short, 3> lvs =
|
||||
{{ toFloat16(lv.x()), toFloat16(lv.y()), toFloat16(lv.z()) }};
|
||||
bns->addUInt16(lvs[0]).addUInt16(lvs[1]).addUInt16(lvs[2]);
|
||||
std::array<short, 3> avs =
|
||||
{{ toFloat16(av.x()), toFloat16(av.y()), toFloat16(av.z()) }};
|
||||
bns->addUInt16(avs[0]).addUInt16(avs[1]).addUInt16(avs[2]);
|
||||
|
||||
btQuaternion uncompressed_q = decompressbtQuaternion(compressed_q);
|
||||
t.setRotation(uncompressed_q);
|
||||
Vec3 uncompressed_lv(toFloat32(lvs[0]), toFloat32(lvs[1]),
|
||||
toFloat32(lvs[2]));
|
||||
Vec3 uncompressed_av(toFloat32(avs[0]), toFloat32(avs[1]),
|
||||
toFloat32(avs[2]));
|
||||
body->setWorldTransform(t);
|
||||
ms->setWorldTransform(t);
|
||||
body->setInterpolationWorldTransform(t);
|
||||
body->setLinearVelocity(uncompressed_lv);
|
||||
body->setAngularVelocity(uncompressed_av);
|
||||
body->setInterpolationLinearVelocity(uncompressed_lv);
|
||||
body->setInterpolationAngularVelocity(uncompressed_av);
|
||||
} // compress
|
||||
// ------------------------------------------------------------------------
|
||||
inline void decompress(const BareNetworkString* bns, btTransform* t,
|
||||
@ -51,7 +72,7 @@ namespace CompressNetworkBody
|
||||
vec[1] = bns->getUInt16();
|
||||
vec[2] = bns->getUInt16();
|
||||
*av = Vec3(toFloat32(vec[0]), toFloat32(vec[1]), toFloat32(vec[2]));
|
||||
} // compress
|
||||
} // decompress
|
||||
};
|
||||
|
||||
#endif // HEADER_COMPRESS_NETWORK_BODY_HPP
|
||||
|
@ -814,9 +814,9 @@ BareNetworkString* PhysicalObject::saveState(std::vector<std::string>* ru)
|
||||
{
|
||||
btTransform cur_transform = m_body->getWorldTransform();
|
||||
if ((cur_transform.getOrigin() - m_last_transform.getOrigin())
|
||||
.length() == 0.0f &&
|
||||
m_body->getLinearVelocity() == m_last_lv &&
|
||||
m_body->getLinearVelocity() == m_last_av)
|
||||
.length() < 0.01f &&
|
||||
(m_body->getLinearVelocity() - m_last_lv).length() < 0.01f &&
|
||||
(m_body->getLinearVelocity() - m_last_av).length() < 0.01f)
|
||||
return nullptr;
|
||||
|
||||
ru->push_back(getUniqueIdentity());
|
||||
@ -825,7 +825,7 @@ BareNetworkString* PhysicalObject::saveState(std::vector<std::string>* ru)
|
||||
m_last_lv = m_body->getLinearVelocity();
|
||||
m_last_av = m_body->getAngularVelocity();
|
||||
CompressNetworkBody::compress(m_last_transform, m_last_lv, m_last_av,
|
||||
buffer);
|
||||
buffer, m_body, m_motion_state);
|
||||
return buffer;
|
||||
} // saveState
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user