feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -30,8 +30,6 @@
|
|||
|
||||
#include "file_access_compressed.h"
|
||||
|
||||
#include "core/string/print_string.h"
|
||||
|
||||
void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, uint32_t p_block_size) {
|
||||
magic = p_magic.ascii().get_data();
|
||||
magic = (magic + " ").substr(0, 4);
|
||||
|
|
@ -40,25 +38,13 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_
|
|||
block_size = p_block_size;
|
||||
}
|
||||
|
||||
#define WRITE_FIT(m_bytes) \
|
||||
{ \
|
||||
if (write_pos + (m_bytes) > write_max) { \
|
||||
write_max = write_pos + (m_bytes); \
|
||||
} \
|
||||
if (write_max > write_buffer_size) { \
|
||||
write_buffer_size = next_power_of_2(write_max); \
|
||||
buffer.resize(write_buffer_size); \
|
||||
write_ptr = buffer.ptrw(); \
|
||||
} \
|
||||
}
|
||||
|
||||
Error FileAccessCompressed::open_after_magic(Ref<FileAccess> p_base) {
|
||||
f = p_base;
|
||||
cmode = (Compression::Mode)f->get_32();
|
||||
block_size = f->get_32();
|
||||
if (block_size == 0) {
|
||||
f.unref();
|
||||
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Can't open compressed file '" + p_base->get_path() + "' with block size 0, it is corrupted.");
|
||||
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, vformat("Can't open compressed file '%s' with block size 0, it is corrupted.", p_base->get_path()));
|
||||
}
|
||||
read_total = f->get_32();
|
||||
uint32_t bc = (read_total / block_size) + 1;
|
||||
|
|
@ -137,7 +123,7 @@ void FileAccessCompressed::_close() {
|
|||
f->store_buffer((const uint8_t *)mgc.get_data(), mgc.length()); //write header 4
|
||||
f->store_32(cmode); //write compression mode 4
|
||||
f->store_32(block_size); //write block size 4
|
||||
f->store_32(write_max); //max amount of data written 4
|
||||
f->store_32(uint32_t(write_max)); //max amount of data written 4
|
||||
uint32_t bc = (write_max / block_size) + 1;
|
||||
|
||||
for (uint32_t i = 0; i < bc; i++) {
|
||||
|
|
@ -159,7 +145,7 @@ void FileAccessCompressed::_close() {
|
|||
|
||||
f->seek(16); //ok write block sizes
|
||||
for (uint32_t i = 0; i < bc; i++) {
|
||||
f->store_32(block_sizes[i]);
|
||||
f->store_32(uint32_t(block_sizes[i]));
|
||||
}
|
||||
f->seek_end();
|
||||
f->store_buffer((const uint8_t *)mgc.get_data(), mgc.length()); //magic at the end too
|
||||
|
|
@ -260,38 +246,6 @@ bool FileAccessCompressed::eof_reached() const {
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t FileAccessCompressed::get_8() const {
|
||||
ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use.");
|
||||
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
|
||||
|
||||
if (at_end) {
|
||||
read_eof = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t ret = read_ptr[read_pos];
|
||||
|
||||
read_pos++;
|
||||
if (read_pos >= read_block_size) {
|
||||
read_block++;
|
||||
|
||||
if (read_block < read_block_count) {
|
||||
//read another block of compressed data
|
||||
f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
|
||||
int total = Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
|
||||
ERR_FAIL_COND_V_MSG(total == -1, 0, "Compressed file is corrupt.");
|
||||
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
|
||||
read_pos = 0;
|
||||
|
||||
} else {
|
||||
read_block--;
|
||||
at_end = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t FileAccessCompressed::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
|
||||
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
|
||||
ERR_FAIL_COND_V_MSG(f.is_null(), -1, "File must be opened before use.");
|
||||
|
|
@ -341,12 +295,25 @@ void FileAccessCompressed::flush() {
|
|||
// compressed files keep data in memory till close()
|
||||
}
|
||||
|
||||
void FileAccessCompressed::store_8(uint8_t p_dest) {
|
||||
ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use.");
|
||||
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
|
||||
bool FileAccessCompressed::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
ERR_FAIL_COND_V_MSG(f.is_null(), false, "File must be opened before use.");
|
||||
ERR_FAIL_COND_V_MSG(!writing, false, "File has not been opened in write mode.");
|
||||
|
||||
WRITE_FIT(1);
|
||||
write_ptr[write_pos++] = p_dest;
|
||||
if (write_pos + (p_length) > write_max) {
|
||||
write_max = write_pos + (p_length);
|
||||
}
|
||||
if (write_max > write_buffer_size) {
|
||||
write_buffer_size = next_power_of_2(write_max);
|
||||
ERR_FAIL_COND_V(buffer.resize(write_buffer_size) != OK, false);
|
||||
write_ptr = buffer.ptrw();
|
||||
}
|
||||
|
||||
if (p_length) {
|
||||
memcpy(write_ptr + write_pos, p_src, p_length);
|
||||
}
|
||||
|
||||
write_pos += p_length;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileAccessCompressed::file_exists(const String &p_name) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue