Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/wsi/events/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import stormkit;

#include <stormkit/main/main_macro.hpp>

LOGGER("Events");

using namespace stormkit;
using namespace std::literals;

namespace stdr = std::ranges;

constexpr auto LOG_MODULE = log::module { "events" };

template<class... Ts>
inline auto ilog(std::format_string<Ts...> format, Ts&&... args) noexcept -> void {
LOG_MODULE.ilog(std::move(format), std::forward<Ts>(args)...);
}

////////////////////////////////////////
////////////////////////////////////////
auto main(array_view<const string_view> args) -> int {
Expand Down
10 changes: 8 additions & 2 deletions examples/wsi/framebuffer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import stormkit;

#include <stormkit/main/main_macro.hpp>

LOGGER("Framebuffer");

using namespace stormkit;
using namespace stormkit::literals;
using namespace std::literals;

namespace stdr = std::ranges;

constexpr auto LOG_MODULE = log::module { "framebuffer" };

template<class... Ts>
inline auto ilog(std::format_string<Ts...> format, Ts&&... args) noexcept -> void {
LOG_MODULE.ilog(std::move(format), std::forward<Ts>(args)...);
}

auto update_pixels(stormkit::thread_pool& pool, dynarray<ucolor_rgb>& pixels, const auto& extent) noexcept {
const auto rect_width = extent.width / 5;
const auto rect_height = extent.height / 5;
Expand Down
22 changes: 22 additions & 0 deletions modules/stormkit/core/containers/hash_map.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export namespace stormkit { inline namespace core {

template<typename Key, typename Value, usize N>
constexpr auto make_static_hash_map(std::pair<Key, Value> (&&pairs)[N]) noexcept -> static_hash_map<Key, Value, N>;

template<typename Key, typename Value, usize N>
constexpr auto make_static_hash_map(std::array<std::pair<Key, Value>, N>& pairs) noexcept -> static_hash_map<Key, Value, N>;

template<typename Key, typename Value, usize N>
constexpr auto make_static_hash_map(std::array<std::pair<Key, Value>, N>&& pairs) noexcept -> static_hash_map<Key, Value, N>;
}} // namespace stormkit::core

export template<stormkit::core::meta::has_hasher T>
Expand Down Expand Up @@ -72,4 +78,20 @@ namespace stormkit { inline namespace core {
constexpr auto make_static_hash_map(std::pair<Key, Value> (&&pairs)[N]) noexcept -> static_hash_map<Key, Value, N> {
return frozen::make_unordered_map<Key, Value, N>(std::move(pairs));
}

/////////////////////////////////////
/////////////////////////////////////
template<typename Key, typename Value, usize N>
STORMKIT_FORCE_INLINE
constexpr auto make_static_hash_map(std::array<std::pair<Key, Value>, N>& pairs) noexcept -> static_hash_map<Key, Value, N> {
return frozen::make_unordered_map<Key, Value, N>(pairs);
}

/////////////////////////////////////
/////////////////////////////////////
template<typename Key, typename Value, usize N>
STORMKIT_FORCE_INLINE
constexpr auto make_static_hash_map(std::array<std::pair<Key, Value>, N>&& pairs) noexcept -> static_hash_map<Key, Value, N> {
return frozen::make_unordered_map<Key, Value, N>(std::move(pairs));
}
}} // namespace stormkit::core
5 changes: 3 additions & 2 deletions modules/stormkit/core/containers/shmbuffer.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module;
#include <stormkit/core/api.hpp>
#include <stormkit/core/contract_macro.hpp>
#include <stormkit/core/platform_macro.hpp>
#include <stormkit/core/try_expected.hpp>

export module stormkit.core.containers.shmbuffer;

Expand Down Expand Up @@ -84,7 +85,7 @@ namespace stormkit { inline namespace core {
STORMKIT_FORCE_INLINE
inline auto shm_buffer::create(usize size, string name, io::access access) noexcept -> system_result<shm_buffer> {
auto out = shm_buffer { PRIVATE<shm_buffer> };
out.do_init(size, std::move(name), access);
Try(out.do_init(size, std::move(name), access));
return out;
}

Expand All @@ -93,7 +94,7 @@ namespace stormkit { inline namespace core {
STORMKIT_FORCE_INLINE
inline auto shm_buffer::allocate(usize size, string name, io::access access) noexcept -> system_result<heap_ptr<shm_buffer>> {
auto out = allocate_unsafe<shm_buffer>(PRIVATE<shm_buffer>);
out->do_init(size, std::move(name), access);
Try(out->do_init(size, std::move(name), access));
return out;
}

Expand Down
3 changes: 3 additions & 0 deletions modules/stormkit/core/meta/concepts.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export namespace stormkit { inline namespace core { namespace meta {

using std::convertible_to;

template<typename T, typename... U>
concept convertible_to_any_of = (convertible_to<T, U> or ...);

template<typename From, typename To>
concept explicitly_convertible_to = convertible_to<From, To> or requires(From val) { static_cast<To>(val); };

Expand Down
4 changes: 2 additions & 2 deletions modules/stormkit/core/typesafe/checked_value.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export namespace stormkit { inline namespace core {
public:
using value_type = T;
using reference_type = T&;
using const_reference_type = T&;
using const_reference_type = const meta::remove_const_of<T>&;
using copy_param_type = meta::in<T>;
using checked_param_type = meta::in<checked_value>;

Expand Down Expand Up @@ -276,7 +276,7 @@ namespace stormkit { inline namespace core {
requires(meta::destructible<T> and meta::unary_predicate<decltype(CHECK_FN), T>)
STORMKIT_FORCE_INLINE
constexpr checked_value<T, Tag, CHECK_FN>::operator const_reference_type() const noexcept {
return value;
return std::as_const(value);
}

/////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion modules/stormkit/math/geometry.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace stormkit::math {
template<typename T>
STORMKIT_FORCE_INLINE STORMKIT_PURE
constexpr auto AABB(const vec2<T>& pos, const bounding_rect<T>& rect) noexcept -> bool {
return pos.x >= rect.left and pos.x <= rect.right and pos.y >= rect.top and pos.y <= rect.bottom;
return pos.x() >= rect.left and pos.x() <= rect.right and pos.y() >= rect.top and pos.y() <= rect.bottom;
}

////////////////////////////////////////
Expand Down
13 changes: 3 additions & 10 deletions modules/stormkit/wsi/core.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export namespace stormkit::wsi {
SWITCH,
};

constexpr auto as_string(WM wm) noexcept -> string_view;
constexpr auto to_string(WM wm) noexcept -> string;
[[nodiscard]]
constexpr auto tag_invoke(as_fn<string_view>, WM value, const std::source_location&) noexcept -> string_view;

STORMKIT_WSI_API
auto parse_args(array_view<const string_view> args) noexcept -> void;
Expand All @@ -44,7 +44,7 @@ namespace stormkit::wsi {
////////////////////////////////////////
////////////////////////////////////////
STORMKIT_FORCE_INLINE STORMKIT_CONST
constexpr auto as_string(WM wm) noexcept -> string_view {
constexpr auto tag_invoke(as_fn<string_view>, WM wm, const std::source_location&) noexcept -> string_view {
switch (wm) {
case WM::WIN32: return "WM::WIN32";
case WM::WAYLAND: return "WM::WAYLAND";
Expand All @@ -59,11 +59,4 @@ namespace stormkit::wsi {

std::unreachable();
}

////////////////////////////////////////
////////////////////////////////////////
STORMKIT_FORCE_INLINE
constexpr auto to_string(WM wm) noexcept -> string {
return string { as_string(wm) };
}
} // namespace stormkit::wsi
16 changes: 6 additions & 10 deletions modules/stormkit/wsi/keyboard.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import std;

import stormkit.core;

using namespace stormkit::literals;

export namespace stormkit::wsi {
inline constexpr auto GLOBAL_KEYBOARD_ID = 0_u8;

Expand Down Expand Up @@ -142,8 +144,9 @@ export namespace stormkit::wsi {

UNKNOWN = std::numeric_limits<u8>::max(),
};
constexpr auto as_string(Key key) noexcept -> string_view;
constexpr auto to_string(Key key) noexcept -> string;

[[nodiscard]]
constexpr auto tag_invoke(as_fn<string_view>, Key key, const std::source_location&) noexcept -> string_view;
} // namespace stormkit::wsi

////////////////////////////////////////////////////////////////////
Expand All @@ -154,7 +157,7 @@ namespace stormkit::wsi {
////////////////////////////////////////
////////////////////////////////////////
STORMKIT_FORCE_INLINE STORMKIT_CONST
constexpr auto as_string(Key key) noexcept -> string_view {
constexpr auto tag_invoke(as_fn<string_view>, Key key, const std::source_location&) noexcept -> string_view {
switch (key) {
case Key::A: return "Key::A";
case Key::B: return "Key::B";
Expand Down Expand Up @@ -284,11 +287,4 @@ namespace stormkit::wsi {
}
std::unreachable();
}

////////////////////////////////////////
////////////////////////////////////////
STORMKIT_FORCE_INLINE
constexpr auto to_string(Key key) noexcept -> string {
return string { as_string(key) };
}
} // namespace stormkit::wsi
35 changes: 12 additions & 23 deletions modules/stormkit/wsi/monitor.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export module stormkit.wsi:monitor;
import std;

import stormkit.core;
import stormkit.math.extent;

export {
namespace stormkit::wsi {
Expand All @@ -37,13 +38,14 @@ export {
void* native_handle = nullptr;
};

constexpr auto as_string(Monitor::Flags flags) noexcept -> string_view;
constexpr auto to_string(Monitor::Flags flags) noexcept -> string;

auto to_string(const Monitor& monitor) noexcept -> string;
[[nodiscard]]
constexpr auto tag_invoke(as_fn<string_view>,
Monitor::Flags value,
source_location_arg = std::source_location::current()) noexcept -> string_view;

template<typename FormatContext>
auto format_as(const Monitor& monitor, FormatContext& ctx) noexcept -> decltype(ctx.out());
template<typename CharT>
constexpr auto tag_invoke(format_as_fn<CharT>, const Monitor& monitor, meta::format_context auto& ctx) noexcept
-> decltype(ctx.out());

[[nodiscard]]
STORMKIT_WSI_API auto get_monitors(bool update = false) noexcept -> array_view<const Monitor>;
Expand Down Expand Up @@ -105,7 +107,7 @@ namespace stormkit::wsi {
////////////////////////////////////////
////////////////////////////////////////
STORMKIT_FORCE_INLINE STORMKIT_CONST
constexpr auto as_string(Monitor::Flags flags) noexcept -> string_view {
constexpr auto tag_invoke(as_fn<string_view>, Monitor::Flags flags, source_location_arg) noexcept -> string_view {
switch (flags) {
case Monitor::Flags::NONE: return "Monitor::Flags::NONE";
case Monitor::Flags::PRIMARY: return "Monitor::Flags::PRIMARY";
Expand All @@ -117,23 +119,10 @@ namespace stormkit::wsi {

////////////////////////////////////////
////////////////////////////////////////
template<typename CharT>
STORMKIT_FORCE_INLINE
constexpr auto to_string(Monitor::Flags flags) noexcept -> string {
return string { as_string(flags) };
}

////////////////////////////////////////
////////////////////////////////////////
STORMKIT_FORCE_INLINE
inline auto to_string(const Monitor& monitor) noexcept -> string {
return std::format("{}", monitor);
}

////////////////////////////////////////
////////////////////////////////////////
template<typename FormatContext>
STORMKIT_FORCE_INLINE
inline auto format_as(const Monitor& monitor, FormatContext& ctx) noexcept -> decltype(ctx.out()) {
constexpr auto tag_invoke(format_as_fn<CharT>, const Monitor& monitor, meta::format_context auto& ctx) noexcept
-> decltype(ctx.out()) {
return std::format_to(ctx.out(),
"[Monitor name: {}, flags: {}, extents: {}, scale_factor: {}]",
monitor.name,
Expand Down
15 changes: 5 additions & 10 deletions modules/stormkit/wsi/mouse.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import std;

import stormkit.core;

using namespace stormkit::literals;

export namespace stormkit::wsi {
inline constexpr auto GLOBAL_MOUSE_ID = 0_u8;

Expand All @@ -33,8 +35,8 @@ export namespace stormkit::wsi {
BUTTON_12,
};

constexpr auto as_string(MouseButton button) noexcept -> string_view;
constexpr auto to_string(MouseButton button) noexcept -> string;
[[nodiscard]]
constexpr auto tag_invoke(as_fn<string_view>, MouseButton button, const std::source_location&) noexcept -> string_view;
} // namespace stormkit::wsi

////////////////////////////////////////////////////////////////////
Expand All @@ -45,7 +47,7 @@ namespace stormkit::wsi {
////////////////////////////////////////
////////////////////////////////////////
STORMKIT_FORCE_INLINE STORMKIT_CONST
constexpr auto as_string(MouseButton button) noexcept -> string_view {
constexpr auto tag_invoke(as_fn<string_view>, MouseButton button, const std::source_location&) noexcept -> string_view {
switch (button) {
case MouseButton::LEFT: return "MouseButton::LEFT";
case MouseButton::RIGHT: return "MouseButton::RIGHT";
Expand All @@ -67,11 +69,4 @@ namespace stormkit::wsi {

std::unreachable();
}

////////////////////////////////////////
////////////////////////////////////////
STORMKIT_FORCE_INLINE
constexpr auto to_string(MouseButton button) noexcept -> string {
return string { as_string(button) };
}
} // namespace stormkit::wsi
Loading
Loading