From 52ae390db39df1b4ff6936b001b21fa17aa07881 Mon Sep 17 00:00:00 2001 From: Basit Ayantunde Date: Thu, 28 Nov 2024 01:38:22 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20added=20cast=20to=20resource=20type?= =?UTF-8?q?s=20and=20more=20QoL=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ashura/std/dyn.h | 6 ++++++ ashura/std/math.h | 12 +++++++++++- ashura/std/range.h | 4 ++-- ashura/std/time.h | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ashura/std/dyn.h b/ashura/std/dyn.h index b0a688606..4d6dc269f 100644 --- a/ashura/std/dyn.h +++ b/ashura/std/dyn.h @@ -122,4 +122,10 @@ Dyn transmute(Dyn &&base, H handle) return t; } +template +Dyn cast(Dyn &&from) +{ + return transmute((Dyn &&) from, static_cast(from.get())); +} + } // namespace ash diff --git a/ashura/std/math.h b/ashura/std/math.h index c32b7b0bd..3c2704b25 100644 --- a/ashura/std/math.h +++ b/ashura/std/math.h @@ -515,6 +515,16 @@ constexpr Vec4U8 &operator/=(Vec4U8 &a, Vec4U8 b) return a; } +constexpr Vec4U8 as_vec4u8(Vec4 a) +{ + return Vec4U8{(u8) a.x, (u8) a.y, (u8) a.z, (u8) a.w}; +} + +constexpr Vec4 as_vec4(Vec4U8 a) +{ + return Vec4{(f32) a.x, (f32) a.y, (f32) a.z, (f32) a.w}; +} + struct alignas(8) Vec2I { i32 x = 0; @@ -2293,7 +2303,7 @@ constexpr T catmull_rom(T const &p0, T const &p1, T const &p2, T const &p3, constexpr f32 step(f32 a, f32 t) { - return t < a ? 0.0f : 1.0f; + return (t < a) ? 0.0f : 1.0f; } constexpr f32 smoothstep(f32 a, f32 b, f32 t) diff --git a/ashura/std/range.h b/ashura/std/range.h index 9f751e8f1..6a393e88e 100644 --- a/ashura/std/range.h +++ b/ashura/std/range.h @@ -247,9 +247,9 @@ constexpr Init reduce(R &&range, Init &&init, Reduce &&reducer = {}) return (Init &&) init; } -template +template constexpr Init map_reduce(R &&range, Init &&init, Map &&mapper, - Reduce &&reducer) + Reduce &&reducer = {}) { InputIterator auto it = begin(range); while (it != end(range)) diff --git a/ashura/std/time.h b/ashura/std/time.h index 5234bca1a..f49c29d84 100644 --- a/ashura/std/time.h +++ b/ashura/std/time.h @@ -14,8 +14,10 @@ using std::chrono::months; using std::chrono::nanoseconds; using std::chrono::seconds; using std::chrono::steady_clock; +using clock = steady_clock; using time_point = std::chrono::steady_clock::time_point; using std::chrono::years; +using time_point = steady_clock::time_point; using namespace std::chrono_literals; using std::chrono::duration_cast;