Skip to content

Commit

Permalink
Cleaned up intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
kgorking committed Nov 21, 2023
1 parent 433bf76 commit 53786ea
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 60 deletions.
7 changes: 4 additions & 3 deletions include/ecs/detail/interval_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ template <int milliseconds, int microseconds>
struct interval_limiter {
bool can_run() {
using namespace std::chrono_literals;
constexpr std::chrono::nanoseconds interval_size = 1ms * milliseconds + 1us * microseconds;
static constexpr std::chrono::nanoseconds interval_size = 1ms * milliseconds + 1us * microseconds;

auto const now = std::chrono::high_resolution_clock::now();
auto const diff = now - time;
Expand All @@ -25,8 +25,9 @@ struct interval_limiter {
std::chrono::high_resolution_clock::time_point time = std::chrono::high_resolution_clock::now();
};

struct no_interval_limiter {
constexpr bool can_run() {
template <>
struct interval_limiter<0, 0> {
static consteval bool can_run() {
return true;
}
};
Expand Down
4 changes: 1 addition & 3 deletions include/ecs/detail/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ class system : public system_base {
using stripped_component_list = transform_type<ComponentsList, std::remove_cvref_t>;

using user_interval = test_option_type_or<is_interval, Options, opts::interval<0, 0>>;
using interval_type =
std::conditional_t<(user_interval::_ecs_duration > 0.0),
interval_limiter<user_interval::_ecs_duration_ms, user_interval::_ecs_duration_us>, no_interval_limiter>;
using interval_type = interval_limiter<user_interval::ms, user_interval::us>;

//
// ecs::parent related stuff
Expand Down
39 changes: 19 additions & 20 deletions include/ecs/ecs.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -2850,24 +2850,24 @@ private:

ECS_EXPORT namespace ecs::opts {
template <int I>
struct group {
static constexpr int group_id = I;
};
struct group {
static constexpr int group_id = I;
};

template <int Milliseconds, int Microseconds = 0>
struct interval {
static_assert(Milliseconds >= 0, "invalid time values specified");
static_assert(Microseconds >= 0 && Microseconds < 1000, "invalid time values specified");
template <int Milliseconds, int Microseconds = 0>
struct interval {
static_assert(Milliseconds >= 0, "time values can not be negative");
static_assert(Microseconds >= 0, "time values can not be negative");
static_assert(Microseconds <= 999, "microseconds must be in the range 0-999");

static constexpr double _ecs_duration = (1.0 * Milliseconds) + (Microseconds / 1000.0);
static constexpr int _ecs_duration_ms = Milliseconds;
static constexpr int _ecs_duration_us = Microseconds;
};
static constexpr int ms = Milliseconds;
static constexpr int us = Microseconds;
};

struct manual_update {};
struct manual_update {};

struct not_parallel {};
// struct not_concurrent {};
struct not_parallel {};
// struct not_concurrent {};

} // namespace ecs::opts

Expand All @@ -2882,7 +2882,7 @@ template <int milliseconds, int microseconds>
struct interval_limiter {
bool can_run() {
using namespace std::chrono_literals;
constexpr std::chrono::nanoseconds interval_size = 1ms * milliseconds + 1us * microseconds;
static constexpr std::chrono::nanoseconds interval_size = 1ms * milliseconds + 1us * microseconds;

auto const now = std::chrono::high_resolution_clock::now();
auto const diff = now - time;
Expand All @@ -2898,8 +2898,9 @@ private:
std::chrono::high_resolution_clock::time_point time = std::chrono::high_resolution_clock::now();
};

struct no_interval_limiter {
constexpr bool can_run() {
template <>
struct interval_limiter<0, 0> {
static consteval bool can_run() {
return true;
}
};
Expand Down Expand Up @@ -3614,9 +3615,7 @@ protected:
using stripped_component_list = transform_type<ComponentsList, std::remove_cvref_t>;

using user_interval = test_option_type_or<is_interval, Options, opts::interval<0, 0>>;
using interval_type =
std::conditional_t<(user_interval::_ecs_duration > 0.0),
interval_limiter<user_interval::_ecs_duration_ms, user_interval::_ecs_duration_us>, no_interval_limiter>;
using interval_type = interval_limiter<user_interval::ms, user_interval::us>;

//
// ecs::parent related stuff
Expand Down
39 changes: 19 additions & 20 deletions include/ecs/ecs_sh.h
Original file line number Diff line number Diff line change
Expand Up @@ -2850,24 +2850,24 @@ struct parent : entity_id, private std::conditional_t<(sizeof...(ParentTypes) >

ECS_EXPORT namespace ecs::opts {
template <int I>
struct group {
static constexpr int group_id = I;
};
struct group {
static constexpr int group_id = I;
};

template <int Milliseconds, int Microseconds = 0>
struct interval {
static_assert(Milliseconds >= 0, "invalid time values specified");
static_assert(Microseconds >= 0 && Microseconds < 1000, "invalid time values specified");
template <int Milliseconds, int Microseconds = 0>
struct interval {
static_assert(Milliseconds >= 0, "time values can not be negative");
static_assert(Microseconds >= 0, "time values can not be negative");
static_assert(Microseconds <= 999, "microseconds must be in the range 0-999");

static constexpr double _ecs_duration = (1.0 * Milliseconds) + (Microseconds / 1000.0);
static constexpr int _ecs_duration_ms = Milliseconds;
static constexpr int _ecs_duration_us = Microseconds;
};
static constexpr int ms = Milliseconds;
static constexpr int us = Microseconds;
};

struct manual_update {};
struct manual_update {};

struct not_parallel {};
// struct not_concurrent {};
struct not_parallel {};
// struct not_concurrent {};

} // namespace ecs::opts

Expand All @@ -2882,7 +2882,7 @@ template <int milliseconds, int microseconds>
struct interval_limiter {
bool can_run() {
using namespace std::chrono_literals;
constexpr std::chrono::nanoseconds interval_size = 1ms * milliseconds + 1us * microseconds;
static constexpr std::chrono::nanoseconds interval_size = 1ms * milliseconds + 1us * microseconds;

auto const now = std::chrono::high_resolution_clock::now();
auto const diff = now - time;
Expand All @@ -2898,8 +2898,9 @@ struct interval_limiter {
std::chrono::high_resolution_clock::time_point time = std::chrono::high_resolution_clock::now();
};

struct no_interval_limiter {
constexpr bool can_run() {
template <>
struct interval_limiter<0, 0> {
static consteval bool can_run() {
return true;
}
};
Expand Down Expand Up @@ -3614,9 +3615,7 @@ class system : public system_base {
using stripped_component_list = transform_type<ComponentsList, std::remove_cvref_t>;

using user_interval = test_option_type_or<is_interval, Options, opts::interval<0, 0>>;
using interval_type =
std::conditional_t<(user_interval::_ecs_duration > 0.0),
interval_limiter<user_interval::_ecs_duration_ms, user_interval::_ecs_duration_us>, no_interval_limiter>;
using interval_type = interval_limiter<user_interval::ms, user_interval::us>;

//
// ecs::parent related stuff
Expand Down
28 changes: 14 additions & 14 deletions include/ecs/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@

ECS_EXPORT namespace ecs::opts {
template <int I>
struct group {
static constexpr int group_id = I;
};
struct group {
static constexpr int group_id = I;
};

template <int Milliseconds, int Microseconds = 0>
struct interval {
static_assert(Milliseconds >= 0, "invalid time values specified");
static_assert(Microseconds >= 0 && Microseconds < 1000, "invalid time values specified");
template <int Milliseconds, int Microseconds = 0>
struct interval {
static_assert(Milliseconds >= 0, "time values can not be negative");
static_assert(Microseconds >= 0, "time values can not be negative");
static_assert(Microseconds <= 999, "microseconds must be in the range 0-999");

static constexpr double _ecs_duration = (1.0 * Milliseconds) + (Microseconds / 1000.0);
static constexpr int _ecs_duration_ms = Milliseconds;
static constexpr int _ecs_duration_us = Microseconds;
};
static constexpr int ms = Milliseconds;
static constexpr int us = Microseconds;
};

struct manual_update {};
struct manual_update {};

struct not_parallel {};
// struct not_concurrent {};
struct not_parallel {};
// struct not_concurrent {};

} // namespace ecs::opts

Expand Down

0 comments on commit 53786ea

Please sign in to comment.