mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Add 64-bit versions of core power of 2 functions
This commit is contained in:
@@ -415,17 +415,17 @@ class CharBuffer {
|
||||
char stack_buffer[256];
|
||||
|
||||
char *buffer = nullptr;
|
||||
int capacity = 0;
|
||||
int written = 0;
|
||||
int64_t capacity = 0;
|
||||
int64_t written = 0;
|
||||
|
||||
bool grow() {
|
||||
if (vector.resize(next_power_of_2(1 + written)) != OK) {
|
||||
if (vector.resize(next_power_of_2((uint64_t)1 + (uint64_t)written)) != OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffer == stack_buffer) { // first chunk?
|
||||
|
||||
for (int i = 0; i < written; i++) {
|
||||
for (int64_t i = 0; i < written; i++) {
|
||||
vector.write[i] = stack_buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class FileAccessCompressed : public FileAccess {
|
||||
bool writing = false;
|
||||
uint64_t write_pos = 0;
|
||||
uint8_t *write_ptr = nullptr;
|
||||
uint32_t write_buffer_size = 0;
|
||||
uint64_t write_buffer_size = 0;
|
||||
uint64_t write_max = 0;
|
||||
uint32_t block_size = 0;
|
||||
mutable bool read_eof = false;
|
||||
|
||||
@@ -1115,8 +1115,8 @@ bool Image::is_size_po2() const {
|
||||
void Image::resize_to_po2(bool p_square, Interpolation p_interpolation) {
|
||||
ERR_FAIL_COND_MSG(is_compressed(), "Cannot resize in compressed image formats.");
|
||||
|
||||
int w = next_power_of_2(width);
|
||||
int h = next_power_of_2(height);
|
||||
int w = next_power_of_2((uint32_t)width);
|
||||
int h = next_power_of_2((uint32_t)height);
|
||||
if (p_square) {
|
||||
w = h = MAX(w, h);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -200,7 +200,7 @@ Error PacketPeerUDP::bind(int p_port, const IPAddress &p_bind_address, int p_rec
|
||||
_sock->close();
|
||||
return err;
|
||||
}
|
||||
rb.resize(nearest_shift(p_recv_buffer_size));
|
||||
rb.resize(nearest_shift((uint32_t)p_recv_buffer_size));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ Error StreamPeerGZIP::_start(bool p_compress, bool p_is_deflate, int buffer_size
|
||||
ERR_FAIL_COND_V_MSG(buffer_size <= 0, ERR_INVALID_PARAMETER, "Invalid buffer size. It should be a positive integer.");
|
||||
clear();
|
||||
compressing = p_compress;
|
||||
rb.resize(nearest_shift(buffer_size - 1));
|
||||
rb.resize(nearest_shift(uint32_t(buffer_size - 1)));
|
||||
buffer.resize(1024);
|
||||
|
||||
// Create ctx.
|
||||
|
||||
Reference in New Issue
Block a user