Compress physical object state
This commit is contained in:
parent
5330951842
commit
ef65d70f77
57
src/network/compress_network_body.hpp
Normal file
57
src/network/compress_network_body.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2018 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_COMPRESS_NETWORK_BODY_HPP
|
||||
#define HEADER_COMPRESS_NETWORK_BODY_HPP
|
||||
|
||||
#include "network/network_string.hpp"
|
||||
#include "utils/mini_glm.hpp"
|
||||
|
||||
namespace CompressNetworkBody
|
||||
{
|
||||
using namespace MiniGLM;
|
||||
// ------------------------------------------------------------------------
|
||||
inline void compress(const btTransform& t, const Vec3& lv, const Vec3& av,
|
||||
BareNetworkString* bns)
|
||||
{
|
||||
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()));
|
||||
} // compress
|
||||
// ------------------------------------------------------------------------
|
||||
inline void decompress(const BareNetworkString* bns, btTransform* t,
|
||||
Vec3* lv, Vec3* av)
|
||||
{
|
||||
t->setOrigin(bns->getVec3());
|
||||
t->setRotation(decompressbtQuaternion(bns->getUInt32()));
|
||||
short vec[3];
|
||||
vec[0] = bns->getUInt16();
|
||||
vec[1] = bns->getUInt16();
|
||||
vec[2] = bns->getUInt16();
|
||||
*lv = Vec3(toFloat32(vec[0]), toFloat32(vec[1]), toFloat32(vec[2]));
|
||||
vec[0] = bns->getUInt16();
|
||||
vec[1] = bns->getUInt16();
|
||||
vec[2] = bns->getUInt16();
|
||||
*av = Vec3(toFloat32(vec[0]), toFloat32(vec[1]), toFloat32(vec[2]));
|
||||
} // compress
|
||||
};
|
||||
|
||||
#endif // HEADER_COMPRESS_NETWORK_BODY_HPP
|
@ -28,7 +28,7 @@
|
||||
#include "io/xml_node.hpp"
|
||||
#include "physics/physics.hpp"
|
||||
#include "physics/triangle_mesh.hpp"
|
||||
#include "network/network_string.hpp"
|
||||
#include "network/compress_network_body.hpp"
|
||||
#include "network/rewind_manager.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_object.hpp"
|
||||
@ -816,10 +816,8 @@ BareNetworkString* PhysicalObject::saveState(std::vector<std::string>* ru)
|
||||
m_last_transform = cur_transform;
|
||||
m_last_lv = m_body->getLinearVelocity();
|
||||
m_last_av = m_body->getAngularVelocity();
|
||||
buffer->add(m_last_transform.getOrigin());
|
||||
buffer->add(m_last_transform.getRotation());
|
||||
buffer->add(m_last_lv);
|
||||
buffer->add(m_last_av);
|
||||
CompressNetworkBody::compress(m_last_transform, m_last_lv, m_last_av,
|
||||
buffer);
|
||||
return buffer;
|
||||
} // saveState
|
||||
|
||||
@ -827,10 +825,8 @@ BareNetworkString* PhysicalObject::saveState(std::vector<std::string>* ru)
|
||||
void PhysicalObject::restoreState(BareNetworkString *buffer, int count)
|
||||
{
|
||||
m_no_server_state = false;
|
||||
m_last_transform.setOrigin(buffer->getVec3());
|
||||
m_last_transform.setRotation(buffer->getQuat());
|
||||
m_last_lv = buffer->getVec3();
|
||||
m_last_av = buffer->getVec3();
|
||||
CompressNetworkBody::decompress(buffer, &m_last_transform, &m_last_lv,
|
||||
&m_last_av);
|
||||
|
||||
m_body->setWorldTransform(m_last_transform);
|
||||
m_motion_state->setWorldTransform(m_last_transform);
|
||||
|
Loading…
Reference in New Issue
Block a user