diff --git a/CMakeLists.txt b/CMakeLists.txt index 31ff757..0649a2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.26) -project(towards) +project(tw_common) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 23) @@ -42,11 +42,7 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PUBLIC - tw::network - tw::protocol - loft::common - loft::base - loft::render_graph + spdlog::spdlog glm::glm EnTT::EnTT Jolt diff --git a/conanfile.txt b/conanfile.txt index c475c0a..ea0c46e 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,12 +1,15 @@ [requires] protobuf/7.35.0 sdl/3.4.8 +libpqxx/8.0.2 [tool_requires] protobuf/7.35.0 [options] protobuf/*:shared=False +libpqxx/*:shared=False +libpq/*:shared=True sdl/*:shared=False sdl/*:camera=False sdl/*:dialog=False diff --git a/docker/Dockerfile b/docker/Dockerfile index 92e10ee..8b35407 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -83,6 +83,7 @@ RUN --mount=type=cache,target=/build \ && mkdir -p /out/bin /out/shaders \ && cp /build/modules/client/tw_client \ /build/modules/mock_client/tw_mock_client \ + /build/modules/server/tw_server \ /build/modules/chat_service/chat_server_exe/tw_chat_server_exe \ /build/modules/chat_service/chat_service/tests/chat_mock_client/tw_chat_mock_client \ /out/bin/ \ @@ -94,6 +95,8 @@ RUN --mount=type=cache,target=/build \ FROM scratch AS export COPY --from=builder /out/bin/tw_client /tw_client +COPY --from=builder /out/bin/tw_server /tw_server +COPY --from=builder /out/bin/tw_mock_client /tw_mock_client COPY --from=builder /out/shaders/ /shaders/ diff --git a/modules/client/CMakeLists.txt b/modules/client/CMakeLists.txt index 8bfa7b5..f2fa2fa 100644 --- a/modules/client/CMakeLists.txt +++ b/modules/client/CMakeLists.txt @@ -21,7 +21,7 @@ add_dependencies(tw_shaders imgui::plot imgui::plot) target_link_libraries(${PROJECT_NAME} PUBLIC - towards + tw_common tw::network tw::metrics tw::quicr @@ -41,8 +41,6 @@ target_link_libraries(${PROJECT_NAME} Jolt Tracy::TracyClient TracyClient - # pqxx - # pq ) target_include_directories(${PROJECT_NAME} diff --git a/modules/client/src/debug/CharacterControllerDebug.hpp b/modules/client/src/debug/CharacterControllerDebug.hpp index 7b7302f..1da4ddb 100644 --- a/modules/client/src/debug/CharacterControllerDebug.hpp +++ b/modules/client/src/debug/CharacterControllerDebug.hpp @@ -10,34 +10,5 @@ class tw::dbg::ComponentGui { public: void draw(tw::CharacterController* instance) { ImGui::SeparatorText("Character Controller Component"); - - if(ImGui::BeginTable("history", 3)) { - for(auto key : instance->input_history().buffer()) { - // ImGui::TableNextRow(); - - // ImGui::TableNextColumn(); - // ImGui::Text("%u", key.first); - - // ImGui::TableNextColumn(); - // if(instance->input_history().get(key.first).has_value()) { - // glm::vec3 input_vec = *instance->input_history().get(key.first).value(); - // std::string input = std::format("{} {} {}", input_vec.x, input_vec.y, input_vec.z); - // ImGui::Text("%s", input.c_str()); - // } else { - // ImGui::Text("None"); - // } - - // ImGui::TableNextColumn(); - // if(instance->position_history().get(key).has_value()) { - // glm::vec3 position_vec = *instance->position_history().get(key).value(); - // std::string position = std::format("{} {} {}", position_vec.x, position_vec.y, position_vec.z); - // ImGui::Text("%s", position.c_str()); - // } else { - // ImGui::Text("None"); - // } - } - - ImGui::EndTable(); - } } }; diff --git a/modules/mock_client/CMakeLists.txt b/modules/mock_client/CMakeLists.txt index 5995a40..558390e 100644 --- a/modules/mock_client/CMakeLists.txt +++ b/modules/mock_client/CMakeLists.txt @@ -8,7 +8,7 @@ add_executable(${PROJECT_NAME} ${FILES}) target_link_libraries(${PROJECT_NAME} PUBLIC - towards + tw_common tw::network tw::quicr tw::protocol diff --git a/modules/peer_to_peer/CMakeLists.txt b/modules/peer_to_peer/CMakeLists.txt index 9a0b5b4..18338b7 100644 --- a/modules/peer_to_peer/CMakeLists.txt +++ b/modules/peer_to_peer/CMakeLists.txt @@ -22,7 +22,7 @@ target_include_directories(tw_peer_to_peer_lib target_link_libraries(tw_peer_to_peer_lib PUBLIC - towards + tw_common tw::network tw::quicr tw::protocol @@ -32,8 +32,6 @@ target_link_libraries(tw_peer_to_peer_lib spdlog::spdlog ) -# ── standalone executable ───────────────────────────────────────────────────── - add_executable(${PROJECT_NAME} src/PeerToPeer.cpp) target_link_libraries(${PROJECT_NAME} @@ -41,6 +39,4 @@ target_link_libraries(${PROJECT_NAME} tw_peer_to_peer_lib ) -# ── tests ───────────────────────────────────────────────────────────────────── - add_subdirectory(tests) diff --git a/modules/serialization/CMakeLists.txt b/modules/serialization/CMakeLists.txt index 05c44f7..aebc0ef 100644 --- a/modules/serialization/CMakeLists.txt +++ b/modules/serialization/CMakeLists.txt @@ -20,8 +20,6 @@ target_link_libraries(tw_serialization EnTT::EnTT ) -# Require C++20 for concepts / span target_compile_features(tw_serialization INTERFACE cxx_std_20) -# ── Tests / benchmarks ─────────────────────────────────────────────────────── -add_subdirectory(tests) +# add_subdirectory(tests) diff --git a/modules/serialization/tests/CMakeLists.txt b/modules/serialization/tests/CMakeLists.txt index 16bf7b3..45e58f6 100644 --- a/modules/serialization/tests/CMakeLists.txt +++ b/modules/serialization/tests/CMakeLists.txt @@ -17,7 +17,7 @@ file(GLOB FILES # ) # add_executable(${PROJECT_NAME}) -add_executable(SerializationBenchmarks ./SerializationBenchmarks.cpp) +# add_executable(SerializationBenchmarks ./SerializationBenchmarks.cpp) target_compile_definitions(SerializationBenchmarks PRIVATE TRACY_ON_DEMAND=1) diff --git a/modules/server/CMakeLists.txt b/modules/server/CMakeLists.txt index 2596805..92eab6d 100644 --- a/modules/server/CMakeLists.txt +++ b/modules/server/CMakeLists.txt @@ -14,6 +14,7 @@ file(GLOB FILES src/network/*.cpp ) +find_package(libpqxx CONFIG REQUIRED) add_library(tw_server_lib STATIC ${FILES}) target_include_directories(tw_server_lib @@ -23,7 +24,7 @@ target_include_directories(tw_server_lib target_link_libraries(tw_server_lib PUBLIC - towards + tw_common tw::io tw::network tw::protocol @@ -35,10 +36,8 @@ target_link_libraries(tw_server_lib Jolt protobuf::libprotobuf ${Boost_LIBRARIES} - ${LIBDECOR_LIB} Tracy::TracyClient - pqxx - pq + libpqxx::pqxx ) add_executable(${PROJECT_NAME} src/server.cpp) diff --git a/modules/server/src/monitoring/TimescaleDbMetricsReporter.cpp b/modules/server/src/monitoring/TimescaleDbMetricsReporter.cpp index fc57c1b..7194d1f 100644 --- a/modules/server/src/monitoring/TimescaleDbMetricsReporter.cpp +++ b/modules/server/src/monitoring/TimescaleDbMetricsReporter.cpp @@ -7,7 +7,7 @@ TimescaleDbMetricsReporter::TimescaleDbMetricsReporter(const TimescaleDbConfigur m_last_flush_time(std::chrono::steady_clock::now()) { try { - m_connection = pqxx::connection(config.connection.to_string()); + m_connection.emplace(config.connection.to_string()); spdlog::info("Connected to TimescaleDB at {}:{}", config.connection.host, config.connection.port); } catch (const std::exception& e) { spdlog::error("Failed to connect to TimescaleDB: {}", e.what()); @@ -23,9 +23,9 @@ void TimescaleDbMetricsReporter::flush() { pqxx::work tx{*m_connection}; const auto table = m_connection->quote_name(m_metrics_table); - tx.exec("INSERT INTO " + table + " (time, outbound, inbound, player_count) VALUES (NOW(), $1, $2, $3)", - pqxx::params(m_outbound_bucket, m_inbound_bucket, m_player_count)) - .no_rows(); + tx.exec_prepared("INSERT INTO " + table + " (time, outbound, inbound, player_count) VALUES (NOW(), $1, $2, $3)", + m_outbound_bucket, m_inbound_bucket, m_player_count) + .empty(); tx.commit(); TracyPlot("outbound", (int64_t)m_outbound_bucket); diff --git a/modules/server_gui/CMakeLists.txt b/modules/server_gui/CMakeLists.txt index 15590c8..c203a8c 100644 --- a/modules/server_gui/CMakeLists.txt +++ b/modules/server_gui/CMakeLists.txt @@ -24,7 +24,7 @@ target_link_libraries( tw::protocol tw::message_protocol tw::quicr - towards + tw_common tw::gui imgui::imgui imgui::plot diff --git a/modules/template/CMakeLists.txt b/modules/template/CMakeLists.txt index 55ff869..8344fff 100644 --- a/modules/template/CMakeLists.txt +++ b/modules/template/CMakeLists.txt @@ -33,8 +33,6 @@ target_link_libraries(tw_server_lib protobuf::libprotobuf ${Boost_LIBRARIES} Tracy::TracyClient - pqxx - pq ) add_executable(${PROJECT_NAME} src/server.cpp) diff --git a/src/world/CharacterBody.hpp b/src/world/CharacterBody.hpp index cf4a653..a1680fb 100644 --- a/src/world/CharacterBody.hpp +++ b/src/world/CharacterBody.hpp @@ -1,6 +1,5 @@ #pragma once -#include "metrics/HistoryBuffer.hpp" #include #include diff --git a/src/world/CharacterController.hpp b/src/world/CharacterController.hpp index 8723e25..f0cad4d 100644 --- a/src/world/CharacterController.hpp +++ b/src/world/CharacterController.hpp @@ -4,8 +4,6 @@ #include #include -#include "metrics/HistoryBuffer.hpp" - namespace tw { /** @@ -17,9 +15,6 @@ private: using Clock = std::chrono::steady_clock; - HistoryBuffer m_history; - HistoryBuffer m_position_history; - struct InputSlot { uint32_t frame; glm::vec3 input; @@ -34,13 +29,9 @@ private: public: GET(m_speed, speed); - GET_MUT_REF(m_history, input_history); - GET_MUT_REF(m_position_history, position_history); CharacterController(float speed) : m_speed(speed), - m_history(Clock::now(), glm::vec3(), 10 * 20), - m_position_history(Clock::now(), glm::vec3(), 10 * 20), m_input_ring(64), m_last_input_frame(0), m_frame_idx(0) diff --git a/src/world/JoltPhysicsWorld.hpp b/src/world/JoltPhysicsWorld.hpp index 165a0cc..6c7a9b6 100644 --- a/src/world/JoltPhysicsWorld.hpp +++ b/src/world/JoltPhysicsWorld.hpp @@ -3,7 +3,6 @@ #include "world/RigidBody.hpp" #include #include -#include "metrics/HistoryBuffer.hpp" #include #include