mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
refactor: config (#30)
* refactor(config): replace singleton with dependency injection * refactor(client_player): return ChunkPosSet by value in non-const getter Copy the internal set under the mutex lock to avoid exposing a mutable reference that could be used unsafely after the lock is released. This fixes a potential data race when the caller holds the returned reference beyond the critical section. Also update the caller in `client_world` to remove the now-unnecessary `std::move`. * fix(gameplay): prevent use-after-free in pending delete queues during destruction * refactor(config): separate game and server configuration with explicit paths
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include "Cubed/gameplay/server_world.hpp"
|
||||
|
||||
#include "Cubed/config.hpp"
|
||||
#include "Cubed/gameplay/packet.hpp"
|
||||
#include "Cubed/gameplay/session.hpp"
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
@@ -14,7 +13,7 @@ using namespace std::chrono_literals;
|
||||
using namespace google::protobuf;
|
||||
|
||||
namespace Cubed {
|
||||
ServerWorld::ServerWorld() {}
|
||||
ServerWorld::ServerWorld(Config& config) : m_config(config) {}
|
||||
|
||||
ServerWorld::~ServerWorld() { stop(); }
|
||||
|
||||
@@ -501,8 +500,7 @@ bool ServerWorld::set_block(const glm::ivec3& block_pos, unsigned id) {
|
||||
}
|
||||
|
||||
void ServerWorld::hot_reload() {
|
||||
auto& config = Config::get();
|
||||
int dist = config.get<int>("world.rendering_distance");
|
||||
int dist = m_config.get("server_distance", 24);
|
||||
m_rendering_distance = dist <= MAX_DISTANCE ? dist : MAX_DISTANCE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user