177 lines
5.3 KiB
C++
177 lines
5.3 KiB
C++
#pragma once
|
|
#include <functional>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
#include <glm/gtc/quaternion.hpp>
|
|
#include <vector>
|
|
|
|
#include "material.h"
|
|
#include "utils/snowflake.h"
|
|
#include "vulkan_engine/vulkan/buffer_handle.h"
|
|
#include "vulkan_engine/vulkan/vertex.h"
|
|
#include "utils/thread_pool.h"
|
|
|
|
extern std::uint8_t CLIENTID;
|
|
|
|
namespace veng {
|
|
struct Model {
|
|
Model() : ID(utils::GenerateID(CLIENTID)), graphics_(nullptr) {
|
|
}
|
|
Model(class Graphics* graphics)
|
|
: ID(utils::GenerateID(CLIENTID)), graphics_(graphics) {
|
|
}
|
|
~Model();
|
|
|
|
Model(const Model& other)
|
|
: ID(utils::GenerateID(CLIENTID)),
|
|
name(/*"_" + */other.name),
|
|
asset_name(other.asset_name),
|
|
vertices(other.vertices),
|
|
vertex_buffer(other.vertex_buffer),
|
|
indices(other.indices),
|
|
index_buffer(other.index_buffer),
|
|
transform(other.transform),
|
|
position(other.position),
|
|
linear_velocity(other.linear_velocity),
|
|
linear_acceleration(other.linear_acceleration),
|
|
rotation(other.rotation),
|
|
angular_velocity(other.angular_velocity),
|
|
angular_acceleration(other.angular_acceleration),
|
|
scale(other.scale),
|
|
material(other.material),
|
|
original_offset(other.original_offset),
|
|
owner(other.owner),
|
|
radius(other.radius),
|
|
lifespan(other.lifespan),
|
|
OnColision(other.OnColision),
|
|
visible(other.visible),
|
|
colision(other.colision),
|
|
networkReplicated(other.networkReplicated),
|
|
lastUpdatedTime(other.lastUpdatedTime) {
|
|
graphics_ = nullptr;
|
|
}
|
|
|
|
Model(Model&& other)
|
|
: ID(other.ID),
|
|
name(other.name),
|
|
asset_name(other.asset_name),
|
|
vertices(std::move(other.vertices)),
|
|
vertex_buffer(std::move(other.vertex_buffer)),
|
|
indices(std::move(other.indices)),
|
|
index_buffer(std::move(other.index_buffer)),
|
|
transform(other.transform),
|
|
position(other.position),
|
|
linear_velocity(other.linear_velocity),
|
|
linear_acceleration(other.linear_acceleration),
|
|
rotation(other.rotation),
|
|
angular_velocity(other.angular_velocity),
|
|
angular_acceleration(other.angular_acceleration),
|
|
scale(other.scale),
|
|
material(other.material),
|
|
original_offset(other.original_offset),
|
|
owner(other.owner),
|
|
radius(other.radius),
|
|
lifespan(other.lifespan),
|
|
OnColision(other.OnColision),
|
|
visible(other.visible),
|
|
colision(other.colision),
|
|
networkReplicated(other.networkReplicated),
|
|
lastUpdatedTime(other.lastUpdatedTime) {
|
|
::memset(&other.ID, 0, 8);
|
|
|
|
graphics_ = other.graphics_;
|
|
other.graphics_ = nullptr;
|
|
}
|
|
|
|
Model& operator=(Model&& other) noexcept {
|
|
if (this != &other) {
|
|
ID = other.ID;
|
|
::memset(&other.ID, 0, 8);
|
|
name = other.name;
|
|
asset_name = other.asset_name;
|
|
vertices = std::move(other.vertices);
|
|
vertex_buffer = std::move(other.vertex_buffer);
|
|
indices = std::move(other.indices);
|
|
index_buffer = std::move(other.index_buffer);
|
|
transform = other.transform;
|
|
position = other.position;
|
|
linear_velocity = other.linear_velocity;
|
|
linear_acceleration = other.linear_acceleration;
|
|
rotation = other.rotation;
|
|
angular_velocity = other.angular_velocity;
|
|
angular_acceleration = other.angular_acceleration;
|
|
scale = other.scale;
|
|
material = std::move(other.material);
|
|
original_offset = other.original_offset;
|
|
owner = other.owner;
|
|
radius = other.radius;
|
|
lifespan = other.lifespan;
|
|
OnColision = other.OnColision;
|
|
visible = other.visible;
|
|
colision = other.colision;
|
|
networkReplicated = other.networkReplicated;
|
|
lastUpdatedTime = other.lastUpdatedTime;
|
|
|
|
graphics_ = other.graphics_;
|
|
other.graphics_ = nullptr;
|
|
}
|
|
return *this;
|
|
}
|
|
utils::Snowflake ID;
|
|
std::string name;
|
|
std::string asset_name;
|
|
|
|
std::vector<char> Serialize();
|
|
void Deserialize(std::vector<char> data);
|
|
|
|
std::vector<veng::Vertex> vertices;
|
|
veng::BufferHandle vertex_buffer;
|
|
std::vector<std::uint32_t> indices;
|
|
veng::BufferHandle index_buffer;
|
|
|
|
glm::mat4 transform = glm::rotate(glm::mat4(1.0f), glm::radians(180.f),
|
|
glm::vec3(0.f, 0.f, 1.f));
|
|
|
|
glm::vec3 position = glm::vec3(0.f);
|
|
glm::vec3 linear_velocity = glm::vec3(0.f);
|
|
glm::vec3 linear_acceleration = glm::vec3(0.f);
|
|
|
|
glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
|
|
glm::vec3 angular_velocity = glm::vec3(0.f); // 축 * 각속도(rad/s)
|
|
glm::vec3 angular_acceleration = glm::vec3(0.f);
|
|
|
|
glm::vec3 scale = glm::vec3(1.f);
|
|
|
|
Material material;
|
|
|
|
void Update(float dt);
|
|
|
|
glm::vec3 original_offset = glm::vec3(0.f);
|
|
|
|
std::weak_ptr<Model> owner;
|
|
|
|
std::float_t radius = 0.f;
|
|
|
|
std::float_t lifespan = -1.f;
|
|
|
|
std::function<void(utils::ThreadPool* thread_pool, std::shared_ptr<Model> self,
|
|
std::shared_ptr<Model> other)>
|
|
OnColision = nullptr;
|
|
|
|
bool visible = true;
|
|
bool colision = false;
|
|
bool networkReplicated = true;
|
|
bool shouldBeDestroyed = false;
|
|
|
|
bool needsUpdate = true;
|
|
|
|
double lastUpdatedTime = 0.f; // 서버 기준 업데이트된 시간임
|
|
|
|
std::uint8_t updateRedundantCount;
|
|
|
|
std::mutex modding;
|
|
|
|
private:
|
|
class Graphics* graphics_;
|
|
};
|
|
} // namespace veng
|