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:
12
src/app.cpp
12
src/app.cpp
@@ -12,7 +12,14 @@
|
||||
#include <imgui_impl_glfw.h>
|
||||
namespace Cubed {
|
||||
|
||||
App::App() : m_client_world(m_audio) {}
|
||||
App::App()
|
||||
|
||||
: m_game_config(ASSETS_PATH "config.toml"),
|
||||
m_texture_manager(m_game_config), m_audio(m_game_config),
|
||||
m_client_world(m_audio, m_game_config), m_dev_panel(*this),
|
||||
m_renderer(m_camera, m_client_world, m_texture_manager, m_dev_panel,
|
||||
m_game_config),
|
||||
m_window(m_renderer, m_game_config) {}
|
||||
|
||||
App::~App() {
|
||||
if (m_client) {
|
||||
@@ -357,7 +364,7 @@ void App::update() {
|
||||
const auto& player = m_client_world.get_player();
|
||||
if (player_gait != player.get_gait()) {
|
||||
player_gait = player.get_gait();
|
||||
float fov = static_cast<float>(Config::get().get<double>("player.fov"));
|
||||
float fov = m_game_config.get("player.fov", 70.0f);
|
||||
if (player_gait == Gait::WALK) {
|
||||
m_renderer.update_fov(fov);
|
||||
}
|
||||
@@ -401,6 +408,7 @@ TextureManager& App::texture_manager() { return m_texture_manager; }
|
||||
Window& App::window() { return m_window; }
|
||||
ClientWorld& App::client_world() { return m_client_world; }
|
||||
ServerWorld& App::server_world() { return m_server.server_world(); }
|
||||
Config& App::config() { return m_game_config; }
|
||||
const App::Argument& App::argument() const { return m_argument; }
|
||||
AudioEngine& App::audio() { return m_audio; }
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user