1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-27 05:45:18 +01:00

Refactor meshgen-related code

This commit is contained in:
sfan5
2025-06-23 12:30:44 +02:00
parent 0ea89d4112
commit 6545710c8e
6 changed files with 95 additions and 61 deletions

View File

@@ -22,11 +22,24 @@ struct QueuedMeshUpdate
int crack_level = -1;
v3s16 crack_pos;
MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop()
std::vector<MapBlock *> map_blocks;
std::vector<MapBlock*> map_blocks;
bool urgent = false;
QueuedMeshUpdate() = default;
~QueuedMeshUpdate();
/**
* Get blocks needed for this mesh update from the map.
* Blocks that were already loaded are skipped.
* @param map Map
* @param cell_size mesh grid cell size
*/
void retrieveBlocks(Map *map, u16 cell_size);
/**
* Drop block references.
* @note not done by destructor, since this is only safe on main thread
*/
void dropBlocks();
};
/*
@@ -45,9 +58,16 @@ public:
~MeshUpdateQueue();
// Caches the block at p and its neighbors (if needed) and queues a mesh
// update for the block at p
bool addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent);
/**
* Caches the block at p and its neighbors (if needed) and queues a mesh
* update for the block p.
* @param map Map
* @param p block position
* @param ack_to_server Should be acked to server when done?
* @param urget High-priority?
* @param from_neighbor was this update only necessary due to a neighbor change?
*/
bool addBlock(Map *map, v3s16 p, bool ack_to_server, bool urgent, bool from_neighbor);
// Returned pointer must be deleted
// Returns NULL if queue is empty
@@ -56,7 +76,7 @@ public:
// Marks a position as finished, unblocking the next update
void done(v3s16 pos);
u32 size()
size_t size()
{
MutexAutoLock lock(m_mutex);
return m_queue.size();
@@ -83,7 +103,7 @@ struct MeshUpdateResult
u8 solid_sides;
std::vector<v3s16> ack_list;
bool urgent = false;
std::vector<MapBlock *> map_blocks;
std::vector<MapBlock*> map_blocks;
MeshUpdateResult() = default;
};
@@ -117,6 +137,7 @@ public:
void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent,
bool update_neighbors = false);
void putResult(const MeshUpdateResult &r);
/// @note caller needs to refDrop() the affected map_blocks
bool getNextResult(MeshUpdateResult &r);