From 4934be18f0919b20462cfa1cc7f287b30570c46b Mon Sep 17 00:00:00 2001 From: Koncord Date: Sun, 28 May 2017 14:56:51 +0800 Subject: [PATCH] [General] Add compression flag to RW methods Advantages: and 2 bytes per float value, using huffman algorithm for structures and strings. Disadvantages: bad for performance and precision for float/double variables. --- components/openmw-mp/Packets/BasePacket.hpp | 28 ++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/components/openmw-mp/Packets/BasePacket.hpp b/components/openmw-mp/Packets/BasePacket.hpp index 88d0fa2a3..8c568815f 100644 --- a/components/openmw-mp/Packets/BasePacket.hpp +++ b/components/openmw-mp/Packets/BasePacket.hpp @@ -50,12 +50,22 @@ namespace mwmp } template - void RW(templateType &data, bool write) + void RW(templateType &data, bool write, bool compress = 0) { if (write) - bs->Write(data); + { + if(compress) + bs->WriteCompressed(data); + else + bs->Write(data); + } else - bs->Read(data); + { + if(compress) + bs->ReadCompressed(data); + else + bs->Read(data); + } } void RW(bool &data, bool write) @@ -73,17 +83,23 @@ namespace mwmp } } - void RW(std::string &str, bool write) + void RW(std::string &str, bool write, bool compress = 0) { if (write) { RakNet::RakString rstr(str.c_str()); - bs->Write(rstr); + if(compress) + rstr.SerializeCompressed(bs); + else + bs->Write(rstr); } else { RakNet::RakString rstr; - bs->Read(rstr); + if(compress) + rstr.DeserializeCompressed(bs); + else + bs->Read(rstr); str = rstr.C_String(); } }