refactor players

This commit is contained in:
MihailRis
2024-11-22 16:17:13 +03:00
parent 7f41f95013
commit bd2acd5766
13 changed files with 101 additions and 151 deletions
+7 -2
View File
@@ -29,12 +29,14 @@ constexpr int SPAWN_ATTEMPTS_PER_UPDATE = 64;
Player::Player(
Level* level,
int64_t id,
glm::vec3 position,
float speed,
std::shared_ptr<Inventory> inv,
entityid_t eid
)
: level(level),
id(id),
speed(speed),
chosenSlot(0),
position(position),
@@ -49,8 +51,7 @@ Player::Player(
tpCamera->setFov(glm::radians(90.0f));
}
Player::~Player() {
}
Player::~Player() = default;
void Player::updateEntity() {
if (eid == 0) {
@@ -283,6 +284,8 @@ glm::vec3 Player::getSpawnPoint() const {
dv::value Player::serialize() const {
auto root = dv::object();
root["id"] = id;
root["position"] = dv::to_value(position);
root["rotation"] = dv::to_value(cam);
root["spawnpoint"] = dv::to_value(spawnpoint);
@@ -304,6 +307,8 @@ dv::value Player::serialize() const {
}
void Player::deserialize(const dv::value& src) {
src.at("id").get(id);
const auto& posarr = src["position"];
dv::get_vec(posarr, position);
+6 -5
View File
@@ -4,7 +4,6 @@
#include <memory>
#include <optional>
#include "interfaces/Object.hpp"
#include "interfaces/Serializable.hpp"
#include "settings.hpp"
#include "voxels/voxel.hpp"
@@ -40,8 +39,9 @@ struct CursorSelection {
entityid_t entity = ENTITY_NONE;
};
class Player : public Object, public Serializable {
class Player : public Serializable {
Level* level;
int64_t id;
float speed;
int chosenSlot;
glm::vec3 position;
@@ -52,7 +52,7 @@ class Player : public Object, public Serializable {
bool infiniteItems = true;
bool instantDestruction = true;
entityid_t eid;
entityid_t selectedEid;
entityid_t selectedEid = 0;
public:
std::shared_ptr<Camera> fpCamera, spCamera, tpCamera;
std::shared_ptr<Camera> currentCamera;
@@ -62,6 +62,7 @@ public:
Player(
Level* level,
int64_t id,
glm::vec3 position,
float speed,
std::shared_ptr<Inventory> inv,
@@ -115,7 +116,7 @@ public:
static void convert(dv::value& data, const ContentReport* report);
inline int getId() const {
return objectUID;
inline u64id_t getId() const {
return id;
}
};