1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-14 13:41:12 +00:00

Add 64-bit versions of core power of 2 functions

This commit is contained in:
Aaron Franke
2025-05-19 09:53:53 -07:00
parent 64b09905c7
commit f6f1df7d73
25 changed files with 161 additions and 124 deletions

View File

@@ -38,7 +38,7 @@
void PacketPeer::set_encode_buffer_max_size(int p_max_size) {
ERR_FAIL_COND_MSG(p_max_size < 1024, "Max encode buffer must be at least 1024 bytes");
ERR_FAIL_COND_MSG(p_max_size > 256 * 1024 * 1024, "Max encode buffer cannot exceed 256 MiB");
encode_buffer_max_size = next_power_of_2(p_max_size);
encode_buffer_max_size = next_power_of_2((uint32_t)p_max_size);
encode_buffer.clear();
}
@@ -103,7 +103,7 @@ Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) {
if (unlikely(encode_buffer.size() < len)) {
encode_buffer.resize(0); // Avoid realloc
encode_buffer.resize(next_power_of_2(len));
encode_buffer.resize(next_power_of_2((uint32_t)len));
}
uint8_t *w = encode_buffer.ptrw();
@@ -301,8 +301,8 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
ERR_FAIL_COND_MSG(p_max_size < 0, "Max size of input buffer size cannot be smaller than 0.");
// WARNING: May lose packets.
ERR_FAIL_COND_MSG(ring_buffer.data_left(), "Buffer in use, resizing would cause loss of data.");
ring_buffer.resize(nearest_shift(next_power_of_2(p_max_size + 4)) - 1);
input_buffer.resize(next_power_of_2(p_max_size + 4));
ring_buffer.resize(nearest_shift(next_power_of_2((uint32_t)p_max_size + (uint32_t)4)) - 1);
input_buffer.resize(next_power_of_2((uint32_t)p_max_size + (uint32_t)4));
}
int PacketPeerStream::get_input_buffer_max_size() const {
@@ -310,7 +310,7 @@ int PacketPeerStream::get_input_buffer_max_size() const {
}
void PacketPeerStream::set_output_buffer_max_size(int p_max_size) {
output_buffer.resize(next_power_of_2(p_max_size + 4));
output_buffer.resize(next_power_of_2((uint32_t)p_max_size + (uint32_t)4));
}
int PacketPeerStream::get_output_buffer_max_size() const {