이대로 제출해버릴까..
This commit is contained in:
@@ -14,9 +14,8 @@ Session::Session(gsl::not_null<Network::IOCP*> iocp, utils::ThreadPool* tp,
|
||||
case SessionProtocol::QUIC:
|
||||
case SessionProtocol::TCP:
|
||||
case SessionProtocol::TLS: {
|
||||
Network::TCPSocket* sock = new Network::TCPSocket();
|
||||
Network::TCPSocket* sock = new Network::TCPSocket(addr.family);
|
||||
sock_ = sock;
|
||||
sock->init(addr.family);
|
||||
switch (type) {
|
||||
case SessionType::CONNECT:
|
||||
sock->connect(addr);
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace Network {
|
||||
|
||||
Socket::Socket() {
|
||||
init(AF_INET, SOCK_STREAM, 0);
|
||||
}
|
||||
|
||||
Socket::Socket(int domain, int type, int protocol) {
|
||||
init(domain, type, protocol);
|
||||
}
|
||||
@@ -61,6 +65,8 @@ int Socket::bind(Address __addr) {
|
||||
bindAddr = __addr;
|
||||
int retVal = ::bind(sock, &__addr.addr, __addr.length);
|
||||
if (retVal == INVALID_SOCKET) {
|
||||
int err = WSAGetLastError();
|
||||
spdlog::error("bind() failed: WSA error {} (0x{:X})", err, err);
|
||||
spdlog::critical("bind()");
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Network {
|
||||
|
||||
TCPSocket::TCPSocket(int domain) { init(domain); }
|
||||
|
||||
int TCPSocket::init(int domain) { return init(domain, SOCK_STREAM, 0); }
|
||||
|
||||
int TCPSocket::listen(int __n) {
|
||||
|
||||
16
impl/utils/ConfigManager.cpp
Normal file
16
impl/utils/ConfigManager.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "Utils/ConfigManager.h"
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace utils {
|
||||
void ConfigManager::save(Config& config) {
|
||||
|
||||
std::ofstream configfile("config.json", std::ios::out);
|
||||
|
||||
configfile << config.configJsonRoot;
|
||||
|
||||
configfile.close();
|
||||
}
|
||||
} // namespace utils
|
||||
@@ -55,6 +55,9 @@ std::vector<char> Model::Serialize() {
|
||||
Append(buffer, scale);
|
||||
|
||||
Append(buffer, original_offset);
|
||||
|
||||
Append(buffer, OwnerID);
|
||||
|
||||
Append(buffer, radius);
|
||||
Append(buffer, lifespan);
|
||||
|
||||
@@ -84,6 +87,9 @@ void Model::Deserialize(std::vector<char> data) {
|
||||
Read(data, offset, scale);
|
||||
|
||||
Read(data, offset, original_offset);
|
||||
|
||||
Read(data, offset, OwnerID);
|
||||
|
||||
Read(data, offset, radius);
|
||||
Read(data, offset, lifespan);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user