mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
chore: add clang-format and pre-commit configuration
This commit is contained in:
@@ -3,17 +3,12 @@
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
struct AABB {
|
||||
glm::vec3 min{0.0f, 0.0f, 0.0f};
|
||||
glm::vec3 max{0.0f, 0.0f, 0.0f};
|
||||
|
||||
AABB(glm::vec3 min_point, glm::vec3 max_point):
|
||||
min(min_point),
|
||||
max(max_point)
|
||||
{
|
||||
|
||||
}
|
||||
AABB(glm::vec3 min_point, glm::vec3 max_point)
|
||||
: min(min_point), max(max_point) {}
|
||||
|
||||
bool intersects(const AABB& other) const {
|
||||
return (min.x <= other.max.x && max.x >= other.min.x) &&
|
||||
@@ -22,4 +17,4 @@ struct AABB {
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,28 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <Cubed/camera.hpp>
|
||||
#include <Cubed/dev_panel.hpp>
|
||||
#include <Cubed/gameplay/world.hpp>
|
||||
#include <Cubed/input.hpp>
|
||||
#include <Cubed/renderer.hpp>
|
||||
#include <Cubed/texture_manager.hpp>
|
||||
#include <Cubed/window.hpp>
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include "Cubed/camera.hpp"
|
||||
#include "Cubed/dev_panel.hpp"
|
||||
#include "Cubed/gameplay/world.hpp"
|
||||
#include "Cubed/renderer.hpp"
|
||||
#include "Cubed/texture_manager.hpp"
|
||||
#include "Cubed/window.hpp"
|
||||
namespace Cubed {
|
||||
|
||||
class App {
|
||||
public:
|
||||
App();
|
||||
~App();
|
||||
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos);
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
|
||||
static void cursor_position_callback(GLFWwindow* window, double xpos,
|
||||
double ypos);
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode,
|
||||
int action, int mods);
|
||||
static void mouse_button_callback(GLFWwindow* window, int button,
|
||||
int action, int mods);
|
||||
static void window_focus_callback(GLFWwindow* window, int focused);
|
||||
static void window_reshape_callback(GLFWwindow* window, int new_width, int new_height);
|
||||
static void mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
static void window_reshape_callback(GLFWwindow* window, int new_width,
|
||||
int new_height);
|
||||
static void mouse_scroll_callback(GLFWwindow* window, double xoffset,
|
||||
double yoffset);
|
||||
static void cursor_enter_callback(GLFWwindow* window, int entered);
|
||||
static void char_callback(GLFWwindow* window, unsigned int ch);
|
||||
static int start_cubed_application(int argc, char** argv);
|
||||
|
||||
|
||||
static unsigned int seed();
|
||||
static float delte_time();
|
||||
static float get_fps();
|
||||
@@ -34,7 +38,6 @@ public:
|
||||
Window& window();
|
||||
World& world();
|
||||
|
||||
|
||||
private:
|
||||
Camera m_camera;
|
||||
TextureManager m_texture_manager;
|
||||
@@ -43,23 +46,23 @@ private:
|
||||
Renderer m_renderer{m_camera, m_world, m_texture_manager, m_dev_panel};
|
||||
|
||||
Window m_window{m_renderer};
|
||||
|
||||
|
||||
inline static double last_time = glfwGetTime();
|
||||
inline static double current_time = glfwGetTime();
|
||||
inline static double delta_time = 0.0f;
|
||||
inline static double fps_time_count = 0.0f;
|
||||
inline static int frame_count = 0;
|
||||
inline static int fps = 0;
|
||||
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
auto init_camera();
|
||||
auto init_texture();
|
||||
auto init_world();
|
||||
|
||||
|
||||
void render();
|
||||
void run();
|
||||
void update();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,27 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
class Player;
|
||||
|
||||
|
||||
class Camera {
|
||||
private:
|
||||
|
||||
bool m_firse_mouse = true;
|
||||
Player* m_player;
|
||||
float m_last_mouse_x, m_last_mouse_y;
|
||||
glm::vec3 m_camera_pos;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
Camera();
|
||||
|
||||
void update_move_camera();
|
||||
@@ -35,6 +31,4 @@ public:
|
||||
const glm::vec3& get_camera_pos() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
#pragma once
|
||||
#include <toml++/toml.hpp>
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
|
||||
#include <Cubed/tools/cubed_assert.hpp>
|
||||
#include <toml++/toml.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
template <typename T>
|
||||
concept TomlValueType =
|
||||
std::same_as<T, int> ||
|
||||
std::same_as<T, bool> ||
|
||||
std::same_as<T, double> ||
|
||||
std::same_as<T, const char*> ||
|
||||
std::same_as<T, toml::date> ||
|
||||
std::same_as<T, toml::time> ||
|
||||
std::same_as<T, toml::date_time> ||
|
||||
std::same_as<T, std::string>
|
||||
;
|
||||
concept TomlValueType =
|
||||
std::same_as<T, int> || std::same_as<T, bool> || std::same_as<T, double> ||
|
||||
std::same_as<T, const char*> || std::same_as<T, toml::date> ||
|
||||
std::same_as<T, toml::time> || std::same_as<T, toml::date_time> ||
|
||||
std::same_as<T, std::string>;
|
||||
|
||||
class Config {
|
||||
public:
|
||||
@@ -30,8 +24,7 @@ public:
|
||||
void load_or_create_config();
|
||||
void save_to_file();
|
||||
|
||||
template <TomlValueType T>
|
||||
T get(std::string_view key) const{
|
||||
template <TomlValueType T> T get(std::string_view key) const {
|
||||
size_t cur = 0;
|
||||
auto pos = key.find('.');
|
||||
const toml::table* table = &m_tbl;
|
||||
@@ -59,7 +52,7 @@ public:
|
||||
std::abort();
|
||||
}
|
||||
auto opt = (*table)[n_key].value<T>();
|
||||
if (opt){
|
||||
if (opt) {
|
||||
return *opt;
|
||||
} else {
|
||||
Logger::error("Can't find key {}", n_key);
|
||||
@@ -67,11 +60,10 @@ public:
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
void set(std::string_view key, T&& val) {
|
||||
template <typename T> void set(std::string_view key, T&& val) {
|
||||
if constexpr (!TomlValueType<std::decay_t<T>>) {
|
||||
static_assert(false, "Type Not Support");
|
||||
}
|
||||
}
|
||||
size_t cur = 0;
|
||||
auto pos = key.find('.');
|
||||
toml::table* table = &m_tbl;
|
||||
@@ -90,7 +82,6 @@ public:
|
||||
auto [it, inserted] = table->insert_or_assign(s, toml::table{});
|
||||
table = it->second.as_table();
|
||||
}
|
||||
|
||||
}
|
||||
std::string_view n_key = key.substr(cur);
|
||||
if (n_key.empty()) {
|
||||
@@ -99,21 +90,18 @@ public:
|
||||
std::abort();
|
||||
}
|
||||
table->insert_or_assign(n_key, std::forward<T>(val));
|
||||
|
||||
}
|
||||
template <typename T>
|
||||
void set_and_save(std::string_view key, T&& val) {
|
||||
template <typename T> void set_and_save(std::string_view key, T&& val) {
|
||||
set(key, std::forward(val));
|
||||
save_to_file();
|
||||
}
|
||||
toml::node_view<toml::node> val_view(std::string_view key);
|
||||
|
||||
private:
|
||||
|
||||
toml::table m_tbl;
|
||||
constexpr static inline std::string_view CONGIF_PATH = ASSETS_PATH"config.toml";
|
||||
constexpr static inline std::string_view CONGIF_PATH =
|
||||
ASSETS_PATH "config.toml";
|
||||
void create_config();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -18,10 +18,10 @@ constexpr int MAX_DISTANCE = 128;
|
||||
constexpr float DEFAULT_FOV = 70.0f;
|
||||
constexpr float DEFAULT_MAX_WALK_SPEED = 4.5f;
|
||||
constexpr float DEFAULT_MAX_RUN_SPEED = 7.0f;
|
||||
constexpr float DEFAULT_ACCELERATION = 10.0f;
|
||||
constexpr float DEFAULT_ACCELERATION = 10.0f;
|
||||
constexpr float DEFAULT_DECELERATION = 15.0f;
|
||||
constexpr float DEFAULT_G = 22.5f;
|
||||
|
||||
using HeightMapArray = std::array<std::array<float, CHUCK_SIZE>, CHUCK_SIZE>;
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,18 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <Cubed/primitive_data.hpp>
|
||||
#include <Cubed/ui/text.hpp>
|
||||
#include "Cubed/ui/text.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
class DebugCollector {
|
||||
public:
|
||||
static DebugCollector& get();
|
||||
DebugCollector();
|
||||
|
||||
|
||||
std::unordered_map<std::size_t, Text>& all_texts();
|
||||
|
||||
Text& text(std::string_view name);
|
||||
@@ -23,4 +21,4 @@ private:
|
||||
std::unordered_map<std::size_t, Text> m_texts;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -29,11 +29,12 @@ class DevPanel {
|
||||
struct TextEditing {
|
||||
bool perlin_seed = false;
|
||||
};
|
||||
|
||||
public:
|
||||
DevPanel(App& app);
|
||||
void init();
|
||||
void render();
|
||||
|
||||
|
||||
private:
|
||||
App& m_app;
|
||||
ConfigView m_config;
|
||||
@@ -50,8 +51,6 @@ private:
|
||||
|
||||
void update_config_view();
|
||||
void update_player_profile();
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -12,14 +12,7 @@ constexpr float FOREST_FREQ = 1.2f;
|
||||
constexpr float DESERT_FREQ = 1.2f;
|
||||
constexpr float MOUNTAIN_FREQ = 2.0f;
|
||||
|
||||
enum class Biome {
|
||||
PLAIN = 0,
|
||||
FOREST,
|
||||
DESERT,
|
||||
MOUNTAIN,
|
||||
NONE
|
||||
};
|
||||
|
||||
enum class Biome { PLAIN = 0, FOREST, DESERT, MOUNTAIN, NONE };
|
||||
|
||||
struct BiomeHeightRange {
|
||||
int base_y;
|
||||
@@ -32,12 +25,11 @@ struct BiomeNonAdjacent {
|
||||
Biome replace;
|
||||
};
|
||||
|
||||
static inline const std::vector<BiomeNonAdjacent> NON_ADJACENT {{
|
||||
{Biome::PLAIN, {Biome::NONE}, Biome::PLAIN},
|
||||
{Biome::FOREST, {Biome::DESERT}, Biome::PLAIN},
|
||||
{Biome::DESERT, {Biome::MOUNTAIN, Biome::FOREST}, Biome::PLAIN},
|
||||
{Biome::MOUNTAIN, {Biome::DESERT}, Biome::PLAIN}
|
||||
}};
|
||||
static inline const std::vector<BiomeNonAdjacent> NON_ADJACENT{
|
||||
{{Biome::PLAIN, {Biome::NONE}, Biome::PLAIN},
|
||||
{Biome::FOREST, {Biome::DESERT}, Biome::PLAIN},
|
||||
{Biome::DESERT, {Biome::MOUNTAIN, Biome::FOREST}, Biome::PLAIN},
|
||||
{Biome::MOUNTAIN, {Biome::DESERT}, Biome::PLAIN}}};
|
||||
|
||||
struct BaseBiomeParams {
|
||||
Biome biome;
|
||||
@@ -47,32 +39,27 @@ struct BaseBiomeParams {
|
||||
BiomeHeightRange height_range;
|
||||
};
|
||||
|
||||
struct PlainParams : public BaseBiomeParams {
|
||||
|
||||
};
|
||||
struct PlainParams : public BaseBiomeParams {};
|
||||
|
||||
struct ForestParams : public BaseBiomeParams {
|
||||
float tree_frequency;
|
||||
};
|
||||
|
||||
struct DesertParams : public BaseBiomeParams {
|
||||
struct DesertParams : public BaseBiomeParams {};
|
||||
|
||||
};
|
||||
|
||||
struct MountainParams : public BaseBiomeParams {
|
||||
|
||||
};
|
||||
struct MountainParams : public BaseBiomeParams {};
|
||||
|
||||
std::string get_biome_str(Biome biome);
|
||||
Biome get_biome_from_noise(float temp, float humid);
|
||||
std::array<float, 3> get_noise_frequencies_for_biome(Biome biome);
|
||||
BiomeHeightRange get_biome_height_range(Biome biome);
|
||||
Biome safe_int_to_biome(int x);
|
||||
int get_interpolated_height(float world_x, float world_z, float temp, float humid);
|
||||
int get_interpolated_height(float world_x, float world_z, float temp,
|
||||
float humid);
|
||||
|
||||
PlainParams& plain_params();
|
||||
ForestParams& forest_params();
|
||||
DesertParams& desert_params();
|
||||
MountainParams& mountain_params();
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
#pragma once
|
||||
#include "Cubed/constants.hpp"
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/constants.hpp>
|
||||
#include <Cubed/tools/cubed_assert.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
struct BlockTexture {
|
||||
std::string name;
|
||||
unsigned id;
|
||||
std::vector<GLuint> texture;
|
||||
};
|
||||
|
||||
struct Block : public BlockTexture{
|
||||
|
||||
};
|
||||
struct Block : public BlockTexture {};
|
||||
|
||||
struct BlockRenderData {
|
||||
std::vector<bool> draw_face;
|
||||
@@ -28,12 +24,8 @@ struct BlockRenderData {
|
||||
BlockRenderData() = default;
|
||||
BlockRenderData(const BlockRenderData&) = default;
|
||||
BlockRenderData& operator=(const BlockRenderData&) = default;
|
||||
BlockRenderData(BlockRenderData&& data) :
|
||||
draw_face(std::move(data.draw_face)),
|
||||
block_id(data.block_id)
|
||||
{
|
||||
|
||||
}
|
||||
BlockRenderData(BlockRenderData&& data)
|
||||
: draw_face(std::move(data.draw_face)), block_id(data.block_id) {}
|
||||
BlockRenderData& operator=(BlockRenderData&& data) {
|
||||
draw_face = std::move(data.draw_face);
|
||||
block_id = data.block_id;
|
||||
@@ -47,29 +39,14 @@ struct LookBlock {
|
||||
};
|
||||
|
||||
constexpr std::array<std::string_view, MAX_BLOCK_NUM> BLOCK_REISTER{
|
||||
"air",
|
||||
"grass_block",
|
||||
"dirt",
|
||||
"stone",
|
||||
"sand",
|
||||
"log",
|
||||
"leaf"
|
||||
};
|
||||
"air", "grass_block", "dirt", "stone", "sand", "log", "leaf"};
|
||||
|
||||
const std::array<bool, MAX_BLOCK_NUM> TRANSPARENT_MAP {
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
};
|
||||
const std::array<bool, MAX_BLOCK_NUM> TRANSPARENT_MAP{
|
||||
true, false, false, false, false, false, true};
|
||||
|
||||
inline bool is_in_transparent_map(unsigned id) {
|
||||
ASSERT_MSG(id < MAX_BLOCK_NUM, "ID is invaild");
|
||||
return TRANSPARENT_MAP[id];
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,20 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/gameplay/biome.hpp"
|
||||
#include "Cubed/gameplay/block.hpp"
|
||||
#include "Cubed/gameplay/chunk_generator.hpp"
|
||||
#include "Cubed/gameplay/chunk_pos.hpp"
|
||||
#include "Cubed/primitive_data.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/primitive_data.hpp>
|
||||
#include <Cubed/gameplay/biome.hpp>
|
||||
#include <Cubed/gameplay/chunk_generator.hpp>
|
||||
#include <Cubed/gameplay/chunk_pos.hpp>
|
||||
#include <Cubed/gameplay/block.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
class World;
|
||||
// if want to use, do init_chunk(), gen_vertex_data() and
|
||||
// if want to use, do init_chunk(), gen_vertex_data() and
|
||||
class Chunk {
|
||||
private:
|
||||
static constexpr int SIZE_X = CHUCK_SIZE;
|
||||
@@ -22,13 +20,13 @@ private:
|
||||
static constexpr int SIZE_Z = CHUCK_SIZE;
|
||||
|
||||
using HeightMapArray = std::array<std::array<float, SIZE_Z>, SIZE_X>;
|
||||
std::atomic<bool> m_dirty {false};
|
||||
std::atomic<bool> m_dirty{false};
|
||||
std::atomic<bool> m_need_upload{true};
|
||||
std::atomic<bool> m_is_on_gen_vertex_data {false};
|
||||
std::atomic<bool> m_is_on_gen_vertex_data{false};
|
||||
std::atomic<size_t> m_vertex_sum = 0;
|
||||
std::atomic<Biome> m_biome = Biome::PLAIN;
|
||||
std::mutex m_vertexs_data_mutex;
|
||||
|
||||
|
||||
std::unique_ptr<ChunkGenerator> m_generator;
|
||||
|
||||
ChunkPos m_chunk_pos;
|
||||
@@ -38,7 +36,7 @@ private:
|
||||
std::vector<uint8_t> m_blocks;
|
||||
GLuint m_vbo = 0;
|
||||
std::vector<Vertex> m_vertexs_data;
|
||||
|
||||
|
||||
float frequency = 0.01f;
|
||||
float height = 80;
|
||||
|
||||
@@ -54,7 +52,7 @@ public:
|
||||
|
||||
Biome get_biome() const;
|
||||
ChunkPos get_chunk_pos() const;
|
||||
const std::vector<uint8_t>& get_chunk_blocks() const;
|
||||
const std::vector<uint8_t>& get_chunk_blocks() const;
|
||||
HeightMapArray get_heightmap() const;
|
||||
static int get_index(int x, int y, int z);
|
||||
static int get_index(const glm::vec3& pos);
|
||||
@@ -66,32 +64,35 @@ public:
|
||||
// Generate heightmap using biome-specific noise
|
||||
void gen_phase_three();
|
||||
// Blend heightmap with neighbors for smooth transitions
|
||||
void gen_phase_four(const std::array<std::optional<HeightMapArray>, 4>& neighbor_heightmap);
|
||||
void gen_phase_four(
|
||||
const std::array<std::optional<HeightMapArray>, 4>& neighbor_heightmap);
|
||||
// Generate terrain blocks from heightmap and biome
|
||||
void gen_phase_five();
|
||||
// Blend surface blocks at chunk borders with neighbors
|
||||
void gen_phase_six(const std::array<std::optional<std::vector<uint8_t>>, 4>& neighbor_block);
|
||||
void gen_phase_six(const std::array<std::optional<std::vector<uint8_t>>, 4>&
|
||||
neighbor_block);
|
||||
// Generate biome-specific vegetation/structures
|
||||
void gen_phase_seven();
|
||||
//void gen_vertex_data();
|
||||
// 0 : (1, 0)
|
||||
// 1 : (-1, 0)
|
||||
// 2 : (0, 1)
|
||||
// 3 : (0, -1)
|
||||
void gen_vertex_data(const std::array<const std::vector<uint8_t>*, 4>& neighbor_block);
|
||||
// void gen_vertex_data();
|
||||
// 0 : (1, 0)
|
||||
// 1 : (-1, 0)
|
||||
// 2 : (0, 1)
|
||||
// 3 : (0, -1)
|
||||
void gen_vertex_data(
|
||||
const std::array<const std::vector<uint8_t>*, 4>& neighbor_block);
|
||||
void upload_to_gpu();
|
||||
|
||||
|
||||
GLuint get_vbo() const;
|
||||
size_t get_vertex_sum() const;
|
||||
|
||||
|
||||
bool is_dirty() const;
|
||||
void mark_dirty();
|
||||
|
||||
|
||||
bool is_need_upload() const;
|
||||
void need_upload();
|
||||
|
||||
void set_chunk_block(int index, unsigned id);
|
||||
|
||||
|
||||
ChunkPos chunk_pos() const;
|
||||
Biome biome() const;
|
||||
void biome(Biome b);
|
||||
@@ -99,5 +100,4 @@ public:
|
||||
std::vector<uint8_t>& blocks();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,20 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <Cubed/constants.hpp>
|
||||
#include <Cubed/tools/cubed_random.hpp>
|
||||
#include "Cubed/constants.hpp"
|
||||
#include "Cubed/tools/cubed_random.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <optional>
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
class Chunk;
|
||||
|
||||
class ChunkGenerator {
|
||||
static constexpr int SIZE_X = CHUCK_SIZE;
|
||||
static constexpr int SIZE_Y = WORLD_SIZE_Y;
|
||||
static constexpr int SIZE_Z = CHUCK_SIZE;
|
||||
using HeightMapArray = std::array<std::array<float, CHUCK_SIZE>, CHUCK_SIZE>;
|
||||
using HeightMapArray =
|
||||
std::array<std::array<float, CHUCK_SIZE>, CHUCK_SIZE>;
|
||||
|
||||
public:
|
||||
ChunkGenerator(Chunk& chunk);
|
||||
|
||||
@@ -26,25 +27,28 @@ public:
|
||||
// Generate Biome
|
||||
void assign_chunk_biome();
|
||||
// Adjust Biome
|
||||
void resolve_biome_adjacency_conflict(const std::array<const Chunk*, 4>& adj_chunks);
|
||||
void resolve_biome_adjacency_conflict(
|
||||
const std::array<const Chunk*, 4>& adj_chunks);
|
||||
// Generate Heightmap
|
||||
void generate_heightmap();
|
||||
// Adjust Height
|
||||
void blend_heightmap_boundaries(const std::array<std::optional<HeightMapArray>, 4>& neighbor_heightmap);
|
||||
void blend_heightmap_boundaries(
|
||||
const std::array<std::optional<HeightMapArray>, 4>& neighbor_heightmap);
|
||||
// Generate Block
|
||||
void generate_terrain_blocks();
|
||||
// Adjust Block;
|
||||
void blend_surface_blocks_borders(const std::array<std::optional<std::vector<uint8_t>>, 4>& neighbor_block);
|
||||
void blend_surface_blocks_borders(
|
||||
const std::array<std::optional<std::vector<uint8_t>>, 4>&
|
||||
neighbor_block);
|
||||
// Generate Structure
|
||||
void generate_vegetation();
|
||||
|
||||
private:
|
||||
static inline std::atomic<bool> is_init {false};
|
||||
static inline unsigned m_generator_seed {0};
|
||||
static inline std::atomic<bool> is_seed_change {false};
|
||||
static inline std::atomic<bool> is_init{false};
|
||||
static inline unsigned m_generator_seed{0};
|
||||
static inline std::atomic<bool> is_seed_change{false};
|
||||
Chunk& m_chunk;
|
||||
Random m_random;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,27 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
||||
#include <Cubed/tools/log.hpp>
|
||||
#include <Cubed/tools/cubed_assert.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
struct ChunkPos {
|
||||
int x;
|
||||
int z;
|
||||
|
||||
|
||||
bool operator==(const ChunkPos&) const = default;
|
||||
struct Hash {
|
||||
std::size_t operator()(const ChunkPos& pos) const{
|
||||
std::size_t operator()(const ChunkPos& pos) const {
|
||||
std::size_t h1 = std::hash<int>{}(pos.x);
|
||||
std::size_t h2 = std::hash<int>{}(pos.z);
|
||||
return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
|
||||
}
|
||||
};
|
||||
|
||||
ChunkPos operator+(const ChunkPos& pos) const{
|
||||
ChunkPos operator+(const ChunkPos& pos) const {
|
||||
return ChunkPos{x + pos.x, z + pos.z};
|
||||
}
|
||||
|
||||
@@ -32,5 +28,4 @@ struct ChunkPos {
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -5,22 +5,17 @@
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
enum class GameMode {
|
||||
CREATIVE = 0,
|
||||
SPECTATOR
|
||||
};
|
||||
enum class GameMode { CREATIVE = 0, SPECTATOR };
|
||||
|
||||
inline std::string to_str(GameMode mode) {
|
||||
using enum GameMode;
|
||||
switch (mode) {
|
||||
case CREATIVE:
|
||||
return {"Creative"};
|
||||
case SPECTATOR:
|
||||
return {"Spective"};
|
||||
case CREATIVE:
|
||||
return {"Creative"};
|
||||
case SPECTATOR:
|
||||
return {"Spective"};
|
||||
}
|
||||
throw std::invalid_argument{"GameMode is invaild"};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,23 +1,18 @@
|
||||
#pragma once
|
||||
#include "Cubed/AABB.hpp"
|
||||
#include "Cubed/constants.hpp"
|
||||
#include "Cubed/gameplay/block.hpp"
|
||||
#include "Cubed/gameplay/chunk_pos.hpp"
|
||||
#include "Cubed/gameplay/game_mode.hpp"
|
||||
#include "Cubed/input.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <Cubed/AABB.hpp>
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/constants.hpp>
|
||||
#include <Cubed/gameplay/block.hpp>
|
||||
#include <Cubed/gameplay/chunk_pos.hpp>
|
||||
#include <Cubed/gameplay/game_mode.hpp>
|
||||
#include <Cubed/input.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
enum class Gait{
|
||||
WALK = 0,
|
||||
RUN
|
||||
};
|
||||
enum class Gait { WALK = 0, RUN };
|
||||
|
||||
class World;
|
||||
|
||||
@@ -26,46 +21,48 @@ private:
|
||||
using enum GameMode;
|
||||
float m_max_walk_speed = DEFAULT_MAX_WALK_SPEED;
|
||||
float m_max_run_speed = DEFAULT_MAX_RUN_SPEED;
|
||||
float m_acceleration = DEFAULT_ACCELERATION;
|
||||
float m_acceleration = DEFAULT_ACCELERATION;
|
||||
float m_deceleration = DEFAULT_DECELERATION;
|
||||
float m_g = DEFAULT_G;
|
||||
|
||||
constexpr static float MAX_SPACE_ON_TIME = 0.3f;
|
||||
constexpr static float MAX_SPACE_ON_TIME = 0.3f;
|
||||
|
||||
float m_yaw = 0.0f;
|
||||
float m_pitch = 0.0f;
|
||||
|
||||
|
||||
float m_sensitivity = 0.15f;
|
||||
|
||||
float m_max_speed = m_max_walk_speed;
|
||||
float m_y_speed = 0.0f;
|
||||
bool can_up = true;
|
||||
|
||||
|
||||
float space_on_time = 0.0f;
|
||||
bool space_on = false;
|
||||
bool is_fly = false;
|
||||
|
||||
float m_xz_speed = 0.0f;
|
||||
|
||||
glm::vec3 direction = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
glm::vec3 move_distance {0.0f, 0.0f, 0.0f};
|
||||
// player is tow block tall, the pos is the lower pos
|
||||
|
||||
glm::vec3 m_player_pos {0.0f, 255.0f, 0.0f};
|
||||
ChunkPos m_player_chunk_pos {0, 0};
|
||||
|
||||
glm::vec3 m_front {0, 0, -1};
|
||||
glm::vec3 m_right {0, 0, 0};
|
||||
glm::vec3 m_size {0.6f, 1.8f, 0.6f};
|
||||
float m_xz_speed = 0.0f;
|
||||
|
||||
glm::vec3 direction = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
glm::vec3 move_distance{0.0f, 0.0f, 0.0f};
|
||||
// player is tow block tall, the pos is the lower pos
|
||||
|
||||
glm::vec3 m_player_pos{0.0f, 255.0f, 0.0f};
|
||||
ChunkPos m_player_chunk_pos{0, 0};
|
||||
|
||||
glm::vec3 m_front{0, 0, -1};
|
||||
glm::vec3 m_right{0, 0, 0};
|
||||
glm::vec3 m_size{0.6f, 1.8f, 0.6f};
|
||||
|
||||
Gait m_gait = Gait::WALK;
|
||||
MoveState m_move_state {};
|
||||
MoveState m_move_state{};
|
||||
GameMode m_game_mode = CREATIVE;
|
||||
std::optional<LookBlock> m_look_block = std::nullopt;
|
||||
std::string m_name {};
|
||||
std::string m_name{};
|
||||
World& m_world;
|
||||
|
||||
bool ray_cast(const glm::vec3& start, const glm::vec3& dir, glm::ivec3& block_pos, glm::vec3& normal, float distance = 4.0f);
|
||||
bool ray_cast(const glm::vec3& start, const glm::vec3& dir,
|
||||
glm::ivec3& block_pos, glm::vec3& normal,
|
||||
float distance = 4.0f);
|
||||
|
||||
void check_player_chunk_transition();
|
||||
void update_direction();
|
||||
@@ -84,7 +81,7 @@ public:
|
||||
const std::optional<LookBlock>& get_look_block_pos() const;
|
||||
const glm::vec3& get_player_pos() const;
|
||||
const MoveState& get_move_state() const;
|
||||
|
||||
|
||||
void change_mode(GameMode mode);
|
||||
void hot_reload();
|
||||
void set_player_pos(const glm::vec3& pos);
|
||||
@@ -96,14 +93,12 @@ public:
|
||||
float& max_walk_speed();
|
||||
float& max_run_speed();
|
||||
float& max_speed();
|
||||
float& acceleration();
|
||||
float& acceleration();
|
||||
float& deceleration();
|
||||
float& g();
|
||||
|
||||
Gait& gait();
|
||||
GameMode& game_mode();
|
||||
|
||||
GameMode& game_mode();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -13,4 +13,4 @@ struct TreeStructNode {
|
||||
|
||||
bool build_tree(Chunk& chunk, const glm::ivec3& pos);
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
#include "Cubed/AABB.hpp"
|
||||
#include "Cubed/gameplay/chunk.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <Cubed/AABB.hpp>
|
||||
#include <Cubed/primitive_data.hpp>
|
||||
#include <Cubed/gameplay/chunk.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
@@ -19,18 +19,18 @@ struct ChunkRenderSnapshot {
|
||||
glm::vec3 half_extents;
|
||||
};
|
||||
|
||||
|
||||
class Player;
|
||||
|
||||
class World {
|
||||
private:
|
||||
using ChunkPtrUpdateList = std::vector<std::pair<ChunkPos, Chunk*>>;
|
||||
using ChunkUpdateList = std::vector<std::pair<ChunkPos, Chunk>>;
|
||||
using ConstChunkMap = std::unordered_map<ChunkPos, const Chunk*, ChunkPos::Hash>;
|
||||
using ChunkPosSet = std::unordered_set<ChunkPos, ChunkPos::Hash>;
|
||||
using ConstChunkMap =
|
||||
std::unordered_map<ChunkPos, const Chunk*, ChunkPos::Hash>;
|
||||
using ChunkPosSet = std::unordered_set<ChunkPos, ChunkPos::Hash>;
|
||||
|
||||
glm::vec3 m_gen_player_pos{0.0f, 0.0f, 0.0f};
|
||||
std::unordered_map<ChunkPos , Chunk, ChunkPos::Hash> m_chunks;
|
||||
std::unordered_map<ChunkPos, Chunk, ChunkPos::Hash> m_chunks;
|
||||
std::unordered_map<std::size_t, Player> m_players;
|
||||
std::vector<glm::vec4> m_planes;
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
std::condition_variable m_gen_cv;
|
||||
std::atomic<bool> m_gen_running{false};
|
||||
std::atomic<bool> m_need_gen_chunk{false};
|
||||
std::atomic<bool> m_is_rebuilding {false};
|
||||
std::atomic<bool> m_is_rebuilding{false};
|
||||
std::atomic<bool> m_could_gen{true};
|
||||
std::atomic<int> m_rendering_distance{24};
|
||||
std::atomic<float> m_chunk_gen_fraction{0.0f};
|
||||
@@ -58,38 +58,44 @@ private:
|
||||
void gen_chunks_internal();
|
||||
void sync_player_pos(glm::vec3& player_pos);
|
||||
void compute_required_chunks(ChunkPosSet& required_chunks);
|
||||
void sync_and_collect_missing_chunks(std::vector<ChunkPos>& , const ChunkPosSet&);
|
||||
void build_neighbor_context_for_new_chunks(ConstChunkMap& new_chunks_neighbor, ChunkPtrUpdateList& affected_neighbor, const ChunkUpdateList& new_chunks);
|
||||
void build_neighbor_context_for_affected_neighbors(ChunkPtrUpdateList&, ConstChunkMap&);
|
||||
void sync_and_collect_missing_chunks(std::vector<ChunkPos>&,
|
||||
const ChunkPosSet&);
|
||||
void
|
||||
build_neighbor_context_for_new_chunks(ConstChunkMap& new_chunks_neighbor,
|
||||
ChunkPtrUpdateList& affected_neighbor,
|
||||
const ChunkUpdateList& new_chunks);
|
||||
void build_neighbor_context_for_affected_neighbors(ChunkPtrUpdateList&,
|
||||
ConstChunkMap&);
|
||||
void start_gen_thread();
|
||||
void stop_gen_thread();
|
||||
|
||||
public:
|
||||
|
||||
World();
|
||||
~World();
|
||||
|
||||
bool can_move(const AABB& player_box) const;
|
||||
//const BlockRenderData& get_block_render_data(int x, int y ,int z);
|
||||
|
||||
const std::optional<LookBlock>& get_look_block_pos(const std::string& name) const;
|
||||
// const BlockRenderData& get_block_render_data(int x, int y ,int z);
|
||||
|
||||
const std::optional<LookBlock>&
|
||||
get_look_block_pos(const std::string& name) const;
|
||||
const Chunk* get_chunk(const ChunkPos& pos) const;
|
||||
|
||||
Player& get_player(const std::string& name);
|
||||
void init_world();
|
||||
bool is_aabb_in_frustum(const glm::vec3& center, const glm::vec3& half_extents);
|
||||
bool is_aabb_in_frustum(const glm::vec3& center,
|
||||
const glm::vec3& half_extents);
|
||||
|
||||
int get_block(const glm::ivec3& block_pos) const;
|
||||
bool is_block(const glm::ivec3& block_pos) const;
|
||||
|
||||
|
||||
static ChunkPos chunk_pos(int world_x, int world_z);
|
||||
|
||||
void need_gen();
|
||||
void render(const glm::mat4& mvp_matrix);
|
||||
|
||||
|
||||
void set_block(const glm::ivec3& pos, unsigned id);
|
||||
void update(float delta_time);
|
||||
|
||||
|
||||
void push_delete_vbo(GLuint vbo);
|
||||
|
||||
void hot_reload();
|
||||
@@ -101,4 +107,4 @@ public:
|
||||
void rendering_distance(int rendering_distance);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
struct MoveState {
|
||||
bool forward = false;
|
||||
bool back = false;
|
||||
@@ -30,10 +29,8 @@ struct InputState {
|
||||
};
|
||||
|
||||
namespace Input {
|
||||
InputState& get_input_state();
|
||||
InputState& get_input_state();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -8,12 +8,12 @@ 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 unsigned get_id_from_name(const std::string& name);
|
||||
static void init_map();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -39,12 +39,12 @@ constexpr float VERTICES_POS[6][6][3] = {
|
||||
{0.0f, 1.0f, 1.0f}, // front left
|
||||
{0.0f, 1.0f, 0.0f}}, // back left
|
||||
// ===== bottom (y = -1) =====
|
||||
{{0.0f, 0.0f, 1.0f}, // front left
|
||||
{1.0f, 0.0f, 1.0f}, // front right
|
||||
{1.0f, 0.0f, 0.0f}, // back right
|
||||
{1.0f, 0.0f, 0.0f}, // back right
|
||||
{0.0f, 0.0f, 0.0f}, // back left
|
||||
{0.0f, 0.0f, 1.0f}} // front left
|
||||
{{0.0f, 0.0f, 1.0f}, // front left
|
||||
{1.0f, 0.0f, 1.0f}, // front right
|
||||
{1.0f, 0.0f, 0.0f}, // back right
|
||||
{1.0f, 0.0f, 0.0f}, // back right
|
||||
{0.0f, 0.0f, 0.0f}, // back left
|
||||
{0.0f, 0.0f, 1.0f}} // front left
|
||||
};
|
||||
|
||||
constexpr float TEX_COORDS[6][6][2] = {
|
||||
@@ -84,49 +84,34 @@ constexpr float TEX_COORDS[6][6][2] = {
|
||||
{0.0f, 1.0f}, // front left
|
||||
{0.0f, 0.0f}}, // back left
|
||||
// ===== bottom (y = -1) =====
|
||||
{{0.0f, 0.0f}, // front left
|
||||
{1.0f, 0.0f}, // front right
|
||||
{1.0f, 1.0f}, // back right
|
||||
{1.0f, 1.0f}, // back right
|
||||
{0.0f, 1.0f}, // back left
|
||||
{0.0f, 0.0f}} // front left
|
||||
{{0.0f, 0.0f}, // front left
|
||||
{1.0f, 0.0f}, // front right
|
||||
{1.0f, 1.0f}, // back right
|
||||
{1.0f, 1.0f}, // back right
|
||||
{0.0f, 1.0f}, // back left
|
||||
{0.0f, 0.0f}} // front left
|
||||
};
|
||||
|
||||
constexpr float CUBE_VER[24] = {
|
||||
0.0, 0.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
1.0, 1.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0,
|
||||
1.0, 0.0, 1.0,
|
||||
1.0, 1.0, 1.0,
|
||||
0.0, 1.0, 1.0
|
||||
};
|
||||
constexpr float CUBE_VER[24] = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0,
|
||||
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0,
|
||||
0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0};
|
||||
|
||||
|
||||
constexpr int OUTLINE_CUBE_INDICES[24] = {
|
||||
0,1, 1,2, 2,3, 3,0,
|
||||
4,5, 5,6, 6,7, 7,4,
|
||||
0,4, 1,5, 2,6, 3,7
|
||||
};
|
||||
constexpr int OUTLINE_CUBE_INDICES[24] = {0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6,
|
||||
6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7};
|
||||
|
||||
constexpr float SQUARE_VERTICES[6][2] = {
|
||||
{-0.5f, -0.5f}, // bottom left
|
||||
{-0.5f, 0.5f}, // top left
|
||||
{ 0.5f, 0.5f}, // top right
|
||||
{ 0.5f, 0.5f}, // top right
|
||||
{ 0.5f, -0.5f}, // bottom right
|
||||
{-0.5f, -0.5f} // bottom left
|
||||
{-0.5f, -0.5f}, // bottom left
|
||||
{-0.5f, 0.5f}, // top left
|
||||
{0.5f, 0.5f}, // top right
|
||||
{0.5f, 0.5f}, // top right
|
||||
{0.5f, -0.5f}, // bottom right
|
||||
{-0.5f, -0.5f} // bottom left
|
||||
};
|
||||
|
||||
constexpr float SQUARE_TEXTURE_POS[6][2] = {
|
||||
{0.0f, 0.0f},
|
||||
{0.0f, 1.0f},
|
||||
{1.0f, 1.0f},
|
||||
{1.0f, 1.0f},
|
||||
{1.0f, 0.0f},
|
||||
{0.0f, 0.0f},
|
||||
};
|
||||
{0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f},
|
||||
{1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 0.0f},
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||
@@ -140,4 +125,4 @@ struct Vertex2D {
|
||||
float layer = 0.0f;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,12 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/constants.hpp>
|
||||
#include <Cubed/primitive_data.hpp>
|
||||
#include <Cubed/shader.hpp>
|
||||
#include <Cubed/ui/text.hpp>
|
||||
#include "Cubed/constants.hpp"
|
||||
#include "Cubed/primitive_data.hpp"
|
||||
#include "Cubed/shader.hpp"
|
||||
#include "Cubed/ui/text.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
namespace Cubed {
|
||||
@@ -19,7 +17,8 @@ class Renderer {
|
||||
public:
|
||||
constexpr static int NUM_VAO = 5;
|
||||
|
||||
Renderer(const Camera& camera, World& world, const TextureManager& texture_manager, DevPanel& dev_panel);
|
||||
Renderer(const Camera& camera, World& world,
|
||||
const TextureManager& texture_manager, DevPanel& dev_panel);
|
||||
~Renderer();
|
||||
void hot_reload();
|
||||
void init();
|
||||
@@ -27,8 +26,8 @@ public:
|
||||
void render();
|
||||
void update_fov(float fov);
|
||||
void update_proj_matrix(float aspect, float width, float height);
|
||||
|
||||
private:
|
||||
|
||||
const Camera& m_camera;
|
||||
DevPanel& m_dev_panel;
|
||||
const TextureManager& m_texture_manager;
|
||||
@@ -37,7 +36,7 @@ private:
|
||||
float m_aspect = 0.0f;
|
||||
float m_fov = DEFAULT_FOV;
|
||||
glm::mat4 m_p_mat, m_v_mat, m_m_mat, m_mv_mat, m_mvp_mat;
|
||||
|
||||
|
||||
GLuint m_mv_loc;
|
||||
GLuint m_proj_loc;
|
||||
|
||||
@@ -57,10 +56,10 @@ private:
|
||||
|
||||
void render_outline();
|
||||
void render_sky();
|
||||
void render_text();
|
||||
void render_text();
|
||||
void render_ui();
|
||||
void render_world();
|
||||
void render_dev_panel();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,22 +1,22 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
Shader();
|
||||
Shader(const std::string& name, const std::string& v_shader_path, const std::string& f_shader_path);
|
||||
Shader(const std::string& name, const std::string& v_shader_path,
|
||||
const std::string& f_shader_path);
|
||||
~Shader();
|
||||
Shader(const Shader&) = delete;
|
||||
Shader& operator=(const Shader&) = delete;
|
||||
Shader(Shader&& shader) noexcept;
|
||||
Shader& operator=(Shader&& shader) noexcept;
|
||||
|
||||
void create(const std::string& name, const std::string& v_shader_path, const std::string& f_shader_path);
|
||||
void create(const std::string& name, const std::string& v_shader_path,
|
||||
const std::string& f_shader_path);
|
||||
std::size_t hash() const;
|
||||
GLuint loc(const std::string& loc) const;
|
||||
const std::string& name() const;
|
||||
@@ -26,7 +26,6 @@ private:
|
||||
GLuint m_program = 0;
|
||||
std::size_t m_hash = 0;
|
||||
std::string m_name = "-1";
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,16 +1,15 @@
|
||||
#pragma once
|
||||
#include "Cubed/gameplay/block.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <Cubed/gameplay/block.hpp>
|
||||
#include <Cubed/tools/shader_tools.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
class TextureManager {
|
||||
private:
|
||||
bool m_need_reload = false;
|
||||
GLuint m_block_status_array;
|
||||
GLuint m_texture_array;
|
||||
GLuint m_texture_array;
|
||||
GLuint m_ui_array;
|
||||
GLfloat m_max_aniso = 0.0f;
|
||||
int m_aniso = 1;
|
||||
@@ -21,8 +20,8 @@ private:
|
||||
public:
|
||||
TextureManager();
|
||||
~TextureManager();
|
||||
|
||||
void delet_texture();
|
||||
|
||||
void delet_texture();
|
||||
GLuint get_block_status_array() const;
|
||||
GLuint get_texture_array() const;
|
||||
GLuint get_ui_array() const;
|
||||
@@ -34,5 +33,4 @@ public:
|
||||
int max_aniso() const;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,37 +1,34 @@
|
||||
#pragma once
|
||||
#include <Cubed/tools/log.hpp>
|
||||
#include "Cubed/tools/log.hpp"
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
namespace Assert {
|
||||
inline void msg(const char* condition, const char* file,
|
||||
int line, const char* func,
|
||||
std::string_view message = ""
|
||||
) {
|
||||
|
||||
Logger::error("Assertion failed: {} at {}: {} in function {}",
|
||||
condition, file, line, func);
|
||||
if (message.size()) {
|
||||
Logger::error("Message: {}", message);
|
||||
}
|
||||
std::abort();
|
||||
inline void msg(const char* condition, const char* file, int line,
|
||||
const char* func, std::string_view message = "") {
|
||||
|
||||
Logger::error("Assertion failed: {} at {}: {} in function {}", condition,
|
||||
file, line, func);
|
||||
if (message.size()) {
|
||||
Logger::error("Message: {}", message);
|
||||
}
|
||||
std::abort();
|
||||
}
|
||||
} // namespace Assert
|
||||
|
||||
#ifdef DEBUG_MODE
|
||||
#define ASSERT(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
::Cubed::Assert::msg(#cond, __FILE__, __LINE__, __func__); \
|
||||
} \
|
||||
#define ASSERT(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
::Cubed::Assert::msg(#cond, __FILE__, __LINE__, __func__); \
|
||||
} \
|
||||
} while (0)
|
||||
#define ASSERT_MSG(cond, message) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
::Cubed::Assert::msg(#cond, __FILE__, __LINE__, __func__, message); \
|
||||
} \
|
||||
#define ASSERT_MSG(cond, message) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
::Cubed::Assert::msg(#cond, __FILE__, __LINE__, __func__, \
|
||||
message); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
@@ -39,4 +36,4 @@ namespace Assert {
|
||||
#define ASSERT_MSG(cond, message) ((void)0)
|
||||
#endif
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,33 +1,32 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
namespace HASH {
|
||||
inline std::size_t str(std::string_view value) {
|
||||
return std::hash<std::string_view>{}(value);
|
||||
}
|
||||
inline uint32_t mix_hash(int32_t a, int32_t b, uint32_t fixed_seed) {
|
||||
uint32_t h = fixed_seed;
|
||||
|
||||
h ^= (uint32_t)a * 0xcc9e2d51u;
|
||||
h = (h << 15) | (h >> 17); // rotl 15
|
||||
h *= 0x1b873593u;
|
||||
|
||||
h ^= (uint32_t)b * 0xcc9e2d51u;
|
||||
h = (h << 15) | (h >> 17); // rotl 15
|
||||
h *= 0x1b873593u;
|
||||
|
||||
// Finalization(avalanche)
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6bu;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35u;
|
||||
h ^= h >> 16;
|
||||
|
||||
return h;
|
||||
}
|
||||
inline std::size_t str(std::string_view value) {
|
||||
return std::hash<std::string_view>{}(value);
|
||||
}
|
||||
inline uint32_t mix_hash(int32_t a, int32_t b, uint32_t fixed_seed) {
|
||||
uint32_t h = fixed_seed;
|
||||
|
||||
}
|
||||
h ^= (uint32_t)a * 0xcc9e2d51u;
|
||||
h = (h << 15) | (h >> 17); // rotl 15
|
||||
h *= 0x1b873593u;
|
||||
|
||||
h ^= (uint32_t)b * 0xcc9e2d51u;
|
||||
h = (h << 15) | (h >> 17); // rotl 15
|
||||
h *= 0x1b873593u;
|
||||
|
||||
// Finalization(avalanche)
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6bu;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35u;
|
||||
h ^= h >> 16;
|
||||
|
||||
return h;
|
||||
}
|
||||
} // namespace HASH
|
||||
|
||||
} // namespace Cubed
|
||||
@@ -17,5 +17,4 @@ private:
|
||||
std::mt19937 m_engine;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#include "Cubed/primitive_data.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <Cubed/primitive_data.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
struct Character {
|
||||
glm::vec2 uv_min;
|
||||
glm::vec2 uv_max;
|
||||
@@ -28,9 +26,12 @@ public:
|
||||
Font();
|
||||
~Font();
|
||||
|
||||
static std::vector<Vertex2D> vertices(const std::string& text, float x = 0.0f, float y = 0.0f, float scale = 1.0f);
|
||||
static std::vector<Vertex2D> vertices(const std::string& text,
|
||||
float x = 0.0f, float y = 0.0f,
|
||||
float scale = 1.0f);
|
||||
static GLuint text_texture();
|
||||
static const std::string& font_path();
|
||||
|
||||
private:
|
||||
FT_Library m_ft;
|
||||
FT_Face m_face;
|
||||
@@ -39,13 +40,12 @@ private:
|
||||
float m_texture_height = 64;
|
||||
|
||||
static inline GLuint m_text_texture;
|
||||
static inline std::string m_font_path{ASSETS_PATH "fonts/IBMPlexSans-Regular.ttf"};
|
||||
static inline std::string m_font_path{ASSETS_PATH
|
||||
"fonts/IBMPlexSans-Regular.ttf"};
|
||||
std::unordered_map<char8_t, Character> m_characters;
|
||||
|
||||
void load_character(char8_t c);
|
||||
void setup_font_character();
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,102 +1,85 @@
|
||||
#pragma once
|
||||
#include <syncstream>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <syncstream>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
namespace Logger {
|
||||
enum class Level {
|
||||
TRACE,
|
||||
DEBUG,
|
||||
INFO,
|
||||
ERROR,
|
||||
WARN
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
inline void info(std::format_string<Args...> fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::
|
||||
time_point_cast<std::chrono::seconds>
|
||||
(std::chrono::system_clock::now());
|
||||
|
||||
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
std::osyncstream(std::cout) << "\033[1;32m"
|
||||
<< std::format("[INFO][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg
|
||||
<< "\033[0m"
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void error(std::format_string<Args...> fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::
|
||||
time_point_cast<std::chrono::seconds>
|
||||
(std::chrono::system_clock::now());
|
||||
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
std::osyncstream(std::cerr) << "\033[1;31m"
|
||||
<< std::format("[ERROR][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg
|
||||
<< "\033[0m"
|
||||
<< "\n";
|
||||
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void warn(std::format_string<Args...> fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::
|
||||
time_point_cast<std::chrono::seconds>
|
||||
(std::chrono::system_clock::now());
|
||||
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
std::osyncstream(std::cout) << "\033[1;33m"
|
||||
<< std::format("[WARN][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg
|
||||
<< "\033[0m"
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void log(Level level, std::source_location loc, std::format_string<Args...> fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::
|
||||
time_point_cast<std::chrono::seconds>
|
||||
(std::chrono::system_clock::now());
|
||||
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
switch (level) {
|
||||
case Logger::Level::TRACE:
|
||||
std::osyncstream(std::cout) << "\033[1;34m"
|
||||
<< std::format("[TRACE][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< "[" << loc.file_name() << ":" << loc.line() << "]"
|
||||
<< "[" << loc.function_name() << "]"
|
||||
<< msg
|
||||
<< "\033[0m"
|
||||
<< "\n";
|
||||
break;
|
||||
case Logger::Level::DEBUG:
|
||||
std::osyncstream(std::cout) << "\033[1;34m"
|
||||
<< std::format("[DEBUG][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg
|
||||
<< "\033[0m"
|
||||
<< "\n";
|
||||
break;
|
||||
case Logger::Level::INFO:
|
||||
info(fmt, std::forward<Args>(args)...);
|
||||
break;
|
||||
case Logger::Level::WARN:
|
||||
warn(fmt, std::forward<Args>(args)...);
|
||||
break;
|
||||
case Logger::Level::ERROR:
|
||||
error(fmt, std::forward<Args>(args)...);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
enum class Level { TRACE, DEBUG, INFO, ERROR, WARN };
|
||||
|
||||
template <typename... Args>
|
||||
inline void info(std::format_string<Args...> fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::time_point_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now());
|
||||
|
||||
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
std::osyncstream(std::cout)
|
||||
<< "\033[1;32m" << std::format("[INFO][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg << "\033[0m"
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void error(std::format_string<Args...> fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::time_point_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now());
|
||||
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
std::osyncstream(std::cerr)
|
||||
<< "\033[1;31m"
|
||||
<< std::format("[ERROR][{:%Y-%m-%d %H:%M:%S}]", now_time) << msg
|
||||
<< "\033[0m"
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void warn(std::format_string<Args...> fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::time_point_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now());
|
||||
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
std::osyncstream(std::cout)
|
||||
<< "\033[1;33m" << std::format("[WARN][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg << "\033[0m"
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void log(Level level, std::source_location loc,
|
||||
std::format_string<Args...> fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::time_point_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now());
|
||||
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||
switch (level) {
|
||||
case Logger::Level::TRACE:
|
||||
std::osyncstream(std::cout)
|
||||
<< "\033[1;34m"
|
||||
<< std::format("[TRACE][{:%Y-%m-%d %H:%M:%S}]", now_time) << "["
|
||||
<< loc.file_name() << ":" << loc.line() << "]"
|
||||
<< "[" << loc.function_name() << "]" << msg << "\033[0m"
|
||||
<< "\n";
|
||||
break;
|
||||
case Logger::Level::DEBUG:
|
||||
std::osyncstream(std::cout)
|
||||
<< "\033[1;34m"
|
||||
<< std::format("[DEBUG][{:%Y-%m-%d %H:%M:%S}]", now_time) << msg
|
||||
<< "\033[0m"
|
||||
<< "\n";
|
||||
break;
|
||||
case Logger::Level::INFO:
|
||||
info(fmt, std::forward<Args>(args)...);
|
||||
break;
|
||||
case Logger::Level::WARN:
|
||||
warn(fmt, std::forward<Args>(args)...);
|
||||
break;
|
||||
case Logger::Level::ERROR:
|
||||
error(fmt, std::forward<Args>(args)...);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Logger
|
||||
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
namespace Math {
|
||||
void extract_frustum_planes(const glm::mat4& mvp_matrix, std::vector<glm::vec4>& planes);
|
||||
void extract_frustum_planes(const glm::mat4& mvp_matrix,
|
||||
std::vector<glm::vec4>& planes);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -4,19 +4,18 @@
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
class PerlinNoise {
|
||||
public:
|
||||
static void init(unsigned seed);
|
||||
static float noise(float x, float y, float z);
|
||||
static void reload(unsigned seed);
|
||||
|
||||
private:
|
||||
static inline std::atomic<bool> is_init = false;
|
||||
static inline std::vector<int> p;
|
||||
static float fade(float t);
|
||||
static float lerp(float t, float a, float b);
|
||||
static float grad(int hash, float x, float y, float z);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,21 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <SOIL2.h>
|
||||
#include <glad/glad.h>
|
||||
#include <string>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
namespace Tools {
|
||||
GLuint create_shader_program(const std::string& v_shader_path, const std::string& f_shader_path);
|
||||
void print_shader_log(GLuint shader);
|
||||
void print_program_info(int prog);
|
||||
bool check_opengl_error();
|
||||
std::string read_shader_source(const std::string& file_path);
|
||||
void delete_image_data(unsigned char* data);
|
||||
unsigned char* load_image_data(const std::string& tex_image_path);
|
||||
GLuint create_shader_program(const std::string& v_shader_path,
|
||||
const std::string& f_shader_path);
|
||||
void print_shader_log(GLuint shader);
|
||||
void print_program_info(int prog);
|
||||
bool check_opengl_error();
|
||||
std::string read_shader_source(const std::string& file_path);
|
||||
void delete_image_data(unsigned char* data);
|
||||
unsigned char* load_image_data(const std::string& tex_image_path);
|
||||
|
||||
}
|
||||
} // namespace Tools
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -1,36 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/tools/log.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <Cubed/tools/log.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
typedef LONG (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
|
||||
#include <windows.h>
|
||||
typedef LONG(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
|
||||
#elif defined(__linux__)
|
||||
#include <fstream>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
namespace Tools {
|
||||
|
||||
inline bool get_os_version(std::string& str) {
|
||||
#ifdef _WIN32
|
||||
HMODULE hntdll = GetModuleHandleW(L"ntdll.dll");
|
||||
if (!hntdll) return false;
|
||||
if (!hntdll)
|
||||
return false;
|
||||
|
||||
auto prtl_get_version = reinterpret_cast<RtlGetVersionPtr>(
|
||||
GetProcAddress(hntdll, "RtlGetVersion"));
|
||||
if (!prtl_get_version) return false;
|
||||
if (!prtl_get_version)
|
||||
return false;
|
||||
|
||||
RTL_OSVERSIONINFOW osvi = { 0 };
|
||||
RTL_OSVERSIONINFOW osvi = {0};
|
||||
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||
if (prtl_get_version(&osvi) != 0) return false;
|
||||
if (prtl_get_version(&osvi) != 0)
|
||||
return false;
|
||||
if (osvi.dwMajorVersion == 10) {
|
||||
if (osvi.dwBuildNumber >= 22000) {
|
||||
str = "Windows 11 Build " + std::to_string(osvi.dwBuildNumber);
|
||||
@@ -58,7 +61,7 @@ inline bool get_os_version(std::string& str) {
|
||||
continue;
|
||||
}
|
||||
str = line.substr(eq_pos + 1);
|
||||
|
||||
|
||||
if (str.size() >= 2 && str.front() == '"' && str.back() == '"') {
|
||||
str = str.substr(1, str.size() - 2);
|
||||
return true;
|
||||
@@ -74,7 +77,8 @@ inline bool get_os_version(std::string& str) {
|
||||
inline size_t get_current_rss() {
|
||||
#ifdef _WIN32
|
||||
PROCESS_MEMORY_COUNTERS_EX pmc;
|
||||
if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc))) {
|
||||
if (GetProcessMemoryInfo(GetCurrentProcess(),
|
||||
(PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc))) {
|
||||
return pmc.WorkingSetSize;
|
||||
}
|
||||
return 0;
|
||||
@@ -94,19 +98,25 @@ inline std::string get_cpu_info() {
|
||||
#ifdef _WIN32
|
||||
HKEY h_key;
|
||||
std::string cpu_name;
|
||||
|
||||
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
|
||||
0, KEY_READ, &h_key) == ERROR_SUCCESS) {
|
||||
|
||||
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0,
|
||||
KEY_READ, &h_key) == ERROR_SUCCESS) {
|
||||
|
||||
DWORD dw_size = 0;
|
||||
if (RegQueryValueExW(h_key, L"ProcessorNameString", NULL, NULL, NULL, &dw_size) == ERROR_SUCCESS && dw_size > 0) {
|
||||
if (RegQueryValueExW(h_key, L"ProcessorNameString", NULL, NULL, NULL,
|
||||
&dw_size) == ERROR_SUCCESS &&
|
||||
dw_size > 0) {
|
||||
std::vector<wchar_t> buffer(dw_size / sizeof(wchar_t));
|
||||
if (RegQueryValueExW(h_key, L"ProcessorNameString", NULL, NULL, (LPBYTE)buffer.data(), &dw_size) == ERROR_SUCCESS) {
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, buffer.data(), -1, NULL, 0, NULL, NULL);
|
||||
if (RegQueryValueExW(h_key, L"ProcessorNameString", NULL, NULL,
|
||||
(LPBYTE)buffer.data(),
|
||||
&dw_size) == ERROR_SUCCESS) {
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, buffer.data(), -1,
|
||||
NULL, 0, NULL, NULL);
|
||||
if (len > 0) {
|
||||
std::vector<char> narrow(len);
|
||||
WideCharToMultiByte(CP_UTF8, 0, buffer.data(), -1, narrow.data(), len, NULL, NULL);
|
||||
WideCharToMultiByte(CP_UTF8, 0, buffer.data(), -1,
|
||||
narrow.data(), len, NULL, NULL);
|
||||
cpu_name = narrow.data();
|
||||
}
|
||||
}
|
||||
@@ -117,7 +127,7 @@ inline std::string get_cpu_info() {
|
||||
cpu_name = "Unknown";
|
||||
}
|
||||
return cpu_name;
|
||||
#elif defined (__linux__)
|
||||
#elif defined(__linux__)
|
||||
std::ifstream file("/proc/cpuinfo");
|
||||
if (!file.is_open()) {
|
||||
return std::string{"Unkown"};
|
||||
@@ -141,8 +151,6 @@ inline std::string get_cpu_info() {
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Tools
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#include <Cubed/tools/cubed_assert.hpp>
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
enum class Color {
|
||||
BLACK,
|
||||
WHITE,
|
||||
@@ -25,37 +25,36 @@ inline constexpr glm::vec4 color_value(Color color) {
|
||||
using glm::vec4;
|
||||
|
||||
switch (color) {
|
||||
case Color::BLACK:
|
||||
return vec4{0.0f, 0.0f, 0.0f, 1.0f};
|
||||
case Color::WHITE:
|
||||
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::RED:
|
||||
return vec4{1.0f, 0.0f, 0.0f, 1.0f};
|
||||
case Color::GREEN:
|
||||
return vec4{0.0f, 1.0f, 0.0f, 1.0f};
|
||||
case Color::BLUE:
|
||||
return vec4{0.0f, 0.0f, 1.0f, 1.0f};
|
||||
case Color::YELLOW:
|
||||
return vec4{1.0f, 1.0f, 0.0f, 1.0f};
|
||||
case Color::CYAN:
|
||||
return vec4{0.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::MAGENTA:
|
||||
return vec4{1.0f, 0.0f, 1.0f, 1.0f};
|
||||
case Color::GRAY:
|
||||
return vec4{0.5f, 0.5f, 0.5f, 1.0f};
|
||||
case Color::ORANGE:
|
||||
return vec4{1.0f, 0.647f, 0.0f, 1.0f};
|
||||
case Color::PURPLE:
|
||||
return vec4{0.502f, 0.0f, 0.502f, 1.0f};
|
||||
case Color::PINK:
|
||||
return vec4{1.0f, 0.753f, 0.769f, 1.0f};
|
||||
case Color::BROWN:
|
||||
return vec4{0.647f, 0.165f, 0.165f, 1.0f};
|
||||
default:
|
||||
ASSERT_MSG(false, "Unknown Color");
|
||||
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::BLACK:
|
||||
return vec4{0.0f, 0.0f, 0.0f, 1.0f};
|
||||
case Color::WHITE:
|
||||
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::RED:
|
||||
return vec4{1.0f, 0.0f, 0.0f, 1.0f};
|
||||
case Color::GREEN:
|
||||
return vec4{0.0f, 1.0f, 0.0f, 1.0f};
|
||||
case Color::BLUE:
|
||||
return vec4{0.0f, 0.0f, 1.0f, 1.0f};
|
||||
case Color::YELLOW:
|
||||
return vec4{1.0f, 1.0f, 0.0f, 1.0f};
|
||||
case Color::CYAN:
|
||||
return vec4{0.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::MAGENTA:
|
||||
return vec4{1.0f, 0.0f, 1.0f, 1.0f};
|
||||
case Color::GRAY:
|
||||
return vec4{0.5f, 0.5f, 0.5f, 1.0f};
|
||||
case Color::ORANGE:
|
||||
return vec4{1.0f, 0.647f, 0.0f, 1.0f};
|
||||
case Color::PURPLE:
|
||||
return vec4{0.502f, 0.0f, 0.502f, 1.0f};
|
||||
case Color::PINK:
|
||||
return vec4{1.0f, 0.753f, 0.769f, 1.0f};
|
||||
case Color::BROWN:
|
||||
return vec4{0.647f, 0.165f, 0.165f, 1.0f};
|
||||
default:
|
||||
ASSERT_MSG(false, "Unknown Color");
|
||||
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline glm::vec4 rgb255_to_float(int r, int g, int b, int a) {
|
||||
@@ -67,4 +66,4 @@ inline glm::vec4 rgb255_to_float(int r, int g, int b, int a) {
|
||||
return glm::vec4{nr, ng, nb, na};
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,32 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/primitive_data.hpp"
|
||||
#include "Cubed/ui/color.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/primitive_data.hpp>
|
||||
#include <Cubed/ui/color.hpp>
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
class Shader;
|
||||
|
||||
class Text {
|
||||
public:
|
||||
explicit Text(std::string_view name);
|
||||
Text(std::string_view name, std::string_view str, glm::vec2 pos = glm::vec2{0.0f, 0.0f}, Color color = Color::BLACK);
|
||||
Text(std::string_view name, std::string_view str,
|
||||
glm::vec2 pos = glm::vec2{0.0f, 0.0f}, Color color = Color::BLACK);
|
||||
~Text();
|
||||
Text(const Text&) = delete;
|
||||
Text(Text&&) noexcept;
|
||||
Text& operator=(const Text&) = delete;
|
||||
Text& operator=(Text&&) noexcept = delete;
|
||||
Text& color(Color color);
|
||||
//Text& color(const glm::vec4& color, int pos);
|
||||
// Text& color(const glm::vec4& color, int pos);
|
||||
Text& position(float x, float y);
|
||||
Text& scale(float s);
|
||||
Text& text(std::string_view str);
|
||||
|
||||
|
||||
std::size_t uuid() const;
|
||||
static void set_loc(const Shader& shader);
|
||||
void render();
|
||||
@@ -42,7 +41,7 @@ private:
|
||||
std::string m_text;
|
||||
glm::vec4 m_color{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
glm::mat4 m_model_matrix;
|
||||
|
||||
|
||||
std::vector<Vertex2D> m_vertices;
|
||||
GLuint m_vbo = 0;
|
||||
static inline GLuint m_color_loc = 0;
|
||||
@@ -50,7 +49,6 @@ private:
|
||||
|
||||
void update_vertices();
|
||||
void upload_to_gpu();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
namespace Cubed{
|
||||
namespace Cubed {
|
||||
|
||||
class Renderer;
|
||||
class Window {
|
||||
@@ -19,7 +20,7 @@ public:
|
||||
|
||||
void toggle_fullscreen();
|
||||
void toggle_mouse_able();
|
||||
|
||||
|
||||
private:
|
||||
bool m_mouse_enable = false;
|
||||
float m_aspect;
|
||||
@@ -27,7 +28,6 @@ private:
|
||||
int m_width;
|
||||
int m_height;
|
||||
Renderer& m_renderer;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user