mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat(gameplay): optimize chunk request with player chunk tracking
Add `update_player_chunk()` method to `ClientPlayer` that triggers a chunk request when the player moves more than 2 chunks away from the last recorded chunk. Introduce an atomic `m_requesting_chunk` flag in `ClientWorld` to prevent concurrent requests. Rename `m_player_chunk_pos` to `m_last_chunk_pos` for clarity.
This commit is contained in:
@@ -86,7 +86,7 @@ private:
|
||||
// player is tow block tall, the pos is the lower pos
|
||||
|
||||
glm::vec3 m_player_pos{0.0f, 255.0f, 0.0f};
|
||||
ChunkPos m_player_chunk_pos{0, 0};
|
||||
ChunkPos m_last_chunk_pos{0, 0};
|
||||
|
||||
glm::vec3 m_front{0, 0, -1};
|
||||
glm::vec3 m_right{0, 0, 0};
|
||||
@@ -112,5 +112,6 @@ private:
|
||||
void update_x_move(glm::vec3& player_pos);
|
||||
void update_y_move(glm::vec3& player_pos);
|
||||
void update_z_move(glm::vec3& player_pos);
|
||||
void update_player_chunk();
|
||||
};
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
void stop_client_thread();
|
||||
|
||||
void hot_reload();
|
||||
|
||||
void request_chunk();
|
||||
std::vector<glm::vec4>& planes();
|
||||
std::vector<ChunkRenderSnapshot>& render_snapshots();
|
||||
glm::vec3 sunlight_dir() const;
|
||||
@@ -76,6 +76,7 @@ private:
|
||||
std::atomic<int> m_rendering_distance{24};
|
||||
std::atomic<TickType> m_game_ticks{0};
|
||||
std::atomic<TickType> m_day_tick{6000};
|
||||
std::atomic<bool> m_requesting_chunk{false};
|
||||
std::shared_ptr<NetworkClient> m_client;
|
||||
void client_run(std::stop_token token);
|
||||
|
||||
@@ -83,7 +84,6 @@ private:
|
||||
|
||||
void report_player_pos();
|
||||
|
||||
void request_chunk();
|
||||
void set_block(const glm::ivec3& pos, unsigned id);
|
||||
};
|
||||
} // namespace Cubed
|
||||
|
||||
Reference in New Issue
Block a user