Skip to content

Commit

Permalink
rewrite inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Jan 30, 2024
1 parent d88b0a4 commit ade89fd
Show file tree
Hide file tree
Showing 24 changed files with 492 additions and 829 deletions.
30 changes: 17 additions & 13 deletions sources/include/cage-core/any.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,51 @@ namespace cage
{
namespace detail
{
template<uint32 MaxSize>
template<class T, uint32 MaxSize>
concept AnyValueConcept = std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T> && std::is_same_v<std::remove_cvref_t<T>, T> && sizeof(T) <= MaxSize && sizeof(T) > 0;

template<uint32 MaxSize_>
struct alignas(16) AnyBase
{
AnyBase() = default;
AnyBase(const AnyBase &) = default;

template<class T>
template<AnyValueConcept<MaxSize_> T>
CAGE_FORCE_INLINE AnyBase(const T &v) noexcept
{
static_assert(std::is_trivially_copyable_v<T>);
static_assert(sizeof(T) <= MaxSize);
static_assert(sizeof(T) > 0);
detail::typeIndex<T>(); // detect hash collisions
detail::memcpy(data_, &v, sizeof(T));
type_ = detail::typeHash<T>();
}

AnyBase &operator=(const AnyBase &) = default;

template<class T>
template<AnyValueConcept<MaxSize_> T>
CAGE_FORCE_INLINE AnyBase &operator=(const T &v) noexcept
{
return *this = AnyBase(v);
}

CAGE_FORCE_INLINE void clear() noexcept { type_ = m; }
CAGE_FORCE_INLINE uint32 typeHash() const noexcept { return type_; }
CAGE_FORCE_INLINE explicit operator bool() const noexcept { return type_ != m; }
template<AnyValueConcept<MaxSize_> T>
CAGE_FORCE_INLINE bool has() const noexcept
{
return detail::typeHash<T>() == type_;
}

template<class T>
template<AnyValueConcept<MaxSize_> T>
T get() const
{
static_assert(std::is_trivially_copyable_v<T>);
static_assert(sizeof(T) <= MaxSize);
static_assert(sizeof(T) > 0);
CAGE_ASSERT(detail::typeHash<T>() == type_);
T tmp;
detail::memcpy(&tmp, data_, sizeof(T));
return tmp;
}

CAGE_FORCE_INLINE void clear() noexcept { type_ = m; }
CAGE_FORCE_INLINE uint32 typeHash() const noexcept { return type_; }
CAGE_FORCE_INLINE explicit operator bool() const noexcept { return type_ != m; }
static constexpr uint32 MaxSize = MaxSize_;

private:
char data_[MaxSize];
uint32 type_ = m;
Expand Down
2 changes: 1 addition & 1 deletion sources/include/cage-core/entities.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace cage
class Entity;

template<class T>
concept ComponentConcept = std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T>;
concept ComponentConcept = std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T> && std::is_same_v<std::remove_cvref_t<T>, T>;

class CAGE_CORE_API EntityManager : private Immovable
{
Expand Down
2 changes: 0 additions & 2 deletions sources/include/cage-core/entitiesVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace cage
template<class R, class T, class... Args>
struct DecomposeLambda<R (T::*)(Args...) const>
{
using Return = R;
using Class = T;
using Params = std::tuple<Args...>;
};

Expand Down
2 changes: 1 addition & 1 deletion sources/include/cage-core/typeIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace cage
constexpr PointerRange<const char> typeName() noexcept
{
static_assert(std::is_same_v<std::decay_t<T>, T>);
static_assert(std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, T>);
static_assert(std::is_same_v<std::remove_cvref_t<T>, T>);
#ifdef _MSC_VER
return __FUNCSIG__;
#else
Expand Down
1 change: 0 additions & 1 deletion sources/include/cage-engine/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace cage
enum class CheckBoxStateEnum : uint32;
enum class InputButtonsPlacementModeEnum : uint32;
enum class GuiElementTypeEnum : uint32;
enum class InputClassEnum : uint32;
enum class LightTypeEnum : uint32;
enum class WindowFlags : uint32;

Expand Down
41 changes: 1 addition & 40 deletions sources/include/cage-engine/guiBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@

namespace cage
{
class EntityManager;
class Entity;

namespace privat
{
template<void (*F)(), bool StopPropagation = true>
CAGE_FORCE_INLINE bool guiActionWrapper(Entity *)
{
(F)();
return StopPropagation;
}
}

namespace guiBuilder
{
class GuiBuilder;
Expand Down Expand Up @@ -50,34 +37,8 @@ namespace cage
BuilderItem skin(uint32 index = m);
BuilderItem disabled(bool disable = true);

BuilderItem event(Delegate<bool(Entity *)> ev);
template<bool (*F)(Entity *)>
BuilderItem event()
{
return event(Delegate<bool(Entity *)>().bind<F>());
}
template<class D, bool (*F)(D, Entity *)>
BuilderItem event(D d)
{
return event(Delegate<bool(Entity *)>().bind<D, F>(d));
}
template<void (*F)(), bool StopPropagation = true>
BuilderItem event()
{
return event(Delegate<bool(Entity *)>().bind<&privat::guiActionWrapper<F, StopPropagation>>());
}

BuilderItem event(Delegate<bool(GenericInput)> ev);
BuilderItem update(Delegate<void(Entity *)> u);
template<void (*F)(Entity *)>
BuilderItem update()
{
return update(Delegate<void(Entity *)>().bind<F>());
}
template<class D, void (*F)(D, Entity *)>
BuilderItem update(D d)
{
return update(Delegate<void(Entity *)>().bind<D, F>(d));
}

BuilderItem tooltip(const GuiTooltipComponent &t);
template<StringLiteral Text, uint32 AssetName = 0, uint32 TextName = 0>
Expand Down
16 changes: 8 additions & 8 deletions sources/include/cage-engine/guiComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define guard_guiComponents_sdf1gh45hk485aws

#include <cage-core/stringLiteral.h>
#include <cage-engine/core.h>
#include <cage-engine/inputs.h>

namespace cage
{
Expand Down Expand Up @@ -74,11 +74,14 @@ namespace cage

struct CAGE_ENGINE_API GuiEventComponent
{
Delegate<bool(Entity *)> event;
Delegate<bool(GenericInput)> event;
};

struct CAGE_ENGINE_API GuiUpdateComponent
{
// called periodically from the gui itself
// useful for updating text, image, format, etc.
// do NOT use for adding/removing entities
Delegate<void(Entity *)> update;
};

Expand Down Expand Up @@ -201,12 +204,9 @@ namespace cage
{
// input box and text area
None = 0,
//ReadOnly = 1 << 0,
//SelectAllOnFocusGain = 1 << 1,
GoToEndOnFocusGain = 1 << 2,
ShowArrowButtons = 1 << 3,
AlwaysRoundValueToStep = 1 << 4,
//AcceptTabs = 1 << 5, // tab key will write tab rather than skip to next widget
ShowArrowButtons = 1 << 1,
AlwaysRoundValueToStep = 1 << 2,
GoToEndOnFocusGain = 1 << 3,
};

struct CAGE_ENGINE_API GuiInputComponent
Expand Down
Loading

0 comments on commit ade89fd

Please sign in to comment.