forked from EXTERNAL/bareiron
fix block changes not syncing on interval
This commit is contained in:
@@ -8,11 +8,13 @@
|
||||
void writeBlockChangesToDisk (int from, int to);
|
||||
void writeChestChangesToDisk (uint8_t *storage_ptr, uint8_t slot);
|
||||
void writePlayerDataToDisk ();
|
||||
void writeDataToDiskOnInterval ();
|
||||
#else
|
||||
// Define no-op placeholders for when disk syncing isn't enabled
|
||||
#define writeBlockChangesToDisk(a, b)
|
||||
#define writeChestChangesToDisk(a, b)
|
||||
#define writePlayerDataToDisk()
|
||||
#define writeDataToDiskOnInterval()
|
||||
#define initSerializer() 0
|
||||
#endif
|
||||
|
||||
|
@@ -1483,11 +1483,8 @@ void handleServerTick (int64_t time_since_last_tick) {
|
||||
sc_setHealth(player->client_fd, player->health, player->hunger, player->saturation);
|
||||
}
|
||||
|
||||
// Write data to file (if applicable)
|
||||
writePlayerDataToDisk();
|
||||
#ifdef DISK_SYNC_BLOCKS_ON_INTERVAL
|
||||
writeBlockChangesToDisk(0, block_changes_count);
|
||||
#endif
|
||||
// Perform regular checks for if it's time to write to disk
|
||||
writeDataToDiskOnInterval();
|
||||
|
||||
/**
|
||||
* If the RNG seed ever hits 0, it'll never generate anything
|
||||
|
@@ -115,12 +115,6 @@ int initSerializer () {
|
||||
// Writes a range of block change entries to disk
|
||||
void writeBlockChangesToDisk (int from, int to) {
|
||||
|
||||
#ifdef DISK_SYNC_BLOCKS_ON_INTERVAL
|
||||
// Skip this write if enough time hasn't passed since the last one
|
||||
if (get_program_time() - last_disk_sync_time < DISK_SYNC_INTERVAL) return;
|
||||
last_disk_sync_time = get_program_time();
|
||||
#endif
|
||||
|
||||
// Try to open the file in rw (without overwriting)
|
||||
FILE *file = fopen(FILE_PATH, "r+b");
|
||||
if (!file) {
|
||||
@@ -149,10 +143,6 @@ void writeBlockChangesToDisk (int from, int to) {
|
||||
// Writes all player data to disk
|
||||
void writePlayerDataToDisk () {
|
||||
|
||||
// Skip this write if enough time hasn't passed since the last one
|
||||
if (get_program_time() - last_disk_sync_time < DISK_SYNC_INTERVAL) return;
|
||||
last_disk_sync_time = get_program_time();
|
||||
|
||||
// Try to open the file in rw (without overwriting)
|
||||
FILE *file = fopen(FILE_PATH, "r+b");
|
||||
if (!file) {
|
||||
@@ -176,6 +166,21 @@ void writePlayerDataToDisk () {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
// Writes data queued for interval writes, but only if enough time has passed
|
||||
void writeDataToDiskOnInterval () {
|
||||
|
||||
// Skip this write if enough time hasn't passed since the last one
|
||||
if (get_program_time() - last_disk_sync_time < DISK_SYNC_INTERVAL) return;
|
||||
last_disk_sync_time = get_program_time();
|
||||
|
||||
// Write full player data and block changes buffers
|
||||
writePlayerDataToDisk();
|
||||
#ifdef DISK_SYNC_BLOCKS_ON_INTERVAL
|
||||
writeBlockChangesToDisk(0, block_changes_count);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifdef ALLOW_CHESTS
|
||||
// Writes a chest slot change to disk
|
||||
void writeChestChangesToDisk (uint8_t *storage_ptr, uint8_t slot) {
|
||||
|
Reference in New Issue
Block a user