Replies: 3 comments 4 replies
-
I suspect it's going to take a while: d8c1a50#commitcomment-111968233. |
Beta Was this translation helpful? Give feedback.
-
I guess if you want to get hands dirty, you can hack into Line 1260 in 083c8a0 Then create own fixed metafunction using some existing as base, and rebuild cppfront? |
Beta Was this translation helpful? Give feedback.
-
You can play around with it directly having The current reflection API works pretty well for the built-in metafunctions. In particular, I'd like to reduce the boilerplate of the shim I'm writing.
Before, I wrote a similar shim with TMP for a different library: waarudo.pixel_game_engine.cppThe relevant bits: #include <olcPixelGameEngine.h>
export module waarudo.pixel_game_engine;
template<class T> constexpr bool is_pge_argument{
std::is_scalar_v<T> or std::is_same_v<T, olc::Pixel> or std::is_same_v<T, std::string> or
std::is_same_v<T, olc::vf2d> or std::is_same_v<T, std::array<olc::vf2d, 4>>};
[[nodiscard]] olc::vf2d as_pge_argument(const pge_point<float> v) { return {v.x.number, v.y.number}; }
[[nodiscard]] olc::vf2d as_pge_argument(const pge_vector<float> v) { return {v.x.number, v.y.number}; }
template<bool B, class T> [[nodiscard]] constexpr auto pge_arguments_tie(const T& v) {
if constexpr (is_pge_argument<T>) return std::tie(v);
else if constexpr (B and requires { as_pge_argument(v); }) {
static_assert(is_pge_argument<decltype(as_pge_argument(v))>);
return std::tuple{as_pge_argument(v)};
} else return boost::pfr::structure_tie(v);
}
template<bool B = false, class... T> [[nodiscard]] constexpr decltype(auto) pge_call(const auto f, const T&... v) {
if constexpr ((... and is_pge_argument<T>)) return std::invoke(f, v...);
else return std::apply([&](const auto&... x) { return pge_call<B>(f, x...); }, tuple_cat(pge_arguments_tie<B>(v)...));
}
export class pixel_game_engine : public olc::PixelGameEngine {
public:
void construct(const construct_arguments& args) { expects(pge_call(&PixelGameEngine::Construct, this, args)); }
gui_window_point window_mouse() const { return from_olc(GetWindowMouse()); }
pge_point<std::int32_t> mouse() const { return from_olc(GetMousePos()); }
void screen_size(pge_vector<std::int32_t> v) { pge_call(&PixelGameEngine::SetScreenSize, this, v); }
gui_vector window_size() const { return from_olc(GetWindowSize()); }
gui_vector pixel_size() const { return from_olc(GetPixelSize()); }
gui_vector screen_pixel_size() const { return from_olc(GetScreenPixelSize()); }
#define WAARUDO_PGE_LIFT(F) [](auto* pge, auto... arg) { return pge->F(arg...); }
void draw_decal(_draw_string_args<float, pge_vector<float>{.x{1}, .y{1}}> s) {
pge_call<true>(&PixelGameEngine::DrawStringDecal, this, s);
}
void draw_decal(_draw_string_prop_args<float, pge_vector<float>{.x{1}, .y{1}}> s) {
pge_call<true>(&PixelGameEngine::DrawStringPropDecal, this, s);
}
void draw(_draw_warped_decal_args s) { pge_call<true>(WAARUDO_PGE_LIFT(DrawWarpedDecal), this, s); }
void draw(_draw_partial_warped_decal_args s) { pge_call<true>(WAARUDO_PGE_LIFT(DrawPartialWarpedDecal), this, s); }
};
module: private;
bool pixel_game_engine::draw(pge_point<std::int32_t> pt, olc::Pixel px) {
return pge_call(WAARUDO_PGE_LIFT(Draw), this, pt, px);
}
void pixel_game_engine::draw_line(
pge_point<std::int32_t> a, pge_point<std::int32_t> b, olc::Pixel p, std::uint32_t pattern) {
pge_call(WAARUDO_PGE_LIFT(DrawLine), this, a, b, p, pattern);
}
void pixel_game_engine::draw_circle(pge_point<std::int32_t> center, pge_radius r, olc::Pixel p, std::uint8_t mask) {
pge_call(WAARUDO_PGE_LIFT(DrawCircle), this, center, r, p, mask);
}
void pixel_game_engine::fill_circle(pge_point<std::int32_t> center, pge_radius r, olc::Pixel p) {
pge_call(WAARUDO_PGE_LIFT(FillCircle), this, center, r, p);
}
void pixel_game_engine::draw_rectangle(pge_point<std::int32_t> top_left, pge_vector<std::int32_t> size, olc::Pixel p) {
pge_call(WAARUDO_PGE_LIFT(DrawRect), this, top_left, size, p);
}
void pixel_game_engine::fill_rectangle(pge_point<std::int32_t> top_left, pge_vector<std::int32_t> size, olc::Pixel p) {
pge_call(WAARUDO_PGE_LIFT(FillRect), this, top_left, size, p);
}
void pixel_game_engine::draw_triangle(
pge_point<std::int32_t> vertex0, pge_point<std::int32_t> vertex1, pge_point<std::int32_t> vertex2, olc::Pixel p) {
pge_call(WAARUDO_PGE_LIFT(DrawTriangle), this, vertex0, vertex1, vertex2, p);
}
void pixel_game_engine::fill_triangle(
pge_point<std::int32_t> vertex0, pge_point<std::int32_t> vertex1, pge_point<std::int32_t> vertex2, olc::Pixel p) {
pge_call(WAARUDO_PGE_LIFT(FillTriangle), this, vertex0, vertex1, vertex2, p);
}
void pixel_game_engine::draw_sprite(
pge_point<std::int32_t> top_left, olc::Sprite* s, pge_pixels<std::uint32_t> scale, olc::Sprite::Flip flip) {
pge_call(WAARUDO_PGE_LIFT(DrawSprite), this, top_left, s, scale, flip);
}
void pixel_game_engine::draw_partial_sprite(
pge_point<std::int32_t> window_top_left, olc::Sprite* s, pge_rectangle<std::int32_t> sprite_area,
pge_pixels<std::uint32_t> scale, olc::Sprite::Flip flip) {
pge_call(WAARUDO_PGE_LIFT(DrawPartialSprite), this, window_top_left, s, sprite_area, scale, flip);
}
void pixel_game_engine::draw_string(
pge_point<std::int32_t> top_left, const std::string& text, olc::Pixel p, pge_pixels<std::uint32_t> scale) {
pge_call(WAARUDO_PGE_LIFT(DrawString), this, top_left, text, p, scale);
}
pge_vector<std::int32_t> pixel_game_engine::text_size(const std::string& s) { return from_olc(GetTextSize(s)); }
void pixel_game_engine::draw_string_prop(
pge_point<std::int32_t> top_left, const std::string& text, olc::Pixel p, pge_pixels<std::uint32_t> scale) {
pge_call(WAARUDO_PGE_LIFT(DrawStringProp), this, top_left, text, p, scale);
}
pge_vector<std::int32_t> pixel_game_engine::text_size_prop(const std::string& s) {
return from_olc(GetTextSizeProp(s));
}
} // namespace waarudo
SFML 3 is more modern and idiomatic.
For example, these changes should be possible:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your nice talk on CppCon 2023! This is very inspiring!! (Hoping for a "Typescript for C++" ;-) )
When will it be possible to play with own meta functions. It seems to be limited to the existing ones (
(temporary alpha limitation) currently the supported names are: interface, ...
?Beta Was this translation helpful? Give feedback.
All reactions