mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
refactor(gameplay): rename ClientPlayer to LocalPlayer
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
class ClientPlayer;
|
class LocalPlayer;
|
||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
private:
|
private:
|
||||||
@@ -18,7 +18,7 @@ private:
|
|||||||
THIRD_PERSON_FRONT,
|
THIRD_PERSON_FRONT,
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientPlayer* m_player;
|
LocalPlayer* m_player;
|
||||||
float m_last_mouse_x, m_last_mouse_y;
|
float m_last_mouse_x, m_last_mouse_y;
|
||||||
glm::vec3 m_camera_pos;
|
glm::vec3 m_camera_pos;
|
||||||
bool m_under_water = false;
|
bool m_under_water = false;
|
||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
|
|
||||||
void update_move_camera();
|
void update_move_camera();
|
||||||
|
|
||||||
void camera_init(ClientPlayer* player);
|
void camera_init(LocalPlayer* player);
|
||||||
void hot_reload();
|
void hot_reload();
|
||||||
void update_cursor_position_camera(float offset_x, float offset_y);
|
void update_cursor_position_camera(float offset_x, float offset_y);
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
void change_perspective();
|
void change_perspective();
|
||||||
bool is_first_person() const;
|
bool is_first_person() const;
|
||||||
bool handle_event(const Event& e);
|
bool handle_event(const Event& e);
|
||||||
ClientPlayer* player();
|
LocalPlayer* player();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Cubed
|
} // namespace Cubed
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
class WorldScene;
|
class WorldScene;
|
||||||
class ClientPlayer;
|
class LocalPlayer;
|
||||||
class App;
|
class App;
|
||||||
class DevPanel {
|
class DevPanel {
|
||||||
struct ConfigView {
|
struct ConfigView {
|
||||||
@@ -42,7 +42,7 @@ private:
|
|||||||
WorldScene& m_world_scene;
|
WorldScene& m_world_scene;
|
||||||
Config& m_config;
|
Config& m_config;
|
||||||
ConfigView m_config_view;
|
ConfigView m_config_view;
|
||||||
ClientPlayer* m_player;
|
LocalPlayer* m_player;
|
||||||
PlayerProfile m_player_profile;
|
PlayerProfile m_player_profile;
|
||||||
bool m_need_save_config = false;
|
bool m_need_save_config = false;
|
||||||
bool m_gen_thread_running = true;
|
bool m_gen_thread_running = true;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
#include "Cubed/gameplay/chat_message.hpp"
|
#include "Cubed/gameplay/chat_message.hpp"
|
||||||
#include "Cubed/gameplay/chunk_pos.hpp"
|
#include "Cubed/gameplay/chunk_pos.hpp"
|
||||||
#include "Cubed/gameplay/client_chunk.hpp"
|
#include "Cubed/gameplay/client_chunk.hpp"
|
||||||
#include "Cubed/gameplay/client_player.hpp"
|
|
||||||
#include "Cubed/gameplay/game_time.hpp"
|
#include "Cubed/gameplay/game_time.hpp"
|
||||||
|
#include "Cubed/gameplay/local_player.hpp"
|
||||||
#include "Cubed/gameplay/network_client.hpp"
|
#include "Cubed/gameplay/network_client.hpp"
|
||||||
#include "Cubed/gameplay/player_data.hpp"
|
#include "Cubed/gameplay/player_data.hpp"
|
||||||
#include "Cubed/gameplay/world.hpp"
|
#include "Cubed/gameplay/world.hpp"
|
||||||
@@ -37,8 +37,8 @@ public:
|
|||||||
void update_players(float dt);
|
void update_players(float dt);
|
||||||
bool handle_event(const Event& e);
|
bool handle_event(const Event& e);
|
||||||
const std::optional<LookBlock>& get_look_block_pos() const;
|
const std::optional<LookBlock>& get_look_block_pos() const;
|
||||||
ClientPlayer& get_player();
|
LocalPlayer& get_player();
|
||||||
const ClientPlayer& get_player() const;
|
const LocalPlayer& get_player() const;
|
||||||
int get_block(const glm::ivec3& block_pos) const override;
|
int get_block(const glm::ivec3& block_pos) const override;
|
||||||
bool is_solid(const glm::ivec3& block_pos) const override;
|
bool is_solid(const glm::ivec3& block_pos) const override;
|
||||||
bool can_pass_block(const glm::ivec3& block_pos) const override;
|
bool can_pass_block(const glm::ivec3& block_pos) const override;
|
||||||
@@ -131,7 +131,7 @@ private:
|
|||||||
static constexpr int WORLD_EXIT_TIMEOUT = 200;
|
static constexpr int WORLD_EXIT_TIMEOUT = 200;
|
||||||
static constexpr int MAX_UPLOAD_CHUNK_SUM = 16;
|
static constexpr int MAX_UPLOAD_CHUNK_SUM = 16;
|
||||||
|
|
||||||
ClientPlayer m_player;
|
LocalPlayer m_player;
|
||||||
ChunkHashMap m_chunks;
|
ChunkHashMap m_chunks;
|
||||||
AudioEngine& m_audio;
|
AudioEngine& m_audio;
|
||||||
Config& m_config;
|
Config& m_config;
|
||||||
|
|||||||
@@ -17,14 +17,14 @@
|
|||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
class ClientWorld;
|
class ClientWorld;
|
||||||
class ClientPlayer : public Entity {
|
class LocalPlayer : public Entity {
|
||||||
public:
|
public:
|
||||||
static constexpr size_t HOTBAR_SUM = 10;
|
static constexpr size_t HOTBAR_SUM = 10;
|
||||||
static constexpr float WALK_SOUND_INTERVAL = 0.45f;
|
static constexpr float WALK_SOUND_INTERVAL = 0.45f;
|
||||||
static constexpr float RUN_SOUND_INTERVAL = 0.3f;
|
static constexpr float RUN_SOUND_INTERVAL = 0.3f;
|
||||||
using ChunkPosSet = absl::flat_hash_set<ChunkPos, ChunkPos::Hash>;
|
using ChunkPosSet = absl::flat_hash_set<ChunkPos, ChunkPos::Hash>;
|
||||||
ClientPlayer(ClientWorld& world);
|
LocalPlayer(ClientWorld& world);
|
||||||
~ClientPlayer();
|
~LocalPlayer();
|
||||||
|
|
||||||
bool handle_mouse_button_event(const MouseButtonEvent& e);
|
bool handle_mouse_button_event(const MouseButtonEvent& e);
|
||||||
bool handle_key_event(const KeyEvent& e);
|
bool handle_key_event(const KeyEvent& e);
|
||||||
@@ -37,7 +37,7 @@ target_sources(${PROJECT_NAME}
|
|||||||
gameplay/server_chunk.cpp
|
gameplay/server_chunk.cpp
|
||||||
gameplay/client_chunk.cpp
|
gameplay/client_chunk.cpp
|
||||||
gameplay/server_player.cpp
|
gameplay/server_player.cpp
|
||||||
gameplay/client_player.cpp
|
gameplay/local_player.cpp
|
||||||
gameplay/session.cpp
|
gameplay/session.cpp
|
||||||
gameplay/network_client.cpp
|
gameplay/network_client.cpp
|
||||||
render/player_renderer.cpp
|
render/player_renderer.cpp
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "Cubed/camera.hpp"
|
#include "Cubed/camera.hpp"
|
||||||
|
|
||||||
#include "Cubed/gameplay/client_player.hpp"
|
|
||||||
#include "Cubed/gameplay/client_world.hpp"
|
#include "Cubed/gameplay/client_world.hpp"
|
||||||
|
#include "Cubed/gameplay/local_player.hpp"
|
||||||
#include "Cubed/tools/cubed_assert.hpp"
|
#include "Cubed/tools/cubed_assert.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -58,7 +58,7 @@ void Camera::update_move_camera() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::camera_init(ClientPlayer* player) {
|
void Camera::camera_init(LocalPlayer* player) {
|
||||||
m_player = player;
|
m_player = player;
|
||||||
update_move_camera();
|
update_move_camera();
|
||||||
hot_reload();
|
hot_reload();
|
||||||
@@ -100,7 +100,7 @@ void Camera::change_perspective() {
|
|||||||
bool Camera::is_first_person() const {
|
bool Camera::is_first_person() const {
|
||||||
return m_perspective == Perspective::FIRST_PERSON;
|
return m_perspective == Perspective::FIRST_PERSON;
|
||||||
}
|
}
|
||||||
ClientPlayer* Camera::player() { return m_player; }
|
LocalPlayer* Camera::player() { return m_player; }
|
||||||
bool Camera::handle_event(const Event& e) {
|
bool Camera::handle_event(const Event& e) {
|
||||||
return std::visit(
|
return std::visit(
|
||||||
Overloaded{[this](const MouseMoveEvent& e) {
|
Overloaded{[this](const MouseMoveEvent& e) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "Cubed/app.hpp"
|
#include "Cubed/app.hpp"
|
||||||
#include "Cubed/config.hpp"
|
#include "Cubed/config.hpp"
|
||||||
#include "Cubed/gameplay/cave_path.hpp"
|
#include "Cubed/gameplay/cave_path.hpp"
|
||||||
#include "Cubed/gameplay/client_player.hpp"
|
#include "Cubed/gameplay/local_player.hpp"
|
||||||
#include "Cubed/gameplay/river.path.hpp"
|
#include "Cubed/gameplay/river.path.hpp"
|
||||||
#include "Cubed/scene/world_scene.hpp"
|
#include "Cubed/scene/world_scene.hpp"
|
||||||
#include "Cubed/tools/log.hpp"
|
#include "Cubed/tools/log.hpp"
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ const std::optional<LookBlock>& ClientWorld::get_look_block_pos() const {
|
|||||||
return m_player.get_look_block_pos();
|
return m_player.get_look_block_pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientPlayer& ClientWorld::get_player() { return m_player; }
|
LocalPlayer& ClientWorld::get_player() { return m_player; }
|
||||||
const ClientPlayer& ClientWorld::get_player() const { return m_player; }
|
const LocalPlayer& ClientWorld::get_player() const { return m_player; }
|
||||||
int ClientWorld::get_block(const glm::ivec3& block_pos) const {
|
int ClientWorld::get_block(const glm::ivec3& block_pos) const {
|
||||||
auto [chunk_x, chunk_z] = get_chunk_pos(block_pos.x, block_pos.z);
|
auto [chunk_x, chunk_z] = get_chunk_pos(block_pos.x, block_pos.z);
|
||||||
chunk_cacc cacc;
|
chunk_cacc cacc;
|
||||||
@@ -930,13 +930,13 @@ void ClientWorld::update_players(float dt) {
|
|||||||
m_audio.play_3d(sound, player.render_pos.value);
|
m_audio.play_3d(sound, player.render_pos.value);
|
||||||
};
|
};
|
||||||
if (player.walk.gait == Gait::WALK) {
|
if (player.walk.gait == Gait::WALK) {
|
||||||
if (player.walk.moving_time >= ClientPlayer::WALK_SOUND_INTERVAL) {
|
if (player.walk.moving_time >= LocalPlayer::WALK_SOUND_INTERVAL) {
|
||||||
player.walk.moving_time = 0.0f;
|
player.walk.moving_time = 0.0f;
|
||||||
play_walk_sound();
|
play_walk_sound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (player.walk.gait == Gait::RUN) {
|
if (player.walk.gait == Gait::RUN) {
|
||||||
if (player.walk.moving_time >= ClientPlayer::RUN_SOUND_INTERVAL) {
|
if (player.walk.moving_time >= LocalPlayer::RUN_SOUND_INTERVAL) {
|
||||||
player.walk.moving_time = 0.0f;
|
player.walk.moving_time = 0.0f;
|
||||||
play_walk_sound();
|
play_walk_sound();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Cubed/gameplay/client_player.hpp"
|
#include "Cubed/gameplay/local_player.hpp"
|
||||||
|
|
||||||
#include "Cubed/audio/audio_engine.hpp"
|
#include "Cubed/audio/audio_engine.hpp"
|
||||||
#include "Cubed/config.hpp"
|
#include "Cubed/config.hpp"
|
||||||
@@ -10,26 +10,26 @@
|
|||||||
namespace {} // namespace
|
namespace {} // namespace
|
||||||
|
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
ClientPlayer::ClientPlayer(ClientWorld& world)
|
LocalPlayer::LocalPlayer(ClientWorld& world)
|
||||||
: Entity(0, "cubed:player"), m_world(world) {}
|
: Entity(0, "cubed:player"), m_world(world) {}
|
||||||
ClientPlayer::~ClientPlayer() {}
|
LocalPlayer::~LocalPlayer() {}
|
||||||
|
|
||||||
const glm::vec3& ClientPlayer::get_front() const { return m_front; }
|
const glm::vec3& LocalPlayer::get_front() const { return m_front; }
|
||||||
|
|
||||||
const std::optional<LookBlock>& ClientPlayer::get_look_block_pos() const {
|
const std::optional<LookBlock>& LocalPlayer::get_look_block_pos() const {
|
||||||
return m_look_block;
|
return m_look_block;
|
||||||
}
|
}
|
||||||
glm::vec3 ClientPlayer::get_player_pos() const {
|
glm::vec3 LocalPlayer::get_player_pos() const {
|
||||||
|
|
||||||
std::shared_lock lock(m_player_pos_mutex);
|
std::shared_lock lock(m_player_pos_mutex);
|
||||||
return m_pos.value;
|
return m_pos.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MoveState& ClientPlayer::get_move_state() const { return m_move_state; }
|
const MoveState& LocalPlayer::get_move_state() const { return m_move_state; }
|
||||||
|
|
||||||
bool ClientPlayer::ray_cast(const glm::vec3& start, const glm::vec3& front,
|
bool LocalPlayer::ray_cast(const glm::vec3& start, const glm::vec3& front,
|
||||||
glm::ivec3& block_pos, glm::vec3& normal,
|
glm::ivec3& block_pos, glm::vec3& normal,
|
||||||
float distance) {
|
float distance) {
|
||||||
glm::vec3 dir = glm::normalize(front);
|
glm::vec3 dir = glm::normalize(front);
|
||||||
// float step = 0.1f;
|
// float step = 0.1f;
|
||||||
glm::ivec3 cur = glm::floor(start);
|
glm::ivec3 cur = glm::floor(start);
|
||||||
@@ -100,7 +100,7 @@ bool ClientPlayer::ray_cast(const glm::vec3& start, const glm::vec3& front,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::change_mode(GameMode mode) {
|
void LocalPlayer::change_mode(GameMode mode) {
|
||||||
m_game_mode = mode;
|
m_game_mode = mode;
|
||||||
Logger::info("Change GameMode to {}", to_str(mode));
|
Logger::info("Change GameMode to {}", to_str(mode));
|
||||||
if (mode == CREATIVE) {
|
if (mode == CREATIVE) {
|
||||||
@@ -115,17 +115,17 @@ void ClientPlayer::change_mode(GameMode mode) {
|
|||||||
glm::vec3{m_max_run_speed, m_max_y_speed, m_max_run_speed};
|
glm::vec3{m_max_run_speed, m_max_y_speed, m_max_run_speed};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ClientPlayer::reload_config() {
|
void LocalPlayer::reload_config() {
|
||||||
auto& config = m_world.get_config();
|
auto& config = m_world.get_config();
|
||||||
m_sensitivity = config.get("player.mouse_sensitivity", 0.15f);
|
m_sensitivity = config.get("player.mouse_sensitivity", 0.15f);
|
||||||
}
|
}
|
||||||
void ClientPlayer::set_player_pos(const glm::vec3& pos) {
|
void LocalPlayer::set_player_pos(const glm::vec3& pos) {
|
||||||
|
|
||||||
std::lock_guard lock(m_player_pos_mutex);
|
std::lock_guard lock(m_player_pos_mutex);
|
||||||
m_pos.value = pos;
|
m_pos.value = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::update(float delta_time) {
|
void LocalPlayer::update(float delta_time) {
|
||||||
WalkPose pos = m_walk_pose;
|
WalkPose pos = m_walk_pose;
|
||||||
pos.gait = compute_gait();
|
pos.gait = compute_gait();
|
||||||
m_walk_pose = pos;
|
m_walk_pose = pos;
|
||||||
@@ -138,7 +138,7 @@ void ClientPlayer::update(float delta_time) {
|
|||||||
d_rep("speed", "Speed(x, y, z): {:.2} m/s {:.2} m/s {:.2} m/s",
|
d_rep("speed", "Speed(x, y, z): {:.2} m/s {:.2} m/s {:.2} m/s",
|
||||||
m_velocity.value.x, m_velocity.value.y, m_velocity.value.z);
|
m_velocity.value.x, m_velocity.value.y, m_velocity.value.z);
|
||||||
}
|
}
|
||||||
bool ClientPlayer::update_player_move_state(Key key, KeyAction action) {
|
bool LocalPlayer::update_player_move_state(Key key, KeyAction action) {
|
||||||
if (key == Key::W) {
|
if (key == Key::W) {
|
||||||
if (action == KeyAction::PRESS) {
|
if (action == KeyAction::PRESS) {
|
||||||
m_move_state.forward = true;
|
m_move_state.forward = true;
|
||||||
@@ -238,7 +238,7 @@ bool ClientPlayer::update_player_move_state(Key key, KeyAction action) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::update_front_vec(float offset_x, float offset_y) {
|
void LocalPlayer::update_front_vec(float offset_x, float offset_y) {
|
||||||
Orientation& angle = m_angle;
|
Orientation& angle = m_angle;
|
||||||
angle.yaw += offset_x * m_sensitivity;
|
angle.yaw += offset_x * m_sensitivity;
|
||||||
angle.pitch += offset_y * m_sensitivity;
|
angle.pitch += offset_y * m_sensitivity;
|
||||||
@@ -254,7 +254,7 @@ void ClientPlayer::update_front_vec(float offset_x, float offset_y) {
|
|||||||
m_front = glm::normalize(m_front);
|
m_front = glm::normalize(m_front);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::update_direction() {
|
void LocalPlayer::update_direction() {
|
||||||
m_right = glm::normalize(glm::cross(m_front, glm::vec3(0.0f, 1.0f, 0.0f)));
|
m_right = glm::normalize(glm::cross(m_front, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||||
|
|
||||||
glm::vec3 move_dir_front = glm::vec3(0.0f);
|
glm::vec3 move_dir_front = glm::vec3(0.0f);
|
||||||
@@ -279,7 +279,7 @@ void ClientPlayer::update_direction() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::update_lookup_block() {
|
void LocalPlayer::update_lookup_block() {
|
||||||
// calculate the block that is looked
|
// calculate the block that is looked
|
||||||
glm::ivec3 block_pos;
|
glm::ivec3 block_pos;
|
||||||
glm::vec3 block_normal;
|
glm::vec3 block_normal;
|
||||||
@@ -292,7 +292,7 @@ void ClientPlayer::update_lookup_block() {
|
|||||||
m_look_block = std::nullopt;
|
m_look_block = std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ClientPlayer::place_block(float dt) {
|
void LocalPlayer::place_block(float dt) {
|
||||||
|
|
||||||
if (m_look_block == std::nullopt) {
|
if (m_look_block == std::nullopt) {
|
||||||
return;
|
return;
|
||||||
@@ -324,17 +324,17 @@ void ClientPlayer::place_block(float dt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ClientPlayer::selected_hotbar() const { return m_selected_hotbar; }
|
int LocalPlayer::selected_hotbar() const { return m_selected_hotbar; }
|
||||||
void ClientPlayer::set_hotbar(int pos, const ItemStack& item) {
|
void LocalPlayer::set_hotbar(int pos, const ItemStack& item) {
|
||||||
ASSERT(pos >= 0 && static_cast<size_t>(pos) < HOTBAR_SUM);
|
ASSERT(pos >= 0 && static_cast<size_t>(pos) < HOTBAR_SUM);
|
||||||
m_hotbar[pos] = item;
|
m_hotbar[pos] = item;
|
||||||
}
|
}
|
||||||
std::span<const ItemStack, ClientPlayer::HOTBAR_SUM>
|
std::span<const ItemStack, LocalPlayer::HOTBAR_SUM>
|
||||||
ClientPlayer::get_hotbar() const {
|
LocalPlayer::get_hotbar() const {
|
||||||
return m_hotbar;
|
return m_hotbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::update_move(float delta_time) {
|
void LocalPlayer::update_move(float delta_time) {
|
||||||
// if frame rate less than 1 frame per second, don't update
|
// if frame rate less than 1 frame per second, don't update
|
||||||
if (delta_time > 1.0f) {
|
if (delta_time > 1.0f) {
|
||||||
return;
|
return;
|
||||||
@@ -408,7 +408,7 @@ void ClientPlayer::update_move(float delta_time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::update_player_chunk() {
|
void LocalPlayer::update_player_chunk() {
|
||||||
float x, z;
|
float x, z;
|
||||||
{
|
{
|
||||||
std::shared_lock lock(m_player_pos_mutex);
|
std::shared_lock lock(m_player_pos_mutex);
|
||||||
@@ -424,7 +424,7 @@ void ClientPlayer::update_player_chunk() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Gait ClientPlayer::compute_gait() const {
|
Gait LocalPlayer::compute_gait() const {
|
||||||
if (m_velocity.value.x < 0.01f && m_velocity.value.z < 0.01f)
|
if (m_velocity.value.x < 0.01f && m_velocity.value.z < 0.01f)
|
||||||
return Gait::STOP;
|
return Gait::STOP;
|
||||||
|
|
||||||
@@ -434,7 +434,7 @@ Gait ClientPlayer::compute_gait() const {
|
|||||||
return Gait::WALK;
|
return Gait::WALK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientPlayer::update_scroll(float yoffset) {
|
bool LocalPlayer::update_scroll(float yoffset) {
|
||||||
if (m_game_mode == SPECTATOR) {
|
if (m_game_mode == SPECTATOR) {
|
||||||
if (yoffset > 0) {
|
if (yoffset > 0) {
|
||||||
if (m_max_run_speed < 500.0f) {
|
if (m_max_run_speed < 500.0f) {
|
||||||
@@ -462,7 +462,7 @@ bool ClientPlayer::update_scroll(float yoffset) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientPlayer::handle_mouse_button_event(const MouseButtonEvent& e) {
|
bool LocalPlayer::handle_mouse_button_event(const MouseButtonEvent& e) {
|
||||||
if (e.action == KeyAction::PRESS) {
|
if (e.action == KeyAction::PRESS) {
|
||||||
if (e.key == MouseKey::LEFT_BUTTON) {
|
if (e.key == MouseKey::LEFT_BUTTON) {
|
||||||
m_mouse_state.left = true;
|
m_mouse_state.left = true;
|
||||||
@@ -488,7 +488,7 @@ bool ClientPlayer::handle_mouse_button_event(const MouseButtonEvent& e) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientPlayer::handle_key_event(const KeyEvent& e) {
|
bool LocalPlayer::handle_key_event(const KeyEvent& e) {
|
||||||
|
|
||||||
if (update_player_move_state(e.key, e.action)) {
|
if (update_player_move_state(e.key, e.action)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -496,51 +496,51 @@ bool ClientPlayer::handle_key_event(const KeyEvent& e) {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool ClientPlayer::handle_mouse_wheel_event(const MouseWheelEvent& e) {
|
bool LocalPlayer::handle_mouse_wheel_event(const MouseWheelEvent& e) {
|
||||||
if (update_scroll(e.offset)) {
|
if (update_scroll(e.offset)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::update_chunk_set(const ChunkPosSet& set) {
|
void LocalPlayer::update_chunk_set(const ChunkPosSet& set) {
|
||||||
std::lock_guard lock(m_chunk_pos_mutex);
|
std::lock_guard lock(m_chunk_pos_mutex);
|
||||||
m_player_chunk_pos_set.clear();
|
m_player_chunk_pos_set.clear();
|
||||||
m_player_chunk_pos_set.insert(set.begin(), set.end());
|
m_player_chunk_pos_set.insert(set.begin(), set.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClientPlayer::ChunkPosSet& ClientPlayer::get_chunk_pos_set() const {
|
const LocalPlayer::ChunkPosSet& LocalPlayer::get_chunk_pos_set() const {
|
||||||
std::shared_lock lock(m_chunk_pos_mutex);
|
std::shared_lock lock(m_chunk_pos_mutex);
|
||||||
return m_player_chunk_pos_set;
|
return m_player_chunk_pos_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientPlayer::ChunkPosSet ClientPlayer::get_chunk_pos_set() {
|
LocalPlayer::ChunkPosSet LocalPlayer::get_chunk_pos_set() {
|
||||||
std::lock_guard lock(m_chunk_pos_mutex);
|
std::lock_guard lock(m_chunk_pos_mutex);
|
||||||
return m_player_chunk_pos_set;
|
return m_player_chunk_pos_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
float& ClientPlayer::max_walk_speed() { return m_max_walk_speed; }
|
float& LocalPlayer::max_walk_speed() { return m_max_walk_speed; }
|
||||||
float& ClientPlayer::max_run_speed() { return m_max_run_speed; }
|
float& LocalPlayer::max_run_speed() { return m_max_run_speed; }
|
||||||
float& ClientPlayer::fly_y_speed() { return m_max_y_speed; }
|
float& LocalPlayer::fly_y_speed() { return m_max_y_speed; }
|
||||||
const ItemStack& ClientPlayer::get_current_itemstack() const {
|
const ItemStack& LocalPlayer::get_current_itemstack() const {
|
||||||
return m_hotbar[m_selected_hotbar];
|
return m_hotbar[m_selected_hotbar];
|
||||||
};
|
};
|
||||||
|
|
||||||
GameMode& ClientPlayer::game_mode() { return m_game_mode; }
|
GameMode& LocalPlayer::game_mode() { return m_game_mode; }
|
||||||
ClientWorld& ClientPlayer::get_world() { return m_world; }
|
ClientWorld& LocalPlayer::get_world() { return m_world; }
|
||||||
|
|
||||||
void ClientPlayer::set_uuid(std::string_view uuid) {
|
void LocalPlayer::set_uuid(std::string_view uuid) {
|
||||||
std::lock_guard lock(m_uuid_mutex);
|
std::lock_guard lock(m_uuid_mutex);
|
||||||
m_uuid = uuid;
|
m_uuid = uuid;
|
||||||
}
|
}
|
||||||
std::string ClientPlayer::get_uuid() const {
|
std::string LocalPlayer::get_uuid() const {
|
||||||
|
|
||||||
std::shared_lock lock(m_uuid_mutex);
|
std::shared_lock lock(m_uuid_mutex);
|
||||||
return m_uuid;
|
return m_uuid;
|
||||||
}
|
}
|
||||||
const std::string& ClientPlayer::get_name() const { return m_name; }
|
const std::string& LocalPlayer::get_name() const { return m_name; }
|
||||||
|
|
||||||
void ClientPlayer::reset_input_status() {
|
void LocalPlayer::reset_input_status() {
|
||||||
m_mouse_state.left = false;
|
m_mouse_state.left = false;
|
||||||
m_mouse_state.right = false;
|
m_mouse_state.right = false;
|
||||||
m_move_state.left = false;
|
m_move_state.left = false;
|
||||||
@@ -551,7 +551,7 @@ void ClientPlayer::reset_input_status() {
|
|||||||
m_move_state.up = false;
|
m_move_state.up = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::init(std::string_view name) {
|
void LocalPlayer::init(std::string_view name) {
|
||||||
{
|
{
|
||||||
std::lock_guard lock(m_player_pos_mutex);
|
std::lock_guard lock(m_player_pos_mutex);
|
||||||
m_pos.value = {0.0f, 255.0f, 0.0f};
|
m_pos.value = {0.0f, 255.0f, 0.0f};
|
||||||
@@ -588,6 +588,6 @@ void ClientPlayer::init(std::string_view name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientPlayer::is_underwater() const { return m_underwater; }
|
bool LocalPlayer::is_underwater() const { return m_underwater; }
|
||||||
void ClientPlayer::set_underwater(bool u) { m_underwater = u; }
|
void LocalPlayer::set_underwater(bool u) { m_underwater = u; }
|
||||||
} // namespace Cubed
|
} // namespace Cubed
|
||||||
@@ -175,7 +175,7 @@ ItemSlot* InventoryUI::get_hovered_slot() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
std::pair<ItemSlot*, size_t> InventoryUI::get_hovered_hotbar_slot() {
|
std::pair<ItemSlot*, size_t> InventoryUI::get_hovered_hotbar_slot() {
|
||||||
for (size_t i = 0; i < ClientPlayer::HOTBAR_SUM; ++i) {
|
for (size_t i = 0; i < LocalPlayer::HOTBAR_SUM; ++i) {
|
||||||
auto& slot = m_hotbar[i];
|
auto& slot = m_hotbar[i];
|
||||||
if (slot->hovered()) {
|
if (slot->hovered()) {
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void WorldUIManager::init() {
|
|||||||
auto& hotbar = m_root_widget->add_child<RowLayout>();
|
auto& hotbar = m_root_widget->add_child<RowLayout>();
|
||||||
hotbar.set_anchor(Anchor::BOTTOM_CENTER);
|
hotbar.set_anchor(Anchor::BOTTOM_CENTER);
|
||||||
m_hotbar = &hotbar;
|
m_hotbar = &hotbar;
|
||||||
for (size_t i = 0; i < ClientPlayer::HOTBAR_SUM; ++i) {
|
for (size_t i = 0; i < LocalPlayer::HOTBAR_SUM; ++i) {
|
||||||
auto& slot = hotbar.add_child<ItemSlot>();
|
auto& slot = hotbar.add_child<ItemSlot>();
|
||||||
slot.set_default_background(texture_manager);
|
slot.set_default_background(texture_manager);
|
||||||
slot.set_scale(5.0f);
|
slot.set_scale(5.0f);
|
||||||
@@ -130,7 +130,7 @@ void WorldUIManager::update_hotbar() {
|
|||||||
auto& player = m_scene.client_world().get_player();
|
auto& player = m_scene.client_world().get_player();
|
||||||
auto hotbar = player.get_hotbar();
|
auto hotbar = player.get_hotbar();
|
||||||
size_t selected = player.selected_hotbar();
|
size_t selected = player.selected_hotbar();
|
||||||
for (size_t i = 0; i < ClientPlayer::HOTBAR_SUM; ++i) {
|
for (size_t i = 0; i < LocalPlayer::HOTBAR_SUM; ++i) {
|
||||||
auto type = hotbar[i].type;
|
auto type = hotbar[i].type;
|
||||||
if (selected == i) {
|
if (selected == i) {
|
||||||
m_hotbar_slot[i]->set_border_visale(true);
|
m_hotbar_slot[i]->set_border_visale(true);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "Cubed/window.hpp"
|
#include "Cubed/window.hpp"
|
||||||
|
|
||||||
#include "Cubed/camera.hpp"
|
#include "Cubed/camera.hpp"
|
||||||
#include "Cubed/gameplay/client_player.hpp"
|
#include "Cubed/gameplay/local_player.hpp"
|
||||||
#include "Cubed/tools/cubed_assert.hpp"
|
#include "Cubed/tools/cubed_assert.hpp"
|
||||||
#include "Cubed/tools/env_tools.hpp"
|
#include "Cubed/tools/env_tools.hpp"
|
||||||
#include "Cubed/tools/font.hpp"
|
#include "Cubed/tools/font.hpp"
|
||||||
|
|||||||
Reference in New Issue
Block a user