일단은 멀티로 접속이 됨..
This commit is contained in:
@@ -5,20 +5,25 @@
|
||||
#include <vector>
|
||||
|
||||
#include "material.h"
|
||||
#include "utils/snowflake.h"
|
||||
#include "vulkan_engine/vulkan/buffer_handle.h"
|
||||
#include "vulkan_engine/vulkan/vertex.h"
|
||||
#include "utils/snowflake.h"
|
||||
|
||||
extern std::uint8_t CLIENTID;
|
||||
|
||||
namespace veng {
|
||||
struct Model {
|
||||
Model() : graphics_(nullptr) {}
|
||||
Model(class Graphics* graphics) : graphics_(graphics) {}
|
||||
Model() : ID(utils::GenerateID(CLIENTID)), graphics_(nullptr) {
|
||||
}
|
||||
Model(class Graphics* graphics)
|
||||
: ID(utils::GenerateID(CLIENTID)), graphics_(graphics) {
|
||||
}
|
||||
~Model();
|
||||
|
||||
Model(const Model& other)
|
||||
: asset_name(other.asset_name),
|
||||
: ID(utils::GenerateID(CLIENTID)),
|
||||
name(/*"_" + */other.name),
|
||||
asset_name(other.asset_name),
|
||||
vertices(other.vertices),
|
||||
vertex_buffer(other.vertex_buffer),
|
||||
indices(other.indices),
|
||||
@@ -39,14 +44,14 @@ struct Model {
|
||||
OnColision(other.OnColision),
|
||||
visible(other.visible),
|
||||
colision(other.colision),
|
||||
networkReplicated(other.networkReplicated) {
|
||||
name = "_" + other.name;
|
||||
ID = utils::GenerateID(CLIENTID);
|
||||
networkReplicated(other.networkReplicated),
|
||||
lastUpdatedTime(other.lastUpdatedTime) {
|
||||
graphics_ = nullptr;
|
||||
}
|
||||
|
||||
Model(Model&& other)
|
||||
: name(other.name),
|
||||
: ID(other.ID),
|
||||
name(other.name),
|
||||
asset_name(other.asset_name),
|
||||
vertices(std::move(other.vertices)),
|
||||
vertex_buffer(std::move(other.vertex_buffer)),
|
||||
@@ -68,9 +73,8 @@ struct Model {
|
||||
OnColision(other.OnColision),
|
||||
visible(other.visible),
|
||||
colision(other.colision),
|
||||
networkReplicated(other.networkReplicated)
|
||||
{
|
||||
ID = other.ID;
|
||||
networkReplicated(other.networkReplicated),
|
||||
lastUpdatedTime(other.lastUpdatedTime) {
|
||||
::memset(&other.ID, 0, 8);
|
||||
|
||||
graphics_ = other.graphics_;
|
||||
@@ -104,6 +108,7 @@ struct Model {
|
||||
visible = other.visible;
|
||||
colision = other.colision;
|
||||
networkReplicated = other.networkReplicated;
|
||||
lastUpdatedTime = other.lastUpdatedTime;
|
||||
|
||||
graphics_ = other.graphics_;
|
||||
other.graphics_ = nullptr;
|
||||
@@ -141,13 +146,14 @@ struct Model {
|
||||
|
||||
glm::vec3 original_offset = glm::vec3(0.f);
|
||||
|
||||
Model* owner = this;
|
||||
std::weak_ptr<Model> owner;
|
||||
|
||||
std::float_t radius = 0.f;
|
||||
|
||||
std::float_t lifespan = -1.f;
|
||||
|
||||
std::function<void(Model* self, Model* other)> OnColision = nullptr;
|
||||
std::function<void(std::shared_ptr<Model> self, std::shared_ptr<Model> other)>
|
||||
OnColision = nullptr;
|
||||
|
||||
bool visible = true;
|
||||
bool colision = false;
|
||||
@@ -156,6 +162,10 @@ struct Model {
|
||||
|
||||
bool needsUpdate = true;
|
||||
|
||||
double lastUpdatedTime = 0.f; // 서버 기준 업데이트된 시간임
|
||||
|
||||
std::mutex modding;
|
||||
|
||||
private:
|
||||
class Graphics* graphics_;
|
||||
};
|
||||
|
||||
@@ -20,9 +20,9 @@ class Engine {
|
||||
const Model* GetStaticModel(std::string name);
|
||||
|
||||
// 수명을 무제한으로 놓고 싶으면 lifespan을 -1으로 설정하면 됨
|
||||
Model* SpawnLifedModel(std::string asset_name, std::string name,
|
||||
std::shared_ptr<Model> SpawnLifedModel(std::string asset_name, std::string name,
|
||||
std::float_t lifespan);
|
||||
Model* GetSpawnedObject(std::string name);
|
||||
std::shared_ptr<Model> GetSpawnedObject(std::string name);
|
||||
|
||||
void Update();
|
||||
void NetUpdate(std::shared_ptr<Network::Socket> sock);
|
||||
@@ -53,7 +53,7 @@ class Engine {
|
||||
|
||||
std::unordered_map<std::string, veng::Model> model_assets_;
|
||||
|
||||
std::unordered_map<std::string, veng::Model> models_;
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> models_;
|
||||
};
|
||||
|
||||
} // namespace veng
|
||||
|
||||
@@ -33,7 +33,7 @@ class Graphics final {
|
||||
void RenderBuffer(BufferHandle handle, std::uint32_t vertex_count);
|
||||
void RenderIndexedBuffer(BufferHandle vertex_buffer,
|
||||
BufferHandle index_buffer, std::uint32_t count);
|
||||
void RenderModel(struct Model* model);
|
||||
void RenderModel(std::shared_ptr<struct Model> model);
|
||||
void EndFrame();
|
||||
|
||||
BufferHandle CreateVertexBuffer(gsl::span<Vertex> vertices);
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
namespace veng {
|
||||
class Physics {
|
||||
public:
|
||||
void invokeOnColisionEvent(gsl::not_null<utils::ThreadPool *> thread_pool, gsl::span<Model*> models);
|
||||
void invokeOnColisionEvent(gsl::not_null<utils::ThreadPool*> thread_pool,
|
||||
std::vector<std::shared_ptr<Model>> models);
|
||||
|
||||
bool RayTrace(const glm::vec3& rayOrigin, const glm::vec3& rayDir,
|
||||
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2,
|
||||
|
||||
Reference in New Issue
Block a user