Skip to content

Commit 2599cca

Browse files
Merge pull request #1 from BestITUserEUW/new-stuff
New stuff
2 parents 479ccc9 + ec0200e commit 2599cca

30 files changed

Lines changed: 1988 additions & 827 deletions

.github/workflows/linux.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ jobs:
1717
- compiler: llvm
1818
compiler-version: 18
1919
cxx: 23
20-
- compiler: gcc
21-
compiler-version: 12
22-
cxx: 20
2320
- compiler: gcc
2421
compiler-version: 13
2522
cxx: 20
2623
- compiler: gcc
2724
compiler-version: 14
28-
cxx: 23
25+
cxx: 23
2926
name: "${{ github.job }} (C++${{ matrix.cxx }}-${{ matrix.compiler }}-${{ matrix.compiler-version }})"
30-
runs-on: ubuntu-24.04
27+
runs-on: ubuntu-latest
3128
steps:
3229
- name: Checkout
3330
uses: actions/checkout@v4

CMakeLists.txt

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,41 @@ else()
2020
endif()
2121

2222
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
23-
target_compile_options(${PROJECT_NAME} PRIVATE
24-
/W4
23+
target_compile_options(${PROJECT_NAME}
24+
PRIVATE
25+
/W4
2526
)
2627
else()
27-
target_compile_options(${PROJECT_NAME} PRIVATE
28-
-Wall
29-
-Wextra
30-
-Wuninitialized
31-
-Wno-unused-function
32-
-Wunused-variable
28+
target_compile_options(${PROJECT_NAME}
29+
PRIVATE
30+
-Wall
31+
-Wextra
32+
-Werror
33+
-Wuninitialized
34+
-Wno-unused-function
35+
-Wunused-variable
3336
)
3437
endif()
3538

36-
target_include_directories(${PROJECT_NAME} PUBLIC
37-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
38-
$<INSTALL_INTERFACE:include>
39+
target_include_directories(${PROJECT_NAME}
40+
PUBLIC
41+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
42+
$<INSTALL_INTERFACE:include>
3943
)
4044

41-
target_sources(${PROJECT_NAME} PRIVATE
42-
src/frame_rate_controller.cpp
45+
file(GLOB_RECURSE ORYX_CRT_HEADERS
46+
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
47+
"${CMAKE_CURRENT_SOURCE_DIR}/include/*"
48+
)
49+
50+
target_sources(${PROJECT_NAME}
51+
PRIVATE
52+
src/frame_rate_controller.cpp
53+
src/uuid.cpp
54+
PUBLIC
55+
FILE_SET HEADERS
56+
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
57+
FILES ${ORYX_CRT_HEADERS}
4358
)
4459

4560

@@ -53,8 +68,14 @@ if(ORYX_CRT_BUILD_TESTS)
5368
tests/string_split_test.cpp
5469
tests/callback_list_test.cpp
5570
tests/from_chars_test.cpp
71+
tests/is_one_off_test.cpp
72+
tests/unique_file_ptr_test.cpp
73+
tests/error_group_test.cpp
74+
tests/traits_test.cpp
5675
)
76+
5777
target_link_libraries(${test_exe} PRIVATE ${PROJECT_NAME})
78+
5879
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5980
target_compile_definitions(${test_exe} PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
6081
endif()
@@ -64,35 +85,36 @@ if (ORYX_CRT_INSTALL)
6485
include(GNUInstallDirs)
6586
include(CMakePackageConfigHelpers)
6687

67-
configure_package_config_file(cmake/${PROJECT_NAME}-config.cmake.in
68-
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
69-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
88+
configure_package_config_file(
89+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
90+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
91+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
7092
)
7193

72-
install(
73-
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
74-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
94+
write_basic_package_version_file(
95+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake"
96+
COMPATIBILITY ExactVersion
7597
)
7698

77-
file(GLOB_RECURSE ORYX_CRT_HEADERS RELATIVE ${CMAKE_CURRENT_LIST_DIR} "${CMAKE_CURRENT_LIST_DIR}/include/*" )
78-
79-
target_sources(${PROJECT_NAME}
80-
PUBLIC
81-
FILE_SET oryx_headers
82-
TYPE HEADERS
83-
BASE_DIRS $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
84-
FILES ${ORYX_CRT_HEADERS}
99+
install(
100+
TARGETS ${PROJECT_NAME}
101+
EXPORT ${PROJECT_NAME}-targets
102+
FILE_SET HEADERS
85103
)
86104

87105
install(
88-
TARGETS ${PROJECT_NAME}
89-
EXPORT ${PROJECT_NAME}-exports
90-
FILE_SET oryx_headers DESTINATION ${INCLUDE_INSTALL_DIR}
106+
FILES
107+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
108+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake"
109+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
110+
COMPONENT ${PROJECT_NAME}
91111
)
92112

93113
install(
94-
EXPORT ${PROJECT_NAME}-exports
95-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
114+
EXPORT ${PROJECT_NAME}-targets
115+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
96116
NAMESPACE oryx::
117+
FILE ${PROJECT_NAME}-targets.cmake
118+
COMPONENT ${PROJECT_NAME}
97119
)
98120
endif ()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Common C++ Runtime used for personal C++ Projects. Happy to accept any contribut
1313
## Build Locally
1414

1515
```bash
16-
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug -Bbuild -H.
16+
cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug -Bbuild -H.
1717
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1818
Only needed for clangd
1919
```

include/oryx/argparse.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ class CLI {
4646

4747
template <class T>
4848
void VisitIfContains(std::string_view option, auto visitor) {
49-
if (!Contains(option)) {
50-
return;
51-
}
52-
5349
auto value = GetValue<T>(option);
5450
if (value) {
5551
std::invoke(visitor, std::forward<T>(*value));
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
3+
#include <chrono>
4+
#include <optional>
5+
6+
#include <oryx/scope_exit.hpp>
7+
#include <oryx/chrono/stopwatch.hpp>
8+
9+
namespace oryx::chrono {
10+
11+
template <class Clock = std::chrono::steady_clock>
12+
requires std::chrono::is_clock_v<Clock>
13+
class CycleTimer {
14+
public:
15+
using Duration = std::chrono::milliseconds;
16+
17+
explicit CycleTimer(Duration target)
18+
: target_(target) {}
19+
20+
auto GetNextSleep() -> std::optional<Duration> {
21+
const auto elapsed = sw_.ElapsedMs();
22+
if (elapsed >= target_) {
23+
return std::nullopt;
24+
}
25+
26+
return Duration(target_ - elapsed);
27+
}
28+
29+
void Reset() { sw_.Reset(); }
30+
31+
auto target_cycle_time() const -> Duration { return target_; }
32+
33+
private:
34+
const Duration target_;
35+
details::StopwatchImpl<Clock> sw_{};
36+
};
37+
38+
template <class Clock>
39+
auto MakeScopedCycleTimerReset(CycleTimer<Clock>& timer) {
40+
return ScopeExit{[&timer] { timer.Reset(); }};
41+
}
42+
43+
template <class Clock>
44+
auto MakeFrameRateTimer(int target_fps) {
45+
return CycleTimer<Clock>{typename CycleTimer<Clock>::Duration{1000 / target_fps}};
46+
}
47+
48+
} // namespace oryx::chrono

include/oryx/chrono/frame_rate_controller.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44

55
#include <oryx/chrono/stopwatch.hpp>
66

7-
// TODO: Replace this with a CycleTimeController and add a MakeFrameRateController which just calculates the target
8-
// cycle duration like in the current constructor. Then this can also be used to hold a specific cycle time like we
9-
// already to in PathFindingCpp
10-
117
namespace oryx::chrono {
128

13-
class FrameRateController {
9+
class [[deprecated("Deprecated in favor of MakeFrameRateTimer() from cycle_timer.hpp")]] FrameRateController {
1410
public:
1511
explicit FrameRateController(int target_fps);
1612
auto Sleep() -> bool;

include/oryx/chrono/now.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <chrono>
4+
5+
namespace oryx::chrono {
6+
7+
using NowClock = std::chrono::system_clock;
8+
9+
inline auto Now() { return NowClock::now(); }
10+
11+
inline auto NowMillis() {
12+
using namespace std::chrono;
13+
return duration_cast<milliseconds>(Now().time_since_epoch()).count();
14+
}
15+
16+
inline auto NowSecs() {
17+
using namespace std::chrono;
18+
return duration_cast<seconds>(Now().time_since_epoch()).count();
19+
}
20+
21+
} // namespace oryx::chrono

include/oryx/chrono/stopwatch.hpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@
22

33
#include <chrono>
44

5-
#include <oryx/types.hpp>
6-
75
namespace oryx::chrono {
6+
namespace details {
87

9-
class Stopwatch {
8+
template <class Clock>
9+
requires std::chrono::is_clock_v<Clock>
10+
class StopwatchImpl {
1011
public:
11-
using clock = std::chrono::steady_clock;
12-
13-
Stopwatch()
14-
: start_{clock::now()} {}
12+
StopwatchImpl()
13+
: start_{Clock::now()} {}
1514

16-
Stopwatch(clock::time_point start)
15+
explicit StopwatchImpl(Clock::time_point start)
1716
: start_(start) {}
1817

19-
auto Elapsed() const -> std::chrono::duration<f64> { return std::chrono::duration<f64>(clock::now() - start_); }
18+
auto Elapsed() const -> std::chrono::nanoseconds { return Clock::now() - start_; }
2019
auto ElapsedMs() const -> std::chrono::milliseconds {
21-
return std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - start_);
20+
return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start_);
2221
}
23-
void Reset() { start_ = clock::now(); }
22+
void Reset() { start_ = Clock::now(); }
2423

25-
auto GetStart() const -> clock::time_point { return start_; }
24+
auto GetStart() const { return start_; }
2625

2726
private:
28-
clock::time_point start_;
27+
Clock::time_point start_;
2928
};
3029

30+
} // namespace details
31+
32+
using HighResolutionStopwatch = details::StopwatchImpl<std::chrono::high_resolution_clock>;
33+
using Stopwatch = details::StopwatchImpl<std::chrono::steady_clock>;
34+
3135
} // namespace oryx::chrono

0 commit comments

Comments
 (0)