Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ jobs:
- compiler: llvm
compiler-version: 18
cxx: 23
- compiler: gcc
compiler-version: 12
cxx: 20
- compiler: gcc
compiler-version: 13
cxx: 20
- compiler: gcc
compiler-version: 14
cxx: 23
cxx: 23
name: "${{ github.job }} (C++${{ matrix.cxx }}-${{ matrix.compiler }}-${{ matrix.compiler-version }})"
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
86 changes: 54 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,41 @@ else()
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(${PROJECT_NAME} PRIVATE
/W4
target_compile_options(${PROJECT_NAME}
PRIVATE
/W4
)
else()
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wuninitialized
-Wno-unused-function
-Wunused-variable
target_compile_options(${PROJECT_NAME}
PRIVATE
-Wall
-Wextra
-Werror
-Wuninitialized
-Wno-unused-function
-Wunused-variable
)
endif()

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_sources(${PROJECT_NAME} PRIVATE
src/frame_rate_controller.cpp
file(GLOB_RECURSE ORYX_CRT_HEADERS
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/include/*"
)

target_sources(${PROJECT_NAME}
PRIVATE
src/frame_rate_controller.cpp
src/uuid.cpp
PUBLIC
FILE_SET HEADERS
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
FILES ${ORYX_CRT_HEADERS}
)


Expand All @@ -53,8 +68,14 @@ if(ORYX_CRT_BUILD_TESTS)
tests/string_split_test.cpp
tests/callback_list_test.cpp
tests/from_chars_test.cpp
tests/is_one_off_test.cpp
tests/unique_file_ptr_test.cpp
tests/error_group_test.cpp
tests/traits_test.cpp
)

target_link_libraries(${test_exe} PRIVATE ${PROJECT_NAME})

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_definitions(${test_exe} PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
endif()
Expand All @@ -64,35 +85,36 @@ if (ORYX_CRT_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

configure_package_config_file(cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake"
COMPATIBILITY ExactVersion
)

file(GLOB_RECURSE ORYX_CRT_HEADERS RELATIVE ${CMAKE_CURRENT_LIST_DIR} "${CMAKE_CURRENT_LIST_DIR}/include/*" )

target_sources(${PROJECT_NAME}
PUBLIC
FILE_SET oryx_headers
TYPE HEADERS
BASE_DIRS $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
FILES ${ORYX_CRT_HEADERS}
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
FILE_SET HEADERS
)

install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-exports
FILE_SET oryx_headers DESTINATION ${INCLUDE_INSTALL_DIR}
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
COMPONENT ${PROJECT_NAME}
)

install(
EXPORT ${PROJECT_NAME}-exports
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
NAMESPACE oryx::
FILE ${PROJECT_NAME}-targets.cmake
COMPONENT ${PROJECT_NAME}
)
endif ()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Common C++ Runtime used for personal C++ Projects. Happy to accept any contribut
## Build Locally

```bash
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug -Bbuild -H.
cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug -Bbuild -H.
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Only needed for clangd
```
Expand Down
4 changes: 0 additions & 4 deletions include/oryx/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class CLI {

template <class T>
void VisitIfContains(std::string_view option, auto visitor) {
if (!Contains(option)) {
return;
}

auto value = GetValue<T>(option);
if (value) {
std::invoke(visitor, std::forward<T>(*value));
Expand Down
48 changes: 48 additions & 0 deletions include/oryx/chrono/cycle_timer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <chrono>
#include <optional>

#include <oryx/scope_exit.hpp>
#include <oryx/chrono/stopwatch.hpp>

namespace oryx::chrono {

template <class Clock = std::chrono::steady_clock>
requires std::chrono::is_clock_v<Clock>
class CycleTimer {
public:
using Duration = std::chrono::milliseconds;

explicit CycleTimer(Duration target)
: target_(target) {}

auto GetNextSleep() -> std::optional<Duration> {
const auto elapsed = sw_.ElapsedMs();
if (elapsed >= target_) {
return std::nullopt;
}

return Duration(target_ - elapsed);
}

void Reset() { sw_.Reset(); }

auto target_cycle_time() const -> Duration { return target_; }

private:
const Duration target_;
details::StopwatchImpl<Clock> sw_{};
};

template <class Clock>
auto MakeScopedCycleTimerReset(CycleTimer<Clock>& timer) {
return ScopeExit{[&timer] { timer.Reset(); }};
}

template <class Clock>
auto MakeFrameRateTimer(int target_fps) {
return CycleTimer<Clock>{typename CycleTimer<Clock>::Duration{1000 / target_fps}};
}

} // namespace oryx::chrono
6 changes: 1 addition & 5 deletions include/oryx/chrono/frame_rate_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

#include <oryx/chrono/stopwatch.hpp>

// TODO: Replace this with a CycleTimeController and add a MakeFrameRateController which just calculates the target
// cycle duration like in the current constructor. Then this can also be used to hold a specific cycle time like we
// already to in PathFindingCpp

namespace oryx::chrono {

class FrameRateController {
class [[deprecated("Deprecated in favor of MakeFrameRateTimer() from cycle_timer.hpp")]] FrameRateController {
public:
explicit FrameRateController(int target_fps);
auto Sleep() -> bool;
Expand Down
21 changes: 21 additions & 0 deletions include/oryx/chrono/now.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <chrono>

namespace oryx::chrono {

using NowClock = std::chrono::system_clock;

inline auto Now() { return NowClock::now(); }

inline auto NowMillis() {
using namespace std::chrono;
return duration_cast<milliseconds>(Now().time_since_epoch()).count();
}

inline auto NowSecs() {
using namespace std::chrono;
return duration_cast<seconds>(Now().time_since_epoch()).count();
}

} // namespace oryx::chrono
30 changes: 17 additions & 13 deletions include/oryx/chrono/stopwatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@

#include <chrono>

#include <oryx/types.hpp>

namespace oryx::chrono {
namespace details {

class Stopwatch {
template <class Clock>
requires std::chrono::is_clock_v<Clock>
class StopwatchImpl {
public:
using clock = std::chrono::steady_clock;

Stopwatch()
: start_{clock::now()} {}
StopwatchImpl()
: start_{Clock::now()} {}

Stopwatch(clock::time_point start)
explicit StopwatchImpl(Clock::time_point start)
: start_(start) {}

auto Elapsed() const -> std::chrono::duration<f64> { return std::chrono::duration<f64>(clock::now() - start_); }
auto Elapsed() const -> std::chrono::nanoseconds { return Clock::now() - start_; }
auto ElapsedMs() const -> std::chrono::milliseconds {
return std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - start_);
return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start_);
}
void Reset() { start_ = clock::now(); }
void Reset() { start_ = Clock::now(); }

auto GetStart() const -> clock::time_point { return start_; }
auto GetStart() const { return start_; }

private:
clock::time_point start_;
Clock::time_point start_;
};

} // namespace details

using HighResolutionStopwatch = details::StopwatchImpl<std::chrono::high_resolution_clock>;
using Stopwatch = details::StopwatchImpl<std::chrono::steady_clock>;

} // namespace oryx::chrono
Loading
Loading