tcp/udp 추가, todo:iocp openssl 지원하도록 업데이트하기
This commit is contained in:
@@ -52,7 +52,7 @@ file(GLOB_RECURSE Sources CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${Sources})
|
||||
add_executable(${PROJECT_NAME} ${RootProjectSources} ${Sources})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Vulkan::Vulkan)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE glm)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
|
||||
@@ -62,10 +62,22 @@ target_link_libraries(${PROJECT_NAME} PRIVATE assimp::assimp)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::Crypto)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
if(WIN32)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
||||
endif()
|
||||
if(UNIX AND NOT APPLE AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
BUILD_WITH_INSTALL_RPATH TRUE
|
||||
INSTALL_RPATH "$ORIGIN"
|
||||
SKIP_BUILD_RPATH FALSE
|
||||
BUILD_RPATH "$ORIGIN"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include" "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
|
||||
|
||||
target_precompile_headers(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/precomp.h")
|
||||
target_precompile_headers(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include/precomp.h")
|
||||
|
||||
file(GLOB_RECURSE ShaderSources CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.vert"
|
||||
@@ -80,4 +92,18 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/assets"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/assets"
|
||||
COMMENT "Copying assets to build directory"
|
||||
)
|
||||
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE:spdlog>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying spdlog DLL/so to output directory"
|
||||
)
|
||||
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"$<TARGET_FILE_DIR:spdlog>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying spdlog library files and symlinks to output directory"
|
||||
)
|
||||
@@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <glm/glm.hpp>
|
||||
#include <gsl/gsl>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define NOMINMAX
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <ws2bth.h>
|
||||
#include <ws2def.h>
|
||||
#include <windows.h>
|
||||
#define in_addr_t ULONG
|
||||
#elif __linux__
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/eventfd.h>
|
||||
#define SOCKET int
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
#else
|
||||
#error "이 플랫폼은 지원되지 않습니다."
|
||||
#endif
|
||||
|
||||
#define MAX_BUFFERED_FRAMES (2)
|
||||
@@ -1,78 +0,0 @@
|
||||
#pragma once
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
namespace utils {
|
||||
|
||||
class ThreadPool {
|
||||
public:
|
||||
ThreadPool();
|
||||
ThreadPool(std::uint32_t numThreads);
|
||||
~ThreadPool();
|
||||
|
||||
void init(std::uint32_t numThreads);
|
||||
void terminate();
|
||||
|
||||
void respawnWorker(std::uint32_t numThreads);
|
||||
|
||||
template <typename _Callable, typename... _Args>
|
||||
requires(
|
||||
!std::is_void_v<std::invoke_result_t<_Callable, ThreadPool*, _Args...>>)
|
||||
int enqueueJob(_Callable&& __job,
|
||||
std::invoke_result_t<_Callable, _Args...>& retVal,
|
||||
_Args&&... __args) {
|
||||
if (terminate_) {
|
||||
spdlog::error("Cannot run jobs on threads that terminating...");
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(jobQueueMutex);
|
||||
auto boundFunc = [this, &retVal, __job,
|
||||
... __args = std::move(__args)]() mutable {
|
||||
retVal = __job(this, std::move(__args)...);
|
||||
};
|
||||
auto task = std::packaged_task<void()>(std::move(boundFunc));
|
||||
jobs_.push(std::move(task));
|
||||
jobQueueCV_.notify_one();
|
||||
|
||||
return 0;
|
||||
}
|
||||
template <typename _Callable, typename... _Args>
|
||||
requires std::is_void_v<
|
||||
std::invoke_result_t<_Callable, ThreadPool*, _Args...>>
|
||||
int enqueueJob(_Callable&& __job, _Args&&... __args) {
|
||||
if (terminate_) {
|
||||
spdlog::error("Cannot run jobs on threads that terminating...");
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(jobQueueMutex);
|
||||
auto boundFunc = [this, __job, ... __args = std::move(__args)]() mutable {
|
||||
__job(this, std::move(__args)...);
|
||||
};
|
||||
auto task = std::packaged_task<void()>(std::move(boundFunc));
|
||||
jobs_.push(std::move(task));
|
||||
jobQueueCV_.notify_one();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int threadCount = 0;
|
||||
|
||||
private:
|
||||
void* Worker();
|
||||
|
||||
std::condition_variable jobQueueCV_;
|
||||
std::mutex jobQueueMutex;
|
||||
std::queue<std::packaged_task<void()>> jobs_;
|
||||
std::vector<std::thread> workers_;
|
||||
bool terminate_ = false;
|
||||
};
|
||||
|
||||
} // namespace Chattr
|
||||
@@ -1,82 +0,0 @@
|
||||
#include "utils/thread_pool.h"
|
||||
#include "precomp.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
ThreadPool::ThreadPool() : ThreadPool(0) {}
|
||||
|
||||
ThreadPool::ThreadPool(std::uint32_t numThreads) { init(numThreads); }
|
||||
|
||||
ThreadPool::~ThreadPool() { terminate(); }
|
||||
|
||||
void ThreadPool::init(std::uint32_t numThreads) {
|
||||
int numCPU = numThreads;
|
||||
if (numThreads == 0) {
|
||||
#ifdef _WIN32
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
numCPU = sysinfo.dwNumberOfProcessors;
|
||||
#elif __linux__
|
||||
numCPU = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
#endif
|
||||
spdlog::info("Auto-detected cpu count: {}", numCPU);
|
||||
if (numCPU == 1 || numCPU == 2) {
|
||||
numCPU = 4;
|
||||
spdlog::info(
|
||||
"Set ThreadPool Worker count to: {} due to program to oprate "
|
||||
"concurrently",
|
||||
numCPU);
|
||||
} else {
|
||||
spdlog::info("Set ThreadPool Worker count to: {}", numCPU);
|
||||
}
|
||||
}
|
||||
threadCount = numCPU;
|
||||
workers_.reserve(numCPU);
|
||||
|
||||
while (numCPU--) workers_.emplace_back([this]() { this->Worker(); });
|
||||
}
|
||||
|
||||
void ThreadPool::terminate() {
|
||||
terminate_ = true;
|
||||
jobQueueCV_.notify_all();
|
||||
|
||||
spdlog::debug("waiting for threads to end their jobs...");
|
||||
for (auto& t : workers_) t.join();
|
||||
}
|
||||
|
||||
void ThreadPool::respawnWorker(std::uint32_t numThreads) {
|
||||
terminate();
|
||||
terminate_ = false;
|
||||
init(numThreads);
|
||||
}
|
||||
|
||||
void* ThreadPool::Worker() {
|
||||
#ifdef _WIN32
|
||||
DWORD pid = GetCurrentThreadId();
|
||||
#elif __linux__
|
||||
pthread_t pid = pthread_self();
|
||||
#endif
|
||||
spdlog::trace("ThreadPool Worker : {} up", pid);
|
||||
while (!terminate_) {
|
||||
std::unique_lock<std::mutex> lock(jobQueueMutex);
|
||||
jobQueueCV_.wait(lock,
|
||||
[this]() { return !this->jobs_.empty() || terminate_; });
|
||||
if (this->jobs_.empty() || terminate_) {
|
||||
jobs_ = std::queue<std::packaged_task<void()>>();
|
||||
break;
|
||||
}
|
||||
if (this->jobs_.empty()) continue;
|
||||
|
||||
auto job = std::move(jobs_.front());
|
||||
jobs_.pop();
|
||||
lock.unlock();
|
||||
|
||||
spdlog::trace("ThreadPool Worker : {} Executing a job", pid);
|
||||
job();
|
||||
}
|
||||
spdlog::trace("ThreadPool Worker : {} down", pid);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace Chattr
|
||||
@@ -70,7 +70,7 @@ void Graphics::CreateInstance() {
|
||||
VkApplicationInfo app_info = {};
|
||||
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
app_info.pNext = nullptr;
|
||||
app_info.pApplicationName = "Udemy Course";
|
||||
app_info.pApplicationName = "Asteroid";
|
||||
app_info.applicationVersion = VK_MAKE_API_VERSION(0, 0, 0, 0);
|
||||
app_info.pEngineName = "VEng";
|
||||
app_info.engineVersion = VK_MAKE_API_VERSION(0, 1, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user