일단 오늘은 이걸로..
This commit is contained in:
@@ -48,6 +48,14 @@ FetchContent_Declare(
|
||||
)
|
||||
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
|
||||
"${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 spdlog)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE assimp::assimp)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_static)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
||||
@@ -89,4 +98,18 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
"$<TARGET_FILE_DIR:spdlog>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
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 "utils/log.h"
|
||||
#include "utils/snowflake.h"
|
||||
#include "vulkan_engine/asset/object/model.h"
|
||||
#include "utils/utils.h"
|
||||
#include "vulkan_engine/asset/object/model.h"
|
||||
|
||||
#define LISTENIP "::"
|
||||
#define LISTENPORT 9010
|
||||
#define TICKRATE 30
|
||||
#define TICKRATE 60
|
||||
constexpr double TICKDELAY = (1 / TICKRATE);
|
||||
|
||||
std::uint8_t CLIENTID = 0;
|
||||
@@ -24,7 +24,8 @@ std::list<std::shared_ptr<Network::Socket>> CLIENTS;
|
||||
std::mutex CLIENTS_MUTEX;
|
||||
|
||||
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;
|
||||
std::future<std::list<char>> result;
|
||||
Packet::Header header;
|
||||
@@ -32,7 +33,7 @@ void EchoClient(utils::ThreadPool* tp, Network::IOCP* iocp,
|
||||
|
||||
result = iocp->recv(NewSock, 14);
|
||||
recv_data = utils::CvtListToVector(result.get());
|
||||
|
||||
|
||||
header.Deserialize(recv_data);
|
||||
|
||||
result = iocp->recv(NewSock, header.body_length);
|
||||
@@ -79,6 +80,16 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
}
|
||||
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();) {
|
||||
auto& model = it->second;
|
||||
|
||||
@@ -89,12 +100,7 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
}
|
||||
|
||||
if (model.lifespan <= 0.f) {
|
||||
it = MODELS.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (model.shouldBeDestroyed) {
|
||||
it = MODELS.erase(it);
|
||||
it->second.shouldBeDestroyed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -111,7 +117,13 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
std::vector<char> send_data;
|
||||
auto model_serialized = model.second.Serialize();
|
||||
Packet::Header header;
|
||||
header.opcode = Packet::Opcode::UPDATEMODEL;
|
||||
|
||||
if (model.second.shouldBeDestroyed) {
|
||||
header.opcode = Packet::Opcode::DESPAWNMODEL;
|
||||
} else {
|
||||
header.opcode = Packet::Opcode::UPDATEMODEL;
|
||||
}
|
||||
|
||||
header.timestamp = glfwGetTime();
|
||||
header.body_length = model_serialized.size();
|
||||
auto header_serialized = header.Serialize();
|
||||
@@ -119,14 +131,16 @@ void ClientRefresher(utils::ThreadPool* tp, Network::IOCP* iocp) {
|
||||
header_serialized.end());
|
||||
send_data.insert(send_data.end(), model_serialized.begin(),
|
||||
model_serialized.end());
|
||||
if (!model.second.needsUpdate && !needs_all_update) {
|
||||
if (!model.second.needsUpdate && !needs_all_update &&
|
||||
!model.second.shouldBeDestroyed) {
|
||||
continue;
|
||||
}
|
||||
model.second.needsUpdate = false;
|
||||
if (iocp->send(client, send_data) == -1) {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user