feat(world): add player-based chunk loading and UUID support

Restructure world generation to trigger chunk loading based on player
movement. Replace player name with UUID for identification. Implement
chunk request/response protocol. Improve thread management for gen
thread.
This commit is contained in:
2026-06-24 14:51:48 +08:00
parent 6f39ff771d
commit 9d33b240c6
11 changed files with 222 additions and 83 deletions

View File

@@ -1,10 +1,18 @@
#include "Cubed/gameplay/server_player.hpp"
#include "Cubed/gameplay/server_world.hpp"
namespace Cubed {
ServerPlayer::ServerPlayer(std::string_view name) : m_name(name) {}
ServerPlayer::ServerPlayer(std::string_view name, std::string_view uuid,
ServerWorld& world)
: m_name(name), m_uuid(uuid), m_world(world) {}
const glm::vec3& ServerPlayer::get_pos() const { return m_pos; }
const std::string& ServerPlayer::get_name() const { return m_name; }
void ServerPlayer::update_pos(float x, float y, float z) {
m_pos = glm::vec3{x, y, z};
ChunkPos chunk_pos = get_chunk_pos(x, z);
float dist = distance2(chunk_pos, m_last_chunk_pos);
if (dist > 2) {
m_world.need_gen(m_uuid);
}
}
} // namespace Cubed