일단 오늘은 이걸로..
This commit is contained in:
@@ -47,6 +47,14 @@ FetchContent_Declare(
|
|||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(ASSIMP)
|
FetchContent_MakeAvailable(ASSIMP)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
JSONCPP
|
||||||
|
GIT_REPOSITORY "https://github.com/open-source-parsers/jsoncpp.git"
|
||||||
|
GIT_TAG "1.9.6"
|
||||||
|
GIT_SHALLOW ON
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(JSONCPP)
|
||||||
|
|
||||||
file(GLOB_RECURSE Sources CONFIGURE_DEPENDS
|
file(GLOB_RECURSE Sources CONFIGURE_DEPENDS
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
|
||||||
)
|
)
|
||||||
@@ -58,6 +66,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
|
|||||||
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft.GSL::GSL)
|
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft.GSL::GSL)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog)
|
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE assimp::assimp)
|
target_link_libraries(${PROJECT_NAME} PRIVATE assimp::assimp)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_static)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
||||||
@@ -104,3 +113,17 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|||||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||||
COMMENT "Copying spdlog library files and symlinks to output directory"
|
COMMENT "Copying spdlog library files and symlinks to output directory"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"$<TARGET_FILE:jsoncpp_static>"
|
||||||
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||||
|
COMMENT "Copying jsoncpp DLL/so to output directory"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
"$<TARGET_FILE_DIR:jsoncpp_static>"
|
||||||
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||||
|
COMMENT "Copying jsoncpp library files and symlinks to output directory"
|
||||||
|
)
|
||||||
@@ -53,10 +53,15 @@ void Tick(veng::Engine& engine, std::float_t delta_time) {
|
|||||||
if (glfwGetKey(engine.vulkan_graphics->window->GetHandle(), GLFW_KEY_W) ==
|
if (glfwGetKey(engine.vulkan_graphics->window->GetHandle(), GLFW_KEY_W) ==
|
||||||
GLFW_PRESS) {
|
GLFW_PRESS) {
|
||||||
player->linear_acceleration = glm::normalize(forward) * 10.f;
|
player->linear_acceleration = glm::normalize(forward) * 10.f;
|
||||||
|
player_flame->linear_velocity = player->linear_velocity;
|
||||||
|
player_flame->position = player->position;
|
||||||
|
player_flame->angular_velocity = player->angular_velocity;
|
||||||
|
player_flame->rotation = player->rotation;
|
||||||
player_flame->visible = true;
|
player_flame->visible = true;
|
||||||
|
|
||||||
if (!w_laststate) {
|
if (!w_laststate) {
|
||||||
player->needsUpdate = true;
|
player->needsUpdate = true;
|
||||||
|
player_flame->needsUpdate = true;
|
||||||
player->updateRedundantCount = 0;
|
player->updateRedundantCount = 0;
|
||||||
w_laststate = true;
|
w_laststate = true;
|
||||||
}
|
}
|
||||||
@@ -65,6 +70,7 @@ void Tick(veng::Engine& engine, std::float_t delta_time) {
|
|||||||
player_flame->visible = false;
|
player_flame->visible = false;
|
||||||
if (w_laststate) {
|
if (w_laststate) {
|
||||||
player->needsUpdate = true;
|
player->needsUpdate = true;
|
||||||
|
player_flame->needsUpdate = true;
|
||||||
player->updateRedundantCount = 0;
|
player->updateRedundantCount = 0;
|
||||||
w_laststate = false;
|
w_laststate = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ FetchContent_Declare(
|
|||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(ASSIMP)
|
FetchContent_MakeAvailable(ASSIMP)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
JSONCPP
|
||||||
|
GIT_REPOSITORY "https://github.com/open-source-parsers/jsoncpp.git"
|
||||||
|
GIT_TAG "1.9.6"
|
||||||
|
GIT_SHALLOW ON
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(JSONCPP)
|
||||||
|
|
||||||
file(GLOB_RECURSE Sources CONFIGURE_DEPENDS
|
file(GLOB_RECURSE Sources CONFIGURE_DEPENDS
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
|
||||||
)
|
)
|
||||||
@@ -59,6 +67,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
|
|||||||
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft.GSL::GSL)
|
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft.GSL::GSL)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog)
|
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE assimp::assimp)
|
target_link_libraries(${PROJECT_NAME} PRIVATE assimp::assimp)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_static)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
||||||
@@ -90,3 +99,17 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|||||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||||
COMMENT "Copying spdlog library files and symlinks to output directory"
|
COMMENT "Copying spdlog library files and symlinks to output directory"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"$<TARGET_FILE:jsoncpp_static>"
|
||||||
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||||
|
COMMENT "Copying jsoncpp DLL/so to output directory"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
"$<TARGET_FILE_DIR:jsoncpp_static>"
|
||||||
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||||
|
COMMENT "Copying jsoncpp library files and symlinks to output directory"
|
||||||
|
)
|
||||||
@@ -8,12 +8,12 @@
|
|||||||
#include "socket/wsa_manager.h"
|
#include "socket/wsa_manager.h"
|
||||||
#include "utils/log.h"
|
#include "utils/log.h"
|
||||||
#include "utils/snowflake.h"
|
#include "utils/snowflake.h"
|
||||||
#include "vulkan_engine/asset/object/model.h"
|
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
|
#include "vulkan_engine/asset/object/model.h"
|
||||||
|
|
||||||
#define LISTENIP "::"
|
#define LISTENIP "::"
|
||||||
#define LISTENPORT 9010
|
#define LISTENPORT 9010
|
||||||
#define TICKRATE 30
|
#define TICKRATE 60
|
||||||
constexpr double TICKDELAY = (1 / TICKRATE);
|
constexpr double TICKDELAY = (1 / TICKRATE);
|
||||||
|
|
||||||
std::uint8_t CLIENTID = 0;
|
std::uint8_t CLIENTID = 0;
|
||||||
@@ -24,7 +24,8 @@ std::list<std::shared_ptr<Network::Socket>> CLIENTS;
|
|||||||
std::mutex CLIENTS_MUTEX;
|
std::mutex CLIENTS_MUTEX;
|
||||||
|
|
||||||
void EchoClient(utils::ThreadPool* tp, Network::IOCP* iocp,
|
void EchoClient(utils::ThreadPool* tp, Network::IOCP* iocp,
|
||||||
std::shared_ptr<Network::Socket> NewSock, Network::Address NewAddr) {
|
std::shared_ptr<Network::Socket> NewSock,
|
||||||
|
Network::Address NewAddr) {
|
||||||
if (NewSock->sock == 0) return;
|
if (NewSock->sock == 0) return;
|
||||||
std::future<std::list<char>> result;
|
std::future<std::list<char>> result;
|
||||||
Packet::Header header;
|
Packet::Header header;
|
||||||
@@ -79,6 +80,16 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
|||||||
}
|
}
|
||||||
CLIENTS_MUTEX.unlock();
|
CLIENTS_MUTEX.unlock();
|
||||||
|
|
||||||
|
for (auto it = MODELS.begin(); it != MODELS.end();) {
|
||||||
|
auto& model = it->second;
|
||||||
|
|
||||||
|
if (model.shouldBeDestroyed) {
|
||||||
|
it = MODELS.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto it = MODELS.begin(); it != MODELS.end();) {
|
for (auto it = MODELS.begin(); it != MODELS.end();) {
|
||||||
auto& model = it->second;
|
auto& model = it->second;
|
||||||
|
|
||||||
@@ -89,12 +100,7 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (model.lifespan <= 0.f) {
|
if (model.lifespan <= 0.f) {
|
||||||
it = MODELS.erase(it);
|
it->second.shouldBeDestroyed = true;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (model.shouldBeDestroyed) {
|
|
||||||
it = MODELS.erase(it);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +117,13 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
|||||||
std::vector<char> send_data;
|
std::vector<char> send_data;
|
||||||
auto model_serialized = model.second.Serialize();
|
auto model_serialized = model.second.Serialize();
|
||||||
Packet::Header header;
|
Packet::Header header;
|
||||||
|
|
||||||
|
if (model.second.shouldBeDestroyed) {
|
||||||
|
header.opcode = Packet::Opcode::DESPAWNMODEL;
|
||||||
|
} else {
|
||||||
header.opcode = Packet::Opcode::UPDATEMODEL;
|
header.opcode = Packet::Opcode::UPDATEMODEL;
|
||||||
|
}
|
||||||
|
|
||||||
header.timestamp = glfwGetTime();
|
header.timestamp = glfwGetTime();
|
||||||
header.body_length = model_serialized.size();
|
header.body_length = model_serialized.size();
|
||||||
auto header_serialized = header.Serialize();
|
auto header_serialized = header.Serialize();
|
||||||
@@ -119,14 +131,16 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
|||||||
header_serialized.end());
|
header_serialized.end());
|
||||||
send_data.insert(send_data.end(), model_serialized.begin(),
|
send_data.insert(send_data.end(), model_serialized.begin(),
|
||||||
model_serialized.end());
|
model_serialized.end());
|
||||||
if (!model.second.needsUpdate && !needs_all_update) {
|
if (!model.second.needsUpdate && !needs_all_update &&
|
||||||
|
!model.second.shouldBeDestroyed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
model.second.needsUpdate = false;
|
model.second.needsUpdate = false;
|
||||||
if (iocp->send(client, send_data) == -1) {
|
if (iocp->send(client, send_data) == -1) {
|
||||||
client->sock = 0;
|
client->sock = 0;
|
||||||
}
|
}
|
||||||
spdlog::debug("server-side updated : [{}:{}]", model.second.name, model.second.ID.snowflake);
|
// spdlog::debug("server-side updated : [{}:{}]", model.second.name,
|
||||||
|
// model.second.ID.snowflake);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CLIENTS_MUTEX.unlock();
|
CLIENTS_MUTEX.unlock();
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ void Engine::Update() {
|
|||||||
vulkan_graphics->RenderModel(it.second);
|
vulkan_graphics->RenderModel(it.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
physics_controller_.invokeOnColisionEvent(thread_pool_, models_);
|
Physics::invokeOnColisionEvent(thread_pool_, models_);
|
||||||
|
|
||||||
vulkan_graphics->EndFrame();
|
vulkan_graphics->EndFrame();
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ void Engine::ResponseToServerAndRefresh(std::shared_ptr<Network::Socket> sock) {
|
|||||||
for (auto& it : models_) {
|
for (auto& it : models_) {
|
||||||
if (it.second->ID == model->ID) {
|
if (it.second->ID == model->ID) {
|
||||||
Interpolation(header, it.second, model);
|
Interpolation(header, it.second, model);
|
||||||
spdlog::debug("model updated: [{}:{}]", model->name, model->ID.snowflake);
|
// spdlog::debug("model updated: [{}:{}]", model->name, model->ID.snowflake);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -250,8 +250,17 @@ void Engine::ResponseToServerAndRefresh(std::shared_ptr<Network::Socket> sock) {
|
|||||||
auto spawnedModel =
|
auto spawnedModel =
|
||||||
SpawnLifedModel(model->asset_name, model->name, model->lifespan);
|
SpawnLifedModel(model->asset_name, model->name, model->lifespan);
|
||||||
std::lock_guard lock(spawnedModel->modding);
|
std::lock_guard lock(spawnedModel->modding);
|
||||||
|
|
||||||
spawnedModel->ID = model->ID;
|
spawnedModel->ID = model->ID;
|
||||||
|
spawnedModel->position = model->position;
|
||||||
|
spawnedModel->linear_velocity = model->linear_velocity;
|
||||||
|
spawnedModel->linear_acceleration = model->linear_acceleration;
|
||||||
|
|
||||||
|
spawnedModel->rotation = model->rotation;
|
||||||
|
spawnedModel->angular_velocity = model->angular_velocity;
|
||||||
|
spawnedModel->angular_acceleration = model->angular_acceleration;
|
||||||
|
|
||||||
|
spawnedModel->scale = model->scale;
|
||||||
|
spawnedModel->transform = model->transform;
|
||||||
|
|
||||||
spawnedModel->original_offset = model->original_offset;
|
spawnedModel->original_offset = model->original_offset;
|
||||||
spawnedModel->radius = model->radius;
|
spawnedModel->radius = model->radius;
|
||||||
@@ -260,11 +269,21 @@ void Engine::ResponseToServerAndRefresh(std::shared_ptr<Network::Socket> sock) {
|
|||||||
spawnedModel->visible = model->visible;
|
spawnedModel->visible = model->visible;
|
||||||
spawnedModel->colision = model->colision;
|
spawnedModel->colision = model->colision;
|
||||||
spawnedModel->networkReplicated = false;
|
spawnedModel->networkReplicated = false;
|
||||||
|
|
||||||
Interpolation(header, spawnedModel, model);
|
|
||||||
spdlog::info("model spawned: {}", model->ID.snowflake);
|
spdlog::info("model spawned: {}", model->ID.snowflake);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case Packet::Opcode::DESPAWNMODEL: {
|
||||||
|
std::shared_ptr<veng::Model> model = std::make_shared<veng::Model>();
|
||||||
|
model->Deserialize(recv_data);
|
||||||
|
|
||||||
|
for (auto it = models_.begin(); it != models_.end();) {
|
||||||
|
if (it->second->ID == model->ID) {
|
||||||
|
models_.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
default:
|
default:
|
||||||
spdlog::error("unknown data type");
|
spdlog::error("unknown data type");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,18 +12,23 @@ void Physics::invokeOnColisionEvent(
|
|||||||
for (std::unordered_map<std::string, std::shared_ptr<Model>>::iterator
|
for (std::unordered_map<std::string, std::shared_ptr<Model>>::iterator
|
||||||
iter_A = models.begin();
|
iter_A = models.begin();
|
||||||
iter_A != models.end(); iter_A++) {
|
iter_A != models.end(); iter_A++) {
|
||||||
auto model_A = iter_A->second;
|
|
||||||
if (!model_A->colision) continue;
|
|
||||||
for (auto iter_B = std::next(iter_A); iter_B != models.end(); iter_B++) {
|
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;
|
auto model_B = iter_B->second;
|
||||||
if (!model_B->colision) continue;
|
std::lock_guard<std::mutex> Block(model_B->modding);
|
||||||
|
if (!model_A->colision || !model_B->colision) continue;
|
||||||
std::float_t distance =
|
std::float_t distance =
|
||||||
glm::distance(model_A->position, model_B->position);
|
glm::distance(model_A->position, model_B->position);
|
||||||
std::float_t modelA_radius = model_A->radius * model_A->scale.x;
|
std::float_t modelA_radius = model_A->radius * model_A->scale.x;
|
||||||
std::float_t modelB_radius = model_B->radius * model_B->scale.x;
|
std::float_t modelB_radius = model_B->radius * model_B->scale.x;
|
||||||
if (distance <= modelA_radius + modelB_radius) {
|
if (distance <= modelA_radius + modelB_radius) {
|
||||||
|
model_A = iter_A->second;
|
||||||
|
model_B = iter_B->second;
|
||||||
if (model_A->OnColision)
|
if (model_A->OnColision)
|
||||||
thread_pool->enqueueJob(model_A->OnColision, model_A, model_B);
|
thread_pool->enqueueJob(model_A->OnColision, model_A, model_B);
|
||||||
|
model_A = iter_A->second;
|
||||||
|
model_B = iter_B->second;
|
||||||
if (model_B->OnColision)
|
if (model_B->OnColision)
|
||||||
thread_pool->enqueueJob(model_B->OnColision, model_A, model_B);
|
thread_pool->enqueueJob(model_B->OnColision, model_A, model_B);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ class ThreadPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(jobQueueMutex);
|
std::lock_guard<std::mutex> lock(jobQueueMutex);
|
||||||
auto boundFunc = [this, __job, ... __args = __args]() mutable {
|
auto boundFunc = [this, __job, ... __args = std::move(__args)]() mutable {
|
||||||
__job(this, __args...);
|
__job(this, std::move(__args)...);
|
||||||
};
|
};
|
||||||
auto task = std::packaged_task<void()>(std::move(boundFunc));
|
auto task = std::packaged_task<void()>(std::move(boundFunc));
|
||||||
jobs_.push(std::move(task));
|
jobs_.push(std::move(task));
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ struct Model {
|
|||||||
|
|
||||||
double lastUpdatedTime = 0.f; // 서버 기준 업데이트된 시간임
|
double lastUpdatedTime = 0.f; // 서버 기준 업데이트된 시간임
|
||||||
|
|
||||||
std::uint8_t updateRedundantCount;
|
std::uint8_t updateRedundantCount = 0;
|
||||||
|
|
||||||
std::mutex modding;
|
std::mutex modding;
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ class Engine {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Loader asset_loader_;
|
Loader asset_loader_;
|
||||||
Physics physics_controller_;
|
|
||||||
utils::ThreadPool* thread_pool_;
|
utils::ThreadPool* thread_pool_;
|
||||||
Network::IOCP* iocp_;
|
Network::IOCP* iocp_;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace veng {
|
namespace veng {
|
||||||
class Physics {
|
class Physics {
|
||||||
public:
|
public:
|
||||||
void invokeOnColisionEvent(
|
static void invokeOnColisionEvent(
|
||||||
gsl::not_null<utils::ThreadPool*> thread_pool,
|
gsl::not_null<utils::ThreadPool*> thread_pool,
|
||||||
std::unordered_map<std::string, std::shared_ptr<Model>>& models);
|
std::unordered_map<std::string, std::shared_ptr<Model>>& models);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user