deferred block updates: falling sand

This commit is contained in:
2025-09-27 17:47:28 +02:00
parent 0cffb5a8f1
commit 5fcfe94449
6 changed files with 90 additions and 27 deletions

View File

@@ -74,6 +74,10 @@
// Determines the fixed amount of memory allocated to blocks
#define MAX_BLOCK_CHANGES 20000
// How many "deferred" (happen at a later time than triggered) block updates to store.
// Determines the fixed amount of memory allocated to that list
#define MAX_DEFERRED_BLOCK_UPDATES 64
// If defined, writes and reads world data to/from disk (or flash).
// This is a synchronous operation, and can cause performance issues if
// frequent random disk access is slow. Data is still stored in and
@@ -195,6 +199,13 @@ typedef struct {
uint8_t block;
} BlockChange;
typedef struct {
short x;
short z;
uint8_t y;
uint8_t awaitTicks;
} DeferredBlockUpdate;
#pragma pack(push, 1)
typedef struct {
@@ -267,6 +278,11 @@ typedef struct {
extern BlockChange block_changes[MAX_BLOCK_CHANGES];
extern int block_changes_count;
extern DeferredBlockUpdate deferred_block_updates[MAX_DEFERRED_BLOCK_UPDATES];
extern int deferred_block_updates_count;
extern uint8_t is_processing_deferred_block_updates;
extern uint8_t had_too_many_deferred_block_updates;
extern PlayerData player_data[MAX_PLAYERS];
extern int player_data_count;

View File

@@ -44,6 +44,8 @@ void handlePlayerAction (PlayerData *player, int action, short x, short y, short
void handlePlayerUseItem (PlayerData *player, short x, short y, short z, uint8_t face);
void checkFluidUpdate (short x, uint8_t y, short z, uint8_t block);
void processBlockUpdate (short x, uint8_t y, short z, uint8_t block);
void deferBlockUpdate (short x, uint8_t y, short z, uint8_t awaitTicks);
void spawnMob (uint8_t type, short x, uint8_t y, short z, uint8_t health);
void interactEntity (int entity_id, int interactor_id);