이대로 제출해버릴까..

This commit is contained in:
2025-06-21 22:19:10 +09:00
parent 3a526edcf4
commit 0536f9fb11
19 changed files with 343 additions and 89 deletions

View File

@@ -146,7 +146,7 @@ void Engine::Update() {
vulkan_graphics->RenderModel(it.second);
}
Physics::invokeOnColisionEvent(thread_pool_, models_);
// Physics::invokeOnColisionEvent(thread_pool_, models_);
vulkan_graphics->EndFrame();
}
@@ -187,38 +187,90 @@ float GetAlpha(double old_time, double new_time) {
void Interpolation(Packet::Header header, std::shared_ptr<veng::Model> local,
std::shared_ptr<veng::Model> remote) {
constexpr float position_threshold = 5.0f; // 위치 차이 임계값
constexpr float rotation_threshold = 0.5f; // 회전 차이 임계값 (라디안 기준)
std::lock_guard lock(local->modding);
local->position =
glm::mix(local->position, remote->position,
GetAlpha(local->lastUpdatedTime, header.timestamp));
local->linear_velocity =
glm::mix(local->linear_velocity, remote->linear_velocity,
GetAlpha(local->lastUpdatedTime, header.timestamp));
float alpha = GetAlpha(local->lastUpdatedTime, header.timestamp);
// 위치 보간 또는 강제 이동
if (glm::distance(local->position, remote->position) > position_threshold) {
local->position = remote->position;
} else {
local->position = glm::mix(local->position, remote->position, alpha);
}
// 선속도
if (glm::length(remote->linear_velocity - local->linear_velocity) >
position_threshold) {
local->linear_velocity = remote->linear_velocity;
} else {
local->linear_velocity =
glm::mix(local->linear_velocity, remote->linear_velocity, alpha);
}
local->linear_acceleration =
glm::mix(local->linear_acceleration, remote->linear_acceleration,
GetAlpha(local->lastUpdatedTime, header.timestamp));
glm::mix(local->linear_acceleration, remote->linear_acceleration, alpha);
// 회전 보간 또는 강제 이동
if (glm::length(remote->rotation - local->rotation) > rotation_threshold) {
local->rotation = remote->rotation;
} else {
local->rotation = glm::mix(local->rotation, remote->rotation, alpha);
}
local->rotation =
glm::mix(local->rotation, remote->rotation,
GetAlpha(local->lastUpdatedTime, header.timestamp));
local->angular_velocity =
glm::mix(local->angular_velocity, remote->angular_velocity,
GetAlpha(local->lastUpdatedTime, header.timestamp));
local->angular_acceleration =
glm::mix(local->angular_acceleration, remote->angular_acceleration,
GetAlpha(local->lastUpdatedTime, header.timestamp));
glm::mix(local->angular_velocity, remote->angular_velocity, alpha);
local->scale = glm::mix(local->scale, remote->scale,
GetAlpha(local->lastUpdatedTime, header.timestamp));
local->angular_acceleration = glm::mix(local->angular_acceleration,
remote->angular_acceleration, alpha);
// 스케일은 보간만 적용
local->scale = glm::mix(local->scale, remote->scale, alpha);
// 동기화 항목은 그대로 적용
local->original_offset = remote->original_offset;
local->radius = remote->radius;
local->lifespan = remote->lifespan;
local->visible = remote->visible;
local->colision = remote->colision;
}
//void Interpolation(Packet::Header header, std::shared_ptr<veng::Model> local,
// std::shared_ptr<veng::Model> remote) {
// std::lock_guard lock(local->modding);
// local->position =
// glm::mix(local->position, remote->position,
// GetAlpha(local->lastUpdatedTime, header.timestamp));
// local->linear_velocity =
// glm::mix(local->linear_velocity, remote->linear_velocity,
// GetAlpha(local->lastUpdatedTime, header.timestamp));
// local->linear_acceleration =
// glm::mix(local->linear_acceleration, remote->linear_acceleration,
// GetAlpha(local->lastUpdatedTime, header.timestamp));
//
// local->rotation =
// glm::mix(local->rotation, remote->rotation,
// GetAlpha(local->lastUpdatedTime, header.timestamp));
// local->angular_velocity =
// glm::mix(local->angular_velocity, remote->angular_velocity,
// GetAlpha(local->lastUpdatedTime, header.timestamp));
// local->angular_acceleration =
// glm::mix(local->angular_acceleration, remote->angular_acceleration,
// GetAlpha(local->lastUpdatedTime, header.timestamp));
//
// local->scale = glm::mix(local->scale, remote->scale,
// GetAlpha(local->lastUpdatedTime, header.timestamp));
//
// local->original_offset = remote->original_offset;
// local->radius = remote->radius;
// local->lifespan = remote->lifespan;
//
// local->visible = remote->visible;
// local->colision = remote->colision;
//}
void Engine::ResponseToServerAndRefresh(std::shared_ptr<Network::Socket> sock) {
if (sock->sock == 0) return;

View File

@@ -38,33 +38,31 @@ void Physics::invokeOnColisionEvent(
void Physics::invokeOnColisionEvent(
gsl::not_null<utils::ThreadPool*> thread_pool,
std::unordered_map<utils::Snowflake, Model>& models) {
std::unordered_map<utils::Snowflake, std::shared_ptr<Model>>& models) {
constexpr std::float_t EPSILON = std::numeric_limits<std::float_t>::epsilon();
for (std::unordered_map<utils::Snowflake, Model>::iterator
for (std::unordered_map<utils::Snowflake, std::shared_ptr<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;
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;
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)));
model_A = iter_A->second;
model_B = iter_B->second;
if (model_A->OnColision)
thread_pool->enqueueJob(model_A->OnColision, model_A, model_B);
model_A = iter_A->second;
model_B = iter_B->second;
if (model_B->OnColision)
thread_pool->enqueueJob(model_B->OnColision, model_A, model_B);
}
}
}