initial commit

This commit is contained in:
2025-05-26 19:36:50 +09:00
parent c0ed33ca17
commit 9a20f0b3db
9 changed files with 224 additions and 21 deletions

View File

@@ -5,6 +5,5 @@
namespace veng {
struct Material {
TextureHandle texture_handle;
std::vector<std::uint8_t> texture_image;
};
} // namespace veng

View File

@@ -9,8 +9,34 @@
#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)

View File

@@ -0,0 +1,78 @@
#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

View File

@@ -1,8 +1,9 @@
#pragma once
#include "asset/loader.h"
#include "physics.h"
#include "graphics.h"
#include "physics.h"
#include "utils/thread_pool.h"
namespace veng {
@@ -34,10 +35,11 @@ class Engine {
glm::perspective(glm::radians(103.f), 800.f / 600.f, 0.1f, 1000.f);
gsl::not_null<Graphics*> vulkan_graphics;
private:
Loader asset_loader_;
Physics physics_controller_;
utils::ThreadPool thread_pool_;
glm::ivec2 window_size_ = {0, 0};
std::double_t last_frame_time_ = 0.0;

View File

@@ -2,11 +2,12 @@
#include "asset/object/model.h"
#include "vulkan/vertex.h"
#include "utils/thread_pool.h"
namespace veng {
class Physics {
public:
void invokeOnColisionEvent(gsl::span<Model*> models);
void invokeOnColisionEvent(gsl::not_null<utils::ThreadPool *> thread_pool, gsl::span<Model*> models);
bool RayTrace(const glm::vec3& rayOrigin, const glm::vec3& rayDir,
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2,