1
0
mirror of https://github.com/p2r3/bareiron.git synced 2025-10-02 07:35:08 +02:00

implement syncing world to file on disk

This commit is contained in:
p2r3
2025-08-29 02:49:41 +03:00
parent e4267e7edf
commit 728d49f7b6
6 changed files with 215 additions and 3 deletions

View File

@@ -35,6 +35,14 @@
// How many visited chunk coordinates to "remember"
// The server will not re-send chunks that the player has recently been in
#define VISITED_HISTORY 4
// How many player-made block changes to allow
// Determines the fixed amount of memory allocated to blocks
#define MAX_BLOCK_CHANGES 20000
// If defined, writes and reads world data to/from disk (PC only).
// This is a synchronous operation, and can cause performance issues if
// frequent random disk access is slow. Data is still stored in and
// accessed from memory - reading from disk is only done on startup.
#define SYNC_WORLD_TO_DISK
// If defined, scales the frequency at which player movement updates are
// broadcast based on the amount of players, reducing overhead for higher
// player counts. For very many players, makes movement look jittery.
@@ -137,7 +145,7 @@ typedef struct {
#pragma pack(pop)
extern BlockChange block_changes[20000];
extern BlockChange block_changes[MAX_BLOCK_CHANGES];
extern int block_changes_count;
extern PlayerData player_data[MAX_PLAYERS];

21
include/serialize.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef SERIALIZE_H
#define SERIALIZE_H
#include <stdlib.h>
#include "globals.h"
#if defined(SYNC_WORLD_TO_DISK) && !defined(ESP_PLATFORM)
int initSerializer ();
void writeBlockChangesToDisk (int from, int to);
void writeChestChangesToDisk (uint8_t *storage_ptr, uint8_t slot);
void writePlayerDataToDisk ();
#else
// Define no-op placeholders for when disk syncing isn't enabled
#define writeBlockChangesToDisk(a, b)
#define writeChestChangesToDisk(a, b)
#define writePlayerDataToDisk()
#define initSerializer() 0
#endif
#endif