feat: add world and player tab item

This commit is contained in:
2026-04-25 18:36:13 +08:00
parent 8b5717a655
commit a95ad796ce
10 changed files with 260 additions and 38 deletions

View File

@@ -16,6 +16,11 @@ constexpr int PRE_LOAD_DISTANCE = 24;
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_DECELERATION = 15.0f;
constexpr float DEFAULT_G = 22.5f;
using HeightMapArray = std::array<std::array<float, CHUCK_SIZE>, CHUCK_SIZE>;

View File

@@ -16,6 +16,13 @@ class DevPanel {
int height;
int rendering_distance;
};
struct PlayerProfile {
int game_mode = 0;
int gait = 0;
};
struct TextEditing {
bool perlin_seed = false;
};
public:
DevPanel(App& app);
void init();
@@ -25,12 +32,16 @@ private:
App& m_app;
ConfigView m_config;
Player* m_player;
PlayerProfile m_player_profile;
TextEditing m_text_editing;
bool m_need_save_config = false;
int m_theme = 0;
void show_settings_tab_item();
void show_world_tab_item();
void show_player_tab_item();
void update_player_profile();
};

View File

@@ -7,7 +7,7 @@ namespace Cubed {
enum class GameMode {
CREATIVE,
CREATIVE = 0,
SPECTATOR
};

View File

@@ -3,6 +3,7 @@
#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>
@@ -14,7 +15,7 @@
namespace Cubed {
enum class Gait{
WALK,
WALK = 0,
RUN
};
@@ -23,27 +24,28 @@ class World;
class Player {
private:
using enum GameMode;
constexpr static float WALK_SPEED = 4.5f;
constexpr static float RUN_SPEED = 7.0f;
constexpr static float ACCELERATION = 10.0f;
constexpr static float DECELERATION = 15.0f;
constexpr static float G = 22.5f;
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_deceleration = DEFAULT_DECELERATION;
float m_g = DEFAULT_G;
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 max_speed = WALK_SPEED;
float y_speed = 0.0f;
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 speed = 0;
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};
@@ -91,7 +93,15 @@ public:
void update_player_move_state(int key, int action);
void update_scroll(double yoffset);
float& max_walk_speed();
float& max_run_speed();
float& max_speed();
float& acceleration();
float& deceleration();
float& g();
Gait& gait();
GameMode& game_mode();
};

View File

@@ -28,8 +28,6 @@ private:
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>;
bool m_could_gen = true;
glm::vec3 m_gen_player_pos{0.0f, 0.0f, 0.0f};
std::unordered_map<ChunkPos , Chunk, ChunkPos::Hash> m_chunks;
@@ -46,6 +44,8 @@ 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_could_gen{true};
std::atomic<int> m_rendering_distance{24};
std::vector<ChunkPos> m_dirty_queue;
std::vector<ChunkRenderSnapshot> m_render_snapshots;
@@ -93,6 +93,8 @@ public:
void hot_reload();
void rebuild_world();
};
}

View File

@@ -9,13 +9,18 @@ class PerlinNoise {
public:
static void init();
static float noise(float x, float y, float z);
static void reload();
static const unsigned& seed();
static void seed(unsigned seed);
private:
static inline std::atomic<bool> is_init = false;
static inline std::vector<int> p;
static inline unsigned m_seed = 0;
static inline bool is_seed_change = false;
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);
};
}