서버-사이드 충돌판정 구현 중
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "utils/snowflake.h"
|
||||
#include "utils/utils.h"
|
||||
#include "vulkan_engine/asset/object/model.h"
|
||||
#include "vulkan_engine/vulkan/physics.h"
|
||||
|
||||
#define LISTENIP "::"
|
||||
#define LISTENPORT 9010
|
||||
@@ -46,9 +47,12 @@ void EchoClient(utils::ThreadPool* tp, Network::IOCP* iocp,
|
||||
|
||||
std::lock_guard lock(MODELS_MUTEX);
|
||||
auto ID = model.ID;
|
||||
if (MODELS.find(ID) == MODELS.end())
|
||||
if (MODELS.find(ID) == MODELS.end()) {
|
||||
spdlog::info("model received: {}:{}", model.name, ID.snowflake);
|
||||
MODELS[ID] = std::move(model);
|
||||
} else {
|
||||
MODELS[ID].Deserialize(recv_data);
|
||||
}
|
||||
MODELS[ID].needsUpdate = true;
|
||||
} break;
|
||||
default:
|
||||
@@ -112,6 +116,7 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
for (auto& model : MODELS) {
|
||||
if (model.second.name == "camera_lag") continue;
|
||||
model.second.Update(delta_time);
|
||||
veng::Physics::invokeOnColisionEvent(tp, MODELS);
|
||||
for (auto& client : CLIENTS) {
|
||||
if (client->sock == 0) continue;
|
||||
std::vector<char> send_data;
|
||||
|
||||
@@ -36,10 +36,44 @@ void Physics::invokeOnColisionEvent(
|
||||
}
|
||||
}
|
||||
|
||||
void Physics::invokeOnColisionEvent(
|
||||
gsl::not_null<utils::ThreadPool*> thread_pool,
|
||||
std::unordered_map<utils::Snowflake, Model>& models) {
|
||||
constexpr std::float_t EPSILON = std::numeric_limits<std::float_t>::epsilon();
|
||||
|
||||
for (std::unordered_map<utils::Snowflake, Model>::iterator
|
||||
iter_A = models.begin();
|
||||
iter_A != models.end(); iter_A++) {
|
||||
for (auto iter_B = std::next(iter_A); iter_B != models.end(); iter_B++) {
|
||||
auto& model_A = iter_A->second;
|
||||
std::lock_guard<std::mutex> Alock(model_A.modding);
|
||||
auto& model_B = iter_B->second;
|
||||
std::lock_guard<std::mutex> Block(model_B.modding);
|
||||
if (!model_A.colision || !model_B.colision) continue;
|
||||
std::float_t distance =
|
||||
glm::distance(model_A.position, model_B.position);
|
||||
std::float_t modelA_radius = model_A.radius * model_A.scale.x;
|
||||
std::float_t modelB_radius = model_B.radius * model_B.scale.x;
|
||||
if (distance <= modelA_radius + modelB_radius) {
|
||||
if (model_A.OnColision)
|
||||
thread_pool->enqueueJob(model_A.OnColision,
|
||||
std::make_shared<Model>(std::move(model_A)),
|
||||
std::make_shared<Model>(std::move(model_B)));
|
||||
/*model_A = iter_A->second;
|
||||
model_B = iter_B->second;*/
|
||||
if (model_B.OnColision)
|
||||
thread_pool->enqueueJob(model_B.OnColision,
|
||||
std::make_shared<Model>(std::move(model_B)),
|
||||
std::make_shared<Model>(std::move(model_A)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Physics::RayTrace(const glm::vec3& rayOrigin, const glm::vec3& rayDir,
|
||||
const glm::vec3& v0, const glm::vec3& v1,
|
||||
const glm::vec3& v2, std::float_t& outDistance) {
|
||||
const std::float_t EPSILON = std::numeric_limits<std::float_t>::epsilon();
|
||||
constexpr std::float_t EPSILON = std::numeric_limits<std::float_t>::epsilon();
|
||||
|
||||
// 삼각형 엣지와 노멀 계산
|
||||
glm::vec3 edge1 = v1 - v0;
|
||||
|
||||
@@ -10,6 +10,9 @@ class Physics {
|
||||
static void invokeOnColisionEvent(
|
||||
gsl::not_null<utils::ThreadPool*> thread_pool,
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>>& models);
|
||||
static void invokeOnColisionEvent(
|
||||
gsl::not_null<utils::ThreadPool*> thread_pool,
|
||||
std::unordered_map<utils::Snowflake, 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