Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a3a2c2702 | ||
|
|
be38919758 | ||
|
|
a816ccf6ee | ||
|
|
5e85068e35 | ||
|
|
77865ab4a1 | ||
|
|
5fc6ee27f6 | ||
|
|
5995adf8b6 | ||
|
|
c9f47ed89a | ||
|
|
d6325ffcfa | ||
|
|
9d72472114 | ||
|
|
102350a125 | ||
|
|
1c650cb136 | ||
|
|
625e74653d | ||
|
|
5bad762293 |
@@ -1281,7 +1281,7 @@ thrown away. The reasons for this go far beyond the scope of this document.<br/>
|
||||
To iterate a runtime view, either use it in a range-for loop:
|
||||
|
||||
```cpp
|
||||
entt::component types[] = { entt::type_info<position>::id(), entt::type_info<velocity>::id() };
|
||||
entt::id_type types[] = { entt::type_info<position>::id(), entt::type_info<velocity>::id() };
|
||||
auto view = registry.runtime_view(std::cbegin(types), std::cend(types));
|
||||
|
||||
for(auto entity: view) {
|
||||
@@ -1299,7 +1299,7 @@ for(auto entity: view) {
|
||||
Or rely on the `each` member function to iterate entities:
|
||||
|
||||
```cpp
|
||||
entt::component types[] = { entt::type_info<position>::id(), entt::type_info<velocity>::id() };
|
||||
entt::id_type types[] = { entt::type_info<position>::id(), entt::type_info<velocity>::id() };
|
||||
|
||||
registry.runtime_view(std::cbegin(types), std::cend(types)).each([](auto entity) {
|
||||
// ...
|
||||
@@ -1310,8 +1310,8 @@ Performance are exactly the same in both cases.<br/>
|
||||
Filtering entities by components is also supported for this kind of views:
|
||||
|
||||
```cpp
|
||||
entt::component components[] = { entt::type_info<position>::id() };
|
||||
entt::component filter[] = { entt::type_info<velocity>::id() };
|
||||
entt::id_type components[] = { entt::type_info<position>::id() };
|
||||
entt::id_type filter[] = { entt::type_info<velocity>::id() };
|
||||
auto view = registry.runtime_view(std::cbegin(components), std::cend(components), std::cbegin(filter), std::cend(filter));
|
||||
```
|
||||
|
||||
|
||||
@@ -117,6 +117,7 @@ I hope this list can grow much more in the future:
|
||||
- [Native Scripting](https://www.youtube.com/watch?v=iIUhg88MK5M).
|
||||
- [Native Scripting (now with virtual functions!)](https://www.youtube.com/watch?v=1cHEcrIn8IQ).
|
||||
- [Scene Hierarchy Panel](https://www.youtube.com/watch?v=wziDnE8guvI).
|
||||
- [Properties Panel](https://www.youtube.com/watch?v=NBpB0qscF3E).
|
||||
* [Ability Creator](https://www.erichildebrand.net/blog/ability-creator-project-retrospect):
|
||||
project retrospect by [Eric Hildebrand](https://www.erichildebrand.net/).
|
||||
|
||||
|
||||
@@ -42,5 +42,8 @@ I hope this list can grow much more in the future:
|
||||
* [Specs](https://github.com/amethyst/specs): a parallel ECS based mainly on
|
||||
hierarchical bitsets that allows different types of storage as needed.
|
||||
|
||||
* Zig
|
||||
* [zig-ecs](https://github.com/prime31/zig-ecs): a _zig-ification_ of `EnTT`.
|
||||
|
||||
If you know of other resources out there that can be of interest for the reader,
|
||||
feel free to open an issue or a PR and I'll be glad to add them to this page.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define ENTT_VERSION_MAJOR 3
|
||||
#define ENTT_VERSION_MINOR 5
|
||||
#define ENTT_VERSION_PATCH 0
|
||||
#define ENTT_VERSION_PATCH 2
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,32 +31,6 @@ struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
|
||||
{};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Entity traits for a 16 bits entity identifier.
|
||||
*
|
||||
* A 16 bits entity identifier guarantees:
|
||||
*
|
||||
* * 12 bits for the entity number (up to 4k entities).
|
||||
* * 4 bit for the version (resets in [0-15]).
|
||||
*/
|
||||
template<>
|
||||
struct entt_traits<std::uint16_t> {
|
||||
/*! @brief Underlying entity type. */
|
||||
using entity_type = std::uint16_t;
|
||||
/*! @brief Underlying version type. */
|
||||
using version_type = std::uint8_t;
|
||||
/*! @brief Difference type. */
|
||||
using difference_type = std::int16_t;
|
||||
|
||||
/*! @brief Mask to use to get the entity number out of an identifier. */
|
||||
static constexpr entity_type entity_mask = 0xFFF;
|
||||
/*! @brief Mask to use to get the version out of an identifier. */
|
||||
static constexpr entity_type version_mask = 0xF;
|
||||
/*! @brief Extent of the entity number within an identifier. */
|
||||
static constexpr std::size_t entity_shift = 12u;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Entity traits for a 32 bits entity identifier.
|
||||
*
|
||||
@@ -72,7 +46,7 @@ struct entt_traits<std::uint32_t> {
|
||||
/*! @brief Underlying version type. */
|
||||
using version_type = std::uint16_t;
|
||||
/*! @brief Difference type. */
|
||||
using difference_type = std::int32_t;
|
||||
using difference_type = std::int64_t;
|
||||
|
||||
/*! @brief Mask to use to get the entity number out of an identifier. */
|
||||
static constexpr entity_type entity_mask = 0xFFFFF;
|
||||
|
||||
@@ -212,9 +212,16 @@ class basic_observer {
|
||||
|
||||
template<typename... Reject, typename... Require, typename... NoneOf, typename... AllOf>
|
||||
struct matcher_handler<matcher<type_list<Reject...>, type_list<Require...>, type_list<NoneOf...>, AllOf...>> {
|
||||
template<std::size_t Index>
|
||||
template<std::size_t Index, typename... Ignore>
|
||||
static void maybe_valid_if(basic_observer &obs, const basic_registry<Entity> ®, const Entity entt) {
|
||||
if(reg.template has<AllOf..., Require...>(entt) && !reg.template any<NoneOf..., Reject...>(entt)) {
|
||||
if([®, entt]() {
|
||||
if constexpr(sizeof...(Ignore) == 0) {
|
||||
return reg.template has<AllOf..., Require...>(entt) && !reg.template any<NoneOf..., Reject...>(entt);
|
||||
} else {
|
||||
return reg.template has<AllOf..., Require...>(entt) && ((std::is_same_v<Ignore..., NoneOf> || !reg.template any<NoneOf>(entt)) && ...) && !reg.template any<Reject...>(entt);
|
||||
}
|
||||
}())
|
||||
{
|
||||
if(auto *comp = obs.view.try_get(entt); !comp) {
|
||||
obs.view.emplace(entt);
|
||||
}
|
||||
@@ -235,7 +242,7 @@ class basic_observer {
|
||||
(reg.template on_destroy<Require>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<Reject>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<AllOf>().template connect<&maybe_valid_if<Index>>(obs), ...);
|
||||
(reg.template on_destroy<NoneOf>().template connect<&maybe_valid_if<Index>>(obs), ...);
|
||||
(reg.template on_destroy<NoneOf>().template connect<&maybe_valid_if<Index, NoneOf>>(obs), ...);
|
||||
(reg.template on_destroy<AllOf>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<NoneOf>().template connect<&discard_if<Index>>(obs), ...);
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ public:
|
||||
*/
|
||||
void emplace(const entity_type entt) {
|
||||
ENTT_ASSERT(!contains(entt));
|
||||
assure(page(entt))[offset(entt)] = entity_type(static_cast<typename traits_type::entity_type>(packed.size()));
|
||||
assure(page(entt))[offset(entt)] = entity_type{static_cast<typename traits_type::entity_type>(packed.size())};
|
||||
packed.push_back(entt);
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ public:
|
||||
while(first != last) {
|
||||
const auto entt = *(first++);
|
||||
ENTT_ASSERT(!contains(entt));
|
||||
assure(page(entt))[offset(entt)] = entity_type(next++);
|
||||
assure(page(entt))[offset(entt)] = entity_type{next++};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@ public:
|
||||
algo(from, to, std::move(compare), std::forward<Args>(args)...);
|
||||
|
||||
for(size_type pos = skip, end = skip+length; pos < end; ++pos) {
|
||||
sparse[page(packed[pos])][offset(packed[pos])] = entity_type(static_cast<typename traits_type::entity_type>(pos));
|
||||
sparse[page(packed[pos])][offset(packed[pos])] = entity_type{static_cast<typename traits_type::entity_type>(pos)};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ public:
|
||||
|
||||
while(curr != next) {
|
||||
apply(packed[curr], packed[next]);
|
||||
sparse[page(packed[curr])][offset(packed[curr])] = entity_type(static_cast<typename traits_type::entity_type>(curr));
|
||||
sparse[page(packed[curr])][offset(packed[curr])] = entity_type{static_cast<typename traits_type::entity_type>(curr)};
|
||||
|
||||
curr = next;
|
||||
next = index(packed[curr]);
|
||||
|
||||
@@ -167,10 +167,14 @@ class meta_any {
|
||||
template<typename Type>
|
||||
[[nodiscard]] static meta_any dereference_operator(meta_any &any) {
|
||||
if constexpr(is_meta_pointer_like_v<Type>) {
|
||||
if constexpr(std::is_const_v<std::remove_reference_t<decltype(*std::declval<Type>())>>) {
|
||||
return *any.cast<Type>();
|
||||
} else {
|
||||
using pointed_type = std::remove_reference_t<decltype(*std::declval<Type>())>;
|
||||
|
||||
if constexpr(std::is_const_v<pointed_type> && std::is_copy_constructible_v<pointed_type>) {
|
||||
return std::as_const(*any.cast<Type>());
|
||||
} else if constexpr(!std::is_const_v<pointed_type>) {
|
||||
return std::ref(*any.cast<Type>());
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
return {};
|
||||
@@ -296,6 +300,40 @@ public:
|
||||
return storage.data();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Invokes the underlying function, if possible.
|
||||
*
|
||||
* @sa invoke
|
||||
*
|
||||
* @tparam Args Types of arguments to use to invoke the function.
|
||||
* @param id Unique identifier.
|
||||
* @param args Parameters to use to invoke the function.
|
||||
* @return A meta any containing the returned value, if any.
|
||||
*/
|
||||
template<typename... Args>
|
||||
meta_any invoke(const id_type id, Args &&... args) const;
|
||||
|
||||
/**
|
||||
* @brief Sets the value of a given variable.
|
||||
*
|
||||
* The type of the value must be such that a cast or conversion to the type
|
||||
* of the variable is possible. Otherwise, invoking the setter does nothing.
|
||||
*
|
||||
* @tparam Type Type of value to assign.
|
||||
* @param id Unique identifier.
|
||||
* @param value Parameter to use to set the underlying variable.
|
||||
* @return True in case of success, false otherwise.
|
||||
*/
|
||||
template<typename Type>
|
||||
bool set(const id_type id, Type &&value) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the value of a given variable.
|
||||
* @param id Unique identifier.
|
||||
* @return A meta any containing the value of the underlying variable.
|
||||
*/
|
||||
[[nodiscard]] meta_any get(const id_type id) const;
|
||||
|
||||
/**
|
||||
* @brief Tries to cast an instance to a given type.
|
||||
* @tparam Type Type to which to cast the instance.
|
||||
@@ -916,7 +954,7 @@ struct meta_func {
|
||||
* @param sz Number of parameters to use to invoke the function.
|
||||
* @return A meta any containing the returned value, if any.
|
||||
*/
|
||||
[[nodiscard]] meta_any invoke(meta_handle instance, meta_any * const args, const std::size_t sz) const {
|
||||
meta_any invoke(meta_handle instance, meta_any * const args, const std::size_t sz) const {
|
||||
return sz == size() ? node->invoke(instance, args) : meta_any{};
|
||||
}
|
||||
|
||||
@@ -1305,6 +1343,80 @@ public:
|
||||
return construct(arguments.data(), sizeof...(Args));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Invokes the function with the given identifier, if possible.
|
||||
*
|
||||
* To invoke a meta function, the parameters must be such that a cast or
|
||||
* conversion to the required types is possible. Otherwise, an empty and
|
||||
* thus invalid wrapper is returned.<br/>
|
||||
* It must be possible to cast the instance to the parent type of the meta
|
||||
* function. Otherwise, invoking the underlying function results in an
|
||||
* undefined behavior.
|
||||
*
|
||||
* @param id Unique identifier.
|
||||
* @param instance An opaque instance of the underlying type.
|
||||
* @param args Parameters to use to invoke the function.
|
||||
* @param sz Number of parameters to use to invoke the function.
|
||||
* @return A meta any containing the returned value, if any.
|
||||
*/
|
||||
meta_any invoke(const id_type id, meta_handle instance, meta_any * const args, const std::size_t sz) const {
|
||||
auto const candidate = func(id);
|
||||
return candidate ? candidate.invoke(std::move(instance), args, sz) : meta_any{};
|
||||
}
|
||||
|
||||
/**
|
||||
* @copybrief invoke
|
||||
*
|
||||
* @sa invoke
|
||||
*
|
||||
* @param id Unique identifier.
|
||||
* @tparam Args Types of arguments to use to invoke the function.
|
||||
* @param instance An opaque instance of the underlying type.
|
||||
* @param args Parameters to use to invoke the function.
|
||||
* @return A meta any containing the new instance, if any.
|
||||
*/
|
||||
template<typename... Args>
|
||||
meta_any invoke(const id_type id, meta_handle instance, Args &&... args) const {
|
||||
std::array<meta_any, sizeof...(Args)> arguments{std::forward<Args>(args)...};
|
||||
return invoke(id, std::move(instance), arguments.data(), sizeof...(Args));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the value of a given variable.
|
||||
*
|
||||
* It must be possible to cast the instance to the parent type of the meta
|
||||
* data. Otherwise, invoking the setter results in an undefined
|
||||
* behavior.<br/>
|
||||
* The type of the value must be such that a cast or conversion to the type
|
||||
* of the variable is possible. Otherwise, invoking the setter does nothing.
|
||||
*
|
||||
* @tparam Type Type of value to assign.
|
||||
* @param id Unique identifier.
|
||||
* @param instance An opaque instance of the underlying type.
|
||||
* @param value Parameter to use to set the underlying variable.
|
||||
* @return True in case of success, false otherwise.
|
||||
*/
|
||||
template<typename Type>
|
||||
bool set(const id_type id, meta_handle instance, Type &&value) const {
|
||||
auto const candidate = data(id);
|
||||
return candidate ? candidate.set(std::move(instance), std::forward<Type>(value)) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the value of a given variable.
|
||||
*
|
||||
* It must be possible to cast the instance to the parent type of the meta
|
||||
* data. Otherwise, invoking the getter results in an undefined behavior.
|
||||
*
|
||||
* @param id Unique identifier.
|
||||
* @param instance An opaque instance of the underlying type.
|
||||
* @return A meta any containing the value of the underlying variable.
|
||||
*/
|
||||
[[nodiscard]] meta_any get(const id_type id, meta_handle instance) const {
|
||||
auto const candidate = data(id);
|
||||
return candidate ? candidate.get(std::move(instance)) : meta_any{};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a range to use to visit top-level meta properties.
|
||||
* @return An iterable range to use to visit top-level meta properties.
|
||||
@@ -1352,7 +1464,7 @@ public:
|
||||
* functions and properties, as well as its constructors, destructors and
|
||||
* conversion functions if any.<br/>
|
||||
* Base classes aren't reset but the link between the two types is removed.
|
||||
*
|
||||
*
|
||||
* The meta type is also removed from the list of searchable types.
|
||||
*/
|
||||
void reset() ENTT_NOEXCEPT {
|
||||
@@ -1376,14 +1488,14 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
unregister_all(&node->prop);
|
||||
unregister_all(&node->base);
|
||||
unregister_all(&node->conv);
|
||||
unregister_all(&node->ctor, &internal::meta_ctor_node::prop);
|
||||
unregister_all(&node->data, &internal::meta_data_node::prop);
|
||||
unregister_all(&node->func, &internal::meta_func_node::prop);
|
||||
|
||||
|
||||
node->id = {};
|
||||
node->dtor = nullptr;
|
||||
}
|
||||
@@ -1409,6 +1521,23 @@ private:
|
||||
}
|
||||
|
||||
|
||||
template<typename... Args>
|
||||
meta_any meta_any::invoke(const id_type id, Args &&... args) const {
|
||||
return type().invoke(id, *this, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
template<typename Type>
|
||||
bool meta_any::set(const id_type id, Type &&value) const {
|
||||
return type().set(id, *this, std::forward<Type>(value));
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]] inline meta_any meta_any::get(const id_type id) const {
|
||||
return type().get(id, *this);
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]] inline meta_type meta_base::parent() const ENTT_NOEXCEPT {
|
||||
return node->parent;
|
||||
}
|
||||
|
||||
@@ -340,3 +340,30 @@ TEST(Observer, MultipleFilters) {
|
||||
|
||||
ASSERT_TRUE(observer.empty());
|
||||
}
|
||||
|
||||
TEST(Observer, GroupCornerCase) {
|
||||
constexpr auto add_collector = entt::collector.group<int>(entt::exclude<char>);
|
||||
constexpr auto remove_collector = entt::collector.group<int, char>();
|
||||
|
||||
entt::registry registry;
|
||||
entt::observer add_observer{registry, add_collector};
|
||||
entt::observer remove_observer{registry, remove_collector};
|
||||
|
||||
const auto entity = registry.create();
|
||||
registry.emplace<int>(entity);
|
||||
|
||||
ASSERT_FALSE(add_observer.empty());
|
||||
ASSERT_TRUE(remove_observer.empty());
|
||||
|
||||
add_observer.clear();
|
||||
registry.emplace<char>(entity);
|
||||
|
||||
ASSERT_TRUE(add_observer.empty());
|
||||
ASSERT_FALSE(remove_observer.empty());
|
||||
|
||||
remove_observer.clear();
|
||||
registry.remove<char>(entity);
|
||||
|
||||
ASSERT_FALSE(add_observer.empty());
|
||||
ASSERT_TRUE(remove_observer.empty());
|
||||
}
|
||||
@@ -5,6 +5,14 @@
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include <entt/meta/resolve.hpp>
|
||||
|
||||
struct clazz_t {
|
||||
void member(int i) { value = i; }
|
||||
static void func() { c = 'd'; }
|
||||
|
||||
static inline char c = 'c';
|
||||
int value = 0;
|
||||
};
|
||||
|
||||
struct empty_t {
|
||||
virtual ~empty_t() = default;
|
||||
static void destroy(empty_t &) {
|
||||
@@ -46,6 +54,12 @@ struct MetaAny: ::testing::Test {
|
||||
entt::meta<double>().conv<int>();
|
||||
entt::meta<empty_t>().dtor<&empty_t::destroy>();
|
||||
entt::meta<fat_t>().base<empty_t>().dtor<&fat_t::destroy>();
|
||||
|
||||
entt::meta<clazz_t>()
|
||||
.type("clazz"_hs)
|
||||
.data<&clazz_t::value>("value"_hs)
|
||||
.func<&clazz_t::member>("member"_hs)
|
||||
.func<&clazz_t::func>("func"_hs);
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
@@ -622,3 +636,32 @@ TEST_F(MetaAny, UnmanageableType) {
|
||||
ASSERT_TRUE(std::as_const(any).convert<unmanageable_t>());
|
||||
ASSERT_FALSE(std::as_const(any).convert<int>());
|
||||
}
|
||||
|
||||
TEST_F(MetaAny, Invoke) {
|
||||
clazz_t instance;
|
||||
entt::meta_any any{std::ref(instance)};
|
||||
|
||||
ASSERT_TRUE(any.invoke("func"_hs));
|
||||
ASSERT_TRUE(any.invoke("member"_hs, 42));
|
||||
ASSERT_FALSE(any.invoke("non_existent"_hs, 42));
|
||||
|
||||
ASSERT_EQ(clazz_t::c, 'd');
|
||||
ASSERT_EQ(instance.value, 42);
|
||||
}
|
||||
|
||||
TEST_F(MetaAny, SetGet) {
|
||||
clazz_t instance;
|
||||
entt::meta_any any{std::ref(instance)};
|
||||
|
||||
ASSERT_TRUE(any.set("value"_hs, 42));
|
||||
|
||||
const auto value = any.get("value"_hs);
|
||||
|
||||
ASSERT_TRUE(value);
|
||||
ASSERT_TRUE(value.try_cast<int>());
|
||||
ASSERT_EQ(value.cast<int>(), 42);
|
||||
ASSERT_EQ(instance.value, 42);
|
||||
|
||||
ASSERT_FALSE(any.set("non_existent"_hs, 42));
|
||||
ASSERT_FALSE(any.get("non_existent"_hs));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,14 @@
|
||||
#include <entt/meta/pointer.hpp>
|
||||
#include <entt/meta/resolve.hpp>
|
||||
|
||||
struct not_copyable_t {
|
||||
not_copyable_t() = default;
|
||||
not_copyable_t(const not_copyable_t &) = delete;
|
||||
not_copyable_t(not_copyable_t &&) = default;
|
||||
not_copyable_t & operator=(const not_copyable_t &) = delete;
|
||||
not_copyable_t & operator=(not_copyable_t &&) = default;
|
||||
};
|
||||
|
||||
TEST(MetaPointerLike, DereferenceOperatorInvalidType) {
|
||||
int value = 0;
|
||||
entt::meta_any any{value};
|
||||
@@ -79,3 +87,11 @@ TEST(MetaPointerLike, DereferenceOperatorSmartPointer) {
|
||||
ASSERT_EQ(*any.cast<std::shared_ptr<int>>(), 42);
|
||||
ASSERT_EQ(*value, 42);
|
||||
}
|
||||
|
||||
TEST(MetaPointerLike, PointerToMoveOnlyType) {
|
||||
const not_copyable_t instance;
|
||||
entt::meta_any any{&instance};
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_FALSE(*any);
|
||||
}
|
||||
@@ -272,6 +272,27 @@ TEST_F(MetaType, Func) {
|
||||
ASSERT_TRUE(type.func("func"_hs).invoke({}));
|
||||
}
|
||||
|
||||
TEST_F(MetaType, Invoke) {
|
||||
auto type = entt::resolve<clazz_t>();
|
||||
clazz_t instance{};
|
||||
|
||||
ASSERT_TRUE(type.invoke("member"_hs, instance));
|
||||
ASSERT_FALSE(type.invoke("rebmem"_hs, {}));
|
||||
}
|
||||
|
||||
TEST_F(MetaType, SetGet) {
|
||||
auto type = entt::resolve<clazz_t>();
|
||||
clazz_t instance{};
|
||||
|
||||
ASSERT_TRUE(type.set("value"_hs, instance, 42));
|
||||
ASSERT_FALSE(type.set("eulav"_hs, instance, 3));
|
||||
ASSERT_EQ(instance.value, 42);
|
||||
|
||||
ASSERT_FALSE(type.get("eulav"_hs, instance));
|
||||
ASSERT_TRUE(type.get("value"_hs, instance));
|
||||
ASSERT_EQ(type.get("value"_hs, instance).cast<int>(), 42);
|
||||
}
|
||||
|
||||
TEST_F(MetaType, Construct) {
|
||||
auto any = entt::resolve<clazz_t>().construct(base_t{}, 42);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ int curried_by_ref(const int &i, int j) {
|
||||
}
|
||||
|
||||
int curried_by_ptr(const int *i, int j) {
|
||||
return (*i)+j;
|
||||
return (*i)*j;
|
||||
}
|
||||
|
||||
int non_const_reference(int &i) {
|
||||
@@ -181,16 +181,16 @@ TEST(Delegate, Comparison) {
|
||||
ASSERT_FALSE(lhs == rhs);
|
||||
ASSERT_NE(lhs, rhs);
|
||||
|
||||
lhs.connect([](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val); }, &functor);
|
||||
lhs.connect([](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val) * val; }, &functor);
|
||||
|
||||
ASSERT_NE(lhs, (entt::delegate<int(int)>{[](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val); }, &functor}));
|
||||
ASSERT_NE(lhs, (entt::delegate<int(int)>{[](const void *, int val) { return val + val; }, &functor}));
|
||||
ASSERT_TRUE(lhs != rhs);
|
||||
ASSERT_FALSE(lhs == rhs);
|
||||
ASSERT_NE(lhs, rhs);
|
||||
|
||||
rhs.connect([](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val); }, &functor);
|
||||
rhs.connect([](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val) + val; }, &functor);
|
||||
|
||||
ASSERT_NE(rhs, (entt::delegate<int(int)>{[](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val); }, &functor}));
|
||||
ASSERT_NE(rhs, (entt::delegate<int(int)>{[](const void *, int val) { return val * val; }, &functor}));
|
||||
ASSERT_TRUE(lhs != rhs);
|
||||
ASSERT_FALSE(lhs == rhs);
|
||||
ASSERT_NE(lhs, rhs);
|
||||
@@ -329,7 +329,7 @@ TEST(Delegate, CurriedFunction) {
|
||||
delegate.connect<&curried_by_ptr>(&value);
|
||||
|
||||
ASSERT_TRUE(delegate);
|
||||
ASSERT_EQ(delegate(2), 5);
|
||||
ASSERT_EQ(delegate(2), 6);
|
||||
}
|
||||
|
||||
TEST(Delegate, Constructors) {
|
||||
@@ -351,7 +351,7 @@ TEST(Delegate, Constructors) {
|
||||
ASSERT_EQ(5, ref(3));
|
||||
|
||||
ASSERT_TRUE(ptr);
|
||||
ASSERT_EQ(5, ref(3));
|
||||
ASSERT_EQ(6, ptr(3));
|
||||
|
||||
ASSERT_TRUE(member);
|
||||
ASSERT_EQ(6, member(3));
|
||||
|
||||
Reference in New Issue
Block a user