Skip to content

Commit

Permalink
Merge branch 'wip' into dev/ConstevalHashedString
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack authored Jan 13, 2025
2 parents fdc6ae2 + a6306e1 commit 732f2ae
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
working-directory: build
run: |
sudo apt install lcov
lcov -c -d . -o coverage.info
lcov -c -d . -o coverage.info --ignore-errors gcov,gcov,mismatch,mismatch
lcov -l coverage.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
116 changes: 61 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,76 +222,82 @@ if(ENTT_HAS_LIBCPP)
target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
endif()

# Install pkg-config file
# Install EnTT and all related files

include(JoinPaths)
option(ENTT_INSTALL "Install EnTT and all related files." OFF)

set(EnTT_PKGCONFIG ${CMAKE_CURRENT_BINARY_DIR}/entt.pc)
if(ENTT_INSTALL)
# Install pkg-config file

join_paths(EnTT_PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
include(JoinPaths)

configure_file(
${EnTT_SOURCE_DIR}/cmake/in/entt.pc.in
${EnTT_PKGCONFIG}
@ONLY
)
set(EnTT_PKGCONFIG ${CMAKE_CURRENT_BINARY_DIR}/entt.pc)

install(
FILES ${EnTT_PKGCONFIG}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
join_paths(EnTT_PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")

# Install EnTT
configure_file(
${EnTT_SOURCE_DIR}/cmake/in/entt.pc.in
${EnTT_PKGCONFIG}
@ONLY
)

include(CMakePackageConfigHelpers)
install(
FILES ${EnTT_PKGCONFIG}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

install(
TARGETS EnTT
EXPORT EnTTTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Install EnTT

write_basic_package_version_file(
EnTTConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
include(CMakePackageConfigHelpers)

configure_package_config_file(
${EnTT_SOURCE_DIR}/cmake/in/EnTTConfig.cmake.in
EnTTConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
)
install(
TARGETS EnTT
EXPORT EnTTTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

export(
EXPORT EnTTTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/EnTTTargets.cmake
NAMESPACE EnTT::
)
write_basic_package_version_file(
EnTTConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(
EXPORT EnTTTargets
FILE EnTTTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
NAMESPACE EnTT::
)
configure_package_config_file(
${EnTT_SOURCE_DIR}/cmake/in/EnTTConfig.cmake.in
EnTTConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
)

install(
FILES
${PROJECT_BINARY_DIR}/EnTTConfig.cmake
${PROJECT_BINARY_DIR}/EnTTConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
)
export(
EXPORT EnTTTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/EnTTTargets.cmake
NAMESPACE EnTT::
)

install(
DIRECTORY src/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)
install(
EXPORT EnTTTargets
FILE EnTTTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
NAMESPACE EnTT::
)

export(PACKAGE EnTT)
install(
FILES
${PROJECT_BINARY_DIR}/EnTTConfig.cmake
${PROJECT_BINARY_DIR}/EnTTConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
)

install(
DIRECTORY src/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)

export(PACKAGE EnTT)
endif()

# Tests

Expand Down
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ TODO:
* sparse_set shrink_to_fit argument for sparse array shrink policy (none, empty, deep, whatever)
* any cdynamic to support const ownership construction
* track meta context on meta elements
* safer meta_data/meta_func (no blind indirections)
19 changes: 11 additions & 8 deletions docs/md/entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -1833,23 +1833,26 @@ the `my_type` component, regardless of what other components they have.

### View pack

Views are combined with each other to create new and more specific queries.<br/>
The type returned when combining multiple views together is itself a view, more
in general a multi component one.
Views are combined with storage objects and with each other to create new, more
specific _queries_.<br/>
The type returned when combining multiple elements together is itself a view,
more in general a multi component one.

Combining different views tries to mimic C++20 ranges:
Combining different elements tries to mimic C++20 ranges:

```cpp
auto view = registry.view<position>();
auto other = registry.view<velocity>();
const auto &storage = registry.storage<renderable>();

auto pack = view | other;
auto pack = view | other | renderable;
```

The constness of the types is preserved and their order depends on the order in
which the views are combined. For example, the pack above returns an instance of
`position` first and then one of `velocity`.<br/>
Since combining views generates views, a chain can be of arbitrary length and
which the views are combined. For example, the above _pack_ first returns an
instance of `position`, then one of `velocity`, and finally one of
`renderable`.<br/>
Since combining elements generates views, a chain can be of arbitrary length and
the above type order rules apply sequentially.

### Iteration order
Expand Down
6 changes: 4 additions & 2 deletions src/entt/core/any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ class basic_any {

/**
* @brief Move assignment operator.
*
* @warning
* Self-moving puts objects in a safe but unspecified state.
*
* @param other The instance to move from.
* @return This any object.
*/
basic_any &operator=(basic_any &&other) noexcept {
ENTT_ASSERT(this != &other, "Self move assignment");

reset();

if(other.mode == any_policy::embedded) {
Expand Down
21 changes: 8 additions & 13 deletions src/entt/core/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@

namespace entt {

/*! @cond TURN_OFF_DOXYGEN */
namespace internal {

template<typename>
struct is_tuple_impl: std::false_type {};

template<typename... Args>
struct is_tuple_impl<std::tuple<Args...>>: std::true_type {};

} // namespace internal
/*! @endcond */

/**
* @brief Provides the member constant `value` to true if a given type is a
* tuple, false otherwise.
* @tparam Type The type to test.
*/
template<typename Type>
struct is_tuple: internal::is_tuple_impl<std::remove_cv_t<Type>> {};
struct is_tuple: std::false_type {};

/**
* @copybrief is_tuple
* @tparam Args Tuple template arguments.
*/
template<typename... Args>
struct is_tuple<std::tuple<Args...>>: std::true_type {};

/**
* @brief Helper variable template.
Expand Down
12 changes: 6 additions & 6 deletions src/entt/core/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,18 +772,18 @@ template<typename Type>
// NOLINTBEGIN(modernize-use-transparent-functors)
if constexpr(std::is_array_v<Type>) {
return false;
} else if constexpr(!is_iterator_v<Type> && has_value_type<Type>::value) {
if constexpr(std::is_same_v<typename Type::value_type, Type> || dispatch_is_equality_comparable<typename Type::value_type>()) {
return maybe_equality_comparable<Type>(0);
} else {
return false;
}
} else if constexpr(is_complete_v<std::tuple_size<std::remove_cv_t<Type>>>) {
if constexpr(has_tuple_size_value<Type>::value) {
return maybe_equality_comparable<Type>(0) && unpack_maybe_equality_comparable<Type>(std::make_index_sequence<std::tuple_size<Type>::value>{});
} else {
return maybe_equality_comparable<Type>(0);
}
} else if constexpr(has_value_type<Type>::value) {
if constexpr(is_iterator_v<Type> || std::is_same_v<typename Type::value_type, Type> || dispatch_is_equality_comparable<typename Type::value_type>()) {
return maybe_equality_comparable<Type>(0);
} else {
return false;
}
} else {
return maybe_equality_comparable<Type>(0);
}
Expand Down
26 changes: 15 additions & 11 deletions src/entt/entity/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
payload.resize(from);
}

void swap_at(const std::size_t from, const std::size_t to) {
using std::swap;
swap(element_at(from), element_at(to));
}

void move_to(const std::size_t from, const std::size_t to) {
auto &elem = element_at(from);
allocator_type allocator{get_allocator()};
entt::uninitialized_construct_using_allocator(to_address(assure_at_least(to)), allocator, std::move(elem));
alloc_traits::destroy(allocator, std::addressof(elem));
}

private:
[[nodiscard]] const void *get_at(const std::size_t pos) const final {
return std::addressof(element_at(pos));
Expand All @@ -309,19 +321,11 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
ENTT_ASSERT((from + 1u) && !is_pinned_type, "Pinned type");

if constexpr(!is_pinned_type) {
auto &elem = element_at(from);

if constexpr(traits_type::in_place_delete) {
if(base_type::operator[](to) == tombstone) {
allocator_type allocator{get_allocator()};
entt::uninitialized_construct_using_allocator(to_address(assure_at_least(to)), allocator, std::move(elem));
alloc_traits::destroy(allocator, std::addressof(elem));
return;
}
(base_type::operator[](to) == tombstone) ? move_to(from, to) : swap_at(from, to);
} else {
swap_at(from, to);
}

using std::swap;
swap(elem, element_at(to));
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/entt/entity/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,17 @@ class basic_view<get_t<Get...>, exclude_t<Exclude...>, std::enable_if_t<(sizeof.
return iterable{base_type::begin(), base_type::end()};
}

/**
* @brief Combines a view and a storage in _more specific_ view.
* @tparam OGet Type of storage to combine the view with.
* @param other The storage for the type to combine the view with.
* @return A more specific view.
*/
template<typename OGet>
[[nodiscard]] std::enable_if_t<std::is_base_of_v<common_type, OGet>, basic_view<get_t<Get..., OGet>, exclude_t<Exclude...>>> operator|(OGet &other) const noexcept {
return *this | basic_view<get_t<OGet>, exclude_t<>>{other};
}

/**
* @brief Combines two views in a _more specific_ one.
* @tparam OGet Element list of the view to combine with.
Expand Down Expand Up @@ -1072,6 +1083,17 @@ class basic_view<get_t<Get>, exclude_t<>>
}
}

/**
* @brief Combines a view and a storage in _more specific_ view.
* @tparam OGet Type of storage to combine the view with.
* @param other The storage for the type to combine the view with.
* @return A more specific view.
*/
template<typename OGet>
[[nodiscard]] std::enable_if_t<std::is_base_of_v<common_type, OGet>, basic_view<get_t<Get, OGet>, exclude_t<>>> operator|(OGet &other) const noexcept {
return *this | basic_view<get_t<OGet>, exclude_t<>>{other};
}

/**
* @brief Combines two views in a _more specific_ one.
* @tparam OGet Element list of the view to combine with.
Expand Down
Loading

0 comments on commit 732f2ae

Please sign in to comment.