This commit is contained in:
2025-07-12 03:27:20 +06:00
parent dbe2e2c33c
commit 9c64b893cf
21 changed files with 408 additions and 182 deletions

View File

@@ -1,6 +1,10 @@
#include "Abstract.hpp"
#include <algorithm>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <cstddef>
#include <sstream>
namespace LV {
@@ -99,7 +103,7 @@ CompressedVoxels compressVoxels_byte(const std::vector<VoxelCube>& voxels) {
}
}
return {compressed, defines};
return {compressLinear(compressed), defines};
}
CompressedVoxels compressVoxels_bit(const std::vector<VoxelCube>& voxels) {
@@ -245,7 +249,7 @@ CompressedVoxels compressVoxels_bit(const std::vector<VoxelCube>& voxels) {
for(size_t iter = 0; iter < buff.size(); iter++)
compressed[iter / 8] |= (buff[iter] << (iter % 8));
return {compressed, profile};
return {compressLinear(compressed), profile};
}
CompressedVoxels compressVoxels(const std::vector<VoxelCube>& voxels, bool fast) {
@@ -419,10 +423,11 @@ std::vector<VoxelCube> unCompressVoxels_bit(const std::u8string& compressed) {
}
std::vector<VoxelCube> unCompressVoxels(const std::u8string& compressed) {
if(compressed.front())
return unCompressVoxels_byte(compressed);
const std::u8string& next = unCompressLinear(compressed);
if(next.front())
return unCompressVoxels_byte(next);
else
return unCompressVoxels_bit(compressed);
return unCompressVoxels_bit(next);
}
@@ -510,7 +515,7 @@ CompressedNodes compressNodes_byte(const Node* nodes) {
profiles.shrink_to_fit();
return {compressed, profiles};
return {compressLinear(compressed), profiles};
}
CompressedNodes compressNodes_bit(const Node* nodes) {
@@ -628,15 +633,33 @@ CompressedNodes compressNodes_bit(const Node* nodes) {
}
}
return {compressed, profiles};
return {compressLinear(compressed), profiles};
}
CompressedNodes compressNodes(const Node* nodes, bool fast) {
if(fast)
return compressNodes_byte(nodes);
else
return compressNodes_bit(nodes);
std::u8string data(16*16*16*sizeof(Node), '\0');
const char8_t *ptr = (const char8_t*) nodes;
std::copy(ptr, ptr+16*16*16*4, data.data());
std::vector<DefNodeId_t> node(16*16*16);
for(int iter = 0; iter < 16*16*16; iter++) {
node[iter] = nodes[iter].NodeId;
}
{
std::sort(node.begin(), node.end());
auto last = std::unique(node.begin(), node.end());
node.erase(last, node.end());
node.shrink_to_fit();
}
return {compressLinear(data), std::move(node)};
// if(fast)
// return compressNodes_byte(nodes);
// else
// return compressNodes_bit(nodes);
}
void unCompressNodes_byte(const std::u8string& compressed, Node* ptr) {
@@ -761,10 +784,44 @@ void unCompressNodes_bit(const std::u8string& compressed, Node* ptr) {
}
void unCompressNodes(const std::u8string& compressed, Node* ptr) {
if(compressed.front())
return unCompressNodes_byte(compressed, ptr);
else
return unCompressNodes_bit(compressed, ptr);
const std::u8string& next = unCompressLinear(compressed);
const Node *lPtr = (const Node*) next.data();
std::copy(lPtr, lPtr+16*16*16, ptr);
// if(next.front())
// return unCompressNodes_byte(next, ptr);
// else
// return unCompressNodes_bit(next, ptr);
}
std::u8string compressLinear(const std::u8string& data) {
std::stringstream in;
in.write((const char*) data.data(), data.size());
boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
out.push(boost::iostreams::zlib_compressor());
out.push(in);
std::stringstream compressed;
boost::iostreams::copy(out, compressed);
std::string outString = compressed.str();
return *(std::u8string*) &outString;
}
std::u8string unCompressLinear(const std::u8string& data) {
std::stringstream in;
in.write((const char*) data.data(), data.size());
boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
out.push(boost::iostreams::zlib_decompressor());
out.push(in);
std::stringstream compressed;
boost::iostreams::copy(out, compressed);
std::string outString = compressed.str();
return *(std::u8string*) &outString;
}
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include "Common/Net.hpp"
#include "TOSLib.hpp"
#include <algorithm>
#include <cstdint>
#include <glm/ext.hpp>
@@ -90,7 +91,7 @@ public:
using U = std::make_unsigned_t<T>;
for(size_t iter = 0; iter < N; iter++) {
out |= Pack(U(get(iter))) << BitsPerComponent*iter;
out |= Pack(U(get(iter)) & U((Pack(1) << BitsPerComponent)-1)) << BitsPerComponent*iter;
}
return out;
@@ -100,7 +101,7 @@ public:
using U = std::make_unsigned_t<T>;
for(size_t iter = 0; iter < N; iter++) {
set(iter, U((pack >> BitsPerComponent*iter) & ((Pack(1) << BitsPerComponent)-1)));
set(iter, T(U((pack >> BitsPerComponent*iter) & U((Pack(1) << BitsPerComponent)-1))));
}
}
@@ -481,6 +482,9 @@ struct CompressedNodes {
CompressedNodes compressNodes(const Node* nodes, bool fast = true);
void unCompressNodes(const std::u8string& compressed, Node* ptr);
std::u8string compressLinear(const std::u8string& data);
std::u8string unCompressLinear(const std::u8string& data);
}

View File

@@ -62,6 +62,7 @@ struct PacketQuat {
0 -
1 -
2 - Новая позиция камеры WorldId_c+ObjectPos+PacketQuat
3 - Изменение блока
*/
@@ -74,7 +75,8 @@ enum struct L1 : uint8_t {
enum struct L2System : uint8_t {
InitEnd,
Disconnect,
Test_CAM_PYR_POS
Test_CAM_PYR_POS,
BlockChange
};
}