mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add map table to save block index
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
constexpr int WORLD_SIZE_X = 32;
|
||||
constexpr int WORLD_SIZE_Z = 32;
|
||||
constexpr int WORLD_SIZE_Z = 32;
|
||||
constexpr int MAX_BLOCK_NUM = 1;
|
||||
14
include/Cubed/map_table.hpp
Normal file
14
include/Cubed/map_table.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
class MapTable {
|
||||
private:
|
||||
static std::unordered_map<unsigned, std::string> id_to_name_map;
|
||||
static std::unordered_map<size_t, unsigned> name_to_id_map;
|
||||
public:
|
||||
// please using reference
|
||||
static const std::string& get_name_from_id(unsigned id);
|
||||
static const unsigned get_id_from_name(const std::string& name);
|
||||
static void init_map();
|
||||
|
||||
};
|
||||
@@ -1,26 +1,24 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <Cubed/gameplay/block.hpp>
|
||||
#include <Cubed/tools/shader_tools.hpp>
|
||||
struct BlockTexture {
|
||||
std::string name;
|
||||
std::vector<GLuint> texture;
|
||||
|
||||
};
|
||||
|
||||
class TextureManager {
|
||||
private:
|
||||
static std::size_t make_hash(std::string);
|
||||
std::unordered_map<std::size_t, BlockTexture> m_block_textures;
|
||||
std::vector<BlockTexture> m_block_textures;
|
||||
|
||||
public:
|
||||
TextureManager();
|
||||
~TextureManager();
|
||||
const BlockTexture& get_block_texture(std::string name);
|
||||
const BlockTexture& get_block_texture(const std::string& block_name);
|
||||
const BlockTexture& get_block_texture(unsigned block_id);
|
||||
void delet_texture();
|
||||
|
||||
void load_block_texture(std::string block_name);
|
||||
void load_block_texture(const std::string& block_name);
|
||||
void load_block_texture(unsigned block_id);
|
||||
// Must call after MapTable::init_map() and glfwMakeContextCurrent(window);
|
||||
void init_texture();
|
||||
};
|
||||
8
include/Cubed/tools/cubed_hash.hpp
Normal file
8
include/Cubed/tools/cubed_hash.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
namespace HASH {
|
||||
inline std::size_t str(std::string value) {
|
||||
return std::hash<std::string>{}(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,11 @@
|
||||
#include <SOIL2.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
void print_shader_log(GLuint shader);
|
||||
void print_program_info(int prog);
|
||||
bool check_opengl_error();
|
||||
std::string read_shader_source(const char* file_path);
|
||||
GLuint load_texture(const std::string& tex_image_path);
|
||||
GLuint load_texture(const char* tex_image_path);
|
||||
namespace Shader {
|
||||
void print_shader_log(GLuint shader);
|
||||
void print_program_info(int prog);
|
||||
bool check_opengl_error();
|
||||
std::string read_shader_source(const char* file_path);
|
||||
GLuint load_texture(const std::string& tex_image_path);
|
||||
GLuint load_texture(const char* tex_image_path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user