Reset R/W mode during map file operations in server ChunkManager
This commit is contained in:
parent
d347b1b74f
commit
756c2e98fe
@ -84,7 +84,6 @@ void ChunkManager::load_map_from_file(const std::string& name) {
|
|||||||
m_map_read_only = false;
|
m_map_read_only = false;
|
||||||
LOG_INFO("Created new map '%s'", name.c_str());
|
LOG_INFO("Created new map '%s'", name.c_str());
|
||||||
write_empty_map_header();
|
write_empty_map_header();
|
||||||
get_chunk(math::Vector3i(0)).add_node(1, math::Vector3i(0));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,14 +132,13 @@ polygun::world::Chunk& ChunkManager::get_chunk(const math::Vector3i& pos) {
|
|||||||
|
|
||||||
uint32_t dummy;
|
uint32_t dummy;
|
||||||
if(find_chunk_header_offset(pos, dummy)) {
|
if(find_chunk_header_offset(pos, dummy)) {
|
||||||
char temp[2];
|
char temp[8];
|
||||||
char temp2[8];
|
|
||||||
uint8_t compression_mode;
|
uint8_t compression_mode;
|
||||||
fread(reinterpret_cast<char*>(&compression_mode), 1, 1, m_map_file);
|
fread(reinterpret_cast<char*>(&compression_mode), 1, 1, m_map_file);
|
||||||
fread(temp, 2, 1, m_map_file);
|
fread(temp, 2, 1, m_map_file);
|
||||||
const uint16_t data_size = utils::bytes_to_uint16(temp);
|
const uint16_t data_size = utils::bytes_to_uint16(temp);
|
||||||
fread(temp2, 8, 1, m_map_file);
|
fread(temp, 8, 1, m_map_file);
|
||||||
const uint64_t data_offset = utils::bytes_to_uint64(temp2);
|
const uint64_t data_offset = utils::bytes_to_uint64(temp);
|
||||||
load_chunk(pos[0], pos[1], pos[2], compression_mode, data_size, data_offset);
|
load_chunk(pos[0], pos[1], pos[2], compression_mode, data_size, data_offset);
|
||||||
LOG_VERBOSE("Loaded chunk at position %d %d %d (offset in map file: %lu)", pos[0], pos[1], pos[2], data_offset);
|
LOG_VERBOSE("Loaded chunk at position %d %d %d (offset in map file: %lu)", pos[0], pos[1], pos[2], data_offset);
|
||||||
return *m_loaded_chunks.back();
|
return *m_loaded_chunks.back();
|
||||||
@ -241,9 +239,13 @@ void ChunkManager::write_chunk(const world::Chunk& chunk) {
|
|||||||
char temp2[8];
|
char temp2[8];
|
||||||
uint32_t chunk_index;
|
uint32_t chunk_index;
|
||||||
if(find_chunk_header_offset(chunk.get_pos(), chunk_index)) {
|
if(find_chunk_header_offset(chunk.get_pos(), chunk_index)) {
|
||||||
|
reset_rw_mode();
|
||||||
|
|
||||||
uint64_t chunk_header_offset = ftell(m_map_file);
|
uint64_t chunk_header_offset = ftell(m_map_file);
|
||||||
fwrite(reinterpret_cast<const char*>(&compression_mode), 1, 1, m_map_file);
|
fwrite(reinterpret_cast<const char*>(&compression_mode), 1, 1, m_map_file);
|
||||||
|
|
||||||
|
reset_rw_mode();
|
||||||
|
|
||||||
fread(temp, 2, 1, m_map_file);
|
fread(temp, 2, 1, m_map_file);
|
||||||
const uint16_t prev_data_size = utils::bytes_to_uint16(temp);
|
const uint16_t prev_data_size = utils::bytes_to_uint16(temp);
|
||||||
|
|
||||||
@ -344,4 +346,9 @@ void ChunkManager::close_map() {
|
|||||||
write_chunk(*chunk);
|
write_chunk(*chunk);
|
||||||
}
|
}
|
||||||
fclose(m_map_file);
|
fclose(m_map_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChunkManager::reset_rw_mode() {
|
||||||
|
// Use dummy fseek to reset file R/W mode
|
||||||
|
fseek(m_map_file, 0, SEEK_CUR);
|
||||||
}
|
}
|
@ -61,6 +61,7 @@ namespace polygun::server {
|
|||||||
void write_empty_map_header();
|
void write_empty_map_header();
|
||||||
void write_chunk(const world::Chunk& chunk);
|
void write_chunk(const world::Chunk& chunk);
|
||||||
void close_map();
|
void close_map();
|
||||||
|
void reset_rw_mode();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user