diff --git a/modules/network_synchronizer/SCsub b/modules/network_synchronizer/SCsub index 257431408..91df89d6e 100644 --- a/modules/network_synchronizer/SCsub +++ b/modules/network_synchronizer/SCsub @@ -5,4 +5,8 @@ Import("env_modules") env_network_synchronizer = env_modules.Clone() -env_network_synchronizer.add_source_files(env.modules_sources, "*.cpp") +#env_network_synchronizer.add_source_files(env.modules_sources, "*.cpp") + +env_network_synchronizer.add_source_files(env.modules_sources, "bit_array.cpp") + +env_network_synchronizer.add_source_files(env.modules_sources, "register_types.cpp") \ No newline at end of file diff --git a/modules/network_synchronizer/bit_array.cpp b/modules/network_synchronizer/bit_array.cpp index f22a1da0c..9600d7dd8 100644 --- a/modules/network_synchronizer/bit_array.cpp +++ b/modules/network_synchronizer/bit_array.cpp @@ -35,13 +35,13 @@ #include "bit_array.h" #include "core/math/math_funcs.h" -#include "core/string/ustring.h" +#include "core/ustring.h" BitArray::BitArray(uint32_t p_initial_size_in_bit) { resize_in_bits(p_initial_size_in_bit); } -BitArray::BitArray(const Vector &p_bytes) : +BitArray::BitArray(const PoolByteArray &p_bytes) : bytes(p_bytes) { } @@ -73,6 +73,8 @@ void BitArray::store_bits(int p_bit_offset, uint64_t p_value, int p_bits) { int bit_offset = p_bit_offset; uint64_t val = p_value; + PoolByteArray::Write w = bytes.write(); + while (bits > 0) { const int bits_to_write = MIN(bits, 8 - bit_offset % 8); const int bits_to_jump = bit_offset % 8; @@ -84,16 +86,18 @@ void BitArray::store_bits(int p_bit_offset, uint64_t p_value, int p_bits) { uint8_t byte_clear = 0xFF >> bits_to_jump; byte_clear = byte_clear << (bits_to_jump + bits_to_skip); byte_clear = ~(byte_clear >> bits_to_skip); - bytes.write[byte_offset] &= byte_clear; + w[byte_offset] &= byte_clear; // Now we can continue to write bits - bytes.write[byte_offset] |= (val & 0xFF) << bits_to_jump; + w[byte_offset] |= (val & 0xFF) << bits_to_jump; bits -= bits_to_write; bit_offset += bits_to_write; val >>= bits_to_write; } + + w.release(); } uint64_t BitArray::read_bits(int p_bit_offset, int p_bits) const { @@ -104,7 +108,8 @@ uint64_t BitArray::read_bits(int p_bit_offset, int p_bits) const { int bit_offset = p_bit_offset; uint64_t val = 0; - const uint8_t *bytes_ptr = bytes.ptr(); + PoolByteArray::Read r = bytes.read(); + const uint8_t *bytes_ptr = r.ptr(); int val_bits_to_jump = 0; while (bits > 0) { @@ -124,11 +129,15 @@ uint64_t BitArray::read_bits(int p_bit_offset, int p_bits) const { val_bits_to_jump += bits_to_read; } + r.release(); + return val; } void BitArray::zero() { if (bytes.size() > 0) { - memset(bytes.ptrw(), 0, sizeof(uint8_t) * bytes.size()); + PoolByteArray::Write w = bytes.write(); + memset(w.ptr(), 0, sizeof(uint8_t) * bytes.size()); + w.release(); } } diff --git a/modules/network_synchronizer/bit_array.h b/modules/network_synchronizer/bit_array.h index f812936eb..53bfff1cf 100644 --- a/modules/network_synchronizer/bit_array.h +++ b/modules/network_synchronizer/bit_array.h @@ -1,3 +1,6 @@ +#ifndef BITARRAY_H +#define BITARRAY_H + /*************************************************************************/ /* bit_array.h */ /*************************************************************************/ @@ -32,24 +35,21 @@ @author AndreaCatania */ -#include "core/vector.h" - -#ifndef BITARRAY_H -#define BITARRAY_H +#include "core/variant.h" class BitArray { - Vector bytes; + PoolByteArray bytes; public: BitArray() = default; BitArray(uint32_t p_initial_size_in_bit); - BitArray(const Vector &p_bytes); + BitArray(const PoolByteArray &p_bytes); - const Vector &get_bytes() const { + const PoolByteArray &get_bytes() const { return bytes; } - Vector &get_bytes_mut() { + PoolByteArray &get_bytes_mut() { return bytes; } diff --git a/modules/network_synchronizer/config.py b/modules/network_synchronizer/config.py index 249c3051f..a0209b450 100644 --- a/modules/network_synchronizer/config.py +++ b/modules/network_synchronizer/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return False + return True def configure(env): @@ -7,12 +7,14 @@ def configure(env): def get_doc_classes(): - return [] + return [ + #"BitArray", + ] def get_doc_path(): - return "" + return "doc_classes" def is_enabled(): - return False + return True diff --git a/modules/network_synchronizer/class_docs/DataBuffer.xml b/modules/network_synchronizer/doc_classes/DataBuffer.xml similarity index 100% rename from modules/network_synchronizer/class_docs/DataBuffer.xml rename to modules/network_synchronizer/doc_classes/DataBuffer.xml diff --git a/modules/network_synchronizer/class_docs/Interpolator.xml b/modules/network_synchronizer/doc_classes/Interpolator.xml similarity index 100% rename from modules/network_synchronizer/class_docs/Interpolator.xml rename to modules/network_synchronizer/doc_classes/Interpolator.xml diff --git a/modules/network_synchronizer/class_docs/NetworkedController.xml b/modules/network_synchronizer/doc_classes/NetworkedController.xml similarity index 100% rename from modules/network_synchronizer/class_docs/NetworkedController.xml rename to modules/network_synchronizer/doc_classes/NetworkedController.xml diff --git a/modules/network_synchronizer/class_docs/SceneDiff.xml b/modules/network_synchronizer/doc_classes/SceneDiff.xml similarity index 100% rename from modules/network_synchronizer/class_docs/SceneDiff.xml rename to modules/network_synchronizer/doc_classes/SceneDiff.xml diff --git a/modules/network_synchronizer/class_docs/SceneSynchronizer.xml b/modules/network_synchronizer/doc_classes/SceneSynchronizer.xml similarity index 100% rename from modules/network_synchronizer/class_docs/SceneSynchronizer.xml rename to modules/network_synchronizer/doc_classes/SceneSynchronizer.xml diff --git a/modules/network_synchronizer/register_types.cpp b/modules/network_synchronizer/register_types.cpp index 1b591b440..30c2aab7d 100644 --- a/modules/network_synchronizer/register_types.cpp +++ b/modules/network_synchronizer/register_types.cpp @@ -34,21 +34,24 @@ #include "register_types.h" +/* #include "data_buffer.h" #include "interpolator.h" #include "networked_controller.h" #include "scene_diff.h" #include "scene_synchronizer.h" +*/ void register_network_synchronizer_types() { + /* GDREGISTER_CLASS(DataBuffer); GDREGISTER_CLASS(SceneDiff); GDREGISTER_CLASS(Interpolator); GDREGISTER_CLASS(NetworkedController); GDREGISTER_CLASS(SceneSynchronizer); - - GLOBAL_DEF("NetworkSynchronizer/debug_server_speedup", false); - GLOBAL_DEF("NetworkSynchronizer/debug_doll_speedup", false); +*/ +// GLOBAL_DEF("NetworkSynchronizer/debug_server_speedup", false); +// GLOBAL_DEF("NetworkSynchronizer/debug_doll_speedup", false); } void unregister_network_synchronizer_types() {