Skip to content

Commit

Permalink
✨ added cast to resource types and more QoL improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lamarrr committed Nov 28, 2024
1 parent 1fd5cc2 commit 52ae390
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ashura/std/dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@ Dyn<H> transmute(Dyn<Base> &&base, H handle)
return t;
}

template <typename To, typename From>
Dyn<To> cast(Dyn<From> &&from)
{
return transmute((Dyn<From> &&) from, static_cast<To>(from.get()));
}

} // namespace ash
12 changes: 11 additions & 1 deletion ashura/std/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ashura/std/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ constexpr Init reduce(R &&range, Init &&init, Reduce &&reducer = {})
return (Init &&) init;
}

template <InputRange R, typename Init, typename Map, typename Reduce>
template <InputRange R, typename Init, typename Map, typename Reduce = Add>
constexpr Init map_reduce(R &&range, Init &&init, Map &&mapper,
Reduce &&reducer)
Reduce &&reducer = {})
{
InputIterator auto it = begin(range);
while (it != end(range))
Expand Down
2 changes: 2 additions & 0 deletions ashura/std/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 52ae390

Please sign in to comment.