Files
Cubed/include/Cubed/texture_manager.hpp
zhenyan121 03259f323c 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
2026-07-11 09:22:40 +08:00

59 lines
1.7 KiB
C++

#pragma once
#include "Cubed/config.hpp"
#include "Cubed/gameplay/block.hpp"
#include "Cubed/render/texture.hpp"
#include <glad/glad.h>
#include <memory>
namespace Cubed {
class TextureManager {
private:
bool m_need_reload = false;
bool m_init = false;
std::unique_ptr<Texture> m_block_status_array;
std::unique_ptr<Texture> m_texture_array;
std::unique_ptr<Texture> m_cross_plane_array;
std::unique_ptr<Texture> m_ui_array;
std::unique_ptr<Texture> m_normal_texture_array;
std::unique_ptr<Texture> m_skin;
std::vector<std::unique_ptr<Texture>> m_item_textures;
GLfloat m_max_aniso = 0.0f;
Config& m_config;
int m_aniso = 1;
void load_block_status(unsigned status_id);
void load_block_texture(unsigned block_id);
void load_block_item_texture(unsigned id);
void load_cross_plane_texture(unsigned id);
void load_ui_texture(unsigned id);
void load_pbr_texture(unsigned id);
void init_item();
void init_block();
void init_ui();
void init_block_status();
void init_skin();
void hot_reload();
public:
TextureManager(Config& config);
~TextureManager();
void delete_texture();
const Texture* get_block_status_array() const;
const Texture* get_texture_array() const;
const Texture* get_cross_plane_array() const;
const Texture* get_ui_array() const;
const Texture* get_pbr_texture() const;
const std::vector<std::unique_ptr<Texture>>& item_textures() const;
const Texture* get_skin() const;
// Must call after MapTable::init_map() and glfwMakeContextCurrent(window);
void init_texture();
void need_reload();
void update();
int max_aniso() const;
};
} // namespace Cubed