Compare commits

...

2858 Commits

Author SHA1 Message Date
Michele Caini
8e0747fd50 updated single include file 2021-12-21 08:32:48 +01:00
Michele Caini
1bcc87c916 runtime_view: removed an useless check, slightly improved performance 2021-12-19 10:25:55 +01:00
Michele Caini
45797907d3 doc: updated toc in the README file 2021-12-18 17:51:02 +01:00
Michele Caini
3498dea486 registry (close #521):
* remove visit
* added storage_proxy_iterator (input iterator category, modeled as a random access iterator)
* added ::storage() (const and non-const) to return an iterable object over all pools
2021-12-17 17:05:14 +01:00
Michele Caini
a4aab8458b group/storage/view: minor changes 2021-12-17 16:57:29 +01:00
Michele Caini
534744d615 iterator: minor changes 2021-12-17 16:57:26 +01:00
Michele Caini
dc5450b95e view: natvis friendly representation 2021-12-17 16:57:24 +01:00
Michele Caini
9e0e276740 dense_hash_set/map: removed unnecessary type members 2021-12-17 16:57:22 +01:00
Michele Caini
1c9c02f3ce view: avoid exposing internal details from iterators 2021-12-17 16:57:20 +01:00
Michele Caini
7774f9f402 storage: review + avoid exposing internal details from iterators 2021-12-17 16:57:18 +01:00
Michele Caini
5607219945 sparse_set: minor changes 2021-12-17 16:57:14 +01:00
Michele Caini
69ef3efd2d dense_hash_map/set: avoid exposing internal details from iterators 2021-12-17 16:57:10 +01:00
Michele Caini
36c118922b group/view:
* added default constructors to input iterators
* make sure that a default constructed iterator compares equal to end()
2021-12-17 08:39:54 +01:00
Michele Caini
1d014953e3 storage: try to also please gcc-9 2021-12-16 14:33:24 +01:00
Michele Caini
c5cb1d9bcc storage/view/group:
* added extended_storage_iterator and storage<T...>::each function to return an extended iterable object
* use extended_storage_iterator and iterable_adaptor everywhere to avoid code duplication
2021-12-16 12:31:44 +01:00
Michele Caini
86d12cf317 doc: brief -> copydoc 2021-12-16 12:30:29 +01:00
Michele Caini
db9e59ede1 core: added iterable_adaptor 2021-12-16 12:29:20 +01:00
Michele Caini
cc9b1b0a05 sparse_set: added const_iterator/const_reverse_iterator and cbegin/cend/crbegin/crend 2021-12-16 08:52:13 +01:00
Michele Caini
5c29de2013 updated TODO 2021-12-15 13:13:16 +01:00
Michele Caini
559db104f8 view: suppress some warnings due to initialization order 2021-12-15 10:24:08 +01:00
Michele Caini
365c57be4c build system: allow compiling the tests with clang-cl (thanks gtest for failing otherwise) 2021-12-15 10:23:34 +01:00
Michele Caini
6f0c84fc68 dense_hash_map/dense_hash_set: remove [[nodiscard]] from friend function declaration 2021-12-15 09:33:23 +01:00
Michele Caini
75782d9e99 registry: review/cleanup 2021-12-14 23:15:57 +01:00
Michele Caini
69ddf4936e registry: remove the visit overload that also takes an entity 2021-12-14 22:57:10 +01:00
Michele Caini
4b3108283f dense_hash_map/dense_hash_set: avoid pointer overflow for end iterators (close #804) 2021-12-14 16:44:34 +01:00
Michele Caini
12d177a6c8 registry: removed ::orphans, use ::each/::orphan instead (no way to further optimize it) 2021-12-13 10:00:32 +01:00
Michele Caini
54717dc7e2 test: minor changes 2021-12-12 17:45:13 +01:00
Michele Caini
631c909abd group: drop conceptually broken reverse iterators 2021-12-12 17:45:06 +01:00
Michele Caini
208746f28f view: get rid of the internal::storage_tuple function, back to the uniform model 2021-12-12 17:05:37 +01:00
Michele Caini
61c5f8ae22 registry/view/group: cleanup 2021-12-12 16:51:48 +01:00
Michele Caini
4e0cca3a08 view: clean up 2021-12-12 01:18:41 +01:00
Michele Caini
b86ffc2370 view: drop conceptually broken reverse iterators 2021-12-12 01:11:20 +01:00
Michele Caini
33574c9885 doc: updated README file 2021-12-10 10:24:08 +01:00
Michele Caini
672c542f99 group: removed ::data, use ::handle<T>().data() and ::storage<T>().data() instead 2021-12-10 09:30:16 +01:00
Michele Caini
f741fe48a1 group: added ::handle to non-owning groups 2021-12-10 08:25:46 +01:00
Michele Caini
4347ebcee2 group: added base_type type member 2021-12-09 17:50:51 +01:00
Michele Caini
4e3e5a5361 doc: updated doc for the ecs module 2021-12-09 17:49:30 +01:00
Michele Caini
8e6439c3d1 group: removed ::raw, use ::storage().raw() instead 2021-12-09 17:49:18 +01:00
Michele Caini
b54d358feb view: removed ::data for single type views, use ::storage().data() instead 2021-12-09 09:37:17 +01:00
Michele Caini
78baa7b12d view: removed ::raw for single type views, use ::storage().raw() instead 2021-12-09 09:21:37 +01:00
Michele Caini
19f1dd22e9 view: minor changes to avoid confusion 2021-12-09 09:12:08 +01:00
Michele Caini
73f583f68a registry: doc cleanup 2021-12-09 09:05:14 +01:00
Michele Caini
52de43e329 registry: removed ::empty<T>(), use ::view<T>().empty() or ::storage<T>().empty() instead 2021-12-09 08:20:34 +01:00
Michele Caini
49ddacaac0 registry: removed ::size<T>(), use ::view<T>().size() or ::storage<T>().size() instead 2021-12-08 15:17:35 +01:00
Michele Caini
4533b3a1c0 registry: minor chages (doc/internals) 2021-12-05 17:01:40 +01:00
Michele Caini
f30ea02794 registry:
* removed registry::reserve<Component> (use registry.storage<Component>.reserve(v) instead)
* removed registry::capacity<Component> (use registry.storage<Component>.capacity() instead)
* removed registry::shrink_to_fit<Component> (use registry.storage<Component>.shrink_to_fit() instead)
2021-12-05 16:20:14 +01:00
Michele Caini
7112dda299 build_system: added all headers to the EnTT target 2021-12-05 16:01:32 +01:00
Michele Caini
02636a7108 view: minor changes 2021-12-05 15:55:40 +01:00
Michele Caini
36a9456e0d test: minor changes to make all major compilers agree at least on something :) 2021-12-04 15:32:38 +01:00
Michele Caini
113893dcea meta: added meta_any::owner 2021-12-04 15:28:52 +01:00
Michele Caini
1abbe9c7b2 test: minor changes (code coverage) 2021-12-04 15:21:49 +01:00
Michele Caini
7205ac791c meta: make policies check function return types 2021-12-03 18:25:11 +01:00
Michele Caini
3335b81ad4 meta:
* dtor support to member functions
* review to introduce strict checks on policies
2021-12-03 17:56:09 +01:00
Michele Caini
d9c9438f3c test: minor changes 2021-12-03 14:39:50 +01:00
Michele Caini
37250843e1 sigh: allocator support 2021-12-02 11:30:54 +01:00
Michele Caini
072ab88721 build system: avoid using windows-2016 (deprecated by GH) 2021-12-01 10:33:43 +01:00
Michele Caini
c208e6b107 natvis: avoid errors due to null/tombstone definition not available in some contexts 2021-11-30 14:44:12 +01:00
Michele Caini
65f3185b39 entity: add page_size to entt_traits to make it more natvis friendly and customizable on a per-type basis 2021-11-30 13:48:12 +01:00
Michele Caini
34f73f8a2b registry: added base_type member type 2021-11-30 11:23:15 +01:00
Michele Caini
cb4142a97d entity: simplified to_version 2021-11-30 09:46:15 +01:00
Michele Caini
80d08d5a34 view:
* fixed init list order to suppress a warning
* try to please gcc that fails to compile valid code
2021-11-30 09:46:14 +01:00
Michele Caini
052aecf533 natvis: basic_view (single and multi type) 2021-11-30 09:46:14 +01:00
Michele Caini
7bde714f18 view: minor changes 2021-11-30 09:46:14 +01:00
Michele Caini
5ff429f656 view:
* added single type view overloads for ::storage to make it compatible with the multi-type view version
* removed the useless tuple from single type views
* updated operator|
2021-11-30 09:46:14 +01:00
Michele Caini
92f27299e1 group: added the ::storage method (with tests) 2021-11-30 09:46:14 +01:00
Michele Caini
f9013375f8 view: added the ::storage method (with tests) 2021-11-30 09:46:14 +01:00
Michele Caini
f18b0045ba registry: get around an issue of the toolset v141 2021-11-30 09:46:14 +01:00
Michele Caini
18173cc4c0 view: minor changes 2021-11-30 09:46:12 +01:00
Michele Caini
6a1ffdd7a5 natvis: bypass some natvis idiosyncrasies to display storage information and content in all cases 2021-11-30 09:45:37 +01:00
Michele Caini
8db78b2190 nativs:
* don't abuse Intrinsic, it also has drawbacks
* refine natvis snippet for dispatcher class
2021-11-30 09:45:37 +01:00
Michele Caini
3fcccae241 component traits:
* added page_size to tune the page size on a per-type basis
* turned in_place_delete into a boolean value
* turned ignore_if_empty into a boolean value
* removed in_place_delete_v (no longer required)
2021-11-30 09:45:37 +01:00
Michele Caini
6ff8add164 entity: added missing includes 2021-11-30 09:45:37 +01:00
Michele Caini
58a8c3c82a natvis: make the ecs stuff work with entity classes 2021-11-30 09:45:37 +01:00
Michele Caini
92c5c656c7 natvis: dispatcher 2021-11-30 09:45:37 +01:00
Michele Caini
61856cd648 natvis: poly 2021-11-30 09:45:37 +01:00
Michele Caini
687f82b5c2 natvis: basic_registry 2021-11-30 09:45:37 +01:00
Michele Caini
920c864bed natvis: tombstone/null 2021-11-30 09:45:37 +01:00
Michele Caini
1360c985b7 natvis: when you discover the intrinsic tag... :) 2021-11-30 09:45:37 +01:00
Michele Caini
b6f953e13b natvis: added simple views + minor changes 2021-11-30 09:45:37 +01:00
Michele Caini
796b96071b registry: minor changes 2021-11-30 09:45:37 +01:00
Michele Caini
ec56ccc690 view: minor changes 2021-11-30 09:45:35 +01:00
Michele Caini
95931b67e1 registry: turn storage_type in a public member type 2021-11-30 09:43:48 +01:00
Michele Caini
706bbb83c9 storage: clean up 2021-11-30 09:43:48 +01:00
Michele Caini
43099f47d0 meta: try to suppress a wrong warning from clang 2021-11-30 09:43:48 +01:00
Michele Caini
eca86999c3 doc: added a section about runtime stuff 2021-11-30 09:43:48 +01:00
Michele Caini
a00b44a5fd example: stamp is back 2021-11-30 09:43:48 +01:00
Michele Caini
5b8dcff2a4 helper: make to_entity also work for stable types (close #768) 2021-11-30 09:43:48 +01:00
Michele Caini
e4d36e4982 registry: decouple ::storage/::assure 2021-11-30 09:43:48 +01:00
Michele Caini
adfdbf138d registry:
* public and runtime pools
* removed basic_registry<...>::prepare
2021-11-30 09:43:48 +01:00
Michele Caini
8d1ba26492 registry: try to also please vs2015 ¯\_(ツ)_/¯ 2021-11-30 09:43:48 +01:00
Michele Caini
792625f763 registry: minor changes/cleanup 2021-11-30 09:43:47 +01:00
Michele Caini
5e8eae4ef8 natvis: delegate, sigh, sink, connection, scoped_connection 2021-11-30 09:43:47 +01:00
Michele Caini
148212da96 natvis: minor changes 2021-11-30 09:43:47 +01:00
Michele Caini
23ddb12529 registry: removed pdata container, pools are standalone objects and thus ready to go public 2021-11-30 09:43:47 +01:00
Michele Caini
186a5e8f7b natvis: updated definition for sparse set and storage 2021-11-30 09:43:47 +01:00
Michele Caini
dfb5fe1e04 sparse_set/storage: opaque get from base 2021-11-30 09:43:47 +01:00
Michele Caini
640f75373e doc: minor changes 2021-11-30 09:43:47 +01:00
Michele Caini
46e5d96ced sparse_set/storage: value type from base, if any 2021-11-30 09:43:47 +01:00
Michele Caini
ad3fbe2052 sparse_set/storage: no virtual swap (the silliest thing I've ever done) 2021-11-30 09:43:47 +01:00
Michele Caini
cd6c60fd46 sparse_set/storage: emplace-from-below with value 2021-11-30 09:43:47 +01:00
Michele Caini
f7be386d5a sparse_set: rename context to bind 2021-11-30 09:43:47 +01:00
Michele Caini
89b2131052 doc:
* const thread safe registry
* detached views
2021-11-30 09:43:47 +01:00
Michele Caini
e5d1ca2e3c registry:
* const thread safe implementation
* views created from const registires can refer placeholder pools (that is, they don't refresh)
2021-11-30 09:43:47 +01:00
Michele Caini
32b8224afd runtime_view: simplify the construction process 2021-11-30 09:43:47 +01:00
Michele Caini
00e7ab1db8 entity: fully remove the poly storage support 2021-11-30 09:43:47 +01:00
Michele Caini
e376a53b09 entity:
* custom move ctor/op for the registry class
* no registry argument from storage emplace, remove, ...
* added sparse set context to forward variables to mixins
* removed sparse set user data
2021-11-30 09:43:47 +01:00
Michele Caini
17a9cd5666 cache: use identity as hashing function 2021-11-30 09:43:47 +01:00
Michele Caini
fc3de662c3 registry: combine dense hash maps and identity when the key is a hashed string already 2021-11-30 09:43:47 +01:00
Michele Caini
8de568c2fc *: combine dense hash map and identity when the key is a hashed string already 2021-11-30 09:43:47 +01:00
Michele Caini
55661883d9 registry: use a dense hash map for context variables 2021-11-30 09:43:47 +01:00
Michele Caini
b59d3ebeaa *: dense_hash_map being a drop-in replacement for unordered_map has its advantages :) 2021-11-30 09:43:47 +01:00
Michele Caini
2866dcdd03 doc: updated documentation about making EnTT work smoothly across boundaries 2021-11-30 09:43:47 +01:00
Michele Caini
b147f9d58c registry: make it run smoothly across boundaries (close #719, close #729) 2021-11-30 09:43:47 +01:00
Michele Caini
8e2a6470ac emitter: make it run smoothly across boundaries 2021-11-30 09:43:47 +01:00
Michele Caini
19230f7672 dispatcher: make it run smoothly across boundaries 2021-11-30 09:43:47 +01:00
Michele Caini
764dfbe46a doc: minor changes 2021-11-30 09:43:47 +01:00
Michele Caini
0ec7631310 view: make all unoptimized single type views check for tombstones 2021-11-30 08:58:51 +01:00
Michele Caini
0b39ece990 meta: fix an issue with meta_factory<T>::prop when using tuple of properties 2021-11-18 15:44:12 +01:00
Michele Caini
97500dff57 meta: fixed an issue with meta_factory::conv when used with member functions + code coverage 2021-11-18 14:53:17 +01:00
Michele Caini
dc6299a029 doc: fixed typos 2021-11-18 09:00:52 +01:00
Michele Caini
58b1e2fb98 hashed string: warnings to clarify that it does not take ownerships of the string or copy it (close #798) 2021-11-16 18:05:17 +01:00
Michele Caini
0302fdaaba build system: update gtest upstream branch name 2021-11-16 09:33:32 +01:00
Michele Caini
09b260e0af view: use explicit types to also please clang 6.x 2021-11-15 14:43:20 +01:00
Michele Caini
24b7e998b2 registry: minor changes 2021-11-13 18:30:35 +01:00
Michele Caini
19068ea5c7 doc: updated links 2021-11-13 12:19:51 +01:00
Michele Caini
b5cd3eb468 natvis: hashed_string + minor changes 2021-11-11 14:40:20 +01:00
Michele Caini
91a2b5a5f7 natvis: expand meta_any as a meta_type_node 2021-11-11 11:16:51 +01:00
Michele Caini
0096f6d962 natvis: meta 2021-11-11 10:04:45 +01:00
Michele Caini
87cfe41b15 natvis: minor changes 2021-11-11 10:04:21 +01:00
Michele Caini
c490086097 license: just make it clear that this is about EnTT :) 2021-11-10 11:02:32 +01:00
Michele Caini
5b3fd7537e meta: avoid a (maybe) UB in meta_any 2021-11-08 15:16:22 +01:00
Michele Caini
2cab2583c0 any: minor changes 2021-11-08 13:41:16 +01:00
Michele Caini
a40a3b594d storage: make try_emplace forward user data to base classes 2021-11-06 23:35:25 +01:00
Michele Caini
0fa586a3d8 type_id: reduce the number of static variables due to type_id 2021-11-06 23:31:57 +01:00
Michele Caini
25977cc569 test: use deduction guides :) 2021-11-05 14:17:33 +01:00
Michele Caini
0be7064493 view:
* support for multiple components of the same type
* removed view.each<T>(F), use view.use<T>().each(F) instead
* removed view.each<T>(), use view.use<T>().each() instead
* added use<integral value>() to set leading pool by index
* added get<integral value...>() to get components by index
2021-11-05 11:02:15 +01:00
Michele Caini
0b13dc254a registry: minor changes 2021-11-05 10:58:30 +01:00
Michele Caini
c1e953ab6e registry: removed redundant compile-time check 2021-11-04 18:45:55 +01:00
Michele Caini
a069764af1 type traits:
* unpack_as_t -> unpack_as_type
* unpack_as_v -> unpack_as_value
2021-11-04 14:17:21 +01:00
Michele Caini
3dbe6c3902 meta: cleanup/review 2021-11-04 12:37:20 +01:00
Michele Caini
9f0b380024 container:
* review dense_hash_map_iterator::operator[]
* review dense_hash_set_iterator::operator[]
* code coverage
2021-11-02 09:29:10 +01:00
Michele Caini
193b102013 entity:
* review sparse_set_iterator::operator[]
* review storage_iterator::operator[]
* code coverage
2021-11-02 09:19:57 +01:00
Michele Caini
511fde91fa natvis: snippet for dense_hash_set 2021-10-30 13:49:11 +02:00
Michele Caini
16e3cfc589 container: added dense_hash_set 2021-10-30 13:45:02 +02:00
Michele Caini
ed2012a36c dense_hash_map: minor changes + test coverage 2021-10-30 13:44:00 +02:00
Michele Caini
46598fde32 dense_hash_map: less risky but still on the edge :) 2021-10-29 12:32:09 +02:00
Michele Caini
94d0c5fa5c compressed_pair: added first_type/second_type member types 2021-10-28 12:18:59 +02:00
Michele Caini
4e72291588 meta: define meta_associative_container_traits for dense_hash_map 2021-10-28 08:22:20 +02:00
Michele Caini
74cdf000b4 doc: fixed a couple of typos 2021-10-26 15:44:05 +02:00
Michele Caini
565dc3327b natvis: snippet for meta_any 2021-10-26 15:01:04 +02:00
Michele Caini
462af21793 entity: avoid shadow warnings 2021-10-26 14:19:55 +02:00
Michele Caini
94af659c86 natvis:
* minor changes to entity.natvis
* snippet for dense_hash_map
2021-10-26 11:04:19 +02:00
Michele Caini
b63c9fc67b dense_hash_map: always guarantee that load factor is less than max load factor 2021-10-26 11:04:19 +02:00
Michele Caini
f519b55a47 natvis: compressed_pair 2021-10-26 11:04:19 +02:00
Michele Caini
2fb039b429 entity: minor changes 2021-10-26 11:04:19 +02:00
Michele Caini
4bce5aed77 natvis: snippets for type_info and basic_any 2021-10-26 11:04:19 +02:00
Michele Caini
eca6032306 entity:
* small changes to the entt_traits class
* natvis snippets for basic_sparse_set and basic_storage (with tombstone detection)
2021-10-26 11:04:19 +02:00
Michele Caini
dd2f515af1 build_system: avoid using INTERNAL for cmake variables since it also implies STRING 2021-10-26 11:04:19 +02:00
Michele Caini
df25482643 build_system: support for natvis files (optionally added to the target) 2021-10-26 11:04:19 +02:00
Michele Caini
df016b3bf9 natvis: prepare support for natvis info 2021-10-26 11:04:19 +02:00
Michele Caini
8699e96609 build_system:
* ENTT_USE_LIBCPP default is OFF
* added ENTT_INCLUDE_HEADERS to make adding headers to the EnTT target optional
* slightly better message handling
2021-10-26 11:04:19 +02:00
Michele Caini
b0dcaaf744 build_system: refine ENTT_USE_SANITIZER usage 2021-10-26 11:04:19 +02:00
Michele Caini
7db001995c build system: make EnTT files show up in IDEs automatically (close #776) 2021-10-26 11:04:19 +02:00
Michele Caini
c88adf9314 meta: avoid unnecessary moves (see #794) 2021-10-26 11:04:19 +02:00
Michele Caini
b13713ce98 meta: support transparently base members when attached to meta types for derived classes 2021-10-26 11:03:29 +02:00
Michele Caini
66b89d170f type_traits: tuple-like type support for is_equality_comparable[_v] 2021-10-22 16:50:00 +02:00
Michele Caini
4311e2e686 type_traits: make is_iterator also support void * 2021-10-22 10:25:02 +02:00
Michele Caini
fd566eff7a code coverage: move to codecov action v2 2021-10-21 11:00:42 +02:00
Michele Caini
efaa3f9e55 *: revert unnecessary changes ¯\_(ツ)_/¯ 2021-10-20 12:18:18 +02:00
Michele Caini
b625ff0902 dense_hash_map: iterator review 2021-10-20 11:44:48 +02:00
Michele Caini
fee80321ef meta_[sequence|associative]_container: iterator review 2021-10-20 10:08:49 +02:00
Michele Caini
4b9331f086 sparse_set: iterator review 2021-10-20 09:41:27 +02:00
Michele Caini
df9316b896 runtime_view: iterator review 2021-10-20 09:32:55 +02:00
Michele Caini
dae5f86d4e storage: iterator review 2021-10-20 09:10:29 +02:00
Michele Caini
75a0cefcb3 meta_range: iterator review 2021-10-20 09:06:54 +02:00
Michele Caini
2271aa5b89 registry: make all_of, any_of and a few other functions remove const qualifiers 2021-10-19 08:45:58 +02:00
Michele Caini
b668e2a967 meta: removed unused reference qualifiers 2021-10-18 16:27:49 +02:00
Michele Caini
ce44c59547 meta: suppress warnings due to unreachable code 2021-10-18 11:27:22 +02:00
Michele Caini
84802d931d clean up todo list 2021-10-12 16:56:12 +02:00
Michele Caini
8183c4383e meta: suppress a shadow warning 2021-10-12 16:55:57 +02:00
Michele Caini
af249098cd container: sparse set based dense hash map 2021-10-12 16:50:28 +02:00
Michele Caini
8fdd063f00 entity: include fwd.hpp from entity.hpp (close #790) 2021-10-12 15:14:36 +02:00
Michele Caini
fe328f6a75 identity: add is_transparent member type 2021-10-10 16:31:45 +02:00
Michele Caini
ef7163acd6 storage: non-const to const iterator conversion guaranteed 2021-10-10 10:58:58 +02:00
Michele Caini
6e45f0d5b8 meta_range: non-const to const iterator conversion guaranteed 2021-10-10 10:46:34 +02:00
Michele Caini
ff41faa3fe memory: all of a sudden I remembered what greater than or equal to means :) 2021-10-10 00:42:25 +02:00
Michele Caini
acb2d332ea type_traits: added is_transparent[_v] utility 2021-10-09 19:19:18 +02:00
Michele Caini
0fb86f21e4 type_traits: add tests for is_ebco_eligible_v 2021-10-09 19:03:28 +02:00
Michele Caini
e4991d367e memory: fast_mod no longer requires a compile-time modulus (but it's still a constexpr function) 2021-10-08 20:24:07 +02:00
Michele Caini
3144cfafd5 memory: added constexpr function next_power_of_two 2021-10-07 16:53:22 +02:00
Michele Caini
c538067544 *: cleanup, minor changes 2021-10-06 11:52:32 +02:00
Michele Caini
f8e137a1dc test: suppress warnings due to missing virtual destructor 2021-10-05 08:40:07 +02:00
Michele Caini
36ea38fd91 resource class vs struct definition 2021-10-05 08:39:54 +02:00
Michele Caini
baae5a7215 test: code coverage 2021-10-05 08:38:06 +02:00
Michele Caini
a4b267227e meta: split meta_invoke_with_args function 2021-10-05 08:37:35 +02:00
Michele Caini
58dd159699 meta: add and typename keywords for fun (thanks to msvc that also accepts invalid code) 2021-10-05 08:14:03 +02:00
Michele Caini
80082f9d51 meta: static functions that require the parent type as first argument are treated as (eventually const) member functions 2021-10-04 18:20:16 +02:00
Michele Caini
7975ffc10b meta: minor changes 2021-10-04 16:36:50 +02:00
Michele Caini
012083a4a1 meta: review utilities + code coverage 2021-10-04 16:21:55 +02:00
Michele Caini
3c67723e83 doc: minor changes 2021-10-04 11:52:22 +02:00
Michele Caini
7f0598b3cb meta: cleanup headers 2021-10-04 09:01:13 +02:00
Michele Caini
c5b27e0ae0 test: minor changes (code coverage) 2021-10-03 16:58:58 +02:00
Michele Caini
4e7ad31f18 resource: dynamic resource handle cast example (close #786) 2021-10-03 00:26:46 +02:00
Michele Caini
c7a3e9d4ac resource: cache const correctness review 2021-10-03 00:01:59 +02:00
Michele Caini
a05e7a84c4 resource: handle as value type, const correctness review 2021-10-02 23:52:22 +02:00
Michele Caini
389cb85410 resource: strict check on resource type for cache 2021-10-02 23:35:40 +02:00
Michele Caini
81ae2bed25 resource: added resource_handle::resource_type 2021-10-02 16:26:44 +02:00
Michele Caini
0ab71bc2e7 view: return a const reference to the leading storage 2021-10-01 16:26:11 +02:00
Michele Caini
81e6bbe643 test: minor changes (thanks msvc for accepting invalid code) 2021-10-01 11:05:21 +02:00
Michele Caini
c4723f3b24 view/group: added missing operator-> here and there 2021-10-01 10:57:32 +02:00
Michele Caini
df4d8e0411 meta: make meta_iterator::operator-> const as it ought to be 2021-10-01 10:57:16 +02:00
Michele Caini
4f1820bcad iterator: review of input iterator pointer type 2021-10-01 10:24:05 +02:00
Michele Caini
e375097e43 doc: minor changes 2021-10-01 09:46:41 +02:00
Michele Caini
c51bec0034 meta: add meta_range::operator-> 2021-09-30 17:34:16 +02:00
Michele Caini
081c3fdb5b iterator: added [[nodiscard]] to input_iterator_proxy::operator-> 2021-09-30 16:57:20 +02:00
Michele Caini
f1e7602775 meta: added operator-> to meta containers' iterators 2021-09-30 16:56:58 +02:00
Michele Caini
acd75ffe1c iterator: added utility input_iterator_proxy 2021-09-30 16:34:09 +02:00
Michele Caini
fc813cb59b doc: minor changes 2021-09-30 14:41:33 +02:00
Michele Caini
044d14f542 *: minor changes 2021-09-29 16:12:39 +02:00
Michele Caini
28b9f07b99 *: code coverage, cleanup 2021-09-29 11:27:13 +02:00
Michele Caini
6f20dd4e45 test: suppress a wrong warning with toolset v141 2021-09-29 11:09:37 +02:00
Michele Caini
2fc05e5b90 meta: add missing template keywords (thanks MSVC for accepting invalid code) 2021-09-29 11:03:08 +02:00
Michele Caini
9afde31f97 meta: make meta_any::assign work with mutating this pointers 2021-09-29 10:57:31 +02:00
Michele Caini
e835ce0697 meta: make meta_any::allow_cast work with mutating this pointers 2021-09-29 09:49:22 +02:00
Michele Caini
6030f56c76 meta: make meta_any::try_cast work with mutating this pointers 2021-09-28 18:50:03 +02:00
Michele Caini
ba89b53c63 doc: cleanup 2021-09-28 15:11:29 +02:00
Michele Caini
1bfb877a3b entity: adds to_entity and to_version to the entt namespace (see #788) 2021-09-28 14:52:52 +02:00
Michele Caini
72776d6fb6 entity: make return type of to_integral explicit 2021-09-28 14:31:09 +02:00
Michele Caini
7bb93420c4 storage: avoid reinventing the wheel :) 2021-09-27 08:55:50 +02:00
Michele Caini
bb1b0e0581 sparse_set: minor changes 2021-09-26 23:28:32 +02:00
Michele Caini
45ddcf0df9 sparse_set: compare allocators before moving in the move operator assignment 2021-09-26 11:08:55 +02:00
Michele Caini
9c4d7a286f memory: avoid warnings due to unused parameters 2021-09-26 11:06:36 +02:00
Michele Caini
7b290b43b5 sparse_set: try not to reinvent the wheel :) 2021-09-26 10:59:00 +02:00
Michele Caini
2e2782b030 sparse_set: partial sorting not supported in case of tombstones 2021-09-25 18:29:45 +02:00
Michele Caini
48f23bd1ba doc: cleanup 2021-09-24 16:22:42 +02:00
Michele Caini
3ece33b26a any: avoid using addressof on the result of an operator assignment without a good reason :) 2021-09-24 13:29:16 +02:00
Michele Caini
efa98379b0 meta: internal changes and cleanup 2021-09-24 12:49:43 +02:00
Michele Caini
324aeba70f meta: suppress a warning due to -Wignored-qualifiers (close #785) 2021-09-24 11:50:51 +02:00
Michele Caini
7b6715c7b5 test: code coverage for the storage class for empty types 2021-09-24 11:18:11 +02:00
Michele Caini
1ea392b6c9 test: minor changes to suppress a bunch of warnings + formatting 2021-09-24 10:19:13 +02:00
Michele Caini
8b1a3849e6 meta_any: support assigning the value wrapped by a meta_any 2021-09-24 10:08:59 +02:00
Michele Caini
e1d7e98c92 any: minor changes 2021-09-23 10:36:30 +02:00
Michele Caini
04b2e1152c any:
* when moving fails, try to copy anyway as a fallback
* code coverage
2021-09-22 17:13:02 +02:00
Michele Caini
d392eba4a0 test: code coverage 2021-09-22 16:49:42 +02:00
Michele Caini
799dec4f1c sparse_set: suppress a warning due to -Wreorder 2021-09-22 16:41:40 +02:00
Michele Caini
11df6ec927 type_id: cannot have a static variable in a constexpr function (right msvc?) 2021-09-22 16:38:41 +02:00
Michele Caini
03e363f5d9 any: added the ::assign function to copy/move assign the wrapped variable 2021-09-22 16:27:56 +02:00
Michele Caini
39211889b0 any (close #782):
* make const type_info * a first citizen
* further reduce vtable size
2021-09-22 12:48:25 +02:00
Michele Caini
db44549276 type_info/type_id:
* type_info is no longer default constructible
* users cannot construct type_info objects anymore
* make type_id refer to an object with static storage duration
2021-09-22 12:41:09 +02:00
Michele Caini
49e702c0c7 hashed_string: minor changes 2021-09-22 08:34:31 +02:00
Michele Caini
c9c5214b3e type_info: operator<, operator<=, operator> and operator>= 2021-09-22 08:34:18 +02:00
Michele Caini
24a537d154 meta: review conversion_helper for meta type nodes 2021-09-21 17:11:28 +02:00
Michele Caini
c32ecf171b sparse_set: added user_data field 2021-09-21 15:54:26 +02:00
Michele Caini
a62ae21628 any: const reference instead of pointer as default argument to ::data 2021-09-21 09:03:39 +02:00
Michele Caini
12f05e8f72 doc: fixed typo (close #784) 2021-09-20 08:07:05 +02:00
Michele Caini
81fb727d20 registry: improved ctx and the like (close #782) 2021-09-19 15:14:43 +02:00
Michele Caini
e7655c761d test: code coverage 2021-09-18 23:22:00 +02:00
Michele Caini
464fcf4300 test: fix a test that I've broken a couple of commits ago :) 2021-09-18 00:06:50 +02:00
Michele Caini
73b67ea9df *: review enums 2021-09-18 00:02:35 +02:00
Michele Caini
04a9c80c14 *: removed pointless continue; 2021-09-17 23:44:15 +02:00
Michele Caini
80b5ed3d22 introduced clang-format (close #733) 2021-09-17 23:42:43 +02:00
Michele Caini
be5ad379b6 *: another handful of changes to please clang-format 2021-09-17 17:21:26 +02:00
Michele Caini
13d901fbfa *: a handful of changes to please clang-format 2021-09-17 16:43:15 +02:00
Michele Caini
f7e7273e91 *: minor changes 2021-09-16 23:09:22 +02:00
Michele Caini
4b3bd265a6 meta: minor changes 2021-09-15 12:43:31 +02:00
Michele Caini
42dcec961b meta: support for multi-setters on meta data members 2021-09-15 09:32:12 +02:00
Michele Caini
6b2a3b2916 meta: prepare for multi-setters on meta data members 2021-09-14 14:57:17 +02:00
Michele Caini
930f9ca436 any: minor changes 2021-09-14 08:52:44 +02:00
Michele Caini
a96a767b9b test: code coverage 2021-09-13 19:32:23 +02:00
Michele Caini
36627dbe78 meta:
* removed meta_ctor, no alternatives provided
* removed meta_type::ctor overloads, no alternatives provided
2021-09-13 19:03:22 +02:00
Michele Caini
f86bc31cbb meta: shared lookup function to avoid unnecessary casts when searching for a meta constructor 2021-09-13 16:37:58 +02:00
Michele Caini
4a08ca4b5e meta: minor changes 2021-09-13 14:58:08 +02:00
Michele Caini
e857aa0640 meta: extrapolate can_cast_or_convert 2021-09-13 12:57:06 +02:00
Michele Caini
d3c98ad334 meta_factory: cleanup 2021-09-13 12:56:39 +02:00
Michele Caini
00dadfe14d meta: reduce the size of instantiated symbols in meta_factory 2021-09-13 12:55:07 +02:00
Michele Caini
f26fa92d47 handle: extended operator==/!= 2021-09-12 18:39:20 +02:00
Michele Caini
7458072df2 hashed_string (close #781):
* operator< and operator<=
* operator> and operator>=
2021-09-12 18:26:08 +02:00
Michele Caini
89aa2a1902 *: operator== is not defined as member if unnecessary 2021-09-12 17:52:29 +02:00
Michele Caini
7ab08779dc type_info: temporarily reintroduce type_info::index for performance reasons 2021-09-10 11:29:05 +02:00
Michele Caini
46b686910b any:
* reintroduced operation::TYPE to avoid fat any types
* added optional req parameter to data
* much faster any_cast
* much faster operator==
* internal review
2021-09-10 11:22:07 +02:00
Michele Caini
940a799207 * : minor changes 2021-09-10 00:04:23 +02:00
Michele Caini
778cee3b27 any:
* operator bool doesn't rely on the vtable
* valid but unspecified state after move converts to true
* compare type info objects to avoid future errors if the logic changes
2021-09-09 17:03:36 +02:00
Michele Caini
fb3252732b type_info: name rollback, hash_code -> hash (why should I introduce a breaking change to match a terrible name from the standard library after all?) 2021-09-09 14:49:39 +02:00
Michele Caini
608f7b75e2 any: avoid creating constexpr variables since constexpr-ness isn't guaranteed 2021-09-09 14:14:58 +02:00
Michele Caini
83853c3dee any:
* ::type() returns the object type if any, type_id<void>() otherwise
* avoid indirection when accessing the type
2021-09-09 14:00:08 +02:00
Michele Caini
8a0343ad6b any: avoid creating type_info objects if unnecessary 2021-09-09 11:44:36 +02:00
Michele Caini
92d43ce620 core: rename type_seq to type_index 2021-09-09 09:53:29 +02:00
Michele Caini
6943822fed type_info:
* make the API closer to that of std::type_info
* remove the ::seq member function
* rename :.hash to ::hash_code
2021-09-09 09:44:58 +02:00
Michele Caini
aa146c4125 type_info: avoid testing constexpr-ness because older compilers don't guarantee it 2021-09-09 09:04:04 +02:00
Michele Caini
b8ec6babb5 any:
* reduced vtable size
* internal rework
2021-09-09 00:40:06 +02:00
Michele Caini
505f4a2b4f type_info:
* constexpr support
* reduce instantiations
* reduce function calls/indirection
2021-09-09 00:20:20 +02:00
Michele Caini
1bb0d017c3 type_info: removed useless friend declaration 2021-09-08 23:43:28 +02:00
Michele Caini
f33ce615d9 meta: suppress warnings due to ignored qualifiers on return types 2021-09-08 11:35:50 +02:00
Michele Caini
0edb49d7c6 core: minor changes 2021-09-08 09:13:54 +02:00
Michele Caini
1fa5a03605 test: code coverage 2021-09-07 17:13:53 +02:00
Michele Caini
fc6bda5cd8 meta: turned an useless function into a constexpr value 2021-09-07 08:54:34 +02:00
Michele Caini
59589b6a71 meta: refine the conversion helper (mostly to please the toolset v141) 2021-09-06 14:51:35 +02:00
Michele Caini
57b0624a0a storage: suppress warnings for unused variables 2021-09-06 12:29:52 +02:00
Michele Caini
2f22395eea meta:
* a more robust meta_any::allow_cast (reviewed all overloads)
* removed internal meta_info dispatcher to reduce useless instantiations
* reviewed meta_conversion_helper
2021-09-06 10:19:23 +02:00
Michele Caini
21bc8d4dfb meta: add meta_conv support to references 2021-09-04 11:43:47 +02:00
Michele Caini
2e74fd8196 meta: const correctness 2021-09-04 11:42:03 +02:00
Michele Caini
fee48ab04c meta: also please toolset v141 :) 2021-09-03 18:55:51 +02:00
Michele Caini
591f885e67 meta: automatic conversion function to underlying type for enums (see #735) 2021-09-03 18:23:49 +02:00
Michele Caini
ef803016c0 meta: suppress a shadow warning 2021-09-03 17:31:15 +02:00
Michele Caini
bac51045e5 meta: automatic arithmetic conversions (see #735) 2021-09-03 14:37:52 +02:00
Michele Caini
cb5e9393a4 meta: internal changes 2021-09-03 11:42:20 +02:00
Michele Caini
097509dd2a view: add operator[] to access (eventually unwrapped) components by entity (close #775) 2021-09-02 16:05:46 +02:00
Michele Caini
6cd44248c7 core: added tuple header and unwrap_tuple utility 2021-09-02 15:32:52 +02:00
Michele Caini
1fd61fbcef meta: added missing [[maybe_unused]] to suppress warnings 2021-09-01 10:06:28 +02:00
Michele Caini
cd2245ef03 doc: fixed typo 2021-09-01 10:03:16 +02:00
Michele Caini
5ddc746915 memory: turn is_power_of_two in a constexpr function 2021-08-31 17:39:47 +02:00
Michele Caini
f7d67067ad test: increase code coverage 2021-08-30 17:06:31 +02:00
Michele Caini
d1a824f76e sparse_set/storage: cleanup 2021-08-30 16:53:20 +02:00
Michele Caini
d7b0fc09d7 storage: refine ::release_memory 2021-08-30 16:36:45 +02:00
Michele Caini
2d07a6ec1f storage:
* decouple iterator from allocator
* test iterator aliases to avoid future regressions
* internal changes/rework
2021-08-30 16:18:28 +02:00
Michele Caini
014ba5a7aa sparse_set:
* test iterator aliases to avoid future regressions
* internal changes/rework
2021-08-30 16:09:59 +02:00
Michele Caini
2f12e524dd config/sparse_set/storage: avoid power-of-two check at config level 2021-08-29 23:27:04 +02:00
Michele Caini
ea6af75e8e memory: added utility function fast_mod 2021-08-29 23:04:40 +02:00
Michele Caini
a595c6ec6f memory:
* added utility class is_power_of_two
* added variable template is_power_of_two_v
2021-08-29 22:15:33 +02:00
Michele Caini
98f785d199 memory: make to_address [[nodiscard]] 2021-08-29 22:00:05 +02:00
Michele Caini
a0ed0c864f entt_traits: removed the (mostly useless) difference_type alias 2021-08-29 19:25:23 +02:00
Michele Caini
d4ac42749e storage: minor changes 2021-08-29 19:10:18 +02:00
Michele Caini
86414671d6 sparse_set: minor changes 2021-08-29 19:09:21 +02:00
Michele Caini
6cb935982d storage: removed a couple of old (and wrong) static asserts 2021-08-29 18:43:35 +02:00
Michele Caini
39ad040d8a sparse_set: decouple iterator from allocator 2021-08-29 18:41:59 +02:00
Michele Caini
4cc3824653 test: basic_registry<...>::get_or_emplace must work for empty types 2021-08-28 09:52:46 +02:00
Michele Caini
6d3e0600a1 storage:
* increase code coverage
* remove a pretty much useless if constexpr
2021-08-28 09:52:19 +02:00
Michele Caini
b52c9c1676 test: use storage (and sigh storage mixin) from base type 2021-08-27 16:47:08 +02:00
Michele Caini
f7506251fe build system: increase ctest timeout because ASSERT_DEATH is... expensive, at least :) 2021-08-27 11:03:35 +02:00
Michele Caini
5b06f298f1 sparse_set/storage: make storage safe to use from the base (to be tested) 2021-08-26 17:52:16 +02:00
Michele Caini
dc5488a198 storage: generalized ::insert for all mixins 2021-08-26 17:14:51 +02:00
Michele Caini
23d162e9e4 sparse_set: ::emplace no longer returns the position 2021-08-26 16:13:26 +02:00
Michele Caini
de6b660b12 sparse_set/storage:
* removed basic_sparse_set<...>::emplace_back
* general cleanup
2021-08-26 15:22:29 +02:00
Michele Caini
60c175a51d storage: ::insert always fills holes before appending 2021-08-26 15:09:30 +02:00
Michele Caini
c0a39c8064 sparse_set: insert always fills holes before appending 2021-08-26 14:56:15 +02:00
Michele Caini
61f4f93cc6 sparse_set: internals review 2021-08-26 14:55:47 +02:00
Michele Caini
764404a472 doc: minor changes, updated todo list 2021-08-26 12:19:43 +02:00
Michele Caini
04da85c88a storage: avoid invoking ::page more than once in a row 2021-08-26 12:11:54 +02:00
Michele Caini
9551b7a597 storage: added empty ::get method to storage for empty types 2021-08-25 17:05:58 +02:00
Michele Caini
f1d537d035 compressed_pair:
* disable structured binding support for clang 6
* avoid using structured binding with compressed pair in the codebase
2021-08-24 13:11:21 +02:00
Michele Caini
b43e723c84 meta: reintroduce meta_type::is_array support 2021-08-24 10:13:56 +02:00
Michele Caini
5466039c1a meta: generic begin/end for meta containers 2021-08-24 09:48:59 +02:00
Michele Caini
74e11117be storage: minor changes 2021-08-24 09:00:55 +02:00
Michele Caini
e0abab2dc4 storage:
* fixed typo in the doc
* get around msvc that also accepts invalid code (again) O.o
2021-08-23 18:18:58 +02:00
Michele Caini
08ff3ff55c sparse_set: erase assertion 2021-08-23 18:15:23 +02:00
Michele Caini
0b79d99cac storage: non-copyable allocator aware container 2021-08-23 18:13:24 +02:00
Michele Caini
38f655e7b8 *: get around the fact that msvc also accepts invalid code O.o 2021-08-21 17:28:30 +02:00
Michele Caini
6f546ffe95 sparse_set: entity ::swap -> ::swap_elements 2021-08-21 17:25:38 +02:00
Michele Caini
ef8211a46e sparse_set: non-copyable allocator-aware container 2021-08-21 17:18:04 +02:00
Michele Caini
52ea5e4074 memory: added pocca/pocma/pocs utility functions 2021-08-21 17:03:07 +02:00
Michele Caini
99621cf08a memory: unfancy -> to_address (waiting for C++20) 2021-08-20 15:28:46 +02:00
Michele Caini
a9ae9ce758 test: code coverage 2021-08-20 00:32:02 +02:00
Michele Caini
fc5a529df8 core:
* added memory.hpp
* added public unfancy function
2021-08-20 00:26:25 +02:00
Michele Caini
bc1081550d storage: minor changes 2021-08-20 00:10:09 +02:00
Michele Caini
e311ab1605 test: try to also please g++-7 2021-08-19 23:32:51 +02:00
Michele Caini
994ade0638 meta_factory: suppress shadow warning 2021-08-19 23:02:28 +02:00
Michele Caini
cf9522bd3b sparse_set: ::clear honors the modality of the set 2021-08-19 17:36:16 +02:00
Michele Caini
7fd1858db0 storage: minor changes 2021-08-19 16:34:03 +02:00
Michele Caini
c41509151b sparse_set:
* (almost) allocator-aware container
* unequal containers not supported
* copying a sparse set isn't supported
2021-08-19 15:50:29 +02:00
Michele Caini
4e12853d4a runtime_view: correctly set the no_tombstone_check member 2021-08-17 11:58:49 +02:00
Michele Caini
e1fadbc9b9 registry: removed ::version/::entity (use entt_traits instead) 2021-08-16 23:30:14 +02:00
Michele Caini
3c4d13d8b9 sparse_set/view:
* added basic_sparse_set<E>::current to return known version of identifiers in set
* sparse arrays also contain updated entity versions, no more unused bits
* basic_sparse_set<E>::contains performs a strict version check
* sparse sets manage correctly foreign entities in all cases now
* no tombstone checks for multi-type views, zero-cost pointer stability model
2021-08-16 17:07:52 +02:00
Michele Caini
732159db07 registry:
* ::current no longer asserts, it returns now tombstone versions for invalid entities
* minor changes to doc and tests
2021-08-16 16:56:11 +02:00
Michele Caini
00894eaccf entity/*: minor changes to doc and tests 2021-08-16 16:52:56 +02:00
Michele Caini
17818178cf entity:
* removed null_t::operator| (use entt_traits<T>::combine instead)
* removed tombstone_t::operator| (use entt_traits<T>::combine instead)
2021-08-14 23:00:02 +02:00
Michele Caini
89c0abfada entity:
* reviewed entt_traits<T>::combine
* added entt_traits::reserved
* use entt_traits<T>::combine where it makes sense to slightly improve perf
2021-08-14 22:26:41 +02:00
Michele Caini
8bbdd92739 entity: added entt_traits<T>::combine 2021-08-14 22:24:43 +02:00
Michele Caini
f724ceb052 entity: cleanup 2021-08-14 16:14:11 +02:00
Michele Caini
b7ac85005f updated TODO 2021-08-13 23:58:57 +02:00
Michele Caini
8ec899a8e7 sigh: make scoped_connection move constructible/assignable (close #760) 2021-08-13 15:35:05 +02:00
Michele Caini
1013c6a50e meta: removed annotation support for meta properties 2021-08-12 19:54:12 +02:00
Michele Caini
2cd5d3bab3 meta: cleanup, minor changes 2021-08-12 19:01:38 +02:00
Michele Caini
d9494960a2 meta:
* removed the possibility of invoking meta_factory::prop multiple times
* further reduced instantiations due to meta properties
2021-08-11 17:11:09 +02:00
Michele Caini
c0eb6590da snapshot: include destroyed list head in the entity count (close #757) 2021-08-11 15:23:46 +02:00
Michele Caini
a9cefcb823 meta: avoid risk of name clashing on meta types and meta data members 2021-08-10 16:07:17 +02:00
Michele Caini
d1ff491010 meta:
* removed meta_type::is_member_object_pointer (no alternative provided)
* removed meta_type::is_member_function_pointer (no alternative provided)
2021-08-10 15:39:26 +02:00
Michele Caini
2aa34f05d3 meta: removed meta_type::is_array (no alternative provided) 2021-08-09 12:47:24 +02:00
Michele Caini
135d6915ee meta, review implicitly generated meta default constructors:
* reduce instantiations and remove their static objects
* these ctors are no longer returned from a direct lookup nor during iterations
2021-08-09 10:07:43 +02:00
Michele Caini
6282195b80 meta:
* removed meta_type::is_integral (no alternative provided)
* removed meta_type::is_floating_point (no alternative provided)
* added meta_type::is_arithmetic, prepare for auto-generated implicit conversions
2021-08-07 20:43:02 +02:00
Michele Caini
adec4f08c6 meta: removed meta_type::is_union (no alternative provided) 2021-08-06 12:07:09 +02:00
Michele Caini
b24fe2f122 test: increase code coverage 2021-08-06 12:06:42 +02:00
Michele Caini
7b35bcb68a meta: use enum-as-bitmask support to get rid of old fashioned enum for meta traits 2021-08-05 10:44:13 +02:00
Michele Caini
4b629045c3 core: added enum-as-bitmask support for enum classes (thanks to @TerensTare for the suggestion) 2021-08-05 10:42:42 +02:00
Michele Caini
c6ba1d05d1 view: avoid polluting global namespace with naked operator| 2021-08-04 16:46:53 +02:00
Michele Caini
3adac90573 meta: removed meta_type::is_function_pointer (no alternative provided) 2021-08-04 16:06:58 +02:00
Michele Caini
0332188b6b meta, get rid of useless info from meta_type to further reduce instantiations:
* removed meta_type::rank (no alternative provided)
* removed meta_type::extent (no alternative provided)
* removed meta_type::rmove_extent (no alternative provided)
* removed meta_type::remove_pointer ((*any).type())
2021-08-03 16:29:19 +02:00
Michele Caini
790a1e2812 view: minor changes to get around an issue of clang 2021-08-02 18:28:48 +02:00
Michele Caini
3bd1e13321 view: removed the foobar alias which was not meant to stay there 2021-08-02 18:24:49 +02:00
Michele Caini
0cd642ca11 view: ::use<T> doesn't modify the view in-place anymore, instead it returns a new view 2021-08-02 18:22:58 +02:00
Michele Caini
d5995998b0 view:
* each<T> doesn't invoke use<T> anymore under the hood
* removed ::traverse function
* minor changes
2021-08-02 18:09:38 +02:00
Michele Caini
62babb9c22 updated TODO 2021-08-01 12:02:43 +02:00
Michele Caini
b98c69521b build_system: add support for c++20 (close #751) 2021-08-01 11:41:31 +02:00
Michele Caini
6cd37b3809 view: get around an issue of msvc when using C++20 2021-08-01 11:21:05 +02:00
Michele Caini
238170d0e2 meta: some changes to make tests compile with C++20 (MSVC) 2021-08-01 11:02:05 +02:00
Michele Caini
6fb5b25530 any: don't compare arrays directly (operator== even deprecated in C++20) 2021-08-01 10:51:48 +02:00
Michele Caini
d63f9e1eff build_system: make ENTT_CXX_STD a cached string variable (not used yet, see #751) 2021-08-01 10:47:14 +02:00
Michele Caini
461865bf3b build_system: make ENTT_ID_TYPE a cached string variable 2021-08-01 10:41:28 +02:00
Michele Caini
e95d9b9cf6 doc: updated links.md 2021-08-01 10:18:21 +02:00
Michele Caini
c52b2a4fa9 entity/*:
* add owned_t utility
* change view def to basic_view<T, get_t<C...>, exclude_t<E...>>
* change group def to basic_group<T, owned_t<O...>, get_t<G...>, exclude_t<E...>>
* remove view dispatcher (reduce instantiations)
* make basic_view::traverse use the local policy
2021-08-01 10:03:45 +02:00
Michele Caini
d0ec5d2da0 dispatcher: mionr changes 2021-08-01 09:58:32 +02:00
Michele Caini
6134058abc type_traits: minor changes (coding style) 2021-08-01 09:58:19 +02:00
Michele Caini
bd4121c260 *: cleanup 2021-07-30 14:27:53 +02:00
Michele Caini
fbab047d7f doc: fixed typo (close #749) 2021-07-30 12:13:13 +02:00
Michele Caini
e216144d07 poly: optimize single function vtables (close #689) 2021-07-29 23:54:10 +02:00
Michele Caini
94d5b11191 any: rvalue any_cast no longer forces by-copy constructor (close #730) 2021-07-29 14:30:16 +02:00
Michele Caini
d3c89da2eb doc: mention vcpkg experimental feature in the readme file (close #743) 2021-07-28 14:52:56 +02:00
Michele Caini
754a8a637e doc: updated list of showcases (close #744) 2021-07-28 14:44:42 +02:00
Michele Caini
ab24a50de7 doc: fixed typo 2021-07-27 18:56:16 +02:00
Michele Caini
8099dde34b view: relax policy constraint if possible 2021-07-27 18:56:14 +02:00
Michele Caini
99198fb07f doc: added a note about the no-policy trick 2021-07-27 18:56:08 +02:00
Michele Caini
18d02a0c95 *: suppress a couple of warnings (shadow/unused) 2021-07-27 18:56:06 +02:00
Michele Caini
e6cac7d5fb group/view: remove references to basic_sparse_set 2021-07-27 18:56:03 +02:00
Michele Caini
d8d6f00fee storage: minor changes + some tests for get/get_as_tuple 2021-07-27 18:56:01 +02:00
Michele Caini
ef5c1a1099 snapshot: minor changes 2021-07-27 18:55:55 +02:00
Michele Caini
2d92d8ee67 storage:
* Removed free function get_as_tuple
* Added get_as_tuple function at storage level
2021-07-27 18:55:52 +02:00
Michele Caini
ae60266477 updated todo list 2021-07-27 18:55:49 +02:00
Michele Caini
88da5261fc component/storage:
* removed ignore_if_empty_v, added ignore_as_empty_v
* removed fake getter requirement for empty storage types
2021-07-27 18:55:46 +02:00
Michele Caini
15efe9f702 sparse_set: make capacity virtual 2021-07-27 18:55:42 +02:00
Michele Caini
badbc5c66e storage: internal review 2021-07-27 18:55:35 +02:00
Michele Caini
d6eea41e13 sparse_set: make reserve virtual 2021-07-27 18:55:31 +02:00
Michele Caini
6a2c54adf5 sparse_set: make shrink_to_fit virtual 2021-07-27 18:55:27 +02:00
Michele Caini
75d4bc7c18 doc: minor changes 2021-07-27 18:55:24 +02:00
Michele Caini
834f7feb27 storage: removed ::sort_n, capture pool and use ::get if needed 2021-07-27 18:55:21 +02:00
Michele Caini
5d2af3f9e1 storage: removed ::sort, capture pool and use ::get if needed 2021-07-27 18:55:19 +02:00
Michele Caini
60e8e4a82a doc: updated list of links (close #723) 2021-07-27 18:54:29 +02:00
Michele Caini
92e23476ab doc: updated list of similar projects (close #731) 2021-07-27 18:54:29 +02:00
Michele Caini
4560fef058 doc: updated list of showcases (close #732) 2021-07-27 18:54:29 +02:00
Michele Caini
c5d6574617 entity: updated fwd decls 2021-07-27 18:54:29 +02:00
Michele Caini
de61a0ca45 view:
* suppress warning for shadow parameter
* adjust deduced type to avoid compile-time errors
2021-07-27 18:54:29 +02:00
Michele Caini
98470caae1 view: suppress warning 2021-07-27 18:54:29 +02:00
Michele Caini
53486c067b view: minor changes 2021-07-27 18:54:29 +02:00
Michele Caini
5b805852fa view: internal iterable_storage class 2021-07-27 18:54:28 +02:00
Michele Caini
94d02eeb4e view: minor changes 2021-07-27 18:54:28 +02:00
Michele Caini
dbfec1b247 view: get rid of filter_to_array, filter is always stored as an array 2021-07-27 18:54:28 +02:00
Michele Caini
a9a1a71145 updated TODO list 2021-07-27 18:54:28 +02:00
Michele Caini
91537bf5f3 sparse_set/storage: try to please the code coverage tool 2021-07-27 18:54:28 +02:00
Michele Caini
1baad08288 storage/sparse_set: ctor review 2021-07-27 18:54:28 +02:00
Michele Caini
1c5b846488 storage: get rid of basic_storage_impl wrapper 2021-07-27 18:54:28 +02:00
Michele Caini
6867760cc4 doc: fixed typo 2021-07-27 18:54:28 +02:00
Michele Caini
516a9209b7 sparse_set/storage: no zero sized allocations on construction 2021-07-27 18:54:28 +02:00
Michele Caini
e352c953dc test: minor changes 2021-07-27 18:54:28 +02:00
Michele Caini
f455846d18 sparse_set/storage: avoid using temporary allocators 2021-07-27 18:54:28 +02:00
Michele Caini
6d45ac942d storage: store aside a compressed allocator to avoid frequent conversions 2021-07-27 18:54:28 +02:00
Michele Caini
48939abafa sparse_set/storage: suppress shadow warnings 2021-07-27 18:54:28 +02:00
Michele Caini
fbc9595f12 sparse_set: used compressed pair to hide the cost of storing allocators 2021-07-27 18:54:28 +02:00
Michele Caini
ed2c714419 compressed_pair: added support for structured binding (with tests) 2021-07-27 18:54:28 +02:00
Michele Caini
ef7731fb8b storage: use underlying allocator 2021-07-27 18:54:28 +02:00
Michele Caini
b5ec03f585 sparse_set:
* added get_allocator
* internal review
2021-07-27 18:54:28 +02:00
Michele Caini
a8b224a364 *: minor explicit names for traits types 2021-07-27 18:54:25 +02:00
Michele Caini
3f3943a233 storage: internal review 2021-07-27 18:53:49 +02:00
Michele Caini
4171b4ae47 resource_handle: add ::use_count (close #727) 2021-07-27 18:53:49 +02:00
Michele Caini
baa4c44632 compressed_pair: minor changes 2021-07-27 18:53:49 +02:00
Hussein Taher
ffed8f37de snapshot: fix warning for discarding a nodiscard (#728) 2021-07-27 18:53:49 +02:00
Michele Caini
8978a0d159 core:
* added trait is_ebco_eligible[_v]
* added class compressed_pair
* tests and doc for compressed_pair
2021-07-27 18:53:49 +02:00
Michele Caini
4d09be0cd3 view: minor changes 2021-07-27 18:53:49 +02:00
Michele Caini
987be01bd6 component: added in_place_delete_v and ignore_if_empty_v 2021-07-27 18:53:49 +02:00
Michele Caini
7f59fc6321 test: minor changes 2021-07-27 18:53:49 +02:00
Michele Caini
feeb122c0d updated todo list 2021-07-27 18:53:49 +02:00
Michele Caini
0754f108c9 sparse_set: fix an issue with assuring pages properly on emplace (close #746) 2021-07-27 18:53:09 +02:00
Michele Caini
ea82f86749 meta: fix precedence issue 2021-07-27 11:39:37 +02:00
Michele Caini
7bd217386a meta: shared simplified visit function 2021-07-27 10:08:20 +02:00
Michele Caini
1f1e02fee1 build system: test id type std::uint64_t on the CI, all platforms 2021-07-26 23:48:26 +02:00
Michele Caini
6d1e4fb3da test: make tests for entity traits work when id_type is std::uint64_t 2021-07-26 23:48:23 +02:00
Michele Caini
9090f84611 test: make tests for hashed string work when id_type is std::uint64_t 2021-07-26 23:48:19 +02:00
Michele Caini
8e5ddba173 sparse set: make vs2017 work (more or less) fine when id_type is std::uint64_t 2021-07-26 23:48:15 +02:00
Michele Caini
86fccb5071 entity: avoid UBs when id type is std::uint64_t (close #745) 2021-07-26 23:48:09 +02:00
Michele Caini
414c3baf15 meta: further reduce size of meta_any's vtable 2021-07-26 17:06:16 +02:00
Michele Caini
bbbddbf617 meta: added internal meta_trait enum to reduce memory usage due to meta node traits 2021-07-26 11:16:00 +02:00
Michele Caini
7638b5a95e meta: suppress warnings, get around visibility issue 2021-07-26 09:55:25 +02:00
Michele Caini
3df6b05c00 doc: fixed typo (close #742) 2021-07-26 09:17:11 +02:00
Michele Caini
8566c58f2b meta: cleanup, prep for hook point 2021-07-23 17:24:41 +02:00
Michele Caini
33ccb71526 meta: add cbegin/cend to meta_range 2021-07-23 15:51:26 +02:00
Michele Caini
2b07b92039 meta (prep for hook func):
* removed meta_type::reset
* added meta_reset overloads
2021-07-23 15:47:40 +02:00
Michele Caini
959bc269e4 test: get rid of inconsistent line (close #741) 2021-07-23 07:53:51 +02:00
Michele Caini
8609068dbf type_traits: try to also please gcc :) 2021-07-22 18:21:22 +02:00
Michele Caini
d6cea80768 core: make is_equality_comparable[_v] work with iterators (close #739) 2021-07-22 18:08:19 +02:00
Michele Caini
0f2d6fb324 meta_any: avoid risky fallthrough in the vtable (close #736) 2021-07-22 17:56:22 +02:00
Michele Caini
f5d303045c meta: make meta_invoke and meta_construct utilities also support lambdas 2021-07-22 17:41:50 +02:00
Michele Caini
ad61b0c84e meta: removed parent link from meta nodes 2021-07-22 17:21:09 +02:00
Michele Caini
18373bb679 meta: meta_any::allow_cast overload for meta types 2021-07-22 16:55:45 +02:00
Michele Caini
c30dfe3bfe meta: add fwd.hpp (see #735) 2021-07-22 16:02:03 +02:00
Michele Caini
4993961c16 *: removed deprecated stuff 2021-07-22 15:20:08 +02:00
Michele Caini
89aece7c28 meta: removed meta_type::is_void 2021-07-21 11:35:35 +02:00
Michele Caini
ec96946513 meta: cleanup/further reduce instantiations 2021-07-21 11:35:35 +02:00
Michele Caini
e49aa0d424 meta: simplified meta_any::try_cast 2021-07-21 11:35:35 +02:00
Michele Caini
b5c929572a meta: possibly reduce number of instantiations due to meta_invoke 2021-07-21 11:35:35 +02:00
Michele Caini
394822aa50 meta: remove internal::meta_visit, further reduce the number of instantiations 2021-07-21 11:35:35 +02:00
Michele Caini
d12ba5e527 meta: reduce lambda instantiations 2021-07-21 11:35:35 +02:00
Michele Caini
ab316bcb2e type_info: use fake vtables 2021-07-21 11:35:35 +02:00
Michele Caini
93fc08df45 meta: template info review 2021-07-21 11:35:35 +02:00
Michele Caini
266dd02ef5 meta: utility review and cleanup 2021-07-21 11:35:35 +02:00
Michele Caini
61c1e359e9 meta: cleanup/review 2021-07-21 11:35:35 +02:00
Michele Caini
32c83986e5 meta: minor changes 2021-07-21 11:35:35 +02:00
Michele Caini
f64af2e69d meta: get rid of useless boolean values in the return types of meta containers 2021-07-21 11:35:35 +02:00
Michele Caini
6e925c7cdd meta: container support review (less instantiations, faster to compile) 2021-07-21 11:35:35 +02:00
Michele Caini
5f50f776c6 meta: remove unnecessary nested alias 2021-07-21 11:35:35 +02:00
Michele Caini
946ccf3db4 meta: reduce instantiations for meta containers 2021-07-21 11:35:35 +02:00
Michele Caini
7a0aea390b meta: minor changes (const correctness) 2021-07-21 11:35:35 +02:00
Michele Caini
ff0e6315f9 doc: fixed typo 2021-07-21 11:35:35 +02:00
Michele Caini
b7fb485349 meta: meta_type::construct should not use base constructors 2021-07-21 11:35:35 +02:00
Michele Caini
45cbe66d5d now working on version 3.9.0 2021-07-21 00:18:12 +02:00
Michele Caini
bc7a6399c1 updated single include file 2021-07-21 00:14:12 +02:00
Michele Caini
2d5a3f24aa doc: updated documentation 2021-07-21 00:07:02 +02:00
Michele Caini
1639429edd registry: minor changes 2021-07-01 15:32:30 +02:00
Michele Caini
f81abf4883 add cpp.hint to .gitignore 2021-07-01 12:32:18 +02:00
Michele Caini
dcddb7d50e registry: allow non-const types in const overloads of registry context variable getters (close #720) 2021-06-30 09:35:36 +02:00
Michele Caini
42a763031c storage: minor changes 2021-06-30 08:55:21 +02:00
Michele Caini
0964ca5918 storage: turn to assure_at_least based on position to avoid errors at call site 2021-06-29 16:36:00 +02:00
Michele Caini
4e870b83cd test: suppress warnings due to suggested braces 2021-06-29 15:17:58 +02:00
Michele Caini
0b19c9be0b storage: add override specifier 2021-06-29 15:10:41 +02:00
Michele Caini
ac655902a0 storage:
* internal review for memory management
* added support for nosy destructors to ::in_place_pop
* optimized ::emplace/::insert
2021-06-29 15:05:03 +02:00
Michele Caini
e4fb293b55 sparse_set: added ::emplace_back 2021-06-29 12:37:39 +02:00
Michele Caini
d3df64ef4b sparse_set: emplace returns the slot used for insertion 2021-06-28 18:51:28 +02:00
Michele Caini
93e3d14f34 sparse_set: added ::slot to return the next slot available for insertion 2021-06-28 18:46:02 +02:00
Michele Caini
bc687d412d test: suppress some warnings due to [[nodiscard]] 2021-06-28 18:02:43 +02:00
Michele Caini
71e85b44b0 sparse_set: make ::policy [[nodiscard]] 2021-06-28 18:00:40 +02:00
Michele Caini
d4b59aff97 sparse_set: tombstone/null debug check in ::contains 2021-06-28 16:51:24 +02:00
Michele Caini
e3c21e1f3d sparse_set/storage (close #707):
* improved perf on erase/remove (and therefore also registry::destroy)
* allow to inhibit a pop from derived classes
* removed about_to_pop (virtual) function
2021-06-28 15:53:59 +02:00
Michele Caini
e012250e0a type_traits: minor changes 2021-06-28 11:43:27 +02:00
Michele Caini
c6bf82664c doc: added a note about optimized range-destroy 2021-06-28 11:20:40 +02:00
Michele Caini
c61e98009f registry/benchmark: rollback optimized remove/erase (benchmarks have shown that they are not worth it) 2021-06-28 10:19:27 +02:00
Michele Caini
44bccaaad6 basic_registry:
* added fast path to destroy
* added fast path to remove
* added fast path to erase
* minor changes
2021-06-28 09:24:12 +02:00
Michele Caini
aebca14dea view: added member type iterator_type to internal class view_iterator 2021-06-28 09:10:52 +02:00
Michele Caini
4576f27f6e sparse_set: minor changes 2021-06-28 09:10:12 +02:00
Michele Caini
0c213fca40 type_traits:
* added entt::is_iterator[_v]
* added entt::is_iterator_type[_v]
2021-06-28 09:09:55 +02:00
Michele Caini
891f596191 view: minor changes 2021-06-25 17:26:22 +02:00
Michele Caini
eb2b724902 benchmark: tombstone policy runs 2021-06-24 14:04:35 +02:00
Michele Caini
1f8c896181 registry:
* deprecated ::destroyed (use ::released instead)
* added ::release overloads (aka force-destroy)
2021-06-24 10:51:03 +02:00
Michele Caini
12b39e1fbe doc: added missing tokens 2021-06-23 16:35:00 +02:00
Michele Caini
206d31f27a registry: const ::view/::group also support non-const types (close #715) 2021-06-23 15:37:46 +02:00
Michele Caini
6709331182 resource_handle: conversion functions (close #706) 2021-06-22 18:54:27 +02:00
Michele Caini
9460e04ea5 entt_traits: review/cleanup 2021-06-22 15:39:15 +02:00
Michele Caini
462bfea733 entt_traits: review to reduce the risk of ambiguous calls 2021-06-22 13:03:32 +02:00
Michele Caini
a2d61dfaeb runtime_view: suppress warning for shadow parameter 2021-06-22 09:58:19 +02:00
Michele Caini
538425e35c doc: in-place delete and pointer stability 2021-06-22 09:53:56 +02:00
Michele Caini
2e86c1f1a2 component: add basic_component_traits aside component_traits 2021-06-22 09:52:43 +02:00
Michele Caini
8aa4d46ce0 runtime_view: support for storage policy (tombstones) 2021-06-21 15:18:13 +02:00
Michele Caini
cdf67a1421 sparse_set: public ::policy method for opaque runtime detection 2021-06-21 14:44:09 +02:00
Michele Caini
93d905d93d updated TODO 2021-06-21 13:04:46 +02:00
Michele Caini
2c35203647 view:
* split view iterator from multi-type view
* stable/packed storage policy support
2021-06-21 13:04:37 +02:00
Michele Caini
216871fe56 runtime_view: minor changes 2021-06-21 12:59:44 +02:00
Michele Caini
03511f39b1 registry:
* prevent groups from being used with tombstones
* support to compact one, several or all pools
2021-06-21 12:59:26 +02:00
Michele Caini
5ad0832b22 group: minor changes 2021-06-21 12:57:35 +02:00
Michele Caini
d49e7ba4b2 sparse_set/storage:
* added component traits (component.hpp)
* support for in-place delete (tombstones)
2021-06-21 12:56:33 +02:00
Michele Caini
a621b36389 type_traits: removed internal is_empty[_v] 2021-06-21 12:44:50 +02:00
Michele Caini
d093df02ac test: minor changes 2021-06-21 12:39:18 +02:00
Michele Caini
2e1529e78d entity:
* Updated doc
* No const-ref for basic types
2021-06-21 12:32:30 +02:00
Michele Caini
90be1db402 entity:
* extended entt_traits<T>::to_type support
* added null_t::operator|
* added tombstone_t::operator|
2021-06-04 11:01:26 +02:00
Michele Caini
29265e4181 doc: updated doxy.in file 2021-06-03 10:44:13 +02:00
Michele Caini
2689a7ef13 registry: minor changes 2021-06-03 09:06:38 +02:00
Michele Caini
88b58cf23d doc: added a note about tombstones 2021-06-03 09:06:36 +02:00
Michele Caini
e2e433480b entity/registry:
* added entt_traits<T>::reserved()
* added tombstone_t type and tombstone constant
* create-with-hint also accepts null entities (discarded)
* registry skips over tombstone versions and rejects them
2021-06-03 09:06:34 +02:00
Michele Caini
b8bc3e4e94 test: exception safety for sparse set and storage 2021-06-03 08:44:48 +02:00
Michele Caini
c28f52b816 sparse_set/storage: exception safety (kind of) 2021-06-03 08:44:43 +02:00
Michele Caini
ca34309f75 config: removed ENTT_NOEXCEPT, added ENTT_NOEXCEPTION 2021-06-03 08:44:30 +02:00
Michele Caini
ea614a0f3f entity: review of entt_traits<T>::to_type 2021-05-28 08:59:50 +02:00
Michele Caini
3e7dc7af29 entity:
* review of entt_traits design
* added static constexpr member function entt_traits::to_integral
* added static constexpr member function entt_traits::to_entity
* added static constexpr member function entt_traits::to_version
* added static constexpr member function entt_traits::to_type
* custom class identifiers must expose member type entity_field
* it's no longer required to specialize entt_traits (breaking change)
2021-05-28 08:59:50 +02:00
Michele Caini
0b3e3fd19a doc: updated links (close #709) and TODO file 2021-05-28 08:58:36 +02:00
Michele Caini
d3372dc05c organizer: wrap std::min to trick windows.h (close #710) 2021-05-28 08:54:41 +02:00
Michele Caini
7d141cb183 storage: fix move ctor/op 2021-05-27 16:16:45 +02:00
Michele Caini
755699c31b config:
* removed entt::page_size
* renamed ENTT_PAGE_SIZE to ENTT_SPARSE_PAGE
* added ENTT_PACKED_PAGE (page size for component arrays)
2021-05-25 10:07:20 +02:00
Michele Caini
acf3d4cd74 sparse_set/storage: suppress a couple of warnings 2021-05-25 10:06:55 +02:00
Michele Caini
92414c91b5 sparse_set/storage: review memory management for fancy allocators and the like 2021-05-24 11:53:45 +02:00
Michele Caini
ff67f402bb sparse_set/storage:
* better performance on insertion
* exception guarantee for nothrow default constructible entity types
2021-05-24 10:36:33 +02:00
Michele Caini
f048a3f1d8 sparse_set: minor changes 2021-05-24 10:27:30 +02:00
Michele Caini
9d39cb51cf storage/registry: review range ::insert (breaking change) 2021-05-24 10:27:30 +02:00
Michele Caini
7624a9d34c sparse_set/storage:
* exception safety guarantee (sort of)
* ::insert optimization for non random access iterators
2021-05-24 10:27:30 +02:00
Michele Caini
0fe73fb6ed storage: free memory in move assignment operator (with tests) 2021-05-24 10:27:10 +02:00
Michele Caini
ae11652493 sparse_set: free memory in move assignment operator (with tests) 2021-05-24 09:52:09 +02:00
Michele Caini
0ab46870ae updated TODO list 2021-05-21 09:00:18 +02:00
Michele Caini
a5381374b8 updated workflow 2021-05-20 11:00:42 +02:00
Michele Caini
7fae655651 updated TODO file 2021-05-19 10:49:23 +02:00
Michele Caini
3d9959c8e5 sparse_set/storage: small review and optimizations 2021-05-19 09:29:37 +02:00
Michele Caini
bc86576aa8 storage: improved performance when emplacing 2021-05-17 12:34:42 +02:00
Michele Caini
7c2bce8baf core: added entt::page_size 2021-05-17 12:07:48 +02:00
Michele Caini
b062bbf58d storage/view/group: reintroduce (opaque) ::raw functions as it ought to be 2021-05-17 11:59:51 +02:00
Michele Caini
8e5a048913 storage: updated pointer type for storage iterator 2021-05-17 10:10:54 +02:00
Michele Caini
ff642ffff7 sparse_set: updated pointer type for sparse set iterator 2021-05-17 10:09:50 +02:00
Michele Caini
656c12cebd view/group: opaque pointer type for ::data 2021-05-17 00:00:06 +02:00
Michele Caini
48f3fcf3bd doc: updated links (close #704) 2021-05-16 22:33:04 +02:00
Michele Caini
d797af695b registry: much faster range ::create 2021-05-16 00:26:57 +02:00
Michele Caini
75e0161c5f view :minor changes 2021-05-15 23:01:50 +02:00
Michele Caini
c0662816f1 updated TODO file 2021-05-14 18:24:09 +02:00
Michele Caini
415a31ce23 storage: forward allocator to base class 2021-05-14 15:12:29 +02:00
Michele Caini
6e603e2e51 sparse_set: suppress conversion warning 2021-05-14 15:12:26 +02:00
Michele Caini
9af318a767 test: minor changes 2021-05-14 15:12:23 +02:00
Michele Caini
30827120f6 registry: cleanup 2021-05-14 15:12:20 +02:00
Michele Caini
6194e12616 entity:
* allocator support for sparse set and storage
* pointer stability when assigning components
* removed ::raw functions (registry, view, group)
* to_entity returns null for invalid components
2021-05-14 15:12:16 +02:00
Michele Caini
59a27fb652 registry: deprecated ::reserve_pools 2021-05-13 11:01:46 +02:00
Michele Caini
f8ec57c2f6 *: cleanup 2021-05-11 10:50:38 +02:00
Michele Caini
844ef5e232 meta: avoid warning for unused variable 2021-05-10 09:49:44 +02:00
Michele Caini
5bf3f7b77e meta: suppress warning for extra ; 2021-05-08 17:19:06 +02:00
Michele Caini
00c0afd093 meta: avoid using y_combinator to clean up types (close #700) 2021-05-08 17:13:52 +02:00
Michele Caini
5228739c87 meta: make it work also with VS2017 2021-05-08 17:13:52 +02:00
Michele Caini
0f6d1268c7 meta: further reduced number of instantiations/size of symbols 2021-05-08 17:13:52 +02:00
Michele Caini
b2a4515d2b any: minor changes 2021-05-08 17:13:51 +02:00
Michele Caini
3576c80d33 meta_any: drastically reduce the number of instantiations/size of vtable 2021-05-08 17:13:51 +02:00
Michele Caini
77afd2d36c any: ::owner function (useful to also review meta_any) 2021-05-08 17:13:51 +02:00
Michele Caini
e6ddd5d9c2 any: drastically reduced the number of instantiations/size of vtable 2021-05-08 17:13:51 +02:00
Michele Caini
b9bf1a234e config: added ENTT_LAUNDER 2021-05-08 17:13:51 +02:00
Michele Caini
0ce9122449 any: reduce vtable size, simplify ref/cref creation 2021-05-08 17:13:51 +02:00
Michele Caini
dc41657872 any: empty vtable for void type 2021-05-08 17:13:51 +02:00
Michele Caini
64d9380031 *: updated messages for deprecated functions 2021-05-08 17:13:51 +02:00
Michele Caini
eca7484e30 doc: updated doc for any/meta_any 2021-05-08 17:13:51 +02:00
Michele Caini
2b5c393a13 meta: forward_as_meta 2021-05-08 17:13:51 +02:00
Michele Caini
0817d416a3 meta: make_meta_any -> make_meta 2021-05-08 17:13:51 +02:00
Michele Caini
ccff753305 any: forward_as_any 2021-05-08 17:13:51 +02:00
Michele Caini
11481a430a meta: minor changes 2021-05-08 17:13:51 +02:00
Michele Caini
e252b22735 test: code coverage 2021-05-08 17:13:51 +02:00
Michele Caini
a32ca8eb1d doc: updated doc for any/meta_any/poly 2021-05-08 17:13:50 +02:00
Michele Caini
1979a2279f poly: removed std::reference_wrapper support (incomplete, breaking change) 2021-05-08 17:13:50 +02:00
Michele Caini
1434f942dd *: make it work with VS2017 2021-05-08 17:13:50 +02:00
Michele Caini
955d325f07 meta_any: deprecated std::reference_wrapper support 2021-05-08 17:13:50 +02:00
Michele Caini
3fac3fe2d7 any: deprecate std::reference_wrapper support 2021-05-08 17:13:50 +02:00
Michele Caini
6ff217e74e meta: removed any reference to std::reference_wrapper/std::ref/std::cref 2021-05-08 17:13:50 +02:00
Michele Caini
cd667fe34b meta: make_meta_any 2021-05-08 17:13:50 +02:00
Michele Caini
3d6202ecfd any: make_any 2021-05-08 17:13:50 +02:00
Michele Caini
c40f0ef2bb type traits: is_equality_comparable support for nlohmann json like types (where T::value_type is T) - close #701 2021-05-08 10:43:27 +02:00
Michele Caini
c4b169edd1 registry: make ::remove and ::erase work also with iterators returned by views 2021-05-07 11:16:32 +02:00
Michele Caini
c6bba98828 registry: ::destroy review 2021-05-06 16:34:36 +02:00
Michele Caini
e5d4f1bb58 entity: deprecate handle::remove_all and registry::remove_all 2021-05-06 16:33:43 +02:00
Michele Caini
cf522d60ca doc: updated doc for handle 2021-05-06 10:31:43 +02:00
Michele Caini
daf72a7c61 entity: registry ::remove/::erase entity/range and safe/unsafe versions (close #486) 2021-05-04 11:36:02 +02:00
Michele Caini
f116ad0594 test: use iterators in the poly storage example 2021-05-03 22:29:39 +02:00
Michele Caini
e59d40834d any: reduce vtable options 2021-04-29 11:17:15 +02:00
Michele Caini
d06328af7f any: small review 2021-04-29 10:24:18 +02:00
Michele Caini
baa9d7d836 any: avoid invalid state from assignment operator for non-copyable types 2021-04-29 10:05:01 +02:00
Michele Caini
b030df55ee registry: clean up 2021-04-22 08:55:20 +02:00
Michele Caini
64eb8a2d0d sparse_set: ::remove returns number of actually removed elements 2021-04-22 08:42:35 +02:00
Michele Caini
7d7c36e0c7 registry: clean up ::remove_all 2021-04-21 16:50:33 +02:00
Michele Caini
9ad5768050 registry: clean up ::clear 2021-04-21 16:46:39 +02:00
Michele Caini
1cafbcff38 sparse_set: remove (and range-remove) if exists 2021-04-21 16:39:51 +02:00
Michele Caini
4bbf93fd0c sparse_set: remove -> erase 2021-04-21 15:46:02 +02:00
Michele Caini
120918bc37 any: refine the aggregate support to make any closer to its standard counterpart 2021-04-21 13:45:51 +02:00
Michele Caini
253448cffb sparse_set: suppress warnings for unused variables 2021-04-20 12:38:06 +02:00
Michele Caini
26f19fb90e storage: cleanup 2021-04-20 12:37:50 +02:00
Michele Caini
e8f982e909 view/group: raw() isn't bound to pointer types 2021-04-19 16:05:08 +02:00
Michele Caini
0fa433187e storage: valid state on component removal (allows component destructors to access pools) 2021-04-19 15:34:41 +02:00
Michele Caini
b0069299ea meta_any: avoid dereferencing C-style arrays 2021-04-15 11:45:10 +02:00
Michele Caini
375d5d3e9b doc: cleanup 2021-04-14 15:44:33 +02:00
Michele Caini
2d9398ae1a entity: handle review 2021-04-14 15:44:27 +02:00
Michele Caini
fc69e91636 test: refined custom id example 2021-04-14 15:44:17 +02:00
Michele Caini
5c56cbd672 process: dead -> finished 2021-04-13 09:02:29 +02:00
Michele Caini
a42255158d config: added error messages to ENTT_ASSERT 2021-04-13 09:02:29 +02:00
Michele Caini
f3d10a97df now working on v3.8.0 2021-04-13 09:02:26 +02:00
Michele Caini
5d15a3d69f updated single include file 2021-04-13 08:46:28 +02:00
Michele Caini
94292872dc ready to cut v3.7.1 (general quality of life improvements, no bug fixes, no new feature) 2021-04-12 23:37:53 +02:00
Michele Caini
5c8a1e7d10 type traits: removed is_std_hashable[_v] 2021-04-12 23:37:46 +02:00
Michele Caini
e98d8426bb meta: treat T(*)[N] as non-pointer-like types 2021-04-12 15:59:35 +02:00
Michele Caini
77f80cecf9 test: re-enable tests left commented by mistake 2021-04-12 15:59:31 +02:00
Michele Caini
bce26a1499 meta: remove dependency on std::array 2021-04-12 15:59:28 +02:00
Michele Caini
453f1c6edc test: std::strcmp ... 🤦‍♂️ 2021-04-12 15:59:20 +02:00
Michele Caini
9f8a36f2c9 any/meta: cleanup/better traits usage 2021-04-12 15:58:59 +02:00
Michele Caini
e6a5945463 meta_any: suppress a warning from clang 2021-04-12 15:56:01 +02:00
Michele Caini
60393fbc5f meta_any: decays Type on storage construction to handle correctly const T[N] types (close #687) 2021-04-12 15:55:59 +02:00
Michele Caini
b9a925dbd4 test: avoid regressions with any and deduced const T[N] types 2021-04-12 15:55:57 +02:00
Michele Caini
5dbdb1bcb5 any: internal support for both aggreagates and non-aggregates (qol enhancement :) 2021-04-12 15:55:55 +02:00
Michele Caini
d55cefc086 meta_any: no redundant copies, better perf 2021-04-12 15:55:53 +02:00
Michele Caini
5380e6d98b any: no redundant copies, better perf 2021-04-12 15:55:49 +02:00
Michele Caini
45cc24e0b8 any: favor aggregate initialization upon construction 2021-04-12 15:55:45 +02:00
Michele Caini
76bf1791eb test: cleanup 2021-04-12 13:02:23 +02:00
Michele Caini
7e9a4c4b16 view: initialize all data members on construction 2021-04-12 12:52:22 +02:00
Michele Caini
75cd5f169f *: review deduction guides 2021-04-12 12:48:36 +02:00
Michele Caini
10636c82a2 view/group: review extended iterable mode (close #686) 2021-04-07 10:33:52 +02:00
Michele Caini
04a6729963 build_system: minor changes 2021-04-06 16:49:11 +02:00
Michele Caini
b5617398ad doc: fixed typo 2021-04-06 16:47:20 +02:00
Michele Caini
da14641ccb meta: reduce instantiations due to meta_prop 2021-04-06 16:47:14 +02:00
Michele Caini
3997bd2396 meta: minor changes 2021-04-06 16:47:03 +02:00
Michele Caini
c876350e05 updated single include file 2021-04-02 12:04:31 +02:00
Michele Caini
1e07b981f0 build_system: manually install missing compilers 2021-04-01 14:42:10 +02:00
Michele Caini
756e909f5e *: (static) assert messages 2021-03-31 15:10:15 +02:00
Michele Caini
2404392daf meta_any: vtable review for empty/void types 2021-03-30 15:55:48 +02:00
Michele Caini
bf6576f5af any: use std::addressof to get the address of an object reliably 2021-03-30 15:27:49 +02:00
Michele Caini
158c2ab76e delegate: removed redundant calls to delegate constructors 2021-03-30 11:52:16 +02:00
Michele Caini
56fa50385e build system: minor changes 2021-03-29 23:32:35 +02:00
Michele Caini
eb05ab5fab test: code coverage 2021-03-29 23:30:13 +02:00
Michele Caini
7f87b637d5 workflow: use lcov to process codecoverage 2021-03-29 23:12:34 +02:00
Michele Caini
4b213adc75 test: cleanup 2021-03-29 19:03:10 +02:00
Michele Caini
7e7d5bbf17 registry: suppress a wrong warning from gcc 7.5 2021-03-29 19:00:09 +02:00
Michele Caini
e18c0a0c19 test: verify that dtor isn't invoked for a meta_any that wraps a reference 2021-03-29 17:01:05 +02:00
Michele Caini
02b6ffc771 build system: add ubsan to the CI 2021-03-29 12:19:52 +02:00
Michele Caini
340d66c24c build system: split build and sanitizer runs 2021-03-29 12:07:49 +02:00
Michele Caini
2cbf9d3620 build system: added poly.md to fake docs all target 2021-03-29 12:03:36 +02:00
Michele Caini
11e6793544 build system: cleanup 2021-03-29 12:00:42 +02:00
Michele Caini
d07e0336a2 test: fix ub in the tests 2021-03-29 10:28:58 +02:00
Michele Caini
7dbfb3d9ae test: code coverage (and try to please new gcov) 2021-03-29 08:23:30 +02:00
Michele Caini
02ef5db6e3 test: cleanup 2021-03-28 00:02:51 +01:00
Michele Caini
bb43bb5508 test: code coverage 2021-03-27 23:59:13 +01:00
Michele Caini
a771f083a7 process: added rejected state 2021-03-27 23:19:15 +01:00
Michele Caini
67f8bce1dd test: code coverage 2021-03-27 23:03:24 +01:00
Michele Caini
3b6dd23598 scheduler: small review for perf improvements 2021-03-27 22:48:54 +01:00
Michele Caini
66bbeae7da test: code coverage 2021-03-27 22:47:15 +01:00
Michele Caini
059334a861 test: code coverage 2021-03-27 18:14:36 +01:00
Michele Caini
f874c8309f registry: make vs2017 happy again 2021-03-26 15:35:11 +01:00
Michele Caini
27be812cc3 registry: small review of const correctness for components 2021-03-26 15:11:37 +01:00
Michele Caini
2adc2e97e1 registry: a "better" get 2021-03-26 14:49:42 +01:00
Michele Caini
dc4279a2d0 any/poly: review align parameter and default values (close #676) 2021-03-26 13:05:52 +01:00
Michele Caini
85bff4525a registry: non-const try_get doesn't create pools anymore 2021-03-26 09:38:58 +01:00
Michele Caini
bd648c0745 registry: avoid embedding asserts with return expressions 2021-03-25 11:13:50 +01:00
Michele Caini
d5e7005edd doc: minor changes to make doxygen happy 2021-03-25 09:46:06 +01:00
Michele Caini
8913c7ea18 poly: make vs2017 happy again 2021-03-24 13:53:02 +01:00
Michele Caini
0e2afe4f98 resource: remove the requirement to use shared_ptr (close #679) 2021-03-24 12:03:43 +01:00
Michele Caini
a936f7cdbe doc: added a note about configurable alignment requirements for any and poly 2021-03-24 12:03:43 +01:00
Michele Caini
44fa466618 poly: support for alignment requirements 2021-03-24 12:03:43 +01:00
Michele Caini
b05d84e8e3 test: minor changes 2021-03-24 12:03:43 +01:00
Michele Caini
7787c1ddd7 poly: redefine poly to basic_poly, introduce poly alias declaration 2021-03-24 12:03:43 +01:00
Michele Caini
52bfddd2e7 any: support for sbo storage alignment (close #676) 2021-03-24 12:03:43 +01:00
Michele Caini
f59adcdc37 test: no sbo overaligned any 2021-03-24 12:03:43 +01:00
Michele Caini
e996d3398f any: take in consideration alignment requirements for in_situ test (see #676) 2021-03-24 12:03:43 +01:00
Michele Caini
d73892d25a build system: more on pkg-config + updated README file 2021-03-18 13:48:38 +01:00
Alexandru-Sergiu Marton
1ebf614d79 build system: add pkg-config support (#674) 2021-03-18 13:48:38 +01:00
Michele Caini
f9c995f03f storage: cleanup 2021-03-18 13:47:53 +01:00
Michele Caini
2dcdd561f0 registry: minor changes 2021-03-17 16:10:00 +01:00
Michele Caini
90f97aa8d7 doc: updated try-it link (close #678) 2021-03-17 15:10:10 +01:00
Michele Caini
5a4b067cee view:
* removed view_pack and its tests
* added the possibility of combining different views
* updated documentation
2021-03-17 14:57:51 +01:00
Michele Caini
cabcc761c6 view: uniform design (prepare for chaining) 2021-03-16 17:14:20 +01:00
Michele Caini
a40ac1c46c registry: minor changes 2021-03-16 13:38:29 +01:00
Michele Caini
85ddfc4d21 test: clean up 2021-03-16 13:13:55 +01:00
Michele Caini
037a35df1d storage: removed storage category 2021-03-15 18:47:17 +01:00
Michele Caini
64c753023e doc: minor changes 2021-03-15 17:52:50 +01:00
Michele Caini
9d72ffb9fe test: minor changes 2021-03-12 13:52:46 +01:00
Michele Caini
4162d4fbc6 type_info: a more reliable operator bool 2021-03-12 09:33:42 +01:00
Michele Caini
a4d16bffd3 any: minor changes 2021-03-12 08:42:41 +01:00
Michele Caini
bcaf1489c0 meta: extended template info support 2021-03-11 12:17:48 +01:00
Michele Caini
a85712e8aa meta:
* removed has_meta_sequence_container[_v]
* removed has_meta_associative_container[_v]
2021-03-11 10:40:13 +01:00
Michele Caini
0f95d02cdc any: minor changes 2021-03-10 08:55:02 +01:00
Michele Caini
c151d55237 dispatcher: help std::is_copy_constructible to solve its problems with std::vector :) 2021-03-10 08:51:06 +01:00
Michele Caini
785cd6bc11 storage (close #675):
* stable sigh_storage_mixin::swap_and_pop
* added tests to avoid regressions
2021-03-09 16:09:19 +01:00
Michele Caini
8ec7e3cc97 test: suppress warnings for unused variables 2021-03-09 12:25:32 +01:00
Michele Caini
e376493970 test: removed unnecessary static functions 2021-03-09 12:17:00 +01:00
Michele Caini
08e2322d79 test: meta corner cases and re-registration 2021-03-09 12:11:25 +01:00
Michele Caini
2832767daa meta: updated doc 2021-03-09 12:10:55 +01:00
Michele Caini
62e12ee0aa meta: no need to check the instance in the dtor wrapper 2021-03-09 10:34:06 +01:00
Michele Caini
80e73c1089 meta:
* props no longer depend on the value type
* more tests for meta_prop
2021-03-09 10:26:21 +01:00
Michele Caini
4f93995bd7 test: suppress warnings + increase code coverage 2021-03-09 10:24:28 +01:00
Michele Caini
03c7dac92f meta: internal review to fully support re-registration 2021-03-09 09:50:48 +01:00
Michele Caini
d0b93f565a meta: prop key is returned by const reference rather than by copy 2021-03-08 15:22:25 +01:00
Michele Caini
1512fbae55 meta: safer factory, no-op re-registration 2021-03-08 14:52:46 +01:00
Michele Caini
4d91afdf9f meta: allow range-reset 2021-03-08 14:44:08 +01:00
Michele Caini
c239c3fea3 factory: avoid re-registration of data and type if already registered 2021-03-08 09:29:54 +01:00
Michele Caini
a0b431e8c4 doc: context aliased properties 2021-03-08 09:01:13 +01:00
Michele Caini
005e03aeb3 registry:
* context const correctness
* added support for aliased variables to context
* code coverage to avoid regressions
2021-03-06 22:51:01 +01:00
Michele Caini
6002d373e2 meta: factory ignores already existing unnamed meta objects 2021-03-05 11:32:32 +01:00
Michele Caini
a53066424b meta: cleanup/minor changes 2021-03-04 10:22:36 +01:00
Michele Caini
38ab02ff88 doc: minor changes 2021-03-03 16:49:20 +01:00
Michele Caini
fee0b29a0b registry: added missing template keyword (thanks msvc for accepting it anyway) 2021-03-03 14:24:38 +01:00
Michele Caini
2553695029 meta: minor changes 2021-03-03 12:26:59 +01:00
Michele Caini
301939983f registry: minor changes 2021-03-03 12:26:11 +01:00
Michele Caini
cd9ae1fbad poly: ::emplace support for reference types 2021-03-03 12:25:34 +01:00
Michele Caini
54e9bc86cc doc: updated links 2021-03-02 12:05:49 +01:00
Michele Caini
a1dd4c28c3 view: clean up 2021-03-02 11:21:40 +01:00
Michele Caini
6d3857f337 registry: clean up 2021-03-01 23:55:57 +01:00
Michele Caini
c4be3e731a poly: fwd.hpp 2021-02-28 23:29:36 +01:00
Michele Caini
ea4407b847 doc: fixed typo 2021-02-28 23:24:32 +01:00
Michele Caini
a62a83044f poly: make it work also with non-default Len 2021-02-27 17:34:09 +01:00
Michele Caini
e7e7b06744 doc: updated links 2021-02-26 14:36:20 +01:00
Michele Caini
2222e31885 config: ENTT_PAGE_SIZE sets the number of elements of a page, not the size in bytes 2021-02-25 00:18:04 +01:00
Michele Caini
c3f7f83c55 registry/view (close #660):
* const registry::view is no longer thread safe
* views are always valid when created from a registry, either const or not
* added a note to the doc about const registry and multithreading
2021-02-23 17:01:38 +01:00
Michele Caini
86e18f68c4 sparse_set: added unchecked operator[](pos) 2021-02-23 15:01:05 +01:00
Michele Caini
cc7d9e03d9 doc: updated list of similar projects 2021-02-23 14:39:37 +01:00
Michele Caini
c8639ae434 meta: minor changes 2021-02-23 12:00:59 +01:00
Michele Caini
85cf32516e view: minor changes 2021-02-22 16:52:54 +01:00
Michele Caini
bc85817b07 doc: updated doc for type_seq and the like 2021-02-22 16:39:42 +01:00
Michele Caini
1016394be5 *: minor changes 2021-02-22 16:35:36 +01:00
Michele Caini
de35cbf4af type_info: add conversion operators to underlying types (close #664) 2021-02-22 14:48:35 +01:00
Michele Caini
bb1acee36a entity:
* sparse_set: added optional user data to ::remove and ::clear
* sparse_set: remove the payload, it was really meh
* storage: review sigh_storage_mixin, simplified storage_adapter_mixin
* registry: pass itself twhen adding/patchin/removing components

test: updated tests for sparse set and poly storage
examples: added a test to avoid regressions on storage_adapter_mixin
2021-02-22 14:32:29 +01:00
Michele Caini
c6a2ed78c3 poly: add missing template keyword 2021-02-22 09:45:55 +01:00
Michele Caini
7729958082 doc: updated links 2021-02-21 16:39:29 +01:00
Michele Caini
ccdaec86b3 poly: added configurable sbo size (0 -> forced dyn) 2021-02-20 00:12:43 +01:00
Michele Caini
42afeef993 any: updated tests (sbo vs zeroed sbo size) 2021-02-19 23:46:44 +01:00
Michele Caini
3d06911886 test: code coverage (codecov is odd sometimes) 2021-02-19 16:26:55 +01:00
Michele Caini
98f929e41e any: try to get around an issue with clang only 2021-02-19 16:23:33 +01:00
Michele Caini
94d4e0231e *: suppress a few warnings + fix a call that msvc accepted by mistake 2021-02-19 16:11:19 +01:00
Michele Caini
e60cdb2e3b config: update ENTT_PAGE_SIZE 2021-02-19 15:50:09 +01:00
Michele Caini
550c021097 any: make VS happy :) 2021-02-19 14:56:39 +01:00
Michele Caini
1aec7f71b8 any: doc + test for configurable sbo 2021-02-19 14:45:26 +01:00
Michele Caini
07565927f2 any:
* added configurable sbo size (0 -> forced dyn)
* reverted changes for forced dyn vtable
2021-02-19 12:51:30 +01:00
Michele Caini
fda78ede1b any: prepare for in-place forced dynamic construction 2021-02-19 11:48:25 +01:00
Michele Caini
1249a4f8d3 any/meta_any/poly: as_ref is a member function, no longer an in-class friend function exported in the global namespace 2021-02-19 11:19:32 +01:00
Michele Caini
4e631f1536 meta_handle: deleted copy constructor (close #661) 2021-02-18 23:49:39 +01:00
Michele Caini
1757dbc225 registry: get around an issue of gcc 2021-02-16 17:12:02 +01:00
Michele Caini
8149e204d2 *: refine code that msvc accepts by mistake (🤦‍♂️) 2021-02-16 15:55:45 +01:00
Michele Caini
412f2ef63e doc: updated/reviewed 2021-02-16 15:08:34 +01:00
Michele Caini
ea33673daa registry: faster, better ::clear 2021-02-16 14:53:33 +01:00
Michele Caini
169b816613 entity:
* sparse_set: stable virtual remove
* basic_storage: fake get for empty types,
* sigh_storage_mixin: use swap_and_pop, drop ::remove, ignore emptiness
* poly_storage: ::remove is no longer part of its interface by default
2021-02-16 14:46:42 +01:00
Michele Caini
48edf077fc sigh_storage_mixin:
* Owner as template parameter (to make it reusable in other contexts)
* Use storage payload for retrieving the owner from the storage
2021-02-16 10:44:03 +01:00
Michele Caini
91db153710 registry: rebind pools from move constructor/assignment operator 2021-02-15 18:11:02 +01:00
Michele Caini
ea1f010b1a sparse_set/storage: swap_at and swap_and_pop are protected and non-final 2021-02-15 15:57:17 +01:00
Michele Caini
935a852745 storage:
* Removed storage_adapter_mixin (intermediate step towards the owner-as-payload model)
* The class sigh_storage_mixin expects a plain storage as a base class (intermediate step towards the owner-as-payload model)
* Further reduced the number of instantiations
* All storage classes must expose a ::patch function
2021-02-15 15:56:27 +01:00
Michele Caini
0eb6d7de3c sparse_set: added opaque payload (mainly meant to attach owners for augmented storage mixins) 2021-02-15 15:15:41 +01:00
Michele Caini
3118cd4fa5 sparse_set: added ::at to get the entity at a given position, if any 2021-02-15 14:56:18 +01:00
Michele Caini
18832fcb37 core: make type_id [[nodiscard]] (see #658) 2021-02-14 11:04:12 +01:00
Michele Caini
612554f6af registry: minor changes 2021-02-12 18:18:39 +01:00
Michele Caini
1c794591b9 sparse_set: review sort_n 2021-02-12 15:47:52 +01:00
Michele Caini
a8d95b284d meta: general renaming, size -> arity when it returns the arity of a function 2021-02-12 11:05:07 +01:00
Michele Caini
772c2dba2f type traits: add is_std_hashable[_v] (see #629) 2021-02-11 11:57:55 +01:00
Kartik Saranathan
9d1a210c97 core: PS4 build fix for entt::any (#657)
PS4 headers doesn't define __cpp_lib_launder which fails to compile with -Werror
2021-02-11 10:16:28 +01:00
Michele Caini
b04b966db1 meta:
* updated meta_any::operator== to make it consistent across boundaries
* constness review for meta_type_node
2021-02-10 15:57:20 +01:00
Michele Caini
e2c61d90e9 meta: use meta_node internally to generate template_info 2021-02-09 18:27:40 +01:00
Michele Caini
d50655c4f7 test: suppress a couple of shadow warnings 2021-02-09 18:20:42 +01:00
Michele Caini
5e4c63736b meta: added minimal class template support to meta_type 2021-02-09 17:18:24 +01:00
Michele Caini
b90b71c8c0 meta: support for proxy pointers 2021-02-09 10:57:50 +01:00
Michele Caini
722033e906 meta: split node.hpp and meta.hpp 2021-02-09 09:59:51 +01:00
Michele Caini
b6ec91fcd0 doc: updated links, removed broken one 2021-02-09 08:17:49 +01:00
Michele Caini
e94c0d003a any/registry:
* copying an entt::any always returns a copy of the contained object
* registry::storage returns references (eventually const) to the poly storage
2021-02-08 11:46:22 +01:00
Michele Caini
5c46ccb37e meta:
* avoid copies from meta_type::invoke (small perf improvement)
* meta_handle::operator* no longer available
* added meta_handle::operator bool
2021-02-08 11:33:53 +01:00
Michele Caini
fd989feea3 any: review copy, prepare for #652 2021-02-06 23:22:32 +01:00
Michele Caini
1b53e83dde any: minor changes 2021-02-06 18:35:08 +01:00
Michele Caini
3ebe827b51 doc: minor changes 2021-02-05 11:10:04 +01:00
Michele Caini
b8266e1169 registry: minor changes 2021-02-04 16:12:06 +01:00
Michele Caini
4efbe24607 test: minor changes (code coverage) 2021-02-04 12:14:35 +01:00
Michele Caini
e96ac1f6ff handle: rename ::has/::any to ::all_of/any_of 2021-02-04 12:03:38 +01:00
Michele Caini
14915368c7 test: avoid some ASSERT_DEATH that don't trigger in release mode 2021-02-04 11:50:52 +01:00
Michele Caini
0ff5c18743 registry: rename ::any to ::any_of 2021-02-04 09:45:11 +01:00
Michele Caini
240814cc85 registry: rename ::has to ::all_of 2021-02-04 09:36:28 +01:00
Michele Caini
1912350cc6 registry: use entt::any to store context variables 2021-02-04 09:21:27 +01:00
Michele Caini
146faa6008 doc: updated links 2021-02-04 08:20:03 +01:00
Michele Caini
e5fa67850b sparse_set/registry: avoids UB with sparse_set::clear and component-less registry::clear 2021-02-03 16:18:25 +01:00
Michele Caini
1377b51341 doc: minor changes 2021-02-03 13:07:39 +01:00
Ευάριστος
db67fb3539 build system: delete @bazel_tools//src/conditions:windows_msys. (#649)
This condition is no longer available from Bazel 4.0.0.
2021-02-03 10:08:38 +01:00
Michele Caini
6d216406f3 registry: minor changes 2021-02-03 10:04:16 +01:00
Michele Caini
ab225eaec1 registry: updated precondition of ::assign 2021-02-02 23:37:09 +01:00
Michele Caini
4d6d9e567d registry: minor changes 2021-02-02 13:53:51 +01:00
Michele Caini
0fcf0142ba sparse_set: prepare for detached pools 2021-02-02 12:59:07 +01:00
Michele Caini
ab907e4fef updated README 2021-02-01 10:04:54 +01:00
Michele Caini
1c1c3eb271 meta: added support to self pointer in meta_any 2021-01-29 22:13:31 +01:00
Michele Caini
a03a569534 meta: support for std::vector<bool> and the like 2021-01-29 18:58:18 +01:00
Michele Caini
309fb0fa83 test: updated storage poly example (close #644) 2021-01-29 11:10:01 +01:00
Michele Caini
14c1431848 doc: fixed typo (close #646) 2021-01-29 10:06:22 +01:00
Michele Caini
c3dc32415b meta: make meta utility public and freely available to users 2021-01-28 12:19:02 +01:00
Michele Caini
44d6246278 doc: fixed typo 2021-01-28 12:18:33 +01:00
Michele Caini
5bbd7e03f9 meta: prepare to make internal utilities public 2021-01-27 16:47:01 +01:00
Michele Caini
f5f463b411 any: relaxed checks/constraints 2021-01-26 16:45:02 +01:00
Michele Caini
6eaefbe25c doc: update doc of the runtime reflection system (close #641) 2021-01-26 08:41:41 +01:00
Michele Caini
4b5c2c85a5 doc: updated inline doc (close #640) 2021-01-26 08:36:56 +01:00
Michele Caini
0f951cd322 test: suppress a warning due to an unused variable 2021-01-25 15:22:46 +01:00
Michele Caini
cf0da32fd0 meta: iterators of meta associative containers return keys by const reference rather than by copy 2021-01-25 15:12:59 +01:00
Michele Caini
5a3085c42b registry: removed data<T> and raw<T> (use view<T>::data/::raw instead) 2021-01-25 12:29:22 +01:00
Michele Caini
42cc480bf5 doc: updated links and TODO file 2021-01-23 18:39:08 +01:00
Michele Caini
2822eda858 poly: added ::reset 2021-01-23 18:22:15 +01:00
Michele Caini
6c804b5ca2 meta: added meta_any::reset 2021-01-23 18:19:11 +01:00
Michele Caini
5149d1395e any: minor changes 2021-01-23 18:18:54 +01:00
Michele Caini
f75a2dab8d any (meta/poly): make T& in place construction work with references rather than pointers 2021-01-23 18:09:41 +01:00
Michele Caini
a045c88c61 any: added ::reset 2021-01-23 18:04:03 +01:00
Michele Caini
a5fdf917df test: minor changes (code coverage) 2021-01-22 20:13:15 +01:00
Michele Caini
80a0e47f1a core: more tests for hashed_string (code coverage) 2021-01-22 15:39:03 +01:00
Michele Caini
a304313ad4 any: more tests for the support to not copyable types (code coverage) 2021-01-22 15:28:24 +01:00
Michele Caini
05b1d5a4da meta: more tests for entt::resolve (code coverage) 2021-01-22 15:22:36 +01:00
Michele Caini
edeef3541c meta: tests (code coverage) for meta_ctor (implicitly generated default constructor) 2021-01-22 15:20:03 +01:00
Michele Caini
cd929d8e65 meta: review + tests (code coverage) for implicitly generated default constructors 2021-01-22 15:17:58 +01:00
Michele Caini
b005971427 doc: removed broken badge 2021-01-22 15:17:19 +01:00
Michele Caini
c35614fb63 meta: more tests for meta pointers (code coverage) 2021-01-22 15:08:45 +01:00
Michele Caini
18e16b09f2 any: more tests (code coverage) 2021-01-22 14:57:50 +01:00
Michele Caini
b18b76c1f0 meta: as_ref_t adapts to const objects/const-ref return types 2021-01-22 11:41:17 +01:00
Michele Caini
c9f65267ba meta: factory getter, better is_invocable_v test 2021-01-22 09:17:37 +01:00
Michele Caini
cce52c673b view: use get_as_tuple internally 2021-01-22 09:17:00 +01:00
Michele Caini
fdde216f0e doc: minor changes 2021-01-21 10:32:25 +01:00
Michele Caini
d1901a97d1 doc: minor changes 2021-01-21 09:59:43 +01:00
Michele Caini
eb2077b95b meta: suppress warnings 2021-01-20 19:51:59 +01:00
Michele Caini
fad3bdeed4 meta: ::reset doesn't remove the implicitly generated default constructors 2021-01-20 15:29:35 +01:00
Michele Caini
e1a537e547 doc: minor changes 2021-01-20 15:20:51 +01:00
Michele Caini
ba098e1199 any: use actual constructors to be more like std::any 2021-01-15 17:24:10 +01:00
Michele Caini
0ec755fccf meta: iterable base types as instances of meta_type 2021-01-15 14:34:27 +01:00
Michele Caini
997dd433b3 doc: type list and value list 2021-01-15 11:04:06 +01:00
Michele Caini
4aea1567db type_traits: make is_equality_comparable work with all major compilers 2021-01-15 10:37:14 +01:00
Michele Caini
446c8df3b4 type_traits: added type_list_diff[_t] 2021-01-15 08:36:22 +01:00
Michele Caini
f4bd868d6a type_traits: is_equality_comparable, support for standard containers 2021-01-14 12:56:31 +01:00
Michele Caini
8490264af3 doc: updated list for similar projects 2021-01-13 15:21:01 +01:00
Michele Caini
505cfdd193 any: detect C-style arrays and use delete[] when needed 2021-01-13 13:30:10 +01:00
Michele Caini
39ecd1545c meta: support for dereferencing pointers to functions 2021-01-13 13:14:21 +01:00
Michele Caini
9b80c0028d meta:
* implicitly generated default constructor (overridable)
* pointer-like to void support (no dereference)
2021-01-13 11:53:15 +01:00
Michele Caini
35276b55af any: support for non-copyable types 2021-01-12 16:24:18 +01:00
Michele Caini
eb63dd6227 meta: merged internal.hpp with meta.hpp 2021-01-11 15:08:44 +01:00
Michele Caini
9f24b3c584 meta: minor changes 2021-01-11 14:58:50 +01:00
Michele Caini
53e951d96d meta: removed internal::meta_range 2021-01-11 12:31:55 +01:00
Michele Caini
17dd386937 meta_any: minor changes 2021-01-11 11:53:06 +01:00
Michele Caini
3eb00382e7 meta: removed meta_base, meta_base_node is used internally when needed 2021-01-11 10:46:51 +01:00
Michele Caini
98b5f7a26a meta: removed meta_conv, meta_conv_node is used internally when needed 2021-01-11 10:34:30 +01:00
Michele Caini
fb70ec1cb0 doc: minor changes 2021-01-11 09:46:47 +01:00
Michele Caini
47ada87ba2 now working on version 3.7.0 2021-01-09 17:15:42 +01:00
Michele Caini
7a949dd328 updated single include file 2021-01-09 16:45:27 +01:00
Michele Caini
3982217b67 Update README.md 2021-01-08 11:59:08 +01:00
Michele Caini
8cb61da9c2 *: minor changes 2021-01-08 11:43:26 +01:00
Michele Caini
375c780d3b doc: updated links (close #630) 2021-01-07 09:23:09 +01:00
Michele Caini
f3b6c2ce5d doc: updated links (close #628) 2021-01-06 14:41:27 +01:00
Michele Caini
a7a2c96382 registry: added ::reserve_pools 2021-01-05 09:35:41 +01:00
Michele Caini
99336ef746 doc: dark mode friendly header 2021-01-04 16:33:26 +01:00
Michele Caini
72d2adfe1c *: updated copyright 2021-01-04 14:09:53 +01:00
Michele Caini
707574e294 meta: avoid warnings for unused variables 2021-01-04 12:25:55 +01:00
Michele Caini
18ffbd0027 registry: group -> group_if_exists (close #626) 2021-01-04 08:34:56 +01:00
reworks
68a0e4f39a doc: update links.md (#627) 2021-01-03 16:35:16 +01:00
Michele Caini
ddb99ced34 storage: storage type check 2021-01-02 16:42:49 +01:00
Michele Caini
cb2782bc71 registry: ::remove requires at least a component now (close #623) 2021-01-01 23:55:13 +01:00
Alex Perry
52cade9267 doc: fixed missing prefix "L" (#622) 2021-01-01 23:46:24 +01:00
Michele Caini
ec600eb2f4 any: use feature tests to get around an issue with clang 6.0.0 2020-12-31 11:40:08 +01:00
Michele Caini
61e96e2dab *: get around an issue with entt::integral_constant on (very) old compilers 2020-12-30 18:04:57 +01:00
Michele Caini
9f5433053d poly: minor changes 2020-12-30 17:18:43 +01:00
Michele Caini
d2489a57b7 doc: updated links 2020-12-30 13:12:54 +01:00
Michele Caini
e5841cd467 poly: suppress warnings for unused variables 2020-12-29 18:15:33 +01:00
Michele Caini
820d52428f doc: updated references 2020-12-29 16:51:38 +01:00
Michele Caini
ae6931b046 any: avoid unreachable code 2020-12-28 16:14:05 +01:00
Michele Caini
90a97b90bb doc: minor changes 2020-12-28 16:07:36 +01:00
Michele Caini
4b38d81f00 algorithm: use plain for rather than for_each 2020-12-27 23:07:37 +01:00
Michele Caini
8c27ca9e36 *: suppress some warnings (see #620) 2020-12-27 00:12:28 +01:00
Michele Caini
4b89fc390d poly: renaming to avoid conflicts with libraries that redefine words randomly (close #615) 2020-12-26 17:00:51 +01:00
Michele Caini
29c1766714 registry: const poly storage function 2020-12-24 16:48:07 +01:00
Michele Caini
2e5a9f117c *: cleanup 2020-12-23 19:09:31 +01:00
Michele Caini
2abcbcd30f meta: support for pointer-like types with a custom dereference operator other than operator* 2020-12-23 19:00:05 +01:00
Michele Caini
ac8bde4ea8 doc: get around an issue with doxygen 2020-12-23 17:31:08 +01:00
Michele Caini
78a13efc6c any: minor changes 2020-12-23 12:28:07 +01:00
Michele Caini
c99e859978 meta: container traits not required for const T 2020-12-23 12:27:46 +01:00
Michele Caini
ed448cb99f doc: filled some todos here and there 2020-12-23 11:30:43 +01:00
Michele Caini
5d472a1f2e test: suppress warnings 2020-12-23 09:42:40 +01:00
Michele Caini
92a938db0e meta: reduced instantiations from meta iterators 2020-12-23 09:42:38 +01:00
Michele Caini
aa979b2046 any/meta:
* added alias constructor to any
* added alias constructor to meta_any
* added alias constructor to poly
* added support for const containers, const deref operator and const views to meta_any
2020-12-23 09:42:36 +01:00
Michele Caini
2daaf899d3 any: comparison functions (==, !=) 2020-12-23 09:42:33 +01:00
Michele Caini
fa4c6bccbc meta_any: make ref to pointer-like types work in all cases 2020-12-23 09:42:31 +01:00
Michele Caini
bedea4b11a *: added error messages to static asserts 2020-12-23 09:42:29 +01:00
Michele Caini
bc415242f2 test:
* support for pointer-like to const
* internal meta_range coverage
* fully tested meta_handle
* references as arguments for meta_ctor
* invoke const function on const reference for meta_func
* references as arguments for meta_func
* as_cref_t return type for meta_func
* setter and getter on const reference for meta_data
* as_cref_t getter for meta_data
* set by const and non-const reference for meta_data
* const invoke for meta_any
* const get for meta_any
* aob
2020-12-23 09:42:26 +01:00
Michele Caini
2eeb7552d6 test:
* more on any const and non-const reference support
* poly support for const and non-const references
* poly as_ref overloads
2020-12-23 09:42:24 +01:00
Michele Caini
3a6ecb10a7 meta_sequence_container: extended support for const iterators 2020-12-23 09:42:22 +01:00
Michele Caini
f55004d1e4 test: any::as_ref for const references 2020-12-23 09:42:19 +01:00
Michele Caini
1a3304a886 meta_any:
* set is necessarily non-const
* added non-const overloads for get and invoke
2020-12-23 09:42:17 +01:00
Michele Caini
58bcbe75b7 meta: minor changes 2020-12-23 09:42:14 +01:00
Michele Caini
753df6decf poly: updated doc (const references) 2020-12-23 09:42:11 +01:00
Michele Caini
c32f947c18 meta:
* support for pointers to const types
* use std::reference_wrapper instead of std::ref to let pass constness
2020-12-23 09:42:09 +01:00
Michele Caini
6123e4ac8a any/meta/poly: as_ref const and non-const overloads 2020-12-23 09:42:07 +01:00
Michele Caini
c52f16f5b8 meta:
* meta_any: convert -> allow_cast
* support for const references
* as_cref_t policy
2020-12-23 09:42:04 +01:00
Michele Caini
3dac65a012 *: minor changes 2020-12-23 09:42:01 +01:00
Michele Caini
bc089bc4c1 any_cast: review any_cast for better support to const references 2020-12-23 09:41:58 +01:00
Michele Caini
1075ded4dc test: minor changes 2020-12-23 09:41:55 +01:00
Michele Caini
5578ea2f30 meta_any: added support for const references, reviewed meta_any::cast (T vs T &) 2020-12-23 09:41:52 +01:00
Michele Caini
ade3e58829 any: added support to const references 2020-12-23 09:41:49 +01:00
Michele Caini
ee2e88476c any: instance type is now const void * instead of void * 2020-12-23 09:41:44 +01:00
Michele Caini
1726e983ad doc: added Minecraft Earth to the list :) 2020-12-23 09:38:27 +01:00
Michele Caini
44341f0bcc doc: cleaned up example in the README 2020-12-21 13:44:50 +01:00
Michele Caini
366da3d0fe type_info: use remove_cv_t rather than remove_const_t 2020-12-17 10:17:31 +01:00
Michele Caini
f7fa2f605b poly: minor changes 2020-12-17 10:17:23 +01:00
Michele Caini
6854dea47e delegate: use type_list rather than tuple internally 2020-12-17 10:17:11 +01:00
Michele Caini
9d7e1cd99d registry: use type_list rather than tuple internally 2020-12-17 10:17:04 +01:00
Michele Caini
330f3dff77 core: updated ident, removed dependency on <tuple> 2020-12-17 10:16:54 +01:00
Michele Caini
073c46e7bf any: const void * return type for the fake vtable 2020-12-17 10:14:43 +01:00
Michele Caini
9950b2ea34 type_traits: added type_list_element[_t] and value_list_element[_v] 2020-12-17 10:13:02 +01:00
Michele Caini
a7c2a5c49b doc: updated links 2020-12-17 10:12:47 +01:00
Michele Caini
c2c39cd0d0 doc: suppress a warning from doxygen 2020-12-14 11:19:04 +01:00
Michele Caini
b6e7c36b11 delegate: use constness_as_t internally 2020-12-14 11:17:24 +01:00
Michele Caini
002f92fe1e organizer: fixed an issue for free functions with payload (close #613) 2020-12-14 11:17:10 +01:00
Michele Caini
d6d0cdf9aa build system: avoid enabling tests by default when EnTT is the top dir project 2020-12-14 08:43:23 +01:00
Martin Stump
7d002df94f build system: add MAIN_PROJECT check for test option (#610)
* Add MAIN_PROJECT check for test option
* Set MAIN_PROJECT=OFF initially
2020-12-14 08:43:18 +01:00
Michele Caini
f0d7408f94 doc: minor changes 2020-12-13 23:52:16 +01:00
Keith Rosenberg
7154678347 doc: mention aggregate initialization usage in registry::emplace, refs #592 (#593)
* update example to explain aggregate initialization usage, refs #592
* cleanup example; add details about parameterized constructors and aggregate initialization

Co-authored-by: kthrose <kthrose@netpoetica.com>
2020-12-13 23:29:01 +01:00
Fahmi Akbar Wildana
68f0743c40 doc: add @javelin/ecs in references.md (#611) 2020-12-13 23:26:22 +01:00
Michele Caini
3d5905c878 doc: added more details 2020-12-12 16:39:45 +01:00
Michele Caini
a344a1ca59 doc: typo 2020-12-12 15:37:11 +01:00
Michele Caini
5f539ddfb7 doc: updated documentation (core, entity, poly) 2020-12-12 15:13:46 +01:00
Michele Caini
a974235d10 core/entity/meta/poly:
* updated poly (static vtable, design review)
* .ref -> as_ref (any, meta_any, poly)
* poly storage
2020-12-12 15:09:29 +01:00
Michele Caini
2d17ef5c7e meta: removed as_ref tag 2020-12-12 14:58:31 +01:00
Michele Caini
dda8c209df type_traits: added type_identity trait (waiting for C++20) 2020-12-12 14:55:30 +01:00
Michele Caini
be88d5dfb8 type_info: minor changes 2020-12-12 14:51:41 +01:00
Michele Caini
4a537d82d3 minor changes 2020-12-08 19:38:31 +01:00
Michele Caini
6f36723097 runtime_view: public constructor (close #597) 2020-12-06 15:37:51 +01:00
Michele Caini
35bce924f8 handle: added support for destroy (close #598) 2020-12-03 12:17:49 +01:00
Michele Caini
9356e8ccb5 config: reintroduce ENTT_DISABLE_ASSERT (close #599) 2020-12-03 11:18:27 +01:00
Michele Caini
1ffde24ef6 *: updated TODO 2020-12-03 10:55:08 +01:00
Michele Caini
2f52bef882 poly: first implementation 2020-12-02 15:49:40 +01:00
Michele Caini
b1369582e1 type_traits: added value_list 2020-12-02 15:49:05 +01:00
Michele Caini
cf176719a8 *: minor changes here and there 2020-12-02 15:48:36 +01:00
Michele Caini
d7ed72ac06 meta_any: single vtable function to reduce instantiations and storage requirements 2020-12-02 11:10:04 +01:00
Michele Caini
83322664f1 any: doc + more tests 2020-12-02 11:10:04 +01:00
Michele Caini
5af7e96f70 meta/*: removed meta_storage, meta_any uses any internally 2020-12-02 11:10:04 +01:00
Michele Caini
c95041d7c3 core: standalone any class 2020-12-02 11:10:04 +01:00
Michele Caini
62f40dcb21 meta_storage: internal review for better memory usage 2020-12-02 11:10:04 +01:00
Michele Caini
b4f88e303a meta_storage: branchless implementation 2020-12-02 11:10:04 +01:00
Michele Caini
cd0ec69446 meta: reduced instantiations due to meta any, use a fake vtable function 2020-12-02 11:10:04 +01:00
Michele Caini
909415d167 organizer: bug fixing/tests (thanks to @Green-Sky) 2020-12-02 11:09:52 +01:00
Michele Caini
337bc6d97a view_pack: support for multiple views of the same type 2020-12-02 11:09:51 +01:00
Michele Caini
6c9fab7da1 type_traits: minor changes 2020-12-02 11:09:51 +01:00
Michele Caini
315b1f5913 type traits: added is_complete[_v] 2020-12-02 11:09:51 +01:00
Michele Caini
c2d1859858 emitter: truly const emitter, no lazy initialization 2020-12-02 11:09:51 +01:00
Michele Caini
37ba7316e0 doc: fixed typo 2020-12-02 11:09:51 +01:00
Michele Caini
fc1292b1d1 test: get around the best bug ever of msvc, toolset v141 2020-12-02 11:09:51 +01:00
Michele Caini
0507680cc1 view/group: try to get around an issue of gcc v7.5 + suppress some warnings here and there 2020-12-02 11:09:51 +01:00
Michele Caini
60475d3354 view/group: safe invalid views/groups (close #470) 2020-12-02 11:09:51 +01:00
Michele Caini
b1cd794b2c registry: truly const registry 2020-12-02 11:09:51 +01:00
Michele Caini
cd98ecff88 view: default constructible views 2020-12-02 11:09:51 +01:00
Michele Caini
f8ec4027ee group: default constructible groups 2020-12-02 11:09:51 +01:00
Michele Caini
d980a5cf44 build system: use asan on the CI 2020-12-02 11:05:00 +01:00
Michele Caini
761604d044 config: favor detection of clang over that of msvc, otherwise clang-cl will fail 2020-12-02 11:04:21 +01:00
Michele Caini
0f4161f616 build system: added older compiler versions to the CI 2020-12-02 10:46:05 +01:00
Michele Caini
4a668c97a3 type_info: get around a nasty bug of clang < 9 when using libstdc++ 2020-12-02 10:45:41 +01:00
Michele Caini
9d687c25b3 storage: safe self-move to support standard containers (close #601) 2020-12-01 22:59:14 +01:00
Michele Caini
0b73082aa0 build system: minor changes to make it work again with the CI 2020-11-20 17:05:20 +01:00
Gnik
085e1ae157 build system: prefix cmake variables with ENTT_. (#585) 2020-11-20 16:30:22 +01:00
Tom Yaxley
7c0db3203b meta: allow checking meta_any for nullptr (#591) 2020-11-20 09:43:39 +01:00
Michele Caini
bc987ed03f *: force add the version to the single include file 2020-11-20 09:43:36 +01:00
Michele Caini
57e1bf3afd doc: fixed typo 2020-11-20 09:43:34 +01:00
Michele Caini
90606bd410 hashed_string: literals are now enclosed within entt::literals, ENTT_HS_SUFFIX and ENTT_HWS_SUFFIX no longer exist (close #590) 2020-11-20 09:43:28 +01:00
Michele Caini
9744a3745c doc: updated references 2020-11-20 09:43:21 +01:00
Zoltán Kurucz
14e051f970 Fixed const, non-const types section intro in entity.md (#589) 2020-11-14 16:49:11 +01:00
Michele Caini
2396c9b6da snapshot: avoid setting the wrong version for entities during a restore (close #588) 2020-11-14 16:48:11 +01:00
Michele Caini
c386a9d140 runtime_view: removed ::empty, misleading information (breaking change) 2020-11-11 17:03:48 +01:00
Michele Caini
12847593c2 runtime_view: size -> size_hint, misleading name (breaking change) 2020-11-11 17:03:44 +01:00
Michele Caini
6cfa024ea2 doc: small changes 2020-11-11 13:15:46 +01:00
Michele Caini
4b43d99660 group: removed/reduced scope for ::raw, misleading information (breaking change) 2020-11-11 13:15:44 +01:00
Michele Caini
c1bfc29e7f group: removed ::data<T>, misleading information (breaking change) 2020-11-11 13:15:42 +01:00
Michele Caini
7e91e27f14 group: removed ::empty<T...>, misleading information (breaking change) 2020-11-11 13:15:39 +01:00
Michele Caini
f8015036a9 group: removed ::size<T>, misleading information (breaking change) 2020-11-11 13:15:37 +01:00
Michele Caini
b7ef1607dc view: public constructors and deduction guides 2020-11-09 10:31:51 +01:00
Michele Caini
b93a31dd5b helper: removed Const template parameter, used the same model of the handle class (const/non-const entity) 2020-11-08 23:34:32 +01:00
Michele Caini
fa09964f10 storage: a better iterator 2020-11-08 23:03:27 +01:00
Michele Caini
0038728be3 storage: removed const T specialization for storage_traits 2020-11-08 01:06:06 +01:00
Michele Caini
ec56651959 doc: fixed typo in core.md 2020-11-08 00:58:48 +01:00
Michele Caini
8259371d6a handle: minor changes 2020-11-08 00:46:34 +01:00
Michele Caini
d8623991c0 constness_as: updated doc 2020-11-08 00:46:03 +01:00
Michele Caini
0c205431b0 doc: updated documentation for the core classes 2020-11-08 00:37:06 +01:00
Michele Caini
58dbaf4a51 type_traits: added constness_as[_t] 2020-11-08 00:36:41 +01:00
Michele Caini
3b50ebae83 delegate: updated doc 2020-11-07 23:55:53 +01:00
Michele Caini
8b895eff7a *: minor changes to get around some nasty bugs of compilers 2020-11-06 17:29:48 +01:00
Michele Caini
70af0365bf entity:*: removed broken references to the old actor class 2020-11-06 15:00:01 +01:00
Michele Caini
bb3e3bfa1f meta: containers traits are no longer internal details only 2020-11-06 14:58:22 +01:00
Michele Caini
54aa98a752 entity/*: remove the requirement for get_as_tuple from storage classes 2020-11-06 14:49:39 +01:00
Michele Caini
3bff0aa1ea sigh_storage_mixin: don't use get_as_tuple anymore 2020-11-06 12:37:10 +01:00
Michele Caini
b012231635 registry: don't use get_as_tuple and assume that users know what they are doing 2020-11-06 11:32:39 +01:00
Michele Caini
6c6f05fc91 snapshot: cleanup 2020-11-06 11:21:46 +01:00
Michele Caini
3338d5e105 storage_traits: small review 2020-11-06 11:20:10 +01:00
Michele Caini
390ec2f0c1 entity/*: merged storage.hpp and pool.hpp 2020-11-05 18:53:22 +01:00
Michele Caini
4ebdf7a6e8 pool: pool_traits/pool_t -> storage_traits/storage_t 2020-11-05 18:48:52 +01:00
Michele Caini
6f1366dbb5 entity/*: use pool introspection rather than is_empty for filtering 2020-11-05 17:23:39 +01:00
Michele Caini
503791d3c0 view: removed chunked iteration, no real benefits so far and there is no way to make it consistent across all views in future 2020-11-05 15:10:23 +01:00
Michele Caini
902dc49de2 storage: added .get_as_tuple(entity) 2020-11-05 14:29:45 +01:00
Michele Caini
2d299f31e5 storage: removed the requirement to expose try_get 2020-11-05 12:55:34 +01:00
Michele Caini
df298587b8 type_info: suppress warnings for uninitialized members 2020-11-05 12:46:24 +01:00
Michele Caini
b9c33008d8 sparse_set: faster remove/range-remove 2020-11-05 12:21:42 +01:00
Michele Caini
ca97f1c4a3 test: oops, re-enable all bench 2020-11-05 11:10:33 +01:00
Michele Caini
effed56653 sparse_set: a better swap 2020-11-05 10:00:00 +01:00
Michele Caini
7b501aa89b sparse_set/storage: virtual sort 2020-11-04 23:52:48 +01:00
Michele Caini
6c0d0d465b storage: minor changes 2020-11-04 17:19:40 +01:00
Michele Caini
a52bd20912 registry: minor changes 2020-11-04 17:05:22 +01:00
Michele Caini
aabcc445ee *: minor changes 2020-11-04 16:59:35 +01:00
Michele Caini
d491e504cc type_info: small review 2020-11-04 10:49:30 +01:00
Michele Caini
3142e430e7 hashed_string: constexpr ::value suitable for uses with string views 2020-11-04 10:48:40 +01:00
Michele Caini
b784d80a50 pool: minor changes 2020-11-04 00:08:04 +01:00
Michele Caini
7344654308 doc: cleanup 2020-11-03 23:24:59 +01:00
Michele Caini
e01b35c39c config: update default page size 2020-11-03 00:45:46 +01:00
Michele Caini
b8b2c4ee73 handle: get around an issue of VS, toolkit v141 2020-11-03 00:45:24 +01:00
Michele Caini
8cd1ce97f7 handle: it's now possible to convert a handle to a handle view and a handle view to a more restricted one (see #583) 2020-11-03 00:36:11 +01:00
Michele Caini
05b514b743 Revert "entity: minor changes"
This reverts commit af69a0a1fd.
2020-11-02 14:05:07 +01:00
Michele Caini
22596e0f5b entity: added handle_view (close #583) 2020-11-02 13:05:38 +01:00
Michele Caini
e7031794df registry: suppress some warnings (close #582) 2020-11-01 21:49:09 +01:00
Michele Caini
af69a0a1fd entity: minor changes 2020-11-01 00:29:04 +01:00
Michele Caini
52fa690764 view: added use<T> to set explicitly the type that should drive all iterations in a multi type view 2020-10-29 00:03:26 +01:00
Michele Caini
4ad411e320 traits: is_eto_eligible[_v] -> is_empty[_v], internal version 2020-10-28 22:58:26 +01:00
Michele Caini
09da190e93 entity/*: rollback erase -> remove (no longer a breaking change :) 2020-10-28 16:24:44 +01:00
Michele Caini
797dd56bb7 test: removed temporary multi storage example, added a note to the todo list for a refined example 2020-10-28 16:16:52 +01:00
Michele Caini
5e1d77fcd5 doc: updated documentation for registry remove/erase 2020-10-28 13:03:15 +01:00
Michele Caini
2820f2658b entity/: differentiate between remove and erase to avoid name clashing on the custom path (breaking changes) 2020-10-28 12:21:35 +01:00
Michele Caini
f3fc32660b *: updated TODO 2020-10-28 08:43:43 +01:00
Michele Caini
2d4b00ec24 registry: added ::destroyed, made ::assign much faster (breaking changes, close #522) 2020-10-27 23:01:28 +01:00
Michele Caini
86808f5035 doc: minor changes 2020-10-27 09:06:18 +01:00
Michele Caini
82946e2372 pool: storage_adapter -> storage_adapter_mixin 2020-10-27 00:09:32 +01:00
Michele Caini
22d117a397 doc: fixed typo (close #578) 2020-10-26 22:35:49 +01:00
Michele Caini
662cfc9fdc *: cleanup 2020-10-26 15:41:54 +01:00
Michele Caini
a3e73909cf group/view/view_pack: review 2020-10-26 15:31:00 +01:00
Michele Caini
95bafc8ced *: try to get around an issue of gcc v7.5 2020-10-26 15:29:58 +01:00
Michele Caini
05f1906f77 *: get around an issue with clang 2020-10-26 12:43:55 +01:00
Michele Caini
dbbb131424 view_pack: added more functionalities 2020-10-26 12:38:45 +01:00
Michele Caini
fc7ec35242 doc/test: minor changes 2020-10-26 12:29:45 +01:00
Michele Caini
7ac10472dc view/group: small review 2020-10-26 10:50:17 +01:00
Michele Caini
d255889c5c group: added reverse iterators, rbegin and rend to iterable groups 2020-10-26 08:55:17 +01:00
Michele Caini
7662da22fc view: added reverse iterators, rbegin and rend to iterable views 2020-10-25 23:19:56 +01:00
Michele Caini
64cc200df0 test: code coverage 2020-10-25 15:13:13 +01:00
Michele Caini
63c983683c meta: avoid shadow warnings 2020-10-25 15:13:13 +01:00
Michele Caini
92f79c99f7 meta: review overloaded meta functions 2020-10-25 15:13:13 +01:00
Innokentiy Alaytsev
24f937fe4f [meta] Meta-function overload support (#538)
Now meta-functions can be overloaded. When a function with a duplicate
identifier is registered, it's added into the meta-type function list after the
first meta-function with the same id. During the invocation, the meta-functions
with the requested id are iterated, and the best matching one is chosen. The
overload that doesn't require any type conversions or the minimal number of
those is considered the best match. If none of the overloads matches the given
arguments or if there are multiple matching overloads requiring the same number
of type casts then the invocation will fail the same way it happens in C++.

Signed-off-by: Innokentiy Alaytsev <alaitsev@gmail.com>
2020-10-25 15:13:13 +01:00
Michele Caini
47bb682890 doc: updated links 2020-10-23 21:16:38 +02:00
codylico
9ab674ef9a doc: add a note on registry::try_get (#576) 2020-10-23 23:12:35 +02:00
Michele Caini
83eb0de916 doc: updated links 2020-10-22 09:11:52 +02:00
Koward
6359a12dbb doc: Unreal Engine 4 usage instructions (#574) 2020-10-22 09:09:00 +02:00
Michele Caini
eb8e96f413 example: multi instance storage 2020-10-21 08:40:03 +02:00
Michele Caini
138bd96167 doc: updated links 2020-10-21 08:34:22 +02:00
Michele Caini
0d5ea4711d pool/storage: split storage_adapter from basic_storage 2020-10-20 09:45:11 +02:00
Michele Caini
fa4212f07b storage_adapter: extended ::remove 2020-10-20 08:54:58 +02:00
Michele Caini
c7635a7e3d *: updated todo list 2020-10-20 08:23:21 +02:00
Michele Caini
3923c4cfd2 test: more tests, suppress warnings 2020-10-19 22:46:37 +02:00
Michele Caini
6ad884080c meta_func/meta_ctor: support for registering external member functions 2020-10-19 22:38:08 +02:00
Michele Caini
c578a43611 doc: updated doxy file 2020-10-19 12:24:35 +02:00
Michele Caini
aebfa7161f registry: extended ::remove 2020-10-19 12:01:04 +02:00
Michele Caini
682bc502e2 view_pack: minor changes 2020-10-19 09:08:49 +02:00
Michele Caini
cf018ff74c entity: updated operator==/operator!= (close #573) 2020-10-18 23:37:18 +02:00
Michele Caini
5a9cb251ad doc: updated links 2020-10-18 23:24:48 +02:00
Jan Niklas Hasse
bbbf5a5edf Allow compilation for Windows with GNU-like compilers (#566)
Besides MSVC (and compatible compilers like clang-cl) there's also GCC
(MinGW) and GNU-like Clang on Windows. Therefore setting command line
flags in CMake should check for MSVC instead of $<PLATFORM_ID:Windows>.
2020-10-17 18:26:50 +02:00
Michele Caini
7df0449100 view_pack: suppress a shadow warning caused by an unused variable 2020-10-17 18:22:26 +02:00
Michele Caini
820add87ea test: gtest is now working as expected (close #571) 2020-10-17 18:19:49 +02:00
Michele Caini
9a574aa00c doc: more on view_pack 2020-10-17 18:11:09 +02:00
Michele Caini
10da82a331 view_pack: ::each allows to remove the entity from the callback 2020-10-17 18:08:43 +02:00
Michele Caini
26c816e78c type_traits: is_applicable[_v] and is_applicable_r[_v] for tuples 2020-10-17 17:51:58 +02:00
Michele Caini
808e238384 view/group: full callback is tested first now (breaking changes) 2020-10-17 17:19:38 +02:00
Michele Caini
ff068e032b test: code coverage 2020-10-17 00:30:15 +02:00
Michele Caini
5072e96277 view_pack: get around an issue of VS2017 2020-10-17 00:19:27 +02:00
Michele Caini
c55c1c0615 *: view_pack class and tests 2020-10-16 23:59:44 +02:00
Michele Caini
9983faef70 view/group: consistent ::get without template arguments (breaking changes) 2020-10-16 16:15:04 +02:00
Michele Caini
70a264e939 view: updated noexcept-ness for iterators 2020-10-16 09:55:09 +02:00
Michele Caini
9ef6008c67 doc: updated links 2020-10-16 08:29:09 +02:00
Michele Caini
5a3e816544 view/groups: extended get (breaking changes) 2020-10-15 17:02:50 +02:00
Michele Caini
3e385fb884 view/group: minor changes 2020-10-15 16:41:06 +02:00
Michele Caini
fa5cce7477 pool/registry: rename to avoid name clash with virtual functions 2020-10-15 16:13:41 +02:00
Michele Caini
b2de76e8a0 test: temporary workaround for an upstream regression in googletest (see #571) 2020-10-15 15:27:40 +02:00
Michele Caini
edb363b236 sparse_set: avoid comparisons between different types 2020-10-15 15:23:56 +02:00
Michele Caini
12dcfdb5e1 view: candidate selection happens on construction only 2020-10-15 15:23:32 +02:00
Michele Caini
86c1dd7f32 test: suppress some warnings here and there 2020-10-15 15:11:15 +02:00
Michele Caini
d8ff4285da registry: suppress warnings for uninitialized variable 2020-10-15 15:11:05 +02:00
Michele Caini
7effde0478 view: minor changes 2020-10-15 12:52:16 +02:00
Michele Caini
559ee931fb view/group: proxy() -> each() (breaking changes - I know, I shouldn't have changed it before) 2020-10-15 10:06:00 +02:00
Michele Caini
cb27a7fe3e pool: storage adapter and signal mixin are now independent from each other 2020-10-15 09:03:14 +02:00
Michele Caini
c33a8dc2c8 doc: typo 2020-10-14 23:54:58 +02:00
Michele Caini
11fcf88b88 *: some final here and there 2020-10-14 23:54:49 +02:00
Michele Caini
4f0baa80d7 *: object_type -> value_type (breaking changes) 2020-10-14 19:50:00 +02:00
Michele Caini
ddea97bc88 storage: emplace returns the newly created object 2020-10-14 19:44:17 +02:00
Michele Caini
102c9891a0 test: code coverage for sparse set and storage range-erase 2020-10-14 19:37:28 +02:00
Michele Caini
fb4784b695 test: minor changes 2020-10-14 19:18:02 +02:00
Michele Caini
9a0650c703 pool/storage/sparse_set: pushed range-erase at the bottom of the hierarchy 2020-10-14 19:08:23 +02:00
Michele Caini
a62b93acec storage: updated except specification 2020-10-14 17:06:07 +02:00
Michele Caini
2d11bdc736 doc: minor changes 2020-10-14 16:47:39 +02:00
Michele Caini
7d263d36a0 storage: split basic_storage and storage 2020-10-14 16:44:11 +02:00
Michele Caini
4965fd5888 sparse_set: split basic_sparse_set and sparse_set 2020-10-14 16:35:16 +02:00
Michele Caini
36db8b6f59 group: use operator+ for type lists 2020-10-14 16:08:58 +02:00
Michele Caini
9e69f62a39 doc: updated doc for multi component views 2020-10-14 16:08:09 +02:00
Michele Caini
f307021cf1 view: removed multi component view ::raw and ::data (breaking changes) 2020-10-14 16:04:57 +02:00
Michele Caini
0709c402f8 test: reduced the amount of madness by a few degrees :) 2020-10-14 15:54:20 +02:00
Michele Caini
df5deb8b88 view: removed multi component view ::size (breaking changes) 2020-10-14 15:54:08 +02:00
Michele Caini
111dd40097 view: removed multi component view ::empty (breaking changes) 2020-10-14 15:54:00 +02:00
Michele Caini
c83e7d7995 view: removed multi component view ::size<T> (breaking changes) 2020-10-14 15:53:40 +02:00
Michele Caini
718f964de7 type traits: make type_list_cat work with vs2017 2020-10-14 15:37:19 +02:00
Michele Caini
ce0db9b968 type_list: removed type_list_size[_v] in favor of type_list::size (breaking changes) and added operator+ for type lists 2020-10-14 15:36:52 +02:00
Michele Caini
3f0d602353 doc: typo 2020-10-14 15:35:55 +02:00
Michele Caini
5364d778b0 doc: updated links 2020-10-14 15:30:18 +02:00
Michele Caini
0ddec227fa test: minor changes 2020-10-13 14:29:36 +02:00
Michele Caini
a5ea35ee56 meta: use type info objects rather than plain hashes (breaking changes) 2020-10-13 13:48:52 +02:00
Michele Caini
a3e03fb889 type_info: a better operator== 2020-10-13 13:48:18 +02:00
Michele Caini
b7711f0182 doc: updated documentation for meta (clost #569) 2020-10-13 12:52:38 +02:00
Michele Caini
aae199ff1c test: updated plugin examples 2020-10-13 12:41:07 +02:00
Michele Caini
8d0611a188 meta: meta_handle accepts only lvalue references as it ought to be 2020-10-08 14:08:44 +02:00
Michele Caini
958b245c3d doc: typos 2020-10-07 16:05:16 +02:00
Michele Caini
fbb77092eb doc: updated links (engine.... vrooooommm) 2020-10-06 09:32:11 +02:00
Michele Caini
ebc8328712 meta: added size_of to meta type (close #565) 2020-10-06 09:08:50 +02:00
Michele Caini
7967c6dfc8 traits: added size_of[_v] 2020-10-06 09:08:11 +02:00
Michele Caini
fca08a5162 view/group: minor changes 2020-10-05 16:12:27 +02:00
Michele Caini
49f65d6762 registry: internal rework (close #564 among the other things) 2020-10-05 12:52:55 +02:00
Michele Caini
7684e1bad5 doc: minor changes 2020-10-05 11:21:21 +02:00
Michele Caini
46e974d201 registry/pool: removed internal <pool>::patch overload 2020-10-05 08:03:36 +02:00
Michele Caini
ab55d0abc8 doc: updated links 2020-10-03 23:44:00 +02:00
Michele Caini
ed668d5144 view: updated value_type for view_proxy 2020-10-02 10:42:22 +02:00
Michele Caini
dec0f28a2b organizer: added new type to entt/entity 2020-10-02 10:41:56 +02:00
Michele Caini
de7d79f1f4 doc: added a reference to ENTT_USE_ATOMIC where it matters (close #562) 2020-10-02 10:10:55 +02:00
Michele Caini
d204d580dd type info: minor changes 2020-09-29 14:06:09 +02:00
Michele Caini
e4e38edf24 type_info: updated documentation 2020-09-29 08:52:45 +02:00
Michele Caini
3721a1f90b handle: fixed an issue with the comparison operators + minor changes 2020-09-29 08:47:14 +02:00
Vennor
897850c3eb Truly invalid entt::handle (#551) 2020-09-28 22:45:40 +02:00
Michele Caini
a22efb25c6 sparse_set/storage: avoid virtual erase 2020-09-25 17:09:07 +02:00
Michele Caini
f7e80879ae type_info: comparison operators 2020-09-25 16:43:05 +02:00
Michele Caini
bf902e6398 doc: updated links 2020-09-24 17:08:27 +02:00
Michele Caini
aed817f724 doc: updated links (entt topic on GH) 2020-09-24 09:00:01 +02:00
Michele Caini
5ac76d29fc doc: minor changes 2020-09-24 08:44:41 +02:00
Michele Caini
81311ddd03 registry: visit/ctx return type info objects and not only the hash values (breaking changes) 2020-09-24 08:25:49 +02:00
Michele Caini
3c52070243 type_info/type_id: minor changes 2020-09-24 08:25:49 +02:00
Michele Caini
9070f50658 meta_range: minor changes 2020-09-24 08:25:49 +02:00
Michele Caini
ecc3c56cb1 doc: removed all references to old type_info class template 2020-09-24 08:25:49 +02:00
Michele Caini
a86191f6e0 type traits: added type_list_contains[_v] 2020-09-24 08:25:49 +02:00
Michele Caini
aa5fdac522 type_info: it's now copyable and moveable as it ought be 2020-09-24 08:25:49 +02:00
Michele Caini
3cd32c74a1 type info: updated documentation 2020-09-24 08:25:49 +02:00
Michele Caini
2e2f6a03d9 type info: untyped type_info class and type_id functions 2020-09-24 08:25:49 +02:00
Michele Caini
25a073f20b type info: revised to support opaque type info objects (contains breaking changes) 2020-09-24 08:25:49 +02:00
Michele Caini
0fb244e381 type info: removed has_type_index[_v] utility 2020-09-24 08:25:49 +02:00
Michele Caini
631ba70b72 signal: removed unused functions 2020-09-24 08:25:49 +02:00
Michele Caini
0a1d6b2a6f doc: removed reference to ENTT_STANDALONE 2020-09-24 08:25:48 +02:00
Michele Caini
94bfa5ea25 test: get around an issue of toolset v141 2020-09-24 08:25:48 +02:00
Michele Caini
118c14bf1e lib: standalone mode is now the default 2020-09-24 08:25:48 +02:00
Michele Caini
cf395f707a doc: minor changes 2020-09-24 00:13:58 +02:00
Michele Caini
6e040fa87c doc: more on hashed strings (close #559) 2020-09-24 00:09:45 +02:00
Michele Caini
c0a7f84382 doc: correct definition for ranges (close #560) 2020-09-23 23:55:48 +02:00
Michele Caini
826d7b7c26 registry: reintroduce old function type for signals, the registry is now provided to listeners 2020-09-23 23:02:49 +02:00
Michele Caini
91e63d0f19 pool: doc related changes 2020-09-22 08:07:29 +02:00
Michele Caini
2d69e5f6ff doc: updated documentation about signals from a registry 2020-09-22 08:07:14 +02:00
Michele Caini
23f0fcd024 registry: suppress some warnings 2020-09-22 08:06:56 +02:00
Michele Caini
3fcd82abad test: suppress a warning 2020-09-22 08:06:45 +02:00
Michele Caini
d766c39791 *: minor changes 2020-09-22 08:06:41 +02:00
Michele Caini
a76c3b3baa updated TODO file 2020-09-22 08:06:35 +02:00
Michele Caini
9290b4eecc view: size -> size_hint for multi component views (close #553) 2020-09-22 08:06:30 +02:00
Michele Caini
eccfec4b4f registry: use pool_t instead of default_pool 2020-09-22 08:06:24 +02:00
Michele Caini
80aadd3874 registry/pool: split the default pool from the registry class, allow for custom pools 2020-09-22 08:06:16 +02:00
Michele Caini
9da15826db registry: component signals return only the entity 2020-09-22 08:06:04 +02:00
Michele Caini
8c403f8795 bench: added a couple of tests for recycling entities 2020-09-22 08:05:56 +02:00
Michele Caini
b010824dbd registry: faster ::create 2020-09-22 08:05:51 +02:00
Michele Caini
3340f8864f entt/entity: removed deprecated stuff 2020-09-22 08:05:23 +02:00
Michele Caini
9fb3cdfc4c now working on version 2.6 2020-09-22 08:05:04 +02:00
Michele Caini
3a3a2c2702 doc: updated links and references to similar projects 2020-09-22 08:03:55 +02:00
Michele Caini
be38919758 doc: removed references to entt::component (close #557) 2020-09-22 08:03:44 +02:00
Michele Caini
a816ccf6ee meta_any: support for pointer-like types to non-const, non-copyable types (close #556) 2020-09-22 08:03:39 +02:00
Michele Caini
5e85068e35 meta: @Innokentiy-Alaytsev was right and I was not :) 2020-09-22 08:03:33 +02:00
Michele Caini
77865ab4a1 meta: update doc + minor stylistic changes 2020-09-22 08:03:28 +02:00
Innokentiy Alaytsev
5fc6ee27f6 Fixed trailing spaces
Signed-off-by: Innokentiy Alaytsev <alaitsev@gmail.com>
2020-09-22 08:03:21 +02:00
Innokentiy Alaytsev
5995adf8b6 Implemented shortcuts for meta-functions and meta-data
The shortcut for meta-functions allows invoking them directly from an instance
of meta_type or meta_any. If the meta-function was not found or the arguments
don't match its signature an invalid meta_any object is returned.

The shortcut for meta-data allows getting and setting meta-data directly from an
instance of meta_type of meta_any. If the meta_data was not found or
getting/setting it failed and invalid meta_any object is returned.

Signed-off-by: Innokentiy Alaytsev <alaitsev@gmail.com>
2020-09-22 08:03:12 +02:00
Michele Caini
c9f47ed89a sparse_set: minor changes 2020-09-22 08:02:23 +02:00
Michele Caini
d6325ffcfa now working on v3.5.2 2020-09-22 08:02:04 +02:00
Michele Caini
9d72472114 entity: updated difference type for 32b identifiers 2020-09-03 16:22:05 +02:00
Michele Caini
102350a125 entity: removed support for 16b identifiers 2020-09-03 16:22:00 +02:00
Michele Caini
1c650cb136 observer: fixed an issue with exclusion lists (close #549) 2020-09-03 16:21:52 +02:00
Michele Caini
625e74653d test: get around comdat folding 2020-09-03 16:17:11 +02:00
Michele Caini
5bad762293 now working on version 3.5.1 2020-09-03 14:34:34 +02:00
Michele Caini
fc1ff11352 updated single include file 2020-08-31 22:47:23 +02:00
Michele Caini
0595ba384e *: suppress some warnings 2020-08-29 21:59:44 +02:00
Michele Caini
f80f5e9955 doc: updated links 2020-08-29 16:14:11 +02:00
Michele Caini
f689014c3e emitter: the event isn't const by default anymore (close #547) 2020-08-21 18:09:05 +02:00
Michele Caini
9b24655bbf dispatcher: the event isn't const by default anymore (see #547) 2020-08-21 18:02:41 +02:00
Michele Caini
c3201070a1 doc: updated FAQs (close #543) 2020-08-21 16:16:40 +02:00
Michele Caini
8a146209e4 sigh: updated documentation 2020-08-21 15:59:56 +02:00
Michele Caini
2b719726cd view: suppress warnings 2020-08-21 12:24:34 +02:00
Michele Caini
27209e4836 doc: updated links 2020-08-19 16:39:24 +02:00
Michele Caini
0497762f94 doc: typo 2020-08-19 10:41:01 +02:00
Michele Caini
b38f1e744b doc: updated README - EnTT runs everywhere 2020-08-19 10:15:16 +02:00
Michele Caini
481c49e18e doc: added a new link to similar projects 2020-08-19 10:06:38 +02:00
Michele Caini
69cf9115b5 doc: added a new link to the list of showcases (close #546) 2020-08-19 10:02:31 +02:00
Michele Caini
3eedd89efe config/core/entity: added is_eto_eligible[_v] and used it where it makes sense 2020-08-17 18:21:21 +02:00
Michele Caini
ad262ea624 entity/*: suppress some warnings here and there 2020-08-16 12:10:55 +02:00
Michele Caini
08cd8c95f7 updated todo list 2020-08-16 11:25:28 +02:00
Michele Caini
c86790c6b8 test: minor changes 2020-08-16 11:24:57 +02:00
Michele Caini
e466d9252f view: rebind the view only when possible 2020-08-14 12:12:57 +02:00
Michele Caini
02f8a0baa6 view: stable candidate computed on construction 2020-08-14 11:58:10 +02:00
Michele Caini
9f7bbe3f9d doc: updated links 2020-08-14 11:02:37 +02:00
Michele Caini
e81e0e97e0 meta: workaround for an issue of VS2019 (see #314) 2020-08-12 09:05:20 +02:00
Michele Caini
52554c3972 test: suppress a bunch of warnings 2020-08-11 16:53:03 +02:00
Michele Caini
48b6c4876a runtime view: suppress warnings for shadow variables 2020-08-11 16:52:24 +02:00
Michele Caini
99e89c2540 registry: suppress warnings for shadow variables 2020-08-11 16:52:06 +02:00
Michele Caini
0e8453d4ed entt_traits: updated difference types 2020-08-11 15:27:41 +02:00
Michele Caini
c750b746b3 meta: explicit return type to get around an issue with VS2017 2020-08-10 18:16:26 +02:00
Michele Caini
0ac07e2e83 meta: reset is now part of meta_type 2020-08-10 18:15:11 +02:00
Michele Caini
ead6cb9ca3 test: suppress warnings 2020-08-10 10:04:14 +02:00
Michele Caini
c401f9211d test: minor changes 2020-08-10 10:04:14 +02:00
Michele Caini
abb72c0a9a view: rbegin/rend 2020-08-10 10:04:13 +02:00
Michele Caini
bc9172bd43 doc: updated links 2020-08-10 10:04:13 +02:00
Michele Caini
b205a5e49d group: rbegin/rend 2020-08-10 10:04:13 +02:00
Michele Caini
fccf9642d8 view: prepare multi component views for reverse iterators 2020-08-10 10:04:13 +02:00
Michele Caini
96dd68f52b doc: typo 2020-08-10 10:04:12 +02:00
Michele Caini
7f923bb389 doc: added more details about observers (close #536) 2020-08-10 10:04:12 +02:00
Michele Caini
7ab7ebb3f6 doc: added a note about in-place sorting 2020-08-10 10:04:12 +02:00
Michele Caini
4eacb58a3e doc: minor changes 2020-08-10 10:04:12 +02:00
Michele Caini
24248832d1 group/view: explicit proxy object 2020-08-10 10:04:11 +02:00
Michele Caini
a53f0900bd view/group: make range return types explicit in preparation for faster/unsafe reverse iterators 2020-08-10 10:04:11 +02:00
Michele Caini
6a1a5a0f74 sparse set: minor changes 2020-08-10 10:04:10 +02:00
Michele Caini
65aa4e145e registry: minor changes 2020-08-10 10:04:10 +02:00
Michele Caini
cf903aa082 storage: added reverse iterators 2020-08-10 10:04:09 +02:00
Michele Caini
75dd86e8ef sparse set: added reverse iterators 2020-08-10 10:04:09 +02:00
Michele Caini
70a3d62c14 doc: udpated links 2020-08-10 10:04:08 +02:00
Michele Caini
291e3cd229 view: minor changes 2020-08-10 10:04:08 +02:00
Michele Caini
9b28c1fdd2 runtime view: suppress warning (close #540) 2020-08-10 10:01:09 +02:00
Michele Caini
d1d73da039 doc: fixed typo (close #534) 2020-07-28 21:51:59 +02:00
Michele Caini
59f041b9a9 view: minor changes 2020-07-27 10:50:11 +02:00
Michele Caini
fbf3b9ce4d doc: help doxygen not to go crazy (thanks to @erez-o for pointing this out) 2020-07-27 00:07:11 +02:00
Michele Caini
9be2e1c4c9 sigh: don't use std::forward with fake forwarding references 2020-07-26 01:09:58 +02:00
Michele Caini
a06c9f890c meta: cleanup 2020-07-25 23:35:52 +02:00
cugone
fc8e8874a9 *: fix C4003 NOMINMAX issue (#531) 2020-07-25 23:09:26 +02:00
Michele Caini
09e0f68616 view: suppress shadow warnings 2020-07-25 23:02:52 +02:00
Michele Caini
0e7e36f80d view: chunked iteration for multi-component views (close #462) 2020-07-25 18:47:20 +02:00
Michele Caini
8484dcd332 doc: updated links 2020-07-24 11:00:33 +02:00
Michele Caini
8a46296b48 meta: simplified iterators for meta containers 2020-07-24 11:00:33 +02:00
Michele Caini
b748a910b2 meta: fix an issue with meta_associative_container::meta_iterator::value 2020-07-24 11:00:33 +02:00
Michele Caini
932603eea3 *: minor changes 2020-07-24 11:00:33 +02:00
Michele Caini
5056972f79 meta: ctors and funcs also accept a meta_any * + size pair (close #528) 2020-07-24 11:00:33 +02:00
Michele Caini
d99ccca291 meta: minor changes 2020-07-24 11:00:33 +02:00
Sackhorn
1d9b26d9ec doc: backslash typo in FAQ (#532) 2020-07-24 11:00:12 +02:00
Michele Caini
3a64707c6e doc: updated links 2020-07-21 15:43:58 +02:00
Michele Caini
6f4071bd75 view: check filter array correctly (close #527) 2020-07-21 13:12:51 +02:00
Michele Caini
1354fdc613 *: suppress some warnings here and there (close #525) 2020-07-20 00:20:55 +02:00
Michele Caini
991244655a dispatcher: opaque disconnect (close #523) 2020-07-19 12:18:15 +02:00
Michele Caini
0d07d935bf *: removed redundant namespace names 2020-07-19 12:13:51 +02:00
Michele Caini
bd56b642a7 doc: updated links 2020-07-19 11:03:06 +02:00
Sackhorn
d989f0edf2 Update entity.md (#524)
Small typo fix in wiki
2020-07-19 10:20:52 +02:00
Michele Caini
f561cf9c8f build system: suppress wrong warning 2020-07-16 18:03:16 +02:00
Michele Caini
13502e5467 entity: explicit casts to suppress misleading warnings 2020-07-16 17:48:29 +02:00
Michele Caini
045c2a6f05 delegate: removed redundant calls to delegate constructor 2020-07-15 18:13:44 +02:00
Michele Caini
725e9feb68 entity: removed unused constructors from range iterators (being default constructible isn't a requirement for input iterators) 2020-07-15 17:33:21 +02:00
Michele Caini
6e45126f53 test: added explicit test for ENTT_NO_ETO 2020-07-15 16:09:41 +02:00
Michele Caini
6ebc39e038 entity: added sfinae-friendly utility for component-to-pool conversions 2020-07-14 18:25:01 +02:00
Michele Caini
8b0a7c302b storage: workaround for an issue of vs2017 2020-07-14 17:46:08 +02:00
Michele Caini
0c3e50da2f build system: try to reproduce an issue of vs2019, toolset v141 2020-07-14 15:11:39 +02:00
Michele Caini
d220cf4acc platform: minor changes 2020-07-13 23:56:01 +02:00
Innokentiy Alaytsev
eb1ce7e927 meta: Deduplicate the STL-compatible container traits (#518) 2020-07-13 23:55:19 +02:00
Michele Caini
46f6f41a6b entity: remove asserts from to_entity, it's potentially UB as from the standard 2020-07-12 23:53:20 +02:00
Michele Caini
2fa59fc43c entity: added debug asserts to to_entity 2020-07-12 16:45:00 +02:00
Michele Caini
b7763b3887 test: minor changes 2020-07-11 17:59:23 +02:00
Michele Caini
8c002b67d5 runtime view: support for excluded components (close #512) 2020-07-11 17:26:20 +02:00
Michele Caini
7692c4a377 test: ENTT_ID_TYPE -> entt::id_type 2020-07-11 15:56:30 +02:00
Michele Caini
1f0acec06c doc: minor changes 2020-07-11 15:07:23 +02:00
Michele Caini
1b5295a8fe helper: added to_entity function that returns the entity associated with a given component 2020-07-11 12:32:58 +02:00
Michele Caini
0b699a3f20 view: fixed the constrained range-each 2020-07-10 17:54:07 +02:00
Michele Caini
409d7a499d test: code coverage 2020-07-10 17:45:17 +02:00
Michele Caini
ba7428f3d6 group: small changes to get around an issue of g++ v7.5 2020-07-10 17:35:57 +02:00
Michele Caini
c12c32d26e view/group: updated range iterators (thanks to @Lawrencemm for pointing this out) 2020-07-10 15:37:43 +02:00
Michele Caini
0ca5ea0150 test: minor changes 2020-07-10 15:09:40 +02:00
Michele Caini
11ca7c7b3e group: get around an issue with g++ 2020-07-09 19:20:09 +02:00
Michele Caini
8f6c47527d doc: added a note about ranges for views and groups (close #502) 2020-07-09 18:40:41 +02:00
Michele Caini
dd28882b27 group: optimized ranges 2020-07-09 18:18:07 +02:00
Michele Caini
1b93a449b2 view: improved view ranges 2020-07-09 18:09:38 +02:00
Michele Caini
7cf2ec09b7 group: added iterable object to visit entities and components at once 2020-07-09 16:58:26 +02:00
Michele Caini
4d1952a406 view: added iterable object to visit entities and components at once 2020-07-09 16:58:07 +02:00
Michele Caini
b8d25e2327 doc: typos 2020-07-08 18:07:26 +02:00
Michele Caini
89d7c7e572 handle: better API 2020-07-06 09:39:23 +02:00
Michele Caini
75b19230eb entity: make null_t public 2020-07-06 09:24:56 +02:00
Indiana Kernick
7889ca1ca7 Non-owning entt::handle (#513) 2020-07-04 18:00:44 +02:00
Michele Caini
cec1b932bd example: custom identifier (and some fixes for the purpose) 2020-07-02 16:56:49 +02:00
Michele Caini
2c7455ea2b benchmark: use entt::id_type instead of ENTT_ID_TYPE 2020-07-02 15:07:20 +02:00
Michele Caini
edc9cc9278 type_traits: removed ENTT_OPAQUE_TYPE 2020-07-01 18:41:20 +02:00
Michele Caini
51eafaeb4f doc: mention custom types for entity identifiers 2020-07-01 18:41:00 +02:00
Michele Caini
556373d331 registry: better support for integral entity identifiers (even if not recommended) 2020-07-01 18:39:34 +02:00
Michele Caini
804cfb7482 test: use entt::to_integral instead of std::underlying_type_t for entity identifiers 2020-07-01 17:17:33 +02:00
Michele Caini
143eae0729 test: avoid using underlying_type_t with entt_traits 2020-07-01 17:10:42 +02:00
Michele Caini
29d4846de7 entity: bind to_integral to entt_traits instead of a specific enum class 2020-07-01 16:28:56 +02:00
Michele Caini
306178f371 doc: minor changes 2020-07-01 16:06:08 +02:00
Michele Caini
371b541fbc entity: make entt_traits sfinae-friendly and avoid using std::underlying_type_t to define the entity traits types 2020-07-01 15:32:04 +02:00
Oortonaut
902658fd21 Properly case entity version for 64-bit support. (#516) 2020-07-01 10:51:26 +02:00
Michele Caini
0ca8dff974 test: code coverage 2020-06-30 17:50:36 +02:00
Michele Caini
a212b054e7 platform: added support file for android ndk r17 2020-06-30 16:47:27 +02:00
Michele Caini
cccd1baa2f meta: minor changes 2020-06-26 16:04:09 +02:00
Michele Caini
5dd25aed4d meta: assoc container's ::erase/::find accept also convertible keys 2020-06-26 14:59:35 +02:00
Michele Caini
6ddc725b75 meta: minor changes 2020-06-26 12:51:44 +02:00
Michele Caini
36ab7444a0 meta: removed some deprecated functions (semantics had changed, it was already a breaking change in itself) 2020-06-26 12:43:51 +02:00
Michele Caini
a8d004334a meta: minor changes 2020-06-26 12:24:28 +02:00
Michele Caini
900398a632 resource: added prefix resource_ to all classes 2020-06-25 23:37:50 +02:00
Michele Caini
f24bb8737d deprecate actor 2020-06-25 22:55:35 +02:00
Michele Caini
cb5e9b197a doc: added links to docsforge (close #510) 2020-06-24 09:44:54 +02:00
Michele Caini
450e20ae78 meta: minor changes 2020-06-23 11:31:04 +02:00
Michele Caini
5d42a76fe5 meta: added support for convertible types to meta containers ::insert functions 2020-06-23 10:55:40 +02:00
Michele Caini
c5075a3db0 doc: minor changes (see #510) 2020-06-23 08:49:17 +02:00
Michele Caini
ad5bb5198b meta: fixed key_only member function for meta associative containers 2020-06-22 17:02:45 +02:00
Michele Caini
d306bc4a9a test: code coverage 2020-06-22 12:47:10 +02:00
Michele Caini
5c3b956542 doc: fixed some problems with doxygen (see #510) 2020-06-22 12:11:36 +02:00
Michele Caini
ade8533f28 meta: dedicate iterators for different types of meta containers 2020-06-22 11:07:57 +02:00
Michele Caini
ad3413d6ad meta: added is_key_only_meta_associative_container[_v] to type traits 2020-06-22 10:19:06 +02:00
skypjack
f3d0e3f4dd test: fixed tests for meta containers 2020-06-22 09:32:00 +02:00
Michele Caini
6e2e030ba7 meta: updated documentation 2020-06-22 01:05:48 +02:00
Michele Caini
613f993638 core/type_traits: removed is_dereferenceable[_v] 2020-06-21 23:42:07 +02:00
Michele Caini
2566e3631b meta: support for pointer-like types 2020-06-21 23:39:26 +02:00
Michele Caini
4ad6c0a8a9 meta: meta_sequence_container_traits_t -> meta_sequence_container_traits 2020-06-21 23:13:20 +02:00
Michele Caini
0369ac450e meta: added meta sequence container resize + [[nodiscard]] here and there 2020-06-21 23:08:14 +02:00
Michele Caini
ab16680cc8 type_traits: removed container detectors 2020-06-20 01:20:22 +02:00
Michele Caini
8a344cd9b2 meta: meta container support review 2020-06-20 01:17:14 +02:00
Michele Caini
4e66fb4589 test: minor changes, code coverage 2020-06-19 11:52:47 +02:00
Michele Caini
0043e3d623 meta: breaking change, meta_any::operator* dereferences the internal pointer (if any) 2020-06-19 00:15:01 +02:00
Michele Caini
ed168015bf meta: review meta_handle 2020-06-18 18:49:52 +02:00
Michele Caini
1d450ef27e meta: deprecate meta_[any|handle]::operator*, use ::ref instead 2020-06-18 18:21:12 +02:00
Michele Caini
932e681d22 meta: get rid of meta_dtor_node 2020-06-18 16:44:04 +02:00
Michele Caini
032bcd9fbe meta: minor changes 2020-06-18 16:02:26 +02:00
Michele Caini
e113fa53a4 meta: split meta_storage from meta_any 2020-06-18 14:31:06 +02:00
Michele Caini
da212dc2a4 meta: added meta_type::is_dereferenceable 2020-06-18 11:34:44 +02:00
Michele Caini
d1c5a62a9d core: type_traits, added is_dereferenceable[_v] 2020-06-18 11:30:55 +02:00
Michele Caini
0c777e10e5 doc: meta, container support 2020-06-18 10:17:50 +02:00
Michele Caini
b919b172b1 *: suppress some warnings here and there 2020-06-16 23:36:31 +02:00
Michele Caini
5dd8d05114 meta: get around an issue of msvc 2020-06-16 23:29:50 +02:00
Michele Caini
3400b32015 meta: containers support (close #499) 2020-06-16 23:21:45 +02:00
Michele Caini
2e4becad60 type_traits: sequence/associative container traits 2020-06-16 23:18:55 +02:00
Michele Caini
3d485858d5 meta: get around a bug of gcc-7, meta factory has no longer only static members 2020-06-15 00:08:46 +02:00
Michele Caini
be93643808 view: non-const excluded types are always accepted (close #507) 2020-06-14 23:42:15 +02:00
Michele Caini
f704352bae type_traits: unpack_as_t/unpack_as_v 2020-06-14 23:28:35 +02:00
Michele Caini
6683b46b07 meta: factory<Type> has now only static functions 2020-06-14 17:32:28 +02:00
Michele Caini
a1fe458338 meta: removed dependency on <algorithm> from internal.hpp 2020-06-14 16:37:38 +02:00
Michele Caini
e6328e3207 meta: minor changes 2020-06-12 17:47:39 +02:00
Michele Caini
8b1f703397 doc: updated missing description 2020-06-12 16:18:12 +02:00
Michele Caini
583c8add7e meta: make meta_handle copyable 2020-06-12 11:42:05 +02:00
Michele Caini
0266cc8e99 meta: make instances meta handles all around the codebase 2020-06-12 11:36:13 +02:00
Michele Caini
fac4132cb1 meta: meta_type rank/extent 2020-06-12 10:10:43 +02:00
Michele Caini
bf3864b2da meta: arrays are no longer indexable via meta_type::set/get 2020-06-12 09:30:29 +02:00
Michele Caini
7c21042858 sparse_set: improved performance (see #506) - thanks @Kerndog73 2020-06-12 08:19:44 +02:00
Michele Caini
d0fd9e4618 meta: range_iterator are now part of ranges 2020-06-11 19:50:32 +02:00
Michele Caini
9b53230f83 meta: cleanup 2020-06-11 17:59:29 +02:00
Michele Caini
d814b7b11e test: code coverage 2020-06-11 17:03:45 +02:00
Michele Caini
9f5421d3d4 build system: solved an issue with codecov 2020-06-11 16:48:25 +02:00
Michele Caini
6b9e5db3bf meta: updated resolve function(s) 2020-06-11 15:40:16 +02:00
Michele Caini
9eac3faf3d meta: added meta_range and meta_iterator 2020-06-11 15:27:56 +02:00
Michele Caini
252de444fc test: meta, minor changes 2020-06-11 11:00:20 +02:00
Michele Caini
c29b9cc937 test: updated tests for meta 2020-06-11 10:46:40 +02:00
Michele Caini
6ac582a771 test: more on meta_type 2020-06-11 10:10:07 +02:00
Michele Caini
04b0c9f2cf test: more on meta_func 2020-06-11 09:55:49 +02:00
Michele Caini
6b2468f033 test: more on meta_data 2020-06-11 09:53:35 +02:00
Michele Caini
2737acb114 test: added meta_type 2020-06-11 09:45:55 +02:00
Michele Caini
d03e9c48c5 tests: minor changes 2020-06-11 09:01:33 +02:00
Michele Caini
08d9cfe82c test: added meta_func 2020-06-10 17:37:21 +02:00
Michele Caini
e8ea8f91c3 test: added meta_data 2020-06-10 17:22:48 +02:00
Michele Caini
e7cfa7fda5 test: added meta_ctor 2020-06-10 16:43:02 +02:00
Michele Caini
b0b504d002 test: added meta_conv 2020-06-10 15:59:12 +02:00
Michele Caini
1da07ba60b test: added meta_base 2020-06-10 15:51:10 +02:00
Michele Caini
cedebf8145 test: added meta_prop 2020-06-10 15:42:47 +02:00
Michele Caini
29832bb2c0 test: added meta_any 2020-06-10 15:32:30 +02:00
Michele Caini
320d815d60 test: added meta_basic 2020-06-10 15:05:26 +02:00
Michele Caini
9f18401581 meta: split fixture and tests 2020-06-10 14:56:01 +02:00
Michele Caini
b3a2f0e3a3 meta: internal range/iterator support 2020-06-10 11:34:45 +02:00
Michele Caini
c00dcd31d6 meta: small review 2020-06-09 16:41:12 +02:00
Michele Caini
b836be2c84 doc: minor changes 2020-06-09 16:13:47 +02:00
Michele Caini
f89c5cc072 doc: added section pool to entity.md (close #505) 2020-06-09 09:57:57 +02:00
Michele Caini
ab7fa56bb3 doc: updated documentation for groups and nested groups 2020-06-09 09:32:36 +02:00
Michele Caini
7e624159ee registry/group: pool<T>::super is no longer required 2020-06-09 00:55:48 +02:00
Michele Caini
857a791d68 registry: sort/sortable no longer requires pool<T>::super 2020-06-08 00:44:02 +02:00
Michele Caini
171463faf5 [[nodiscard]]: try to get around an issue with VS2017 (see #501) 2020-06-07 17:34:38 +02:00
Michele Caini
2cafb49ffe entity: [[nodiscard]] (close #501) 2020-06-07 00:51:45 +02:00
Michele Caini
ae12fed5fe meta: [[nodiscard]] (see #501) 2020-06-07 00:13:20 +02:00
Michele Caini
be5547de53 core: [[nodiscard]] (see #501) 2020-06-06 23:51:08 +02:00
Michele Caini
cac50ef566 locator: [[nodiscard]] (see #501) 2020-06-06 23:43:56 +02:00
Michele Caini
57a5736942 process: [[nodiscard]] (see #501) 2020-06-06 23:42:48 +02:00
Michele Caini
167eadf699 resource: [[nodiscard]] (see #501) 2020-06-06 23:39:56 +02:00
Michele Caini
5676e420a6 signal: [[nodiscard]] (see #501) 2020-06-06 23:36:31 +02:00
Michele Caini
f5edc9e973 doc: core, type_info<T>::name 2020-06-05 14:57:24 +02:00
Michele Caini
4a305e1568 type_info: added ::name 2020-06-05 00:32:15 +02:00
Michele Caini
748ab221dd delegate: renaming of exported types 2020-06-03 23:59:58 +02:00
Michele Caini
7d786cea8f test: pass ENTT_STANDALONE definition to all targets 2020-06-03 23:42:05 +02:00
Michele Caini
1bf734338d doc: suppress a couple of warnings from doxygen 2020-06-03 17:17:10 +02:00
Michele Caini
98df1d6004 config: type index based lookup as opt-in alternative (close #490) 2020-06-03 17:13:11 +02:00
Michele Caini
290e942f3e doc: updated documentation for meta 2020-06-01 19:38:07 +02:00
Michele Caini
46d54f7e01 factory: try to get around an issue of GCC 2020-05-31 17:23:56 +02:00
Michele Caini
16e1715d06 factory: extended ::data support (close #496) 2020-05-31 17:13:21 +02:00
Michele Caini
52faa1bec5 meta: allow read-only data registration in meta (close #496) 2020-05-29 00:54:39 +02:00
Michele Caini
c8a6465688 meta: reduce instantiations 2020-05-29 00:30:20 +02:00
Alex Ames
0273b7606e snapshot: components no longer need to be copyable (#498)
Replaced calls to std::as_const with std::move so that components can
be moved into place instead of copied when reading them in from a
snapshot.
2020-05-27 23:56:48 +02:00
Michele Caini
51022cb132 meta: reduce instantiations 2020-05-27 00:51:42 +02:00
Michele Caini
78f9d87ac3 test: suppress shadow warnings 2020-05-25 23:03:28 +02:00
Michele Caini
e57135eaab delegate: support for non-capturing lambda functions (see #495) 2020-05-25 22:59:02 +02:00
Michele Caini
5fbb663529 *: added meaningful messages (?) to static asserts (close #493) 2020-05-24 00:32:08 +02:00
Michele Caini
7db0f540bd dispatcher: enqueue works fine with aggregates now (close #491) 2020-05-23 00:40:42 +02:00
Michele Caini
c8f0afb775 test: ugly workaround for an ICE of VS2017 that fails to compile valid C++ code when combined with ENTT_API 2020-05-22 00:33:17 +02:00
Michele Caini
51a5815098 registry: suppress shadow warnings 2020-05-21 22:50:38 +02:00
Michele Caini
18bd2eb729 doc: removed references to patreon account 2020-05-21 08:44:24 +02:00
Michele Caini
f04fd61879 doc: added config section 2020-05-19 00:36:45 +02:00
Michele Caini
c1527cc4c8 doc: more details on the order of components and entities when iterating through pointers returned from raw/data (close #489) 2020-05-17 23:48:43 +02:00
Michele Caini
cf1c1ed126 group: const correctness for constructor arguments 2020-05-17 22:57:16 +02:00
Michele Caini
c4ba8f96e6 view: try to get around a bug in MSVC 2020-05-17 00:44:06 +02:00
Michele Caini
350884c627 view: const correctness for constructor arguments 2020-05-17 00:18:52 +02:00
Michele Caini
aa756f6d68 doc: minor changes 2020-05-17 00:12:43 +02:00
Michele Caini
1a77bf49f5 registry: const correctness 2020-05-16 00:52:28 +02:00
Michele Caini
1b509c56fe meta: cleanup 2020-05-16 00:52:23 +02:00
Joël Lamotte
038b10c74d Added build2 package info (#484) 2020-05-14 00:38:36 +02:00
Michele Caini
39baa59625 registry: remove_if_exists returns the number of components actually removed (close #483) 2020-05-13 00:20:44 +02:00
Michele Caini
3fc091ebb2 view: removed deprecated functions 2020-05-12 00:24:39 +02:00
Michele Caini
a557e133d3 group: removed deprecated functions 2020-05-12 00:18:42 +02:00
Michele Caini
7d4f10ccc6 registry: removed deprecated functions 2020-05-12 00:12:49 +02:00
Michele Caini
39a15bef12 snapshot: removed deprecated functions 2020-05-11 16:38:12 +02:00
Michele Caini
92c59f3ea1 registry: removed the dependency on the snapshot stuff 2020-05-11 16:38:12 +02:00
Michele Caini
226bd44e2c meta: removed deprecated functions 2020-05-11 16:38:12 +02:00
Michele Caini
78d43a49c6 observer: removed deprecated functions 2020-05-11 16:38:12 +02:00
Michele Caini
471651ac5a storage: removed deprecated functions 2020-05-11 16:38:12 +02:00
Michele Caini
89515b0e30 sparse set: removed deprecated functions 2020-05-11 16:38:12 +02:00
Michele Caini
1d61c0d970 build system: updated version, now working on v3.5.0 2020-05-11 16:38:12 +02:00
Michele Caini
35c3acbade doc: added a link to the discord server 2020-05-11 16:37:18 +02:00
Michele Caini
58a2c6a13a updated single include file 2020-05-10 16:14:27 +02:00
Michele Caini
bf0160adbd registry: removed useless check 2020-05-08 23:27:53 +02:00
Michele Caini
dfbc92dd3e test: code coverage 2020-05-08 23:17:36 +02:00
Michele Caini
85b0bbfd55 snapshot: suppress shadow warnings 2020-05-07 17:20:25 +02:00
Michele Caini
fb2a93dc05 snapshot: updated documentation 2020-05-07 16:25:51 +02:00
Michele Caini
4ac46bf19d snapshot: registry friendship is no longer required 2020-05-07 16:02:49 +02:00
Michele Caini
4d73adb540 snapshot: cleanup 2020-05-07 16:02:49 +02:00
Michele Caini
bdfeb1ae22 registry: destroy with suggested version 2020-05-07 16:02:49 +02:00
Michele Caini
3fc116ab53 minor changes 2020-05-07 16:02:49 +02:00
Michele Caini
8db61a38cc sparse set: review 2020-05-07 16:02:49 +02:00
Michele Caini
0a70979934 observer: deprecated .replace, use .update instead 2020-05-07 16:02:49 +02:00
Michele Caini
1a2ccdf991 Update README.md 2020-05-07 16:01:12 +02:00
Michele Caini
0adee56d76 meta: as_alias[_t] -> as_ref[_t] (see #479) 2020-04-30 23:59:17 +02:00
Michele Caini
fedd50efe4 meta: added meta_any::ref as an alias to meta_any operator* (close #479) 2020-04-30 23:53:02 +02:00
Michele Caini
d7de7dbe6b build system: minor changes (close #478) 2020-04-30 23:24:50 +02:00
Michele Caini
9fb8939efd meta: removed redundant assert 2020-04-30 14:28:54 +02:00
Michele Caini
fe8f671137 build system: USE_LIBCPP option is set to ON by default (see #478) 2020-04-30 14:28:34 +02:00
Michele Caini
1a4de1482b build system: minor changes (close #478) 2020-04-29 23:10:42 +02:00
Michele Caini
090a2595e1 config/type_id: minor changes 2020-04-29 01:05:17 +02:00
Michele Caini
89dc7f817f meta: added resolve_type utility 2020-04-25 17:36:57 +02:00
Michele Caini
fe0f26ce9c meta: workaround for an issue of clang 7 (close #472) 2020-04-25 16:48:21 +02:00
Michele Caini
11349629f4 meta: get around an issue of VS2017 2020-04-23 14:56:39 +02:00
Michele Caini
9a67652c0c meta: separate resolve.hpp file 2020-04-22 20:05:24 +02:00
Michele Caini
b35521dfcb meta: deprecated resolve by id, added entt::resolve_id 2020-04-21 18:32:35 +02:00
Michele Caini
9faf306d1e meta: added entt::resolve_if 2020-04-20 23:25:10 +02:00
Michele Caini
d8393dace6 meta: deprecated *::alias(), use ::id() instead 2020-04-20 22:34:30 +02:00
Michele Caini
692e5275a3 entity: the null entity works fine also with C++20 (close #467) 2020-04-20 22:34:30 +02:00
Michele Caini
1cfe517db8 meta: meta_type::id -> meta_type::type_id 2020-04-20 22:34:30 +02:00
Michele Caini
e99e1dc2ac meta: factory::alias -> factory::type (with type_info<T>::id as a default identifier) 2020-04-20 22:34:30 +02:00
Michele Caini
1bf4ebcabb suppress warnings for shadow parameters 2020-04-20 22:34:30 +02:00
Michele Caini
ec4b264868 meta: export also the meta_node class template (close #464) 2020-04-20 22:34:30 +02:00
Michele Caini
efb125b2d5 updated list of contributors 2020-04-20 22:34:16 +02:00
Elias Daler
1c0fdbed59 Fix typo in docs (s/comp/velocity) (#468) 2020-04-20 22:32:52 +02:00
Michele Caini
37bb10e564 doc: updated examples (close #463) 2020-04-17 00:23:04 +02:00
Michele Caini
1507d5d85f updated single include file (close #461) 2020-04-14 18:37:59 +02:00
Michele Caini
2a86acfc50 doc: updated documentation for the core part 2020-04-14 18:35:03 +02:00
Michele Caini
e0ee01b92e doc: fixed typo 2020-04-14 18:29:25 +02:00
Michele Caini
6006917622 storage: assert on requirements (see #458) 2020-04-09 19:42:45 +02:00
Michele Caini
4ffcf6bf3b meta: added the possibility to detach meta types from contexts 2020-04-09 00:26:02 +02:00
Michele Caini
49cde59c4e meta: minor changes 2020-04-08 23:45:48 +02:00
Michele Caini
ed7382995c registry: added ::remove_all to orphan entities (close #446) 2020-04-07 23:48:07 +02:00
Michele Caini
a7faab53b9 basic_continuous_loader: deprecated ::has, use ::contains instead 2020-04-07 00:00:57 +02:00
Michele Caini
a6aad25117 sparse_set/storage: deprecated ::destroy, use ::erase instead 2020-04-06 23:57:20 +02:00
Michele Caini
5f06084b19 sparse_set: deprecated ::has, use ::contains instead 2020-04-06 23:51:59 +02:00
Michele Caini
8151fbcb2e core: tag is no longer deprecated (close #457) 2020-04-06 23:21:17 +02:00
Michele Caini
5a8e46a6b8 doc: updated documentation for the resource module 2020-04-06 23:20:46 +02:00
Michele Caini
c4997c52e2 doc: updated documentation for the entity module 2020-04-06 23:20:28 +02:00
Michele Caini
ff12c22f50 test: cleanup 2020-04-05 23:36:00 +02:00
Michele Caini
ed7f09ab80 registry: updated tests (lib) 2020-04-05 23:32:10 +02:00
Michele Caini
f68941992a emitter: updated tests (lib) 2020-04-05 23:22:16 +02:00
Michele Caini
afcd9285e6 dispatcher: updated tests (lib) 2020-04-05 23:16:16 +02:00
Michele Caini
22f78d5b33 doc: updated documentation for making EnTT work nicely across boundaries 2020-04-05 22:58:07 +02:00
Michele Caini
5259142eb6 registry: use fast path if available, standard path otherwise 2020-04-05 22:07:35 +02:00
Michele Caini
dc403ce8ab emitter: use fast path if available, standard path otherwise 2020-04-05 22:07:23 +02:00
Michele Caini
a6fddd6a2c dispatcher: use fast path if available, standard path otherwise 2020-04-05 22:07:12 +02:00
Michele Caini
819cd623f9 multiple modules: minor changes 2020-04-05 22:04:57 +02:00
Michele Caini
f185494de3 type info: added has_type_index[_v] 2020-04-05 22:03:52 +02:00
Michele Caini
628a17ae72 config: fixed ENTT_IS_EMPTY macro definition 2020-04-03 00:49:47 +02:00
Michele Caini
08169b9180 emitter: reintroduced type_id for the internal pool 2020-04-03 00:22:01 +02:00
Michele Caini
1e79f2441c dispatcher: reintroduced type_id for the internal pool 2020-04-03 00:21:53 +02:00
Michele Caini
8680c0ba39 config: ENTT_DISABLE_ETO -> ENTT_NO_ETO 2020-04-02 18:21:42 +02:00
Michele Caini
8a78b0dbd6 registry: use only sequential indexes for component types now 2020-04-01 22:17:10 +02:00
Michele Caini
0232035e34 emitter: use only sequential indexes now 2020-04-01 21:27:59 +02:00
Michele Caini
74f3df83db dispatcher: use only sequential indexes now 2020-04-01 21:19:38 +02:00
Michele Caini
53fa0d2fe8 registry: ::assure sets a constraint on the type 2020-04-01 00:16:35 +02:00
Michele Caini
52aa9ab761 type_info: split type_info::index to type_index::value 2020-04-01 00:14:28 +02:00
Michele Caini
92cf6195b2 iterators: standard-ish names for better integration 2020-03-30 16:11:10 +02:00
Michele Caini
86a392991a test: type_info::index 2020-03-28 17:05:23 +01:00
Michele Caini
30d426d667 doc: updated core section 2020-03-28 17:01:04 +01:00
Michele Caini
5702c50680 type_info: added ::index to generate type indexes 2020-03-28 17:00:48 +01:00
Michele Caini
e38d2e156d doc: updated list of showcases 2020-03-27 00:25:30 +01:00
Michele Caini
dfc18619a2 build system: updated installation process (close #451) 2020-03-27 00:04:48 +01:00
Michele Caini
9e8f2c52a0 doc: updated section for on_update/on_replace (close #452) 2020-03-25 15:11:14 +01:00
Michele Caini
1c8f5b98f1 build system: updated installation process (close #451) 2020-03-25 00:56:43 +01:00
Michele Caini
972470ad42 benchmark: minor changes 2020-03-24 22:40:39 +01:00
Michele Caini
f7e3a055fb registry: minor changes 2020-03-21 23:35:45 +01:00
Michele Caini
34f05fb8dc doc: updated wiki for meta (close #448) 2020-03-21 16:56:29 +01:00
Michele Caini
709fd34264 registry/storage: ::insert supports all types of iterators 2020-03-21 16:48:31 +01:00
Michele Caini
b888757092 entity/*: iterators review 2020-03-20 23:53:43 +01:00
Michele Caini
0f42827047 entity/*: stop using deprecated functions internally 2020-03-20 16:50:04 +01:00
Michele Caini
e69d1556e1 config: renamed ENTT_ENABLE_ETO to ENTT_IS_EMPTY 2020-03-20 00:04:26 +01:00
Michele Caini
141fbf7472 type_traits: deprecated entt::tag because of the more general purpose alternative entt::integral_constant 2020-03-19 23:41:49 +01:00
Michele Caini
c9a3ae8149 type_traits: added shortcut entt::integral_constant 2020-03-19 23:38:10 +01:00
Michele Caini
e16a8d29ea links: added the Vim of game engines (close #447) 2020-03-19 16:05:31 +01:00
Michele Caini
fff50d0e50 registry: workaround for an issue with MSVC 2020-03-19 16:00:11 +01:00
Michele Caini
360734b447 doc: workaround for some idiosyncracies of doxygen 2020-03-19 00:49:49 +01:00
Michele Caini
7e5edad32b registry: workaround for an issue of gcc7 2020-03-19 00:33:14 +01:00
Michele Caini
fc47b47850 doc: updated doc for empty types 2020-03-18 23:59:44 +01:00
Michele Caini
c7de058e1d storage/registry: empty types are no longer a thing 2020-03-18 00:11:53 +01:00
Michele Caini
0fff3c905c view: deprecated ::less, ::each returns only non-empty types now 2020-03-16 00:30:33 +01:00
Michele Caini
2fcb055c43 group: deprecated ::less, ::each returns only non-empty types now 2020-03-15 23:50:02 +01:00
Michele Caini
97e0d63102 storage: consume args for empty types in all cases 2020-03-13 23:08:59 +01:00
Michele Caini
5e04f0accd registry: strict check on ::insert (see #438) 2020-03-13 00:02:05 +01:00
Michele Caini
16835e3928 registry: get_or_assign -> get_or_emplace 2020-03-12 23:41:58 +01:00
Michele Caini
22e0ef1354 doc: updated examples, wiki and inline documentation 2020-03-12 23:33:08 +01:00
Michele Caini
0141dc519c doc: added similar projects (close #443) 2020-03-11 17:57:36 +01:00
Michele Caini
9aadc30b94 registry: disambiguate calls to ::assign and ::assign_or_replace (close #438) 2020-03-11 16:19:41 +01:00
Michele Caini
23a73fcb7c doc: suppressed some warnings due to missing parameters 2020-03-11 15:36:14 +01:00
Michele Caini
9a3b585110 registry: disambiguate calls to pool_handler<T>::construct (see #438) 2020-03-11 14:34:47 +01:00
Michele Caini
09ee46860a sparse_set: disambiguate calls to ::construct (see #438) 2020-03-11 00:07:41 +01:00
Michele Caini
d8f289182d storage: disambiguate calls to ::construct (see #438) 2020-03-11 00:05:04 +01:00
Michele Caini
dc8fa2153b registry: on_replace becomes on_update 2020-03-09 14:46:38 +01:00
Michele Caini
32fb335832 registry: added ::patch, reintroduced ::replace from arguments (close #437) 2020-03-09 14:34:28 +01:00
Michele Caini
58885854f1 doc: added a warning to registry::replace 2020-03-08 23:36:18 +01:00
Michele Caini
3e87788541 registry: ::replace always returns the component, no matter what 2020-03-08 16:42:17 +01:00
Michele Caini
5746df4d74 doc: added a note on registry::assign 2020-03-08 15:54:07 +01:00
Michele Caini
71d86c44e0 registry: cleanup 2020-03-08 00:56:00 +01:00
Michele Caini
c5e50289e1 workflow: unlock deploy to homebrew-entt (close #397) 2020-03-07 23:26:47 +01:00
Michele Caini
e62f1edada registry: minor changes 2020-03-07 23:26:39 +01:00
Michele Caini
50e8db28b8 minor changes all over the codebase (final) 2020-03-07 00:41:21 +01:00
Michele Caini
ef7c572018 core: define entt::id_type alias for ENTT_ID_TYPE (close #416) 2020-03-07 00:41:21 +01:00
Michele Caini
1e962754cc entity module: added utility.hpp, cleaned up fwd.hpp 2020-03-07 00:41:21 +01:00
Michele Caini
0240453b07 registry: review context variables 2020-03-07 00:41:21 +01:00
Michele Caini
38a80a95f2 registry: reduce instantiations 2020-03-07 00:41:21 +01:00
Michele Caini
b5e411d251 registry: removed deprecated functions 2020-03-07 00:41:21 +01:00
Michele Caini
71a623276e registry: removed deprecated overload for replace 2020-03-07 00:41:21 +01:00
Michele Caini
1e76703144 meta: removed deprecated functions 2020-03-07 00:41:21 +01:00
Michele Caini
6ffaf11226 helper: added a shortcut to invoke members on components from callbacks (close #385) 2020-03-07 00:41:21 +01:00
Michele Caini
fc0caec1a4 build system: updated version, now working on v3.4.0 2020-03-07 00:41:21 +01:00
Michele Caini
043f9a5025 updated single include file 2020-03-07 00:41:15 +01:00
Michele Caini
822264a65e workflow: --dry-run for the deploy.yml debut (see #397) 2020-03-07 00:30:24 +01:00
Michele Caini
8e9a6a4f06 registry: fixed a bug that affects late group initialization (close #440) 2020-03-07 00:30:21 +01:00
Michele Caini
76f3909ec9 workflow: update homebrew-entt (see #397) 2020-03-07 00:30:19 +01:00
Michele Caini
23e839b40e build system: updated install process (close #421) 2020-03-07 00:30:16 +01:00
Michele Caini
6a560fc7bf observer: use any<T...> rather than a fold expression with has<T> 2020-03-07 00:30:08 +01:00
Michele Caini
709d1c93a4 registry: fixed a bug that affects late group initialization (close #436) 2020-03-07 00:29:57 +01:00
Michele Caini
8d4b5f4bb7 sparse_set: remove copy ctor/assignment operator (use range-construct instead) 2020-03-07 00:11:30 +01:00
Paul Gruenbacher
9eb5a85e9e doc: update clone example to handle empty types (#441) 2020-03-07 00:09:19 +01:00
Paul Gruenbacher
e7521445e9 doc: update stamp example (#442) 2020-03-07 00:09:15 +01:00
Michele Caini
bb050e2660 actor: (has<T>(e) && ...) -> has<T...>(e) 2020-03-07 00:07:56 +01:00
Michele Caini
bc3b0eb491 links: added references to Chrysalis (project and blog post) 2020-03-07 00:06:39 +01:00
Michele Caini
7cea05d376 doc: updated documentation for snapshot archives (close #431) 2020-03-07 00:06:32 +01:00
Michele Caini
b8a3bdf6b5 build system: minor changes 2020-03-07 00:06:25 +01:00
Michele Caini
638b6dba17 build system: updated version, now working on v3.3.2 2020-03-06 23:56:55 +01:00
Michele Caini
50ba8c6c39 updated single include file 2020-02-28 23:27:20 +01:00
Michele Caini
94d15ebbef config: being empty isn't enough for ETO, type must be default constructible 2020-02-28 23:18:12 +01:00
Michele Caini
e150882231 doc: udpated doc (see #431) 2020-02-28 23:18:09 +01:00
Michele Caini
80a659c90c doc: typo 2020-02-28 23:18:03 +01:00
Michele Caini
17d96427ea registry: assign_or_replace works also with aggregates now (close #429) 2020-02-28 23:17:58 +01:00
Michele Caini
7fdda788af registry: minor changes (close #424) 2020-02-28 23:17:53 +01:00
Ezekiel Warren
182adbd9d9 Re-added bazel support (#430) 2020-02-28 23:17:45 +01:00
Michele Caini
4931c9cd9b build system: updated version, now working on v3.3.1 2020-02-28 23:17:24 +01:00
Michele Caini
a112409735 updated single include file (close #425) 2020-02-23 16:54:02 +01:00
Michele Caini
7aaa6dd986 build system: suppress a few other warnings here and there 2020-02-19 16:12:36 +01:00
Michele Caini
3c39cfe645 build system: trigger more warnings (at least with MSVC) and suppress as many as possible (close #420, close #394) 2020-02-19 15:01:13 +01:00
Michele Caini
6a46325e7e registry: deprecate ::clone/::stamp 2020-02-18 12:51:19 +01:00
Michele Caini
15c9688a5a entity module: minor changes 2020-02-18 11:50:33 +01:00
Michele Caini
d9f93ccc11 moved tags from entity/helper to core/type_traits (see #419) 2020-02-18 09:58:51 +01:00
Michele Caini
652e569afc registry: cleanup 2020-02-17 13:36:57 +01:00
Michele Caini
c55372459f view: cleanup 2020-02-17 13:36:46 +01:00
Michele Caini
09f36e32f7 type traits: added member_class and member_class_t 2020-02-17 08:18:58 +01:00
Michele Caini
688d435d8e meta: fixed a bug on meta_type::construct with no arguments (close #413) 2020-02-16 21:54:48 +01:00
Michele Caini
e7403d8551 registry: in-place ::replace, the signal no longer receives an extra argument (close #406) 2020-02-15 22:32:50 +01:00
Indiana Kernick
60039441a1 Remove UTF-8 BOM (#414) 2020-02-15 15:40:09 +01:00
Michele Caini
97f4414cc4 minor changes 2020-02-15 00:54:40 +01:00
Michele Caini
df9595bc0d build system: clean up 2020-02-14 23:15:26 +01:00
Michele Caini
93533b7bc6 build system: make it work properly (again) with clang-cl 2020-02-14 23:06:46 +01:00
Michele Caini
a99afa2ddf build system: make gtest compile (again) on macos 2020-02-14 22:56:37 +01:00
Michele Caini
1e651a5145 tests: code coverage 2020-02-14 17:32:05 +01:00
Michele Caini
79ecfa2573 build system: suppress deprecated warnings 2020-02-14 16:43:27 +01:00
Michele Caini
e2b676d54c cleanup 2020-02-13 12:30:01 +01:00
Michele Caini
2b73bf35b6 meta: meta_type_node::id -> meta_type_node::type_id 2020-02-13 12:05:45 +01:00
Michele Caini
2137b3a879 doc: added DungeonSlayer to links 2020-02-11 23:29:50 +01:00
Michele Caini
e52b3fd5bc meta: ::identifier renamed to ::alias, added meta_type::id to get the id of the underlying type (close #412) 2020-02-11 12:30:55 +01:00
Michele Caini
0dfd2aa714 build system: minor changes to make tests compile with VS 2020-02-10 22:57:48 +01:00
Michele Caini
5d63c4c981 storage: basic_storage no longer exists (close #411) 2020-02-10 22:49:23 +01:00
Michele Caini
84d3f9ab9a registry: added missing assert (close #409) 2020-02-10 22:46:49 +01:00
Michele Caini
1133dba9d8 attribute: correct include guard (close #410) 2020-02-10 22:45:30 +01:00
Michele Caini
cd2fdc2ffe build system: use cmake fetch content rather than external add 2020-02-10 22:43:42 +01:00
Michele Caini
57d017ed8e build system: the version is read from cmake rather than written 2020-02-10 22:25:35 +01:00
Michele Caini
3ad2c559f1 build system: better support for IDEs 2020-02-09 23:16:59 +01:00
Michele Caini
c3facfa925 build system: minor changes 2020-02-09 20:07:32 +01:00
Michele Caini
db8d9ebc72 suppress shadow warnings 2020-02-08 16:31:01 +01:00
Michele Caini
3aef00af18 registry: suppress warnings on ::replace for empty components (close #407, close #408) 2020-02-08 15:56:01 +01:00
Michele Caini
a4d576bae8 registry: visit functionality for context variables (close #390) 2020-02-08 15:34:32 +01:00
Michele Caini
9320365ef6 registry: const-correctness for ::visit 2020-02-08 15:34:28 +01:00
Michele Caini
0be7494042 group: added front/back (close #393) 2020-02-08 15:34:22 +01:00
Michele Caini
df55f338ca view: added front/back (see #393) 2020-02-08 15:34:18 +01:00
Michele Caini
8210efb548 delegate: suppress warnings on parameters used for tag dispatching 2020-02-08 15:34:14 +01:00
Michele Caini
43503e2fc9 test: enforce requirements for non default constructible components (close #405) 2020-02-08 15:34:08 +01:00
Michele Caini
448c3ae425 registry/storage: assign review 2020-02-08 15:34:03 +01:00
Michele Caini
f7684a8a3e cleanup/minor changes 2020-02-08 15:33:59 +01:00
Michele Caini
4f200ac71e cleanup 2020-02-08 15:32:09 +01:00
Michele Caini
4772559e8b test: code coverage 2020-02-02 22:12:41 +01:00
Michele Caini
a984ce5bba registry: temporary changes to remove args from assure 2020-02-02 21:51:13 +01:00
Michele Caini
eee8a338e2 doc: updated examples (close #401) 2020-02-02 20:52:14 +01:00
Michele Caini
8894c0ef48 typo 2020-02-01 01:01:03 +01:00
Michele Caini
c5b8577d94 meta: redefined constructors where it matters (close #404) 2020-02-01 00:59:23 +01:00
Michele Caini
ce9def4a56 registry: avoid redundant instantiations 2020-02-01 00:50:13 +01:00
Michele Caini
894601aad2 cleanup/suppress warnings 2020-01-31 23:40:52 +01:00
Michele Caini
285c91e81b config: ENTT_DISABLE_ASSERT no longer exists, ENTT_ASSERT can be redefined now (close #403) 2020-01-31 23:39:37 +01:00
Michele Caini
ba8ca93afc doc: updated the doc for the ecs part (close #390) 2020-01-31 23:32:09 +01:00
Michele Caini
ad0dab2493 registry: added ::visit to get all components in a registry of owned by an entity 2020-01-31 22:43:25 +01:00
Michele Caini
8b66316180 doc: updated README file 2020-01-31 22:42:36 +01:00
Michele Caini
da4ee38914 type_info: minor changes 2020-01-30 20:03:51 +01:00
Michele Caini
62fde229e2 cleanup 2020-01-29 00:26:38 +01:00
Michele Caini
676115d214 delegate/sigh: reduced number of instantiations, moved instantiations out of the way from sigh::publish 2020-01-28 12:20:52 +01:00
Michele Caini
f36d838df1 hashed_string: non-recursive helper (close #400) 2020-01-27 22:46:24 +01:00
Michele Caini
f32f3ab895 config: avoid using pretty function with gcc < 9 (see #396) 2020-01-25 23:19:38 +01:00
Michele Caini
fc0432df8c registry: minor changes 2020-01-24 23:52:39 +01:00
Michele Caini
797b5bcb53 type_info: force constexpr-ness (close #396) 2020-01-24 23:29:12 +01:00
Michele Caini
b816f203cd doc: minor changes (close #398) 2020-01-24 23:29:06 +01:00
Michele Caini
714e2f86a1 cleanup 2020-01-24 16:02:45 +01:00
Michele Caini
ff75085f15 doc: updated links 2020-01-23 22:55:03 +01:00
Michele Caini
dbc8b18b80 registry: added any<T...> (close #371) 2020-01-21 12:52:59 +01:00
Michele Caini
efb2bbe8b2 cleanup: removed entity/utility.hpp 2020-01-21 12:33:37 +01:00
Michele Caini
8278c8eedd doc: minor changes 2020-01-21 12:24:02 +01:00
Michele Caini
6f696a026b registry: callbacks receive the registry as first argument (better dependencies) 2020-01-20 16:09:25 +01:00
Michele Caini
f558797246 workaround for an issue of clang 6 2020-01-20 00:01:10 +01:00
Michele Caini
c8671d1c2b doc: updated signal.md (see #385) 2020-01-19 23:43:57 +01:00
Michele Caini
7fd41e48b9 sigh: support for unbound members 2020-01-19 19:18:33 +01:00
Michele Caini
409d5f5966 delegate: support for unbound members 2020-01-19 15:16:38 +01:00
Michele Caini
5d1802faf7 doc: updated links 2020-01-18 23:05:42 +01:00
Michele Caini
a580bac385 registry: range-assign with optional init function(s) 2020-01-18 01:11:30 +01:00
Michele Caini
c43214543f storage: removed batch construct by copy 2020-01-18 00:57:27 +01:00
Michele Caini
b3c568fb6f registry: faster group initialization 2020-01-16 00:02:22 +01:00
Michele Caini
b34fe3200c storage: batch construct by copy 2020-01-15 23:55:28 +01:00
Michele Caini
dada8dbdeb storage/registry: batch add no longer returns an iterator 2020-01-15 23:21:34 +01:00
Michele Caini
e7d4077065 storage/registry: batch add default-constructs the component 2020-01-15 23:07:35 +01:00
Michele Caini
b1e54bfd86 storage: minor changes 2020-01-15 22:42:17 +01:00
Michele Caini
85ad4c4766 registry (and a few others): callbacks no longer receive components, see #386 2020-01-13 23:11:24 +01:00
Michele Caini
3dce560759 test: updated benchmarks 2020-01-13 23:08:42 +01:00
Michele Caini
969b8f0a7a test: minor changes 2020-01-13 00:27:15 +01:00
Michele Caini
ba8e738f40 doc: updated ecs part 2020-01-13 00:12:22 +01:00
Michele Caini
4bc80fae8d storage: minor changes 2020-01-13 00:06:17 +01:00
Michele Caini
ee5156704d registry: ::assign to assign entities to an empty registry 2020-01-12 00:31:53 +01:00
Michele Caini
986cd03732 registry: added ::data() to get the list of entities of a registry 2020-01-11 23:56:50 +01:00
Michele Caini
937fdabaa9 algorithm: missing include (close #389) 2020-01-11 23:56:11 +01:00
Michele Caini
c0fa97510e minor changes that are aimed mainly at suppressing warnings 2020-01-11 23:06:30 +01:00
Michele Caini
2fc6fe442d workaround of an bug of gcc-7 2020-01-11 21:56:08 +01:00
Michele Caini
7ba14f5a57 registry: only opaque stamp is allowed, use assign/assign_or_replace for components 2020-01-11 01:23:57 +01:00
Michele Caini
352e4576fc registry: ::reset doesn't exist anymore, use ::remove and ::clear instead 2020-01-11 01:11:48 +01:00
Michele Caini
210eebc0dc sparse_set/storage: ::reset is now ::clear 2020-01-09 22:51:35 +01:00
Michele Caini
5904941361 registry: stable assign (close #386) 2020-01-09 22:06:33 +01:00
Michele Caini
b352815cf8 registry: minor chages 2020-01-07 23:58:23 +01:00
Michele Caini
38a2751cd9 tests: code coverage back to 100% 2020-01-07 00:16:46 +01:00
Michele Caini
6388607d11 doc: added PopHead to the list of showcases (close #384) 2020-01-06 23:54:05 +01:00
Michele Caini
469276b8be registry: create no longer accepts a list of default constructible types to assign to entities 2020-01-06 23:46:58 +01:00
Michele Caini
2a863ee851 registry: minor changes 2020-01-06 00:50:03 +01:00
Michele Caini
b6dae2fe57 doc: updated entity.md 2020-01-06 00:40:45 +01:00
Michele Caini
d202bd3e50 registry: create with hint (close #303) 2020-01-06 00:40:22 +01:00
Michele Caini
dc2e44b2c0 doc: added sequentity to the list of showcases 2020-01-06 00:39:33 +01:00
Michele Caini
32c481c28c doc: stomp -> stamp 2020-01-04 22:59:46 +01:00
Michele Caini
8519c99706 updated copyright 2020-01-04 00:17:16 +01:00
Michele Caini
5b1bac4c19 doc: more details on entt::null (close #375) 2020-01-02 23:58:12 +01:00
Michele Caini
0a95a0674b build system: the conan-center-index makes the custom deploy step useless (close #380) 2020-01-02 22:25:12 +01:00
Michele Caini
2f11f6dc37 workaround for an issue of MSVC 2020-01-01 22:39:01 +01:00
Michele Caini
af66274c72 registry: const/non-const review (close #381) 2020-01-01 22:29:13 +01:00
Michele Caini
c5679b208f registry: improved ::group 2019-12-31 16:45:49 +01:00
Michele Caini
020fc179a5 traits: to_integral uses static_cast now 2019-12-31 15:45:36 +01:00
Michele Caini
dc9c1fc762 doc: minor changes 2019-12-31 15:21:53 +01:00
Michele Caini
f0938d70b2 registry: stomp -> stamp 2019-12-31 00:54:10 +01:00
Michele Caini
072761c5ba updated doc 2019-12-31 00:37:52 +01:00
Michele Caini
8aacd4d022 aob: removed mod stuff 2019-12-29 15:53:52 +01:00
Michele Caini
b6f9ca0021 updated TODO 2019-12-29 15:36:36 +01:00
Michele Caini
a43f354511 doc: minor changes 2019-12-29 15:18:20 +01:00
Michele Caini
43766406ae registry/dispatcher/emitter: removed ::discard, updated test and doc 2019-12-29 15:16:12 +01:00
Michele Caini
37dd1ae363 registry: group reworking 2019-12-29 15:16:12 +01:00
Michele Caini
5a3effaef5 group: faster contains 2019-12-29 15:16:12 +01:00
Michele Caini
cd4bcce70f view: faster contains 2019-12-29 15:16:12 +01:00
Michele Caini
c1e7549b61 registry: group reworking 2019-12-29 15:16:12 +01:00
Michele Caini
036ef25da9 registry: uses views to initialize groups 2019-12-29 15:16:12 +01:00
Michele Caini
9884c37ef4 view: gets rid of filter tuple 2019-12-29 15:16:12 +01:00
Michele Caini
23069d76eb registry: minor changes 2019-12-29 15:16:12 +01:00
Michele Caini
b2d0e7fae2 registry: assure returns a reference now 2019-12-29 15:16:12 +01:00
Michele Caini
30a039a031 minor changes: shadow variables, dead doc, todo list 2019-12-29 15:16:12 +01:00
Michele Caini
8d67bb726c test: guarantee that entt::entity{} != entt::null (close #375) 2019-12-29 15:16:12 +01:00
Michele Caini
c4dec4cd4d meta: test review 2019-12-29 15:16:12 +01:00
Michele Caini
f17b975fb9 meta: meta_any support for non-copyable types (close #336) 2019-12-29 15:16:12 +01:00
Michele Caini
7a3b7593d0 doc: updated documentation 2019-12-29 15:16:12 +01:00
Michele Caini
bad342b840 test: lib plugin std cpp 2019-12-29 15:16:12 +01:00
Michele Caini
e3968a8f9d test: lib std cpp 2019-12-29 15:16:12 +01:00
Michele Caini
f577183c24 build system: BUILD_PLUGIN is no longer required, plugins are libs 2019-12-29 15:16:12 +01:00
Michele Caini
be58f2e68a minor changes 2019-12-29 15:16:12 +01:00
Michele Caini
99f81e82d5 build system: removed support for bazel (no longer maintained) 2019-12-29 15:16:12 +01:00
Michele Caini
7cfd3957de test_info:🆔 make the family-like fallback work across boundaries 2019-12-29 15:16:12 +01:00
Michele Caini
c51c88a17c include guards and macros in general: removed superfluous comments 2019-12-29 15:16:12 +01:00
Michele Caini
e09af98dc5 test: minor changes 2019-12-29 15:16:12 +01:00
Michele Caini
89635f6583 type_info:🆔 family-like fallback 2019-12-29 15:16:12 +01:00
Michele Caini
14034642f1 test: review 2019-12-29 15:16:12 +01:00
Michele Caini
4af7d975c1 type_id -> type info + allow also fully runtime ids 2019-12-29 15:16:12 +01:00
Michele Caini
d9884917fb registry: added discard to free explicitly a pool 2019-12-29 15:16:12 +01:00
Michele Caini
95fd4e4c99 emitter: added discard to free explicitly a pool 2019-12-29 15:16:12 +01:00
Michele Caini
9457a55910 dispatcher: added discard to free explicitly a pool 2019-12-29 15:16:12 +01:00
Michele Caini
56e7dd0de0 dispatcher::discard becomes dispatcher::clear 2019-12-29 15:16:12 +01:00
Michele Caini
f0dc882ae9 minor changes here and there 2019-12-29 15:16:12 +01:00
Michele Caini
acb70d4440 meta: uses type_id_v rather than other techniques 2019-12-29 15:16:12 +01:00
Michele Caini
167721bf8c removed ENTT_API from ENTT_OPAQUE_ID 2019-12-29 15:16:12 +01:00
Michele Caini
4f438e5228 family: back to the old-fashioned model 2019-12-29 15:16:12 +01:00
Michele Caini
0f0aeb6d47 meta: prepare migration to entt::type_id 2019-12-29 15:16:12 +01:00
Michele Caini
d1a6edad8a ENTT_OPAQUE_TYPE: to_integer -> to_integral 2019-12-29 15:16:12 +01:00
Michele Caini
388feb7edb docs: updated doxy.in 2019-12-29 15:16:12 +01:00
Michele Caini
962b068c92 test: pass NOMINMAX where cr.h is included 2019-12-29 15:16:12 +01:00
Michele Caini
a32373bc3a meta: updated tests, CR_UNLOAD isn't passed on close 2019-12-29 15:16:12 +01:00
Michele Caini
94a5a4ac1e doc: minor changes 2019-12-29 15:16:12 +01:00
Michele Caini
ed8eea12bd entt::component no longer exists 2019-12-29 15:16:12 +01:00
Michele Caini
83bea8b654 registry: uses type_id_v rather than families 2019-12-29 15:16:12 +01:00
Michele Caini
d4d2db228e minor changes: noexcept-ness review (close #372) 2019-12-29 15:16:12 +01:00
Michele Caini
f8b8c91fe8 type_id: sfinae friendly version to allow extreme customization 2019-12-29 15:16:12 +01:00
Michele Caini
8451301a5a dispatcher/emitter: constrained assure 2019-12-29 15:16:12 +01:00
Michele Caini
449b03f6bd type_id: built-in variadic accepts only single types 2019-12-29 15:16:12 +01:00
Michele Caini
3853ff725f dispatcher/emitter: better assure 2019-12-29 15:16:12 +01:00
Michele Caini
ee66e3ef9e added missing include 2019-12-29 15:16:12 +01:00
Michele Caini
2643500957 type_id: removed redundant check 2019-12-29 15:16:12 +01:00
Michele Caini
88467a87a4 emitter: uses type_id_v rather than a family 2019-12-29 15:16:12 +01:00
Michele Caini
d1cdeb4a2d dispatcher: uses type_id_v rather than a family 2019-12-29 15:16:12 +01:00
Michele Caini
f5ced7fe39 core: (customizable) type_id[_v] 2019-12-29 15:16:12 +01:00
Michele Caini
023267ecab static hashed_string::to_value -> hashed_string::value 2019-12-29 15:16:12 +01:00
Michele Caini
3d515a760c attribute.h: lib -> core 2019-12-29 15:16:12 +01:00
Michele Caini
026c5987dd suppress some warnings here and there 2019-12-29 15:16:12 +01:00
Michele Caini
84fb3694f2 test: meta and plugins 2019-12-29 15:16:12 +01:00
Michele Caini
169dcbcd74 coverage: enabled plugins 2019-12-29 15:16:12 +01:00
Michele Caini
d28b6fbf1e test: use MODULE rather than SHARED for plugins 2019-12-29 15:16:12 +01:00
Michele Caini
9f7a2ef84e updated TODO 2019-12-29 15:16:12 +01:00
Michele Caini
cc5ea60d2b test: minor changes (for code coverage) 2019-12-29 15:16:12 +01:00
Michele Caini
8bc63494bc hashed string: added missing include 2019-12-29 15:16:12 +01:00
Michele Caini
9acdeeed04 CI: enabled plugins 2019-12-29 15:16:12 +01:00
Michele Caini
d2cdb2a209 build system: refine macro SETUP_PLUGIN_TEST 2019-12-29 15:16:12 +01:00
Michele Caini
36bad31355 signal: updated fwd.hpp 2019-12-29 15:16:12 +01:00
Michele Caini
427587e591 test: ENTT_API_* definitions are set by means of cmake 2019-12-29 15:16:12 +01:00
Michele Caini
4f028d8201 test: prepare plugin stuff 2019-12-29 15:16:12 +01:00
Michele Caini
d59c052554 build system: added fungos/cr to the list of dependencies required to compile lib tests 2019-12-29 15:16:12 +01:00
Michele Caini
93ebe91bc5 test: removed useless FAIL() 2019-12-29 15:16:12 +01:00
Michele Caini
fadb8f695e tests: minor changes 2019-12-29 15:16:12 +01:00
Michele Caini
8bb1518d09 registry: (almost) transparent dll/.so support with ENTT_API 2019-12-29 15:16:12 +01:00
Michele Caini
e8d9d663a7 registry: removed superfluous friend declaration 2019-12-29 15:16:12 +01:00
Michele Caini
2d2648cf57 emitter: : (almost) transparent dll/.so support with ENTT_API 2019-12-29 15:16:12 +01:00
Michele Caini
231036784d dispatcher: (almost) transparent dll/.so support with ENTT_API 2019-12-29 15:16:12 +01:00
Michele Caini
882b91b221 family: review to make it work with dllimport/dllexport 2019-12-29 15:16:12 +01:00
Michele Caini
df346ab380 lib, test: minor changes 2019-12-29 15:16:12 +01:00
Michele Caini
c7b8e82ada meta: (almost) transparent dll/.so support with ENTT_API 2019-12-29 15:16:12 +01:00
Michele Caini
b8784863f2 meta: context no longer exists 2019-12-29 15:16:12 +01:00
Michele Caini
3f67054f03 meta: compare function shouldn't be static 2019-12-29 15:16:12 +01:00
Michele Caini
36d1b0a4bc emitter: updated inline doc 2019-12-29 15:16:12 +01:00
Michele Caini
748777b8eb registry: removed superfluous ::template from unset() 2019-12-29 15:16:12 +01:00
Michele Caini
acd8e0bce5 registry: updated ::prepare 2019-12-29 15:16:12 +01:00
Michele Caini
d2d068edff registry: removed superfluous ::template from type() 2019-12-29 15:16:12 +01:00
Michele Caini
e2a7a7ce20 test: cleanup 2019-12-29 15:16:12 +01:00
Michele Caini
b25b1c45fb named types (traits and macros) are no longer available 2019-12-29 15:16:12 +01:00
Michele Caini
c3b0fa6c93 registry no longer uses named types 2019-12-29 15:16:12 +01:00
Michele Caini
63a4e67174 cleanup 2019-12-29 15:16:12 +01:00
Michele Caini
88e37438fa emitter: const/non-const assure 2019-12-29 15:16:12 +01:00
Michele Caini
5be1bf7d82 meta no longer uses named types 2019-12-29 15:16:12 +01:00
Michele Caini
eb4689d2f1 dispatcher no longer uses named types 2019-12-29 15:16:12 +01:00
Michele Caini
e81549e5fd emitter no longer uses named types 2019-12-29 15:16:12 +01:00
Michele Caini
becaef36ff disabled tests for shared objects/named types 2019-12-29 15:16:12 +01:00
Michele Caini
6aefa40ca2 updated TODO (changes requried to get rid of named types) 2019-12-29 15:16:12 +01:00
Michele Caini
250ef50361 added attribute.h 2019-12-29 15:16:12 +01:00
Michele Caini
5a1af60357 view/group: all iterators are at least bidirectional (close #370) 2019-12-29 15:16:12 +01:00
Michele Caini
46db75308c test: modularized lib tests 2019-12-29 15:16:12 +01:00
Michele Caini
33f5e13b29 use std::for_each instead of std::for_each_n (the latter isn't supported by older compilers) 2019-12-29 15:16:12 +01:00
Michele Caini
54bb4797db cleanup 2019-12-29 15:16:12 +01:00
Michele Caini
7a14fbb221 registry: stomp doesn't work anymore with foreign registries 2019-12-29 15:16:12 +01:00
Michele Caini
18349f5ee4 small improvements 2019-12-29 15:16:12 +01:00
Michele Caini
22b93cdd0a meta: updated doc (see #361) 2019-12-29 15:16:12 +01:00
Michele Caini
63bc0b2ba1 entity: updated doc (close #364) 2019-12-29 15:16:12 +01:00
Michele Caini
c57a7c745d meta: improved perf and compilation time, reduced loc 2019-12-29 15:16:12 +01:00
Michele Caini
f2831b5f5c updated doc (close #363) 2019-12-29 15:16:12 +01:00
Michele Caini
96f793f91b meta_any: unifying assignment operator 2019-12-29 15:16:12 +01:00
Michele Caini
4e2a0d6e58 noexcept-ness review (close #362) 2019-12-29 15:16:12 +01:00
Michele Caini
442c7f1f09 meta: review 2019-12-29 15:16:12 +01:00
Michele Caini
dbff4af7c6 cleanup 2019-12-29 15:16:12 +01:00
Michele Caini
93b09836da updated workflow (close #359) 2019-12-29 15:16:12 +01:00
Michele Caini
1782dc1565 emitter: cleanup (close #360) 2019-12-29 15:16:12 +01:00
Michele Caini
cc16874d58 cleanup 2019-12-29 15:16:12 +01:00
Michele Caini
c8925b2ae3 using atomics is no longer the default: ENTT_NO_ATOMIC -> ENTT_USE_ATOMIC 2019-12-29 15:16:12 +01:00
Michele Caini
fc043b9fcd small perf improvements 2019-12-29 15:16:12 +01:00
Michele Caini
ea86d33bc1 meta: removed reset-all function (it was logically broken across boundaries) 2019-12-29 15:16:12 +01:00
Michele Caini
82f33b82e3 meta: allow assigning properties to opaque meta types 2019-12-29 15:16:12 +01:00
Michele Caini
c645cb83a2 meta: reset-all functionality (see #358) 2019-12-29 15:16:12 +01:00
Michele Caini
d6d79a2aa5 code coverage 2019-12-29 15:16:12 +01:00
Michele Caini
786568fd2f updated workflow 2019-12-29 15:16:12 +01:00
Michele Caini
434f77a058 sigh: review connection/scoped_connection 2019-12-29 15:16:12 +01:00
Michele Caini
02f777a143 cleanup 2019-12-29 15:16:12 +01:00
Michele Caini
8025a84aeb updated workflow 2019-12-29 15:16:12 +01:00
Innokentiy Alaytsev
c37a50d3b8 updated faq.md (#351) - close #348 2019-12-29 15:16:12 +01:00
Michele Caini
6dbbb265d1 registry: added range remove 2019-12-29 15:16:12 +01:00
Michele Caini
02ce2ff74c registry: multi component remove 2019-12-29 15:16:12 +01:00
Michele Caini
28e5267132 registry::stomp supports foreign registries (close #315) 2019-12-29 15:16:12 +01:00
Michele Caini
f498b8a049 registry::prepare: strictier check 2019-12-29 15:16:12 +01:00
Michele Caini
b31afe5c8c safer registry::prepare 2019-12-29 15:16:12 +01:00
Michele Caini
eac944dbea get rid of registry::skip_family_pools 2019-12-29 15:16:12 +01:00
Michele Caini
965b20c37a review: dispatcher::assure/emitter::assure 2019-12-29 15:16:12 +01:00
Michele Caini
fba85754d7 review: registry::clone 2019-12-29 15:16:12 +01:00
Michele Caini
3c69f98451 range registry::stomp is no longer available 2019-12-29 15:16:12 +01:00
Michele Caini
cad8a90124 spawning registry::create is no longer available 2019-12-29 15:16:12 +01:00
Michele Caini
b8d888b17f minor changes 2019-12-29 15:16:12 +01:00
Michele Caini
942d783e4e cleanup 2019-12-29 15:16:12 +01:00
Michele Caini
0e352cb466 single component registry::prepare with arguments (suitable for custom pools) 2019-12-29 15:16:12 +01:00
Michele Caini
50af38b952 registry::clone/stomp review (close #350) 2019-12-29 15:16:12 +01:00
Michele Caini
1459c59cd0 updated TODO 2019-12-29 15:16:12 +01:00
Michele Caini
e74f5b2991 cleanup/refactoring 2019-12-29 15:16:12 +01:00
Michele Caini
0dec05fd70 no longer _each (it was too ugly for me) 2019-12-29 15:16:12 +01:00
Michele Caini
3cff21b4d0 updated doc (close #349) 2019-12-29 15:16:12 +01:00
Michele Caini
c380da7214 range stomp is now named stomp_each for consistency 2019-12-29 15:16:12 +01:00
Michele Caini
e2bf903c49 registry::assign_each validates entities 2019-12-29 15:16:12 +01:00
Michele Caini
9cf64ba881 range destroy is now named destroy_each for consistency 2019-12-29 15:16:12 +01:00
Michele Caini
74d901b7ae registry: range assign 2019-12-29 15:16:12 +01:00
Michele Caini
b15cb46a6d now working on v3.3.0 2019-12-29 15:16:12 +01:00
Michele Caini
89dc76e3b2 doc: added SgOgl to the EnTT in Action list (close #378) 2019-12-29 15:12:13 +01:00
Michele Caini
000b7d2651 updated single include file 2019-12-19 15:14:33 +01:00
Michele Caini
9ffa372ba2 workaround for an issue of MSVC (close #373) 2019-12-19 09:19:37 +01:00
Michele Caini
510cfcf1fc now working on v3.2.2 2019-12-19 09:18:41 +01:00
Michele Caini
e7f6d93a1e cleanup 2019-12-01 15:59:25 +01:00
Michele Caini
a17c449075 observer: minor changes 2019-12-01 15:58:05 +01:00
Michele Caini
c4da7a87f9 typo 2019-12-01 15:57:51 +01:00
Michele Caini
4a8b2f826d cleanup 2019-12-01 15:46:28 +01:00
Stefano Fiorentino
4901e4fb80 adding git_shallow to cmake deps helps reducing building time from scratch (#367)
very useful in CI/CD pipelines
2019-12-01 15:45:20 +01:00
Michele Caini
ce3a0157cb updated version.h to v3.2.1 2019-11-26 11:20:54 +01:00
Michele Caini
a146b06e4b updated single include file to v3.2.1 (close #366) 2019-11-26 11:18:41 +01:00
Michele Caini
dc78a3e56d version: 3.2.1 2019-11-26 11:17:13 +01:00
Michele Caini
86c524dade fix: sorting empty types (close #365) 2019-11-26 11:16:02 +01:00
Innokentiy Alaytsev
6889edcfc4 meta, fix: meta_prop::next lazy initialization 2019-11-26 11:11:42 +01:00
Michele Caini
3cd5934bad typo 2019-11-26 11:11:26 +01:00
Michele Caini
064104f23a suppress **all** shadow warnings (close #346) 2019-11-26 11:11:19 +01:00
Michele Caini
e80b1c264c family: it no longer dacays types 2019-11-26 11:11:13 +01:00
Michele Caini
03c3ee514b updated doc 2019-10-25 00:03:58 +02:00
Michele Caini
c93d0f0d59 registry::prepare to force create pools explicitly 2019-10-24 23:10:03 +02:00
Michele Caini
85793d38bc meta: a static assertion forbids using non-copyable types with meta_any (close #336) 2019-10-24 22:55:07 +02:00
David Demelier
49b4a85d55 FAQ: add note about non-copyable objects (#344) 2019-10-24 14:59:22 +02:00
Michele Caini
5e8a9340f1 meta: added meta_type::remove_extent (close #345) 2019-10-23 23:29:25 +02:00
Michele Caini
2b97c01bd6 named_type_traits<Type>::value -> named_type_traits_v<Type> 2019-10-21 22:52:49 +02:00
Michele Caini
39e3a5a708 make macros require a trailing semicolon 2019-10-21 14:23:22 +02:00
Michele Caini
df13d993f7 test: more on type_traits 2019-10-21 13:43:51 +02:00
Michele Caini
36c62763e5 updated TODO 2019-10-20 18:45:49 +02:00
Michele Caini
ad5651ffb2 ENTT_DISABLE_ETO to disable empty type optimization (close #330) 2019-10-20 17:32:10 +02:00
Michele Caini
717b091b49 meta: internal and external indexing to disambiguate property overloads 2019-10-20 15:44:53 +02:00
Michele Caini
4376bbe40b workaround for an issue with clang 6 2019-10-19 22:08:11 +02:00
Michele Caini
2382d2e21c meta: invocable properties (aka annotations - see #299) 2019-10-19 16:25:35 +02:00
Michele Caini
520ccfcd06 meta: support tuple as properties 2019-10-19 16:09:03 +02:00
Michele Caini
0bdc5dfe95 minor changes: make_index_sequence -> index_sequence_for 2019-10-19 15:54:32 +02:00
Michele Caini
6a656a1b0a type_traits: updated choice utility (template variable) 2019-10-19 15:51:27 +02:00
Michele Caini
5ad4079dbf meta: std::get<1>-table properties are no longer accepted, only std::pair is supported 2019-10-19 15:19:58 +02:00
Innokentiy Alaytsev
bfa46b795f Property list (#338)
* Fix typo in comment
* Implemented a function for adding a list of properties to meta-item
2019-10-19 15:13:43 +02:00
Michele Caini
ecaa9c275c typo 2019-10-18 21:45:17 +02:00
Michele Caini
93fd1757f8 meta: more on properties (close #341) 2019-10-18 17:30:32 +02:00
Michele Caini
71d0958398 type_traits: added support for the choice trick 2019-10-18 16:38:23 +02:00
Michele Caini
ed89d94d7a meta: support for key-only properties 2019-10-17 17:23:25 +02:00
Stephan Z
135132e5f0 Snapshot loader can auto-update entities stored in maps now (#335) - close #334
* Detect if member variable is of type map and update the contained entities if needed
* issue 334: tests for identifier update on maps in snapshots
2019-10-16 23:35:29 +02:00
Michele Caini
1ad75f5c1b meta: updated doc (close #324) 2019-10-16 13:43:29 +02:00
Michele Caini
21c6f9e394 meta: updated documentation 2019-10-16 13:43:29 +02:00
Michele Caini
5a7e954aee meta: context review 2019-10-16 13:43:29 +02:00
Michele Caini
c1117e260c meta: meta_node<>::ctx -> meta_node<>::global 2019-10-16 13:43:29 +02:00
Michele Caini
b0ea150e94 meta: properties can be also runtime objects 2019-10-16 13:43:29 +02:00
Michele Caini
0e3bdc02ea meta: meta_factory::type supports named types (the identifier isn't required in this case) 2019-10-16 13:43:29 +02:00
Michele Caini
e5a075a329 meta: minor changes 2019-10-16 13:43:29 +02:00
Michele Caini
30c7a64619 meta: simplified T::prop 2019-10-16 13:43:29 +02:00
Michele Caini
ab12f29ebf meta: introduce extended meta factory 2019-10-16 13:43:29 +02:00
Michele Caini
a0c3a82c76 meta: cleanup and renaming 2019-10-16 13:43:29 +02:00
Michele Caini
085a281f8a meta: some tests across boundaries 2019-10-16 13:43:29 +02:00
Michele Caini
1f871c24b9 meta: plug-and-play mode 2019-10-16 13:43:29 +02:00
Michele Caini
9f46b51985 minor changes 2019-10-16 13:43:29 +02:00
Michele Caini
fc572b8717 updated TODO 2019-10-16 13:43:29 +02:00
Michele Caini
4404601fa3 meta: tests 2019-10-16 13:43:29 +02:00
Michele Caini
faf7e28119 meta: added meta context object 2019-10-16 13:43:29 +02:00
Michele Caini
0303facfd9 updated TODO 2019-10-16 13:43:29 +02:00
Michele Caini
86e056a736 meta: added underlying context 2019-10-16 13:43:29 +02:00
Michele Caini
75105dc1fc meta: cleanup 2019-10-16 13:43:29 +02:00
Michele Caini
14b4979c98 added is_equality_comparable[_v] trait 2019-10-16 13:43:29 +02:00
Michele Caini
f956c64765 meta: doc 2019-10-16 13:43:29 +02:00
Michele Caini
8b3f954ad8 meta: cleanup 2019-10-16 13:43:29 +02:00
Michele Caini
a013cfcd1e meta_type::meta is no longer available 2019-10-16 13:43:29 +02:00
Michele Caini
65553e6c43 meta_type::remove_pointer returns a pointer to an underlying node now 2019-10-16 13:43:29 +02:00
Michele Caini
401c881c00 meta_prop::meta is no longer available 2019-10-16 13:43:29 +02:00
Michele Caini
cf0e4d24a1 meta_func::meta is no longer available 2019-10-16 13:43:29 +02:00
Michele Caini
21810f3b39 meta_data::meta is no longer available 2019-10-16 13:43:29 +02:00
Michele Caini
0b211ab0ba meta_dtor::meta is no longer available 2019-10-16 13:43:29 +02:00
Michele Caini
30c7cf3512 meta_ctor::meta is no longer available 2019-10-16 13:43:29 +02:00
Michele Caini
bf8839a560 meta_base::meta is no longer available 2019-10-16 13:43:29 +02:00
Michele Caini
818998c532 meta_conv::meta is no longer available 2019-10-16 13:43:29 +02:00
Michele Caini
98f54029d0 some consts here and there 2019-10-16 13:43:29 +02:00
Michele Caini
d41f2c138b minor changes 2019-10-16 13:43:29 +02:00
Michele Caini
50f07a6a0d meta: cleanup 2019-10-16 13:43:29 +02:00
Michele Caini
b10116febb review: cache resource_type and id_type 2019-10-16 13:43:29 +02:00
Michele Caini
17b5d732e4 cleanup 2019-10-16 13:43:29 +02:00
Michele Caini
5b16b1d827 entt::resource_cache -> entt::cache 2019-10-16 13:43:29 +02:00
Michele Caini
e5fe962130 entt::resource_handle -> entt::handle 2019-10-16 13:43:29 +02:00
Michele Caini
00f03d9bb7 entt::resource_loader -> entt::loader 2019-10-16 13:43:29 +02:00
Michele Caini
f7c285af20 minor changes 2019-10-16 09:14:08 +02:00
Michele Caini
f6e3121c76 GH sponsorship 2019-10-08 22:56:26 +02:00
Michele Caini
a95aa81850 utility: overloaded and y_combinator 2019-10-01 15:02:18 +02:00
Michele Caini
ffa5825658 cleanup 2019-10-01 15:01:56 +02:00
Michele Caini
df5b90cc7c nested groups: documentation 2019-09-30 00:20:02 +02:00
Michele Caini
9dde644fd0 nested groups: impl + tests 2019-09-30 00:19:17 +02:00
Michele Caini
d525a1536c sink::[before|disconnect]: const void * -> Type * 2019-09-30 00:11:07 +02:00
Michele Caini
54f18f3f0d delegate/sink: pointer payload 2019-09-29 23:40:03 +02:00
Michele Caini
ce4f26a5d5 minor changes 2019-09-29 21:43:30 +02:00
Guillaume Haerinck
177a7429f1 [doc] Add link to Mirror lasers & Robots project (#329) 2019-09-29 21:31:49 +02:00
Michele Caini
f672d734f9 delegate: built-in support for pointer payload 2019-09-29 00:46:29 +02:00
Michele Caini
faf5a38f1c sink: before/disconnect and const void * 2019-09-28 22:56:47 +02:00
Michele Caini
03c4267b84 process: tests with both a complex data type and a fundamental type (close #326) 2019-09-28 00:25:25 +02:00
Michele Caini
ab08621808 updated .gitignore 2019-09-28 00:17:41 +02:00
Michele Caini
d06c0e5c5d updated doc 2019-09-28 00:12:47 +02:00
Griffin Downs
32e76298e4 Add vcpkg installation instructions (#327) 2019-09-28 00:08:38 +02:00
Michele Caini
752163a5c0 workaround for an issue of VS2019 (close #314) 2019-09-27 23:49:43 +02:00
Michele Caini
6568fa23f8 updated TODO 2019-09-27 23:06:26 +02:00
Michele Caini
9c69288304 added more showcases (close #328) 2019-09-27 23:03:45 +02:00
Michele Caini
3a3346e750 typo 2019-09-26 23:32:25 +02:00
Michele Caini
47ab73d9a4 updated doc 2019-09-26 23:03:44 +02:00
Michele Caini
9555385325 updated list of contributors 2019-09-26 16:11:19 +02:00
xiss burg
f80a03afc7 This should allow any type to be used as Delta... (#325)
* This should allow any type to be used as Delta, beyond native numerical types.
* Why write more code than you have to?
2019-09-26 16:09:56 +02:00
Michele Caini
c1b64770d1 updated tests 2019-09-25 23:54:53 +02:00
Michele Caini
400f106d62 updated coverage.yml 2019-09-25 13:52:39 +02:00
Michele Caini
1cc20716ae codecov badge 2019-09-25 12:58:43 +02:00
Michele Caini
fc7d123871 tests: review 2019-09-25 12:54:17 +02:00
Michele Caini
2a8a014ad0 tests: review 2019-09-25 12:37:20 +02:00
Michele Caini
861f452d26 remove coveralls 2019-09-25 11:57:48 +02:00
Michele Caini
64a7d5e4fd codecov 2019-09-25 11:57:29 +02:00
Michele Caini
7c45423969 GH actions: reattach HEAD (workaround for an issue with the checkout action) 2019-09-25 10:13:13 +02:00
Michele Caini
480f70d7e2 GH actions: badges 2019-09-24 17:10:43 +02:00
Michele Caini
7f182896ca deleted appveyor/travis files 2019-09-24 17:01:45 +02:00
Michele Caini
1319fe2eb5 GH actions: conan 2019-09-24 16:45:26 +02:00
Michele Caini
f5c231aa80 GH actions: split CI and coveralls 2019-09-24 11:41:22 +02:00
Michele Caini
84d468333a github actions 2019-09-24 11:36:33 +02:00
Michele Caini
dfdbb0a061 class -> struct 2019-09-24 00:12:49 +02:00
Michele Caini
27365abbe3 registry: always assure and mutable list of pools 2019-09-23 23:44:14 +02:00
Michele Caini
f3aed46c94 minor changes 2019-09-23 23:16:29 +02:00
Michele Caini
7e0ea176cf cleanup 2019-09-23 22:58:47 +02:00
Michele Caini
791e13e7bf updated README 2019-09-23 16:01:50 +02:00
Michele Caini
9dff3ac749 sigh::disconnect and sigh::before support for pointers to instances 2019-09-22 23:42:04 +02:00
Michele Caini
45f207164d minor changes 2019-09-22 16:11:09 +02:00
Michele Caini
bea6f3ec14 sigh: filter out null opaque pointers 2019-09-22 15:19:27 +02:00
Michele Caini
1edc883ca2 cleanup 2019-09-21 17:00:44 +02:00
Michele Caini
116825d604 slightly faster sparse_set::arrange (apply permutation in O(N) now) 2019-09-21 15:29:11 +02:00
Michele Caini
26bc5ef091 workaround for an issue of VS 2019-09-20 17:27:52 +02:00
Michele Caini
8c228287aa doc: sink::before 2019-09-20 15:22:19 +02:00
Michele Caini
5c7c682d41 test: sink::before 2019-09-20 15:20:31 +02:00
Michele Caini
bfc2eca041 sink::before (overloaded function) 2019-09-20 14:53:10 +02:00
Michele Caini
b043b48e6e sparse_set::arrange: more tests (see #323) 2019-09-20 08:33:31 +02:00
Michele Caini
d7c03d7356 fixed an issue with sparse_set::arrange (close #323) 2019-09-19 23:50:30 +02:00
Michele Caini
c41f6aebf4 sorting: more tests 2019-09-19 22:39:13 +02:00
Michele Caini
5e6cda7c5e registry: fixed signal race on groups (close #320) 2019-09-19 14:09:53 +02:00
Carl Findahl
9c71b53abc Add namespace qualifier in CMake (close #321) (#322) 2019-09-19 13:28:33 +02:00
Michele Caini
3f96e04a7b workaround for an issue with clang 6 2019-09-18 23:16:45 +02:00
Michele Caini
90eeeedf52 view supports exclusion list 2019-09-18 14:32:58 +02:00
Michele Caini
6649362fec minor changes 2019-09-18 00:04:45 +02:00
Michele Caini
39c8889585 cleanup 2019-09-18 00:04:22 +02:00
Michele Caini
b5b1a64f0c typo 2019-09-18 00:04:07 +02:00
Michele Caini
cd108b5f57 prepare view for exclusion list 2019-09-17 23:26:54 +02:00
Michele Caini
780f3f8552 updated TODO list 2019-09-17 16:53:52 +02:00
Michele Caini
afea5eb69e added @suVrik to the list of contributors 2019-09-17 16:49:36 +02:00
Michele Caini
b72cf5d364 review: observer 2019-09-17 16:48:54 +02:00
Andrej Suvoraŭ
c133686dde Fix entt::collector::where (#319)
* fix observer
* add chained entt::collector::where test
2019-09-17 16:02:11 +02:00
Michele Caini
e216fa98ef cleanup 2019-09-16 22:37:38 +02:00
Michele Caini
8f9d8e188f updated README 2019-09-16 15:51:00 +02:00
Michele Caini
800751cbe0 sorting no longer requires allocations and is much faster 2019-09-16 15:38:34 +02:00
Michele Caini
14bc73cde9 swap accepts entities, no longer raw positions 2019-09-14 17:49:30 +02:00
Michele Caini
41307046be updated doc 2019-09-14 17:47:24 +02:00
Michele Caini
c259c79384 typo 2019-09-12 23:01:49 +02:00
Michele Caini
49f69facaf cleanup 2019-09-12 22:52:41 +02:00
Michele Caini
da2b6acf91 minor changes - code coverage 2019-09-12 22:34:03 +02:00
Michele Caini
fbdbe848c5 workaround for an issue of VS2017 (close #316) 2019-09-12 22:11:08 +02:00
Michele Caini
cc41caede9 multi-component [registry|view|group]::empty 2019-09-12 14:16:06 +02:00
Michele Caini
ee373eb6fb multi-component registry::shrink_to_fit 2019-09-11 23:12:14 +02:00
Michele Caini
d4b18b1e27 multi-component registry::reserve 2019-09-11 23:10:24 +02:00
Michele Caini
94e2fe2cbb make empty components eat arguments on construction 2019-09-11 22:56:35 +02:00
Michał Janiszewski
c93658ee04 Use Ninja on AppVeyor (#310)
This brings up improved compilation speed and saner error messages.
2019-09-11 22:24:05 +02:00
Michele Caini
ad7ee0b716 mark cmake project explicitly as C++ (see #309) 2019-09-10 23:02:22 +02:00
Michele Caini
b2fad7a567 added dispatch::discard to clear pools of events (close #312) 2019-09-10 22:55:03 +02:00
Michele Caini
e80adc2799 cmake support for clang users on Windows (see #311) 2019-09-10 16:38:38 +02:00
Michele Caini
ac111224ae meta: all function arguments are taken by alias (close #301) 2019-09-10 16:10:09 +02:00
Michele Caini
0813bb1a28 updated doc 2019-09-10 16:10:09 +02:00
Michele Caini
4d1ad8f749 meta_handle no longer exposes try_cast 2019-09-10 16:10:09 +02:00
Michele Caini
80b444e531 added meta_any constructor for the unmanaged object taken from a meta_handle 2019-09-10 16:10:09 +02:00
Michele Caini
3a6468cd0a disable BUILD_MOD for the CI 2019-09-10 15:18:28 +02:00
Michele Caini
c9fdb215f3 C language required for duktape (see BUILD_MOD option for more details) 2019-09-10 15:12:59 +02:00
Michał Janiszewski
85ff5f2d10 Mark CMake project explicitly as C++ (#309)
This prevents checking of C compiler
2019-09-10 14:31:12 +02:00
Michele Caini
be3597524f added a static_assert in a test to suppress a warning from GCC 2019-09-08 22:53:48 +02:00
Michele Caini
5717dbda4f added [[maybe_unused]] to suppress a warning from GCC 2019-09-08 22:50:51 +02:00
Michele Caini
588eec4672 added meta_type::compare, meta_any no longer has to store aside comparison functions 2019-09-08 22:44:06 +02:00
Michele Caini
cc3d0d8211 no more references to the prototype class (close #307) 2019-09-08 00:11:44 +02:00
Michele Caini
1550efaf7e stomp & spawn: const source registry (close #308) 2019-09-08 00:09:43 +02:00
Michele Caini
007300b881 sigh: ordered calls 2019-09-08 00:05:26 +02:00
Michele Caini
454f072f13 review stomp & spawn (close #306) 2019-09-06 17:21:07 +02:00
Michele Caini
b3be6c75c3 cleanup 2019-09-06 16:42:42 +02:00
Michele Caini
f8774f314b sink::disconnect accepts also opaque pointers 2019-09-06 08:19:28 +02:00
Michele Caini
3db35ad343 added openblack to the links 2019-09-06 08:19:28 +02:00
Michele Caini
0e42a779e2 meta_any uses reference_wrapper instead of as_alias_t for aliasing 2019-09-06 08:19:28 +02:00
Michele Caini
d34e829811 perf improvement 2019-09-06 08:19:28 +02:00
Michele Caini
ebd988702e relaxed constraints on the order of types in the group definition 2019-09-06 08:19:28 +02:00
Michele Caini
1232398742 now working on EnTT v3.2.0 2019-09-06 08:19:28 +02:00
Michele Caini
6dbcd47143 updated single file 2019-09-06 08:18:34 +02:00
Michele Caini
0e07482e26 ready to cut v3.1.1 2019-09-05 15:24:08 +02:00
Michele Caini
6bb4800ecd fix batch creation (close #305) 2019-09-05 15:24:03 +02:00
Michele Caini
37e1ac71b0 minor changes 2019-09-05 15:22:24 +02:00
Michele Caini
869f96816c updated doc 2019-09-05 15:21:45 +02:00
Michele Caini
35a7008444 added noexcept specifier 2019-09-03 23:39:38 +02:00
Michele Caini
67f80ee111 the default ctor of entt::meta_factory should be public 2019-09-03 23:31:43 +02:00
Michele Caini
083a58753b typo 2019-09-03 23:31:39 +02:00
Michele Caini
b652357a5c review: group::sort 2019-09-02 16:48:47 +02:00
Michele Caini
49a52140b0 minor changes 2019-09-02 16:34:38 +02:00
Michele Caini
e37f84a227 avoid taking the position twice 2019-09-02 16:23:11 +02:00
Nicki
50fc83d478 Update AUTHORS (#302)
He's one of contributors to the idea of nested groups!! :)
2019-08-30 09:49:46 +02:00
Michele Caini
a3da1c54eb updated single file 2019-08-29 16:01:26 +02:00
Michele Caini
b8471e3cf1 algorithm: radix sort 2019-08-27 23:42:58 +02:00
Michele Caini
4bd645d5c6 updated links 2019-08-26 16:57:30 +02:00
Michele Caini
83446c0694 updated sparse_set interface 2019-08-26 15:01:50 +02:00
Michele Caini
b4c30fc07b cleanup 2019-08-26 14:54:15 +02:00
Michele Caini
8325f5bbae runtime_view no longer uses sparse_set<...>::extent() 2019-08-26 14:54:15 +02:00
Michele Caini
9eb1196526 multi-component view no longer uses sparse_set<...>::extent() 2019-08-26 14:54:15 +02:00
Michele Caini
5fe5d4b6fc runtime_view doesn't use sparse_set<...>::data() anymore 2019-08-26 14:54:15 +02:00
Michele Caini
34af44b8d3 updated doc (close #298) 2019-08-26 14:53:21 +02:00
Michele Caini
643a20fec3 minor changes 2019-08-25 16:52:59 +02:00
Michele Caini
576b931090 meta: updated doc (close #297) 2019-08-25 14:50:12 +02:00
Michele Caini
2cc1f044df constructor to create actors from existing entities (close #296) 2019-08-23 15:54:53 +02:00
Michele Caini
c651392643 removed prototype and dependency (with connect/disconnect) 2019-08-23 15:02:55 +02:00
Michele Caini
9a669176ac workaround for an ICE with VS2019 2019-08-22 23:53:34 +02:00
Michele Caini
b902831db8 cleanup 2019-08-22 23:31:28 +02:00
Michele Caini
90a1de383a more tests 2019-08-22 18:35:23 +02:00
Michele Caini
83f9d42d31 registry: stomp and spawn 2019-08-22 18:03:29 +02:00
Michele Caini
94136531a5 added type_list_size and type_list_size_v 2019-08-22 17:59:15 +02:00
Michele Caini
b8b1e6ba62 registry::stomp: registry & -> basic_registry & 2019-08-21 23:27:35 +02:00
Michele Caini
d6911337f3 added storage::batch overload for copy construction 2019-08-21 23:23:21 +02:00
Michele Caini
d2cbb72490 cleanup 2019-08-21 23:22:32 +02:00
Michele Caini
c835b4d363 updated doc 2019-08-21 17:44:11 +02:00
Michele Caini
ece4480200 batch creation returns iterators and no longer raw pointers 2019-08-21 17:36:56 +02:00
Michele Caini
57f8d90e38 updated README 2019-08-21 17:30:56 +02:00
Michele Caini
da2b2701fe minor changes 2019-08-21 16:57:38 +02:00
Michele Caini
6d7fba3abf updated README 2019-08-21 15:27:29 +02:00
Ezekiel Warren
90798c161b Bazel Support (#287) (#291) 2019-08-21 15:11:29 +02:00
Michele Caini
65e270ff57 minor changes 2019-08-21 14:52:58 +02:00
Michele Caini
4912e19281 workaround for an issue of VS2019 2019-08-20 17:14:09 +02:00
Michele Caini
6402564f44 minor changes 2019-08-20 16:59:49 +02:00
Michele Caini
a06d5dd7bb registry: updated signatures for callbacks, deprecated dependency 2019-08-20 16:52:30 +02:00
Michele Caini
15e7486ca3 appveyor: support for VS2019 2019-08-19 17:58:22 +02:00
Michele Caini
ac462cfce9 workaround for an issue of VS2019 2019-08-19 17:56:28 +02:00
Michele Caini
d921306dd8 workaround for an issue of VS2019 2019-08-19 17:49:55 +02:00
Michele Caini
05417705ed removed useless move(s) 2019-08-19 17:39:46 +02:00
Michele Caini
1c7d9e3d75 signals meet references (close #289) 2019-08-18 15:21:29 +02:00
Ezekiel Warren
97dd928ca4 benchmark to use entt::component (#290)
* benchmark to use entt::component
* updated list of contributors
2019-08-18 15:04:10 +02:00
Michele Caini
03949f7d60 fixed registry::loader, destroyed is set to null as expected 2019-08-17 16:13:28 +02:00
Michele Caini
effe477351 perf improvement 2019-08-17 15:51:22 +02:00
Michele Caini
12ac858242 cleanup 2019-08-17 15:26:04 +02:00
Michele Caini
eec1937f52 updated entt::null comparison functions 2019-08-17 14:51:14 +02:00
Michele Caini
906cd48fb7 version-less entt::null (close #288) 2019-08-16 15:26:36 +02:00
Michele Caini
78beecf6f1 meta: removed wrong noexcept 2019-08-16 00:41:54 +02:00
Michele Caini
06a0646541 registry::stomp: tests + bug fixing 2019-08-15 15:38:47 +02:00
Michele Caini
0499a6c6f9 deprecated prototype/documented registry::stomp 2019-08-14 15:39:49 +02:00
Michele Caini
0e62f2ee85 updated list of showcases 2019-08-14 15:30:54 +02:00
Michele Caini
2ba4c36af0 registry::stomp (to be tested yet) 2019-08-13 15:58:26 +02:00
Michele Caini
688e6ad79f minor changes 2019-08-12 17:52:13 +02:00
Michele Caini
f8ee0ce185 fixed typo 2019-08-12 17:20:20 +02:00
Michele Caini
a226e06ae8 fixed typo 2019-08-12 15:57:59 +02:00
Michele Caini
e0e51b51b7 added exclusion list to registry::clone (close #286) 2019-08-12 15:43:28 +02:00
Michele Caini
9e9e3d43a8 updated doc 2019-08-11 23:46:20 +02:00
Michele Caini
7691a9bdad entt::component is now available 2019-08-11 17:21:30 +02:00
Michele Caini
22020cae49 doc: minor changes 2019-08-11 15:57:45 +02:00
Michele Caini
6cd910b0f6 added a test to meta to show how to set/get plain variables (close #284) 2019-08-11 15:37:48 +02:00
Michele Caini
b5e9811063 updated doc 2019-08-10 23:42:12 +02:00
Michele Caini
7668c7dd00 updated TODO 2019-08-09 16:12:55 +02:00
Michele Caini
d71f743e85 meta: updated documentation 2019-08-09 16:06:50 +02:00
Michele Caini
73ef0222ac tests for meta policies 2019-08-09 00:40:37 +02:00
Michele Caini
6152387096 meta: policies 2019-08-08 23:45:19 +02:00
Michele Caini
b93ffe3b44 workaround for a bug of clang (close #281) 2019-08-08 23:42:28 +02:00
Michele Caini
478eb7c5b5 minor changes 2019-08-08 17:04:45 +02:00
Michele Caini
6c40d8bd8b updated links 2019-08-08 15:28:33 +02:00
Michele Caini
7026fe4d5a meta: review dtor policy 2019-08-06 00:32:29 +02:00
Michele Caini
9a4491dc50 workaround for a bug of gcc7 2019-08-05 14:40:11 +02:00
Michele Caini
0d835e5014 workaround for an issue of gcc7 2019-08-05 14:29:55 +02:00
Michele Caini
29b5ffb58d rewritten self-contained lambda 2019-08-05 14:19:56 +02:00
Michele Caini
a179ec485b minor changes 2019-08-05 09:50:52 +02:00
Michele Caini
f220a577e0 meta: review 2019-08-05 09:50:45 +02:00
Michele Caini
b22b1d4794 meta: prevent aliasing on prop with future changes 2019-08-04 23:03:31 +02:00
Michele Caini
d2d19e3fbc fixed typo 2019-08-04 23:03:00 +02:00
Michele Caini
19ef290499 minor changes 2019-08-01 14:52:28 +02:00
Michele Caini
f6584b45ed doc: fixed typo 2019-07-31 14:17:24 +02:00
Michele Caini
bad97a8b5b meta system:
* perf improvements
* meta_any::try_cast
* meta_any is void-friendly
* meta_any support for unmanaged objects
* general cleanup
2019-07-28 17:08:56 +02:00
Michele Caini
7116df15d6 FAQ: fixed typo - thanks @huwpascoe and @Kerndog73 2019-07-28 17:08:31 +02:00
Michele Caini
ffbb018d12 updated FAQ 2019-07-22 14:47:08 +02:00
Michele Caini
a4dcdfc403 updated FAQ 2019-07-13 00:14:33 +02:00
Michele Caini
87d901b1ae is now possible to sort non-owning groups using a custom comparison function 2019-07-12 15:41:07 +02:00
Michele Caini
9126651cb9 added the possibility to sort free instances for owned types 2019-07-11 14:46:25 +02:00
Michele Caini
3996ce8ce5 test: storage::sort for ranges 2019-07-10 15:00:00 +02:00
Michele Caini
6340423b32 updated doc 2019-07-10 14:35:38 +02:00
Michele Caini
0d921dc1fc added support for free/member functions to meta_conv 2019-07-10 14:29:17 +02:00
Michele Caini
25afea4f9c meta: setters and getters receive instances as references now 2019-07-10 14:26:40 +02:00
Michele Caini
ba46bf3af5 review: sort/respect 2019-07-09 17:26:31 +02:00
Michele Caini
416b4885f9 updated doc (close #277) 2019-07-09 15:15:26 +02:00
Michele Caini
9a10ee0efa updated doc (see #277) 2019-07-09 14:56:32 +02:00
Michele Caini
d63b78f0e7 minor changes 2019-07-09 14:01:56 +02:00
Michele Caini
99411241f6 fixed typo 2019-07-09 13:59:28 +02:00
Michele Caini
941fb1349b added cache::each (close #275) 2019-07-09 13:58:44 +02:00
Michele Caini
a470925305 typo 2019-07-06 15:23:40 +02:00
Michele Caini
e3ac292af1 return types for meta_func are no longer ambiguous (close #274) 2019-07-06 00:10:37 +02:00
Michele Caini
260b9a8d0d meta_any meets void 2019-07-05 23:03:01 +02:00
Michele Caini
530407f9b2 minor changes 2019-07-05 14:13:10 +02:00
Michele Caini
52e7b50e9b sigh: more tests 2019-07-05 13:36:47 +02:00
Michele Caini
23aa097d0a fixed the clone functionality (close #273) 2019-07-05 08:41:24 +02:00
Michele Caini
0bea153aa0 more on sigh, connection and scoped_connection 2019-07-04 15:04:17 +02:00
Michele Caini
00be58e65d cleanup - thanks @Kerndog73 2019-07-03 15:28:11 +02:00
Michele Caini
a5cc985bc2 fixed doc for sigh - thanks @Kerndog73 2019-07-03 15:18:36 +02:00
Michele Caini
afba54fb5e updated doc for delegate/sigh (close #267) 2019-07-02 15:31:55 +02:00
Michele Caini
46150a2da4 delegate works now also with move only types (close #272) 2019-07-02 14:49:49 +02:00
Michele Caini
842988c2ad workaround for an issue of MSVC 2019-07-01 16:21:07 +02:00
Michele Caini
ebad34ae51 sigh: more tests 2019-07-01 15:26:11 +02:00
Michele Caini
bceb359438 minor changes 2019-07-01 15:16:38 +02:00
Michele Caini
19a32134ab tests: sigh connection/scoped_connection 2019-07-01 15:09:55 +02:00
Michele Caini
e44a71daf2 delegate::operator==/!= test the instance as a whole now 2019-06-30 22:19:44 +02:00
Michele Caini
573750a43d added connection/scoped_connection (#267 - test required) 2019-06-30 21:32:45 +02:00
Michele Caini
dd4c73b41f review: signal/sink 2019-06-30 21:32:45 +02:00
Michele Caini
094326220f cleanup 2019-06-30 21:32:45 +02:00
Michele Caini
729a071284 sigh: a more modern approach (as in modern C++) for collectors 2019-06-30 21:32:45 +02:00
Michele Caini
ee7857a560 sigh: removed invoker class 2019-06-30 21:32:45 +02:00
Michele Caini
4cba604712 updated list of projects (close #270) 2019-06-30 20:49:11 +02:00
Michele Caini
18a62797d9 updated FAQ 2019-06-30 17:11:40 +02:00
Michele Caini
5d4ac62c9e removed superfluous base class 2019-06-28 10:35:35 +02:00
Michele Caini
2ef8c41b48 updated list of contributors 2019-06-27 08:52:30 +02:00
Michele Caini
891831a96a Merge pull request #269 from Lawrencemm/conan_editable
Conan: Support package in editable mode
2019-06-27 08:51:38 +02:00
Michele Caini
11d18fa1af entity identifiers as enum classes (close #256) 2019-06-23 16:09:07 +02:00
Lawrence Millar-Madigan
ad69cbc681 Conan: Support package in editable mode
Add a method to the recipe that maps the include path to "src" when the package is put into "editable mode". See:
https://docs.conan.io/en/latest/developing_packages/editable_packages.html
2019-06-22 14:55:02 +10:00
Michele Caini
10995de7bd cleanup - thanks to @Kerndog73 (see #267) 2019-06-19 17:32:32 +02:00
Michele Caini
c4d78c06eb fixed group::sort with components 2019-06-19 15:25:30 +02:00
Michele Caini
eb252321a7 minor changes 2019-06-18 23:23:42 +02:00
Michele Caini
04dd1447ee minor changes 2019-06-17 16:14:20 +02:00
Michele Caini
b14edbe1f4 review: observer 2019-06-16 18:39:56 +02:00
Michele Caini
c697e52c0c fixed range destroy - it's probably slightly slower now but it works also with views and groups (close #261) 2019-06-16 17:14:32 +02:00
Michele Caini
b6911da8f0 CI runs now in debug mode (close #263) 2019-06-16 17:12:41 +02:00
Michele Caini
038448865b workaround for an issue with VS (close #264) 2019-06-16 17:10:25 +02:00
Michele Caini
9e44fdbc55 review: test 2019-06-16 17:08:37 +02:00
Michele Caini
e088f0f31e observer: when -> where (close #265) 2019-06-16 15:16:04 +02:00
Michele Caini
6101feda10 added default constructor to actor 2019-06-13 06:52:01 +02:00
Michele Caini
7a3fa68468 added actor::operator bool() + minor changes 2019-06-12 17:36:26 +02:00
Michele Caini
16a11638a7 updated observer (close #260) 2019-06-11 17:49:08 +02:00
Michele Caini
43932492a7 meta: overall improvements 2019-06-10 23:19:19 +02:00
Michele Caini
8d08ffc4ae slightly faster destroy 2019-06-10 00:24:19 +02:00
Michele Caini
a5a4ee4bfe doc: observer/reactive systems 2019-06-10 00:24:08 +02:00
Michele Caini
e66f3a80e8 observer (they call me reactive system) 2019-06-08 16:59:22 +02:00
Michele Caini
e69efacb47 updated links (close #258) 2019-06-08 14:06:54 +02:00
Michele Caini
528b361e34 meta any: in place construction/emplace 2019-06-08 14:03:31 +02:00
Michele Caini
a77bb3d341 Update FUNDING.yml 2019-06-07 09:52:53 +02:00
Michele Caini
6b17385ad7 updated tests 2019-06-06 14:58:25 +02:00
Michele Caini
33fc01ef4b Create FUNDING.yml 2019-06-06 12:08:59 +02:00
Michele Caini
482324c0bd avoid forcing conversions because of an issue with VS2019 (close #257) 2019-06-04 15:02:30 +02:00
Michele Caini
0ab13a3a70 test coverage 2019-06-03 23:50:09 +02:00
Michele Caini
699fb73726 bug fixing 2019-06-01 15:18:58 +02:00
Michele Caini
ddba29cc09 more on sigh/sink 2019-05-31 22:49:37 +02:00
Michele Caini
1cdb9ef47c updated TODO 2019-05-31 15:11:02 +02:00
Michele Caini
ade3305b4c removed useless references to components from dependencies 2019-05-31 15:10:46 +02:00
Michele Caini
bd2bd37bc4 updated sigh: instances and payload matter now 2019-05-31 15:10:06 +02:00
Michele Caini
ee6f55193e updated doc 2019-05-31 15:09:27 +02:00
Michele Caini
1868df61ea fixed typo 2019-05-31 15:08:49 +02:00
Michele Caini
dfa1fc7b09 review: group handler 2019-05-31 00:14:47 +02:00
Michele Caini
a52b0495f1 minor changes 2019-05-31 00:11:00 +02:00
Michele Caini
ce00eee29f the delegate accepts now also functions with a shorter list of parameters 2019-05-31 00:10:42 +02:00
Michele Caini
858bfade6a a more flexible delegate 2019-05-30 21:54:12 +02:00
Michele Caini
4535cf9274 perf improvement 2019-05-29 22:50:34 +02:00
Michele Caini
84d1fa54ec added the excluded components to the list of template parameters of a group 2019-05-28 15:03:28 +02:00
Michele Caini
7cf4721efa review: as_group 2019-05-27 22:05:16 +02:00
Michele Caini
6578838587 fixed include 2019-05-27 21:49:19 +02:00
Michele Caini
46b7c4717f workaround for an issue in clang 6 2019-05-27 12:08:25 +02:00
Michele Caini
52bcf63554 more on hashed strings and unique identifiers 2019-05-27 00:07:40 +02:00
Michele Caini
37ec97550e fixed typo 2019-05-26 15:38:37 +02:00
Michele Caini
55e20abea8 cleanup 2019-05-25 23:51:16 +02:00
Michele Caini
ec7d81dc7a added support for wstring to hashed_string 2019-05-25 23:42:06 +02:00
Michele Caini
e93387b719 maybe_atomic_t no longer exists 2019-05-25 22:21:44 +02:00
Michele Caini
050b476fc3 suppress warnings 2019-05-25 22:08:56 +02:00
Michele Caini
5b5ffd7eaf Remove superfluous inlines (was PR #249) 2019-05-25 22:03:34 +02:00
Michele Caini
39bf5fdc05 minor changes 2019-05-25 21:43:58 +02:00
Michele Caini
09ff43ef0a updated doc 2019-05-22 08:44:49 +02:00
Michele Caini
5a02aeaa89 raw() is no longer in use 2019-05-22 08:44:43 +02:00
Martin Hammerchmidt
2a3a91af42 Fix: remove garbage unicode U+FEFF failing compilation on Macos (#248, close #247) 2019-05-22 00:19:04 +02:00
Michele Caini
d4a64e93e0 mutable handle 2019-05-21 15:02:30 +02:00
Michele Caini
c126b64892 updated doc 2019-05-21 15:01:55 +02:00
Michele Caini
526814b9ed added registry::ctx_or_set 2019-05-19 23:40:15 +02:00
Michele Caini
bc3b790f13 removed wrong ENTT_NOEXCEPT 2019-05-19 23:25:05 +02:00
Michele Caini
1fb0765443 registry: internal changes 2019-05-19 00:23:48 +02:00
Michele Caini
c4b85f9bda minor changes 2019-05-18 23:53:10 +02:00
Michele Caini
161b5530b9 added [view|group]::less 2019-05-18 14:11:12 +02:00
Michele Caini
e03979ebdc cleanup 2019-05-18 14:05:04 +02:00
Michele Caini
356c0ab594 now working on v3.1.0 2019-05-18 14:04:41 +02:00
Michele Caini
85152bac34 doc 2019-05-15 23:41:51 +02:00
Michele Caini
c832888d56 doc 2019-05-15 23:27:44 +02:00
Michele Caini
cac1b87b44 assert -> ENTT_ASSERT 2019-05-15 23:23:06 +02:00
Michele Caini
30f71b2ed6 assert (has) on replace for empty components 2019-05-15 23:07:24 +02:00
Michele Caini
9f8e9a1916 code coverage 2019-05-15 22:58:46 +02:00
Michele Caini
8519fe57ae minor changes 2019-05-15 16:05:14 +02:00
Michele Caini
1442a3853c minor changes 2019-05-15 15:53:35 +02:00
Michele Caini
2658ddf868 code coverage 2019-05-15 15:25:06 +02:00
Michele Caini
f95eecfcc6 minor changes 2019-05-13 17:29:54 +02:00
Michele Caini
1e598cca31 added validity checks (close #245) 2019-05-12 11:50:46 +02:00
Michele Caini
f3eaeb96f0 review: instance-less pools for empty types 2019-05-10 23:45:26 +02:00
Michele Caini
91fac8049c perf improvement 2019-05-10 10:17:32 +02:00
Michele Caini
b1325a7514 suppress wrong warning 2019-05-09 16:37:41 +02:00
Michele Caini
150b83b4f3 instance-less pools for empty components 2019-05-09 16:20:44 +02:00
Michele Caini
3a3a5dc071 updated links (close #242) 2019-05-08 23:42:17 +02:00
Michele Caini
9b76a5bd66 (maybe) workaround for a bug in msvc 2019-05-07 23:48:12 +02:00
Michele Caini
850a1f9155 workaround for a bug in GCC7 2019-05-07 23:19:09 +02:00
Michele Caini
ef6c8a38d0 minor changes 2019-05-07 23:16:21 +02:00
Michele Caini
e228cb6648 prepare for instance-less pools for empty components 2019-05-07 16:29:31 +02:00
Michele Caini
3a53cac607 rework to easily allow storage specializations 2019-05-07 00:13:05 +02:00
Michele Caini
df4bd57c82 cleanup 2019-05-07 00:12:30 +02:00
Michele Caini
de737fc72d hashed string: support for string views 2019-05-06 00:07:24 +02:00
Michele Caini
ccea7a5783 review: cloning functionality 2019-05-05 22:34:15 +02:00
Michele Caini
5b84e1528a workaround for a bug (?) of msvc 2019-05-05 16:07:45 +02:00
Michele Caini
7382addfe4 minor changes 2019-05-04 18:06:03 +02:00
Michele Caini
b8dd6822ac type_list_cat[_t]/type_list_unique[_t] (close #238) 2019-05-02 22:54:34 +02:00
Sztergbaum Roman
8c47b85b9b add single include of EnTT framework (#236) 2019-05-01 16:39:01 +02:00
Michele Caini
4d2666a0e3 minor changes (close #235) 2019-05-01 15:30:12 +02:00
Michele Caini
fc18eaa292 updated README (close #228 - thanks to @ColinH for the review) 2019-04-30 23:38:26 +02:00
Michele Caini
22199cdd87 updated doc (close #232) 2019-04-30 23:06:35 +02:00
Michele Caini
76820f25c6 updated links 2019-04-30 22:42:12 +02:00
Michele Caini
bac4984496 updated doc (close #231) 2019-04-30 18:11:24 +02:00
Michele Caini
1414c5feac workaround for a wrong warning emitted by GCC8 (close #227) 2019-04-30 17:51:03 +02:00
Michele Caini
c344f63154 fixed cloning functionality (close #237) 2019-04-30 16:54:45 +02:00
Michele Caini
77ea28bef2 slightly improved registry::replace (thanks to ColinH for pointing it out) 2019-04-29 23:19:43 +02:00
Michele Caini
bf63b15e07 updated doc and links 2019-04-29 19:05:42 +02:00
Michele Caini
ce05504278 fixed typos (see #235) 2019-04-29 18:13:18 +02:00
Michele Caini
95b90974a2 removed wrong ENTT_NOEXCEPT (close #233) 2019-04-29 18:11:35 +02:00
Elias Ku
1adbef7352 benchmark fix (#225)
only one entity has all the components
2019-04-25 14:09:23 +02:00
Michele Caini
3109928dcd allows setting a continuous loader as registry context (close #224) 2019-04-24 15:01:25 +02:00
Michele Caini
24dd63789c updated conan test 2019-04-24 12:22:02 +02:00
Michele Caini
27225e6b5e updated README 2019-04-23 14:55:20 +02:00
Michele Caini
2994978fdb updated README 2019-04-23 14:52:37 +02:00
Michele Caini
ffd864dc72 review: registry internals 2019-04-23 14:50:31 +02:00
Michele Caini
53a2c88d4b preparing for v3 2019-04-22 18:00:07 +02:00
Michele Caini
444ae73ffb updated doc 2019-04-22 17:59:54 +02:00
Michele Caini
9f5f4b9c91 static registry::entity/version (close #223) 2019-04-22 17:31:25 +02:00
Michele Caini
ffd2af0257 minor changes 2019-04-21 17:03:06 +02:00
Michele Caini
b983845745 meta: built-in support for arrays 2019-04-19 14:01:00 +02:00
Michele Caini
cfcc6e1029 fix shadow warnigns and positive lambda explanation (#221) 2019-04-16 22:28:24 +02:00
Michele Caini
6fea4377b2 const correctness 2019-04-14 22:48:42 +02:00
Michele Caini
e01230e425 better sorting functionality for groups 2019-04-14 22:19:17 +02:00
Michele Caini
f66db81edd sort owning groups by owned components 2019-04-14 18:29:17 +02:00
Michele Caini
a47471d0ae updated doc 2019-04-14 16:51:42 +02:00
Michele Caini
06b5a91cd3 bug fixing 2019-04-14 15:39:09 +02:00
Michele Caini
8aacf3497e review: snapshot (close #219) 2019-04-14 15:31:00 +02:00
Michele Caini
7fc5e304e3 cleanup 2019-04-13 16:19:23 +02:00
Michele Caini
65536febd5 minor changes 2019-04-13 16:02:25 +02:00
Michele Caini
60f7910840 sligthly better perf 2019-04-13 15:23:26 +02:00
Michele Caini
829c3c612e cleanup 2019-04-12 23:03:30 +02:00
Michele Caini
355c7b59aa cleanup 2019-04-10 13:56:19 +02:00
Michele Caini
6508cdc823 doc: review 2019-04-09 13:44:43 +02:00
Michele Caini
9ef9f603a3 updated links 2019-04-09 09:54:42 +02:00
Michele Caini
e76f881c67 renaming things 2019-04-09 09:47:35 +02:00
Michele Caini
4292d2ce86 signal on replace 2019-04-09 08:54:19 +02:00
Michele Caini
ae927c5600 workaround to make it compile also with clang 5 2019-04-08 22:45:39 +02:00
Michele Caini
57e2eed771 cleanup 2019-04-08 22:13:10 +02:00
Michele Caini
ca807b892f added instance of component to construction signal 2019-04-08 17:48:09 +02:00
Michele Caini
9bc015d10e made the groups sortable 2019-04-06 00:58:47 +02:00
Michele Caini
59b204c3bc fixed typo 2019-04-06 00:57:18 +02:00
Michele Caini
4ac2472a62 minor changes 2019-04-05 23:47:20 +02:00
Michele Caini
054b9c2402 updated doc 2019-04-05 23:17:58 +02:00
Michele Caini
96f267cbfd sort allows to work with entities 2019-04-05 23:00:58 +02:00
Michele Caini
2018163107 Revert "let's see if vs solved its problems with aliases"
This reverts commit 0be2f1b295.
2019-04-04 22:30:24 +02:00
Michele Caini
253b5b1fb7 updated doc 2019-04-04 22:30:13 +02:00
Michele Caini
0be2f1b295 let's see if vs solved its problems with aliases 2019-04-04 22:23:55 +02:00
Michele Caini
a8838fc611 signals on replace 2019-04-04 22:20:24 +02:00
Michele Caini
d02636e370 rollback on signals, no need for these changes 2019-04-03 22:15:24 +02:00
Michele Caini
f3c1b09188 updated doc (close #216) 2019-04-03 14:26:23 +02:00
Michele Caini
7bac69f360 fixed typo 2019-04-01 17:32:52 +02:00
Michele Caini
5a3fdd225e meta: support to unregister types 2019-04-01 14:40:45 +02:00
Michele Caini
4660f58653 hashed string is copyable/moveable now 2019-04-01 14:40:24 +02:00
Michele Caini
5fabca3616 updated doc 2019-03-31 23:14:36 +02:00
Michele Caini
edb74dae87 review: cache (close #213) 2019-03-31 16:08:27 +02:00
Michele Caini
31b833b46a minor changes 2019-03-31 16:08:00 +02:00
Michele Caini
21bc1c51ba updated doc (see #213) 2019-03-31 15:43:19 +02:00
Michele Caini
4f6cab9a45 work around for a bug of msvc (close #212) 2019-03-31 15:16:16 +02:00
Michele Caini
33626fa47c mostly renaming 2019-03-30 15:27:33 +01:00
Michele Caini
9fcc1e17f2 signal handler: substitution 2019-03-30 14:56:43 +01:00
Michele Caini
a5f48f8af8 review: registry::loader 2019-03-30 00:46:38 +01:00
Michele Caini
3dfa526ec6 shrink_to_fit available also for non-owning groups 2019-03-30 00:37:49 +01:00
Michele Caini
dc28066017 shrink_to_fit to release pages 2019-03-30 00:09:49 +01:00
Michele Caini
2f2edfbde8 updated TODO 2019-03-29 16:10:56 +01:00
Michele Caini
3beac98499 updated doc 2019-03-29 14:03:12 +01:00
Michele Caini
f70ce9dd26 added faq doc 2019-03-29 00:23:16 +01:00
Michele Caini
e301b9d399 imnor changes 2019-03-28 23:36:05 +01:00
Michele Caini
42f92ecd7a updated TODO 2019-03-28 18:32:21 +01:00
Michele Caini
27eb0d04b9 introduced ENTT_DISABLE_ASSERT/ENTT_ASSERT macros 2019-03-28 17:49:34 +01:00
Michele Caini
112d13c127 updated doc 2019-03-28 14:56:50 +01:00
Michele Caini
16afc9d0f8 fixed link 2019-03-28 12:45:04 +01:00
Michele Caini
5b4889b46b removed unsafe_* functions 2019-03-28 12:12:48 +01:00
Michele Caini
f7eed0e2af paged reverse array 2019-03-28 00:09:49 +01:00
Michele Caini
cce287e8a6 page size macro/utility 2019-03-28 00:04:27 +01:00
Michele Caini
9a001ebacc review: process/scheduler (close #211) 2019-03-27 14:55:43 +01:00
Michele Caini
79ab4c02bb updated links (close #210) 2019-03-26 18:56:09 +01:00
Michele Caini
b6de70a3a6 Revert "cleanup"
This reverts commit 15cafe2d78.
2019-03-26 18:39:39 +01:00
Michele Caini
15cafe2d78 cleanup 2019-03-26 18:00:41 +01:00
Michele Caini
90197abc5c test coverage 2019-03-25 16:39:57 +01:00
Michele Caini
2147436a2a more on context variables 2019-03-25 15:21:13 +01:00
Michele Caini
8ef0c66966 fixed typo 2019-03-25 09:07:33 +01:00
Michele Caini
2779ad6c6f added unset for context variables 2019-03-24 23:12:03 +01:00
Michele Caini
f30fe3c746 fixed typo 2019-03-24 22:53:56 +01:00
Michele Caini
f71496693f updated example in the README file (close #209) 2019-03-23 13:51:18 +01:00
Michele Caini
e4cd5dbf1f fixed benchmark (thanks to Kerndog73) 2019-03-22 23:05:07 +01:00
Michele Caini
ffd5defcb6 updated benchmark 2019-03-22 22:17:58 +01:00
Michele Caini
0b81421124 updated TODO 2019-03-22 17:43:47 +01:00
Michele Caini
0f73b9e07f clean up 2019-03-22 16:49:19 +01:00
Michele Caini
d3078699d6 type_list is now an empty type 2019-03-22 15:56:19 +01:00
Michele Caini
cc39f9f891 clean up 2019-03-22 15:32:50 +01:00
Michele Caini
70608df843 improved multi component view 2019-03-22 10:12:04 +01:00
Michele Caini
e7f2c6b5ba more on context variables 2019-03-21 22:04:55 +01:00
Michele Caini
420fc9aa24 removed annoying/useless benchmark 2019-03-21 21:39:44 +01:00
Michele Caini
200012fd41 added component-to-entity functionality to the sparse sets + renamed some member functions 2019-03-21 17:25:13 +01:00
Michele Caini
e3c858278b minor changes 2019-03-21 15:06:10 +01:00
Michele Caini
1ec7c3afa4 context variables (aka tags revenge) 2019-03-21 14:52:44 +01:00
Michele Caini
6ab0b60f12 avoid global shadowing to an extent (close #207) 2019-03-20 08:33:26 +01:00
Michele Caini
5ec38b44b0 Update README.md 2019-03-20 08:24:22 +01:00
Michele Caini
39c2294d43 updated doc 2019-03-17 16:24:08 +01:00
Michele Caini
3b92481133 added utility functions to groups/views 2019-03-17 15:55:54 +01:00
Michele Caini
6b8d24d2f5 shared types -> named types 2019-03-15 14:42:50 +01:00
Michele Caini
62d6ff61ab updated links 2019-03-15 08:42:35 +01:00
Michele Caini
f7c056145a added fwd decl for runtime view 2019-03-13 22:20:25 +01:00
Michele Caini
451f54b036 added NovusCore to EnTT in Action (close #204) 2019-03-13 21:41:39 +01:00
Michele Caini
ef378de883 updated links 2019-03-13 10:47:50 +01:00
Michele Caini
2f2b63da4a renaming: label -> tag 2019-03-13 08:54:21 +01:00
Michele Caini
01d8f2c7e6 updated TODO 2019-03-12 23:23:25 +01:00
Michele Caini
330d553ffb removed potentially ambiguous call (fix #203) 2019-03-12 23:19:17 +01:00
Michele Caini
f1d0895eb1 added forward declaration for what matters (close #178) 2019-03-12 22:21:58 +01:00
Michele Caini
4eaf6415b7 cleanup 2019-03-12 15:08:53 +01:00
Michele Caini
f0650bf64f updated documentation 2019-03-12 14:58:07 +01:00
Michele Caini
44856c6207 removed useless remove_reference_t 2019-03-12 14:56:28 +01:00
Michele Caini
dcbf6e43c7 added get_or_assign (close #202) 2019-03-12 14:50:47 +01:00
Michele Caini
0d22da672d fixed test 2019-03-12 00:09:59 +01:00
Michele Caini
a62471b9b8 added default constructor to resource handle 2019-03-09 15:39:10 +01:00
Michele Caini
f673f2c5bc added each-with-type to multiple component views 2019-03-09 14:41:31 +01:00
Michele Caini
a7caae5c17 minor changes 2019-03-09 13:46:38 +01:00
Michele Caini
d0deefd0d7 review: registry (fix #199) 2019-03-09 00:35:11 +01:00
Michele Caini
9810da6982 batch add is now available 2019-03-08 22:49:14 +01:00
Michele Caini
cb93a3bee3 minor changes 2019-03-08 22:49:14 +01:00
Michele Caini
aeacc3e39d updated list of patrons 2019-03-08 15:29:47 +01:00
Michele Caini
e1c861cc8a updated links.md 2019-03-06 16:21:19 +01:00
Michele Caini
37ee05a576 updated TODO 2019-03-02 14:34:35 +01:00
Michele Caini
07a2bd817d minor changes 2019-03-01 17:35:54 +01:00
Michele Caini
78c171e0c2 meta: review 2019-03-01 17:07:08 +01:00
Michele Caini
1ae436cb08 added compile-time checks 2019-03-01 16:38:53 +01:00
Michele Caini
b0d3a84d1e setters/getters correctly handle references now (#fix 196) 2019-03-01 16:25:46 +01:00
Michele Caini
1acd9ca981 updated list of contributors 2019-03-01 08:45:43 +01:00
WizardIke
72467b6b9c Fix getting distance between forward iterators (#195) 2019-03-01 08:44:24 +01:00
Michele Caini
862c85387c Update README.md 2019-03-01 08:32:38 +01:00
Michele Caini
eeeca3e21c fix #194 2019-02-28 00:06:12 +01:00
Michele Caini
4ee4af7fd4 updated registry::destroy for ranges 2019-02-27 23:56:07 +01:00
Michele Caini
d131cc1871 fixed typo 2019-02-27 22:38:47 +01:00
Michele Caini
bd21ee318d fix #193 2019-02-27 22:12:55 +01:00
Michele Caini
02e7fc0bca updated README 2019-02-27 15:11:53 +01:00
Michele Caini
51ba46970e updated README (close #191) 2019-02-27 15:07:57 +01:00
Michele Caini
9d65b44ab7 removed pointless extra arguments from dispatcher (close #190) 2019-02-27 15:04:17 +01:00
Michele Caini
350d51a92d const T & = --> std::as_const 2019-02-27 15:03:39 +01:00
Michele Caini
2a8202caa7 bug fixing 2019-02-27 14:43:55 +01:00
Michele Caini
9e4591554f minor changes (close #192) 2019-02-27 14:04:40 +01:00
Michele Caini
e98ecfd1f9 cleanup 2019-02-27 13:57:24 +01:00
Michele Caini
1cbf5c4359 removed from the todo list some requests that would not bring benefits because they cannot be optimized 2019-02-25 23:56:18 +01:00
Michele Caini
0446faeb6f minor changes 2019-02-25 23:30:26 +01:00
Michele Caini
0417ea23c3 updated README 2019-02-25 23:11:59 +01:00
Michele Caini
de9886e011 more tests 2019-02-25 22:12:19 +01:00
Michele Caini
770e57c361 emitter works across boundaries now 2019-02-24 23:59:15 +01:00
Michele Caini
d80a00701d dispatcher works across boundaries now 2019-02-24 23:37:08 +01:00
Michele Caini
62d3cd8795 updated doc 2019-02-24 21:54:27 +01:00
Michele Caini
ad9ec22fd1 updated doc 2019-02-23 23:47:44 +01:00
Michele Caini
293985ec10 EXPAND -> ENTT_EXPAND 2019-02-23 23:47:41 +01:00
Michele Caini
105598ac8e (maybe) solved issue due to a bug of msvc 2019-02-23 23:47:38 +01:00
Michele Caini
ff93f2220a workaround for msvc that seems not to appreciate much macros 2019-02-23 23:47:35 +01:00
Michele Caini
33fddcb289 added a test that goes across boundaries 2019-02-23 23:47:31 +01:00
Michele Caini
6a09bf2c54 increase code coverage with minimum effort 2019-02-23 23:47:26 +01:00
Michele Caini
2913f5bbbe registry: refactoring 2019-02-23 23:47:22 +01:00
Michele Caini
671bdb09b8 macro review 2019-02-23 23:47:15 +01:00
Michele Caini
353a0d14a4 get rid of clang errors 2019-02-23 23:47:11 +01:00
Michele Caini
e0fd83211b lib support for registry (first draft) 2019-02-23 23:47:03 +01:00
Michele Caini
2c94d9cc37 slightly improved 2019-02-23 23:47:00 +01:00
Michele Caini
f7dec412ec minor changes 2019-02-23 23:46:52 +01:00
Michele Caini
f7c756d215 wip: make shared traits usable 2019-02-23 23:46:48 +01:00
Michele Caini
617635a989 wip: lib support 2019-02-23 23:46:42 +01:00
Michele Caini
ea3b2c4713 fixed link to patreon 2019-02-20 09:42:36 +01:00
Michele Caini
15455a7e68 updated AUTHORS 2019-02-20 09:14:58 +01:00
Michele Caini
ad5cedc08c cleanup 2019-02-19 14:43:45 +01:00
Michele Caini
328f0c6da8 fixed error with clang 2019-02-17 16:27:20 +01:00
Michele Caini
8ef818f581 hashed string: added possibility to use both uint32 and uint64 2019-02-17 16:19:58 +01:00
Michele Caini
48dace64e4 updated TODO 2019-02-17 16:17:32 +01:00
Michele Caini
ab5837c7c4 sigh: more tests 2019-02-17 16:17:21 +01:00
Michele Caini
9fbdbc1844 review: delegate/sigh 2019-02-17 16:17:13 +01:00
Michele Caini
54129cecc2 typo 2019-02-16 15:59:10 +01:00
Michele Caini
69c514d1a4 doc: fixed typo 2019-02-13 15:03:14 +01:00
Michele Caini
7047d12eba updated doc 2019-02-13 14:59:59 +01:00
Michele Caini
8ab61637f0 fixed get-or-assign (close #185) 2019-02-12 14:29:15 +01:00
Michele Caini
7e0bd92593 fix #184 - conflicts between partial-owning groups aren't correctly detected 2019-02-10 23:00:59 +01:00
Michele Caini
99d9a9f44e fixed tests 2019-02-10 13:21:45 +01:00
Erik Scholz
9c55111e14 [DOCS] removed excess "registry." in groups code sample (#181) 2019-02-09 19:00:23 +01:00
Michele Caini
b1d6ba57ad use the right family for groups 2019-02-09 14:33:15 +01:00
Michele Caini
47e9330646 groups 2019-02-09 14:04:09 +01:00
Michele Caini
e16a3d503c simplified sparse_set::clone 2019-02-08 17:21:03 +01:00
Michele Caini
dc9c93b347 cleanup 2019-02-08 17:20:39 +01:00
Michele Caini
faceff620a exclude is now a variable template 2019-02-08 17:20:21 +01:00
Michele Caini
a5a6a58556 removed indexes from persistent views 2019-02-08 17:20:14 +01:00
Michele Caini
45fdab27c9 meta_any: fixed #180 2019-02-01 23:48:00 +01:00
Michele Caini
8b360479f4 updated list of contributors 2019-02-01 22:30:08 +01:00
Michele Caini
b170f2f69a reduce the number of template instantiations 2019-02-01 22:29:24 +01:00
Michele Caini
7f1abab9ae bug fixing (find on views) 2019-01-29 09:00:34 +01:00
Michele Caini
2ec7bc878e minor changes 2019-01-29 08:42:37 +01:00
Michele Caini
e97d9bb095 maybe_atomic_type -> maybe_atomic_t 2019-01-29 08:40:49 +01:00
Michele Caini
2f3b02e870 typo 2019-01-29 08:40:27 +01:00
Michele Caini
11b7a45c32 improved registry::reset 2019-01-29 08:40:22 +01:00
Michele Caini
fb10d2f9c2 cleanup 2019-01-29 08:38:59 +01:00
Michele Caini
60bb7f66cf updated todo list 2019-01-29 08:38:48 +01:00
Michele Caini
ad5143169a removed registry::component_pool 2019-01-29 08:36:50 +01:00
Michele Caini
d68c90a429 removed registry ::pool/::managed 2019-01-29 08:36:42 +01:00
Michele Caini
8a51549395 updated list of contributors 2019-01-26 16:43:31 +01:00
corystegel
9f997fe1fa Fix sparse_set invalid state when component constructor throws (#176)
Fix sparse_set invalid state when component constructor throws

Previously, a component's constructor that throws would cause the sparse
set to think that the entity still exists in the set. This is because the underlying
sparse set that stores the entities will have its entry added before the component
is added to the component set.

This could cause a number of invalid memory access problems such as the following:

1) Exception triggers destructor of enclosing object that then tries to remove
   the component that was just added. SparseSet<entity_t, Component>::has() will
   return true for the entity but when destroy() is called "instances" will be empty
   so instances.back() will be invalid.

2) If the exception is handled then calling get(entity) for the same entity
   identifier that initially threw the exception will give a position for that
   entity even though it was not added. This can cause an invalid memory access
   or accessing the data of a different stored component.
2019-01-25 22:36:30 +01:00
Michele Caini
00f1f6d86b updated sigh + added future plans for this class to the todo list 2019-01-25 14:39:00 +01:00
Michele Caini
be72728000 updated doc 2019-01-24 14:30:16 +01:00
Michele Caini
f558126854 fixed typo + added tests (thanks to Kerndog73) 2019-01-24 08:36:55 +01:00
Michele Caini
08ed1500ac updated doc + minor changes 2019-01-23 16:06:53 +01:00
Michele Caini
f0926f1cc7 removed final specifier 2019-01-23 15:51:55 +01:00
Michele Caini
fe3f6aa22b signal: review 2019-01-23 15:42:29 +01:00
Michele Caini
1325f75e81 updated links 2019-01-23 15:37:15 +01:00
Michele Caini
4b1d3a7b6f allow for null entity members (#174) 2019-01-13 22:28:40 +01:00
Michele Caini
404afcdfd6 added default constructor to handle 2019-01-12 14:49:14 +01:00
Michele Caini
99793180f1 minor changes 2019-01-08 17:24:42 +01:00
Michele Caini
c91f9beddb removed raw view + added extended each member function to all the other views 2019-01-04 10:44:27 +01:00
Michele Caini
c9c5ccaa6d updated file links.md 2019-01-04 10:43:18 +01:00
Michele Caini
da42de7ac8 updated copyright 2019-01-02 15:36:14 +01:00
Michele Caini
3c9a6ad218 delegate: curried functions can accept linked parameters either by value or by reference 2019-01-01 15:01:13 +01:00
Michele Caini
f0389d6b47 updated TODO 2018-12-31 17:52:58 +01:00
Michele Caini
76eab21738 appveyor runs the tests now 2018-12-29 00:57:23 +01:00
Michele Caini
3b32c57d94 delegate: updated constraints for curried functions 2018-12-28 22:53:21 +01:00
Michele Caini
d119032cb9 added support for extra arguments to dispatcher 2018-12-28 16:10:09 +01:00
Michele Caini
397a04b49c typo 2018-12-26 15:00:46 +01:00
Michele Caini
d32c8e9457 empty type optimization 2018-12-26 14:50:30 +01:00
Michele Caini
ebb2974ca7 added exclude alias for type_list 2018-12-21 16:23:23 +01:00
Michele Caini
cbb1131a5d added maybe_atomic_type 2018-12-21 15:35:27 +01:00
Michele Caini
d9de7fe3b0 more tests 2018-12-19 15:26:21 +01:00
Michele Caini
24ba692884 delegate: support for curried functions 2018-12-19 14:18:59 +01:00
Michele Caini
960bbbde29 more on registry::clone (close #161) 2018-12-17 21:39:30 +01:00
Michele Caini
eb79b79c35 updated contributors list 2018-12-16 13:50:04 +01:00
Michele Caini
8212ed6d87 monostate: helper template variable 2018-12-16 13:49:13 +01:00
Michele Caini
c639cb5285 added hashed_string::to_value for direct computation 2018-12-16 13:49:09 +01:00
ceeac
a88fd1c669 Fix compile error when compiling example with GCC8 (#170) 2018-12-16 13:48:23 +01:00
Michele Caini
b053f23d15 registry::clone supports type list now (close #165) 2018-12-14 22:24:52 +01:00
Michele Caini
9d32a89491 doc: used @copydoc where possible 2018-12-13 22:50:23 +01:00
Michele Caini
cb9a147fff clone functionality (close #161) 2018-12-13 08:55:43 +01:00
Michele Caini
c9fddedbf1 UB/Crash in entt::insertion_sort (#167) 2018-12-11 14:17:39 +01:00
ProWolf
530bbbe4c5 added compile time version macros (#166) 2018-12-10 22:53:22 +01:00
Michele Caini
73e5a9f45b support for filtered persistent views 2018-12-09 13:50:41 +01:00
Michele Caini
72d4e947b6 Conan: Add CI setup #163 2018-12-05 14:51:56 +01:00
Michele Caini
41750c3639 typo 2018-11-30 14:56:48 +01:00
Michele Caini
52b36f38a0 delegate: a few more tests 2018-11-30 11:52:39 +01:00
Michele Caini
58ceb454dd review: delegate 2018-11-30 10:34:49 +01:00
Michele Caini
9e5a2db4c5 a few more links 2018-11-29 15:20:48 +01:00
Michele Caini
781f283c89 utility: as_view (resolve #157) 2018-11-29 11:49:15 +01:00
Michele Caini
f1cd085727 updated AUTHORS 2018-11-28 16:50:25 +01:00
Michael "Croydon" Keck
3aba855bd6 Add basic Conan support (#162)
* Add Conan support
* Conan: Add test_package
2018-11-28 11:25:49 +01:00
Michele Caini
7e3abb27a4 added find functionality to sparse sets/views 2018-11-28 10:47:09 +01:00
Michele Caini
f0c11daa37 cleanup 2018-11-27 23:44:40 +01:00
Michele Caini
167c174f4d added support for const instances * to the delegate 2018-11-27 23:16:55 +01:00
Michele Caini
0173060eaf typo 2018-11-27 22:20:52 +01:00
Michele Caini
4edd25ff5d review: registry 2018-11-27 22:13:19 +01:00
Michele Caini
2a4e098645 persistent views are now more reliable (fix #160) 2018-11-23 09:40:42 +01:00
willtunnels
7c5019c30f Fix find_package(EnTT) when EnTT is installed using vcpkg (#159)
This commit fixes a bug where find_package(EnTT) fails when EnTT is
installed using vcpkg.

The bug occurs because EnTTConfig.cmake.in calls
check_required_components(), yet the call to
configure_package_config_file() in CMakeLists.txt that generates
EnTTConfig.cmake is passed NO_CHECK_REQUIRED_COMPONENTS_MACRO. This
causes CMake to error when it tries to parse the output EnTTConfig.cmake
file if that file is generated from EnTTConfig.cmake.in e.g. when
installing EnTT using vcpkg.
2018-11-21 17:44:06 +01:00
Michele Caini
c13fe3feb6 views: const, non-const and all in between (fix #152) 2018-11-20 14:45:28 +01:00
Michele Caini
0ced60e712 added get overload with default value to registry (#152) 2018-11-19 16:08:26 +01:00
Michele Caini
d0764d5854 accommodate => assign_or_replace (#153) 2018-11-19 14:14:01 +01:00
Michele Caini
f7905e3bc2 get_if => try_get (#153) 2018-11-19 14:00:22 +01:00
Michele Caini
3e770792a4 meta: minor changes 2018-11-15 23:26:31 +01:00
Michele Caini
8f9934a7f4 boost persistent views (around 100x) 2018-11-12 23:13:23 +01:00
Michele Caini
b921e7d595 review: return values 2018-11-07 17:23:08 +01:00
Michele Caini
a9cb2d2efd updated TODO 2018-11-01 17:07:21 +01:00
Michele Caini
fe519b3acf (maybe) suppress error on vs2017 2018-10-31 22:34:27 +01:00
Michele Caini
30cc4a1668 re-enabled appveyor 2018-10-31 22:27:23 +01:00
Michele Caini
a71e4d8970 note/request 2018-10-31 17:42:24 +01:00
Michele Caini
66e7141415 meta: support for setters/getters 2018-10-31 17:39:40 +01:00
Michele Caini
6f0cdc864f added registry::create overload to create multiple entities at once 2018-10-30 15:14:57 +01:00
Michele Caini
4f9deaaf09 minor changes 2018-10-30 15:10:17 +01:00
Michele Caini
380745a814 fixed constness 2018-10-30 14:25:03 +01:00
Michele Caini
ce4e335412 doc 2018-10-29 22:57:07 +01:00
Michele Caini
274b8181d1 doc 2018-10-29 22:10:51 +01:00
Michele Caini
767bdcc2ce minor changes 2018-10-28 14:24:56 +01:00
Paul Gruenbacher
c00cde8bcc workaround for an issue with gcc 8.1.0 (#146 - fix #145) 2018-10-27 23:43:24 +02:00
Michele Caini
5859a18b3a added get_if where possible 2018-10-27 13:45:51 +02:00
Michele Caini
375124642d fixed warning 2018-10-25 23:02:31 +02:00
Michele Caini
af9e6dea68 review: doc 2018-10-25 22:28:56 +02:00
Michele Caini
78f2267b06 delegate: deduction guidelines 2018-10-22 15:32:18 +02:00
Michele Caini
0a34f22240 dispatcher: allow for deduced types for events 2018-10-21 22:48:06 +02:00
Michele Caini
b0651fcaed delegate: empty -> operator bool 2018-10-21 14:59:24 +02:00
Michele Caini
d59faa2a08 BUILD_TESTING set to OFF by default 2018-10-20 15:45:04 +02:00
Michele Caini
6a3bc37dc1 minor changes 2018-10-19 22:54:11 +02:00
Michele Caini
2ea7796b26 coverage purposes 2018-10-17 09:58:40 +02:00
Michele Caini
cf0057bac4 coverage purposes 2018-10-17 09:25:23 +02:00
Michele Caini
fafb325a88 fixed typo 2018-10-16 23:08:42 +02:00
Michele Caini
6b69b4671f fixed typo 2018-10-16 22:49:13 +02:00
Michele Caini
eaa95ee840 fixed typo 2018-10-16 22:21:36 +02:00
Michele Caini
a86ba1fdf6 a few changes to the meta system 2018-10-15 15:29:40 +02:00
Michele Caini
09e0d2d15b meta: inline variables 2018-10-13 13:19:34 +02:00
Michele Caini
6d9fa6418d fixed typo 2018-10-12 16:30:45 +02:00
Michele Caini
6010f5b7a6 meta: final review 2018-10-12 16:18:51 +02:00
Michele Caini
9c164e1cea meta: full support for constant values and enums 2018-10-12 00:09:58 +02:00
Michele Caini
880fba8dce fixed clang error with meta 2018-10-10 09:12:31 +02:00
Michele Caini
17d57ee49a value types and meta objects 2018-10-10 08:42:41 +02:00
Michele Caini
234949a627 updated contributors list 2018-10-08 22:52:17 +02:00
Michele Caini
ff34671526 typos 2018-10-07 22:33:39 +02:00
Michele Caini
6e22983d98 updated TODO list 2018-10-07 22:13:05 +02:00
Michele Caini
18254c30ec Update README.md 2018-10-07 22:07:27 +02:00
Michele Caini
922c955239 fixed doc + updated TODO list 2018-10-07 21:53:07 +02:00
Michele Caini
618a325057 reflection system 2018-10-05 13:38:22 +02:00
Michele Caini
d81cb7f866 EnTT v3 (draft) 2018-09-30 14:04:39 +02:00
Michele Caini
f71a4d5381 updated build system 2018-09-30 13:55:31 +02:00
Michele Caini
282cb60a66 added link to patreon 2018-09-29 23:02:10 +02:00
Michele Caini
58dbac4422 fixed typo 2018-09-03 10:24:05 +02:00
Michele Caini
53e228465b Update README.md 2018-09-02 23:28:48 +02:00
Michele Caini
06426e4fd7 updated version 2018-09-02 22:48:24 +02:00
Michele Caini
c55a97c24d updated TODO 2018-09-01 16:26:58 +02:00
Michele Caini
0d61289bf3 fixed #135 2018-09-01 16:21:59 +02:00
Michele Caini
bf10cbc70b review: documentation 2018-09-01 14:57:06 +02:00
Michele Caini
2d945e426b fixed #133 2018-08-29 23:10:03 +02:00
Michele Caini
13250887fa review: dependency 2018-08-22 15:51:13 +02:00
Michele Caini
3507c22968 bug fixing (Snapshot::destroyed - #128) 2018-08-22 14:22:54 +02:00
Michele Caini
cc3f98ebcd fixed tests (#129) 2018-08-22 14:00:11 +02:00
Michele Caini
4116e2d6ac added some projects to the entt-in-action list 2018-08-19 14:23:31 +02:00
Michele Caini
48eab6b4a7 minor changes 2018-08-11 14:44:41 +02:00
Michele Caini
25866b5369 fixed typo 2018-08-11 01:09:44 +02:00
Michele Caini
c4dd06fa45 delegate/signal: support for const member functions 2018-08-11 00:54:43 +02:00
Michele Caini
4846d211e0 updated TODO list 2018-08-06 14:07:34 +02:00
Michele Caini
a586ad1237 updated build system 2018-08-05 15:17:48 +02:00
Michele Caini
b701c9c464 review 2018-08-05 15:10:56 +02:00
Michele Caini
d0f20ed2bf updated tests 2018-08-05 13:54:21 +02:00
Michele Caini
0f64a2f3b0 updated .travis.yml (see #110) 2018-08-03 08:17:03 +02:00
Michele Caini
bd83fba6cd updated version 2018-08-02 17:17:09 +02:00
Michele Caini
15b9255a25 fix #120 2018-08-02 16:55:03 +02:00
Michele Caini
6794d21487 one shot bubble sort alg 2018-07-31 09:11:18 +02:00
Michele Caini
118c4432ec typo 2018-07-24 09:25:01 +02:00
Michele Caini
ccda429bf1 Update README.md 2018-07-23 12:10:48 +02:00
Michele Caini
590937d2a0 added Registry::entity 2018-07-20 22:17:18 +02:00
Michele Caini
241827dd80 added gitter badge 2018-07-20 22:03:24 +02:00
Michele Caini
77b4e0b4bd EnTT in action: Face Smash 2018-07-18 15:01:36 +02:00
Michele Caini
6a53cb32d8 updated TODO 2018-07-18 14:08:30 +02:00
Michele Caini
f12ff3b15e fix #116 2018-07-18 14:07:48 +02:00
Michele Caini
69ad8676b7 added USE_ASAN option 2018-07-18 14:07:43 +02:00
Michele Caini
d0fd756f6b logo + review doc 2018-07-12 15:30:52 +02:00
Michele Caini
7f8ab67e9e performance improvements 2018-07-09 16:48:35 +02:00
Michele Caini
0e68bb3d2c added entt::label 2018-07-07 13:40:20 +02:00
Michele Caini
d5b3933752 updated README (added a note on EnTT and shared libraries - see #111) 2018-07-05 16:14:42 +02:00
Michele Caini
0b7206a92d review: README 2018-07-04 13:42:37 +02:00
Michele Caini
e875f306fd added FIND_GTEST_PACKAGE to force using system-wide gtest version (#106) 2018-07-03 22:09:28 +02:00
Michele Caini
8ed5e5ee28 updated cmake min version 2018-07-03 16:57:46 +02:00
Indi Kernick
948b0d40f6 Update packages with Travis-CI (#110) 2018-07-03 12:57:36 +02:00
David Kalnischkies
48f4feb7a7 Fix README: identifiers are accessed via type<>() 2018-07-02 13:29:03 +02:00
Michele Caini
ddc0a32bbc fix: runtime view (#108) 2018-07-02 08:40:30 +02:00
Michele Caini
10a7c54364 runtime view 2018-06-28 14:31:04 +02:00
Michele Caini
a66fa9d844 review: capacity 2018-06-28 08:36:24 +02:00
Michele Caini
a16f2ac15c fixed build system 2018-06-27 22:53:21 +02:00
Michele Caini
b699797a40 naming convention 2018-06-25 14:02:31 +02:00
Michele Caini
a6e9520d06 updated TODO 2018-06-25 13:16:11 +02:00
Michele Caini
f8310b1296 added monostate (built-in config system) 2018-06-23 19:43:22 +02:00
Michele Caini
353bf99cd5 now working with vs2017 (again) 2018-06-22 14:46:43 +02:00
Michele Caini
a478e4acc9 fixed compilation errors and suppressed warnings with clang 2018-06-22 14:16:02 +02:00
Michele Caini
d810e0ba7d review ident 2018-06-22 09:59:03 +02:00
Michele Caini
1e51ffdb72 user defined string literal for hashed strings 2018-06-20 17:08:14 +02:00
Michele Caini
7da1d1fc64 minor changes 2018-06-19 15:36:21 +02:00
Michele Caini
957697c383 review: delegate (see #101 and #102) 2018-06-18 17:10:31 +02:00
Michele Caini
107eb72225 updated TODO 2018-06-18 13:25:34 +02:00
Michele Caini
810b77f9da use null entity everywhere 2018-06-18 08:34:27 +02:00
Michele Caini
5e3bc2049b clean up 2018-06-14 14:48:19 +02:00
Michele Caini
229500347d review: process scheduler 2018-06-14 14:46:39 +02:00
Michele Caini
1f461db0a1 minor changes 2018-06-13 23:33:47 +02:00
Malte
6c55aafee3 Export CMake Config file and "modernize" CMake scripts (#87)
* CMake modifications and Config file generation

* CMake minor style changes

* Get rid of commented lines, fix indentation

* Respect Windows conventions for CMake config directory, Fix error with Config Version file, Export CMake package

* Add CMake option for use of ENTT_COMPILE_OPTIONS, Add CMake option for using libc++, Remove  from EnTT target and move it to test targets

* Fix indentation

* Fix indentation (again)

* Fix Windows problems with compile option -Wall in not using it on Windows

* Improved generator expression
The problem with -Wall is not due to the platform but due to the compiler MSVC

* Set compatibility for ConfigVersion file to AnyNewerVersion, Add PATH_VARS CMAKE_INSTALL_INCLUDE_DIR of configure_package_config_file, Remove redundant options, correct target_include_directory for INSTALL_INTERFACE, set the Version in EnTTConfig file and check CMake version

* Add missing closing brace, Add a special config file for the build tree
2018-06-13 14:04:05 +02:00
Michele Caini
d57e55b719 improved sort 2018-06-12 22:32:11 +02:00
Michele Caini
bf772e5fe5 docs 2018-06-12 13:00:33 +02:00
Michele Caini
413f3356ce updated README 2018-06-12 08:46:05 +02:00
Michele Caini
f147326fe0 typo 2018-06-11 14:50:43 +02:00
Michele Caini
30c59644b6 minor changes 2018-06-11 13:57:37 +02:00
Michele Caini
3fa5acf2e6 updated TOC 2018-06-11 08:26:53 +02:00
Michele Caini
3e6ded8823 more on destroy 2018-06-11 08:24:48 +02:00
Michele Caini
612017aaa2 null entity 2018-06-11 08:23:07 +02:00
Michele Caini
ef57d7e7b6 removed wrong noexcept 2018-06-10 00:10:12 +02:00
Michele Caini
a8d0db5036 updated README 2018-06-09 23:51:57 +02:00
Michele Caini
ad6b5f8fc1 fixed tests 2018-06-09 23:51:48 +02:00
Michele Caini
e3cb6a0aec minor changes 2018-06-09 21:58:49 +02:00
Sztergbaum Roman
cbf18a7dc4 fix warning on windows C4267 (#97) 2018-06-09 21:49:33 +02:00
Michele Caini
01559410a9 updated TODO 2018-06-09 12:26:59 +02:00
Michele Caini
f2ab94fa7f added operator[] to sparse set and views 2018-06-09 00:36:22 +02:00
Michele Caini
d7394a8369 more on prototype 2018-06-08 23:03:05 +02:00
Michele Caini
9feef11d6f cleanup + tests 2018-06-08 22:58:12 +02:00
Michele Caini
dc4e5ddc3c review: iterators (sparse set/view) 2018-06-08 22:30:50 +02:00
Michele Caini
8600781bb6 fixed doc + minor changes 2018-06-08 19:04:19 +02:00
Michele Caini
bdc7bbdc9d DefaultPrototype depends on DefaultRegistry now 2018-06-06 14:39:56 +02:00
Michele Caini
73badef594 updated gtest (#92) 2018-06-06 13:42:09 +02:00
Michele Caini
9474e6c08c updated prototype (#91) 2018-06-05 08:38:27 +02:00
Michele Caini
653ded0e6f updated version 2018-06-04 08:52:10 +02:00
Michele Caini
e34bec7dee cloning an entity is no longer allowed 2018-06-04 08:49:13 +02:00
Michele Caini
610b560fb5 typo 2018-06-03 22:24:45 +02:00
Michele Caini
0a03ddb8a7 typo 2018-06-03 22:17:06 +02:00
Michele Caini
f31790631a fixed include 2018-06-03 22:10:33 +02:00
Michele Caini
e07128760e review: prototype (#89) 2018-06-03 19:06:12 +02:00
Michele Caini
dd02ae313d minor changes 2018-06-02 17:06:44 +02:00
Michele Caini
d14b0b6843 updated version 2018-05-30 22:46:47 +02:00
Michele Caini
f763c8a777 docs 2018-05-30 22:40:06 +02:00
Michele Caini
4231b040d8 documented an already existent feature (#86) 2018-05-30 22:19:04 +02:00
Michele Caini
67c587e673 updated README.md 2018-05-23 23:35:39 +02:00
Michele Caini
3978e24fd8 added CONTRIBUTING.md 2018-05-23 23:12:23 +02:00
Michele Caini
c45de0c032 tests + bug fixing 2018-05-23 12:28:10 +02:00
Michele Caini
ff935efea1 updated README 2018-05-23 12:27:53 +02:00
Michele Caini
808464f47d more on save/restore (#67) 2018-05-23 12:26:53 +02:00
Michele Caini
c986a6c4dd added clone functionality 2018-05-22 22:49:24 +02:00
Michele Caini
17c0479343 minor changes 2018-05-22 22:45:09 +02:00
Michele Caini
d93238912a workaround for an ICE of g++-5 (see #79) 2018-05-18 09:27:57 +02:00
Michele Caini
d6ef0956e6 performance improvements 2018-05-17 17:47:02 +02:00
Michele Caini
05db0aad29 fixed constness of iterators' member functions 2018-05-16 17:04:44 +02:00
Michele Caini
89bbdfa1fe benchmark: clean up 2018-05-16 16:59:45 +02:00
Michele Caini
871bda6198 fixed toc 2018-05-15 23:30:45 +02:00
Michele Caini
20732c9206 added const begin/end on views + tests 2018-05-15 22:51:47 +02:00
Michele Caini
2a34a3ebb6 fixed and added more tests for prototype 2018-05-15 22:31:27 +02:00
Michele Caini
3f04247a53 fixed errors with vs2017 + const begin/end on iterators for sparse set 2018-05-15 22:21:51 +02:00
Michele Caini
ca0a1f8f8b review: multi component standard view 2018-05-15 17:30:22 +02:00
Michele Caini
d8a9f0ca12 minor changes 2018-05-15 17:29:05 +02:00
Michele Caini
c2116b841e fixed typo 2018-05-15 14:16:24 +02:00
Michele Caini
700cf69f18 prefer a clean api instead of cumbersome ones 2018-05-11 23:19:11 +02:00
Michele Caini
ed5dee5218 fixed error with msvc - logic flipped upside down :-( 2018-05-11 22:51:50 +02:00
Michele Caini
b224dfdfac trying to work around msvc limitations 2018-05-11 22:25:03 +02:00
Michele Caini
e7da68547f fixed errors with clang 2018-05-11 22:24:10 +02:00
Michele Caini
9a785ceb2e added prototype class 2018-05-11 22:12:43 +02:00
Indi Kernick
fca1cd5a1c Implement entt::Prototype (#74)
first draft - to be reviewed
2018-05-08 13:37:21 +02:00
Michele Caini
24b862e32e more flexible 2018-05-06 13:58:50 +02:00
Michele Caini
2ec9043cf2 fixed comments 2018-05-04 17:18:53 +02:00
Michele Caini
1102d63469 fix #73 2018-05-02 22:50:55 +02:00
Michele Caini
b89f39d78c added has for tag + entity to test ownership 2018-05-02 17:07:20 +02:00
Michele Caini
7ba479c9c9 minor changes 2018-05-02 13:17:50 +02:00
Michele Caini
8ad6a2980c updated doc 2018-05-01 17:32:11 +02:00
Michele Caini
d3b6ed78d9 custom sort function (#72) 2018-04-30 17:14:36 +02:00
Michele Caini
8bd5605c2a now works also with VS2017 and GCC6 2018-04-27 23:19:08 +02:00
Michele Caini
08dc2fcf33 performance improvement 2018-04-27 15:27:16 +02:00
Michele Caini
caa8d16371 updated README 2018-04-24 14:01:18 +02:00
Michele Caini
bce92b3d85 updated README + AUTHORS 2018-04-22 23:23:15 +02:00
Michele Caini
67858bf300 faster accommodate 2018-04-22 13:32:38 +02:00
Michele Caini
7157e7e77d minor changes 2018-04-20 17:11:57 +02:00
Michele Caini
cf5074bdc5 added Registry::data/::raw 2018-04-20 16:23:39 +02:00
Michele Caini
fda44063ce removed Registry::persistent/Registry::raw 2018-04-20 15:32:30 +02:00
Michele Caini
f9becda02c more tests 2018-04-20 14:57:21 +02:00
Michele Caini
fb9fc952c6 more tests 2018-04-20 14:28:40 +02:00
Michele Caini
18451edfe9 review: views and sparse sets 2018-04-20 13:17:50 +02:00
Michele Caini
8c73cac72f added ENTT_NOEXCEPT macro to fully disable exception handling (ie required with UE4) 2018-04-18 16:36:14 +02:00
Michele Caini
c54cedf14b readme: updated benchmarks 2018-04-18 16:16:15 +02:00
Michele Caini
8ef4cdc9c3 improvements 2018-04-18 13:48:50 +02:00
Michele Caini
c0213e84f6 signals on tags 2018-04-16 17:14:22 +02:00
Michele Caini
29de6d89d4 improvements 2018-04-13 22:54:20 +02:00
Michele Caini
c9bf38ce36 fixed dispatcher + minor changes 2018-04-13 14:01:34 +02:00
Michele Caini
338eb75bab review: actor + tests 2018-04-12 08:18:10 +02:00
Michele Caini
31b1b453b0 updated doc and tests 2018-04-10 15:12:42 +02:00
Michele Caini
aaf0e145eb fixed - no more anonymous namespaces 2018-04-10 11:25:17 +02:00
Michele Caini
089b3e13fd no more anonymous namespaces 2018-04-10 09:00:15 +02:00
Michele Caini
e9da2ce12a (maybe) fixed 2018-04-10 08:45:54 +02:00
Michele Caini
92048ac17b removed signal + added dependency function(s) 2018-04-09 23:26:39 +02:00
Michele Caini
5e8561a578 more on tags and components 2018-04-09 08:14:35 +02:00
Michele Caini
d2f5e13074 typo 2018-04-08 23:25:32 +02:00
Michele Caini
820178f006 tag dispatching to disambiguate tags and components (#65) 2018-04-07 00:29:09 +02:00
Michele Caini
0a36a91e6d review + docs 2018-04-06 23:30:13 +02:00
Michele Caini
5013a92795 review snapshot/loaders 2018-04-06 22:08:23 +02:00
Michele Caini
d81ecfec32 removed extra create functions from the registry (#52) 2018-04-06 22:06:44 +02:00
Michele Caini
e99d7e2c3c signals on component creation/destruction (#62) 2018-04-06 22:04:58 +02:00
Michele Caini
d417984ff3 review: iterators + fixed bug on raw views 2018-03-30 14:54:14 +02:00
Michele Caini
d38b3e641b added a note about thread safety (see #64) 2018-03-29 23:38:50 +02:00
Michele Caini
28ce491dd5 review sigh + added set/move for tags 2018-03-29 22:30:23 +02:00
Michele Caini
c260d72125 fixed typo 2018-03-28 22:35:30 +02:00
Michele Caini
d1d1b3156d fixed doc for #27 2018-03-28 22:29:01 +02:00
Michele Caini
472064b751 ensure -> assure (#63) 2018-03-28 22:04:16 +02:00
Michele Caini
95ab9a0b70 updated TODO 2018-03-28 17:20:31 +02:00
Michele Caini
4b03f6a039 minor changes 2018-03-28 15:49:02 +02:00
Michele Caini
c3460727fa updated TODO 2018-03-28 10:24:01 +02:00
Michele Caini
2cc1850212 save/restore - see #27 2018-03-28 10:23:47 +02:00
Matteo Galeotti
2d7443acaf Add Dispatcher header to EnTT global include (#59)
Add dispatcher.hpp to entt.hpp
2018-03-22 14:05:55 +01:00
Michele Caini
13d0b0940c raw views 2018-03-15 22:09:43 +01:00
Michele Caini
c101797924 minor changes 2018-03-15 22:03:18 +01:00
Michele Caini
83b55f8e3f fixed benchmark 2018-03-14 14:11:29 +01:00
Michele Caini
b3b6362cd9 minor changes 2018-03-14 14:00:48 +01:00
Nicholas Farshidmehr
fc9af32d5f Fix spelling mistakes. (#57)
Fix spelling mistakes.
2018-03-14 13:47:23 +01:00
Michele Caini
4cd1025011 cleanup 2018-03-14 08:41:31 +01:00
Michele Caini
5233fe8abc updated TODO 2018-03-14 08:39:33 +01:00
Michele Caini
041e31ea78 removed spaces: not satisfied with the current implementation 2018-03-14 08:38:20 +01:00
Michele Caini
7a3e881099 review: benchmark 2018-03-14 08:28:56 +01:00
Michele Caini
631bf42f84 cleanup 2018-03-13 13:55:37 +01:00
Michele Caini
1f704a7019 updated TODO list 2018-03-12 11:28:00 +01:00
Michele Caini
d295c88474 spaces 2018-03-11 23:11:45 +01:00
Michele Caini
1dd9da4dff improved views (extended API + better performance) 2018-03-11 23:07:10 +01:00
Michele Caini
f2eb0c8427 added Registry::fast 2018-03-11 23:05:56 +01:00
Michele Caini
c8ba11faf8 more tests 2018-03-11 23:04:32 +01:00
Michele Caini
a2e243d992 improved multi component standard view 2018-03-07 22:38:21 +01:00
Michele Caini
c588fff5ca minor changes 2018-03-07 17:24:44 +01:00
Michele Caini
87f9599fea minor changes 2018-03-07 08:52:13 +01:00
Michele Caini
0459599b1d added estimated number of entities for multi component standard view 2018-03-07 08:31:03 +01:00
Michele Caini
9447b1a696 fixed 2018-03-06 22:34:46 +01:00
Michele Caini
0ccb7443c2 only the registry should create views 2018-03-06 22:34:38 +01:00
Michele Caini
02cf27091f coding style 2018-03-06 22:22:52 +01:00
Michele Caini
fdfbd04503 review 2018-03-06 13:27:29 +01:00
Michele Caini
866c18200a iterators from sparse sets and views have now operator+/operator+= 2018-03-04 16:45:24 +01:00
Michele Caini
c1cada49d4 review 2018-03-04 16:03:59 +01:00
Michele Caini
7bf550a75f id/version review 2018-03-04 15:32:08 +01:00
Michele Caini
9c540c03aa thread safe family class + minor changes 2018-03-04 15:21:10 +01:00
Michele Caini
b3df46db19 better test 2018-03-02 08:58:09 +01:00
Michele Caini
7ca615a1c1 sfinaed construct in sparse set to favor emplace_back with arguments when possible (#48) 2018-03-02 08:45:59 +01:00
Michele Caini
c83db557a6 more tests + minor changes 2018-03-01 19:24:12 +01:00
Michele Caini
d54594f11d orphans/orphan + minor changes 2018-03-01 19:23:42 +01:00
Michele Caini
434e38608f fixed typo 2018-03-01 19:22:26 +01:00
Michele Caini
871f090ca0 bug fixing 2018-03-01 16:18:23 +01:00
Michele Caini
d1d235e025 Fixed #46 (#47)
Use libc++ if possible
2018-02-28 19:02:12 +01:00
Michele Caini
e822a5fd53 more tests 2018-02-27 23:42:19 +01:00
Michele Caini
7b82a4ae50 updated TODO 2018-02-27 23:42:05 +01:00
Michele Caini
c532e9f2eb updated TODO list 2018-02-25 22:53:57 +01:00
Michele Caini
3fd034816e more tests on sparse set 2018-02-22 23:23:46 +01:00
Michele Caini
bb4b868c79 improvement: standard multi component view 2018-02-22 22:46:42 +01:00
Michele Caini
3b3da11a36 cleanup 2018-02-22 13:13:02 +01:00
Nick Lange
f2cbb5306b Fix MSVC 2017 warning C4458 (#43)
Fix MSVC 2017 warning C4458.
2018-02-22 13:08:36 +01:00
Michele Caini
94ede1b324 updated TODO 2018-02-21 22:24:23 +01:00
Michele Caini
0367248338 Documentation (#42)
Everything is finally documented.
2018-02-21 22:16:02 +01:00
Michele Caini
936db30e58 Fewer allocations, faster destroy (#41)
Overall improvement of the registry.
2018-02-20 10:10:13 +01:00
Michele Caini
4822f0dd11 fixed 2018-02-18 23:19:26 +01:00
Michele Caini
456d220829 updated TODO 2018-02-15 09:27:39 +01:00
Michele Caini
b459ba6ea7 TODO list 2018-02-15 08:46:15 +01:00
Michele Caini
a19ef9bd16 slightly improved 2018-02-12 19:24:07 +01:00
Paolo Monteverde
59cec88a28 fixing clang build (#38) 2018-02-08 14:56:07 +01:00
Michele Caini
3ebc75af80 updated version 2018-02-08 12:42:38 +01:00
Michele Caini
4dce474e03 revert: too risky a function 2018-02-08 12:27:48 +01:00
Michele Caini
31a18da578 fix #37 2018-02-08 12:23:48 +01:00
Michele Caini
8c499850fc fixed doc 2018-02-04 12:36:50 +01:00
Michele Caini
6b6998a247 duktape is now an external 2018-02-04 12:31:24 +01:00
Michele Caini
a6cb0fc856 added Registry::alive and Registry::orphans 2018-02-02 17:35:15 +01:00
Michele Caini
e36b93e87b fixed 2018-02-02 12:58:10 +01:00
Michele Caini
1e3723b8bb minor changes 2018-02-02 12:38:17 +01:00
Michele Caini
412372289e updated copyright 2018-01-26 17:28:40 +01:00
Michele Caini
96f7e66073 fixed 2018-01-14 00:53:55 +01:00
Michele Caini
6040f8f263 issue #31: multi component get 2018-01-14 00:32:23 +01:00
Michele Caini
9761b6e14a updated version 2017-12-29 18:29:38 +01:00
Michele Caini
cb49910ed2 allow attaching listeners at any time, allow removing current listener 2017-12-29 18:25:49 +01:00
Michele Caini
62bd742673 fixed doc 2017-12-27 17:59:57 +01:00
Michele Caini
42d0a3d734 v2.4.0 2017-12-27 17:57:04 +01:00
Michele Caini
f0f8681455 bug fixing 2017-12-27 17:55:26 +01:00
Michele Caini
c801afddcb added optional data to process::init 2017-12-23 00:30:00 +01:00
Michele Caini
20e0e1333e minor changes 2017-12-23 00:21:05 +01:00
Michele Caini
a6b373fec4 minor changes 2017-12-23 00:18:23 +01:00
Michele Caini
41c77720bb added optional data to scheduler/process 2017-12-22 23:59:07 +01:00
Michele Caini
92e6340120 cleanup 2017-12-22 23:58:49 +01:00
Michele Caini
1221f63cbd updated doc 2017-12-22 09:24:56 +01:00
Michele Caini
0f24418891 added ResourceCache::temp 2017-12-20 13:39:23 +01:00
Michele Caini
f477c0ab87 fixed reserve 2017-12-18 14:57:23 +01:00
Michele Caini
9358691901 added reserve 2017-12-18 14:08:38 +01:00
Michele Caini
cd343ba598 updated appveyor.yml (waiting for a new stable release of googletest) 2017-12-15 23:06:43 +01:00
Michele Caini
50069d3743 fixed docs 2017-12-14 23:15:47 +01:00
Michele Caini
1e03f27f23 v2.3.0 2017-12-14 22:56:40 +01:00
Michele Caini
36bb55a9ce doc: fixed 2017-12-13 16:20:36 +01:00
Michele Caini
451e4050db cleanup 2017-12-11 22:35:48 +01:00
Michele Caini
367fd3e87f minor changes 2017-12-11 16:04:25 +01:00
Michele Caini
a67a2e12fd minor changes 2017-12-11 15:03:43 +01:00
Michele Caini
292978daf0 #23: runtime components (doc) 2017-12-11 15:03:35 +01:00
Michele Caini
85a4a76a14 mod example with duktape 2017-12-10 17:43:48 +01:00
Michele Caini
9d0ab7ed70 added target entt_aob 2017-12-04 15:10:52 +01:00
Michele Caini
3d5b6a5e0b exposed family types 2017-12-04 14:59:08 +01:00
Michele Caini
ab20372093 minor changes 2017-12-04 14:06:10 +01:00
Michele Caini
ab887f30e4 typo 2017-11-21 08:33:48 +01:00
Michele Caini
6cb6a8c25f minor changes 2017-11-20 15:45:08 +01:00
Michele Caini
9d1d2aca0a updated build system 2017-11-18 17:31:11 +01:00
Michele Caini
75cb2cd1f7 improved sort functionalities 2017-11-18 15:54:04 +01:00
Michele Caini
ed6adbbfd7 Update README.md 2017-11-15 22:45:35 +01:00
Michele Caini
b6c950ffc5 tests, tags and few other features 2017-11-15 22:25:37 +01:00
Michele Caini
8b89c69d5f fixed #20 2017-11-14 22:48:37 +01:00
Michele Caini
290dda50fe now it works with MSVC2017 (#19)
#18
2017-11-13 10:39:55 +01:00
Michele Caini
a7278573a8 review: hashed_string 2017-11-13 08:49:04 +01:00
Michele Caini
68ce4dc689 added actor class 2017-11-12 16:11:32 +01:00
Michele Caini
a9f5118013 updated documentation 2017-11-11 23:48:08 +01:00
Michele Caini
d1f2e8ecf9 updated tests 2017-11-11 23:47:31 +01:00
Michele Caini
fe6873b61a updated version 2017-11-11 23:46:29 +01:00
Michele Caini
7c7bcf80cf added stuff for resource management 2017-11-11 23:46:10 +01:00
Michele Caini
cf6022866d added process and scheduler 2017-11-11 23:42:52 +01:00
Michele Caini
c630cb1de2 added core/hashed_string 2017-11-11 23:41:48 +01:00
Michele Caini
2e6c8d542c updated signal module 2017-11-11 23:41:16 +01:00
Michele Caini
2f781906b5 updated entity module 2017-11-11 23:40:50 +01:00
Michele Caini
b4f3b6f7bd updated readme 2017-10-28 00:15:42 +02:00
Michele Caini
71b464f44a updated build system 2017-10-28 00:15:20 +02:00
Michele Caini
438070ed58 updated entt.hpp 2017-10-28 00:15:01 +02:00
Michele Caini
a06c891969 updated entity-component system 2017-10-28 00:14:32 +02:00
Michele Caini
a935bd09aa updated core stuff 2017-10-28 00:13:56 +02:00
Michele Caini
fb8745ccf0 minimal locator implementation 2017-10-28 00:13:29 +02:00
Michele Caini
53a4c4be7f signalling stuff 2017-10-28 00:13:06 +02:00
Michele Caini
c0a110ea8a updated travis config 2017-10-28 00:12:27 +02:00
Michele Caini
c426a8e331 removed tests with 50M entities (jenkins gives up with them) 2017-10-19 17:52:17 +02:00
Michele Caini
526e4f69a4 updated version 2017-10-19 16:23:20 +02:00
Michele Caini
f901fa50ff fixed: custom registry required to manage 50M entities 2017-10-19 16:07:33 +02:00
Michele Caini
bea9eeac16 fixed: registry.destroy makes available the wrong entity identifier 2017-10-19 15:53:59 +02:00
Michele Caini
3055da5316 fixed typo 2017-10-18 18:24:13 +02:00
Michele Caini
3706fbdfee EnTT v2 (#14)
EnTT v2
2017-10-18 09:19:14 +02:00
Michele Caini
b4d18e94da more tests 2017-09-17 21:31:38 +02:00
Michele Caini
41523d9555 typo 2017-09-17 21:18:30 +02:00
Michele Caini
3b4c025743 update version 2017-09-14 13:30:29 +02:00
Michele Caini
df065c5647 Now it works on VS2017 (#11)
* update appveyor config
* update build system
* refactoring
2017-09-14 13:27:56 +02:00
Michele Caini
21380aacb8 fixed example code 2017-09-13 22:05:05 +02:00
Michele Caini
5884b1cec5 cleanup 2017-09-11 13:46:42 +02:00
Michele Caini
05860fcf9b WIP: docs 2017-09-11 13:38:46 +02:00
Michele Caini
2916aaeda8 WIP: docs 2017-09-10 23:35:00 +02:00
Michele Caini
ec9a221a8f WIP: docs 2017-09-10 23:28:12 +02:00
Michele Caini
97d8ad7fc6 WIP: docs 2017-09-10 23:25:33 +02:00
Michele Caini
adfb4cd694 WIP: docs 2017-09-10 23:07:10 +02:00
Michele Caini
34374afd36 WIP: docs 2017-09-10 22:47:14 +02:00
Michele Caini
b29949c0fa WIP: readme 2017-09-10 22:34:46 +02:00
Michele Caini
d26e163f66 rollback to libstdc++-4.9-dev 2017-09-10 18:30:19 +02:00
Michele Caini
e47fb67d74 it seems that Travis CI doesn't like much libc++ 2017-09-10 18:27:27 +02:00
Michele Caini
b328c49899 struggling against Travis CI 2017-09-10 18:20:42 +02:00
Michele Caini
9f3b602c0a updated CMakeLists.txt 2017-09-10 18:14:33 +02:00
Michele Caini
994a68eb81 updated travis conf 2017-09-10 18:09:36 +02:00
Michele Caini
bc256a989e updated travis conf 2017-09-10 18:05:00 +02:00
Michele Caini
2aeec2d50f WIP: docs 2017-09-10 16:48:23 +02:00
Michele Caini
03afa7652b WIP: documentation 2017-09-10 16:40:32 +02:00
Michele Caini
6791cf1e2e minor changes 2017-09-10 16:40:20 +02:00
Michele Caini
e69b90ef1a WIP: updated readme 2017-09-09 17:36:36 +02:00
Michele Caini
6c925a32b4 updated registry/sparse_set 2017-09-09 17:32:41 +02:00
Michele Caini
8d3f381a5a arguments are no longer accepted by the constructor 2017-09-09 17:07:37 +02:00
Michele Caini
02c424bd21 only internal pool is allowed 2017-09-09 17:02:13 +02:00
Michele Caini
c324ee310a updated build system 2017-09-09 16:16:25 +02:00
Michele Caini
fe7250bfc1 tests 2017-09-08 16:57:48 +02:00
Michele Caini
63c1b046e0 WIP: tests + bug fixing 2017-09-08 15:35:02 +02:00
Michele Caini
ed98ae3e70 fixed: sort functionalities 2017-09-07 14:05:58 +02:00
Michele Caini
2011defb1e tests + bug fixing 2017-09-05 14:06:28 +02:00
Michele Caini
b35737b5d7 WIP: swap/sort functionalities 2017-09-04 15:30:19 +02:00
Michele Caini
aeaf1632c8 minor changes 2017-09-03 16:12:50 +02:00
Michele Caini
af70573634 WIP: improvements and new features 2017-09-03 15:55:33 +02:00
226 changed files with 117985 additions and 1915 deletions

41
.clang-format Normal file
View File

@@ -0,0 +1,41 @@
BasedOnStyle: llvm
---
AccessModifierOffset: -4
AlignEscapedNewlines: DontAlign
AllowShortBlocksOnASingleLine: Empty
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
ColumnLimit: 0
DerivePointerAlignment: false
IncludeCategories:
- Regex: '<[[:alnum:]_]+>'
Priority: 1
- Regex: '<(gtest|gmock)/'
Priority: 2
- Regex: '<[[:alnum:]_./]+>'
Priority: 3
- Regex: '<entt/'
Priority: 4
- Regex: '.*'
Priority: 5
IndentPPDirectives: AfterHash
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
PointerAlignment: Right
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: After
SpaceBeforeCaseColon: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: false
Standard: Latest
TabWidth: 4
UseTab: Never

12
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: skypjack
patreon:
open_collective:
ko_fi:
tidelift:
community_bridge:
liberapay:
issuehunt:
otechie:
custom: https://www.paypal.me/skypjack

180
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,180 @@
name: build
on: [push, pull_request]
jobs:
linux:
timeout-minutes: 10
strategy:
matrix:
compiler:
- pkg: g++-7
exe: g++-7
- pkg: g++-8
exe: g++-8
- pkg: g++-9
exe: g++-9
- pkg: g++
exe: g++
- pkg: clang-8
exe: clang++-8
- pkg: clang-9
exe: clang++-9
- pkg: clang-10
exe: clang++-10
- pkg: clang
exe: clang++
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install compiler
run: |
sudo apt-get update
sudo apt-get install ${{ matrix.compiler.pkg }} -y
- name: Compile tests
working-directory: build
env:
CXX: ${{ matrix.compiler.exe }}
run: |
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
make -j4
- name: Run tests
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --timeout 30 -C Debug -j4
linux-extra:
timeout-minutes: 10
strategy:
matrix:
compiler: [g++, clang++]
id_type: [uint32, uint64]
cxx_std: [cxx_std_17, cxx_std_20]
include:
- id_type: uint64
id_type_variable: -DENTT_ID_TYPE=std::uint64_t
- cxx_std: cxx_std_20
cxx_std_variable: -DENTT_CXX_STD=cxx_std_20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Compile tests
working-directory: build
env:
CXX: ${{ matrix.compiler }}
run: |
cmake -DENTT_BUILD_TESTING=ON ${{ matrix.id_type_variable }} ${{ matrix.cxx_std_variable }} ..
make -j4
- name: Run tests
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --timeout 30 -C Debug -j4
windows:
timeout-minutes: 10
strategy:
matrix:
toolset: [clang-cl, default, v141]
include:
- toolset: clang-cl
toolset_option: -T"ClangCl"
- toolset: v141
toolset_option: -T"v141"
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Compile tests
working-directory: build
run: |
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ${{ matrix.toolset_option }} ..
cmake --build . -j 4
- name: Run tests
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --timeout 30 -C Debug -j4
windows-extra:
timeout-minutes: 10
strategy:
matrix:
id_type: [uint32, uint64]
cxx_std: [cxx_std_17, cxx_std_20]
include:
- id_type: uint64
id_type_variable: -DENTT_ID_TYPE=std::uint64_t
- cxx_std: cxx_std_20
cxx_std_variable: -DENTT_CXX_STD=cxx_std_20
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Compile tests
working-directory: build
run: |
cmake -DENTT_BUILD_TESTING=ON ${{ matrix.id_type_variable }} ${{ matrix.cxx_std_variable }} ..
cmake --build . -j 4
- name: Run tests
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --timeout 30 -C Debug -j4
macos:
timeout-minutes: 10
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
- name: Compile tests
working-directory: build
run: |
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
make -j4
- name: Run tests
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --timeout 30 -C Debug -j4
macos-extra:
timeout-minutes: 10
strategy:
matrix:
id_type: [uint32, uint64]
cxx_std: [cxx_std_17, cxx_std_20]
include:
- id_type: uint64
id_type_variable: -DENTT_ID_TYPE=std::uint64_t
- cxx_std: cxx_std_20
cxx_std_variable: -DENTT_CXX_STD=cxx_std_20
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
- name: Compile tests
working-directory: build
run: |
cmake -DENTT_BUILD_TESTING=ON ${{ matrix.id_type_variable }} ${{ matrix.cxx_std_variable }} ..
make -j4
- name: Run tests
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --timeout 30 -C Debug -j4

38
.github/workflows/coverage.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
name: coverage
on: [push, pull_request]
jobs:
codecov:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Compile tests
working-directory: build
env:
CXXFLAGS: "--coverage -fno-inline"
CXX: g++
run: |
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
make -j4
- name: Run tests
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --timeout 30 -C Debug -j4
- name: Collect data
working-directory: build
run: |
sudo apt install lcov
lcov -c -d . -o coverage.info
lcov -l coverage.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build/coverage.info
name: EnTT
fail_ci_if_error: true

39
.github/workflows/deploy.yml vendored Normal file
View File

@@ -0,0 +1,39 @@
name: deploy
on:
release:
types: published
jobs:
homebrew-entt:
timeout-minutes: 5
runs-on: ubuntu-latest
env:
GH_REPO: homebrew-entt
FORMULA: entt.rb
steps:
- uses: actions/checkout@v2
- name: Clone repository
working-directory: build
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git clone https://$GITHUB_ACTOR:$PERSONAL_ACCESS_TOKEN@github.com/$GITHUB_ACTOR/$GH_REPO.git
- name: Prepare formula
working-directory: build
run: |
cd $GH_REPO
curl "https://github.com/${{ github.repository }}/archive/${{ github.ref }}.tar.gz" --location --fail --silent --show-error --output archive.tar.gz
sed -i -e '/url/s/".*"/"'$(echo "https://github.com/${{ github.repository }}/archive/${{ github.ref }}.tar.gz" | sed -e 's/[\/&]/\\&/g')'"/' $FORMULA
sed -i -e '/sha256/s/".*"/"'$(openssl sha256 archive.tar.gz | cut -d " " -f 2)'"/' $FORMULA
- name: Update remote
working-directory: build
run: |
cd $GH_REPO
git config --local user.email "action@github.com"
git config --local user.name "$GITHUB_ACTOR"
git add $FORMULA
git commit -m "Update to ${{ github.ref }}"
git push origin master

36
.github/workflows/sanitizer.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: sanitizer
on: [push, pull_request]
jobs:
linux:
timeout-minutes: 10
strategy:
matrix:
compiler: [clang++]
id_type: [uint32, uint64]
cxx_std: [cxx_std_17, cxx_std_20]
include:
- id_type: uint64
id_type_variable: -DENTT_ID_TYPE=std::uint64_t
- cxx_std: cxx_std_20
cxx_std_variable: -DENTT_CXX_STD=cxx_std_20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Compile tests
working-directory: build
env:
CXX: ${{ matrix.compiler }}
run: |
cmake -DENTT_USE_SANITIZER=ON -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ${{ matrix.id_type_variable }} ${{ matrix.cxx_std_variable }} ..
make -j4
- name: Run tests
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --timeout 30 -C Debug -j4

13
.gitignore vendored
View File

@@ -1,2 +1,13 @@
# QtCreator
# Conan
conan/test_package/build
# IDEs
*.user
.idea
.vscode
.vs
CMakeSettings.json
cpp.hint
# Bazel
/bazel-*

View File

@@ -1,55 +0,0 @@
language: cpp
dist: trusty
sudo: false
matrix:
include:
- os: linux
compiler: gcc
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6']
env: COMPILER=g++-6
- os: linux
compiler: clang
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
packages: ['clang-4.0', 'libstdc++-4.9-dev']
env: COMPILER=clang++-4.0
- os: osx
osx_image: xcode8.3
compiler: clang
env: COMPILER=clang++
- os: linux
compiler: gcc
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6']
env:
- COMPILER=g++-6
- CXXFLAGS="-O0 --coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
before_script:
- pip install --user cpp-coveralls
after_success:
- coveralls --gcov gcov-6 --gcov-options '\-lp' --root ${TRAVIS_BUILD_DIR} --build-root ${TRAVIS_BUILD_DIR}/build --extension cpp --extension hpp --exclude deps --include src
notifications:
email:
on_success: never
on_failure: always
install:
- echo ${PATH}
- cmake --version
- export CXX=${COMPILER}
- echo ${CXX}
- ${CXX} --version
- ${CXX} -v
script:
- mkdir -p build && cd build
- cmake -DCMAKE_BUILD_TYPE=Release .. && make -j4
- CTEST_OUTPUT_ON_FAILURE=1 make test

48
AUTHORS
View File

@@ -1,7 +1,51 @@
# Author
Michele Caini aka skypjack
skypjack
# Contributors
Paolo Monteverde aka morbo84
alexames
BenediktConze
bjadamson
ceeac
ColinH
corystegel
Croydon
cugone
dbacchet
dBagrat
djarek
DonKult
drglove
eliasdaler
erez-o
eugeneko
gale83
ghost
grdowns
Green-Sky
Innokentiy-Alaytsev
Kerndog73
Koward
Lawrencemm
markand
mhammerc
Milerius
morbo84
m-waka
netpoetica
NixAJ
Oortonaut
Paolo-Oliverio
pgruenbacher
prowolf
stefanofiorentino
suVrik
szunhammer
The5-1
vblanco20-1
willtunnels
WizardIke
w1th0utnam3
xissburg
zaucy

14
BUILD.bazel Normal file
View File

@@ -0,0 +1,14 @@
_msvc_copts = ["/std:c++17"]
_gcc_copts = ["-std=c++17"]
cc_library(
name = "entt",
visibility = ["//visibility:public"],
strip_include_prefix = "src",
hdrs = glob(["src/**/*.h", "src/**/*.hpp"]),
copts = select({
"@bazel_tools//src/conditions:windows": _msvc_copts,
"@bazel_tools//src/conditions:windows_msvc": _msvc_copts,
"//conditions:default": _gcc_copts,
}),
)

View File

@@ -2,7 +2,7 @@
# EnTT
#
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.12.4)
#
# Building in-tree is not allowed (we take care of your craziness).
@@ -12,69 +12,324 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the source code and call cmake from there. Thank you.")
endif()
#
# Read project version
#
set(ENTT_VERSION_REGEX "#define ENTT_VERSION_.*[ \t]+(.+)")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/src/entt/config/version.h" ENTT_VERSION REGEX ${ENTT_VERSION_REGEX})
list(TRANSFORM ENTT_VERSION REPLACE ${ENTT_VERSION_REGEX} "\\1")
string(JOIN "." ENTT_VERSION ${ENTT_VERSION})
#
# Project configuration
#
project(entt VERSION 1.0.0)
project(
EnTT
VERSION ${ENTT_VERSION}
DESCRIPTION "Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more"
HOMEPAGE_URL "https://github.com/skypjack/entt"
LANGUAGES C CXX
)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
set(SETTINGS_ORGANIZATION "Michele Caini")
set(SETTINGS_APPLICATION ${PROJECT_NAME})
set(PROJECT_AUTHOR "Michele Caini")
set(PROJECT_AUTHOR_EMAIL "michele.caini@gmail.com")
message("*")
message("* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
message("* Copyright (c) 2017 ${PROJECT_AUTHOR} <${PROJECT_AUTHOR_EMAIL}>")
message("*")
message(VERBOSE "*")
message(VERBOSE "* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
message(VERBOSE "* Copyright (c) 2017-2021 Michele Caini <michele.caini@gmail.com>")
message(VERBOSE "*")
#
# Compile stuff
# Compiler stuff
#
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wconversion")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DRELEASE")
option(ENTT_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if availbale." OFF)
option(ENTT_USE_SANITIZER "Enable sanitizers by adding -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined flags if availbale." OFF)
if(ENTT_USE_LIBCPP)
if(NOT WIN32)
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
check_cxx_source_compiles("
#include<type_traits>
int main() { return std::is_same_v<int, char>; }
" ENTT_HAS_LIBCPP)
cmake_pop_check_state()
endif()
if(NOT ENTT_HAS_LIBCPP)
message(VERBOSE "The option ENTT_USE_LIBCPP is set but libc++ is not available. The flag will not be added to the target.")
endif()
endif()
if(ENTT_USE_SANITIZER)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(ENTT_HAS_SANITIZER TRUE CACHE BOOL "" FORCE)
mark_as_advanced(ENTT_HAS_SANITIZER)
endif()
if(NOT ENTT_HAS_SANITIZER)
message(VERBOSE "The option ENTT_USE_SANITIZER is set but sanitizer support is not available. The flags will not be added to the target.")
endif()
endif()
#
# CMake configuration
# Add EnTT target
#
set(PROJECT_CMAKE_IN ${entt_SOURCE_DIR}/cmake/in)
set(PROJECT_DEPS_DIR ${entt_SOURCE_DIR}/deps)
set(PROJECT_SRC_DIR ${entt_SOURCE_DIR}/src)
option(ENTT_INCLUDE_HEADERS "Add all EnTT headers to the EnTT target." OFF)
option(ENTT_INCLUDE_NATVIS "Add EnTT natvis files to the EnTT target." OFF)
set(PROJECT_RUNTIME_OUTPUT_DIRECTORY bin)
if(ENTT_INCLUDE_NATVIS)
if(MSVC)
set(ENTT_HAS_NATVIS TRUE CACHE BOOL "" FORCE)
mark_as_advanced(ENTT_HAS_NATVIS)
endif()
if(NOT ENTT_HAS_NATVIS)
message(VERBOSE "The option ENTT_INCLUDE_NATVIS is set but natvis files are not supported. They will not be added to the target.")
endif()
endif()
include(GNUInstallDirs)
add_library(EnTT INTERFACE)
add_library(EnTT::EnTT ALIAS EnTT)
target_include_directories(
EnTT
INTERFACE
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_features(EnTT INTERFACE cxx_std_17)
if(ENTT_INCLUDE_HEADERS)
target_sources(
EnTT
INTERFACE
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/config/config.h>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/config/version.h>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/container/dense_hash_map.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/container/dense_hash_set.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/container/fwd.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/algorithm.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/any.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/attribute.h>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/compressed_pair.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/enum.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/family.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/fwd.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/hashed_string.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/ident.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/iterator.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/memory.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/monostate.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/tuple.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/type_info.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/type_traits.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/utility.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/component.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/entity.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/fwd.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/group.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/handle.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/helper.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/observer.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/organizer.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/registry.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/runtime_view.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/snapshot.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/sparse_set.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/storage.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/utility.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/view.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/locator/locator.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/adl_pointer.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/container.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/ctx.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/factory.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/fwd.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/meta.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/node.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/pointer.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/policy.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/range.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/resolve.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/template.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/type_traits.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/utility.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/platform/android-ndk-r17.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/poly/fwd.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/poly/poly.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/process/process.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/process/scheduler.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/resource/cache.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/resource/fwd.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/resource/handle.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/resource/loader.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/delegate.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/dispatcher.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/emitter.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/fwd.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/sigh.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entt.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/fwd.hpp>
)
endif()
if(ENTT_HAS_NATVIS)
target_sources(
EnTT
INTERFACE
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/config.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/container.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/core.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/entity.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/locator.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/meta.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/platform.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/poly.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/process.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/resource.natvis>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/signal.natvis>
)
endif()
if(ENTT_HAS_SANITIZER)
target_compile_options(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
target_link_libraries(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
endif()
if(ENTT_HAS_LIBCPP)
target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
endif()
#
# Enable test support using ctest-like interface
# Install pkg-config file
#
option(BUILD_TESTING "Enable testing with ctest." ON)
set(EnTT_PKGCONFIG ${CMAKE_CURRENT_BINARY_DIR}/entt.pc)
configure_file(
${EnTT_SOURCE_DIR}/cmake/in/entt.pc.in
${EnTT_PKGCONFIG}
@ONLY
)
install(
FILES ${EnTT_PKGCONFIG}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
#
# build testing stuff if required
# Install EnTT
#
if(BUILD_TESTING)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
include(CMakePackageConfigHelpers)
# gtest, gtest_main, gmock and gmock_main targets are available from now on
set(GOOGLETEST_DEPS_DIR ${PROJECT_DEPS_DIR}/googletest)
configure_file(${PROJECT_CMAKE_IN}/googletest.in ${GOOGLETEST_DEPS_DIR}/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${GOOGLETEST_DEPS_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${GOOGLETEST_DEPS_DIR})
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${GOOGLETEST_DEPS_DIR}/src ${GOOGLETEST_DEPS_DIR}/build)
install(
TARGETS EnTT
EXPORT EnTTTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
write_basic_package_version_file(
EnTTConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${EnTT_SOURCE_DIR}/cmake/in/EnTTConfig.cmake.in
EnTTConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
)
export(
EXPORT EnTTTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/EnTTTargets.cmake
NAMESPACE EnTT::
)
install(
EXPORT EnTTTargets
FILE EnTTTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
NAMESPACE 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})
export(PACKAGE EnTT)
#
# Tests
#
option(ENTT_BUILD_TESTING "Enable building tests." OFF)
if(ENTT_BUILD_TESTING)
option(ENTT_FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)
option(ENTT_BUILD_BENCHMARK "Build benchmark." OFF)
option(ENTT_BUILD_EXAMPLE "Build examples." OFF)
option(ENTT_BUILD_LIB "Build lib tests." OFF)
option(ENTT_BUILD_SNAPSHOT "Build snapshot test with Cereal." OFF)
set(ENTT_ID_TYPE std::uint32_t CACHE STRING "Type of identifiers to use for the tests")
set(ENTT_CXX_STD cxx_std_17 CACHE STRING "C++ standard revision to use for the tests")
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
#
# Documentation
#
option(ENTT_BUILD_DOCS "Enable building with documentation." OFF)
if(ENTT_BUILD_DOCS)
find_package(Doxygen 1.8)
if(DOXYGEN_FOUND)
add_subdirectory(docs)
endif()
endif()
#
# AOB
#
add_custom_target(
aob
SOURCES
.github/workflows/build.yml
.github/workflows/coverage.yml
.github/workflows/deploy.yml
.github/workflows/sanitizer.yml
.github/FUNDING.yml
AUTHORS
CONTRIBUTING.md
LICENSE
README.md
TODO
)

43
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,43 @@
# Contributing
First of all, thank you very much for taking the time to contribute to the
`EnTT` framework.<br/>
How to do it mostly depends on the type of contribution:
* If you have a question, **please** ensure there isn't already an answer for
you by searching on GitHub under
[issues](https://github.com/skypjack/entt/issues). Do not forget to search
also through the closed ones. If you are unable to find a proper answer, feel
free to [open a new issue](https://github.com/skypjack/entt/issues/new).
Usually, questions are marked as such and closed in a few days.
* If you want to fix a typo in the inline documentation or in the README file,
if you want to add some new sections or if you want to help me with the
language by reviewing what I wrote so far (I'm not a native speaker after
all), **please** open a new
[pull request](https://github.com/skypjack/entt/pulls) with your changes.
* If you found a bug, **please** ensure there isn't already an answer for you by
searching on GitHub under [issues](https://github.com/skypjack/entt/issues).
If you are unable to find an open issue addressing the problem, feel free to
[open a new one](https://github.com/skypjack/entt/issues/new). **Please**, do
not forget to carefully describe how to reproduce the problem, then add all
the information about the system on which you are experiencing it and point
out the version of `EnTT` you are using (tag or commit).
* If you found a bug and you wrote a patch to fix it, open a new
[pull request](https://github.com/skypjack/entt/pulls) with your code.
**Please**, add some tests to avoid regressions in future if possible, it
would be really appreciated. Note that the `EnTT` framework has a
[coverage at 100%](https://coveralls.io/github/skypjack/entt?branch=master)
(at least it was at 100% at the time I wrote this file) and this is the reason
for which you can be confident with using it in a production environment.
* If you want to propose a new feature and you know how to code it, **please**
do not issue directly a pull request. Before to do it,
[create a new issue](https://github.com/skypjack/entt/issues/new) to discuss
your proposal. Other users could be interested in your idea and the discussion
that will follow can refine it and therefore give us a better solution.
* If you want to request a new feature, I'm available for hiring. Take a look at
[my profile](https://github.com/skypjack) and feel free to write me.

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2017 Michele Caini
Copyright (c) 2017-2021 Michele Caini, author of EnTT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

599
README.md
View File

@@ -1,349 +1,428 @@
# EnTT - Entity-Component System in modern C++
![EnTT: Gaming meets modern C++](https://user-images.githubusercontent.com/1812216/103550016-90752280-4ea8-11eb-8667-12ed2219e137.png)
[![Build Status](https://travis-ci.org/skypjack/entt.svg?branch=master)](https://travis-ci.org/skypjack/uvw)
[![Build status](https://ci.appveyor.com/api/projects/status/rvhaabjmghg715ck?svg=true)](https://ci.appveyor.com/project/skypjack/entt)
[![Coverage Status](https://coveralls.io/repos/github/skypjack/entt/badge.svg?branch=master)](https://coveralls.io/github/skypjack/entt?branch=master)
<!--
@cond TURN_OFF_DOXYGEN
-->
[![Build Status](https://github.com/skypjack/entt/workflows/build/badge.svg)](https://github.com/skypjack/entt/actions)
[![Coverage](https://codecov.io/gh/skypjack/entt/branch/master/graph/badge.svg)](https://codecov.io/gh/skypjack/entt)
[![Try online](https://img.shields.io/badge/try-online-brightgreen)](https://godbolt.org/z/zxW73f)
[![Documentation](https://img.shields.io/badge/docs-docsforge-blue)](http://entt.docsforge.com/)
[![Gitter chat](https://badges.gitter.im/skypjack/entt.png)](https://gitter.im/skypjack/entt)
[![Discord channel](https://img.shields.io/discord/707607951396962417?logo=discord)](https://discord.gg/5BjPWBd)
[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/skypjack)
`EnTT` is a header-only, tiny and easy to use library for game programming and
much more written in **modern C++**.<br/>
[Among others](https://github.com/skypjack/entt/wiki/EnTT-in-Action), it's used
in [**Minecraft**](https://minecraft.net/en-us/attribution/) by Mojang, the
[**ArcGIS Runtime SDKs**](https://developers.arcgis.com/arcgis-runtime/) by Esri
and the amazing [**Ragdoll**](https://ragdolldynamics.com/).<br/>
If you don't see your project in the list, please open an issue, submit a PR or
add the [#entt](https://github.com/topics/entt) tag to your _topics_! :+1:
---
Do you want to **keep up with changes** or do you have a **question** that
doesn't require you to open an issue?<br/>
Join the [gitter channel](https://gitter.im/skypjack/entt) and the
[discord server](https://discord.gg/5BjPWBd), meet other users like you. The
more we are, the better for everyone.<br/>
Don't forget to check the
[FAQs](https://github.com/skypjack/entt/wiki/Frequently-Asked-Questions) and the
[wiki](https://github.com/skypjack/entt/wiki) too. Your answers may already be
there.
Do you want to support `EnTT`? Consider becoming a
[**sponsor**](https://github.com/users/skypjack/sponsorship).
Many thanks to [these people](https://skypjack.github.io/sponsorship/) and
**special** thanks to:
[![mojang](https://user-images.githubusercontent.com/1812216/106253145-67ca1980-6217-11eb-9c0b-d93561b37098.png)](https://mojang.com)
[![imgly](https://user-images.githubusercontent.com/1812216/106253726-271ed000-6218-11eb-98e0-c9c681925770.png)](https://img.ly/)
# Table of Contents
* [Introduction](#introduction)
* [Code Example](#code-example)
* [Motivation](#motivation)
* [Performance](#performance)
* [Integration](#integration)
* [Requirements](#requirements)
* [CMake](#cmake)
* [Natvis support](#natvis-support)
* [Packaging Tools](#packaging-tools)
* [pkg-config](#pkg-config)
* [Documentation](#documentation)
* [Tests](#tests)
* [EnTT in Action](#entt-in-action)
* [Contributors](#contributors)
* [License](#license)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
`EnTT` is a header-only, tiny and easy to use Entity-Component System in modern C++.<br/>
ECS is an architectural pattern used mostly in game development. For further details:
The entity-component-system (also known as _ECS_) is an architectural pattern
used mostly in game development. For further details:
* [Entity Systems Wiki](http://entity-systems.wikidot.com/)
* [Evolve Your Hierarchy](http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/)
* [ECS on Wikipedia](https://en.wikipedia.org/wiki/Entity%E2%80%93component%E2%80%93system)
This project started off as a pure entity-component system. Over time the
codebase has grown as more and more classes and functionalities were added.<br/>
Here is a brief, yet incomplete list of what it offers today:
* Built-in **RTTI system** mostly similar to the standard one.
* A `constexpr` utility for human readable **resource names**.
* Minimal **configuration system** built using the monostate pattern.
* Incredibly fast **entity-component system** with its own _pay for what you
use_ policy.
* Views and groups to iterate entities and components and allow different access
patterns, from **perfect SoA** to fully random.
* A lot of **facilities** built on top of the entity-component system to help
the users and avoid reinventing the wheel.
* The smallest and most basic implementation of a **service locator** ever seen.
* A built-in, non-intrusive and macro-free runtime **reflection system**.
* **Static polymorphism** made simple and within everyone's reach.
* A few homemade containers, like a sparse set based **dense hash map**.
* A **cooperative scheduler** for processes of any type.
* All that is needed for **resource management** (cache, loaders, handles).
* Delegates, **signal handlers** and a tiny event dispatcher.
* A general purpose **event emitter** as a CRTP idiom based class template.
* And **much more**! Check out the
[**wiki**](https://github.com/skypjack/entt/wiki).
**Breaking news**:
* The ECS allows attaching multiple components of the same type to an entity.
* All tools work perfectly across boundaries (DLL-friendly)!!
:slightly_smiling_face:
Consider these lists a work in progress as well as the project. The whole API is
fully documented in-code for those who are brave enough to read it.
It is also known that `EnTT` is used in **Minecraft**.<br/>
Given that the game is available literally everywhere, I can confidently say
that the library has been sufficiently tested on every platform that can come to
mind.
## Code Example
```cpp
#include <iostream>
#include <registry.hpp>
#include <entt/entt.hpp>
struct Position {
struct position {
float x;
float y;
};
struct Velocity {
struct velocity {
float dx;
float dy;
};
using ECS = entt::DefaultRegistry<Position, Velocity>;
void update(entt::registry &registry) {
auto view = registry.view<const position, velocity>();
// use a callback
view.each([](const auto &pos, auto &vel) { /* ... */ });
// use an extended callback
view.each([](const auto entity, const auto &pos, auto &vel) { /* ... */ });
// use a range-for
for(auto [entity, pos, vel]: view.each()) {
// ...
}
// use forward iterators and get only the components of interest
for(auto entity: view) {
auto &vel = view.get<velocity>(entity);
// ...
}
}
int main() {
ECS ecs;
entt::registry registry;
for(auto i = 0; i < 10; ++i) {
auto entity = ecs.create();
ecs.assign<Position>(entity, i * 1.f, i * 1.f);
if(i % 2 == 0) { ecs.assign<Velocity>(entity, i * .1f, i * .1f); }
for(auto i = 0u; i < 10u; ++i) {
const auto entity = registry.create();
registry.emplace<position>(entity, i * 1.f, i * 1.f);
if(i % 2 == 0) { registry.emplace<velocity>(entity, i * .1f, i * .1f); }
}
std::cout << "single component view" << std::endl;
for(auto entity: ecs.view<Position>()) {
auto &position = ecs.get<Position>(entity);
std::cout << position.x << "," << position.y << std::endl;
}
std::cout << "multi component view" << std::endl;
for(auto entity: ecs.view<Position, Velocity>()) {
auto &position = ecs.get<Position>(entity);
auto &velocity = ecs.get<Velocity>(entity);
std::cout << position.x << "," << position.y << " - " << velocity.dx << "," << velocity.dy << std::endl;
if(entity % 4) { ecs.remove<Velocity>(entity); }
else { ecs.destroy(entity); }
}
std::cout << "single component view" << std::endl;
for(auto entity: ecs.view<Position>()) {
auto &position = ecs.get<Position>(entity);
std::cout << position.x << "," << position.y << std::endl;
}
std::cout << "multi component view" << std::endl;
for(auto entity: ecs.view<Position, Velocity>()) {
auto &position = ecs.get<Position>(entity);
auto &velocity = ecs.get<Velocity>(entity);
std::cout << position.x << "," << position.y << " - " << velocity.dx << "," << velocity.dy << std::endl;
if(entity % 4) { ecs.remove<Velocity>(entity); }
else { ecs.destroy(entity); }
}
ecs.reset();
update(registry);
}
```
## Motivation
I started using another well known Entity-Component System named [`EntityX`](https://github.com/alecthomas/entityx).<br/>
While I was playing with it, I found that I didn't like that much the way it manages its memory.
Moreover, I was pretty sure that one could achieve better performance with a slightly modified pool under the hood.<br/>
That's also the reason for which the interface is quite similar to the one of `EntityX`, so that `EnTT` can be used as a
drop-in replacement for it with a minimal effort.
I started developing `EnTT` for the _wrong_ reason: my goal was to design an
entity-component system to beat another well known open source solution both in
terms of performance and possibly memory usage.<br/>
In the end, I did it, but it wasn't very satisfying. Actually it wasn't
satisfying at all. The fastest and nothing more, fairly little indeed. When I
realized it, I tried hard to keep intact the great performance of `EnTT` and to
add all the features I wanted to see in *my own library* at the same time.
### Performance
Nowadays, `EnTT` is finally what I was looking for: still faster than its
_competitors_, lower memory usage in the average case, a really good API and an
amazing set of features. And even more, of course.
As it stands right now, `EnTT` is just fast enough for my requirements if compared to my first choice (that was already
amazingly fast).
These are the results of the twos when compiled with GCC 6.3:
## Performance
| Benchmark | EntityX (experimental/compile_time) | EnTT |
|-----------|-------------|-------------|
| Creating 10M entities | 0.187042s | **0.0928331s** |
| Destroying 10M entities | 0.0735151s | **0.060166s** |
| Iterating over 10M entities, unpacking one component | 0.00784801s | **1.02e-07s** |
| Iterating over 10M entities, unpacking two components | 0.00865273s | **0.00326714s** |
| Iterating over 10M entities, unpacking five components | 0.0122006s | **0.00323354s** |
| Iterating over 10M entities, unpacking ten components | 0.0100089s | **0.00323615s** |
| Iterating over 50M entities, unpacking one component | 0.0394404s | **1.14e-07s** |
| Iterating over 50M entities, unpacking two components | 0.0400407s | **0.0179783s** |
The proposed entity-component system is incredibly fast to iterate entities and
components, this is a fact. Some compilers make a lot of optimizations because
of how `EnTT` works, some others aren't that good. In general, if we consider
real world cases, `EnTT` is somewhere between a bit and much faster than many of
the other solutions around, although I couldn't check them all for obvious
reasons.
These are the results of the twos when compiled with Clang 3.8.1:
If you are interested, you can compile the `benchmark` test in release mode (to
enable compiler optimizations, otherwise it would make little sense) by setting
the `ENTT_BUILD_BENCHMARK` option of `CMake` to `ON`, then evaluate yourself
whether you're satisfied with the results or not.
| Benchmark | EntityX (experimental/compile_time) | EnTT |
|-----------|-------------|-------------|
| Creating 10M entities | 0.268049s | **0.0899998s** |
| Destroying 10M entities | **0.0713912s** | 0.078663s |
| Iterating over 10M entities, unpacking one component | 0.00863192s | **3.05e-07s** |
| Iterating over 10M entities, unpacking two components | 0.00780158s | **2.5434e-05s** |
| Iterating over 10M entities, unpacking five components | 0.00829669s | **2.5497e-05s** |
| Iterating over 10M entities, unpacking ten components | 0.00789789s | **2.5563e-05s** |
| Iterating over 50M entities, unpacking one component | 0.0423244s | **1.94e-07s** |
| Iterating over 50M entities, unpacking two components | 0.0435464s | **0.00012661s** |
Honestly I got tired of updating the README file whenever there is an
improvement.<br/>
There are already a lot of projects out there that use `EnTT` as a basis for
comparison (this should already tell you a lot). Many of these benchmarks are
completely wrong, many others are simply incomplete, good at omitting some
information and using the wrong function to compare a given feature. Certainly
there are also good ones but they age quickly if nobody updates them, especially
when the library they are dealing with is actively developed.
I don't know what Clang does to squeeze out of `EnTT` the performance above, but I'd say that it does it incredibly well.
The choice to use `EnTT` should be based on its carefully designed API, its
set of features and the general performance, **not** because some single
benchmark shows it to be the fastest tool available.
See [benchmark.cpp](https://github.com/skypjack/entt/blob/master/test/benchmark.cpp) for further details.<br/>
Of course, I'll try to get out of it more features and better performance anyway in the future, mainly for fun.
If you want to contribute and have any suggestion, feel free to make a PR or open an issue to discuss them.
In the future I'll likely try to get even better performance while still adding
new features, mainly for fun.<br/>
If you want to contribute and/or have suggestions, feel free to make a PR or
open an issue to discuss your idea.
### Benchmarks / Comparisons
# Integration
`EnTT` includes its own benchmarks, mostly similar to the ones of `EntityX` so as to compare them.<br/>
On Github you can find also a [benchmark suite](https://github.com/abeimler/ecs_benchmark) testing `EntityX` (both the official version and the compile-time one), `Anax` and `Artemis C++` with up to 10M entities.
`EnTT` is a header-only library. This means that including the `entt.hpp` header
is enough to include the library as a whole and use it. For those who are
interested only in the entity-component system, consider to include the sole
`entity/registry.hpp` header instead.<br/>
It's a matter of adding the following line to the top of a file:
# Build Instructions
```cpp
#include <entt/entt.hpp>
```
Use the line below to include only the entity-component system instead:
```cpp
#include <entt/entity/registry.hpp>
```
Then pass the proper `-I` argument to the compiler to add the `src` directory to
the include paths.
## Requirements
To be able to use `EnTT`, users must provide a full-featured compiler that supports at least C++14.<br/>
CMake version 3.4 or later is mandatory to compile the tests, you don't have to install it otherwise.
To be able to use `EnTT`, users must provide a full-featured compiler that
supports at least C++17.<br/>
The requirements below are mandatory to compile the tests and to extract the
documentation:
## Library
* `CMake` version 3.7 or later.
* `Doxygen` version 1.8 or later.
`EnTT` is a header-only library. This means that including the `registry.hpp` header is enough to use it.<br/>
It's a matter of adding the following line at the top of a file:
Alternatively, [Bazel](https://bazel.build) is also supported as a build system
(credits to [zaucy](https://github.com/zaucy) who offered to maintain it).<br/>
In the documentation below I'll still refer to `CMake`, this being the official
build system of the library.
```cpp
#include <registry.hpp>
```
## CMake
Then pass the proper `-I` argument to the compiler to add the `src` directory to the include paths.<br/>
To use `EnTT` from a `CMake` project, just link an existing target to the
`EnTT::EnTT` alias.<br/>
The library offers everything you need for locating (as in `find_package`),
embedding (as in `add_subdirectory`), fetching (as in `FetchContent`) or using
it in many of the ways that you can think of and that involve `CMake`.<br/>
Covering all possible cases would require a treaty and not a simple README file,
but I'm confident that anyone reading this section also knows what it's about
and can use `EnTT` from a `CMake` project without problems.
## Documentation
## Natvis support
### API Reference
When using `CMake`, just enable the option `ENTT_INCLUDE_NATVIS` and enjoy
it.<br/>
Otherwise, most of the tools are covered via Natvis and all files can be found
in the `natvis` directory, divided by module.<br/>
If you spot errors or have suggestions, any contribution is welcome!
`EnTT` contains three main actors: the *registry*, the *view* and the *pool*.<br/>
Unless you have specific requirements of memory management, the default registry (that used the pool provided with
`EnTT`) should be good enough for any use. Customization is an option anyway, so that you can use your own pool as
long as it offers the expected interface.
## Packaging Tools
#### The Registry
`EnTT` is available for some of the most known packaging tools. In particular:
There are three options to instantiate your own registry:
* [`Conan`](https://github.com/conan-io/conan-center-index), the C/C++ Package
Manager for Developers.
* By using the default one:
* [`vcpkg`](https://github.com/Microsoft/vcpkg), Microsoft VC++ Packaging
Tool.<br/>
You can download and install `EnTT` in just a few simple steps:
```cpp
auto registry = entt::DefaultRegistry<Components...>{args...};
```
```
$ git clone https://github.com/Microsoft/vcpkg.git
$ cd vcpkg
$ ./bootstrap-vcpkg.sh
$ ./vcpkg integrate install
$ vcpkg install entt
```
That is, you must provide the whole list of components to be registered with the default registry.
Or you can use the `experimental` feature to test the latest changes:
* By using the standard one:
```
vcpkg install entt[experimental] --head
```
```cpp
auto registry = entt::StandardRegistry<std::uint16_t, Components...>{args...};
```
The `EnTT` port in `vcpkg` is kept up to date by Microsoft team members and
community contributors.<br/>
If the version is out of date, please
[create an issue or pull request](https://github.com/Microsoft/vcpkg) on the
`vcpkg` repository.
That is, you must provide the whole list of components to be registered with the default registry **and** the desired type for the entities. Note that the default type is `std::uint32_t`, that is larger enough for almost all the games but also too big for the most of the games.
* [`Homebrew`](https://github.com/skypjack/homebrew-entt), the missing package
manager for macOS.<br/>
Available as a homebrew formula. Just type the following to install it:
* By using your own pool:
```
brew install skypjack/entt/entt
```
```cpp
auto registry = entt::Registry<DesiredEntityType, YourOwnPool<Components...>>{args...};
```
* [`build2`](https://build2.org), build toolchain for developing and packaging C
and C++ code.<br/>
In order to use the [`entt`](https://cppget.org/entt) package in a `build2`
project, add the following line or a similar one to the `manifest` file:
Note that the registry expects a class template where the template parameters are the components to be managed.
```
depends: entt ^3.0.0
```
In both cases, `args...` parameters are forwarded to the underlying pool during the construction.<br/>
There are no requirements for the components but to be moveable, therefore POD types are just fine.
Also check that the configuration refers to a valid repository, so that the
package can be found by `build2`:
Once you have created a registry, the followings are the exposed member functions:
* [`cppget.org`](https://cppget.org), the open-source community central
repository, accessible as `https://pkg.cppget.org/1/stable`.
* `size`: returns the number of entities still alive.
* `capacity`: returns the maximum number of entities created till now.
* `valid`: returns true if the entity is still in use, false otherwise.
* `empty<Component>`: returns `true` if at least an instance of `Component` exists, `false` otherwise.
* `empty`: returns `true` if all the entities have been destroyed, `false` otherwise.
* `create<Components...>`: creates a new entity and assigns it the given components, then returns the entity.
* `create`: creates a new entity and returns it, no components assigned.
* `destroy`: destroys the entity and all its components.
* `assign<Component>(entity, args...)`: assigns the given component to the entity and uses `args...` to initialize it.
* `remove<Component>(entity)`: removes the given component from the entity.
* `has<Components...>(entity)`: returns `true` if the entity has the given components, `false` otherwise.
* `get<Component>(entity)`: returns a reference to the given component for the entity (undefined behaviour if the entity has not the component).
* `replace<Component>(entity, args...)`: replaces the given component for the entity, using `args...` to create the new component.
* `accomodate<Component>(entity, args...)`: replaces the given component for the entity if it exists, otherwise assigns it to the entity and uses `args...` to initialize it.
* `clone(entity)`: clones an entity and all its components, then returns the new entity identifier.
* `copy<Component>(to, from)`: copies a component from an entity to another one (both the entities must already have been assigned the component, undefined behaviour otherwise).
* `copy(to, from)`: copies all the components and their contents from an entity to another one (comoonents are created or destroyed if needed).
* `reset<Component>(entity)`: removes the given component from the entity if assigned.
* `reset<Component>()`: destroys all the instances of `Component`.
* `reset()`: resets the pool and destroys all the entities and their components.
* `view<Components...>()`: gets a view of the entities that have the given components (see below for further details).
* [Package source repository](https://github.com/build2-packaging/entt):
accessible as either `https://github.com/build2-packaging/entt.git` or
`ssh://git@github.com/build2-packaging/entt.git`.
Feel free to [report issues](https://github.com/build2-packaging/entt) with
this package.
Note that entities are numbers and nothing more. They are not classes and they have no member functions at all.
Both can be used with `bpkg add-repo` or added in a project
`repositories.manifest`. See the official
[documentation](https://build2.org/build2-toolchain/doc/build2-toolchain-intro.xhtml#guide-repositories)
for more details.
#### The View
Consider this list a work in progress and help me to make it longer if you like.
There are three different kinds of view, each one with a slighlty different interface:
## pkg-config
* The _single component view_.
* The _multi component view_.
`EnTT` also supports `pkg-config` (for some definition of _supports_ at least).
A suitable file called `entt.pc` is generated and installed in a proper
directory when running `CMake`.<br/>
This should also make it easier to use with tools such as `Meson` or similar.
All of them are iterable. In other terms they have `begin` and `end` member functions that are suitable for a range-based for loop:
# Documentation
```cpp
auto view = registry.view<Position, Velocity>();
The documentation is based on [doxygen](http://www.doxygen.nl/). To build it:
for(auto entity: view) {
// do whatever you want with your entities
}
```
$ cd build
$ cmake .. -DENTT_BUILD_DOCS=ON
$ make
Iterators are extremely poor, they are meant exclusively to be used to iterate over a set of entities.<br/>
Guaranteed exposed member functions are:
The API reference will be created in HTML format within the directory
`build/docs/html`. To navigate it with your favorite browser:
* `operator++()`
* `operator++(int)`
* `operator==()`
* `operator!=()`
* `operator*()`
$ cd build
$ your_favorite_browser docs/html/index.html
The single component view has an additional member function:
<!--
@cond TURN_OFF_DOXYGEN
-->
The same version is also available [online](https://skypjack.github.io/entt/)
for the latest release, that is the last stable tag. If you are looking for
something more pleasing to the eye, consider reading the nice-looking version
available on [docsforge](https://entt.docsforge.com/): same documentation, much
more pleasant to read.<br/>
Moreover, there exists a [wiki](https://github.com/skypjack/entt/wiki) dedicated
to the project where users can find all related documentation pages.
<!--
@endcond TURN_OFF_DOXYGEN
-->
* `size()`: returns the exact number of expected entities.
The multi component view has an additional member function:
* `reset()`: reorganizes internal data so as to further create optimized iterators (use it whenever the data within the registry are known to be changed).
All the views can be used more than once. They return newly created and correctly initialized iterators whenever
`begin` or `end` is invoked. Anyway views and iterators are tiny objects and the time to construct them can be safely ignored.
I'd suggest not to store them anywhere and to invoke the `Registry::view` member function at each iteration to get a properly
initialized view over which to iterate.
**Note**: If underlying sets are modified, iterators are invalidated and using them is undefined behaviour.<br/>
Do not try to assign or remove components on which you are iterating to entities. There are no guarantees.
**Note**: Iterators aren't thread safe. Do no try to iterate over a set of components and modify them concurrently.
That being said, as long as a thread iterates over the entities that have the component `X` or assign and removes
that component from a set of entities and another thread does something similar with components `Y` and `Z`, it shouldn't be a
problem at all.<br/>
As an example, that means that users can freely run the rendering system over the renderable entities and update the physics
concurrently on a separate thread if needed.
#### The Pool
Custom pools for a given component can be defined as a specialization of the class template `ComponentPool`.<br/>
In particular:
```cpp
template<>
struct ComponentPool<Entity, MyComponent> final {
// ...
};
```
Where `Entity` is the desired type for the entities, `MyComponent` the type of the component to be stored.
A custom pool should expose at least the following member functions:
* `bool empty() const noexcept;`
* `size_type capacity() const noexcept;`
* `size_type size() const noexcept;`
* `iterator_type begin() noexcept;`
* `const_iterator_type begin() const noexcept;`
* `iterator_type end() noexcept;`
* `const_iterator_type end() const noexcept;`
* `bool has(entity_type entity) const noexcept;`
* `const component_type & get(entity_type entity) const noexcept;`
* `component_type & get(entity_type entity) noexcept;`
* `template<typename... Args> component_type & construct(entity_type entity, Args... args);`
* `void destroy(entity_type entity);`
* `void reset();`
This is a fast and easy way to define a custom pool specialization for a given component (as an example, if the
component `X` requires to be ordered internally somehow during construction or destruction operations) and to use the
default pool for all the other components.<br/>
It's a mattrer of including the given specialization along with the registry, so that it can find it during the instantiation.<br/>
In this case, users are not required to use the more explicit `Registry` class. Instead, they can still use `entt::DefaultRegistry`.
In cases when the per-component pools are not good enough, the registry can be initialized with a custom pool.<br/>
In other terms, `entt::Registry` has a template template parameter that can be used to provide both the pool and the list of
components:
```cpp
auto registry = entt::Registry<Entity, MyCustomPool<Component1, Component2>>{};
```
Even though the underlying pool doesn't store the components separately, the registry must know them to be able to do
specific actions (like `destroy` or `copy`). That's why they must be explicitly specified.<br/>
A generic pool should expose at least the following memeber functions:
* `template<typename Component> bool empty() const noexcept;`
* `template<typename Component> size_type capacity() const noexcept;`
* `template<typename Component> size_type size() const noexcept;`
* `template<typename Component> iterator_type begin() noexcept;`
* `template<typename Component> const_iterator_type begin() const noexcept;`
* `template<typename Component> iterator_type end() noexcept;`
* `template<typename Component> const_iterator_type end() const noexcept;`
* `template<typename Component> bool has(entity_type entity) const noexcept;`
* `template<typename Component> const Comp & get(entity_type entity) const noexcept;`
* `template<typename Component> Comp & get(entity_type entity) noexcept;`
* `template<typename Component, typename... Args> Comp & construct(entity_type entity, Args... args);`
* `template<typename Component> void destroy(entity_type entity);`
* `template<typename Component> void reset();`
* `void reset();`
Good luck. If you come out with a more performant components pool, do not forget to make a PR so that I can add it to
the list of available ones. I would be glad to have such a contribution to the project!!
## Tests
# Tests
To compile and run the tests, `EnTT` requires *googletest*.<br/>
Run the script `deps.sh` to download it. It is good practice to do it every time one pull the project.
`cmake` will download and compile the library before compiling anything else.
In order to build the tests, set the `CMake` option `ENTT_BUILD_TESTING` to
`ON`.
Then, to build the tests:
To build the most basic set of tests:
* `$ cd build`
* `$ cmake ..`
* `$ cmake -DENTT_BUILD_TESTING=ON ..`
* `$ make`
* `$ make test`
Note that benchmarks are not part of this set.
<!--
@cond TURN_OFF_DOXYGEN
-->
# EnTT in Action
`EnTT` is widely used in private and commercial applications. I cannot even
mention most of them because of some signatures I put on some documents time
ago. Fortunately, there are also people who took the time to implement open
source projects based on `EnTT` and did not hold back when it came to
documenting them.
[Here](https://github.com/skypjack/entt/wiki/EnTT-in-Action) you can find an
incomplete list of games, applications and articles that can be used as a
reference.
If you know of other resources out there that are about `EnTT`, feel free to
open an issue or a PR and I'll be glad to add them to the list.
# Contributors
If you want to contribute, please send patches as pull requests against the branch master.<br/>
Check the [contributors list](https://github.com/skypjack/entt/blob/master/AUTHORS) to see who has partecipated so far.
Requests for features, PRs, suggestions ad feedback are highly appreciated.
If you find you can help and want to contribute to the project with your
experience or you do want to get part of the project for some other reason, feel
free to contact me directly (you can find the mail in the
[profile](https://github.com/skypjack)).<br/>
I can't promise that each and every contribution will be accepted, but I can
assure that I'll do my best to take them all as soon as possible.
If you decide to participate, please see the guidelines for
[contributing](CONTRIBUTING.md) before to create issues or pull
requests.<br/>
Take also a look at the
[contributors list](https://github.com/skypjack/entt/blob/master/AUTHORS) to
know who has participated so far.
<!--
@endcond TURN_OFF_DOXYGEN
-->
# License
Code and documentation Copyright (c) 2017 Michele Caini.<br/>
Code released under [the MIT license](https://github.com/skypjack/entt/blob/master/LICENSE).
Code and documentation Copyright (c) 2017-2021 Michele Caini.<br/>
Colorful logo Copyright (c) 2018-2021 Richard Caseres.
Code released under
[the MIT license](https://github.com/skypjack/entt/blob/master/LICENSE).<br/>
Documentation released under
[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).<br/>
All logos released under
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).

25
TODO Normal file
View File

@@ -0,0 +1,25 @@
* long term feature: shared_ptr less locator and resource cache
* debugging tools (#60): the issue online already contains interesting tips on this, look at it
* work stealing job system (see #100) + mt scheduler based on const awareness for types
* add examples (and credits) from @alanjfs :)
WIP:
* add the possibility of disabling entities without deleting components thanks to the new full check
* add registry::storage id -> basic_sparse_set (no template arg), add example of use
* fast-contains for sparse sets (low prio but nice-to-have)
* runtime events (dispatcher/emitter), runtime context variables...
* runtime_view/registry, remove reference to basic_sparse_set<E>
* dedicated entity storage, in-place O(1) release/destroy for non-orphaned entities, out-of-sync model
* custom allocators all over
WIP:
* customizable any_vtable, sfinae-friendly definition and op::custom for user-def
* resource, forward the id to the loader from the cache and if constexpr the call to load, update doc and describe customization points
* add user data to type_info
* headless (sparse set only) view
* write documentation for custom storages and views!!
* make runtime views use opaque storage and therefore return also elements.
* add exclude-only views to combine with packs
* entity-aware observer, add observer functions aside observer class
* deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views
* snapshot: support for range-based archives

1
WORKSPACE Normal file
View File

@@ -0,0 +1 @@
workspace(name = "com_github_skypjack_entt")

View File

@@ -1,23 +0,0 @@
# can use variables like {build} and {branch}
version: 1.0.{build}
image: Visual Studio 2015
environment:
BUILD_DIR: "%APPVEYOR_BUILD_FOLDER%\\build"
platform:
- Win32
configuration:
- Release
before_build:
- deps.bat
- cd %BUILD_DIR%
- cmake .. -G"%CMAKE_GENERATOR_NAME%"
build:
parallel: true
project: build/entt.sln
verbosity: minimal

View File

@@ -0,0 +1,5 @@
@PACKAGE_INIT@
set(EnTT_VERSION "@PROJECT_VERSION@")
include("${CMAKE_CURRENT_LIST_DIR}/EnTTTargets.cmake")
check_required_components("@PROJECT_NAME@")

8
cmake/in/entt.pc.in Normal file
View File

@@ -0,0 +1,8 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: EnTT
Description: Gaming meets modern C++
Url: https://github.com/skypjack/entt
Version: @ENTT_VERSION@
Cflags: -I${includedir}

View File

@@ -1,19 +0,0 @@
project(googletest-download NONE)
cmake_minimum_required(VERSION 3.2)
include(ExternalProject)
ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
DOWNLOAD_DIR ${GOOGLETEST_DEPS_DIR}
TMP_DIR ${GOOGLETEST_DEPS_DIR}/tmp
STAMP_DIR ${GOOGLETEST_DEPS_DIR}/stamp
SOURCE_DIR ${GOOGLETEST_DEPS_DIR}/src
BINARY_DIR ${GOOGLETEST_DEPS_DIR}/build
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

37
conan/build.py Normal file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from cpt.packager import ConanMultiPackager
import os
if __name__ == "__main__":
username = os.getenv("GITHUB_ACTOR")
tag_version = os.getenv("GITHUB_REF")
tag_package = os.getenv("GITHUB_REPOSITORY")
login_username = os.getenv("CONAN_LOGIN_USERNAME")
package_version = tag_version.replace("refs/tags/v", "")
package_name = tag_package.replace("skypjack/", "")
reference = "{}/{}".format(package_name, package_version)
channel = os.getenv("CONAN_CHANNEL", "stable")
upload = os.getenv("CONAN_UPLOAD")
stable_branch_pattern = os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+.*")
test_folder = os.getenv("CPT_TEST_FOLDER", os.path.join("conan", "test_package"))
upload_only_when_stable = os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
disable_shared = os.getenv("CONAN_DISABLE_SHARED_BUILD", "False")
builder = ConanMultiPackager(username=username,
reference=reference,
channel=channel,
login_username=login_username,
upload=upload,
stable_branch_pattern=stable_branch_pattern,
upload_only_when_stable=upload_only_when_stable,
test_folder=test_folder)
builder.add()
filtered_builds = []
for settings, options, env_vars, build_requires, reference in builder.items:
if disable_shared == "False" or not options["{}:shared".format(package_name)]:
filtered_builds.append([settings, options, env_vars, build_requires])
builder.builds = filtered_builds
builder.run()

7
conan/ci/build.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -e
set -x
conan user
python conan/build.py

6
conan/ci/install.sh Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
set -e
set -x
pip install -U conan_package_tools conan

View File

@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.7.2)
project(test_package)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, CMake
import os
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

View File

@@ -0,0 +1,56 @@
#include <entt/entt.hpp>
#include <cstdint>
struct position {
float x;
float y;
};
struct velocity {
float dx;
float dy;
};
void update(entt::registry &registry) {
auto view = registry.view<position, velocity>();
for(auto entity: view) {
// gets only the components that are going to be used ...
auto &vel = view.get<velocity>(entity);
vel.dx = 0.;
vel.dy = 0.;
// ...
}
}
void update(std::uint64_t dt, entt::registry &registry) {
registry.view<position, velocity>().each([dt](auto &pos, auto &vel) {
// gets all the components of the view at once ...
pos.x += vel.dx * dt;
pos.y += vel.dy * dt;
// ...
});
}
int main() {
entt::registry registry;
std::uint64_t dt = 16;
for(auto i = 0; i < 10; ++i) {
auto entity = registry.create();
registry.emplace<position>(entity, i * 1.f, i * 1.f);
if(i % 2 == 0) { registry.emplace<velocity>(entity, i * .1f, i * .1f); }
}
update(dt, registry);
update(registry);
// ...
return EXIT_SUCCESS;
}

27
conanfile.py Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile
class EnttConan(ConanFile):
name = "entt"
description = "Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more "
topics = ("conan," "entt", "gaming", "entity", "ecs")
url = "https://github.com/skypjack/entt"
homepage = url
author = "Michele Caini <michele.caini@gmail.com>"
license = "MIT"
exports = ["LICENSE"]
exports_sources = ["src/*"]
no_copy_source = True
def package(self):
self.copy(pattern="LICENSE", dst="licenses")
self.copy(pattern="*", dst="include", src="src", keep_path=True)
def package_info(self):
if not self.in_local_cache:
self.cpp_info.includedirs = ["src"]
def package_id(self):
self.info.header_only()

2
deps/.gitignore vendored
View File

@@ -1,2 +0,0 @@
*
!.gitignore

40
docs/CMakeLists.txt Normal file
View File

@@ -0,0 +1,40 @@
#
# Doxygen configuration (documentation)
#
set(DOXY_DEPS_DIRECTORY ${EnTT_SOURCE_DIR}/deps)
set(DOXY_SOURCE_DIRECTORY ${EnTT_SOURCE_DIR}/src)
set(DOXY_DOCS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set(DOXY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
configure_file(doxy.in doxy.cfg @ONLY)
add_custom_target(
docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxy.cfg
WORKING_DIRECTORY ${EnTT_SOURCE_DIR}
VERBATIM
SOURCES
dox/extra.dox
md/config.md
md/container.md
md/core.md
md/entity.md
md/faq.md
md/lib.md
md/links.md
md/locator.md
md/meta.md
md/poly.md
md/process.md
md/reference.md
md/resource.md
md/signal.md
md/unreal.md
doxy.in
)
install(
DIRECTORY ${DOXY_OUTPUT_DIRECTORY}/html
DESTINATION share/${PROJECT_NAME}-${PROJECT_VERSION}/
)

5
docs/dox/extra.dox Normal file
View File

@@ -0,0 +1,5 @@
/**
* @namespace entt
*
* @brief `EnTT` default namespace.
*/

2609
docs/doxy.in Normal file

File diff suppressed because it is too large Load Diff

111
docs/md/config.md Normal file
View File

@@ -0,0 +1,111 @@
# Crash Course: configuration
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [Definitions](#definitions)
* [ENTT_NOEXCEPTION](#entt_noexcept)
* [ENTT_USE_ATOMIC](#entt_use_atomic)
* [ENTT_ID_TYPE](#entt_id_type)
* [ENTT_SPARSE_PAGE](#entt_sparse_page)
* [ENTT_PACKED_PAGE](#entt_packed_page)
* [ENTT_ASSERT](#entt_assert)
* [ENTT_DISABLE_ASSERT](#entt_disable_assert)
* [ENTT_NO_ETO](#entt_no_eto)
* [ENTT_STANDARD_CPP](#entt_standard_cpp)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
`EnTT` doesn't offer many hooks for customization but it certainly offers
some.<br/>
In the vast majority of cases, users will have no interest in changing the
default parameters. For all other cases, the list of possible configurations
with which it's possible to adjust the behavior of the library at runtime can be
found below.
# Definitions
All options are intended as parameters to the compiler (or user-defined macros
within the compilation units, if preferred).<br/>
Each parameter can result in internal library definitions. It's not recommended
to try to also modify these definitions, since there is no guarantee that they
will remain stable over time unlike the options below.
## ENTT_NOEXCEPTION
This parameter can be used to switch off exception handling in `EnTT`.<br/>
To do this, simply define the variable without assigning any value to it. This
is roughly equivalent to setting the compiler flag `-ff-noexceptions`.
## ENTT_USE_ATOMIC
In general, `EnTT` doesn't offer primitives to support multi-threading. Many of
the features can be split over multiple threads without any explicit control and
the user is the only one who knows if and when a synchronization point is
required.<br/>
However, some features aren't easily accessible to users and can be made
thread-safe by means of this definition.
## ENTT_ID_TYPE
`entt::id_type` is directly controlled by this definition and widely used within
the library.<br/>
By default, its type is `std::uint32_t`. However, users can define a different
default type if necessary.
## ENTT_SPARSE_PAGE
It's known that the ECS module of `EnTT` is based on _sparse sets_. What is less
known perhaps is that the sparse arrays are paged to reduce memory usage.<br/>
Default size of pages (that is, the number of elements they contain) is 4096 but
users can adjust it if appropriate. In all case, the chosen value **must** be a
power of 2.
## ENTT_PACKED_PAGE
Similar to sparse arrays, packed arrays of components are paginated as well. In
However, int this case the aim isn't to reduce memory usage but to have pointer
stability upon component creation.<br/>
Default size of pages (that is, the number of elements they contain) is 1024 but
users can adjust it if appropriate. In all case, the chosen value **must** be a
power of 2.
## ENTT_ASSERT
For performance reasons, `EnTT` doesn't use exceptions or any other control
structures. In fact, it offers many features that result in undefined behavior
if not used correctly.<br/>
To get around this, the library relies on a lot of asserts for the purpose of
detecting errors in debug builds. By default, it uses `assert` internally, but
users are allowed to overwrite its behavior by setting this variable.
### ENTT_DISABLE_ASSERT
Assertions may in turn affect performance to an extent when enabled. Whether
`ENTT_ASSERT` is redefined or not, all asserts can be disabled at once by means
of this definition.<br/>
Note that `ENTT_DISABLE_ASSERT` takes precedence over the redefinition of
`ENTT_ASSERT` and is therefore meant to disable all controls no matter what.
## ENTT_NO_ETO
In order to reduce memory consumption and increase performance, empty types are
never stored by the ECS module of `EnTT`.<br/>
Use this variable to treat these types like all others and therefore to create a
dedicated storage for them.
## ENTT_STANDARD_CPP
`EnTT` mixes non-standard language features with others that are perfectly
compliant to offer some of its functionalities.<br/>
This definition will prevent the library from using non-standard techniques,
that is, functionalities that aren't fully compliant with the standard C++.<br/>
While there are no known portability issues at the time of this writing, this
should make the library fully portable anyway if needed.

56
docs/md/container.md Normal file
View File

@@ -0,0 +1,56 @@
# Crash Course: containers
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [Containers](#containers)
* [Dense hash map](#dense-hash-map)
* [Dense hash set](#dense-hash-set)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
The standard C++ library offers a wide range of containers and it's really
difficult to do better (although it's very easy to do worse, as many examples
available online demonstrate).<br/>
`EnTT` doesn't try in any way to replace what is offered by the standard. Quite
the opposite, given the widespread use that is made of standard containers.<br/>
However, the library also tries to fill a gap in features and functionality by
making available some containers initially developed for internal use.
This section of the library is likely to grow larger over time. However, for the
moment it's quite small and mainly aimed at satisfying some internal needs.<br/>
For all containers made available, full test coverage and stability over time is
guaranteed as usual.
# Containers
## Dense hash map
The dense hash map made available in `EnTT` is a map that aims to return a
packed array of elements, so as to reduce the number of jumps in memory during
the iteration.<br/>
The implementation is based on _sparse sets_ and each bucket is identified by an
implicit list within the packed array itself.
The interface is in all respects similar to its counterpart in the standard
library, that is, `std::unordered_map`.<br/>
Therefore, there is no need to go into the API description.
## Dense hash set
The dense hash set made available in `EnTT` is a set that aims to return a
packed array of elements, so as to reduce the number of jumps in memory during
the iteration.<br/>
The implementation is based on _sparse sets_ and each bucket is identified by an
implicit list within the packed array itself.
The interface is in all respects similar to its counterpart in the standard
library, that is, `std::unordered_set`.<br/>
Therefore, there is no need to go into the API description.

856
docs/md/core.md Normal file
View File

@@ -0,0 +1,856 @@
# Crash Course: core functionalities
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [Unique sequential identifiers](#unique-sequential-identifiers)
* [Compile-time generator](#compile-time-generator)
* [Runtime generator](#runtime-generator)
* [Hashed strings](#hashed-strings)
* [Wide characters](wide-characters)
* [Conflicts](#conflicts)
* [Monostate](#monostate)
* [Any as in any type](#any-as-in-any-type)
* [Small buffer optimization](#small-buffer-optimization)
* [Alignment requirement](#alignment-requirement)
* [Type support](#type-support)
* [Built-in RTTI support](#built-in-rtti-support)
* [Type info](#type-info)
* [Almost unique identifiers](#almost-unique-identifiers)
* [Type traits](#type-traits)
* [Size of](#size-of)
* [Is applicable](#is-applicable)
* [Constness as](#constness-as)
* [Member class type](#member-class-type)
* [Integral constant](#integral-constant)
* [Tag](#tag)
* [Type list and value list](#type-list-and-value-list)
* [Compressed pair](#compressed-pair)
* [Enum as bitmask](#enum-as-bitmask)
* [Utilities](#utilities)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
`EnTT` comes with a bunch of core functionalities mostly used by the other parts
of the library itself.<br/>
Hardly users will include these features in their code, but it's worth
describing what `EnTT` offers so as not to reinvent the wheel in case of need.
# Unique sequential identifiers
Sometimes it's useful to be able to give unique, sequential numeric identifiers
to types either at compile-time or runtime.<br/>
There are plenty of different solutions for this out there and I could have used
one of them. However, I decided to spend my time to define a couple of tools
that fully embraces what the modern C++ has to offer.
## Compile-time generator
To generate sequential numeric identifiers at compile-time, `EnTT` offers the
`identifier` class template:
```cpp
// defines the identifiers for the given types
using id = entt::identifier<a_type, another_type>;
// ...
switch(a_type_identifier) {
case id::type<a_type>:
// ...
break;
case id::type<another_type>:
// ...
break;
default:
// ...
}
```
This is all what this class template has to offer: a `type` inline variable that
contains a numeric identifier for the given type. It can be used in any context
where constant expressions are required.
As long as the list remains unchanged, identifiers are also guaranteed to be
stable across different runs. In case they have been used in a production
environment and a type has to be removed, one can just use a placeholder to left
the other identifiers unchanged:
```cpp
template<typename> struct ignore_type {};
using id = entt::identifier<
a_type_still_valid,
ignore_type<a_type_no_longer_valid>,
another_type_still_valid
>;
```
Perhaps a bit ugly to see in a codebase but it gets the job done at least.
## Runtime generator
To generate sequential numeric identifiers at runtime, `EnTT` offers the
`family` class template:
```cpp
// defines a custom generator
using id = entt::family<struct my_tag>;
// ...
const auto a_type_id = id::type<a_type>;
const auto another_type_id = id::type<another_type>;
```
This is all what a _family_ has to offer: a `type` inline variable that contains
a numeric identifier for the given type.<br/>
The generator is customizable, so as to get different _sequences_ for different
purposes if needed.
Please, note that identifiers aren't guaranteed to be stable across different
runs. Indeed it mostly depends on the flow of execution.
# Hashed strings
A hashed string is a zero overhead unique identifier. Users can use
human-readable identifiers in the codebase while using their numeric
counterparts at runtime, thus without affecting performance.<br/>
The class has an implicit `constexpr` constructor that chews a bunch of
characters. Once created, all what one can do with it is getting back the
original string through the `data` member function or converting the instance
into a number.<br/>
The good part is that a hashed string can be used wherever a constant expression
is required and no _string-to-number_ conversion will take place at runtime if
used carefully.
Example of use:
```cpp
auto load(entt::hashed_string::hash_type resource) {
// uses the numeric representation of the resource to load and return it
}
auto resource = load(entt::hashed_string{"gui/background"});
```
There is also a _user defined literal_ dedicated to hashed strings to make them
more user-friendly:
```cpp
using namespace entt::literals;
constexpr auto str = "text"_hs;
```
To use it, remember that all user defined literals in `EnTT` are enclosed in the
`entt::literals` namespace. Therefore, the entire namespace or selectively the
literal of interest must be explicitly included before each use, a bit like
`std::literals`.<br/>
Finally, in case users need to create hashed strings at runtime, this class also
offers the necessary functionalities:
```cpp
std::string orig{"text"};
// create a full-featured hashed string...
entt::hashed_string str{orig.c_str()};
// ... or compute only the unique identifier
const auto hash = entt::hashed_string::value(orig.c_str());
```
This possibility shouldn't be exploited in tight loops, since the computation
takes place at runtime and no longer at compile-time and could therefore impact
performance to some degrees.
## Wide characters
The hashed string has a design that is close to that of an `std::basic_string`.
It means that `hashed_string` is nothing more than an alias for
`basic_hashed_string<char>`. For those who want to use the C++ type for wide
character representation, there exists also the alias `hashed_wstring` for
`basic_hashed_string<wchar_t>`.<br/>
In this case, the user defined literal to use to create hashed strings on the
fly is `_hws`:
```cpp
constexpr auto str = L"text"_hws;
```
Note that the hash type of the `hashed_wstring` is the same of its counterpart.
## Conflicts
The hashed string class uses internally FNV-1a to compute the numeric
counterpart of a string. Because of the _pigeonhole principle_, conflicts are
possible. This is a fact.<br/>
There is no silver bullet to solve the problem of conflicts when dealing with
hashing functions. In this case, the best solution seemed to be to give up.
That's all.<br/>
After all, human-readable unique identifiers aren't something strictly defined
and over which users have not the control. Choosing a slightly different
identifier is probably the best solution to make the conflict disappear in this
case.
# Monostate
The monostate pattern is often presented as an alternative to a singleton based
configuration system. This is exactly its purpose in `EnTT`. Moreover, this
implementation is thread safe by design (hopefully).<br/>
Keys are represented by hashed strings, values are basic types like `int`s or
`bool`s. Values of different types can be associated to each key, even more than
one at a time. Because of this, users must pay attention to use the same type
both during an assignment and when they try to read back their data. Otherwise,
they will probably incur in unexpected results.
Example of use:
```cpp
entt::monostate<entt::hashed_string{"mykey"}>{} = true;
entt::monostate<"mykey"_hs>{} = 42;
// ...
const bool b = entt::monostate<"mykey"_hs>{};
const int i = entt::monostate<entt::hashed_string{"mykey"}>{};
```
# Any as in any type
`EnTT` comes with its own `any` type. It may seem redundant considering that
C++17 introduced `std::any`, but it is not (hopefully).<br/>
In fact, the _type_ returned by an `std::any` is a const reference to an
`std::type_info`, an implementation defined class that's not something everyone
wants to see in a software. Furthermore, there is no way to connect it with the
type system of the library and therefore with its integrated RTTI support.<br/>
Note that this class is largely used internally by the library itself.
The API is very similar to that of its most famous counterpart, mainly because
this class serves the same purpose of being an opaque container for any type of
value.<br/>
Instances of `any` also minimize the number of allocations by relying on a well
known technique called _small buffer optimization_ and a fake vtable.
Creating an object of the `any` type, whether empty or not, is trivial:
```cpp
// an empty container
entt::any empty{};
// a container for an int
entt::any any{0};
// in place construction
entt::any in_place{std::in_place_type<int>, 42};
```
Alternatively, the `make_any` function serves the same purpose but requires to
always be explicit about the type:
```cpp
entt::any any = entt::make_any<int>(42);
```
In both cases, the `any` class takes the burden of destroying the contained
element when required, regardless of the storage strategy used for the specific
object.<br/>
Furthermore, an instance of `any` is not tied to an actual type. Therefore, the
wrapper will be reconfigured by assigning it an object of a different type than
the one contained, so as to be able to handle the new instance.
There exists also a way to directly assign a value to the variable contained by
an `entt::any`, without necessarily replacing it. This is especially useful when
the object is used in _aliasing mode_, as described below:
```cpp
entt::any any{42};
entt::any value{3};
// assigns by copy
any.assign(value);
// assigns by move
any.assign(std::move(value));
```
The `any` class will also perform a check on the type information and whether or
not the original type was copy or move assignable, as appropriate.<br/>
In all cases, the `assign` function returns a boolean value to indicate the
success or failure of the operation.
When in doubt about the type of object contained, the `type` member function of
`any` returns a const reference to the `type_info` associated with its element,
or `type_id<void>()` if the container is empty. The type is also used internally
when comparing two `any` objects:
```cpp
if(any == empty) { /* ... */ }
```
In this case, before proceeding with a comparison, it's verified that the _type_
of the two objects is actually the same.<br/>
Refer to the `EnTT` type system documentation for more details about how
`type_info` works and on possible risks of a comparison.
A particularly interesting feature of this class is that it can also be used as
an opaque container for const and non-const references:
```cpp
int value = 42;
entt::any any{std::in_place_type<int &>(value)};
entt::any cany = entt::make_any<const int &>(value);
entt::any fwd = entt::forward_as_any(value);
any.emplace<const int &>(value);
```
In other words, whenever `any` is explicitly told to construct an _alias_, it
acts as a pointer to the original instance rather than making a copy of it or
moving it internally. The contained object is never destroyed and users must
ensure that its lifetime exceeds that of the container.<br/>
Similarly, it's possible to create non-owning copies of `any` from an existing
object:
```cpp
// aliasing constructor
entt::any ref = other.as_ref();
```
In this case, it doesn't matter if the original container actually holds an
object or acts already as a reference for unmanaged elements, the new instance
thus created won't create copies and will only serve as a reference for the
original item.<br/>
This means that, starting from the example above, both `ref` and` other` will
point to the same object, whether it's initially contained in `other` or already
an unmanaged element.
As a side note, it's worth mentioning that, while everything works transparently
when it comes to non-const references, there are some exceptions when it comes
to const references.<br/>
In particular, the `data` member function invoked on a non-const instance of
`any` that wraps a const reference will return a null pointer in all cases.
To cast an instance of `any` to a type, the library offers a set of `any_cast`
functions in all respects similar to their most famous counterparts.<br/>
The only difference is that, in the case of `EnTT`, these won't raise exceptions
but will only trigger an assert in debug mode, otherwise resulting in undefined
behavior in case of misuse in release mode.
## Small buffer optimization
The `any` class uses a technique called _small buffer optimization_ to reduce
the number of allocations where possible.<br/>
The default reserved size for an instance of `any` is `sizeof(double[2])`.
However, this is also configurable if needed. In fact, `any` is defined as an
alias for `basic_any<Len>`, where `Len` is the size above.<br/>
Users can easily set a custom size or define their own aliases:
```cpp
using my_any = entt::basic_any<sizeof(double[4])>;
```
This feature, in addition to allowing the choice of a size that best suits the
needs of an application, also offers the possibility of forcing dynamic creation
of objects during construction.<br/>
In other terms, if the size is 0, `any` avoids the use of any optimization and
always dynamically allocates objects (except for aliasing cases).
Note that the size of the internal storage as well as the alignment requirements
are directly part of the type and therefore contribute to define different types
that won't be able to interoperate with each other.
## Alignment requirement
The alignment requirement is optional and by default the most stringent (the
largest) for any object whose size is at most equal to the one provided.<br/>
The `basic_any` class template inspects the alignment requirements in each case,
even when not provided and may decide not to use the small buffer optimization
in order to meet them.
The alignment requirement is provided as an optional second parameter following
the desired size for the internal storage:
```cpp
using my_any = entt::basic_any<sizeof(double[4]), alignof(double[4])>;
```
Note that the alignment requirements as well as the size of the internal storage
are directly part of the type and therefore contribute to define different types
that won't be able to interoperate with each other.
# Type support
`EnTT` provides some basic information about types of all kinds.<br/>
It also offers additional features that are not yet available in the standard
library or that will never be.
## Built-in RTTI support
Runtime type identification support (or RTTI) is one of the most frequently
disabled features in the C++ world, especially in the gaming sector. Regardless
of the reasons for this, it's often a shame not to be able to rely on opaque
type information at runtime.<br/>
The library tries to fill this gap by offering a built-in system that doesn't
serve as a replacement but comes very close to being one and offers similar
information to that provided by its counterpart.
Basically, the whole system relies on a handful of classes. In particular:
* The unique sequential identifier associated with a given type:
```cpp
auto index = entt::type_index<a_type>::value();
```
The returned value isn't guaranteed to be stable across different runs.
However, it can be very useful as index in associative and unordered
associative containers or for positional accesses in a vector or an array.
So as not to conflict with the other tools available, the `family` class isn't
used to generate these indexes. Therefore, the numeric identifiers returned by
the two tools may differ.<br/>
On the other hand, this leaves users with full powers over the `family` class
and therefore the generation of custom runtime sequences of indices for their
own purposes, if necessary.
An external generator can also be used if needed. In fact, `type_index` can be
specialized by type and is also _sfinae-friendly_ in order to allow more
refined specializations such as:
```cpp
template<typename Type>
struct entt::type_index<Type, std::void_d<decltype(Type::index())>> {
static entt::id_type value() ENTT_NOEXCEPT {
return Type::index();
}
};
```
Note that indexes **must** still be generated sequentially in this case.<br/>
The tool is widely used within `EnTT`. Generating indices not sequentially
would break an assumption and would likely lead to undesired behaviors.
* The hash value associated with a given type:
```cpp
auto hash = entt::type_hash<a_type>::value();
```
In general, the `value` function exposed by `type_hash` is also `constexpr`
but this isn't guaranteed for all compilers and platforms (although it's valid
with the most well-known and popular ones).
This function **can** use non-standard features of the language for its own
purposes. This makes it possible to provide compile-time identifiers that
remain stable across different runs.<br/>
In all cases, users can prevent the library from using these features by means
of the `ENTT_STANDARD_CPP` definition. In this case, there is no guarantee
that identifiers remain stable across executions. Moreover, they are generated
at runtime and are no longer a compile-time thing.
As for `type_index`, also `type_hash` is a _sfinae-friendly_ class that can be
specialized in order to customize its behavior globally or on a per-type or
per-traits basis.
* The name associated with a given type:
```cpp
auto name = entt::type_name<a_type>::value();
```
The name associated with a type is extracted from some information generally
made available by the compiler in use. Therefore, it may differ depending on
the compiler and may be empty in the event that this information isn't
available.<br/>
For example, given the following class:
```cpp
struct my_type { /* ... */ };
```
The name is `my_type` when compiled with GCC or CLang and `struct my_type`
when MSVC is in use.<br/>
Most of the time the name is also retrieved at compile-time and is therefore
always returned through an `std::string_view`. Users can easily access it and
modify it as needed, for example by removing the word `struct` to standardize
the result. `EnTT` won't do this for obvious reasons, since it requires
copying and creating a new string potentially at runtime.
This function **can** use non-standard features of the language for its own
purposes. Users can prevent the library from using non-standard features by
means of the `ENTT_STANDARD_CPP` definition. In this case, the name will be
empty by default.
As for `type_index`, also `type_name` is a _sfinae-friendly_ class that can be
specialized in order to customize its behavior globally or on a per-type or
per-traits basis.
These are then combined into utilities that aim to offer an API that is somewhat
similar to that offered by the language.
### Type info
The `type_info` class isn't a drop-in replacement for `std::type_info` but can
provide similar information which are not implementation defined and don't
require to enable RTTI.<br/>
Therefore, they can sometimes be even more reliable than those obtained
otherwise.
A type info object is an opaque class that is also copy and move constructible.
Objects of this class are returned by the `type_id` function template:
```cpp
auto info = entt::type_id<a_type>();
```
These are the information made available by a `type_info` object:
* The index associated with a given type:
```cpp
auto idx = entt::type_id<a_type>().index();
```
This is also an alias for the following:
```cpp
auto idx = entt::type_index<std::remove_const_t<std::remove_reference_t<a_type>>>::value();
```
* The hash value associated with a given type:
```cpp
auto hash = entt::type_id<a_type>().hash();
```
This is also an alias for the following:
```cpp
auto hash = entt::type_hash<std::remove_const_t<std::remove_reference_t<a_type>>>::value();
```
* The name associated with a given type:
```cpp
auto name = entt::type_id<my_type>().name();
```
This is also an alias for the following:
```cpp
auto name = entt::type_name<std::remove_const_t<std::remove_reference_t<a_type>>>::value();
```
Where all accessed features are available at compile-time, the `type_info` class
is also fully `constexpr`. However, this cannot be guaranteed in advance and
depends mainly on the compiler in use and any specializations of the classes
described above.
### Almost unique identifiers
Since the default non-standard, compile-time implementation of `type_hash` makes
use of hashed strings, it may happen that two types are assigned the same hash
value.<br/>
In fact, although this is quite rare, it's not entirely excluded.
Another case where two types are assigned the same identifier is when classes
from different contexts (for example two or more libraries loaded at runtime)
have the same fully qualified name. In this case, also `type_name` will return
the same value for the two types.<br/>
Fortunately, there are several easy ways to deal with this:
* The most trivial one is to define the `ENTT_STANDARD_CPP` macro. Runtime
identifiers don't suffer from the same problem in fact. However, this solution
doesn't work well with a plugin system, where the libraries aren't linked.
* Another possibility is to specialize the `type_name` class for one of the
conflicting types, in order to assign it a custom identifier. This is probably
the easiest solution that also preserves the feature of the tool.
* A fully customized identifier generation policy (based for example on enum
classes or preprocessing steps) may represent yet another option.
These are just some examples of possible approaches to the problem but there are
many others. As already mentioned above, since users have full control over
their types, this problem is in any case easy to solve and should not worry too
much.<br/>
In all likelihood, it will never happen to run into a conflict anyway.
## Type traits
A handful of utilities and traits not present in the standard template library
but which can be useful in everyday life.<br/>
This list **is not** exhaustive and contains only some of the most useful
classes. Refer to the inline documentation for more information on the features
offered by this module.
### Size of
The standard operator `sizeof` complains when users provide it for example with
function or incomplete types. On the other hand, it's guaranteed that its result
is always nonzero, even if applied to an empty class type.<br/>
This small class combines the two and offers an alternative to `sizeof` that
works under all circumstances, returning zero if the type isn't supported:
```cpp
const auto size = entt::size_of_v<void>;
```
### Is applicable
The standard library offers the great `std::is_invocable` trait in several
forms. This takes a function type and a series of arguments and returns true if
the condition is satisfied.<br/>
Moreover, users are also provided with `std::apply`, a tool for combining
invocable elements and tuples of arguments.
It would therefore be a good idea to have a variant of `std::is_invocable` that
also accepts its arguments in the form of a tuple-like type, so as to complete
the offer:
```cpp
constexpr bool result = entt::is_applicable<Func, std::tuple<a_type, another_type>>;
```
This trait is built on top of `std::is_invocable` and does nothing but unpack a
tuple-like type and simplify the code at the call site.
### Constness as
An utility to easily transfer the constness of a type to another type:
```cpp
// type is const dst_type because of the constness of src_type
using type = entt::constness_as_t<dst_type, const src_type>;
```
The trait is subject to the rules of the language. Therefore, for example,
transferring constness between references won't give the desired effect.
### Member class type
The `auto` template parameter introduced with C++17 made it possible to simplify
many class templates and template functions but also made the class type opaque
when members are passed as template arguments.<br/>
The purpose of this utility is to extract the class type in a few lines of code:
```cpp
template<typename Member>
using clazz = entt::member_class_t<Member>;
```
### Integral constant
Since `std::integral_constant` may be annoying because of its form that requires
to specify both a type and a value of that type, there is a more user-friendly
shortcut for the creation of integral constants.<br/>
This shortcut is the alias template `entt::integral_constant`:
```cpp
constexpr auto constant = entt::integral_constant<42>;
```
Among the other uses, when combined with a hashed string it helps to define tags
as human-readable _names_ where actual types would be required otherwise:
```cpp
constexpr auto enemy_tag = entt::integral_constant<"enemy"_hs>;
registry.emplace<enemy_tag>(entity);
```
### Tag
Since `id_type` is very important and widely used in `EnTT`, there is a more
user-friendly shortcut for the creation of integral constants based on it.<br/>
This shortcut is the alias template `entt::tag`.
If used in combination with hashed strings, it helps to use human-readable names
where types would be required otherwise. As an example:
```cpp
registry.emplace<entt::tag<"enemy"_hs>>(entity);
```
However, this isn't the only permitted use. Literally any value convertible to
`id_type` is a good candidate, such as the named constants of an unscoped enum.
### Type list and value list
There is no respectable library where the much desired _type list_ can be
missing.<br/>
`EnTT` is no exception and provides (making extensive use of it internally) the
`type_list` type, in addition to its `value_list` counterpart dedicated to
non-type template parameters.
Here is a (possibly incomplete) list of the functionalities that come with a
type list:
* `type_list_element[_t]` to get the N-th element of a type list.
* `type_list_cat[_t]` and a handy `operator+` to concatenate type lists.
* `type_list_unique[_t]` to remove duplicate types from a type list.
* `type_list_contains[_v]` to know if a type list contains a given type.
* `type_list_diff[_t]` to remove types from type lists.
I'm also pretty sure that more and more utilities will be added over time as
needs become apparent.<br/>
Many of these functionalities also exist in their version dedicated to value
lists. We therefore have `value_list_element[_v]` as well as
`value_list_cat[_t]`and so on.
# Compressed pair
Primarily designed for internal use and far from being feature complete, the
`compressed_pair` class does exactly what it promises: it tries to reduce the
size of a pair by exploiting _Empty Base Class Optimization_ (or _EBCO_).<br/>
This class **is not** a drop-in replacement for `std::pair`. However, it offers
enough functionalities to be a good alternative for when reducing memory usage
is more important than having some cool and probably useless feature.
Although the API is very close to that of `std::pair` (apart from the fact that
the template parameters are inferred from the constructor and therefore there is
no` entt::make_compressed_pair`), the major difference is that `first` and
`second` are functions for implementation needs:
```cpp
entt::compressed_pair pair{0, 3.};
pair.first() = 42;
```
There isn't much to describe then. It's recommended to rely on documentation and
intuition. At the end of the day, it's just a pair and nothing more.
# Enum as bitmask
Sometimes it's useful to be able to use enums as bitmasks. However, enum classes
aren't really suitable for the purpose out of the box. Main problem is that they
don't convert implicitly to their underlying type.<br/>
All that remains is to make a choice between using old-fashioned enums (with all
their problems that I don't want to discuss here) or writing _ugly_ code.
Fortunately, there is also a third way: adding enough operators in the global
scope to treat enum classes as bitmask transparently.<br/>
The ultimate goal is to be able to write code like the following (or maybe
something more meaningful, but this should give a grasp and remain simple at the
same time):
```cpp
enum class my_flag {
unknown = 0x01,
enabled = 0x02,
disabled = 0x04
};
const my_flag flags = my_flag::enabled;
const bool is_enabled = !!(flags & my_flag::enabled);
```
The problem with adding all operators to the global scope is that these will
come into play even when not required, with the risk of introducing errors that
are difficult to deal with.<br/>
However, C++ offers enough tools to get around this problem. In particular, the
library requires users to register all enum classes for which bitmask support
should be enabled:
```cpp
template<>
struct entt::enum_as_bitmask<my_flag>
: std::true_type
{};
```
This is handy when dealing with enum classes defined by third party libraries
and over which the users have no control. However, it's also verbose and can be
avoided by adding a specific value to the enum class itself:
```cpp
enum class my_flag {
unknown = 0x01,
enabled = 0x02,
disabled = 0x04,
_entt_enum_as_bitmask
};
```
In this case, there is no need to specialize the `enum_as_bitmask` traits, since
`EnTT` will automatically detect the flag and enable the bitmask support.<br/>
Once the enum class has been registered (in one way or the other) all the most
common operators will be available, such as `&`, `|` but also `&=` and `|=`.
Refer to the official documentation for the full list of operators.
# Utilities
It's not possible to escape the temptation to add utilities of some kind to a
library. In fact, `EnTT` also provides a handful of tools to simplify the
life of developers:
* `entt::identity`: the identity function object that will be available with
C++20. It returns its argument unchanged and nothing more. It's useful as a
sort of _do nothing_ function in template programming.
* `entt::overload`: a tool to disambiguate different overloads from their
function type. It works with both free and member functions.<br/>
Consider the following definition:
```cpp
struct clazz {
void bar(int) {}
void bar() {}
};
```
This utility can be used to get the _right_ overload as:
```cpp
auto *member = entt::overload<void(int)>(&clazz::bar);
```
The line above is literally equivalent to:
```cpp
auto *member = static_cast<void(clazz:: *)(int)>(&clazz::bar);
```
Just easier to read and shorter to type.
* `entt::overloaded`: a small class template used to create a new type with an
overloaded `operator()` from a bunch of lambdas or functors.<br/>
As an example:
```cpp
entt::overloaded func{
[](int value) { /* ... */ },
[](char value) { /* ... */ }
};
func(42);
func('c');
```
Rather useful when doing metaprogramming and having to pass to a function a
callable object that supports multiple types at once.
* `entt::y_combinator`: this is a C++ implementation of **the** _y-combinator_.
If it's not clear what it is, there is probably no need for this utility.<br/>
Below is a small example to show its use:
```cpp
entt::y_combinator gauss([](const auto &self, auto value) -> unsigned int {
return value ? (value + self(value-1u)) : 0;
});
const auto result = gauss(3u);
```
Maybe convoluted at a first glance but certainly effective. Unfortunately,
the language doesn't make it possible to do much better.
This is a rundown of the (actually few) utilities made available by `EnTT`. The
list will probably grow over time but the size of each will remain rather small,
as has been the case so far.

2307
docs/md/entity.md Normal file

File diff suppressed because it is too large Load Diff

203
docs/md/faq.md Normal file
View File

@@ -0,0 +1,203 @@
# Frequently Asked Questions
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [FAQ](#faq)
* [Why is my debug build on Windows so slow?](#why-is-my-debug-build-on-windows-so-slow)
* [How can I represent hierarchies with my components?](#how-can-i-represent-hierarchies-with-my-components)
* [Custom entity identifiers: yay or nay?](#custom-entity-identifiers-yay-or-nay)
* [Warning C4307: integral constant overflow](#warning-C4307-integral-constant-overflow)
* [Warning C4003: the min, the max and the macro](#warning-C4003-the-min-the-max-and-the-macro)
* [The standard and the non-copyable types](#the-standard-and-the-non-copyable-types)
* [Which functions trigger which signals](#which-functions-trigger-which-signals)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
This is a constantly updated section where I'll try to put the answers to the
most frequently asked questions.<br/>
If you don't find your answer here, there are two cases: nobody has done it yet
or this section needs updating. In both cases, try to
[open a new issue](https://github.com/skypjack/entt/issues/new) or enter the
[gitter channel](https://gitter.im/skypjack/entt) and ask your question.
Probably someone already has an answer for you and we can then integrate this
part of the documentation.
# FAQ
## Why is my debug build on Windows so slow?
`EnTT` is an experimental project that I also use to keep me up-to-date with the
latest revision of the language and the standard library. For this reason, it's
likely that some classes you're working with are using standard containers under
the hood.<br/>
Unfortunately, it's known that the standard containers aren't particularly
performing in debugging (the reasons for this go beyond this document) and are
even less so on Windows apparently. Fortunately this can also be mitigated a
lot, achieving good results in many cases.
First of all, there are two things to do in a Windows project:
* Disable the [`/JMC`](https://docs.microsoft.com/cpp/build/reference/jmc)
option (_Just My Code_ debugging), available starting in Visual Studio 2017
version 15.8.
* Set the [`_ITERATOR_DEBUG_LEVEL`](https://docs.microsoft.com/cpp/standard-library/iterator-debug-level)
macro to 0. This will disable checked iterators and iterator debugging.
Moreover, the macro `ENTT_ASSERT` should be redefined to disable internal checks
made by `EnTT` in debug:
```cpp
#define ENTT_ASSERT(...) ((void)0)
```
These asserts are introduced to help the users but they require to access to the
underlying containers and therefore risk ruining the performance in some cases.
With these changes, debug performance should increase enough for most cases. If
you want something more, you can can also switch to an optimization level `O0`
or preferably `O1`.
## How can I represent hierarchies with my components?
This is one of the first questions that anyone makes when starting to work with
the entity-component-system architectural pattern.<br/>
There are several approaches to the problem and whats the best one depends
mainly on the real problem one is facing. In all cases, how to do it doesn't
strictly depend on the library in use, but the latter can certainly allow or
not different techniques depending on how the data are laid out.
I tried to describe some of the techniques that fit well with the model of
`EnTT`. [Here](https://skypjack.github.io/2019-06-25-ecs-baf-part-4/) is the
first post of a series that tries to explore the problem. More will probably
come in future.<br/>
In addition, `EnTT` also offers the possibility to create stable storage types
and therefore have pointer stability for one, all or some components. This is by
far the most convenient solution when it comes to creating hierarchies and
whatnot. See the documentation for the ECS part of the library and in particular
what concerns the `component_traits` class for further details.
## Custom entity identifiers: yay or nay?
Custom entity identifiers are definitely a good idea in two cases at least:
* If `std::uint32_t` isn't large enough for your purposes, since this is the
underlying type of `entt::entity`.
* If you want to avoid conflicts when using multiple registries.
Identifiers can be defined through enum classes and class types that define an
`entity_type` member of type `std::uint32_t` or `std::uint64_t`.<br/>
In fact, this is a definition equivalent to that of `entt::entity`:
```cpp
enum class entity: std::uint32_t {};
```
There is no limit to the number of identifiers that can be defined.
## Warning C4307: integral constant overflow
According to [this](https://github.com/skypjack/entt/issues/121) issue, using a
hashed string under VS could generate a warning.<br/>
First of all, I want to reassure you: it's expected and harmless. However, it
can be annoying.
To suppress it and if you don't want to suppress all the other warnings as well,
here is a workaround in the form of a macro:
```cpp
#if defined(_MSC_VER)
#define HS(str) __pragma(warning(suppress:4307)) entt::hashed_string{str}
#else
#define HS(str) entt::hashed_string{str}
#endif
```
With an example of use included:
```cpp
constexpr auto identifier = HS("my/resource/identifier");
```
Thanks to [huwpascoe](https://github.com/huwpascoe) for the courtesy.
## Warning C4003: the min, the max and the macro
On Windows, a header file defines two macros `min` and `max` which may result in
conflicts with their counterparts in the standard library and therefore in
errors during compilation.
It's a pretty big problem but fortunately it's not a problem of `EnTT` and there
is a fairly simple solution to it.<br/>
It consists in defining the `NOMINMAX` macro before to include any other header
so as to get rid of the extra definitions:
```cpp
#define NOMINMAX
```
Please refer to [this](https://github.com/skypjack/entt/issues/96) issue for
more details.
## The standard and the non-copyable types
`EnTT` uses internally the trait `std::is_copy_constructible_v` to check if a
component is actually copyable. This trait doesn't check if an object can
actually be copied but only verifies if there is a copy constructor
available.<br/>
This can lead to surprising results due to some idiosyncrasies of the standard
mainly related to the need to guarantee backward compatibility.
For example, `std::vector` defines a copy constructor no matter if its value
type is copyable or not. As a result, `std::is_copy_constructible_v` is true
for the following specialization:
```cpp
struct type {
std::vector<std::unique_ptr<action>> vec;
};
```
When trying to assign an instance of this type to an entity in the ECS part,
this may trigger a compilation error because we cannot really make a copy of
it.<br/>
As a workaround, users can mark the type explicitly as non-copyable:
```cpp
struct type {
type(const type &) = delete;
type & operator=(const type &) = delete;
std::vector<std::unique_ptr<action>> vec;
};
```
Unfortunately, this will also disable aggregate initialization.
## Which functions trigger which signals
The `registry` class offers three signals that are emitted following specific
operations. Maybe not everyone knows what these operations are, though.<br/>
If this isn't clear, below you can find a _vademecum_ for this purpose:
* `on_created` is invoked when a component is first added (neither modified nor
replaced) to an entity.
* `on_update` is called whenever an existing component is modified or replaced.
* `on_destroyed` is called when a component is explicitly or implicitly removed
from an entity.
Among the most controversial functions can be found `emplace_or_replace` and
`destroy`. However, following the above rules, it's quite simple to know what
will happen.<br/>
In the first case, `on_created` is invoked if the entity has not the component,
otherwise the latter is replaced and therefore `on_update` is triggered. As for
the second case, components are removed from their entities and thus freed when
they are recycled. It means that `on_destroyed` is triggered for every component
owned by the entity that is destroyed.

110
docs/md/lib.md Normal file
View File

@@ -0,0 +1,110 @@
# Push EnTT across boundaries
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Working across boundaries](#working-across-boundaries)
* [Smooth until proven otherwise](#smooth-until-proven-otherwise)
* [Meta context](#meta-context)
* [Memory management](#memory-management)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Working across boundaries
`EnTT` has historically had a limit when used across boundaries on Windows in
general and on GNU/Linux when default visibility was set to hidden. The
limitation was mainly due to a custom utility used to assign unique, sequential
identifiers with different types.<br/>
Fortunately, nowadays using `EnTT` across boundaries is much easier.
## Smooth until proven otherwise
Many classes in `EnTT` make extensive use of type erasure for their purposes.
This isn't a problem on itself (in fact, it's the basis of an API so convenient
to use). However, a way is needed to recognize the objects whose type has been
erased on the other side of a boundary.<br/>
The `type_hash` class template is how identifiers are generated and thus made
available to the rest of the library. In general, this class doesn't arouse much
interest. The only exception is when a conflict between identifiers occurs
(definitely uncommon though) or when the default solution proposed by `EnTT`
isn't suitable for the user's purposes.<br/>
The section dedicated to `type_info` contains all the details to get around the
issue in a concise and elegant way. Please refer to the specific documentation.
When working with linked libraries, compile definitions `ENTT_API_EXPORT` and
`ENTT_API_IMPORT` can be used where there is a need to import or export symbols,
so as to make everything work nicely across boundaries.<br/>
On the other hand, everything should run smoothly when working with plugins or
shared libraries that don't export any symbols.
For anyone who needs more details, the test suite contains multiple examples
covering the most common cases (see the `lib` directory for all details).<br/>
It goes without saying that it's impossible to cover **all** possible cases.
However, what is offered should hopefully serve as a basis for all of them.
## Meta context
The runtime reflection system deserves a special mention when it comes to using
it across boundaries.<br/>
Since it's linked already to a static context to which the visible components
are attached and different contexts don't relate to each other, they must be
_shared_ to allow the use of meta types across boundaries.
Sharing a context is trivial though. First of all, the local one must be
acquired in the main space:
```cpp
entt::meta_ctx ctx{};
```
Then, it must passed to the receiving space that will set it as its global
context, thus releasing the local one that remains available but is no longer
referred to by the runtime reflection system:
```cpp
entt::meta_ctx::bind(ctx);
```
From now on, both spaces will refer to the same context and on it will be
attached the new visible meta types, no matter where they are created.<br/>
A context can also be reset and then associated again locally as:
```cpp
entt::meta_ctx::bind(entt::meta_ctx{});
```
This is allowed because local and global contexts are separated. Therefore, it's
always possible to make the local context the current one again.
Before to release a context, all locally registered types should be reset to
avoid dangling references. Otherwise, if a type is accessed from another space
by name, there could be an attempt to address its parts that are no longer
available.
## Memory Management
There is another subtle problem due to memory management that can lead to
headaches.<br/>
It can occur where there are pools of objects (such as components or events)
dynamically created on demand. This is usually not a problem when working with
linked libraries that rely on the same dynamic runtime. However, it can occur in
the case of plugins or statically linked runtimes.
As an example, imagine creating an instance of `registry` in the main executable
and sharing it with a plugin. If the latter starts working with a component that
is unknown to the former, a dedicated pool is created within the registry on
first use.<br/>
As one can guess, this pool is instantiated on a different side of the boundary
from the `registry`. Therefore, the instance is now managing memory from
different spaces and this can quickly lead to crashes if not properly addressed.
To overcome the risk, it's recommended to use well-defined interfaces that make
fundamental types pass through the boundaries, isolating the instances of the
`EnTT` classes from time to time and as appropriate.<br/>
Refer to the test suite for some examples, read the documentation available
online about this type of issues or consult someone who has already had such
experiences to avoid problems.

235
docs/md/links.md Normal file
View File

@@ -0,0 +1,235 @@
# EnTT in Action
`EnTT` is widely used in private and commercial applications. I cannot even
mention most of them because of some signatures I put on some documents time
ago. Fortunately, there are also people who took the time to implement open
source projects based on `EnTT` and didn't hold back when it came to documenting
them.
Below an incomplete list of games, applications and articles that can be used as
a reference. Where I put the word _apparently_ means that the use of `EnTT` is
documented but the authors didn't make explicit announcements or contacted me
directly.
I hope this list can grow much more in the future:
* Games:
* [Minecraft](https://minecraft.net/en-us/attribution/) by
[Mojang](https://mojang.com/): of course, **that** Minecraft, see the
open source attributions page for more details.
* [Minecraft Earth](https://www.minecraft.net/en-us/about-earth) by
[Mojang](https://mojang.com/): an augmented reality game for mobile, that
lets users bring Minecraft into the real world.
* [TiltedOnline](https://github.com/tiltedphoques/TiltedOnline) by
[Tilted Phoques](https://github.com/tiltedphoques): Skyrim and Fallout 4 mod
to play online.
* [Apparently](https://www.youtube.com/watch?v=P8xvOA3ikrQ&t=1105s)
[Call of Duty: Vanguard](https://www.callofduty.com/vanguard): I can neither
confirm nor deny but there is a license I know in the credits.
* [Antkeeper](https://github.com/antkeeper/antkeeper-source): an ant colony
simulation [game](https://antkeeper.com/).
* [Openblack](https://github.com/openblack/openblack): open source
reimplementation of the game _Black & White_ (2001).
* [Land of the Rair](https://github.com/LandOfTheRair/core2): the new backend
of [a retro-style MUD](https://rair.land/) for the new age.
* [Face Smash](https://play.google.com/store/apps/details?id=com.gamee.facesmash):
a game to play with your face.
* [EnTT Pacman](https://github.com/Kerndog73/EnTT-Pacman): an example of how
to make Pacman with `EnTT`.
* [Wacman](https://github.com/carlfindahl/wacman): a pacman clone with OpenGL.
* [Classic Tower Defence](https://github.com/kerndog73/Classic-Tower-Defence):
a tiny little tower defence game featuring a homemade font.
[Check it out](https://indi-kernick.itch.io/classic-tower-defence).
* [The Machine](https://github.com/Kerndog73/The-Machine): a box pushing
puzzler with logic gates and other cool stuff.
[Check it out](https://indi-kernick.itch.io/the-machine-web-version).
* [EnTTPong](https://github.com/DomRe/EnttPong): a basic game made to showcase
different parts of EnTT and C++17.
* [Randballs](https://github.com/gale93/randballs): simple `SFML` and `EnTT`
playground.
* [EnTT Tower Defense](https://github.com/Daivuk/tddod): a data oriented tower
defense example.
* [EnTT Breakout](https://github.com/vblanco20-1/entt-breakout): simple
example of a breakout game, using `SDL` and `EnTT`.
* [Arcade puzzle game with EnTT](https://github.com/MasonRG/ArcadePuzzleGame):
arcade puzzle game made in C++ using the `SDL2` and `EnTT` libraries.
* [Snake with EnTT](https://github.com/MasonRG/SnakeGame): simple snake game
made in C++ with the `SDL2` and `EnTT` libraries.
* [Mirrors lasers and robots](https://github.com/guillaume-haerinck/imac-tower-defense):
a small tower defense game based on mirror orientation.
* [PopHead](https://github.com/SPC-Some-Polish-Coders/PopHead/): 2D, Zombie,
RPG game made from scratch in C++.
* [Robotligan](https://github.com/Trisslotten/robotligan): multiplayer
football game.
* [DungeonSlayer](https://github.com/alohaeee/DungeonSlayer): 2D game made
from scratch in C++.
* [3DGame](https://github.com/kwarkGorny/3DGame): 2.5D top-down space shooter.
* [Pulcher](https://github.com/AODQ/pulcher): 2D cross-platform game inspired
by Quake.
* [Destroid](https://github.com/tyrannicaltoucan/destroid): _one-bazillionth_
arcade game about shooting dirty rocks in space, inspired by Asteroids.
* [Wanderer](https://github.com/albin-johansson/wanderer): a 2D exploration
based indie game.
* [Spelunky® Classic remake](https://github.com/dbeef/spelunky-psp): a truly
multiplatform experience with a rewrite from scratch.
* [CubbyTower](https://github.com/utilForever/CubbyTower): a simple tower
defense game using C++ with Entity Component System (ECS).
* [Runeterra](https://github.com/utilForever/Runeterra): Legends of Runeterra
simulator using C++ with some reinforcement learning.
* [Black Sun](https://store.steampowered.com/app/1670930/Black_Sun/): fly your
space ship through a large 2D open world.
* [PokeMaster](https://github.com/utilForever/PokeMaster): Pokemon Battle
simulator using C++ with some reinforcement learning.
* Engines and the like:
* [Aether Engine](https://hadean.com/spatial-simulation/)
[v1.1+](https://docs.hadean.com/v1.1/Licenses/) by
[Hadean](https://hadean.com/): a library designed for spatially partitioning
agent-based simulations.
* [Fling Engine](https://github.com/flingengine/FlingEngine): a Vulkan game
engine with a focus on data oriented design.
* [NovusCore](https://github.com/novuscore/NovusCore): a modern take on World
of Warcraft emulation.
* [Chrysalis](https://github.com/ivanhawkes/Chrysalis): action RPG SDK for
CRYENGINE games.
* [LM-Engine](https://github.com/Lawrencemm/LM-Engine): the Vim of game
engines.
* [Edyn](https://github.com/xissburg/edyn): a real-time physics engine
organized as an ECS.
* [MushMachine](https://github.com/MadeOfJelly/MushMachine): engine...
vrooooommm.
* [Antara Gaming SDK](https://github.com/KomodoPlatform/antara-gaming-sdk):
the Komodo Gaming Software Development Kit.
* [XVP](https://ravingbots.com/xvp-expansive-vehicle-physics-for-unreal-engine/):
[_eXpansive Vehicle Physics_](https://github.com/raving-bots/xvp/wiki/Plugin-integration-guide)
plugin for Unreal Engine.
* [Apparently](https://teamwisp.github.io/credits/)
[Wisp](https://teamwisp.github.io/product/) by
[Team Wisp](https://teamwisp.github.io/): an advanced real-time ray tracing
renderer built for the demands of video game artists.
* [shiva](https://github.com/Milerius/shiva): modern C++ engine with
modularity.
* [ImGui/EnTT editor](https://github.com/Green-Sky/imgui_entt_entity_editor):
a drop-in, single-file entity editor for `EnTT` that uses `ImGui` as
graphical backend (with
[demo code](https://github.com/Green-Sky/imgui_entt_entity_editor_demo)).
* [SgOgl](https://github.com/stwe/SgOgl): a game engine library for OpenGL
developed for educational purposes.
* [Lumos](https://github.com/jmorton06/Lumos): game engine written in C++
using OpenGL and Vulkan.
* [Silvanus](https://github.com/hobbyistmaker/silvanus): Silvanus Fusion 360
Box Generator.
* [Lina Engine](https://github.com/inanevin/LinaEngine): an open-source,
modular, tiny and fast C++ game engine, aimed to develop 3D desktop games.
* [Spike](https://github.com/FahimFuad/Spike): a powerful game engine which
can run on a toaster.
* [Helena Framework](https://github.com/NIKEA-SOFT/HelenaFramework): a modern
framework in C++17 for backend development.
* [Unity/EnTT](https://github.com/TongTungGiang/unity-entt): tech demo of a
native simulation layer using `EnTT` and `Unity` as a rendering engine.
* [OverEngine](https://github.com/OverShifted/OverEngine): an over-engineered
game engine.
* [Electro](https://github.com/Electro-Technologies/Electro): high performance
3D game engine with a high emphasis on rendering.
* [Kawaii](https://github.com/Mathieu-Lala/Kawaii_Engine): a modern data
oriented game engine.
* [Becketron](https://github.com/Doctor-Foxling/Becketron): a game engine
written mostly in C++.
* [Spatial Engine](https://github.com/luizgabriel/Spatial.Engine): A
cross-platform engine created on top of google's filament rendering engine.
* [Kaguya](https://github.com/KaiH0717/Kaguya): D3D12 Rendering Engine.
* [OpenAWE](https://github.com/OpenAWE-Project/OpenAWE): Open implementation
of the Alan Wake Engine.
* Articles, videos and blog posts:
* [Some posts](https://skypjack.github.io/tags/#entt) on my personal
[blog](https://skypjack.github.io/) are about `EnTT`, for those who want to
know **more** on this project.
* [Game Engine series](https://www.youtube.com/c/TheChernoProject/videos) by
[The Cherno](https://github.com/TheCherno) (not only about `EnTT` but also
on the use of an ECS in general):
- [Intro to EnTT](https://www.youtube.com/watch?v=D4hz0wEB978).
- [Entities and Components](https://www.youtube.com/watch?v=-B1iu4QJTUc).
- [The ENTITY Class](https://www.youtube.com/watch?v=GfSzeAcsBb0).
- [Camera Systems](https://www.youtube.com/watch?v=ubZn7BlrnTU).
- [Scene Camera](https://www.youtube.com/watch?v=UKVFRRufKzo).
- [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).
- [Camera Component UI](https://www.youtube.com/watch?v=RIMt_6agUiU).
- [Drawing Component UI](https://www.youtube.com/watch?v=u3yq8s3KuSE).
- [Transform Component UI](https://www.youtube.com/watch?v=8JqcXYbzPJc).
- [Adding/Removing Entities and Components UI](https://www.youtube.com/watch?v=PsyGmsIgp9M).
- [Saving and Loading Scenes](https://www.youtube.com/watch?v=IEiOP7Y-Mbc).
- ... And so on.
[Check out](https://www.youtube.com/channel/UCQ-W1KE9EYfdxhL6S4twUNw) the
_Game Engine Series_ by The Cherno for more videos.
* [Space Battle: Huge edition](http://victor.madtriangles.com/code%20experiment/2018/06/11/post-ecs-battle-huge.html):
huge space battle built entirely from scratch.
* [Space Battle](https://github.com/vblanco20-1/ECS_SpaceBattle): huge space
battle built on `UE4`.
* [Experimenting with ECS in UE4](http://victor.madtriangles.com/code%20experiment/2018/03/25/post-ue4-ecs-battle.html):
interesting article about `UE4` and `EnTT`.
* [Implementing ECS architecture in UE4](https://forums.unrealengine.com/development-discussion/c-gameplay-programming/1449913-implementing-ecs-architecture-in-ue4-giant-space-battle):
giant space battle.
* [Conan Adventures (SFML and EnTT in C++)](https://leinnan.github.io/blog/conan-adventuressfml-and-entt-in-c.html):
create projects in modern C++ using `SFML`, `EnTT`, `Conan` and `CMake`.
* [Adding EnTT ECS to Chrysalis](https://www.tauradius.com/post/adding-an-ecs-to-chrysalis/):
a blog entry (and its
[follow-up](https://www.tauradius.com/post/chrysalis-update-2020-08-02/))
about the integration of `EnTT` into `Chrysalis`, an action RPG SDK for
CRYENGINE games.
* [Creating Minecraft in One Week with C++ and Vulkan](https://vazgriz.com/189/creating-minecraft-in-one-week-with-c-and-vulkan/):
a crack at recreating Minecraft in one week using a custom C++ engine and
Vulkan ([code included](https://github.com/vazgriz/VoxelGame)).
* [Ability Creator](https://www.erichildebrand.net/blog/ability-creator-project-retrospect):
project retrospect by [Eric Hildebrand](https://www.erichildebrand.net/).
* [EnTT Entity Component System Gaming Library](https://gamefromscratch.com/entt-entity-component-system-gaming-library/):
`EnTT` on GameFromScratch.com.
* Any Other Business:
* [ArcGIS Runtime SDKs](https://developers.arcgis.com/arcgis-runtime/) by
[Esri](https://www.esri.com/): they use `EnTT` for the internal ECS and the
cross platform C++ rendering engine. The SDKs are utilized by a lot of
enterprise custom apps, as well as by Esri for its own public applications
such as
[Explorer](https://play.google.com/store/apps/details?id=com.esri.explorer),
[Collector](https://play.google.com/store/apps/details?id=com.esri.arcgis.collector)
and
[Navigator](https://play.google.com/store/apps/details?id=com.esri.navigator).
* [FASTSUITE Edition 2](https://www.fastsuite.com/en_EN/fastsuite/fastsuite-edition-2.html)
by [Cenit](http://www.cenit.com/en_EN/about-us/overview.html): they use
`EnTT` to drive their simulation, that is, the communication between robot
controller emulator and renderer.
* [Ragdoll](https://ragdolldynamics.com/): real-time physics for Autodesk Maya
2020.
* [Project Lagrange](https://github.com/adobe/lagrange): a robust geometry
processing library by [Adobe](https://github.com/adobe).
* [AtomicDEX](https://github.com/KomodoPlatform/atomicDEX-Desktop): a secure
wallet and non-custodial decentralized exchange rolled into one application.
* [Apparently](https://www.linkedin.com/in/skypjack/)
[NIO](https://www.nio.io/): there was a collaboration to make some changes
to `EnTT`, at the time used for internal projects.
* [Apparently](https://www.linkedin.com/jobs/view/architekt-c%2B%2B-at-tieto-1219512333/)
[Tieto](https://www.tieto.com/): they published a job post where `EnTT` was
listed on their software stack.
* [Sequentity](https://github.com/alanjfs/sequentity): A MIDI-like
sequencer/tracker for C++ and `ImGui` (with `Magnum` and `EnTT`).
* [EnTT meets Sol2](https://github.com/skaarj1989/entt-meets-sol2): freely
available examples of how to combine `EnTT` and `Sol2`.
* [Godot meets EnTT](https://github.com/portaloffreedom/godot_entt_example/):
a simple example on how to use `EnTT` within
[`Godot`](https://godotengine.org/).
* [Godot and GameNetworkingSockets meet EnTT](https://github.com/portaloffreedom/godot_entt_net_example):
a simple example on how to use `EnTT` and
[`GameNetworkingSockets`](https://github.com/ValveSoftware/GameNetworkingSockets)
within [`Godot`](https://godotengine.org/).
* [MatchOneEntt](https://github.com/mhaemmerle/MatchOneEntt): port of
[Match One](https://github.com/sschmid/Match-One) for `Entitas-CSharp`.
* GitHub contains also
[many other examples](https://github.com/search?o=desc&q=%22skypjack%2Fentt%22&s=indexed&type=Code)
of use of `EnTT` from which to take inspiration if interested.
If you know of other resources out there that are about `EnTT`, feel free to
open an issue or a PR and I'll be glad to add them to this page.

75
docs/md/locator.md Normal file
View File

@@ -0,0 +1,75 @@
# Crash Course: service locator
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [Service locator](#service-locator)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
Usually service locators are tightly bound to the services they expose and it's
hard to define a general purpose solution. This template based implementation
tries to fill the gap and to get rid of the burden of defining a different
specific locator for each application.<br/>
This class is tiny, partially unsafe and thus risky to use. Moreover it doesn't
fit probably most of the scenarios in which a service locator is required. Look
at it as a small tool that can sometimes be useful if users know how to handle
it.
# Service locator
The API is straightforward. The basic idea is that services are implemented by
means of interfaces and rely on polymorphism.<br/>
The locator is instantiated with the base type of the service if any and a
concrete implementation is provided along with all the parameters required to
initialize it. As an example:
```cpp
// the service has no base type, a locator is used to treat it as a kind of singleton
entt::service_locator<my_service>::set(params...);
// sets up an opaque service
entt::service_locator<audio_interface>::set<audio_implementation>(params...);
// resets (destroys) the service
entt::service_locator<audio_interface>::reset();
```
The locator can also be queried to know if an active service is currently set
and to retrieve it if necessary (either as a pointer or as a reference):
```cpp
// no service currently set
auto empty = entt::service_locator<audio_interface>::empty();
// gets a (possibly empty) shared pointer to the service ...
std::shared_ptr<audio_interface> ptr = entt::service_locator<audio_interface>::get();
// ... or a reference, but it's undefined behaviour if the service isn't set yet
audio_interface &ref = entt::service_locator<audio_interface>::ref();
```
A common use is to wrap the different locators in a container class, creating
aliases for the various services:
```cpp
struct locator {
using camera = entt::service_locator<camera_interface>;
using audio = entt::service_locator<audio_interface>;
// ...
};
// ...
void init() {
locator::camera::set<camera_null>();
locator::audio::set<audio_implementation>(params...);
// ...
}
```

978
docs/md/meta.md Normal file
View File

@@ -0,0 +1,978 @@
# Crash Course: runtime reflection system
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [Names and identifiers](#names-and-identifiers)
* [Reflection in a nutshell](#reflection-in-a-nutshell)
* [Any to the rescue](#any-to-the-rescue)
* [Enjoy the runtime](#enjoy-the-runtime)
* [Container support](#container-support)
* [Pointer-like types](#pointer-like-types)
* [Template information](#template-information)
* [Automatic conversions](#automatic-conversions)
* [Implicitly generated default constructor](#implicitly-generated-default-constructor)
* [Policies: the more, the less](#policies-the-more-the-less)
* [Named constants and enums](#named-constants-and-enums)
* [Properties and meta objects](#properties-and-meta-objects)
* [Unregister types](#unregister-types)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
Reflection (or rather, its lack) is a trending topic in the C++ world and a tool
that can unlock a lot of interesting feature in the specific case of `EnTT`. I
looked for a third-party library that met my needs on the subject, but I always
came across some details that I didn't like: macros, being intrusive, too many
allocations, and so on.<br/>
I finally decided to write a built-in, non-intrusive and macro-free runtime
reflection system for `EnTT`. Maybe I didn't do better than others or maybe yes,
time will tell me, but at least I can model this tool around the library to
which it belongs and not the opposite.
# Names and identifiers
The meta system doesn't force users to rely on the tools provided by the library
when it comes to working with names and identifiers. It does this by offering an
API that works with opaque identifiers that may or may not be generated by means
of a hashed string.<br/>
This means that users can assign any type of identifier to the meta objects, as
long as they are numeric. It doesn't matter if they are generated at runtime, at
compile-time or with custom functions.
That being said, the examples in the following sections are all based on the
`hashed_string` class as provided by this library. Therefore, where an
identifier is required, it's likely that an user defined literal is used as
follows:
```cpp
auto factory = entt::meta<my_type>().type("reflected_type"_hs);
```
For what it's worth, this is likely completely equivalent to:
```cpp
auto factory = entt::meta<my_type>().type(42);
```
Obviously, human-readable identifiers are more convenient to use and highly
recommended.
# Reflection in a nutshell
Reflection always starts from real types (users cannot reflect imaginary types
and it would not make much sense, we wouldn't be talking about reflection
anymore).<br/>
To create a meta node, the library provides the `meta` function that accepts a
type to reflect as a template parameter:
```cpp
auto factory = entt::meta<my_type>();
```
This isn't enough to _export_ the given type and make it visible though.<br/>
The returned value is a factory object to use to continue building the meta
type. In order to make the type _visible_, users can assign it an identifier:
```cpp
auto factory = entt::meta<my_type>().type("reflected_type"_hs);
```
Or use the default one, that is, the built-in identifier for the given type:
```cpp
auto factory = entt::meta<my_type>().type();
```
Identifiers are important because users can retrieve meta types at runtime by
searching for them by _name_ other than by type.<br/>
On the other hand, there are cases in which users can be interested in adding
features to a reflected type so that the reflection system can use it correctly
under the hood, but they don't want to also make the type _searchable_. In this
case, it's sufficient not to invoke `type`.
A factory is such that all its member functions return the factory itself or a
decorated version of it. This object can be used to add the following:
* _Constructors_. Actual constructors can be assigned to a reflected type by
specifying their list of arguments. Free functions (namely, factories) can be
used as well, as long as the return type is the expected one. From a client's
point of view, nothing changes if a constructor is a free function or an
actual constructor.<br/>
Use the `ctor` member function for this purpose:
```cpp
entt::meta<my_type>().ctor<int, char>().ctor<&factory>();
```
* _Destructors_. Free functions and member functions can be used as destructors
of reflected types. The purpose is to give users the ability to free up
resources that require special treatment before an object is actually
destroyed.<br/>
Use the `dtor` member function for this purpose:
```cpp
entt::meta<my_type>().dtor<&destroy>();
```
A function should neither delete nor explicitly invoke the destructor of a
given instance.
* _Data members_. Both real data members of the underlying type and static and
global variables, as well as constants of any kind, can be attached to a meta
type. From the point of view of the client, all the variables associated with
the reflected type will appear as if they were part of the type itself.<br/>
Use the `data` member function for this purpose:
```cpp
entt::meta<my_type>()
.data<&my_type::static_variable>("static"_hs)
.data<&my_type::data_member>("member"_hs)
.data<&global_variable>("global"_hs);
```
The function requires as an argument the identifier to give to the meta data
once created. Users can then access meta data at runtime by searching for them
by _name_.<br/>
Data members can also be defined by means of a setter and getter pair. Setters
and getters can be either free functions, class members or a mix of them, as
long as they respect the required signatures. This approach is also convenient
to create a read-only variable from a non-const data member:
```cpp
entt::meta<my_type>().data<nullptr, &my_type::data_member>("member"_hs);
```
Multiple setters are also supported by means of a `value_list` object:
```cpp
entt::meta<my_type>().data<entt::value_list<&from_int, &from_string>, &my_type::data_member>("member"_hs);
```
Refer to the inline documentation for all the details.
* _Member functions_. Both real member functions of the underlying type and free
functions can be attached to a meta type. From the point of view of the
client, all the functions associated with the reflected type will appear as if
they were part of the type itself.<br/>
Use the `func` member function for this purpose:
```cpp
entt::meta<my_type>()
.func<&my_type::static_function>("static"_hs)
.func<&my_type::member_function>("member"_hs)
.func<&free_function>("free"_hs);
```
The function requires as an argument the identifier to give to the meta
function once created. Users can then access meta functions at runtime by
searching for them by _name_.<br/>
Overloading of meta functions is supported. Overloaded functions are resolved
at runtime by the reflection system according to the types of the arguments.
* _Base classes_. A base class is such that the underlying type is actually
derived from it. In this case, the reflection system tracks the relationship
and allows for implicit casts at runtime when required.<br/>
Use the `base` member function for this purpose:
```cpp
entt::meta<derived_type>().base<base_type>();
```
From now on, wherever a `base_type` is required, an instance of `derived_type`
will also be accepted.
* _Conversion functions_. Actual types can be converted, this is a fact. Just
think of the relationship between a `double` and an `int` to see it. Similar
to bases, conversion functions allow users to define conversions that will be
implicitly performed by the reflection system when required.<br/>
Use the `conv` member function for this purpose:
```cpp
entt::meta<double>().conv<int>();
```
That's all, everything users need to create meta types and enjoy the reflection
system. At first glance it may not seem that much, but users usually learn to
appreciate it over time.<br/>
Also, do not forget what these few lines hide under the hood: a built-in,
non-intrusive and macro-free system for reflection in C++. Features that are
definitely worth the price, at least for me.
## Any to the rescue
The reflection system offers a kind of _extended version_ of the `entt::any`
class (see the core module for more details).<br/>
The purpose is to add some feature on top of those already present, so as to
integrate it with the meta type system without having to duplicate the code.
The API is very similar to that of the `any` type. The class `meta_any` _wraps_
many of the feature to infer a meta node, before forwarding some or all of the
arguments to the underlying storage.<br/>
Among the few relevant differences, `meta_any` adds support for containers and
pointer-like types (see the following sections for more details), while `any`
does not.<br/>
Similar to `any`, this class can also be used to create _aliases_ for unmanaged
objects either with `forward_as_meta` or using the `std::in_place_type<T &>`
disambiguation tag, as well as from an existing object by means of the `as_ref`
member function. However, unlike `any`, `meta_any` treats an empty instance and
one initialized with `void` differently:
```cpp
entt::meta_any empty{};
entt::meta_any other{std::in_place_type<void>};
```
While `any` considers both as empty, `meta_any` treats objects initialized with
`void` as if they were _valid_ ones. This allows to differentiate between failed
function calls and function calls that are successful but return nothing.<br/>
Finally, the member functions `try_cast`, `cast` and `allow_cast` are used to
cast the underlying object to a given type (either a reference or a value type)
or to _convert_ a `meta_any` in such a way that a cast becomes viable for the
resulting object. There is in fact no `any_cast` equivalent for `meta_any`.
## Enjoy the runtime
Once the web of reflected types has been constructed, it's a matter of using it
at runtime where required.<br/>
All this has the great merit that the reflection system stands in fact as a
non-intrusive tool for the runtime, unlike the vast majority of the things
offered by this library and closely linked to the compile-time.
To search for a reflected type there are a few options:
```cpp
// direct access to a reflected type
auto by_type = entt::resolve<my_type>();
// look up a reflected type by identifier
auto by_id = entt::resolve("reflected_type"_hs);
// look up a reflected type by type info
auto by_type_id = entt::resolve(entt::type_id<my_type>());
```
There exits also an overload of the `resolve` function to use to iterate all the
reflected types at once. It returns an iterable object that can be used in a
range-for loop:
```cpp
for(auto type: entt::resolve()) {
// ...
}
```
In all cases, the returned value is an instance of `meta_type`. This kind of
objects offer an API to know their _runtime identifiers_, to iterate all the
meta objects associated with them and even to build instances of the underlying
type.<br/>
Refer to the inline documentation for all the details.
The meta objects that compose a meta type are accessed in the following ways:
* _Meta data_. They are accessed by _name_:
```cpp
auto data = entt::resolve<my_type>().data("member"_hs);
```
The returned type is `meta_data` and may be invalid if there is no meta data
object associated with the given identifier.<br/>
A meta data object offers an API to query the underlying type (for example, to
know if it's a const or a static one), to get the meta type of the variable
and to set or get the contained value.
* _Meta functions_. They are accessed by _name_:
```cpp
auto func = entt::resolve<my_type>().func("member"_hs);
```
The returned type is `meta_func` and may be invalid if there is no meta
function object associated with the given identifier.<br/>
A meta function object offers an API to query the underlying type (for
example, to know if it's a const or a static function), to know the number of
arguments, the meta return type and the meta types of the parameters. In
addition, a meta function object can be used to invoke the underlying function
and then get the return value in the form of a `meta_any` object.
* _Meta bases_. They are accessed through the _name_ of the base types:
```cpp
auto base = entt::resolve<derived_type>().base("base"_hs);
```
The returned type is `meta_type` and may be invalid if there is no meta base
object associated with the given identifier.
All the objects thus obtained as well as the meta types can be explicitly
converted to a boolean value to check if they are valid:
```cpp
if(auto func = entt::resolve<my_type>().func("member"_hs); func) {
// ...
}
```
Furthermore, all them are also returned by specific overloads that provide the
caller with iterable ranges of top-level elements. As an example:
```cpp
for(auto data: entt::resolve<my_type>().data()) {
// ...
}
```
A meta type can be used to `construct` actual instances of the underlying
type.<br/>
In particular, the `construct` member function accepts a variable number of
arguments and searches for a match. It then returns a `meta_any` object that may
or may not be initialized, depending on whether a suitable constructor has been
found or not.
There is no object that wraps the destructor of a meta type nor a `destroy`
member function in its API. Destructors are invoked implicitly by `meta_any`
behind the scenes and users have not to deal with them explicitly. Furthermore,
they have no name, cannot be searched and wouldn't have member functions to
expose anyway.<br/>
Similarly, conversion functions aren't directly accessible. They are used
internally by `meta_any` and the meta objects when needed.
Meta types and meta objects in general contain much more than what is said: a
plethora of functions in addition to those listed whose purposes and uses go
unfortunately beyond the scope of this document.<br/>
I invite anyone interested in the subject to look at the code, experiment and
read the inline documentation to get the best out of this powerful tool.
## Container support
The runtime reflection system also supports containers of all types.<br/>
Moreover, _containers_ doesn't necessarily mean those offered by the C++
standard library. In fact, user defined data structures can also work with the
meta system in many cases.
To make a container be recognized as such by the meta system, users are required
to provide specializations for either the `meta_sequence_container_traits` class
or the `meta_associative_container_traits` class, according with the actual type
of the container.<br/>
`EnTT` already exports the specializations for some common classes. In
particular:
* `std::vector` and `std::array` are exported as _sequence containers_.
* `std::map`, `std::set` and their unordered counterparts are exported as
_associative containers_.
It's important to include the header file `container.hpp` to make these
specializations available to the compiler when needed.<br/>
The same file also contains many examples for the users that are interested in
making their own containers available to the meta system.
When a specialization of the `meta_sequence_container_traits` class exists, the
meta system treats the wrapped type as a sequence container. In a similar way,
a type is treated as an associative container if a specialization of the
`meta_associative_container_traits` class is found for it.<br/>
Proxy objects are returned by dedicated members of the `meta_any` class. The
following is a deliberately verbose example of how users can access a proxy
object for a sequence container:
```cpp
std::vector<int> vec{1, 2, 3};
entt::meta_any any = entt::forward_as_meta(vec);
if(any.type().is_sequence_container()) {
if(auto view = any.as_sequence_container(); view) {
// ...
}
}
```
The method to use to get a proxy object for associative containers is
`as_associative_container` instead.<br/>
It goes without saying that it's not necessary to perform a double check.
Instead, it's sufficient to query the meta type or verify that the proxy object
is valid. In fact, proxies are contextually convertible to bool to know if they
are valid. For example, invalid proxies are returned when the wrapped object
isn't a container.<br/>
In all cases, users aren't expected to _reflect_ containers explicitly. It's
sufficient to assign a container for which a specialization of the traits
classes exists to a `meta_any` object to be able to get its proxy object.
The interface of the `meta_sequence_container` proxy object is the same for all
types of sequence containers, although the available features differ from case
to case. In particular:
* The `value_type` member function returns the meta type of the elements.
* The `size` member function returns the number of elements in the container as
an unsigned integer value:
```cpp
const auto size = view.size();
```
* The `resize` member function allows to resize the wrapped container and
returns true in case of succes:
```cpp
const bool ok = view.resize(3u);
```
For example, it's not possible to resize fixed size containers.
* The `clear` member function allows to clear the wrapped container and returns
true in case of success:
```cpp
const bool ok = view.clear();
```
For example, it's not possible to clear fixed size containers.
* The `begin` and `end` member functions return opaque iterators that can be
used to iterate the container directly:
```cpp
for(entt::meta_any element: view) {
// ...
}
```
In all cases, given an underlying container of type `C`, the returned element
contains an object of type `C::value_type` which therefore depends on the
actual container.<br/>
All meta iterators are input iterators and don't offer an indirection operator
on purpose.
* The `insert` member function can be used to add elements to the container. It
accepts a meta iterator and the element to insert:
```cpp
auto last = view.end();
// appends an integer to the container
view.insert(last, 42);
```
This function returns a meta iterator pointing to the inserted element and a
boolean value to indicate whether the operation was successful or not. Note
that a call to `insert` may silently fail in case of fixed size containers or
whether the arguments aren't at least convertible to the required types.<br/>
Since the meta iterators are contextually convertible to bool, users can rely
on them to know if the operation has failed on the actual container or
upstream, for example for an argument conversion problem.
* The `erase` member function can be used to remove elements from the container.
It accepts a meta iterator to the element to remove:
```cpp
auto first = view.begin();
// removes the first element from the container
view.erase(first);
```
This function returns a meta iterator following the last removed element and a
boolean value to indicate whether the operation was successful or not. Note
that a call to `erase` may silently fail in case of fixed size containers.
* The `operator[]` can be used to access elements in a container. It accepts a
single argument, that is the position of the element to return:
```cpp
for(std::size_t pos{}, last = view.size(); pos < last; ++pos) {
entt::meta_any value = view[pos];
// ...
}
```
The function returns instances of `meta_any` that directly refer to the actual
elements. Modifying the returned object will then directly modify the element
inside the container.
Similarly, also the interface of the `meta_associative_container` proxy object
is the same for all types of associative containers. However, there are some
differences in behavior in the case of key-only containers. In particular:
* The `key_only` member function returns true if the wrapped container is a
key-only one.
* The `key_type` member function returns the meta type of the keys.
* The `mapped_type` member function returns an invalid meta type for key-only
containers and the meta type of the mapped values for all other types of
containers.
* The `value_type` member function returns the meta type of the elements.<br/>
For example, it returns the meta type of `int` for `std::set<int>` while it
returns the meta type of `std::pair<const int, char>` for
`std::map<int, char>`.
* The `size` member function returns the number of elements in the container as
an unsigned integer value:
```cpp
const auto size = view.size();
```
* The `clear` member function allows to clear the wrapped container and returns
true in case of success:
```cpp
const bool ok = view.clear();
```
* The `begin` and `end` member functions return opaque iterators that can be
used to iterate the container directly:
```cpp
for(std::pair<entt::meta_any, entt::meta_any> element: view) {
// ...
}
```
In all cases, given an underlying container of type `C`, the returned element
is a key-value pair where the key has type `C::key_type` and the value has
type `C::mapped_type`. Since key-only containers don't have a mapped type,
their _value_ is nothing more than an invalid `meta_any` object.<br/>
All meta iterators are input iterators and don't offer an indirection operator
on purpose.
While the accessed key is usually constant in the associative containers and
is therefore returned by copy, the value (if any) is wrapped by an instance of
`meta_any` that directly refers to the actual element. Modifying it will then
directly modify the element inside the container.
* The `insert` member function can be used to add elements to the container. It
accepts two arguments, respectively the key and the value to be inserted:
```cpp
auto last = view.end();
// appends an integer to the container
view.insert(last.handle(), 42, 'c');
```
This function returns a boolean value to indicate whether the operation was
successful or not. Note that a call to `insert` may fail when the arguments
aren't at least convertible to the required types.
* The `erase` member function can be used to remove elements from the container.
It accepts a single argument, that is the key to be removed:
```cpp
view.erase(42);
```
This function returns a boolean value to indicate whether the operation was
successful or not. Note that a call to `erase` may fail when the argument
isn't at least convertible to the required type.
* The `operator[]` can be used to access elements in a container. It accepts a
single argument, that is the key of the element to return:
```cpp
entt::meta_any value = view[42];
```
The function returns instances of `meta_any` that directly refer to the actual
elements. Modifying the returned object will then directly modify the element
inside the container.
Container support is minimal but likely sufficient to satisfy all needs.
## Pointer-like types
As with containers, it's also possible to communicate to the meta system which
types to consider _pointers_. This will allow to dereference instances of
`meta_any`, thus obtaining light _references_ to the pointed objects that are
also correctly associated with their meta types.<br/>
To make the meta system recognize a type as _pointer-like_, users can specialize
the `is_meta_pointer_like` class. `EnTT` already exports the specializations for
some common classes. In particular:
* All types of raw pointers.
* `std::unique_ptr` and `std::shared_ptr`.
It's important to include the header file `pointer.hpp` to make these
specializations available to the compiler when needed.<br/>
The same file also contains many examples for the users that are interested in
making their own pointer-like types available to the meta system.
When a type is recognized as a pointer-like one by the meta system, it's
possible to dereference the instances of `meta_any` that contain these objects.
The following is a deliberately verbose example to show how to use this feature:
```cpp
int value = 42;
// meta type equivalent to that of int *
entt::meta_any any{&value};
if(any.type().is_pointer_like()) {
// meta type equivalent to that of int
if(entt::meta_any ref = *any; ref) {
// ...
}
}
```
Of course, it's not necessary to perform a double check. Instead, it's enough to
query the meta type or verify that the returned object is valid. For example,
invalid instances are returned when the wrapped object isn't a pointer-like
type.<br/>
Note that dereferencing a pointer-like object returns an instance of `meta_any`
which refers to the pointed object and allows users to modify it directly
(unless the returned element is const, of course).
In general, _dereferencing_ a pointer-like type boils down to a `*ptr`. However,
`EnTT` also supports classes that don't offer an `operator*`. In particular:
* It's possible to exploit a solution based on ADL lookup by offering a function
(also a template one) named `dereference_meta_pointer_like`:
```cpp
template<typename Type>
Type & dereference_meta_pointer_like(const custom_pointer_type<Type> &ptr) {
return ptr.deref();
}
```
* When not in control of the type's namespace, it's possible to inject into the
`entt` namespace a specialization of the `adl_meta_pointer_like` class
template to bypass the adl lookup as a whole:
```cpp
template<typename Type>
struct entt::adl_meta_pointer_like<custom_pointer_type<Type>> {
static decltype(auto) dereference(const custom_pointer_type<Type> &ptr) {
return ptr.deref();
}
};
```
In all other cases, that is, when dereferencing a pointer works as expected and
regardless of the pointed type, no user intervention is required.
## Template information
Meta types also provide a minimal set of information about the nature of the
original type in case it's a class template.<br/>
By default, this works out of the box and requires no user action. However, it's
important to include the header file `template.hpp` to make these information
available to the compiler when needed.
Meta template information are easily found:
```cpp
// this method returns true if the type is recognized as a class template specialization
if(auto type = entt::resolve<std::shared_ptr<my_type>>(); type.is_template_specialization()) {
// meta type of the class template conveniently wrapped by entt::meta_class_template_tag
auto class_type = type.template_type();
// number of template arguments
std::size_t arity = type.template_arity();
// meta type of the i-th argument
auto arg_type = type.template_arg(0u);
}
```
Typically, when template information for a type are required, what the library
provides is sufficient. However, there are some cases where a user may want more
details or a different set of information.<br/>
Consider the case of a class template that is meant to wrap function types:
```cpp
template<typename>
struct function_type;
template<typename Ret, typename... Args>
struct function_type<Ret(Args...)> {};
```
In this case, rather than the function type, the user might want the return type
and unpacked arguments as if they were different template parameters for the
original class template.<br/>
To achieve this, users must enter the library internals and provide their own
specialization for the class template `entt::meta_template_traits`, such as:
```cpp
template<typename Ret, typename... Args>
struct entt::meta_template_traits<function_type<Ret(Args...)>> {
using class_type = meta_class_template_tag<function_type>;
using args_type = type_list<Ret, Args...>;
};
```
The reflection system doesn't verify the accuracy of the information nor infer a
correspondence between real types and meta types.<br/>
Therefore, the specialization will be used as is and the information it contains
will be associated with the appropriate type when required.
## Automatic conversions
In C++, there are a number of conversions allowed between arithmetic types that
make it convenient to work with this kind of data.<br/>
If this were to be translated into explicit registrations with the reflection
system, it would result in a long series of instructions such as the following:
```cpp
entt::meta<int>()
.conv<bool>()
.conv<char>()
// ...
.conv<double>();
```
Repeated for each type eligible to undergo this type of conversions. This is
both error prone and repetitive.<br/>
Similarly, the language allows users to silently convert unscoped enums to their
underlying types and offers what it takes to do the same for scoped enums. It
would result in the following if it were to be done explicitly:
```cpp
entt::meta<my_enum>()
.conv<std::underlying_type_t<my_enum>>();
```
Fortunately, all of this can also be avoided. `EnTT` offers implicit support for
these types of conversions:
```cpp
entt::meta_any any{42};
any.allow_cast<double>();
double value = any.cast<double>();
```
With no need for registration, the conversion takes place automatically under
the hood. The same goes for a call to `allow_cast` involving a meta type:
```cpp
entt::meta_type type = entt::resolve<int>();
entt::meta_any any{my_enum::a_value};
any.allow_cast(type);
int value = any.cast<int>();
```
This should make working with arithmetic types and scoped or unscoped enums as
easy as it is in C++.<br/>
It's also worth noting that it's still possible to set up conversion functions
manually and these will always be preferred over the automatic ones.
## Implicitly generated default constructor
In many cases, it's useful to be able to create objects of default constructible
types through the reflection system, while not having to explicitly register the
meta type or the default constructor.<br/>
For example, in the case of primitive types like `int` or `char`, but not just
them.
For this reason and only for default constructible types, default constructors
are automatically defined and associated with their meta types, whether they are
explicitly or implicitly generated.<br/>
Therefore, this is all is needed to construct an integer from its meta type:
```cpp
entt::resolve<int>().construct();
```
Where the meta type can be for example the one returned from a meta container,
useful for building keys without knowing or having to register the actual types.
In all cases, when users register default constructors, they are preferred both
during searches and when the `construct` member function is invoked.
## Policies: the more, the less
Policies are a kind of compile-time directives that can be used when registering
reflection information.<br/>
Their purpose is to require slightly different behavior than the default in some
specific cases. For example, when reading a given data member, its value is
returned wrapped in a `meta_any` object which, by default, makes a copy of it.
For large objects or if the caller wants to access the original instance, this
behavior isn't desirable. Policies are there to offer a solution to this and
other problems.
There are a few alternatives available at the moment:
* The _as-is_ policy, associated with the type `entt::as_is_t`.<br/>
This is the default policy. In general, it should never be used explicitly,
since it's implicitly selected if no other policy is specified.<br/>
In this case, the return values of the functions as well as the properties
exposed as data members are always returned by copy in a dedicated wrapper and
therefore associated with their original meta types.
* The _as-void_ policy, associated with the type `entt::as_void_t`.<br/>
Its purpose is to discard the return value of a meta object, whatever it is,
thus making it appear as if its type were `void`:
```cpp
entt::meta<my_type>().func<&my_type::member_function, entt::as_void_t>("member"_hs);
```
If the use with functions is obvious, it must be said that it's also possible
to use this policy with constructors and data members. In the first case, the
constructor will be invoked but the returned wrapper will actually be empty.
In the second case, instead, the property will not be accessible for reading.
* The _as-ref_ and _as-cref_ policies, associated with the types
`entt::as_ref_t` and `entt::as_cref_t`.<br/>
They allow to build wrappers that act as references to unmanaged objects.
Accessing the object contained in the wrapper for which the _reference_ was
requested will make it possible to directly access the instance used to
initialize the wrapper itself:
```cpp
entt::meta<my_type>().data<&my_type::data_member, entt::as_ref_t>("member"_hs);
```
These policies work with constructors (for example, when objects are taken
from an external container rather than created on demand), data members and
functions in general.<br/>
If on the one hand `as_cref_t` always forces the return type to be const,
`as_ref_t` _adapts_ to the constness of the passed object and to that of the
return type if any.
Some uses are rather trivial, but it's useful to note that there are some less
obvious corner cases that can in turn be solved with the use of policies.
## Named constants and enums
A special mention should be made for constant values and enums. It wouldn't be
necessary, but it will help distracted readers.
As mentioned, the `data` member function can be used to reflect constants of any
type among the other things.<br/>
This allows users to create meta types for enums that will work exactly like any
other meta type built from a class. Similarly, arithmetic types can be enriched
with constants of special meaning where required.<br/>
Personally, I find it very useful not to export what is the difference between
enums and classes in C++ directly in the space of the reflected types.
All the values thus exported will appear to users as if they were constant data
members of the reflected types.
Exporting constant values or elements from an enum is as simple as ever:
```cpp
entt::meta<my_enum>()
.data<my_enum::a_value>("a_value"_hs)
.data<my_enum::another_value>("another_value"_hs);
entt::meta<int>().data<2048>("max_int"_hs);
```
It goes without saying that accessing them is trivial as well. It's a matter of
doing the following, as with any other data member of a meta type:
```cpp
auto value = entt::resolve<my_enum>().data("a_value"_hs).get({}).cast<my_enum>();
auto max = entt::resolve<int>().data("max_int"_hs).get({}).cast<int>();
```
As a side note, remember that all this happens behind the scenes without any
allocation because of the small object optimization performed by the `meta_any`
class.
## Properties and meta objects
Sometimes (for example, when it comes to creating an editor) it might be useful
to attach properties to the meta objects created. Fortunately, this is possible
for most of them.<br/>
For the meta objects that support properties, the member functions of the
factory used for registering them will return a decorated version of the factory
itself. The latter can be used to attach properties to the last created meta
object.<br/>
Apparently, it's more difficult to say than to do:
```cpp
entt::meta<my_type>().type("reflected_type"_hs).prop("tooltip"_hs, "message");
```
Properties are always in the key/value form. There are no restrictions on the
type of the key or value, as long as they are copy constructible objects.<br/>
Multiple formats are supported when it comes to defining a property:
* Properties as key/value pairs:
```cpp
entt::meta<my_type>().type("reflected_type"_hs).prop("tooltip"_hs, "message");
```
* Properties as `std::pair`s:
```cpp
entt::meta<my_type>().type("reflected_type"_hs).prop(std::make_pair("tooltip"_hs, "message"));
```
* Key only properties:
```cpp
entt::meta<my_type>().type("reflected_type"_hs).prop(my_enum::key_only);
```
* Properties as `std::tuple`s:
```cpp
entt::meta<my_type>().type("reflected_type"_hs).prop(std::make_tuple(std::make_pair("tooltip"_hs, "message"), my_enum::key_only));
```
A tuple contains one or more properties. All of them are treated individually.
Note that it's not possible to invoke `prop` multiple times for the same meta
object and trying to do that will result in a compilation error.<br/>
However, the `props` function is available to associate several properties at
once. In this case, properties in the key/value form aren't allowed, since they
would be interpreted as two different properties rather than a single one.
The meta objects for which properties are supported are currently meta types,
meta data and meta functions.<br/>
These types also offer a couple of member functions named `prop` to iterate all
properties at once or to search a specific property by key:
```cpp
// iterate all properties of a meta type
for(auto prop: entt::resolve<my_type>().prop()) {
// ...
}
// search for a given property by name
auto prop = entt::resolve<my_type>().prop("tooltip"_hs);
```
Meta properties are objects having a fairly poor interface, all in all. They
only provide the `key` and the `value` member functions to be used to retrieve
the key and the value contained in the form of `meta_any` objects, respectively.
## Unregister types
A type registered with the reflection system can also be unregistered. This
means unregistering all its data members, member functions, conversion functions
and so on. However, base classes aren't unregistered as well, since they don't
necessarily depend on it. Similarly, implicitly generated types (as an example,
the meta types implicitly generated for function parameters when needed) aren't
unregistered.<br/>
Roughly speaking, unregistering a type means disconnecting all associated meta
objects from it and making its identifier no longer visible. The underlying node
will remain available though, as if it were implicitly generated:
```cpp
entt::meta_reset<my_type>();
```
It's also possible to reset types by their unique identifiers if required:
```cpp
entt::meta_reset("my_type"_hs);
```
Finally, there exists a non-template overload of the `meta_reset` function that
doesn't accept argument and resets all searchable types (that is, all types that
were assigned an unique identifier):
```cpp
entt::meta_reset();
```
All types can be re-registered later with a completely different name and form.

359
docs/md/poly.md Normal file
View File

@@ -0,0 +1,359 @@
# Crash Course: poly
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [Other libraries](#other-libraries)
* [Concept and implementation](#concept-and-implementation)
* [Deduced interface](#deduced-interface)
* [Defined interface](#defined-interface)
* [Fullfill a concept](#fullfill-a-concept)
* [Inheritance](#inheritance)
* [Static polymorphism in the wild](#static-polymorphism-in-the-wild)
* [Storage size and alignment requirement](#storage-size-and-alignment-requirement)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
Static polymorphism is a very powerful tool in C++, albeit sometimes cumbersome
to obtain.<br/>
This module aims to make it simple and easy to use.
The library allows to define _concepts_ as interfaces to fullfill with concrete
classes withouth having to inherit from a common base.<br/>
This is, among others, one of the advantages of static polymorphism in general
and of a generic wrapper like that offered by the `poly` class template in
particular.<br/>
What users get is an object that can be passed around as such and not through a
reference or a pointer, as happens when it comes to working with dynamic
polymorphism.
Since the `poly` class template makes use of `entt::any` internally, it also
supports most of its feature. Among the most important, the possibility to
create aliases to existing and thus unmanaged objects. This allows users to
exploit the static polymorphism while maintaining ownership of objects.<br/>
Likewise, the `poly` class template also benefits from the small buffer
optimization offered by the `entt::any` class and therefore minimizes the number
of allocations, avoiding them altogether where possible.
## Other libraries
There are some very interesting libraries regarding static polymorphism.<br/>
Among all, the two that I prefer are:
* [`dyno`](https://github.com/ldionne/dyno): runtime polymorphism done right.
* [`Poly`](https://github.com/facebook/folly/blob/master/folly/docs/Poly.md):
a class template that makes it easy to define a type-erasing polymorphic
object wrapper.
The former is admittedly an experimental library, with many interesting ideas.
I've some doubts about the usefulness of some feature in real world projects,
but perhaps my lack of experience comes into play here. In my opinion, its only
flaw is the API which I find slightly more cumbersome than other solutions.<br/>
The latter was undoubtedly a source of inspiration for this module, although I
opted for different choices in the implementation of both the final API and some
feature.
Either way, the authors are gurus of the C++ community, people I only have to
learn from.
# Concept and implementation
The first thing to do to create a _type-erasing polymorphic object wrapper_ (to
use the terminology introduced by Eric Niebler) is to define a _concept_ that
types will have to adhere to.<br/>
For this purpose, the library offers a single class that supports both deduced
and fully defined interfaces. Although having interfaces deduced automatically
is convenient and allows users to write less code in most cases, this has some
limitations and it's therefore useful to be able to get around the deduction by
providing a custom definition for the static virtual table.
Once the interface is defined, it will be sufficient to provide a generic
implementation to fullfill the concept.<br/>
Also in this case, the library allows customizations based on types or families
of types, so as to be able to go beyond the generic case where necessary.
## Deduced interface
This is how a concept with a deduced interface is introduced:
```cpp
struct Drawable: entt::type_list<> {
template<typename Base>
struct type: Base {
void draw() { this->template invoke<0>(*this); }
};
// ...
};
```
It's recognizable by the fact that it inherits from an empty type list.<br/>
Functions can also be const, accept any number of paramters and return a type
other than `void`:
```cpp
struct Drawable: entt::type_list<> {
template<typename Base>
struct type: Base {
bool draw(int pt) const { return this->template invoke<0>(*this, pt); }
};
// ...
};
```
In this case, all parameters must be passed to `invoke` after the reference to
`this` and the return value is whatever the internal call returns.<br/>
As for `invoke`, this is a name that is injected into the _concept_ through
`Base`, from which one must necessarily inherit. Since it's also a dependent
name, the `this-> template` form is unfortunately necessary due to the rules of
the language. However, there exists also an alternative that goes through an
external call:
```cpp
struct Drawable: entt::type_list<> {
template<typename Base>
struct type: Base {
void draw() const { entt::poly_call<0>(*this); }
};
// ...
};
```
Once the _concept_ is defined, users must provide a generic implementation of it
in order to tell the system how any type can satisfy its requirements. This is
done via an alias template within the concept itself.<br/>
The index passed as a template parameter to either `invoke` or `poly_call`
refers to how this alias is defined.
## Defined interface
A fully defined concept is no different to one for which the interface is
deduced, with the only difference that the list of types is not empty this time:
```cpp
struct Drawable: entt::type_list<void()> {
template<typename Base>
struct type: Base {
void draw() { entt::poly_call<0>(*this); }
};
// ...
};
```
Again, parameters and return values other than `void` are allowed. Also, the
function type must be const when the method to bind to it is const:
```cpp
struct Drawable: entt::type_list<bool(int) const> {
template<typename Base>
struct type: Base {
bool draw(int pt) const { return entt::poly_call<0>(*this, pt); }
};
// ...
};
```
Why should a user fully define a concept if the function types are the same as
the deduced ones?<br>
Because, in fact, this is exactly the limitation that can be worked around by
manually defining the static virtual table.
When things are deduced, there is an implicit constraint.<br/>
If the concept exposes a member function called `draw` with function type
`void()`, a concept can be satisfied:
* Either by a class that exposes a member function with the same name and the
same signature.
* Or through a lambda that makes use of existing member functions from the
interface itself.
In other words, it's not possible to make use of functions not belonging to the
interface, even if they are present in the types that fulfill the concept.<br/>
Similarly, it's not possible to deduce a function in the static virtual table
with a function type different from that of the associated member function in
the interface itself.
Explicitly defining a static virtual table suppresses the deduction step and
allows maximum flexibility when providing the implementation for a concept.
## Fullfill a concept
The `impl` alias template of a concept is used to define how it's fulfilled:
```cpp
struct Drawable: entt::type_list<> {
// ...
template<typename Type>
using impl = entt::value_list<&Type::draw>;
};
```
In this case, it's stated that the `draw` method of a generic type will be
enough to satisfy the requirements of the `Drawable` concept.<br/>
Both member functions and free functions are supported to fullfill concepts:
```cpp
template<typename Type>
void print(Type &self) { self.print(); }
struct Drawable: entt::type_list<void()> {
// ...
template<typename Type>
using impl = entt::value_list<&print<Type>>;
};
```
Likewise, as long as the parameter types and return type support conversions to
and from those of the function type referenced in the static virtual table, the
actual implementation may differ in its function type since it's erased
internally.<br/>
Moreover, the `self` parameter isn't strictly required by the system and can be
left out for free functions if not required.
Refer to the inline documentation for more details.
# Inheritance
_Concept inheritance_ is straightforward due to how poly looks like in `EnTT`.
Therefore, it's quite easy to build hierarchies of concepts if necessary.<br/>
The only constraint is that all concepts in a hierarchy must belong to the same
_family_, that is, they must be either all deduced or all defined.
For a deduced concept, inheritance is achieved in a few steps:
```cpp
struct DrawableAndErasable: entt::type_list<> {
template<typename Base>
struct type: typename Drawable::template type<Base> {
static constexpr auto base = std::tuple_size_v<typename entt::poly_vtable<Drawable>::type>;
void erase() { entt::poly_call<base + 0>(*this); }
};
template<typename Type>
using impl = entt::value_list_cat_t<
typename Drawable::impl<Type>,
entt::value_list<&Type::erase>
>;
};
```
The static virtual table is empty and must remain so.<br/>
On the other hand, `type` no longer inherits from `Base` and instead forwards
its template parameter to the type exposed by the _base class_. Internally, the
size of the static virtual table of the base class is used as an offset for the
local indexes.<br/>
Finally, by means of the `value_list_cat_t` utility, the implementation consists
in appending the new functions to the previous list.
As for a defined concept instead, also the list of types must be extended, in a
similar way to what is shown for the implementation of the above concept.<br/>
To do this, it's useful to declare a function that allows to convert a _concept_
into its underlying `type_list` object:
```cpp
template<typename... Type>
entt::type_list<Type...> as_type_list(const entt::type_list<Type...> &);
```
The definition isn't strictly required, since the function will only be used
through a `decltype` as it follows:
```cpp
struct DrawableAndErasable: entt::type_list_cat_t<
decltype(as_type_list(std::declval<Drawable>())),
entt::type_list<void()>
> {
// ...
};
```
Similar to above, `type_list_cat_t` is used to concatenate the underlying static
virtual table with the new function types.<br/>
Everything else is the same as already shown instead.
# Static polymorphism in the wild
Once the _concept_ and implementation have been introduced, it will be possible
to use the `poly` class template to contain instances that meet the
requirements:
```cpp
using drawable = entt::poly<Drawable>;
struct circle {
void draw() { /* ... */ }
};
struct square {
void draw() { /* ... */ }
};
// ...
drawable instance{circle{}};
instance->draw();
instance = square{};
instance->draw();
```
The `poly` class template offers a wide range of constructors, from the default
one (which will return an uninitialized `poly` object) to the copy and move
constructors, as well as the ability to create objects in-place.<br/>
Among others, there is also a constructor that allows users to wrap unmanaged
objects in a `poly` instance (either const or non-const ones):
```cpp
circle shape;
drawable instance{std::in_place_type<circle &>, shape};
```
Similarly, it's possible to create non-owning copies of `poly` from an existing
object:
```cpp
drawable other = instance.as_ref();
```
In both cases, although the interface of the `poly` object doesn't change, it
won't construct any element or take care of destroying the referenced objects.
Note also how the underlying concept is accessed via a call to `operator->` and
not directly as `instance.draw()`.<br/>
This allows users to decouple the API of the wrapper from that of the concept.
Therefore, where `instance.data()` will invoke the `data` member function of the
poly object, `instance->data()` will map directly to the functionality exposed
by the underlying concept.
# Storage size and alignment requirement
Under the hood, the `poly` class template makes use of `entt::any`. Therefore,
it can take advantage of the possibility of defining at compile-time the size of
the storage suitable for the small buffer optimization as well as the alignment
requirements:
```cpp
entt::basic_poly<Drawable, sizeof(double[4]), alignof(double[4])>
```
The default size is `sizeof(double[2])`, which seems like a good compromise
between a buffer that is too large and one unable to hold anything larger than
an integer. The alignment requirement is optional instead and by default such
that it's the most stringent (the largest) for any object whose size is at most
equal to the one provided.<br/>
It's worth noting that providing a size of 0 (which is an accepted value in all
respects) will force the system to dynamically allocate the contained objects in
all cases.

212
docs/md/process.md Normal file
View File

@@ -0,0 +1,212 @@
# Crash Course: cooperative scheduler
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [The process](#the-process)
* [Adaptor](#adaptor)
* [The scheduler](#the-scheduler)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
Sometimes processes are a useful tool to work around the strict definition of a
system and introduce logic in a different way, usually without resorting to the
introduction of other components.
`EnTT` offers a minimal support to this paradigm by introducing a few classes
that users can use to define and execute cooperative processes.
# The process
A typical process must inherit from the `process` class template that stays true
to the CRTP idiom. Moreover, derived classes must specify what's the intended
type for elapsed times.
A process should expose publicly the following member functions whether needed
(note that it isn't required to define a function unless the derived class wants
to _override_ the default behavior):
* `void update(Delta, void *);`
It's invoked once per tick until a process is explicitly aborted or it
terminates either with or without errors. Even though it's not mandatory to
declare this member function, as a rule of thumb each process should at
least define it to work properly. The `void *` parameter is an opaque pointer
to user data (if any) forwarded directly to the process during an update.
* `void init();`
It's invoked when the process joins the running queue of a scheduler. This
happens as soon as it's attached to the scheduler if the process is a top
level one, otherwise when it replaces its parent if the process is a
continuation.
* `void succeeded();`
It's invoked in case of success, immediately after an update and during the
same tick.
* `void failed();`
It's invoked in case of errors, immediately after an update and during the
same tick.
* `void aborted();`
It's invoked only if a process is explicitly aborted. There is no guarantee
that it executes in the same tick, this depends solely on whether the
process is aborted immediately or not.
Derived classes can also change the internal state of a process by invoking
`succeed` and `fail`, as well as `pause` and `unpause` the process itself. All
these are protected member functions made available to be able to manage the
life cycle of a process from a derived class.
Here is a minimal example for the sake of curiosity:
```cpp
struct my_process: entt::process<my_process, std::uint32_t> {
using delta_type = std::uint32_t;
my_process(delta_type delay)
: remaining{delay}
{}
void update(delta_type delta, void *) {
remaining -= std::min(remaining, delta);
// ...
if(!remaining) {
succeed();
}
}
private:
delta_type remaining;
};
```
## Adaptor
Lambdas and functors can't be used directly with a scheduler for they are not
properly defined processes with managed life cycles.<br/>
This class helps in filling the gap and turning lambdas and functors into
full featured processes usable by a scheduler.
The function call operator has a signature similar to the one of the `update`
function of a process but for the fact that it receives two extra arguments to
call whenever a process is terminated with success or with an error:
```cpp
void(Delta delta, void *data, auto succeed, auto fail);
```
Parameters have the following meaning:
* `delta` is the elapsed time.
* `data` is an opaque pointer to user data if any, `nullptr` otherwise.
* `succeed` is a function to call when a process terminates with success.
* `fail` is a function to call when a process terminates with errors.
Both `succeed` and `fail` accept no parameters at all.
Note that usually users shouldn't worry about creating adaptors at all. A
scheduler creates them internally each and every time a lambda or a functor is
used as a process.
# The scheduler
A cooperative scheduler runs different processes and helps managing their life
cycles.
Each process is invoked once per tick. If it terminates, it's removed
automatically from the scheduler and it's never invoked again. Otherwise it's
a good candidate to run one more time the next tick.<br/>
A process can also have a child. In this case, the parent process is replaced
with its child when it terminates and only if it returns with success. In case
of errors, both the parent process and its child are discarded. This way, it's
easy to create chain of processes to run sequentially.
Using a scheduler is straightforward. To create it, users must provide only the
type for the elapsed times and no arguments at all:
```cpp
entt::scheduler<std::uint32_t> scheduler;
```
It has member functions to query its internal data structures, like `empty` or
`size`, as well as a `clear` utility to reset it to a clean state:
```cpp
// checks if there are processes still running
const auto empty = scheduler.empty();
// gets the number of processes still running
entt::scheduler<std::uint32_t>::size_type size = scheduler.size();
// resets the scheduler to its initial state and discards all the processes
scheduler.clear();
```
To attach a process to a scheduler there are mainly two ways:
* If the process inherits from the `process` class template, it's enough to
indicate its type and submit all the parameters required to construct it to
the `attach` member function:
```cpp
scheduler.attach<my_process>(1000u);
```
* Otherwise, in case of a lambda or a functor, it's enough to provide an
instance of the class to the `attach` member function:
```cpp
scheduler.attach([](auto...){ /* ... */ });
```
In both cases, the return value is an opaque object that offers a `then` member
function to use to create chains of processes to run sequentially.<br/>
As a minimal example of use:
```cpp
// schedules a task in the form of a lambda function
scheduler.attach([](auto delta, void *, auto succeed, auto fail) {
// ...
})
// appends a child in the form of another lambda function
.then([](auto delta, void *, auto succeed, auto fail) {
// ...
})
// appends a child in the form of a process class
.then<my_process>(1000u);
```
To update a scheduler and therefore all its processes, the `update` member
function is the way to go:
```cpp
// updates all the processes, no user data are provided
scheduler.update(delta);
// updates all the processes and provides them with custom data
scheduler.update(delta, &data);
```
In addition to these functions, the scheduler offers an `abort` member function
that can be used to discard all the running processes at once:
```cpp
// aborts all the processes abruptly ...
scheduler.abort(true);
// ... or gracefully during the next tick
scheduler.abort();
```

71
docs/md/reference.md Normal file
View File

@@ -0,0 +1,71 @@
# Similar projects
There are many projects similar to `EnTT`, both open source and not.<br/>
Some even borrowed some ideas from this library and expressed them in different
languages.<br/>
Others developed different architectures from scratch and therefore offer
alternative solutions with their pros and cons.
Below an incomplete list of those that I've come across so far.<br/>
If some terms or designs aren't clear, I recommend referring to the
[_ECS Back and Forth_](https://skypjack.github.io/tags/#ecs) series for all the
details.
I hope this list can grow much more in the future:
* C:
* [destral_ecs](https://github.com/roig/destral_ecs): a single-file ECS based
on sparse sets.
* [Diana](https://github.com/discoloda/Diana): an ECS that uses sparse sets to
keep track of entities in systems.
* [Flecs](https://github.com/SanderMertens/flecs): a multithreaded archetype
ECS based on semi-contiguous arrays rather than chunks.
* [lent](https://github.com/nem0/lent): the Donald Trump of the ECS libraries.
* C++:
* [decs](https://github.com/vblanco20-1/decs): a chunk based archetype ECS.
* [ecst](https://github.com/SuperV1234/ecst): a multithreaded compile-time
ECS that uses sparse sets to keep track of entities in systems.
* [EntityX](https://github.com/alecthomas/entityx): a bitset based ECS that
uses a single large matrix of components indexed with entities.
* [Polypropylene](https://github.com/pmbittner/Polypropylene): a hybrid
solution between an ECS and dynamic mixins.
* C#
* [Entitas](https://github.com/sschmid/Entitas-CSharp): the ECS framework for
C# and Unity, where _reactive systems_ were invented.
* [LeoECS](https://github.com/Leopotam/ecs): simple lightweight C# Entity
Component System framework.
* [Svelto.ECS](https://github.com/sebas77/Svelto.ECS): a very interesting
platform agnostic and table based ECS framework.
* Go:
* [gecs](https://github.com/tutumagi/gecs): a sparse sets based ECS inspired
by `EnTT`.
* Javascript:
* [\@javelin/ecs](https://github.com/3mcd/javelin/tree/master/packages/ecs):
an archetype ECS in TypeScript.
* [ecsy](https://github.com/MozillaReality/ecsy): I haven't had the time to
investigate the underlying design of `ecsy` but it looks cool anyway.
* Perl:
* [Game::Entities](https://gitlab.com/jjatria/perl-game-entities): a simple
entity registry for ECS designs inspired by `EnTT`.
* Raku:
* [Game::Entities](https://gitlab.com/jjatria/raku-game-entities): a simple
entity registry for ECS designs inspired by `EnTT`.
* Rust:
* [Legion](https://github.com/TomGillen/legion): a chunk based archetype ECS.
* [Shipyard](https://github.com/leudz/shipyard): it borrows some ideas from
`EnTT` and offers a sparse sets based ECS with grouping functionalities.
* [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.

231
docs/md/resource.md Normal file
View File

@@ -0,0 +1,231 @@
# Crash Course: resource management
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [The resource, the loader and the cache](#the-resource-the-loader-and-the-cache)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
Resource management is usually one of the most critical part of a software like
a game. Solutions are often tuned to the particular application. There exist
several approaches and all of them are perfectly fine as long as they fit the
requirements of the piece of software in which they are used.<br/>
Examples are loading everything on start, loading on request, predictive
loading, and so on.
`EnTT` doesn't pretend to offer a _one-fits-all_ solution for the different
cases. Instead, it offers a minimal and perhaps trivial cache that can be useful
most of the time during prototyping and sometimes even in a production
environments.<br/>
For those interested in the subject, the plan is to improve it considerably over
time in terms of performance, memory usage and functionalities. Hoping to make
it, of course, one step at a time.
# The resource, the loader and the cache
There are three main actors in the model: the resource, the loader and the
cache.
The _resource_ is whatever users want it to be. An image, a video, an audio,
whatever. There are no limits.<br/>
As a minimal example:
```cpp
struct my_resource { const int value; };
```
A _loader_ is a class the aim of which is to load a specific resource. It has to
inherit directly from a dedicated base class as in the following example:
```cpp
struct my_loader final: entt::resource_loader<my_loader, my_resource> {
// ...
};
```
Where `my_resource` is the type of resources it creates.<br/>
A resource loader must also expose a public const member function named `load`
that accepts a variable number of arguments and returns a shared pointer to a
resource.<br/>
As an example:
```cpp
struct my_loader: entt::resource_loader<my_loader, my_resource> {
std::shared_ptr<my_resource> load(int value) const {
// ...
return std::shared_ptr<my_resource>(new my_resource{ value });
}
};
```
In general, resource loaders should not have a state or retain data of any type.
They should let the cache manage their resources instead.<br/>
As a side note, base class and CRTP idiom aren't strictly required with the
current implementation. One could argue that a cache can easily work with
loaders of any type. However, future changes won't be breaking ones by forcing
the use of a base class today and that's why the model is already in its place.
Finally, a cache is a specialization of a class template tailored to a specific
resource:
```cpp
using my_cache = entt::resource_cache<my_resource>;
// ...
my_cache cache{};
```
The idea is to create different caches for different types of resources and to
manage each one independently in the most appropriate way.<br/>
As a (very) trivial example, audio tracks can survive in most of the scenes of
an application while meshes can be associated with a single scene and then
discarded when users leave it.
A cache offers a set of basic functionalities to query its internal state and to
_organize_ it:
```cpp
// gets the number of resources managed by a cache
const auto size = cache.size();
// checks if a cache contains at least a valid resource
const auto empty = cache.empty();
// clears a cache and discards its content
cache.clear();
```
Besides these member functions, a cache contains what is needed to load, use and
discard resources of the given type.<br/>
Before exploring this part of the interface, it makes sense to mention how
resources are identified. They have type `id_type` and therefore they can be
created explicitly as in the following example:
```cpp
constexpr auto identifier = "my/resource/identifier"_hs;
// this is equivalent to the following
constexpr entt::id_type hs = entt::hashed_string{"my/resource/identifier"};
```
The class `hashed_string` is described in a dedicated section, so I won't go in
details here.
Resources are loaded and thus stored in a cache through the `load` member
function. It accepts the loader to use as a template parameter, the resource
identifier and the parameters used to construct the resource as arguments:
```cpp
// uses the identifier declared above
cache.load<my_loader>(identifier, 0);
// uses a hashed string directly
cache.load<my_loader>("another/identifier"_hs, 42);
```
The function returns a handle to the resource, whether it already exists or is
loaded. In case the loader returns an invalid pointer, the handle is invalid as
well and therefore it can be easily used with an `if` statement:
```cpp
if(entt::resource_handle handle = cache.load<my_loader>("another/identifier"_hs, 42); handle) {
// ...
}
```
Before trying to load a resource, the `contains` member function can be used to
know if a cache already contains a specific resource:
```cpp
auto exists = cache.contains("my/identifier"_hs);
```
There exists also a member function to use to force a reload of an already
existing resource if needed:
```cpp
auto handle = cache.reload<my_loader>("another/identifier"_hs, 42);
```
As above, the function returns a handle to the resource that is invalid in case
of errors. The `reload` member function is a kind of alias of the following
snippet:
```cpp
cache.discard(identifier);
cache.load<my_loader>(identifier, 42);
```
Where the `discard` member function is used to get rid of a resource if loaded.
In case the cache doesn't contain a resource for the given identifier, `discard`
does nothing and returns immediately.
So far, so good. Resources are finally loaded and stored within the cache.<br/>
They are returned to users in the form of handles. To get one of them later on:
```cpp
auto handle = cache.handle("my/identifier"_hs);
```
The idea behind a handle is the same of the flyweight pattern. In other terms,
resources aren't copied around. Instead, instances are shared between handles.
Users of a resource own a handle that guarantees that a resource isn't destroyed
until all the handles are destroyed, even if the resource itself is removed from
the cache.<br/>
Handles are tiny objects both movable and copyable. They return the contained
resource as a (possibly const) reference on request:
* By means of the `get` member function:
```cpp
auto &resource = handle.get();
```
* Using the proper cast operator:
```cpp
auto &resource = handle;
```
* Through the dereference operator:
```cpp
auto &resource = *handle;
```
The resource can also be accessed directly using the arrow operator if required:
```cpp
auto value = handle->value;
```
To test if a handle is still valid, the cast operator to `bool` allows users to
use it in a guard:
```cpp
if(handle) {
// ...
}
```
Finally, in case there is the need to load a resource and thus to get a handle
without storing the resource itself in the cache, users can rely on the `temp`
member function template.<br/>
The declaration is similar to that of `load`, a (possibly invalid) handle for
the resource is returned also in this case:
```cpp
if(auto handle = cache.temp<my_loader>(42); handle) {
// ...
}
```
Do not forget to test the handle for validity. Otherwise, getting a reference to
the resource it points may result in undefined behavior.

581
docs/md/signal.md Normal file
View File

@@ -0,0 +1,581 @@
# Crash Course: events, signals and everything in between
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Introduction](#introduction)
* [Delegate](#delegate)
* [Runtime arguments](#runtime-arguments)
* [Lambda support](#lambda-support)
* [Signals](#signals)
* [Event dispatcher](#event-dispatcher)
* [Event emitter](#event-emitter)
<!--
@endcond TURN_OFF_DOXYGEN
-->
# Introduction
Signals are usually a core part of games and software architectures in
general.<br/>
Roughly speaking, they help to decouple the various parts of a system while
allowing them to communicate with each other somehow.
The so called _modern C++_ comes with a tool that can be useful in these terms,
the `std::function`. As an example, it can be used to create delegates.<br/>
However, there is no guarantee that an `std::function` does not perform
allocations under the hood and this could be problematic sometimes. Furthermore,
it solves a problem but may not adapt well to other requirements that may arise
from time to time.
In case that the flexibility and power of an `std::function` isn't required or
if the price to pay for them is too high,` EnTT` offers a complete set of
lightweight classes to solve the same and many other problems.
# Delegate
A delegate can be used as a general purpose invoker with no memory overhead for
free functions and members provided along with an instance on which to invoke
them.<br/>
It doesn't claim to be a drop-in replacement for an `std::function`, so don't
expect to use it whenever an `std::function` fits well. That said, it's most
likely even a better fit than an `std::function` in a lot of cases, so expect to
use it quite a lot anyway.
The interface is trivial. It offers a default constructor to create empty
delegates:
```cpp
entt::delegate<int(int)> delegate{};
```
All what is needed to create an instance is to specify the type of the function
the delegate will _contain_, that is the signature of the free function or the
member one wants to assign to it.
Attempting to use an empty delegate by invoking its function call operator
results in undefined behavior or most likely a crash. Before to use a delegate,
it must be initialized.<br/>
There exists a bunch of overloads of the `connect` member function to do that.
As an example of use:
```cpp
int f(int i) { return i; }
struct my_struct {
int f(const int &i) const { return i; }
};
// bind a free function to the delegate
delegate.connect<&f>();
// bind a member function to the delegate
my_struct instance;
delegate.connect<&my_struct::f>(instance);
```
The delegate class accepts also data members, if needed. In this case, the
function type of the delegate is such that the parameter list is empty and the
value of the data member is at least convertible to the return type.
Free functions having type equivalent to `void(T &, args...)` are accepted as
well. The first argument `T &` is considered a payload and the function will
receive it back every time it's invoked. In other terms, this works just fine
with the above definition:
```cpp
void g(const char &c, int i) { /* ... */ }
const char c = 'c';
delegate.connect<&g>(c);
delegate(42);
```
The function `g` will be invoked with a reference to `c` and `42`. However, the
function type of the delegate is still `void(int)`. This is also the signature
of its function call operator.
Another interesting aspect of the delegate class is that it accepts also
functions with a list of parameters that is shorter than that of the function
type used to specialize the delegate itself.<br/>
The following code is therefore perfectly valid:
```cpp
void g() { /* ... */ }
delegate.connect<&g>();
delegate(42);
```
Where the function type of the delegate is `void(int)` as above. It goes without
saying that the extra arguments are silently discarded internally.<br/>
This is a nice-to-have feature in a lot of cases, as an example when the
`delegate` class is used as a building block of a signal-slot system.
To create and initialize a delegate at once, there are a few specialized
constructors. Because of the rules of the language, the listener is provided by
means of the `entt::connect_arg` variable template:
```cpp
entt::delegate<int(int)> func{entt::connect_arg<&f>};
```
Aside `connect`, a `disconnect` counterpart isn't provided. Instead, there
exists a `reset` member function to use to clear a delegate.<br/>
To know if a delegate is empty, it can be used explicitly in every conditional
statement:
```cpp
if(delegate) {
// ...
}
```
Finally, to invoke a delegate, the function call operator is the way to go as
already shown in the examples above:
```cpp
auto ret = delegate(42);
```
In all cases, the listeners don't have to strictly follow the signature of the
delegate. As long as a listener can be invoked with the given arguments to yield
a result that is convertible to the given result type, everything works just
fine.
As a side note, members of classes may or may not be associated with instances.
If they are not, the first argument of the function type must be that of the
class on which the members operate and an instance of this class must obviously
be passed when invoking the delegate:
```cpp
entt::delegate<void(my_struct &, int)> delegate;
delegate.connect<&my_struct::f>();
my_struct instance;
delegate(instance, 42);
```
In this case, it's not possible to deduce the function type since the first
argument doesn't necessarily have to be a reference (for example, it can be a
pointer, as well as a const reference).<br/>
Therefore, the function type must be declared explicitly for unbound members.
## Runtime arguments
The `delegate` class is meant to be used primarily with template arguments.
However, as a consequence of its design, it can also offer minimal support for
runtime arguments.<br/>
When used in this modality, some feature aren't supported though. In particular:
* Curried functions aren't accepted.
* Functions with an argument list that differs from that of the delegate aren't
supported.
* Return type and types of arguments **must** coincide with those of the
delegate and _being at least convertible_ isn't enough anymore.
Moreover, for a given function type `Ret(Args...)`, the signature of the
functions connected at runtime must necessarily be `Ret(const void *, Args...)`.
Runtime arguments can be passed both to the constructor of a delegate and to the
`connect` member function. An optional parameter is also accepted in both cases.
This argument is used to pass arbitrary user data back and forth as a
`const void *` upon invocation.<br/>
To connect a function to a delegate _in the hard way_:
```cpp
int func(const void *ptr, int i) { return *static_cast<const int *>(ptr) * i; }
const int value = 42;
// use the constructor ...
entt::delegate delegate{&func, &value};
// ... or the connect member function
delegate.connect(&func, &value);
```
The type of the delegate is deduced from the function if possible. In this case,
since the first argument is an implementation detail, the deduced function type
is `int(int)`.<br/>
Invoking a delegate built in this way follows the same rules as previously
explained.
## Lambda support
In general, the `delegate` class doesn't fully support lambda functions in all
their nuances. The reason is pretty simple: a `delegate` isn't a drop-in
replacement for an `std::function`. Instead, it tries to overcome the problems
with the latter.<br/>
That being said, non-capturing lambda functions are supported, even though some
feature aren't available in this case.
This is a logical consequence of the support for connecting functions at
runtime. Therefore, lambda functions undergo the same rules and
limitations.<br/>
In fact, since non-capturing lambda functions decay to pointers to functions,
they can be used with a `delegate` as if they were _normal functions_ with
optional payload:
```cpp
my_struct instance;
// use the constructor ...
entt::delegate delegate{+[](const void *ptr, int value) {
return static_cast<const my_struct *>(ptr)->f(value);
}, &instance};
// ... or the connect member function
delegate.connect([](const void *ptr, int value) {
return static_cast<const my_struct *>(ptr)->f(value);
}, &instance);
```
As above, the first parameter (`const void *`) isn't part of the function type
of the delegate and is used to dispatch arbitrary user data back and forth. In
other terms, the function type of the delegate above is `int(int)`.
# Signals
Signal handlers work with references to classes, function pointers and pointers
to members. Listeners can be any kind of objects and users are in charge of
connecting and disconnecting them from a signal to avoid crashes due to
different lifetimes. On the other side, performance shouldn't be affected that
much by the presence of such a signal handler.<br/>
Signals make use of delegates internally and therefore they undergo the same
rules and offer similar functionalities. It may be a good idea to consult the
documentation of the `delegate` class for further information.
A signal handler can be used as a private data member without exposing any
_publish_ functionality to the clients of a class. The basic idea is to impose a
clear separation between the signal itself and the `sink` class, that is a tool
to be used to connect and disconnect listeners on the fly.
The API of a signal handler is straightforward. If a collector is supplied to
the signal when something is published, all the values returned by the listeners
can be literally _collected_ and used later by the caller. Otherwise, the class
works just like a plain signal that emits events from time to time.<br/>
To create instances of signal handlers it is sufficient to provide the type of
function to which they refer:
```cpp
entt::sigh<void(int, char)> signal;
```
Signals offer all the basic functionalities required to know how many listeners
they contain (`size`) or if they contain at least a listener (`empty`), as well
as a function to use to swap handlers (`swap`).
Besides them, there are member functions to use both to connect and disconnect
listeners in all their forms by means of a sink:
```cpp
void foo(int, char) { /* ... */ }
struct listener {
void bar(const int &, char) { /* ... */ }
};
// ...
entt::sink sink{signal};
listener instance;
sink.connect<&foo>();
sink.connect<&listener::bar>(instance);
// ...
// disconnects a free function
sink.disconnect<&foo>();
// disconnect a member function of an instance
sink.disconnect<&listener::bar>(instance);
// disconnect all member functions of an instance, if any
sink.disconnect(instance);
// discards all listeners at once
sink.disconnect();
```
As shown above, the listeners don't have to strictly follow the signature of the
signal. As long as a listener can be invoked with the given arguments to yield a
result that is convertible to the given return type, everything works just
fine.<br/>
It's also possible to connect a listener before other listeners already
contained by the signal. The `before` function returns a `sink` object correctly
initialized for the purpose that can be used to connect one or more listeners in
order and in the desired position:
```cpp
sink.before<&foo>().connect<&listener::bar>(instance);
```
In all cases, the `connect` member function returns by default a `connection`
object to be used as an alternative to break a connection by means of its
`release` member function. A `scoped_connection` can also be created from a
connection. In this case, the link is broken automatically as soon as the object
goes out of scope.
Once listeners are attached (or even if there are no listeners at all), events
and data in general can be published through a signal by means of the `publish`
member function:
```cpp
signal.publish(42, 'c');
```
To collect data, the `collect` member function should be used instead. Below is
a minimal example to show how to use it:
```cpp
int f() { return 0; }
int g() { return 1; }
// ...
entt::sigh<int()> signal;
entt::sink sink{signal};
sink.connect<&f>();
sink.connect<&g>();
std::vector<int> vec{};
signal.collect([&vec](int value) { vec.push_back(value); });
assert(vec[0] == 0);
assert(vec[1] == 1);
```
A collector must expose a function operator that accepts as an argument a type
to which the return type of the listeners can be converted. Moreover, it can
optionally return a boolean value that is true to stop collecting data, false
otherwise. This way one can avoid calling all the listeners in case it isn't
necessary.<br/>
Functors can also be used in place of a lambda. Since the collector is copied
when invoking the `collect` member function, `std::ref` is the way to go in this
case:
```cpp
struct my_collector {
std::vector<int> vec{};
bool operator()(int v) noexcept {
vec.push_back(v);
return true;
}
};
// ...
my_collector collector;
signal.collect(std::ref(collector));
```
# Event dispatcher
The event dispatcher class is designed so as to be used in a loop. It allows
users both to trigger immediate events or to queue events to be published all
together once per tick.<br/>
This class shares part of its API with the one of the signal handler, but it
doesn't require that all the types of events are specified when declared:
```cpp
// define a general purpose dispatcher
entt::dispatcher dispatcher{};
```
In order to register an instance of a class to a dispatcher, its type must
expose one or more member functions the arguments of which are such that `E &`
can be converted to them for each type of event `E`, no matter what the return
value is.<br/>
The name of the member function aimed to receive the event must be provided to
the `connect` member function of the sink in charge for the specific event:
```cpp
struct an_event { int value; };
struct another_event {};
struct listener {
void receive(const an_event &) { /* ... */ }
void method(const another_event &) { /* ... */ }
};
// ...
listener listener;
dispatcher.sink<an_event>().connect<&listener::receive>(listener);
dispatcher.sink<another_event>().connect<&listener::method>(listener);
```
The `disconnect` member function follows the same pattern and can be used to
remove one listener at a time or all of them at once:
```cpp
dispatcher.sink<an_event>().disconnect<&listener::receive>(listener);
dispatcher.sink<another_event>().disconnect(listener);
```
The `trigger` member function serves the purpose of sending an immediate event
to all the listeners registered so far. It offers a convenient approach that
relieves users from having to create the event itself. Instead, it's enough to
specify the type of event and provide all the parameters required to construct
it.<br/>
As an example:
```cpp
dispatcher.trigger<an_event>(42);
dispatcher.trigger<another_event>();
```
Listeners are invoked immediately, order of execution isn't guaranteed. This
method can be used to push around urgent messages like an _is terminating_
notification on a mobile app.
On the other hand, the `enqueue` member function queues messages together and
allows to maintain control over the moment they are sent to listeners. The
signature of this method is more or less the same of `trigger`:
```cpp
dispatcher.enqueue<an_event>(42);
dispatcher.enqueue<another_event>();
```
Events are stored aside until the `update` member function is invoked, then all
the messages that are still pending are sent to the listeners at once:
```cpp
// emits all the events of the given type at once
dispatcher.update<an_event>();
// emits all the events queued so far at once
dispatcher.update();
```
This way users can embed the dispatcher in a loop and literally dispatch events
once per tick to their systems.
# Event emitter
A general purpose event emitter thought mainly for those cases where it comes to
working with asynchronous stuff.<br/>
Originally designed to fit the requirements of
[`uvw`](https://github.com/skypjack/uvw) (a wrapper for `libuv` written in
modern C++), it was adapted later to be included in this library.
To create a custom emitter type, derived classes must inherit directly from the
base class as:
```cpp
struct my_emitter: emitter<my_emitter> {
// ...
}
```
The full list of accepted types of events isn't required. Handlers are created
internally on the fly and thus each type of event is accepted by default.
Whenever an event is published, an emitter provides the listeners with a
reference to itself along with a reference to the event. Therefore listeners
have an handy way to work with it without incurring in the need of capturing a
reference to the emitter itself.<br/>
In addition, an opaque object is returned each time a connection is established
between an emitter and a listener, allowing the caller to disconnect them at a
later time.<br/>
The opaque object used to handle connections is both movable and copyable. On
the other side, an event emitter is movable but not copyable by default.
To create new instances of an emitter, no arguments are required:
```cpp
my_emitter emitter{};
```
Listeners must be movable and callable objects (free functions, lambdas,
functors, `std::function`s, whatever) whose function type is compatible with:
```cpp
void(Event &, my_emitter &)
```
Where `Event` is the type of event they want to listen.<br/>
There are two ways to attach a listener to an event emitter that differ
slightly from each other:
* To register a long-lived listener, use the `on` member function. It is meant
to register a listener designed to be invoked more than once for the given
event type.<br/>
As an example:
```cpp
auto conn = emitter.on<my_event>([](const my_event &event, my_emitter &emitter) {
// ...
});
```
The connection object can be freely discarded. Otherwise, it can be used later
to disconnect the listener if required.
* To register a short-lived listener, use the `once` member function. It is
meant to register a listener designed to be invoked only once for the given
event type. The listener is automatically disconnected after the first
invocation.<br/>
As an example:
```cpp
auto conn = emitter.once<my_event>([](const my_event &event, my_emitter &emitter) {
// ...
});
```
The connection object can be freely discarded. Otherwise, it can be used later
to disconnect the listener if required.
In both cases, the connection object can be used with the `erase` member
function:
```cpp
emitter.erase(conn);
```
There are also two member functions to use either to disconnect all the
listeners for a given type of event or to clear the emitter:
```cpp
// removes all the listener for the specific event
emitter.clear<my_event>();
// removes all the listeners registered so far
emitter.clear();
```
To send an event to all the listeners that are interested in it, the `publish`
member function offers a convenient approach that relieves users from having to
create the event:
```cpp
struct my_event { int i; };
// ...
emitter.publish<my_event>(42);
```
Finally, the `empty` member function tests if there exists at least either a
listener registered with the event emitter or to a given type of event:
```cpp
bool empty;
// checks if there is any listener registered for the specific event
empty = emitter.empty<my_event>();
// checks it there are listeners registered with the event emitter
empty = emitter.empty();
```
In general, the event emitter is a handy tool when the derived classes _wrap_
asynchronous operations, because it introduces a _nice-to-have_ model based on
events and listeners that kindly hides the complexity behind the scenes. However
it is not limited to such uses.

107
docs/md/unreal.md Normal file
View File

@@ -0,0 +1,107 @@
# EnTT and Unreal Engine
<!--
@cond TURN_OFF_DOXYGEN
-->
# Table of Contents
* [Enable Cpp17](#enable-cpp17)
* [EnTT as a third party module](#entt-as-a-third-party-module)
* [Include EnTT](#include-entt)
<!--
@endcond TURN_OFF_DOXYGEN
-->
## Enable Cpp17
As of writing (Unreal Engine v4.25), the default C++ standard of Unreal Engine
is C++14.<br/>
On the other hand, note that `EnTT` requires C++17 to compile. To enable it, in
the main module of the project there should be a `<Game Name>.Build.cs` file,
the constructor of which must contain the following lines:
```cs
PCHUsage = PCHUsageMode.NoSharedPCHs;
PrivatePCHHeaderFile = "<PCH filename>.h";
CppStandard = CppStandardVersion.Cpp17;
```
Replace `<PCH filename>.h` with the name of the already existing PCH header
file, if any.<br/>
In case the project doesn't already contain a file of this type, it's possible
to create one with the following content:
```cpp
#pragma once
#include "CoreMinimal.h"
```
Remember to remove any old `PCHUsage = <...>` line that was previously there. At
this point, C++17 support should be in place.<br/>
Try to compile the project to ensure it works as expected before following
further steps.
Note that updating a *project* to C++17 doesn't necessarily mean that the IDE in
use will also start to recognize its syntax.<br/>
If the plan is to use C++17 in the project too, check the specific instructions
for the IDE in use.
## EnTT as a third party module
Once this point is reached, the `Source` directory should look like this:
```
Source
| MyGame.Target.cs
| MyGameEditor.Target.cs
|
+---MyGame
| | MyGame.Build.cs
| | MyGame.h (PCH Header file)
|
\---ThirdParty
\---EnTT
| EnTT.Build.cs
|
\---entt (GitHub repository content inside)
```
To make this happen, create the folder `ThirdParty` under `Source` if it doesn't
exist already. Then, add an `EnTT` folder under `ThirdParty`.<br/>
Within the latter, create a new file `EnTT.Build.cs` with the following content:
```cs
using System.IO;
using UnrealBuildTool;
public class EnTT: ModuleRules {
public EnTT(ReadOnlyTargetRules Target) : base(Target) {
Type = ModuleType.External;
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "entt", "src", "entt"));
}
}
```
The last line indicates that the actual files will be found in the directory
`EnTT/entt/src/entt`.<br/>
Download the repository for `EnTT` and place it next to `EnTT.Build.cs` or
update the path above accordingly.
Finally, open the `<Game Name>.Build.cs` file and add `EnTT` as a dependency at
the end of the list:
```cs
PublicDependencyModuleNames.AddRange(new[] {
"Core", "CoreUObject", "Engine", "InputCore", [...], "EnTT"
});
```
Note that some IDEs might require a restart to start recognizing the new module
for code-highlighting features and such.
## Include EnTT
In any source file of the project, add `#include "entt.hpp"` or any other path
to the file from `EnTT` to use it.<br/>
Try to create a registry as `entt::registry registry;` to make sure everything
compiles fine.

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
</AutoVisualizer>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="entt::dense_hash_map&lt;*&gt;">
<Intrinsic Name="size" Expression="packed.first_base::value.size()"/>
<Intrinsic Name="bucket_count" Expression="sparse.first_base::value.size()"/>
<DisplayString>{{ size={ size() } }}</DisplayString>
<Expand>
<Item Name="[capacity]" ExcludeView="simple">packed.first_base::value.capacity()</Item>
<Item Name="[bucket_count]" ExcludeView="simple">bucket_count()</Item>
<Item Name="[load_factor]" ExcludeView="simple">(float)size() / (float)bucket_count()</Item>
<Item Name="[max_load_factor]" ExcludeView="simple">threshold</Item>
<IndexListItems>
<Size>size()</Size>
<ValueNode>packed.first_base::value[$i].element</ValueNode>
</IndexListItems>
</Expand>
</Type>
<Type Name="entt::dense_hash_set&lt;*&gt;">
<Intrinsic Name="size" Expression="packed.first_base::value.size()"/>
<Intrinsic Name="bucket_count" Expression="sparse.first_base::value.size()"/>
<DisplayString>{{ size={ size() } }}</DisplayString>
<Expand>
<Item Name="[capacity]" ExcludeView="simple">packed.first_base::value.capacity()</Item>
<Item Name="[bucket_count]" ExcludeView="simple">bucket_count()</Item>
<Item Name="[load_factor]" ExcludeView="simple">(float)size() / (float)bucket_count()</Item>
<Item Name="[max_load_factor]" ExcludeView="simple">threshold</Item>
<IndexListItems>
<Size>size()</Size>
<ValueNode>packed.first_base::value[$i].element</ValueNode>
</IndexListItems>
</Expand>
</Type>
</AutoVisualizer>

31
natvis/entt/core.natvis Normal file
View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="entt::basic_any&lt;*&gt;">
<DisplayString>{{ type={ info->alias,na }, policy={ mode,en } }}</DisplayString>
</Type>
<Type Name="entt::compressed_pair&lt;*&gt;">
<Intrinsic Name="first" Optional="true" Expression="((first_base*)this)->value"/>
<Intrinsic Name="first" Optional="true" Expression="*(first_base::base_type*)this"/>
<Intrinsic Name="second" Optional="true" Expression="((second_base*)this)->value"/>
<Intrinsic Name="second" Optional="true" Expression="*(second_base::base_type*)this"/>
<DisplayString >({ first() }, { second() })</DisplayString>
<Expand>
<Item Name="[first]">first()</Item>
<Item Name="[second]">second()</Item>
</Expand>
</Type>
<Type Name="entt::basic_hashed_string&lt;*&gt;">
<DisplayString Condition="str != nullptr">{{ hash={ hash } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<Item Name="[data]">str,na</Item>
</Expand>
</Type>
<Type Name="entt::type_info">
<DisplayString>{{ name={ alias,na } }}</DisplayString>
<Expand>
<Item Name="[hash]">identifier</Item>
<Item Name="[index]">seq</Item>
</Expand>
</Type>
</AutoVisualizer>

119
natvis/entt/entity.natvis Normal file
View File

@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="entt::basic_registry&lt;*&gt;">
<Intrinsic Name="pools_size" Expression="pools.packed.first_base::value.size()"/>
<Intrinsic Name="vars_size" Expression="vars.packed.first_base::value.size()"/>
<Intrinsic Name="to_entity" Expression="*((entity_traits::entity_type *)&amp;entity) &amp; entity_traits::entity_mask">
<Parameter Name="entity" Type="entity_traits::value_type &amp;"/>
</Intrinsic>
<DisplayString>{{ size={ entities.size() } }}</DisplayString>
<Expand>
<Item IncludeView="simple" Name="[entities]">entities,view(simple)nr</Item>
<Synthetic Name="[entities]" ExcludeView="simple">
<DisplayString>{ entities.size() }</DisplayString>
<Expand>
<CustomListItems>
<Variable Name="pos" InitialValue="0" />
<Variable Name="last" InitialValue="entities.size()"/>
<Loop>
<Break Condition="pos == last"/>
<If Condition="to_entity(entities[pos]) == pos">
<Item Name="[{ pos }]">entities[pos]</Item>
</If>
<Exec>++pos</Exec>
</Loop>
</CustomListItems>
</Expand>
</Synthetic>
<Synthetic Name="[destroyed]" ExcludeView="simple">
<DisplayString>{ to_entity(free_list) != entity_traits::entity_mask }</DisplayString>
<Expand>
<CustomListItems>
<Variable Name="it" InitialValue="to_entity(free_list)" />
<Loop>
<Break Condition="it == entity_traits::entity_mask"/>
<Item Name="[{ it }]">entities[it]</Item>
<Exec>it = to_entity(entities[it])</Exec>
</Loop>
</CustomListItems>
</Expand>
</Synthetic>
<Synthetic Name="[pools]">
<DisplayString>{ pools_size() }</DisplayString>
<Expand>
<IndexListItems ExcludeView="simple">
<Size>pools_size()</Size>
<ValueNode>*pools.packed.first_base::value[$i].element.second</ValueNode>
</IndexListItems>
<IndexListItems IncludeView="simple">
<Size>pools_size()</Size>
<ValueNode>*pools.packed.first_base::value[$i].element.second,view(simple)</ValueNode>
</IndexListItems>
</Expand>
</Synthetic>
<Item Name="[groups]" ExcludeView="simple">groups.size()</Item>
<Synthetic Name="[vars]">
<DisplayString>{ vars_size() }</DisplayString>
<Expand>
<IndexListItems>
<Size>vars_size()</Size>
<ValueNode>vars.packed.first_base::value[$i].element.second</ValueNode>
</IndexListItems>
</Expand>
</Synthetic>
</Expand>
</Type>
<Type Name="entt::basic_sparse_set&lt;*&gt;">
<DisplayString>{{ size={ packed.size() }, type={ info->alias,na } }}</DisplayString>
<Expand>
<Item Name="[capacity]" ExcludeView="simple">packed.capacity()</Item>
<Item Name="[policy]">mode,en</Item>
<ExpandedItem IncludeView="simple">packed,view(simple)</ExpandedItem>
<CustomListItems ExcludeView="simple">
<Variable Name="pos" InitialValue="0" />
<Variable Name="last" InitialValue="packed.size()"/>
<Loop>
<Break Condition="pos == last"/>
<If Condition="*((entity_traits::entity_type *)&amp;packed[pos]) &lt; ~entity_traits::entity_mask">
<Item Name="[{ pos }]">packed[pos]</Item>
</If>
<Exec>++pos</Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
<Type Name="entt::basic_storage&lt;*&gt;">
<DisplayString>{{ size={ base_type::packed.size() }, type={ base_type::info->alias,na } }}</DisplayString>
<Expand>
<Item Name="[capacity]" Optional="true" ExcludeView="simple">packed.first_base::value.capacity() * comp_traits::page_size</Item>
<Item Name="[page size]" Optional="true" ExcludeView="simple">comp_traits::page_size</Item>
<Item Name="[base]" ExcludeView="simple">(base_type*)this,nand</Item>
<Item Name="[base]" IncludeView="simple">(base_type*)this,view(simple)nand</Item>
<!-- having SFINAE-like techniques in natvis is priceless :) -->
<CustomListItems Condition="packed.first_base::value.size() != 0" Optional="true">
<Variable Name="pos" InitialValue="0" />
<Variable Name="last" InitialValue="base_type::packed.size()"/>
<Loop>
<Break Condition="pos == last"/>
<If Condition="*((base_type::entity_traits::entity_type *)&amp;base_type::packed[pos]) &lt; ~base_type::entity_traits::entity_mask">
<Item Name="[{ pos }]">packed.first_base::value[pos / comp_traits::page_size][pos &amp; (comp_traits::page_size - 1)]</Item>
</If>
<Exec>++pos</Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
<Type Name="entt::basic_view&lt;*&gt;">
<DisplayString>{{ size_hint={ view->packed.size() } }}</DisplayString>
<Expand>
<Item Name="[pools]">pools,na</Item>
<Item Name="[filter]">filter,na</Item>
</Expand>
</Type>
<Type Name="entt::null_t">
<DisplayString>&lt;null&gt;</DisplayString>
</Type>
<Type Name="entt::tombstone_t">
<DisplayString>&lt;tombstone&gt;</DisplayString>
</Type>
</AutoVisualizer>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
</AutoVisualizer>

197
natvis/entt/meta.natvis Normal file
View File

@@ -0,0 +1,197 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="entt::meta_any">
<DisplayString Condition="node != nullptr">{{ type={ node->info->alias,na }, policy={ storage.mode,en } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<ExpandedItem Condition="node != nullptr">*node</ExpandedItem>
</Expand>
</Type>
<Type Name="entt::meta_associative_container">
<DisplayString Condition="mapped_type_node != nullptr">{{ key_type={ key_type_node->info->alias,na }, mapped_type={ mapped_type_node->info->alias,na } }}</DisplayString>
<DisplayString Condition="key_type_node != nullptr">{{ key_type={ key_type_node->info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
</Type>
<Type Name="entt::internal::meta_base_node">
<DisplayString Condition="type != nullptr">{{ type={ type->info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
</Type>
<Type Name="entt::internal::meta_conv_node">
<DisplayString Condition="type != nullptr">{{ type={ type->info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
</Type>
<Type Name="entt::internal::meta_ctor_node">
<DisplayString Condition="arg != nullptr">{{ arity={ arity } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
</Type>
<Type Name="entt::internal::meta_data_node">
<Intrinsic Name="has_property" Expression="!!(traits &amp; property)">
<Parameter Name="property" Type="int"/>
</Intrinsic>
<DisplayString Condition="type != nullptr">{{ type={ type->info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<Item Name="[id]">id</Item>
<Item Name="[arity]">arity</Item>
<Item Name="[is_const]">has_property(entt::internal::meta_traits::is_const)</Item>
<Item Name="[is_static]">has_property(entt::internal::meta_traits::is_static)</Item>
<Synthetic Name="[prop]" Condition="prop != nullptr">
<Expand>
<LinkedListItems>
<HeadPointer>prop</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>*this</ValueNode>
</LinkedListItems>
</Expand>
</Synthetic>
</Expand>
</Type>
<Type Name="entt::meta_data">
<DisplayString Condition="node != nullptr">{ *node }</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<ExpandedItem Condition="node != nullptr">node</ExpandedItem>
</Expand>
</Type>
<Type Name="entt::internal::meta_func_node" >
<Intrinsic Name="has_property" Expression="!!(traits &amp; property)">
<Parameter Name="property" Type="int"/>
</Intrinsic>
<DisplayString Condition="ret != nullptr">{{ arity={ arity }, ret={ ret->info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<Item Name="[id]">id</Item>
<Item Name="[is_const]">has_property(entt::internal::meta_traits::is_const)</Item>
<Item Name="[is_static]">has_property(entt::internal::meta_traits::is_static)</Item>
<Synthetic Name="[prop]" Condition="prop != nullptr">
<Expand>
<LinkedListItems>
<HeadPointer>prop</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>*this</ValueNode>
</LinkedListItems>
</Expand>
</Synthetic>
</Expand>
</Type>
<Type Name="entt::meta_func">
<DisplayString Condition="node != nullptr">{ *node }</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<ExpandedItem Condition="node != nullptr">node</ExpandedItem>
</Expand>
</Type>
<Type Name="entt::meta_handle">
<DisplayString>{ any }</DisplayString>
</Type>
<Type Name="entt::internal::meta_prop_node">
<DisplayString Condition="value.node != nullptr">{{ key_type={ id.node->info->alias,na }, mapped_type={ value.node->info->alias,na } }}</DisplayString>
<DisplayString Condition="id.node != nullptr">{{ key_type={ id.node->info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<Item Name="[key]">id</Item>
<Item Name="[value]">value</Item>
</Expand>
</Type>
<Type Name="entt::meta_prop">
<DisplayString Condition="node != nullptr">{ *node }</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<ExpandedItem Condition="node != nullptr">node</ExpandedItem>
</Expand>
</Type>
<Type Name="entt::meta_sequence_container">
<DisplayString Condition="value_type_node != nullptr">{{ value_type={ value_type_node->info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
</Type>
<Type Name="entt::internal::meta_template_node">
<DisplayString Condition="type != nullptr">{{ type={ type->info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<Item Name="[arity]">arity</Item>
</Expand>
</Type>
<Type Name="entt::internal::meta_type_node">
<Intrinsic Name="has_property" Expression="!!(traits &amp; property)">
<Parameter Name="property" Type="int"/>
</Intrinsic>
<DisplayString Condition="info != nullptr">{{ type={ info->alias,na } }}</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<Item Name="[id]">id</Item>
<Item Name="[sizeof]">size_of</Item>
<Item Name="[is_arithmetic]">has_property(entt::internal::meta_traits::is_arithmetic)</Item>
<Item Name="[is_array]">has_property(entt::internal::meta_traits::is_array)</Item>
<Item Name="[is_enum]">has_property(entt::internal::meta_traits::is_enum)</Item>
<Item Name="[is_class]">has_property(entt::internal::meta_traits::is_class)</Item>
<Item Name="[is_pointer]">has_property(entt::internal::meta_traits::is_pointer)</Item>
<Item Name="[is_meta_pointer_like]">has_property(entt::internal::meta_traits::is_meta_pointer_like)</Item>
<Item Name="[is_meta_sequence_container]">has_property(entt::internal::meta_traits::is_meta_sequence_container)</Item>
<Item Name="[is_meta_associative_container]">has_property(entt::internal::meta_traits::is_meta_associative_container)</Item>
<Item Name="[default_constructor]">default_constructor != nullptr</Item>
<Item Name="[conversion_helper]">conversion_helper != nullptr</Item>
<Item Name="[template_info]" Condition="templ != nullptr">*templ</Item>
<Synthetic Name="[ctor]" Condition="ctor != nullptr">
<Expand>
<LinkedListItems>
<HeadPointer>ctor</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>*this</ValueNode>
</LinkedListItems>
</Expand>
</Synthetic>
<Synthetic Name="[base]" Condition="base != nullptr">
<Expand>
<LinkedListItems>
<HeadPointer>base</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>*this</ValueNode>
</LinkedListItems>
</Expand>
</Synthetic>
<Synthetic Name="[conv]" Condition="conv != nullptr">
<Expand>
<LinkedListItems>
<HeadPointer>conv</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>*this</ValueNode>
</LinkedListItems>
</Expand>
</Synthetic>
<Synthetic Name="[data]" Condition="data != nullptr">
<Expand>
<LinkedListItems>
<HeadPointer>data</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>*this</ValueNode>
</LinkedListItems>
</Expand>
</Synthetic>
<Synthetic Name="[func]" Condition="func != nullptr">
<Expand>
<LinkedListItems>
<HeadPointer>func</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>*this</ValueNode>
</LinkedListItems>
</Expand>
</Synthetic>
<Synthetic Name="[prop]" Condition="prop != nullptr">
<Expand>
<LinkedListItems>
<HeadPointer>prop</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>*this</ValueNode>
</LinkedListItems>
</Expand>
</Synthetic>
</Expand>
</Type>
<Type Name="entt::meta_type">
<DisplayString Condition="node != nullptr">{ *node }</DisplayString>
<DisplayString>{{}}</DisplayString>
<Expand>
<ExpandedItem Condition="node != nullptr">node</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
</AutoVisualizer>

6
natvis/entt/poly.natvis Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="entt::basic_poly&lt;*&gt;">
<DisplayString>{ storage }</DisplayString>
</Type>
</AutoVisualizer>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
</AutoVisualizer>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
</AutoVisualizer>

52
natvis/entt/signal.natvis Normal file
View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="entt::connection">
<DisplayString>{{ bound={ signal != nullptr } }}</DisplayString>
</Type>
<Type Name="entt::delegate&lt;*&gt;">
<DisplayString>{{ type={ "$T1" } }}</DisplayString>
<Expand>
<Item Name="[empty]">fn == nullptr</Item>
<Item Name="[data]">data</Item>
</Expand>
</Type>
<Type Name="entt::dispatcher">
<DisplayString>{{ size={ pools.size() } }}</DisplayString>
<Expand>
<Synthetic Name="[pools]">
<DisplayString>{ pools.size() }</DisplayString>
<Expand>
<IndexListItems>
<Size>pools.size()</Size>
<ValueNode>*pools.packed.first_base::value[$i].element.second</ValueNode>
</IndexListItems>
</Expand>
</Synthetic>
</Expand>
</Type>
<Type Name="entt::dispatcher::pool_handler&lt;*&gt;">
<DisplayString>{{ size={ events.size() }, event={ "$T1" } }}</DisplayString>
<Expand>
<Item Name="[signal]">signal</Item>
</Expand>
</Type>
<Type Name="entt::scoped_connection">
<DisplayString>{ conn }</DisplayString>
</Type>
<Type Name="entt::sigh&lt;*&gt;">
<DisplayString>{{ size={ calls.size() }, type={ "$T1" } }}</DisplayString>
<Expand>
<IndexListItems>
<Size>calls.size()</Size>
<ValueNode>calls[$i]</ValueNode>
</IndexListItems>
</Expand>
</Type>
<Type Name="entt::sink&lt;*&gt;">
<DisplayString>{{ type={ "$T1" } }}</DisplayString>
<Expand>
<Item Name="[signal]">signal,na</Item>
<Item Name="[offset]">offset</Item>
</Expand>
</Type>
</AutoVisualizer>

299
scripts/amalgamate.py Normal file
View File

@@ -0,0 +1,299 @@
#!/usr/bin/env python
# coding=utf-8
# amalgamate.py - Amalgamate C source and header files.
# Copyright (c) 2012, Erik Edlund <erik.edlund@32767.se>
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of Erik Edlund, nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import datetime
import json
import os
import re
class Amalgamation(object):
# Prepends self.source_path to file_path if needed.
def actual_path(self, file_path):
if not os.path.isabs(file_path):
file_path = os.path.join(self.source_path, file_path)
return file_path
# Search included file_path in self.include_paths and
# in source_dir if specified.
def find_included_file(self, file_path, source_dir):
search_dirs = self.include_paths[:]
if source_dir:
search_dirs.insert(0, source_dir)
for search_dir in search_dirs:
search_path = os.path.join(search_dir, file_path)
if os.path.isfile(self.actual_path(search_path)):
return search_path
return None
def __init__(self, args):
with open(args.config, 'r') as f:
config = json.loads(f.read())
for key in config:
setattr(self, key, config[key])
self.verbose = args.verbose == "yes"
self.prologue = args.prologue
self.source_path = args.source_path
self.included_files = []
# Generate the amalgamation and write it to the target file.
def generate(self):
amalgamation = ""
if self.prologue:
with open(self.prologue, 'r') as f:
amalgamation += datetime.datetime.now().strftime(f.read())
if self.verbose:
print("Config:")
print(" target = {0}".format(self.target))
print(" working_dir = {0}".format(os.getcwd()))
print(" include_paths = {0}".format(self.include_paths))
print("Creating amalgamation:")
for file_path in self.sources:
# Do not check the include paths while processing the source
# list, all given source paths must be correct.
# actual_path = self.actual_path(file_path)
print(" - processing \"{0}\"".format(file_path))
t = TranslationUnit(file_path, self, True)
amalgamation += t.content
with open(self.target, 'w') as f:
f.write(amalgamation)
print("...done!\n")
if self.verbose:
print("Files processed: {0}".format(self.sources))
print("Files included: {0}".format(self.included_files))
print("")
def _is_within(match, matches):
for m in matches:
if match.start() > m.start() and \
match.end() < m.end():
return True
return False
class TranslationUnit(object):
# // C++ comment.
cpp_comment_pattern = re.compile(r"//.*?\n")
# /* C comment. */
c_comment_pattern = re.compile(r"/\*.*?\*/", re.S)
# "complex \"stri\\\ng\" value".
string_pattern = re.compile("[^']" r'".*?(?<=[^\\])"', re.S)
# Handle simple include directives. Support for advanced
# directives where macros and defines needs to expanded is
# not a concern right now.
include_pattern = re.compile(
r'#\s*include\s+(<|")(?P<path>.*?)("|>)', re.S)
# #pragma once
pragma_once_pattern = re.compile(r'#\s*pragma\s+once', re.S)
# Search for pattern in self.content, add the match to
# contexts if found and update the index accordingly.
def _search_content(self, index, pattern, contexts):
match = pattern.search(self.content, index)
if match:
contexts.append(match)
return match.end()
return index + 2
# Return all the skippable contexts, i.e., comments and strings
def _find_skippable_contexts(self):
# Find contexts in the content in which a found include
# directive should not be processed.
skippable_contexts = []
# Walk through the content char by char, and try to grab
# skippable contexts using regular expressions when found.
i = 1
content_len = len(self.content)
while i < content_len:
j = i - 1
current = self.content[i]
previous = self.content[j]
if current == '"':
# String value.
i = self._search_content(j, self.string_pattern,
skippable_contexts)
elif current == '*' and previous == '/':
# C style comment.
i = self._search_content(j, self.c_comment_pattern,
skippable_contexts)
elif current == '/' and previous == '/':
# C++ style comment.
i = self._search_content(j, self.cpp_comment_pattern,
skippable_contexts)
else:
# Skip to the next char.
i += 1
return skippable_contexts
# Returns True if the match is within list of other matches
# Removes pragma once from content
def _process_pragma_once(self):
content_len = len(self.content)
if content_len < len("#include <x>"):
return 0
# Find contexts in the content in which a found include
# directive should not be processed.
skippable_contexts = self._find_skippable_contexts()
pragmas = []
pragma_once_match = self.pragma_once_pattern.search(self.content)
while pragma_once_match:
if not _is_within(pragma_once_match, skippable_contexts):
pragmas.append(pragma_once_match)
pragma_once_match = self.pragma_once_pattern.search(self.content,
pragma_once_match.end())
# Handle all collected pragma once directives.
prev_end = 0
tmp_content = ''
for pragma_match in pragmas:
tmp_content += self.content[prev_end:pragma_match.start()]
prev_end = pragma_match.end()
tmp_content += self.content[prev_end:]
self.content = tmp_content
# Include all trivial #include directives into self.content.
def _process_includes(self):
content_len = len(self.content)
if content_len < len("#include <x>"):
return 0
# Find contexts in the content in which a found include
# directive should not be processed.
skippable_contexts = self._find_skippable_contexts()
# Search for include directives in the content, collect those
# which should be included into the content.
includes = []
include_match = self.include_pattern.search(self.content)
while include_match:
if not _is_within(include_match, skippable_contexts):
include_path = include_match.group("path")
search_same_dir = include_match.group(1) == '"'
found_included_path = self.amalgamation.find_included_file(
include_path, self.file_dir if search_same_dir else None)
if found_included_path:
includes.append((include_match, found_included_path))
include_match = self.include_pattern.search(self.content,
include_match.end())
# Handle all collected include directives.
prev_end = 0
tmp_content = ''
for include in includes:
include_match, found_included_path = include
tmp_content += self.content[prev_end:include_match.start()]
tmp_content += "// {0}\n".format(include_match.group(0))
if found_included_path not in self.amalgamation.included_files:
t = TranslationUnit(found_included_path, self.amalgamation, False)
tmp_content += t.content
prev_end = include_match.end()
tmp_content += self.content[prev_end:]
self.content = tmp_content
return len(includes)
# Make all content processing
def _process(self):
if not self.is_root:
self._process_pragma_once()
self._process_includes()
def __init__(self, file_path, amalgamation, is_root):
self.file_path = file_path
self.file_dir = os.path.dirname(file_path)
self.amalgamation = amalgamation
self.is_root = is_root
self.amalgamation.included_files.append(self.file_path)
actual_path = self.amalgamation.actual_path(file_path)
if not os.path.isfile(actual_path):
raise IOError("File not found: \"{0}\"".format(file_path))
with open(actual_path, 'r') as f:
self.content = f.read()
self._process()
def main():
description = "Amalgamate C source and header files."
usage = " ".join([
"amalgamate.py",
"[-v]",
"-c path/to/config.json",
"-s path/to/source/dir",
"[-p path/to/prologue.(c|h)]"
])
argsparser = argparse.ArgumentParser(
description=description, usage=usage)
argsparser.add_argument("-v", "--verbose", dest="verbose",
choices=["yes", "no"], metavar="", help="be verbose")
argsparser.add_argument("-c", "--config", dest="config",
required=True, metavar="", help="path to a JSON config file")
argsparser.add_argument("-s", "--source", dest="source_path",
required=True, metavar="", help="source code path")
argsparser.add_argument("-p", "--prologue", dest="prologue",
required=False, metavar="", help="path to a C prologue file")
amalgamation = Amalgamation(argsparser.parse_args())
amalgamation.generate()
if __name__ == "__main__":
main()

8
scripts/config.json Normal file
View File

@@ -0,0 +1,8 @@
{
"project": "entt",
"target": "single_include/entt/entt.hpp",
"sources": [
"src/entt/entt.hpp"
],
"include_paths": ["src"]
}

60
scripts/update_homebrew.sh Executable file
View File

@@ -0,0 +1,60 @@
#!/bin/sh
# only argument should be the version to upgrade to
if [ $# != 1 ]
then
echo "Expected a version tag like v2.7.1"
exit 1
fi
VERSION="$1"
URL="https://github.com/skypjack/entt/archive/$VERSION.tar.gz"
FORMULA="entt.rb"
echo "Updating homebrew package to $VERSION"
echo "Cloning..."
git clone https://github.com/skypjack/homebrew-entt.git
if [ $? != 0 ]
then
exit 1
fi
cd homebrew-entt
# download the repo at the version
# exit with error messages if curl fails
echo "Curling..."
curl "$URL" --location --fail --silent --show-error --output archive.tar.gz
if [ $? != 0 ]
then
exit 1
fi
# compute sha256 hash
echo "Hashing..."
HASH="$(openssl sha256 archive.tar.gz | cut -d " " -f 2)"
# delete the archive
rm archive.tar.gz
echo "Sedding..."
# change the url in the formula file
# the slashes in the URL must be escaped
ESCAPED_URL="$(echo "$URL" | sed -e 's/[\/&]/\\&/g')"
sed -i -e '/url/s/".*"/"'$ESCAPED_URL'"/' $FORMULA
# change the hash in the formula file
sed -i -e '/sha256/s/".*"/"'$HASH'"/' $FORMULA
# delete temporary file created by sed
rm -rf "$FORMULA-e"
# update remote repo
echo "Gitting..."
git add entt.rb
git commit -m "Update to $VERSION"
git push origin master
# out of homebrew-entt dir
cd ..

61437
single_include/entt/entt.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,235 +0,0 @@
#ifndef ENTT_COMPONENT_POOL_HPP
#define ENTT_COMPONENT_POOL_HPP
#include <utility>
#include <vector>
#include <cassert>
namespace entt {
template<typename, typename, typename...>
class ComponentPool;
template<typename Entity, typename Component>
class ComponentPool<Entity, Component> {
public:
using component_type = Component;
using entity_type = Entity;
using pos_type = entity_type;
using size_type = typename std::vector<component_type>::size_type;
using iterator_type = typename std::vector<entity_type>::iterator;
using const_iterator_type = typename std::vector<entity_type>::const_iterator;
private:
inline bool valid(entity_type entity) const noexcept {
return entity < reverse.size() && reverse[entity] < direct.size() && direct[reverse[entity]] == entity;
}
public:
explicit ComponentPool(size_type dim = 4098) noexcept {
assert(!(dim < 0));
data.reserve(dim);
}
ComponentPool(ComponentPool &&) = default;
~ComponentPool() noexcept {
assert(empty());
}
ComponentPool & operator=(ComponentPool &&) = default;
bool empty() const noexcept {
return data.empty();
}
size_type capacity() const noexcept {
return data.capacity();
}
size_type size() const noexcept {
return data.size();
}
iterator_type begin() noexcept {
return direct.begin();
}
const_iterator_type cbegin() const noexcept {
return direct.cbegin();
}
iterator_type end() noexcept {
return direct.end();
}
const_iterator_type cend() const noexcept {
return direct.cend();
}
bool has(entity_type entity) const noexcept {
return valid(entity);
}
const component_type & get(entity_type entity) const noexcept {
assert(valid(entity));
return data[reverse[entity]];
}
component_type & get(entity_type entity) noexcept {
return const_cast<component_type &>(const_cast<const ComponentPool *>(this)->get(entity));
}
template<typename... Args>
component_type & construct(entity_type entity, Args... args) {
assert(!valid(entity));
if(!(entity < reverse.size())) {
reverse.resize(entity+1);
}
reverse[entity] = pos_type(direct.size());
direct.emplace_back(entity);
data.push_back({ args... });
return data.back();
}
void destroy(entity_type entity) {
assert(valid(entity));
auto last = direct.size() - 1;
reverse[direct[last]] = reverse[entity];
direct[reverse[entity]] = direct[last];
data[reverse[entity]] = std::move(data[last]);
direct.pop_back();
data.pop_back();
}
void reset() {
data.clear();
reverse.resize(0);
direct.clear();
}
private:
std::vector<component_type> data;
std::vector<pos_type> reverse;
std::vector<entity_type> direct;
};
template<typename Entity, typename Component, typename... Components>
class ComponentPool
: ComponentPool<Entity, Component>, ComponentPool<Entity, Components>...
{
template<typename Comp>
using Pool = ComponentPool<Entity, Comp>;
public:
using entity_type = typename Pool<Component>::entity_type;
using pos_type = typename Pool<Component>::pos_type;
using size_type = typename Pool<Component>::size_type;
using iterator_type = typename Pool<Component>::iterator_type;
using const_iterator_type = typename Pool<Component>::const_iterator_type;
explicit ComponentPool(size_type dim = 4098) noexcept
#ifdef _MSC_VER
: ComponentPool<Entity, Component>{dim}, ComponentPool<Entity, Components>{dim}...
#else
: Pool<Component>{dim}, Pool<Components>{dim}...
#endif
{
assert(!(dim < 0));
}
ComponentPool(const ComponentPool &) = delete;
ComponentPool(ComponentPool &&) = delete;
ComponentPool & operator=(const ComponentPool &) = delete;
ComponentPool & operator=(ComponentPool &&) = delete;
template<typename Comp>
bool empty() const noexcept {
return Pool<Comp>::empty();
}
template<typename Comp>
size_type capacity() const noexcept {
return Pool<Comp>::capacity();
}
template<typename Comp>
size_type size() const noexcept {
return Pool<Comp>::size();
}
template<typename Comp>
iterator_type begin() noexcept {
return Pool<Comp>::begin();
}
template<typename Comp>
const_iterator_type cbegin() const noexcept {
return Pool<Comp>::cbegin();
}
template<typename Comp>
iterator_type end() noexcept {
return Pool<Comp>::end();
}
template<typename Comp>
const_iterator_type cend() const noexcept {
return Pool<Comp>::cend();
}
template<typename Comp>
bool has(entity_type entity) const noexcept {
return Pool<Comp>::has(entity);
}
template<typename Comp>
const Comp & get(entity_type entity) const noexcept {
return Pool<Comp>::get(entity);
}
template<typename Comp>
Comp & get(entity_type entity) noexcept {
return const_cast<Comp &>(const_cast<const ComponentPool *>(this)->get<Comp>(entity));
}
template<typename Comp, typename... Args>
Comp & construct(entity_type entity, Args... args) {
return Pool<Comp>::construct(entity, args...);
}
template<typename Comp>
void destroy(entity_type entity) {
Pool<Comp>::destroy(entity);
}
template<typename Comp>
void reset() {
Pool<Comp>::reset();
}
void reset() {
using accumulator_type = int[];
Pool<Component>::reset();
accumulator_type accumulator = { (Pool<Components>::reset(), 0)... };
(void)accumulator;
}
};
}
#endif // ENTT_COMPONENT_POOL_HPP

69
src/entt/config/config.h Normal file
View File

@@ -0,0 +1,69 @@
#ifndef ENTT_CONFIG_CONFIG_H
#define ENTT_CONFIG_CONFIG_H
#if defined(__cpp_exceptions) && !defined(ENTT_NOEXCEPTION)
# define ENTT_NOEXCEPT noexcept
# define ENTT_THROW throw
# define ENTT_TRY try
# define ENTT_CATCH catch(...)
#else
# define ENTT_NOEXCEPT
# define ENTT_THROW
# define ENTT_TRY if(true)
# define ENTT_CATCH if(false)
#endif
#if defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606L
# include <new>
# define ENTT_LAUNDER(expr) std::launder(expr)
#else
# define ENTT_LAUNDER(expr) expr
#endif
#ifndef ENTT_USE_ATOMIC
# define ENTT_MAYBE_ATOMIC(Type) Type
#else
# include <atomic>
# define ENTT_MAYBE_ATOMIC(Type) std::atomic<Type>
#endif
#ifndef ENTT_ID_TYPE
# include <cstdint>
# define ENTT_ID_TYPE std::uint32_t
#endif
#ifndef ENTT_SPARSE_PAGE
# define ENTT_SPARSE_PAGE 4096
#endif
#ifndef ENTT_PACKED_PAGE
# define ENTT_PACKED_PAGE 1024
#endif
#ifdef ENTT_DISABLE_ASSERT
# undef ENTT_ASSERT
# define ENTT_ASSERT(...) (void(0))
#elif !defined ENTT_ASSERT
# include <cassert>
# define ENTT_ASSERT(condition, ...) assert(condition)
#endif
#ifdef ENTT_NO_ETO
# define ENTT_IGNORE_IF_EMPTY false
#else
# define ENTT_IGNORE_IF_EMPTY true
#endif
#ifndef ENTT_STANDARD_CPP
# if defined __clang__ || defined __GNUC__
# define ENTT_PRETTY_FUNCTION __PRETTY_FUNCTION__
# define ENTT_PRETTY_FUNCTION_PREFIX '='
# define ENTT_PRETTY_FUNCTION_SUFFIX ']'
# elif defined _MSC_VER
# define ENTT_PRETTY_FUNCTION __FUNCSIG__
# define ENTT_PRETTY_FUNCTION_PREFIX '<'
# define ENTT_PRETTY_FUNCTION_SUFFIX '>'
# endif
#endif
#endif

View File

@@ -0,0 +1,8 @@
#ifndef ENTT_CONFIG_VERSION_H
#define ENTT_CONFIG_VERSION_H
#define ENTT_VERSION_MAJOR 3
#define ENTT_VERSION_MINOR 9
#define ENTT_VERSION_PATCH 0
#endif

View File

@@ -0,0 +1,959 @@
#ifndef ENTT_CONTAINER_DENSE_HASH_MAP_HPP
#define ENTT_CONTAINER_DENSE_HASH_MAP_HPP
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <functional>
#include <iterator>
#include <limits>
#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "../config/config.h"
#include "../core/compressed_pair.hpp"
#include "../core/memory.hpp"
#include "../core/type_traits.hpp"
#include "fwd.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename Key, typename Type>
struct dense_hash_map_node final {
template<typename... Args>
dense_hash_map_node(const std::size_t pos, Args &&...args)
: next{pos},
element{std::forward<Args>(args)...} {}
std::size_t next;
std::pair<Key, Type> element;
};
template<typename It>
class dense_hash_map_iterator {
friend dense_hash_map_iterator<const std::remove_pointer_t<It> *>;
using iterator_traits = std::iterator_traits<decltype(std::addressof(std::declval<It>()->element))>;
public:
using value_type = typename iterator_traits::value_type;
using pointer = typename iterator_traits::pointer;
using reference = typename iterator_traits::reference;
using difference_type = typename iterator_traits::difference_type;
using iterator_category = std::random_access_iterator_tag;
dense_hash_map_iterator() ENTT_NOEXCEPT = default;
dense_hash_map_iterator(const It iter) ENTT_NOEXCEPT
: it{iter} {}
template<bool Const = std::is_const_v<std::remove_pointer_t<It>>, typename = std::enable_if_t<Const>>
dense_hash_map_iterator(const dense_hash_map_iterator<std::remove_const_t<std::remove_pointer_t<It>> *> &other)
: it{other.it} {}
dense_hash_map_iterator &operator++() ENTT_NOEXCEPT {
return ++it, *this;
}
dense_hash_map_iterator operator++(int) ENTT_NOEXCEPT {
dense_hash_map_iterator orig = *this;
return ++(*this), orig;
}
dense_hash_map_iterator &operator--() ENTT_NOEXCEPT {
return --it, *this;
}
dense_hash_map_iterator operator--(int) ENTT_NOEXCEPT {
dense_hash_map_iterator orig = *this;
return operator--(), orig;
}
dense_hash_map_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
it += value;
return *this;
}
dense_hash_map_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
dense_hash_map_iterator copy = *this;
return (copy += value);
}
dense_hash_map_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
return (*this += -value);
}
dense_hash_map_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
return (*this + -value);
}
[[nodiscard]] reference operator[](const difference_type value) const {
return it[value].element;
}
[[nodiscard]] pointer operator->() const {
return std::addressof(it->element);
}
[[nodiscard]] reference operator*() const {
return *operator->();
}
template<typename ILhs, typename IRhs>
friend auto operator-(const dense_hash_map_iterator<ILhs> &, const dense_hash_map_iterator<IRhs> &) ENTT_NOEXCEPT;
template<typename ILhs, typename IRhs>
friend bool operator==(const dense_hash_map_iterator<ILhs> &, const dense_hash_map_iterator<IRhs> &) ENTT_NOEXCEPT;
template<typename ILhs, typename IRhs>
friend bool operator<(const dense_hash_map_iterator<ILhs> &, const dense_hash_map_iterator<IRhs> &) ENTT_NOEXCEPT;
private:
It it;
};
template<typename ILhs, typename IRhs>
[[nodiscard]] auto operator-(const dense_hash_map_iterator<ILhs> &lhs, const dense_hash_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return lhs.it - rhs.it;
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator==(const dense_hash_map_iterator<ILhs> &lhs, const dense_hash_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return lhs.it == rhs.it;
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator!=(const dense_hash_map_iterator<ILhs> &lhs, const dense_hash_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator<(const dense_hash_map_iterator<ILhs> &lhs, const dense_hash_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return lhs.it < rhs.it;
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator>(const dense_hash_map_iterator<ILhs> &lhs, const dense_hash_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return rhs < lhs;
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator<=(const dense_hash_map_iterator<ILhs> &lhs, const dense_hash_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return !(lhs > rhs);
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator>=(const dense_hash_map_iterator<ILhs> &lhs, const dense_hash_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return !(lhs < rhs);
}
template<typename It>
class dense_hash_map_local_iterator {
friend dense_hash_map_local_iterator<const std::remove_pointer_t<It> *>;
using iterator_traits = std::iterator_traits<decltype(std::addressof(std::declval<It>()->element))>;
public:
using value_type = typename iterator_traits::value_type;
using pointer = typename iterator_traits::pointer;
using reference = typename iterator_traits::reference;
using difference_type = typename iterator_traits::difference_type;
using iterator_category = std::forward_iterator_tag;
dense_hash_map_local_iterator() ENTT_NOEXCEPT = default;
dense_hash_map_local_iterator(It iter, const std::size_t pos) ENTT_NOEXCEPT
: it{iter},
offset{pos} {}
template<bool Const = std::is_const_v<std::remove_pointer_t<It>>, typename = std::enable_if_t<Const>>
dense_hash_map_local_iterator(const dense_hash_map_local_iterator<std::remove_const_t<std::remove_pointer_t<It>> *> &other)
: it{other.it},
offset{other.offset} {}
dense_hash_map_local_iterator &operator++() ENTT_NOEXCEPT {
return offset = it[offset].next, *this;
}
dense_hash_map_local_iterator operator++(int) ENTT_NOEXCEPT {
dense_hash_map_local_iterator orig = *this;
return ++(*this), orig;
}
[[nodiscard]] pointer operator->() const {
return std::addressof(it[offset].element);
}
[[nodiscard]] reference operator*() const {
return *operator->();
}
[[nodiscard]] std::size_t index() const ENTT_NOEXCEPT {
return offset;
}
private:
It it;
std::size_t offset;
};
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator==(const dense_hash_map_local_iterator<ILhs> &lhs, const dense_hash_map_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return lhs.index() == rhs.index();
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator!=(const dense_hash_map_local_iterator<ILhs> &lhs, const dense_hash_map_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief Associative container for key-value pairs with unique keys.
*
* Internally, elements are organized into buckets. Which bucket an element is
* placed into depends entirely on the hash of its key. Keys with the same hash
* code appear in the same bucket.
*
* @tparam Key Key type of the associative container.
* @tparam Type Mapped type of the associative container.
* @tparam Hash Type of function to use to hash the keys.
* @tparam KeyEqual Type of function to use to compare the keys for equality.
* @tparam Allocator Type of allocator used to manage memory and elements.
*/
template<typename Key, typename Type, typename Hash, typename KeyEqual, typename Allocator>
class dense_hash_map final {
static constexpr float default_threshold = 0.875f;
static constexpr std::size_t minimum_capacity = 8u;
using allocator_traits = std::allocator_traits<Allocator>;
using alloc = typename allocator_traits::template rebind_alloc<std::pair<const Key, Type>>;
using alloc_traits = typename std::allocator_traits<alloc>;
using node_type = internal::dense_hash_map_node<const Key, Type>;
using sparse_container_type = std::vector<std::size_t, typename alloc_traits::template rebind_alloc<std::size_t>>;
using packed_container_type = std::vector<node_type, typename alloc_traits::template rebind_alloc<node_type>>;
[[nodiscard]] std::size_t hash_to_bucket(const std::size_t hash) const ENTT_NOEXCEPT {
return fast_mod(hash, bucket_count());
}
template<typename Other>
[[nodiscard]] auto constrained_find(const Other &key, std::size_t bucket) {
for(auto it = begin(bucket), last = end(bucket); it != last; ++it) {
if(packed.second()(it->first, key)) {
return begin() + it.index();
}
}
return end();
}
template<typename Other>
[[nodiscard]] auto constrained_find(const Other &key, std::size_t bucket) const {
for(auto it = cbegin(bucket), last = cend(bucket); it != last; ++it) {
if(packed.second()(it->first, key)) {
return cbegin() + it.index();
}
}
return cend();
}
template<typename... Args>
[[nodiscard]] auto get_or_emplace(const Key &key, Args &&...args) {
const auto hash = sparse.second()(key);
auto index = hash_to_bucket(hash);
if(auto it = constrained_find(key, index); it != end()) {
return std::make_pair(it, false);
}
if(const auto count = size() + 1u; count > (bucket_count() * max_load_factor())) {
rehash(bucket_count() * 2u);
index = hash_to_bucket(hash);
}
packed.first().emplace_back(sparse.first()[index], std::forward<Args>(args)...);
// update goes after emplace to enforce exception guarantees
sparse.first()[index] = size() - 1u;
return std::make_pair(--end(), true);
}
void move_and_pop(const std::size_t pos) {
if(const auto last = size() - 1u; pos != last) {
size_type *curr = sparse.first().data() + bucket(packed.first().back().element.first);
for(; *curr != last; curr = &packed.first()[*curr].next) {}
*curr = pos;
using node_allocator_traits = typename alloc_traits::template rebind_traits<decltype(node_type::element)>;
typename node_allocator_traits::allocator_type allocator = packed.first().get_allocator();
auto *ptr = std::addressof(packed.first()[pos].element);
std::destroy_at(ptr);
packed.first()[pos].next = packed.first().back().next;
// no exception guarantees when mapped type has a throwing move constructor (we're technically doomed)
node_allocator_traits::construct(allocator, ptr, std::move(packed.first().back().element));
}
packed.first().pop_back();
}
public:
/*! @brief Key type of the container. */
using key_type = Key;
/*! @brief Mapped type of the container. */
using mapped_type = Type;
/*! @brief Key-value type of the container. */
using value_type = std::pair<const Key, Type>;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Type of function to use to hash the keys. */
using hasher = Hash;
/*! @brief Type of function to use to compare the keys for equality. */
using key_equal = KeyEqual;
/*! @brief Allocator type. */
using allocator_type = Allocator;
/*! @brief Random access iterator type. */
using iterator = internal::dense_hash_map_iterator<typename packed_container_type::pointer>;
/*! @brief Constant random access iterator type. */
using const_iterator = internal::dense_hash_map_iterator<typename packed_container_type::const_pointer>;
/*! @brief Forward iterator type. */
using local_iterator = internal::dense_hash_map_local_iterator<typename packed_container_type::pointer>;
/*! @brief Constant forward iterator type. */
using const_local_iterator = internal::dense_hash_map_local_iterator<typename packed_container_type::const_pointer>;
/*! @brief Default constructor. */
dense_hash_map()
: dense_hash_map(minimum_capacity) {}
/**
* @brief Constructs an empty container with a given allocator.
* @param allocator The allocator to use.
*/
explicit dense_hash_map(const allocator_type &allocator)
: dense_hash_map{minimum_capacity, hasher{}, key_equal{}, allocator} {}
/**
* @brief Constructs an empty container with a given allocator and user
* supplied minimal number of buckets.
* @param bucket_count Minimal number of buckets.
* @param allocator The allocator to use.
*/
dense_hash_map(const size_type bucket_count, const allocator_type &allocator)
: dense_hash_map{bucket_count, hasher{}, key_equal{}, allocator} {}
/**
* @brief Constructs an empty container with a given allocator, hash
* function and user supplied minimal number of buckets.
* @param bucket_count Minimal number of buckets.
* @param hash Hash function to use.
* @param allocator The allocator to use.
*/
dense_hash_map(const size_type bucket_count, const hasher &hash, const allocator_type &allocator)
: dense_hash_map{bucket_count, hash, key_equal{}, allocator} {}
/**
* @brief Constructs an empty container with a given allocator, hash
* function, compare function and user supplied minimal number of buckets.
* @param bucket_count Minimal number of buckets.
* @param hash Hash function to use.
* @param equal Compare function to use.
* @param allocator The allocator to use.
*/
explicit dense_hash_map(const size_type bucket_count, const hasher &hash = hasher{}, const key_equal &equal = key_equal{}, const allocator_type &allocator = allocator_type())
: sparse{allocator, hash},
packed{allocator, equal},
threshold{default_threshold} {
rehash(bucket_count);
}
/**
* @brief Copy constructor.
* @param other The instance to copy from.
*/
dense_hash_map(const dense_hash_map &other)
: dense_hash_map{other, alloc_traits::select_on_container_copy_construction(other.get_allocator())} {}
/**
* @brief Allocator-extended copy constructor.
* @param other The instance to copy from.
* @param allocator The allocator to use.
*/
dense_hash_map(const dense_hash_map &other, const allocator_type &allocator)
: sparse{sparse_container_type{other.sparse.first(), allocator}, other.sparse.second()},
// cannot copy the container directly due to a nasty issue of apple clang :(
packed{packed_container_type{other.packed.first().begin(), other.packed.first().end(), allocator}, other.packed.second()},
threshold{other.threshold} {
}
/**
* @brief Default move constructor.
* @param other The instance to move from.
*/
dense_hash_map(dense_hash_map &&other) ENTT_NOEXCEPT = default;
/**
* @brief Allocator-extended move constructor.
* @param other The instance to move from.
* @param allocator The allocator to use.
*/
dense_hash_map(dense_hash_map &&other, const allocator_type &allocator) ENTT_NOEXCEPT
: sparse{sparse_container_type{std::move(other.sparse.first()), allocator}, std::move(other.sparse.second())},
// cannot move the container directly due to a nasty issue of apple clang :(
packed{packed_container_type{std::make_move_iterator(other.packed.first().begin()), std::make_move_iterator(other.packed.first().end()), allocator}, std::move(other.packed.second())},
threshold{other.threshold} {}
/*! @brief Default destructor. */
~dense_hash_map() = default;
/**
* @brief Copy assignment operator.
* @param other The instance to copy from.
* @return This container.
*/
dense_hash_map &operator=(const dense_hash_map &other) {
threshold = other.threshold;
sparse.first().clear();
packed.first().clear();
rehash(other.bucket_count());
packed.first().reserve(other.packed.first().size());
insert(other.cbegin(), other.cend());
return *this;
}
/**
* @brief Default move assignment operator.
* @param other The instance to move from.
* @return This container.
*/
dense_hash_map &operator=(dense_hash_map &&other) ENTT_NOEXCEPT = default;
/**
* @brief Returns the associated allocator.
* @return The associated allocator.
*/
[[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
return sparse.first().get_allocator();
}
/**
* @brief Returns an iterator to the beginning.
*
* The returned iterator points to the first instance of the internal array.
* If the array is empty, the returned iterator will be equal to `end()`.
*
* @return An iterator to the first instance of the internal array.
*/
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
return packed.first().data();
}
/*! @copydoc cbegin */
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
return cbegin();
}
/*! @copydoc begin */
[[nodiscard]] iterator begin() ENTT_NOEXCEPT {
return packed.first().data();
}
/**
* @brief Returns an iterator to the end.
*
* The returned iterator points to the element following the last instance
* of the internal array. Attempting to dereference the returned iterator
* results in undefined behavior.
*
* @return An iterator to the element following the last instance of the
* internal array.
*/
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
return packed.first().data() + size();
}
/*! @copydoc cend */
[[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
return cend();
}
/*! @copydoc end */
[[nodiscard]] iterator end() ENTT_NOEXCEPT {
return packed.first().data() + size();
}
/**
* @brief Checks whether a container is empty.
* @return True if the container is empty, false otherwise.
*/
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
return packed.first().empty();
}
/**
* @brief Returns the number of elements in a container.
* @return Number of elements in a container.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return packed.first().size();
}
/*! @brief Clears the container. */
void clear() ENTT_NOEXCEPT {
sparse.first().clear();
packed.first().clear();
rehash(0u);
}
/**
* @brief Inserts an element into the container, if the key does not exist.
* @param value A key-value pair eventually convertible to the value type.
* @return A pair consisting of an iterator to the inserted element (or to
* the element that prevented the insertion) and a bool denoting whether the
* insertion took place.
*/
std::pair<iterator, bool> insert(const value_type &value) {
return emplace(value);
}
/*! @copydoc insert */
std::pair<iterator, bool> insert(value_type &&value) {
return emplace(std::move(value));
}
/**
* @copydoc insert
* @tparam Arg Type of the key-value pair to insert into the container.
*/
template<typename Arg>
std::enable_if_t<std::is_constructible_v<value_type, Arg &&>, std::pair<iterator, bool>>
insert(Arg &&value) {
return emplace(std::forward<Arg>(value));
}
/**
* @brief Inserts elements into the container, if their keys do not exist.
* @tparam It Type of input iterator.
* @param first An iterator to the first element of the range of elements.
* @param last An iterator past the last element of the range of elements.
*/
template<typename It>
void insert(It first, It last) {
for(; first != last; ++first) {
emplace(*first);
}
}
/**
* @brief Inserts an element into the container or assigns to the current
* element if the key already exists.
* @tparam Arg Type of the value to insert or assign.
* @param key A key used both to look up and to insert if not found.
* @param value A value to insert or assign.
* @return A pair consisting of an iterator to the element and a bool
* denoting whether the insertion took place.
*/
template<typename Arg>
std::pair<iterator, bool> insert_or_assign(const key_type &key, Arg &&value) {
auto result = try_emplace(key, std::forward<Arg>(value));
if(!result.second) {
result.first->second = std::forward<Arg>(value);
}
return result;
}
/*! @copydoc insert_or_assign */
template<typename Arg>
std::pair<iterator, bool> insert_or_assign(key_type &&key, Arg &&value) {
auto result = try_emplace(std::move(key), std::forward<Arg>(value));
if(!result.second) {
result.first->second = std::forward<Arg>(value);
}
return result;
}
/**
* @brief Constructs an element in-place, if the key does not exist.
* @tparam Args Types of arguments to forward to the constructor of the
* element.
* @param args Arguments to forward to the constructor of the element.
* @return A pair consisting of an iterator to the inserted element (or to
* the element that prevented the insertion) and a bool denoting whether the
* insertion took place.
*/
template<typename... Args>
std::pair<iterator, bool> emplace(Args &&...args) {
if constexpr(sizeof...(Args) == 0u) {
return get_or_emplace(key_type{});
} else if constexpr(sizeof...(Args) == 1u) {
return get_or_emplace(args.first..., std::forward<Args>(args)...);
} else if constexpr(sizeof...(Args) == 2u) {
return get_or_emplace(std::get<0u>(std::tie(args...)), std::forward<Args>(args)...);
} else {
static_assert(sizeof...(Args) == 3u, "Invalid arguments");
return emplace(std::pair<key_type, mapped_type>{std::forward<Args>(args)...});
}
}
/**
* @brief Inserts in-place if the key does not exist, does nothing if the
* key exists.
* @tparam Args Types of arguments to forward to the constructor of the
* element.
* @param key A key used both to look up and to insert if not found.
* @param args Arguments to forward to the constructor of the element.
* @return A pair consisting of an iterator to the inserted element (or to
* the element that prevented the insertion) and a bool denoting whether the
* insertion took place.
*/
template<typename... Args>
std::pair<iterator, bool> try_emplace(const key_type &key, Args &&...args) {
return get_or_emplace(key, std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(std::forward<Args>(args)...));
}
/*! @copydoc try_emplace */
template<typename... Args>
std::pair<iterator, bool> try_emplace(key_type &&key, Args &&...args) {
return get_or_emplace(key, std::piecewise_construct, std::forward_as_tuple(std::move(key)), std::forward_as_tuple(std::forward<Args>(args)...));
}
/**
* @brief Removes an element from a given position.
* @param pos An iterator to the element to remove.
* @return An iterator following the removed element.
*/
iterator erase(const_iterator pos) {
const auto dist = std::distance(cbegin(), pos);
erase(pos->first);
return begin() + dist;
}
/**
* @brief Removes the given elements from a container.
* @param first An iterator to the first element of the range of elements.
* @param last An iterator past the last element of the range of elements.
* @return An iterator following the last removed element.
*/
iterator erase(const_iterator first, const_iterator last) {
const auto dist = std::distance(cbegin(), first);
for(auto rfirst = std::make_reverse_iterator(last), rlast = std::make_reverse_iterator(first); rfirst != rlast; ++rfirst) {
erase(rfirst->first);
}
return dist > static_cast<decltype(dist)>(size()) ? end() : (begin() + dist);
}
/**
* @brief Removes the element associated with a given key.
* @param key A key value of an element to remove.
* @return Number of elements removed (either 0 or 1).
*/
size_type erase(const key_type &key) {
for(size_type *curr = sparse.first().data() + bucket(key); *curr != std::numeric_limits<size_type>::max(); curr = &packed.first()[*curr].next) {
if(packed.second()(packed.first()[*curr].element.first, key)) {
const auto index = *curr;
*curr = packed.first()[*curr].next;
move_and_pop(index);
return true;
}
}
return false;
}
/**
* @brief Exchanges the contents with those of a given container.
* @param other Container to exchange the content with.
*/
void swap(dense_hash_map &other) {
using std::swap;
swap(sparse, other.sparse);
swap(packed, other.packed);
swap(threshold, other.threshold);
}
/**
* @brief Accesses a given element with bounds checking.
* @param key A key of an element to find.
* @return A reference to the mapped value of the requested element.
*/
[[nodiscard]] Type &at(const key_type &key) {
auto it = find(key);
ENTT_ASSERT(it != end(), "Invalid key");
return it->second;
}
/*! @copydoc at */
[[nodiscard]] const Type &at(const key_type &key) const {
auto it = find(key);
ENTT_ASSERT(it != cend(), "Invalid key");
return it->second;
}
/**
* @brief Accesses or inserts a given element.
* @param key A key of an element to find or insert.
* @return A reference to the mapped value of the requested element.
*/
[[nodiscard]] Type &operator[](const key_type &key) {
return try_emplace(key).first->second;
}
/**
* @brief Accesses or inserts a given element.
* @param key A key of an element to find or insert.
* @return A reference to the mapped value of the requested element.
*/
[[nodiscard]] Type &operator[](key_type &&key) {
return try_emplace(std::move(key)).first->second;
}
/**
* @brief Finds an element with a given key.
* @param key Key value of an element to search for.
* @return An iterator to an element with the given key. If no such element
* is found, a past-the-end iterator is returned.
*/
[[nodiscard]] iterator find(const key_type &key) {
return constrained_find(key, bucket(key));
}
/*! @copydoc find */
[[nodiscard]] const_iterator find(const key_type &key) const {
return constrained_find(key, bucket(key));
}
/**
* @brief Finds an element with a key that compares _equivalent_ to a given
* value.
* @tparam Other Type of the key value of an element to search for.
* @param key Key value of an element to search for.
* @return An iterator to an element with the given key. If no such element
* is found, a past-the-end iterator is returned.
*/
template<typename Other>
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, iterator>>
find(const Other &key) {
return constrained_find(key, bucket(key));
}
/*! @copydoc find */
template<typename Other>
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, const_iterator>>
find(const Other &key) const {
return constrained_find(key, bucket(key));
}
/**
* @brief Checks if the container contains an element with a given key.
* @param key Key value of an element to search for.
* @return True if there is such an element, false otherwise.
*/
[[nodiscard]] bool contains(const key_type &key) const {
return (find(key) != cend());
}
/**
* @brief Checks if the container contains an element with a key that
* compares _equivalent_ to a given value.
* @tparam Other Type of the key value of an element to search for.
* @param key Key value of an element to search for.
* @return True if there is such an element, false otherwise.
*/
template<typename Other>
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, bool>>
contains(const Other &key) const {
return (find(key) != cend());
}
/**
* @brief Returns an iterator to the beginning of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the beginning of the given bucket.
*/
[[nodiscard]] const_local_iterator cbegin(const size_type index) const {
return {packed.first().data(), sparse.first()[index]};
}
/**
* @brief Returns an iterator to the beginning of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the beginning of the given bucket.
*/
[[nodiscard]] const_local_iterator begin(const size_type index) const {
return cbegin(index);
}
/**
* @brief Returns an iterator to the beginning of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the beginning of the given bucket.
*/
[[nodiscard]] local_iterator begin(const size_type index) {
return {packed.first().data(), sparse.first()[index]};
}
/**
* @brief Returns an iterator to the end of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the end of the given bucket.
*/
[[nodiscard]] const_local_iterator cend([[maybe_unused]] const size_type index) const {
return {packed.first().data(), std::numeric_limits<size_type>::max()};
}
/**
* @brief Returns an iterator to the end of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the end of the given bucket.
*/
[[nodiscard]] const_local_iterator end([[maybe_unused]] const size_type index) const {
return cend(index);
}
/**
* @brief Returns an iterator to the end of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the end of the given bucket.
*/
[[nodiscard]] local_iterator end([[maybe_unused]] const size_type index) {
return {packed.first().data(), std::numeric_limits<size_type>::max()};
}
/**
* @brief Returns the number of buckets.
* @return The number of buckets.
*/
[[nodiscard]] size_type bucket_count() const {
return sparse.first().size();
}
/**
* @brief Returns the maximum number of buckets.
* @return The maximum number of buckets.
*/
[[nodiscard]] size_type max_bucket_count() const {
return sparse.first().max_size();
}
/**
* @brief Returns the number of elements in a given bucket.
* @param index The index of the bucket to examine.
* @return The number of elements in the given bucket.
*/
[[nodiscard]] size_type bucket_size(const size_type index) const {
return static_cast<size_type>(std::distance(begin(index), end(index)));
}
/**
* @brief Returns the bucket for a given key.
* @param key The value of the key to examine.
* @return The bucket for the given key.
*/
[[nodiscard]] size_type bucket(const key_type &key) const {
return hash_to_bucket(sparse.second()(key));
}
/**
* @brief Returns the average number of elements per bucket.
* @return The average number of elements per bucket.
*/
[[nodiscard]] float load_factor() const {
return size() / static_cast<float>(bucket_count());
}
/**
* @brief Returns the maximum average number of elements per bucket.
* @return The maximum average number of elements per bucket.
*/
[[nodiscard]] float max_load_factor() const {
return threshold;
}
/**
* @brief Sets the desired maximum average number of elements per bucket.
* @param value A desired maximum average number of elements per bucket.
*/
void max_load_factor(const float value) {
ENTT_ASSERT(value > 0.f, "Invalid load factor");
threshold = value;
rehash(0u);
}
/**
* @brief Reserves at least the specified number of buckets and regenerates
* the hash table.
* @param count New number of buckets.
*/
void rehash(const size_type count) {
auto value = (std::max)(count, minimum_capacity);
value = (std::max)(value, static_cast<size_type>(size() / max_load_factor()));
if(const auto sz = next_power_of_two(value); sz != bucket_count()) {
sparse.first().resize(sz);
std::fill(sparse.first().begin(), sparse.first().end(), std::numeric_limits<size_type>::max());
for(size_type pos{}, last = size(); pos < last; ++pos) {
const auto index = bucket(packed.first()[pos].element.first);
packed.first()[pos].next = std::exchange(sparse.first()[index], pos);
}
}
}
/**
* @brief Reserves space for at least the specified number of elements and
* regenerates the hash table.
* @param count New number of elements.
*/
void reserve(const size_type count) {
packed.first().reserve(count);
rehash(static_cast<size_type>(std::ceil(count / max_load_factor())));
}
/**
* @brief Returns the function used to hash the keys.
* @return The function used to hash the keys.
*/
[[nodiscard]] hasher hash_function() const {
return sparse.second();
}
/**
* @brief Returns the function used to compare keys for equality.
* @return The function used to compare keys for equality.
*/
[[nodiscard]] key_equal key_eq() const {
return packed.second();
}
private:
compressed_pair<sparse_container_type, hasher> sparse;
compressed_pair<packed_container_type, key_equal> packed;
float threshold;
};
} // namespace entt
#endif

View File

@@ -0,0 +1,849 @@
#ifndef ENTT_CONTAINER_DENSE_HASH_SET_HPP
#define ENTT_CONTAINER_DENSE_HASH_SET_HPP
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <functional>
#include <iterator>
#include <limits>
#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "../config/config.h"
#include "../core/compressed_pair.hpp"
#include "../core/memory.hpp"
#include "../core/type_traits.hpp"
#include "fwd.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename Type>
struct dense_hash_set_node final {
template<typename... Args>
dense_hash_set_node(const std::size_t pos, Args &&...args)
: next{pos},
element{std::forward<Args>(args)...} {}
std::size_t next;
Type element;
};
template<typename It>
class dense_hash_set_iterator {
friend dense_hash_set_iterator<const std::remove_pointer_t<It> *>;
using iterator_traits = std::iterator_traits<decltype(std::addressof(std::as_const(std::declval<It>()->element)))>;
public:
using value_type = typename iterator_traits::value_type;
using pointer = typename iterator_traits::pointer;
using reference = typename iterator_traits::reference;
using difference_type = typename iterator_traits::difference_type;
using iterator_category = std::random_access_iterator_tag;
dense_hash_set_iterator() ENTT_NOEXCEPT = default;
dense_hash_set_iterator(const It iter) ENTT_NOEXCEPT
: it{iter} {}
template<bool Const = std::is_const_v<std::remove_pointer_t<It>>, typename = std::enable_if_t<Const>>
dense_hash_set_iterator(const dense_hash_set_iterator<std::remove_const_t<std::remove_pointer_t<It>> *> &other)
: it{other.it} {}
dense_hash_set_iterator &operator++() ENTT_NOEXCEPT {
return ++it, *this;
}
dense_hash_set_iterator operator++(int) ENTT_NOEXCEPT {
dense_hash_set_iterator orig = *this;
return ++(*this), orig;
}
dense_hash_set_iterator &operator--() ENTT_NOEXCEPT {
return --it, *this;
}
dense_hash_set_iterator operator--(int) ENTT_NOEXCEPT {
dense_hash_set_iterator orig = *this;
return operator--(), orig;
}
dense_hash_set_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
it += value;
return *this;
}
dense_hash_set_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
dense_hash_set_iterator copy = *this;
return (copy += value);
}
dense_hash_set_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
return (*this += -value);
}
dense_hash_set_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
return (*this + -value);
}
[[nodiscard]] reference operator[](const difference_type value) const {
return it[value].element;
}
[[nodiscard]] pointer operator->() const {
return std::addressof(it->element);
}
[[nodiscard]] reference operator*() const {
return *operator->();
}
template<typename ILhs, typename IRhs>
friend auto operator-(const dense_hash_set_iterator<ILhs> &, const dense_hash_set_iterator<IRhs> &) ENTT_NOEXCEPT;
template<typename ILhs, typename IRhs>
friend bool operator==(const dense_hash_set_iterator<ILhs> &, const dense_hash_set_iterator<IRhs> &) ENTT_NOEXCEPT;
template<typename ILhs, typename IRhs>
friend bool operator<(const dense_hash_set_iterator<ILhs> &, const dense_hash_set_iterator<IRhs> &) ENTT_NOEXCEPT;
private:
It it;
};
template<typename ILhs, typename IRhs>
[[nodiscard]] auto operator-(const dense_hash_set_iterator<ILhs> &lhs, const dense_hash_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return lhs.it - rhs.it;
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator==(const dense_hash_set_iterator<ILhs> &lhs, const dense_hash_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return lhs.it == rhs.it;
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator!=(const dense_hash_set_iterator<ILhs> &lhs, const dense_hash_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator<(const dense_hash_set_iterator<ILhs> &lhs, const dense_hash_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return lhs.it < rhs.it;
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator>(const dense_hash_set_iterator<ILhs> &lhs, const dense_hash_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return rhs < lhs;
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator<=(const dense_hash_set_iterator<ILhs> &lhs, const dense_hash_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return !(lhs > rhs);
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator>=(const dense_hash_set_iterator<ILhs> &lhs, const dense_hash_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return !(lhs < rhs);
}
template<typename It>
class dense_hash_set_local_iterator {
friend dense_hash_set_local_iterator<const std::remove_pointer_t<It> *>;
using iterator_traits = std::iterator_traits<decltype(std::addressof(std::as_const(std::declval<It>()->element)))>;
public:
using value_type = typename iterator_traits::value_type;
using pointer = typename iterator_traits::pointer;
using reference = typename iterator_traits::reference;
using difference_type = typename iterator_traits::difference_type;
using iterator_category = std::forward_iterator_tag;
dense_hash_set_local_iterator() ENTT_NOEXCEPT = default;
dense_hash_set_local_iterator(It iter, const std::size_t pos) ENTT_NOEXCEPT
: it{iter},
offset{pos} {}
template<bool Const = std::is_const_v<std::remove_pointer_t<It>>, typename = std::enable_if_t<Const>>
dense_hash_set_local_iterator(const dense_hash_set_local_iterator<std::remove_const_t<std::remove_pointer_t<It>> *> &other)
: it{other.it},
offset{other.offset} {}
dense_hash_set_local_iterator &operator++() ENTT_NOEXCEPT {
return offset = it[offset].next, *this;
}
dense_hash_set_local_iterator operator++(int) ENTT_NOEXCEPT {
dense_hash_set_local_iterator orig = *this;
return ++(*this), orig;
}
[[nodiscard]] pointer operator->() const {
return std::addressof(it[offset].element);
}
[[nodiscard]] reference operator*() const {
return *operator->();
}
[[nodiscard]] std::size_t index() const ENTT_NOEXCEPT {
return offset;
}
private:
It it;
std::size_t offset;
};
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator==(const dense_hash_set_local_iterator<ILhs> &lhs, const dense_hash_set_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return lhs.index() == rhs.index();
}
template<typename ILhs, typename IRhs>
[[nodiscard]] bool operator!=(const dense_hash_set_local_iterator<ILhs> &lhs, const dense_hash_set_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief Associative container for unique objects of a given type.
*
* Internally, elements are organized into buckets. Which bucket an element is
* placed into depends entirely on its hash. Elements with the same hash code
* appear in the same bucket.
*
* @tparam Type Value type of the associative container.
* @tparam Hash Type of function to use to hash the values.
* @tparam KeyEqual Type of function to use to compare the values for equality.
* @tparam Allocator Type of allocator used to manage memory and elements.
*/
template<typename Type, typename Hash, typename KeyEqual, typename Allocator>
class dense_hash_set final {
static constexpr float default_threshold = 0.875f;
static constexpr std::size_t minimum_capacity = 8u;
using allocator_traits = std::allocator_traits<Allocator>;
using alloc = typename allocator_traits::template rebind_alloc<Type>;
using alloc_traits = typename std::allocator_traits<alloc>;
using node_type = internal::dense_hash_set_node<Type>;
using sparse_container_type = std::vector<std::size_t, typename alloc_traits::template rebind_alloc<std::size_t>>;
using packed_container_type = std::vector<node_type, typename alloc_traits::template rebind_alloc<node_type>>;
[[nodiscard]] std::size_t hash_to_bucket(const std::size_t hash) const ENTT_NOEXCEPT {
return fast_mod(hash, bucket_count());
}
template<typename Other>
[[nodiscard]] auto constrained_find(const Other &value, std::size_t bucket) {
for(auto it = begin(bucket), last = end(bucket); it != last; ++it) {
if(packed.second()(*it, value)) {
return begin() + it.index();
}
}
return end();
}
template<typename Other>
[[nodiscard]] auto constrained_find(const Other &value, std::size_t bucket) const {
for(auto it = cbegin(bucket), last = cend(bucket); it != last; ++it) {
if(packed.second()(*it, value)) {
return cbegin() + it.index();
}
}
return cend();
}
template<typename Arg>
[[nodiscard]] auto get_or_emplace(Arg &&arg) {
const auto hash = sparse.second()(arg);
auto index = hash_to_bucket(hash);
if(auto it = constrained_find(arg, index); it != end()) {
return std::make_pair(it, false);
}
if(const auto count = size() + 1u; count > (bucket_count() * max_load_factor())) {
rehash(bucket_count() * 2u);
index = hash_to_bucket(hash);
}
packed.first().emplace_back(sparse.first()[index], std::forward<Arg>(arg));
// update goes after emplace to enforce exception guarantees
sparse.first()[index] = size() - 1u;
return std::make_pair(--end(), true);
}
template<typename Other>
bool do_erase(const Other &value) {
for(size_type *curr = sparse.first().data() + bucket(value); *curr != std::numeric_limits<size_type>::max(); curr = &packed.first()[*curr].next) {
if(packed.second()(packed.first()[*curr].element, value)) {
const auto index = *curr;
*curr = packed.first()[*curr].next;
move_and_pop(index);
return true;
}
}
return false;
}
void move_and_pop(const std::size_t pos) {
if(const auto last = size() - 1u; pos != last) {
size_type *curr = sparse.first().data() + bucket(packed.first().back().element);
for(; *curr != last; curr = &packed.first()[*curr].next) {}
*curr = pos;
// basic exception guarantees when value type has a throwing move constructor
packed.first()[pos] = std::move(packed.first().back());
}
packed.first().pop_back();
}
public:
/*! @brief Key type of the container. */
using key_type = Type;
/*! @brief Value type of the container. */
using value_type = Type;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Type of function to use to hash the elements. */
using hasher = Hash;
/*! @brief Type of function to use to compare the elements for equality. */
using key_equal = KeyEqual;
/*! @brief Allocator type. */
using allocator_type = Allocator;
/*! @brief Random access iterator type. */
using iterator = internal::dense_hash_set_iterator<typename packed_container_type::pointer>;
/*! @brief Constant random access iterator type. */
using const_iterator = internal::dense_hash_set_iterator<typename packed_container_type::const_pointer>;
/*! @brief Forward iterator type. */
using local_iterator = internal::dense_hash_set_local_iterator<typename packed_container_type::pointer>;
/*! @brief Constant forward iterator type. */
using const_local_iterator = internal::dense_hash_set_local_iterator<typename packed_container_type::const_pointer>;
/*! @brief Default constructor. */
dense_hash_set()
: dense_hash_set(minimum_capacity) {}
/**
* @brief Constructs an empty container with a given allocator.
* @param allocator The allocator to use.
*/
explicit dense_hash_set(const allocator_type &allocator)
: dense_hash_set{minimum_capacity, hasher{}, key_equal{}, allocator} {}
/**
* @brief Constructs an empty container with a given allocator and user
* supplied minimal number of buckets.
* @param bucket_count Minimal number of buckets.
* @param allocator The allocator to use.
*/
dense_hash_set(const size_type bucket_count, const allocator_type &allocator)
: dense_hash_set{bucket_count, hasher{}, key_equal{}, allocator} {}
/**
* @brief Constructs an empty container with a given allocator, hash
* function and user supplied minimal number of buckets.
* @param bucket_count Minimal number of buckets.
* @param hash Hash function to use.
* @param allocator The allocator to use.
*/
dense_hash_set(const size_type bucket_count, const hasher &hash, const allocator_type &allocator)
: dense_hash_set{bucket_count, hash, key_equal{}, allocator} {}
/**
* @brief Constructs an empty container with a given allocator, hash
* function, compare function and user supplied minimal number of buckets.
* @param bucket_count Minimal number of buckets.
* @param hash Hash function to use.
* @param equal Compare function to use.
* @param allocator The allocator to use.
*/
explicit dense_hash_set(const size_type bucket_count, const hasher &hash = hasher{}, const key_equal &equal = key_equal{}, const allocator_type &allocator = allocator_type())
: sparse{allocator, hash},
packed{allocator, equal},
threshold{default_threshold} {
rehash(bucket_count);
}
/**
* @brief Copy constructor.
* @param other The instance to copy from.
*/
dense_hash_set(const dense_hash_set &other)
: dense_hash_set{other, alloc_traits::select_on_container_copy_construction(other.get_allocator())} {}
/**
* @brief Allocator-extended copy constructor.
* @param other The instance to copy from.
* @param allocator The allocator to use.
*/
dense_hash_set(const dense_hash_set &other, const allocator_type &allocator)
: sparse{sparse_container_type{other.sparse.first(), allocator}, other.sparse.second()},
// cannot copy the container directly due to a nasty issue of apple clang :(
packed{packed_container_type{other.packed.first().begin(), other.packed.first().end(), allocator}, other.packed.second()},
threshold{other.threshold} {
}
/**
* @brief Default move constructor.
* @param other The instance to move from.
*/
dense_hash_set(dense_hash_set &&other) ENTT_NOEXCEPT = default;
/**
* @brief Allocator-extended move constructor.
* @param other The instance to move from.
* @param allocator The allocator to use.
*/
dense_hash_set(dense_hash_set &&other, const allocator_type &allocator) ENTT_NOEXCEPT
: sparse{sparse_container_type{std::move(other.sparse.first()), allocator}, std::move(other.sparse.second())},
// cannot move the container directly due to a nasty issue of apple clang :(
packed{packed_container_type{std::make_move_iterator(other.packed.first().begin()), std::make_move_iterator(other.packed.first().end()), allocator}, std::move(other.packed.second())},
threshold{other.threshold} {}
/*! @brief Default destructor. */
~dense_hash_set() = default;
/**
* @brief Copy assignment operator.
* @param other The instance to copy from.
* @return This container.
*/
dense_hash_set &operator=(const dense_hash_set &other) {
threshold = other.threshold;
sparse.first().clear();
packed.first().clear();
rehash(other.bucket_count());
packed.first().reserve(other.packed.first().size());
insert(other.cbegin(), other.cend());
return *this;
}
/**
* @brief Default move assignment operator.
* @param other The instance to move from.
* @return This container.
*/
dense_hash_set &operator=(dense_hash_set &&other) ENTT_NOEXCEPT = default;
/**
* @brief Returns the associated allocator.
* @return The associated allocator.
*/
[[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
return sparse.first().get_allocator();
}
/**
* @brief Returns an iterator to the beginning.
*
* The returned iterator points to the first instance of the internal array.
* If the array is empty, the returned iterator will be equal to `end()`.
*
* @return An iterator to the first instance of the internal array.
*/
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
return packed.first().data();
}
/*! @copydoc cbegin */
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
return cbegin();
}
/*! @copydoc begin */
[[nodiscard]] iterator begin() ENTT_NOEXCEPT {
return packed.first().data();
}
/**
* @brief Returns an iterator to the end.
*
* The returned iterator points to the element following the last instance
* of the internal array. Attempting to dereference the returned iterator
* results in undefined behavior.
*
* @return An iterator to the element following the last instance of the
* internal array.
*/
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
return packed.first().data() + size();
}
/*! @copydoc cend */
[[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
return cend();
}
/*! @copydoc end */
[[nodiscard]] iterator end() ENTT_NOEXCEPT {
return packed.first().data() + size();
}
/**
* @brief Checks whether a container is empty.
* @return True if the container is empty, false otherwise.
*/
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
return packed.first().empty();
}
/**
* @brief Returns the number of elements in a container.
* @return Number of elements in a container.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return packed.first().size();
}
/*! @brief Clears the container. */
void clear() ENTT_NOEXCEPT {
sparse.first().clear();
packed.first().clear();
rehash(0u);
}
/**
* @brief Inserts an element into the container, if it does not exist.
* @param value An element to insert into the container.
* @return A pair consisting of an iterator to the inserted element (or to
* the element that prevented the insertion) and a bool denoting whether the
* insertion took place.
*/
std::pair<iterator, bool> insert(const value_type &value) {
return emplace(value);
}
/*! @copydoc insert */
std::pair<iterator, bool> insert(value_type &&value) {
return emplace(std::move(value));
}
/**
* @brief Inserts elements into the container, if they do not exist.
* @tparam It Type of input iterator.
* @param first An iterator to the first element of the range of elements.
* @param last An iterator past the last element of the range of elements.
*/
template<typename It>
void insert(It first, It last) {
for(; first != last; ++first) {
emplace(*first);
}
}
/**
* @brief Constructs an element in-place, if it does not exist.
* @tparam Args Types of arguments to forward to the constructor of the
* element.
* @param args Arguments to forward to the constructor of the element.
* @return A pair consisting of an iterator to the inserted element (or to
* the element that prevented the insertion) and a bool denoting whether the
* insertion took place.
*/
template<typename... Args>
std::pair<iterator, bool> emplace(Args &&...args) {
if constexpr(((sizeof...(Args) == 1u) && ... && std::is_same_v<std::remove_const_t<std::remove_reference_t<Args>>, value_type>)) {
return get_or_emplace(std::forward<Args>(args)...);
} else {
return get_or_emplace(value_type{std::forward<Args>(args)...});
}
}
/**
* @brief Removes an element from a given position.
* @param pos An iterator to the element to remove.
* @return An iterator following the removed element.
*/
iterator erase(const_iterator pos) {
const auto dist = std::distance(cbegin(), pos);
erase(*pos);
return begin() + dist;
}
/**
* @brief Removes the given elements from a container.
* @param first An iterator to the first element of the range of elements.
* @param last An iterator past the last element of the range of elements.
* @return An iterator following the last removed element.
*/
iterator erase(const_iterator first, const_iterator last) {
const auto dist = std::distance(cbegin(), first);
for(auto rfirst = std::make_reverse_iterator(last), rlast = std::make_reverse_iterator(first); rfirst != rlast; ++rfirst) {
erase(*rfirst);
}
return dist > static_cast<decltype(dist)>(size()) ? end() : (begin() + dist);
}
/**
* @brief Removes the element associated with a given value.
* @param value Value of an element to remove.
* @return Number of elements removed (either 0 or 1).
*/
size_type erase(const value_type &value) {
return do_erase(value);
}
/**
* @brief Exchanges the contents with those of a given container.
* @param other Container to exchange the content with.
*/
void swap(dense_hash_set &other) {
using std::swap;
swap(sparse, other.sparse);
swap(packed, other.packed);
swap(threshold, other.threshold);
}
/**
* @brief Finds an element with a given value.
* @param value Value of an element to search for.
* @return An iterator to an element with the given value. If no such
* element is found, a past-the-end iterator is returned.
*/
[[nodiscard]] iterator find(const value_type &value) {
return constrained_find(value, bucket(value));
}
/*! @copydoc find */
[[nodiscard]] const_iterator find(const value_type &value) const {
return constrained_find(value, bucket(value));
}
/**
* @brief Finds an element that compares _equivalent_ to a given value.
* @tparam Other Type of an element to search for.
* @param value Value of an element to search for.
* @return An iterator to an element with the given value. If no such
* element is found, a past-the-end iterator is returned.
*/
template<typename Other>
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, iterator>>
find(const Other &value) {
return constrained_find(value, bucket(value));
}
/*! @copydoc find */
template<typename Other>
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, const_iterator>>
find(const Other &value) const {
return constrained_find(value, bucket(value));
}
/**
* @brief Checks if the container contains an element with a given value.
* @param value Value of an element to search for.
* @return True if there is such an element, false otherwise.
*/
[[nodiscard]] bool contains(const value_type &value) const {
return (find(value) != cend());
}
/**
* @brief Checks if the container contains an element that compares
* _equivalent_ to a given value.
* @tparam Other Type of an element to search for.
* @param value Value of an element to search for.
* @return True if there is such an element, false otherwise.
*/
template<typename Other>
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, bool>>
contains(const Other &value) const {
return (find(value) != cend());
}
/**
* @brief Returns an iterator to the beginning of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the beginning of the given bucket.
*/
[[nodiscard]] const_local_iterator cbegin(const size_type index) const {
return {packed.first().data(), sparse.first()[index]};
}
/**
* @brief Returns an iterator to the beginning of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the beginning of the given bucket.
*/
[[nodiscard]] const_local_iterator begin(const size_type index) const {
return cbegin(index);
}
/**
* @brief Returns an iterator to the beginning of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the beginning of the given bucket.
*/
[[nodiscard]] local_iterator begin(const size_type index) {
return {packed.first().data(), sparse.first()[index]};
}
/**
* @brief Returns an iterator to the end of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the end of the given bucket.
*/
[[nodiscard]] const_local_iterator cend([[maybe_unused]] const size_type index) const {
return {packed.first().data(), std::numeric_limits<size_type>::max()};
}
/**
* @brief Returns an iterator to the end of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the end of the given bucket.
*/
[[nodiscard]] const_local_iterator end([[maybe_unused]] const size_type index) const {
return cend(index);
}
/**
* @brief Returns an iterator to the end of a given bucket.
* @param index An index of a bucket to access.
* @return An iterator to the end of the given bucket.
*/
[[nodiscard]] local_iterator end([[maybe_unused]] const size_type index) {
return {packed.first().data(), std::numeric_limits<size_type>::max()};
}
/**
* @brief Returns the number of buckets.
* @return The number of buckets.
*/
[[nodiscard]] size_type bucket_count() const {
return sparse.first().size();
}
/**
* @brief Returns the maximum number of buckets.
* @return The maximum number of buckets.
*/
[[nodiscard]] size_type max_bucket_count() const {
return sparse.first().max_size();
}
/**
* @brief Returns the number of elements in a given bucket.
* @param index The index of the bucket to examine.
* @return The number of elements in the given bucket.
*/
[[nodiscard]] size_type bucket_size(const size_type index) const {
return static_cast<size_type>(std::distance(begin(index), end(index)));
}
/**
* @brief Returns the bucket for a given element.
* @param value The value of the element to examine.
* @return The bucket for the given element.
*/
[[nodiscard]] size_type bucket(const value_type &value) const {
return hash_to_bucket(sparse.second()(value));
}
/**
* @brief Returns the average number of elements per bucket.
* @return The average number of elements per bucket.
*/
[[nodiscard]] float load_factor() const {
return size() / static_cast<float>(bucket_count());
}
/**
* @brief Returns the maximum average number of elements per bucket.
* @return The maximum average number of elements per bucket.
*/
[[nodiscard]] float max_load_factor() const {
return threshold;
}
/**
* @brief Sets the desired maximum average number of elements per bucket.
* @param value A desired maximum average number of elements per bucket.
*/
void max_load_factor(const float value) {
ENTT_ASSERT(value > 0.f, "Invalid load factor");
threshold = value;
rehash(0u);
}
/**
* @brief Reserves at least the specified number of buckets and regenerates
* the hash table.
* @param count New number of buckets.
*/
void rehash(const size_type count) {
auto value = (std::max)(count, minimum_capacity);
value = (std::max)(value, static_cast<size_type>(size() / max_load_factor()));
if(const auto sz = next_power_of_two(value); sz != bucket_count()) {
sparse.first().resize(sz);
std::fill(sparse.first().begin(), sparse.first().end(), std::numeric_limits<size_type>::max());
for(size_type pos{}, last = size(); pos < last; ++pos) {
const auto index = bucket(packed.first()[pos].element);
packed.first()[pos].next = std::exchange(sparse.first()[index], pos);
}
}
}
/**
* @brief Reserves space for at least the specified number of elements and
* regenerates the hash table.
* @param count New number of elements.
*/
void reserve(const size_type count) {
packed.first().reserve(count);
rehash(static_cast<size_type>(std::ceil(count / max_load_factor())));
}
/**
* @brief Returns the function used to hash the elements.
* @return The function used to hash the elements.
*/
[[nodiscard]] hasher hash_function() const {
return sparse.second();
}
/**
* @brief Returns the function used to compare elements for equality.
* @return The function used to compare elements for equality.
*/
[[nodiscard]] key_equal key_eq() const {
return packed.second();
}
private:
compressed_pair<sparse_container_type, hasher> sparse;
compressed_pair<packed_container_type, key_equal> packed;
float threshold;
};
} // namespace entt
#endif

View File

@@ -0,0 +1,25 @@
#ifndef ENTT_CONTAINER_FWD_HPP
#define ENTT_CONTAINER_FWD_HPP
#include <functional>
#include <memory>
namespace entt {
template<
typename Key, typename Type,
typename = std::hash<Key>,
typename = std::equal_to<Key>,
typename = std::allocator<std::pair<const Key, Type>>>
class dense_hash_map;
template<
typename Type,
typename = std::hash<Type>,
typename = std::equal_to<Type>,
typename = std::allocator<Type>>
class dense_hash_set;
} // namespace entt
#endif

137
src/entt/core/algorithm.hpp Normal file
View File

@@ -0,0 +1,137 @@
#ifndef ENTT_CORE_ALGORITHM_HPP
#define ENTT_CORE_ALGORITHM_HPP
#include <algorithm>
#include <functional>
#include <iterator>
#include <utility>
#include <vector>
#include "utility.hpp"
namespace entt {
/**
* @brief Function object to wrap `std::sort` in a class type.
*
* Unfortunately, `std::sort` cannot be passed as template argument to a class
* template or a function template.<br/>
* This class fills the gap by wrapping some flavors of `std::sort` in a
* function object.
*/
struct std_sort {
/**
* @brief Sorts the elements in a range.
*
* Sorts the elements in a range using the given binary comparison function.
*
* @tparam It Type of random access iterator.
* @tparam Compare Type of comparison function object.
* @tparam Args Types of arguments to forward to the sort function.
* @param first An iterator to the first element of the range to sort.
* @param last An iterator past the last element of the range to sort.
* @param compare A valid comparison function object.
* @param args Arguments to forward to the sort function, if any.
*/
template<typename It, typename Compare = std::less<>, typename... Args>
void operator()(It first, It last, Compare compare = Compare{}, Args &&...args) const {
std::sort(std::forward<Args>(args)..., std::move(first), std::move(last), std::move(compare));
}
};
/*! @brief Function object for performing insertion sort. */
struct insertion_sort {
/**
* @brief Sorts the elements in a range.
*
* Sorts the elements in a range using the given binary comparison function.
*
* @tparam It Type of random access iterator.
* @tparam Compare Type of comparison function object.
* @param first An iterator to the first element of the range to sort.
* @param last An iterator past the last element of the range to sort.
* @param compare A valid comparison function object.
*/
template<typename It, typename Compare = std::less<>>
void operator()(It first, It last, Compare compare = Compare{}) const {
if(first < last) {
for(auto it = first + 1; it < last; ++it) {
auto value = std::move(*it);
auto pre = it;
for(; pre > first && compare(value, *(pre - 1)); --pre) {
*pre = std::move(*(pre - 1));
}
*pre = std::move(value);
}
}
}
};
/**
* @brief Function object for performing LSD radix sort.
* @tparam Bit Number of bits processed per pass.
* @tparam N Maximum number of bits to sort.
*/
template<std::size_t Bit, std::size_t N>
struct radix_sort {
static_assert((N % Bit) == 0, "The maximum number of bits to sort must be a multiple of the number of bits processed per pass");
/**
* @brief Sorts the elements in a range.
*
* Sorts the elements in a range using the given _getter_ to access the
* actual data to be sorted.
*
* This implementation is inspired by the online book
* [Physically Based Rendering](http://www.pbr-book.org/3ed-2018/Primitives_and_Intersection_Acceleration/Bounding_Volume_Hierarchies.html#RadixSort).
*
* @tparam It Type of random access iterator.
* @tparam Getter Type of _getter_ function object.
* @param first An iterator to the first element of the range to sort.
* @param last An iterator past the last element of the range to sort.
* @param getter A valid _getter_ function object.
*/
template<typename It, typename Getter = identity>
void operator()(It first, It last, Getter getter = Getter{}) const {
if(first < last) {
static constexpr auto mask = (1 << Bit) - 1;
static constexpr auto buckets = 1 << Bit;
static constexpr auto passes = N / Bit;
using value_type = typename std::iterator_traits<It>::value_type;
std::vector<value_type> aux(std::distance(first, last));
auto part = [getter = std::move(getter)](auto from, auto to, auto out, auto start) {
std::size_t index[buckets]{};
std::size_t count[buckets]{};
for(auto it = from; it != to; ++it) {
++count[(getter(*it) >> start) & mask];
}
for(std::size_t pos{}, end = buckets - 1u; pos < end; ++pos) {
index[pos + 1u] = index[pos] + count[pos];
}
for(auto it = from; it != to; ++it) {
out[index[(getter(*it) >> start) & mask]++] = std::move(*it);
}
};
for(std::size_t pass = 0; pass < (passes & ~1); pass += 2) {
part(first, last, aux.begin(), pass * Bit);
part(aux.begin(), aux.end(), first, (pass + 1) * Bit);
}
if constexpr(passes & 1) {
part(first, last, aux.begin(), (passes - 1) * Bit);
std::move(aux.begin(), aux.end(), first);
}
}
}
};
} // namespace entt
#endif

494
src/entt/core/any.hpp Normal file
View File

@@ -0,0 +1,494 @@
#ifndef ENTT_CORE_ANY_HPP
#define ENTT_CORE_ANY_HPP
#include <cstddef>
#include <memory>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "../core/utility.hpp"
#include "fwd.hpp"
#include "type_info.hpp"
#include "type_traits.hpp"
namespace entt {
/**
* @brief A SBO friendly, type-safe container for single values of any type.
* @tparam Len Size of the storage reserved for the small buffer optimization.
* @tparam Align Optional alignment requirement.
*/
template<std::size_t Len, std::size_t Align>
class basic_any {
enum class operation : std::uint8_t {
copy,
move,
transfer,
assign,
destroy,
compare,
get
};
enum class policy : std::uint8_t {
owner,
ref,
cref
};
using storage_type = std::aligned_storage_t<Len + !Len, Align>;
using vtable_type = const void *(const operation, const basic_any &, const void *);
template<typename Type>
static constexpr bool in_situ = Len && alignof(Type) <= alignof(storage_type) && sizeof(Type) <= sizeof(storage_type) && std::is_nothrow_move_constructible_v<Type>;
template<typename Type>
static const void *basic_vtable([[maybe_unused]] const operation op, [[maybe_unused]] const basic_any &value, [[maybe_unused]] const void *other) {
static_assert(!std::is_same_v<Type, void> && std::is_same_v<std::remove_reference_t<std::remove_const_t<Type>>, Type>, "Invalid type");
const Type *instance = nullptr;
if constexpr(in_situ<Type>) {
instance = (value.mode == policy::owner) ? ENTT_LAUNDER(reinterpret_cast<const Type *>(&value.storage)) : static_cast<const Type *>(value.instance);
} else {
instance = static_cast<const Type *>(value.instance);
}
switch(op) {
case operation::copy:
if constexpr(std::is_copy_constructible_v<Type>) {
static_cast<basic_any *>(const_cast<void *>(other))->initialize<Type>(*instance);
}
break;
case operation::move:
if constexpr(in_situ<Type>) {
if(value.mode == policy::owner) {
return new(&static_cast<basic_any *>(const_cast<void *>(other))->storage) Type{std::move(*const_cast<Type *>(instance))};
}
}
return (static_cast<basic_any *>(const_cast<void *>(other))->instance = std::exchange(const_cast<basic_any &>(value).instance, nullptr));
case operation::transfer:
if constexpr(std::is_move_assignable_v<Type>) {
*const_cast<Type *>(instance) = std::move(*static_cast<Type *>(const_cast<void *>(other)));
return other;
}
[[fallthrough]];
case operation::assign:
if constexpr(std::is_copy_assignable_v<Type>) {
*const_cast<Type *>(instance) = *static_cast<const Type *>(other);
return other;
}
break;
case operation::destroy:
if constexpr(in_situ<Type>) {
instance->~Type();
} else if constexpr(std::is_array_v<Type>) {
delete[] instance;
} else {
delete instance;
}
break;
case operation::compare:
if constexpr(!std::is_function_v<Type> && !std::is_array_v<Type> && is_equality_comparable_v<Type>) {
return *static_cast<const Type *>(instance) == *static_cast<const Type *>(other) ? other : nullptr;
} else {
return (instance == other) ? other : nullptr;
}
case operation::get:
return instance;
}
return nullptr;
}
template<typename Type, typename... Args>
void initialize([[maybe_unused]] Args &&...args) {
if constexpr(!std::is_void_v<Type>) {
vtable = basic_vtable<std::remove_const_t<std::remove_reference_t<Type>>>;
info = &type_id<Type>();
if constexpr(std::is_lvalue_reference_v<Type>) {
static_assert(sizeof...(Args) == 1u && (std::is_lvalue_reference_v<Args> && ...), "Invalid arguments");
mode = std::is_const_v<std::remove_reference_t<Type>> ? policy::cref : policy::ref;
instance = (std::addressof(args), ...);
} else if constexpr(in_situ<Type>) {
if constexpr(sizeof...(Args) != 0u && std::is_aggregate_v<Type>) {
new(&storage) Type{std::forward<Args>(args)...};
} else {
new(&storage) Type(std::forward<Args>(args)...);
}
} else {
if constexpr(sizeof...(Args) != 0u && std::is_aggregate_v<Type>) {
instance = new Type{std::forward<Args>(args)...};
} else {
instance = new Type(std::forward<Args>(args)...);
}
}
}
}
basic_any(const basic_any &other, const policy pol) ENTT_NOEXCEPT
: instance{other.data()},
info{other.info},
vtable{other.vtable},
mode{pol} {}
public:
/*! @brief Size of the internal storage. */
static constexpr auto length = Len;
/*! @brief Alignment requirement. */
static constexpr auto alignment = Align;
/*! @brief Default constructor. */
basic_any() ENTT_NOEXCEPT
: instance{},
info{&type_id<void>()},
vtable{},
mode{policy::owner} {}
/**
* @brief Constructs a wrapper by directly initializing the new object.
* @tparam Type Type of object to use to initialize the wrapper.
* @tparam Args Types of arguments to use to construct the new instance.
* @param args Parameters to use to construct the instance.
*/
template<typename Type, typename... Args>
explicit basic_any(std::in_place_type_t<Type>, Args &&...args)
: basic_any{} {
initialize<Type>(std::forward<Args>(args)...);
}
/**
* @brief Constructs a wrapper from a given value.
* @tparam Type Type of object to use to initialize the wrapper.
* @param value An instance of an object to use to initialize the wrapper.
*/
template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, basic_any>>>
basic_any(Type &&value)
: basic_any{} {
initialize<std::decay_t<Type>>(std::forward<Type>(value));
}
/**
* @brief Copy constructor.
* @param other The instance to copy from.
*/
basic_any(const basic_any &other)
: basic_any{} {
if(other.vtable) {
other.vtable(operation::copy, other, this);
}
}
/**
* @brief Move constructor.
* @param other The instance to move from.
*/
basic_any(basic_any &&other) ENTT_NOEXCEPT
: instance{},
info{other.info},
vtable{other.vtable},
mode{other.mode} {
if(other.vtable) {
other.vtable(operation::move, other, this);
}
}
/*! @brief Frees the internal storage, whatever it means. */
~basic_any() {
if(vtable && mode == policy::owner) {
vtable(operation::destroy, *this, nullptr);
}
}
/**
* @brief Copy assignment operator.
* @param other The instance to copy from.
* @return This any object.
*/
basic_any &operator=(const basic_any &other) {
reset();
if(other.vtable) {
other.vtable(operation::copy, other, this);
}
return *this;
}
/**
* @brief Move assignment operator.
* @param other The instance to move from.
* @return This any object.
*/
basic_any &operator=(basic_any &&other) ENTT_NOEXCEPT {
reset();
if(other.vtable) {
other.vtable(operation::move, other, this);
info = other.info;
vtable = other.vtable;
mode = other.mode;
}
return *this;
}
/**
* @brief Value assignment operator.
* @tparam Type Type of object to use to initialize the wrapper.
* @param value An instance of an object to use to initialize the wrapper.
* @return This any object.
*/
template<typename Type>
std::enable_if_t<!std::is_same_v<std::decay_t<Type>, basic_any>, basic_any &>
operator=(Type &&value) {
emplace<std::decay_t<Type>>(std::forward<Type>(value));
return *this;
}
/**
* @brief Returns the object type if any, `type_id<void>()` otherwise.
* @return The object type if any, `type_id<void>()` otherwise.
*/
[[nodiscard]] const type_info &type() const ENTT_NOEXCEPT {
return *info;
}
/**
* @brief Returns an opaque pointer to the contained instance.
* @return An opaque pointer the contained instance, if any.
*/
[[nodiscard]] const void *data() const ENTT_NOEXCEPT {
return vtable ? vtable(operation::get, *this, nullptr) : nullptr;
}
/**
* @brief Returns an opaque pointer to the contained instance.
* @param req Expected type.
* @return An opaque pointer the contained instance, if any.
*/
[[nodiscard]] const void *data(const type_info &req) const ENTT_NOEXCEPT {
return *info == req ? data() : nullptr;
}
/**
* @brief Returns an opaque pointer to the contained instance.
* @return An opaque pointer the contained instance, if any.
*/
[[nodiscard]] void *data() ENTT_NOEXCEPT {
return (!vtable || mode == policy::cref) ? nullptr : const_cast<void *>(vtable(operation::get, *this, nullptr));
}
/**
* @brief Returns an opaque pointer to the contained instance.
* @param req Expected type.
* @return An opaque pointer the contained instance, if any.
*/
[[nodiscard]] void *data(const type_info &req) ENTT_NOEXCEPT {
return *info == req ? data() : nullptr;
}
/**
* @brief Replaces the contained object by creating a new instance directly.
* @tparam Type Type of object to use to initialize the wrapper.
* @tparam Args Types of arguments to use to construct the new instance.
* @param args Parameters to use to construct the instance.
*/
template<typename Type, typename... Args>
void emplace(Args &&...args) {
reset();
initialize<Type>(std::forward<Args>(args)...);
}
/**
* @brief Copy assigns a value to the contained object without replacing it.
* @param other The value to assign to the contained object.
* @return True in case of success, false otherwise.
*/
bool assign(const any &other) {
if(vtable && mode != policy::cref && *info == *other.info) {
return (vtable(operation::assign, *this, other.data()) != nullptr);
}
return false;
}
/**
* @brief Move assigns a value to the contained object without replacing it.
* @param other The value to assign to the contained object.
* @return True in case of success, false otherwise.
*/
bool assign(any &&other) {
if(vtable && mode != policy::cref && *info == *other.info) {
if(auto *val = other.data(); val) {
return (vtable(operation::transfer, *this, val) != nullptr);
} else {
return (vtable(operation::assign, *this, std::as_const(other).data()) != nullptr);
}
}
return false;
}
/*! @brief Destroys contained object */
void reset() {
if(vtable && mode == policy::owner) {
vtable(operation::destroy, *this, nullptr);
}
info = &type_id<void>();
vtable = nullptr;
mode = policy::owner;
}
/**
* @brief Returns false if a wrapper is empty, true otherwise.
* @return False if the wrapper is empty, true otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return vtable != nullptr;
}
/**
* @brief Checks if two wrappers differ in their content.
* @param other Wrapper with which to compare.
* @return False if the two objects differ in their content, true otherwise.
*/
bool operator==(const basic_any &other) const ENTT_NOEXCEPT {
if(vtable && *info == *other.info) {
return (vtable(operation::compare, *this, other.data()) != nullptr);
}
return (!vtable && !other.vtable);
}
/**
* @brief Aliasing constructor.
* @return A wrapper that shares a reference to an unmanaged object.
*/
[[nodiscard]] basic_any as_ref() ENTT_NOEXCEPT {
return basic_any{*this, (mode == policy::cref ? policy::cref : policy::ref)};
}
/*! @copydoc as_ref */
[[nodiscard]] basic_any as_ref() const ENTT_NOEXCEPT {
return basic_any{*this, policy::cref};
}
/**
* @brief Returns true if a wrapper owns its object, false otherwise.
* @return True if the wrapper owns its object, false otherwise.
*/
[[nodiscard]] bool owner() const ENTT_NOEXCEPT {
return (mode == policy::owner);
}
private:
union {
const void *instance;
storage_type storage;
};
const type_info *info;
vtable_type *vtable;
policy mode;
};
/**
* @brief Checks if two wrappers differ in their content.
* @tparam Len Size of the storage reserved for the small buffer optimization.
* @tparam Align Alignment requirement.
* @param lhs A wrapper, either empty or not.
* @param rhs A wrapper, either empty or not.
* @return True if the two wrappers differ in their content, false otherwise.
*/
template<std::size_t Len, std::size_t Align>
[[nodiscard]] inline bool operator!=(const basic_any<Len, Align> &lhs, const basic_any<Len, Align> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
/**
* @brief Performs type-safe access to the contained object.
* @tparam Type Type to which conversion is required.
* @tparam Len Size of the storage reserved for the small buffer optimization.
* @tparam Align Alignment requirement.
* @param data Target any object.
* @return The element converted to the requested type.
*/
template<typename Type, std::size_t Len, std::size_t Align>
Type any_cast(const basic_any<Len, Align> &data) ENTT_NOEXCEPT {
const auto *const instance = any_cast<std::remove_reference_t<Type>>(&data);
ENTT_ASSERT(instance, "Invalid instance");
return static_cast<Type>(*instance);
}
/*! @copydoc any_cast */
template<typename Type, std::size_t Len, std::size_t Align>
Type any_cast(basic_any<Len, Align> &data) ENTT_NOEXCEPT {
// forces const on non-reference types to make them work also with wrappers for const references
auto *const instance = any_cast<std::remove_reference_t<const Type>>(&data);
ENTT_ASSERT(instance, "Invalid instance");
return static_cast<Type>(*instance);
}
/*! @copydoc any_cast */
template<typename Type, std::size_t Len, std::size_t Align>
Type any_cast(basic_any<Len, Align> &&data) ENTT_NOEXCEPT {
if constexpr(std::is_copy_constructible_v<std::remove_const_t<std::remove_reference_t<Type>>>) {
if(auto *const instance = any_cast<std::remove_reference_t<Type>>(&data); instance) {
return static_cast<Type>(std::move(*instance));
} else {
return any_cast<Type>(data);
}
} else {
auto *const instance = any_cast<std::remove_reference_t<Type>>(&data);
ENTT_ASSERT(instance, "Invalid instance");
return static_cast<Type>(std::move(*instance));
}
}
/*! @copydoc any_cast */
template<typename Type, std::size_t Len, std::size_t Align>
const Type *any_cast(const basic_any<Len, Align> *data) ENTT_NOEXCEPT {
const auto &info = type_id<std::remove_const_t<std::remove_reference_t<Type>>>();
return static_cast<const Type *>(data->data(info));
}
/*! @copydoc any_cast */
template<typename Type, std::size_t Len, std::size_t Align>
Type *any_cast(basic_any<Len, Align> *data) ENTT_NOEXCEPT {
const auto &info = type_id<std::remove_const_t<std::remove_reference_t<Type>>>();
// last attempt to make wrappers for const references return their values
return static_cast<Type *>(static_cast<constness_as_t<basic_any<Len, Align>, Type> *>(data)->data(info));
}
/**
* @brief Constructs a wrapper from a given type, passing it all arguments.
* @tparam Type Type of object to use to initialize the wrapper.
* @tparam Len Size of the storage reserved for the small buffer optimization.
* @tparam Align Optional alignment requirement.
* @tparam Args Types of arguments to use to construct the new instance.
* @param args Parameters to use to construct the instance.
* @return A properly initialized wrapper for an object of the given type.
*/
template<typename Type, std::size_t Len = basic_any<>::length, std::size_t Align = basic_any<Len>::alignment, typename... Args>
basic_any<Len, Align> make_any(Args &&...args) {
return basic_any<Len, Align>{std::in_place_type<Type>, std::forward<Args>(args)...};
}
/**
* @brief Forwards its argument and avoids copies for lvalue references.
* @tparam Len Size of the storage reserved for the small buffer optimization.
* @tparam Align Optional alignment requirement.
* @tparam Type Type of argument to use to construct the new instance.
* @param value Parameter to use to construct the instance.
* @return A properly initialized and not necessarily owning wrapper.
*/
template<std::size_t Len = basic_any<>::length, std::size_t Align = basic_any<Len>::alignment, typename Type>
basic_any<Len, Align> forward_as_any(Type &&value) {
return basic_any<Len, Align>{std::in_place_type<std::conditional_t<std::is_rvalue_reference_v<Type>, std::decay_t<Type>, Type>>, std::forward<Type>(value)};
}
} // namespace entt
#endif

30
src/entt/core/attribute.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef ENTT_CORE_ATTRIBUTE_H
#define ENTT_CORE_ATTRIBUTE_H
#ifndef ENTT_EXPORT
# if defined _WIN32 || defined __CYGWIN__ || defined _MSC_VER
# define ENTT_EXPORT __declspec(dllexport)
# define ENTT_IMPORT __declspec(dllimport)
# define ENTT_HIDDEN
# elif defined __GNUC__ && __GNUC__ >= 4
# define ENTT_EXPORT __attribute__((visibility("default")))
# define ENTT_IMPORT __attribute__((visibility("default")))
# define ENTT_HIDDEN __attribute__((visibility("hidden")))
# else /* Unsupported compiler */
# define ENTT_EXPORT
# define ENTT_IMPORT
# define ENTT_HIDDEN
# endif
#endif
#ifndef ENTT_API
# if defined ENTT_API_EXPORT
# define ENTT_API ENTT_EXPORT
# elif defined ENTT_API_IMPORT
# define ENTT_API ENTT_IMPORT
# else /* No API */
# define ENTT_API
# endif
#endif
#endif

View File

@@ -0,0 +1,269 @@
#ifndef ENTT_CORE_COMPRESSED_PAIR_HPP
#define ENTT_CORE_COMPRESSED_PAIR_HPP
#include <cstddef>
#include <tuple>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "type_traits.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename Type, std::size_t, typename = void>
struct compressed_pair_element {
using reference = Type &;
using const_reference = const Type &;
template<bool Dummy = true, typename = std::enable_if_t<Dummy && std::is_default_constructible_v<Type>>>
compressed_pair_element()
: value{} {}
template<typename Args, typename = std::enable_if_t<!std::is_same_v<std::remove_const_t<std::remove_reference_t<Args>>, compressed_pair_element>>>
compressed_pair_element(Args &&args)
: value{std::forward<Args>(args)} {}
template<typename... Args, std::size_t... Index>
compressed_pair_element(std::tuple<Args...> args, std::index_sequence<Index...>)
: value{std::get<Index>(args)...} {}
[[nodiscard]] reference get() ENTT_NOEXCEPT {
return value;
}
[[nodiscard]] const_reference get() const ENTT_NOEXCEPT {
return value;
}
private:
Type value;
};
template<typename Type, std::size_t Tag>
struct compressed_pair_element<Type, Tag, std::enable_if_t<is_ebco_eligible_v<Type>>>: Type {
using reference = Type &;
using const_reference = const Type &;
using base_type = Type;
template<bool Dummy = true, typename = std::enable_if_t<Dummy && std::is_default_constructible_v<base_type>>>
compressed_pair_element()
: base_type{} {}
template<typename Args, typename = std::enable_if_t<!std::is_same_v<std::remove_const_t<std::remove_reference_t<Args>>, compressed_pair_element>>>
compressed_pair_element(Args &&args)
: base_type{std::forward<Args>(args)} {}
template<typename... Args, std::size_t... Index>
compressed_pair_element(std::tuple<Args...> args, std::index_sequence<Index...>)
: base_type{std::get<Index>(args)...} {}
[[nodiscard]] reference get() ENTT_NOEXCEPT {
return *this;
}
[[nodiscard]] const_reference get() const ENTT_NOEXCEPT {
return *this;
}
};
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief A compressed pair.
*
* A pair that exploits the _Empty Base Class Optimization_ (or _EBCO_) to
* reduce its final size to a minimum.
*
* @tparam First The type of the first element that the pair stores.
* @tparam Second The type of the second element that the pair stores.
*/
template<typename First, typename Second>
class compressed_pair final
: internal::compressed_pair_element<First, 0u>,
internal::compressed_pair_element<Second, 1u> {
using first_base = internal::compressed_pair_element<First, 0u>;
using second_base = internal::compressed_pair_element<Second, 1u>;
public:
/*! @brief The type of the first element that the pair stores. */
using first_type = First;
/*! @brief The type of the second element that the pair stores. */
using second_type = Second;
/**
* @brief Default constructor, conditionally enabled.
*
* This constructor is only available when the types that the pair stores
* are both at least default constructible.
*
* @tparam Dummy Dummy template parameter used for internal purposes.
*/
template<bool Dummy = true, typename = std::enable_if_t<Dummy && std::is_default_constructible_v<first_type> && std::is_default_constructible_v<second_type>>>
constexpr compressed_pair()
: first_base{},
second_base{} {}
/**
* @brief Copy constructor.
* @param other The instance to copy from.
*/
constexpr compressed_pair(const compressed_pair &other) = default;
/**
* @brief Move constructor.
* @param other The instance to move from.
*/
constexpr compressed_pair(compressed_pair &&other) ENTT_NOEXCEPT = default;
/**
* @brief Constructs a pair from its values.
* @tparam Arg Type of value to use to initialize the first element.
* @tparam Other Type of value to use to initialize the second element.
* @param arg Value to use to initialize the first element.
* @param other Value to use to initialize the second element.
*/
template<typename Arg, typename Other>
constexpr compressed_pair(Arg &&arg, Other &&other)
: first_base{std::forward<Arg>(arg)},
second_base{std::forward<Other>(other)} {}
/**
* @brief Constructs a pair by forwarding the arguments to its parts.
* @tparam Args Types of arguments to use to initialize the first element.
* @tparam Other Types of arguments to use to initialize the second element.
* @param args Arguments to use to initialize the first element.
* @param other Arguments to use to initialize the second element.
*/
template<typename... Args, typename... Other>
constexpr compressed_pair(std::piecewise_construct_t, std::tuple<Args...> args, std::tuple<Other...> other)
: first_base{std::move(args), std::index_sequence_for<Args...>{}},
second_base{std::move(other), std::index_sequence_for<Other...>{}} {}
/**
* @brief Copy assignment operator.
* @param other The instance to copy from.
* @return This compressed pair object.
*/
constexpr compressed_pair &operator=(const compressed_pair &other) = default;
/**
* @brief Move assignment operator.
* @param other The instance to move from.
* @return This compressed pair object.
*/
constexpr compressed_pair &operator=(compressed_pair &&other) ENTT_NOEXCEPT = default;
/**
* @brief Returns the first element that a pair stores.
* @return The first element that a pair stores.
*/
[[nodiscard]] first_type &first() ENTT_NOEXCEPT {
return static_cast<first_base &>(*this).get();
}
/*! @copydoc first */
[[nodiscard]] const first_type &first() const ENTT_NOEXCEPT {
return static_cast<const first_base &>(*this).get();
}
/**
* @brief Returns the second element that a pair stores.
* @return The second element that a pair stores.
*/
[[nodiscard]] second_type &second() ENTT_NOEXCEPT {
return static_cast<second_base &>(*this).get();
}
/*! @copydoc second */
[[nodiscard]] const second_type &second() const ENTT_NOEXCEPT {
return static_cast<const second_base &>(*this).get();
}
/**
* @brief Swaps two compressed pair objects.
* @param other The compressed pair to swap with.
*/
void swap(compressed_pair &other) {
using std::swap;
swap(first(), other.first());
swap(second(), other.second());
}
/**
* @brief Extracts an element from the compressed pair.
* @tparam Index An integer value that is either 0 or 1.
* @return Returns a reference to the first element if `Index` is 0 and a
* reference to the second element if `Index` is 1.
*/
template<std::size_t Index>
decltype(auto) get() ENTT_NOEXCEPT {
if constexpr(Index == 0u) {
return first();
} else {
static_assert(Index == 1u, "Index out of bounds");
return second();
}
}
/*! @copydoc get */
template<std::size_t Index>
decltype(auto) get() const ENTT_NOEXCEPT {
if constexpr(Index == 0u) {
return first();
} else {
static_assert(Index == 1u, "Index out of bounds");
return second();
}
}
};
/**
* @brief Deduction guide.
* @tparam Type Type of value to use to initialize the first element.
* @tparam Other Type of value to use to initialize the second element.
*/
template<typename Type, typename Other>
compressed_pair(Type &&, Other &&) -> compressed_pair<std::decay_t<Type>, std::decay_t<Other>>;
/**
* @brief Swaps two compressed pair objects.
* @tparam First The type of the first element that the pairs store.
* @tparam Second The type of the second element that the pairs store.
* @param lhs A valid compressed pair object.
* @param rhs A valid compressed pair object.
*/
template<typename First, typename Second>
inline void swap(compressed_pair<First, Second> &lhs, compressed_pair<First, Second> &rhs) {
lhs.swap(rhs);
}
} // namespace entt
// disable structured binding support for clang 6, it messes when specializing tuple_size
#if !defined __clang_major__ || __clang_major__ > 6
namespace std {
template<typename First, typename Second>
struct tuple_size<entt::compressed_pair<First, Second>>: integral_constant<size_t, 2u> {};
template<size_t Index, typename First, typename Second>
struct tuple_element<Index, entt::compressed_pair<First, Second>>: conditional<Index == 0u, First, Second> {
static_assert(Index < 2u, "Index out of bounds");
};
} // namespace std
#endif
#endif

112
src/entt/core/enum.hpp Normal file
View File

@@ -0,0 +1,112 @@
#ifndef ENTT_CORE_FLAG_HPP
#define ENTT_CORE_FLAG_HPP
#include <type_traits>
#include "../config/config.h"
namespace entt {
/**
* @brief Enable bitmask support for enum classes.
* @tparam Type The enum type for which to enable bitmask support.
*/
template<typename Type, typename = void>
struct enum_as_bitmask: std::false_type {};
/*! @copydoc enum_as_bitmask */
template<typename Type>
struct enum_as_bitmask<Type, std::void_t<decltype(Type::_entt_enum_as_bitmask)>>: std::true_type {};
/**
* @brief Helper variable template.
* @tparam Type The enum class type for which to enable bitmask support.
*/
template<typename Type>
inline constexpr bool enum_as_bitmask_v = enum_as_bitmask<Type>::value;
} // namespace entt
/**
* @brief Operator available for enums for which bitmask support is enabled.
* @tparam Type Enum class type.
* @param lhs The first value to use.
* @param rhs The second value to use.
* @return The result of invoking the operator on the underlying types of the
* two values provided.
*/
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
operator|(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
return Type{static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs)};
}
/*! @copydoc operator| */
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
operator&(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
return Type{static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs)};
}
/*! @copydoc operator| */
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
operator^(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
return Type{static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs)};
}
/**
* @brief Operator available for enums for which bitmask support is enabled.
* @tparam Type Enum class type.
* @param value The value to use.
* @return The result of invoking the operator on the underlying types of the
* value provided.
*/
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
operator~(const Type value) ENTT_NOEXCEPT {
return Type{~static_cast<std::underlying_type_t<Type>>(value)};
}
/*! @copydoc operator~ */
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, bool>
operator!(const Type value) ENTT_NOEXCEPT {
return !static_cast<std::underlying_type_t<Type>>(value);
}
/*! @copydoc operator| */
template<typename Type>
constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type &>
operator|=(Type &lhs, const Type rhs) ENTT_NOEXCEPT {
return (lhs = (lhs | rhs));
}
/*! @copydoc operator| */
template<typename Type>
constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type &>
operator&=(Type &lhs, const Type rhs) ENTT_NOEXCEPT {
return (lhs = (lhs & rhs));
}
/*! @copydoc operator| */
template<typename Type>
constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type &>
operator^=(Type &lhs, const Type rhs) ENTT_NOEXCEPT {
return (lhs = (lhs ^ rhs));
}
/*! @copydoc operator| */
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
operator==(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
return (static_cast<std::underlying_type_t<Type>>(lhs) == static_cast<std::underlying_type_t<Type>>(rhs));
}
/*! @copydoc operator| */
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
operator!=(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
#endif

32
src/entt/core/family.hpp Normal file
View File

@@ -0,0 +1,32 @@
#ifndef ENTT_CORE_FAMILY_HPP
#define ENTT_CORE_FAMILY_HPP
#include "../config/config.h"
#include "fwd.hpp"
namespace entt {
/**
* @brief Dynamic identifier generator.
*
* Utility class template that can be used to assign unique identifiers to types
* at runtime. Use different specializations to create separate sets of
* identifiers.
*/
template<typename...>
class family {
inline static ENTT_MAYBE_ATOMIC(id_type) identifier{};
public:
/*! @brief Unsigned integer type. */
using family_type = id_type;
/*! @brief Statically generated unique identifier for the given type. */
template<typename... Type>
// at the time I'm writing, clang crashes during compilation if auto is used instead of family_type
inline static const family_type type = identifier++;
};
} // namespace entt
#endif

20
src/entt/core/fwd.hpp Normal file
View File

@@ -0,0 +1,20 @@
#ifndef ENTT_CORE_FWD_HPP
#define ENTT_CORE_FWD_HPP
#include <type_traits>
#include "../config/config.h"
namespace entt {
template<std::size_t Len = sizeof(double[2]), std::size_t = alignof(typename std::aligned_storage_t<Len + !Len>)>
class basic_any;
/*! @brief Alias declaration for type identifiers. */
using id_type = ENTT_ID_TYPE;
/*! @brief Alias declaration for the most common use case. */
using any = basic_any<>;
} // namespace entt
#endif

View File

@@ -0,0 +1,314 @@
#ifndef ENTT_CORE_HASHED_STRING_HPP
#define ENTT_CORE_HASHED_STRING_HPP
#include <cstddef>
#include <cstdint>
#include "../config/config.h"
#include "fwd.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename>
struct fnv1a_traits;
template<>
struct fnv1a_traits<std::uint32_t> {
using type = std::uint32_t;
static constexpr std::uint32_t offset = 2166136261;
static constexpr std::uint32_t prime = 16777619;
};
template<>
struct fnv1a_traits<std::uint64_t> {
using type = std::uint64_t;
static constexpr std::uint64_t offset = 14695981039346656037ull;
static constexpr std::uint64_t prime = 1099511628211ull;
};
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief Zero overhead unique identifier.
*
* A hashed string is a compile-time tool that allows users to use
* human-readable identifers in the codebase while using their numeric
* counterparts at runtime.<br/>
* Because of that, a hashed string can also be used in constant expressions if
* required.
*
* @warning
* This class doesn't take ownership of user-supplied strings nor does it make a
* copy of them.
*
* @tparam Char Character type.
*/
template<typename Char>
class basic_hashed_string {
using hs_traits = internal::fnv1a_traits<id_type>;
struct const_wrapper {
// non-explicit constructor on purpose
constexpr const_wrapper(const Char *curr) ENTT_NOEXCEPT: str{curr} {}
const Char *str;
};
// FowlerNollVo hash function v. 1a - the good
[[nodiscard]] static constexpr id_type helper(const Char *curr) ENTT_NOEXCEPT {
auto value = hs_traits::offset;
while(*curr != 0) {
value = (value ^ static_cast<hs_traits::type>(*(curr++))) * hs_traits::prime;
}
return value;
}
public:
/*! @brief Character type. */
using value_type = Char;
/*! @brief Unsigned integer type. */
using hash_type = id_type;
/**
* @brief Returns directly the numeric representation of a string view.
* @param str Human-readable identifer.
* @param size Length of the string to hash.
* @return The numeric representation of the string.
*/
[[nodiscard]] static constexpr hash_type value(const value_type *str, std::size_t size) ENTT_NOEXCEPT {
id_type partial{hs_traits::offset};
while(size--) { partial = (partial ^ (str++)[0]) * hs_traits::prime; }
return partial;
}
/**
* @brief Returns directly the numeric representation of a string.
*
* Forcing template resolution avoids implicit conversions. An
* human-readable identifier can be anything but a plain, old bunch of
* characters.<br/>
* Example of use:
* @code{.cpp}
* const auto value = basic_hashed_string<char>::value("my.png");
* @endcode
*
* @tparam N Number of characters of the identifier.
* @param str Human-readable identifer.
* @return The numeric representation of the string.
*/
template<std::size_t N>
[[nodiscard]] static constexpr hash_type value(const value_type (&str)[N]) ENTT_NOEXCEPT {
return helper(str);
}
/**
* @brief Returns directly the numeric representation of a string.
* @param wrapper Helps achieving the purpose by relying on overloading.
* @return The numeric representation of the string.
*/
[[nodiscard]] static hash_type value(const_wrapper wrapper) ENTT_NOEXCEPT {
return helper(wrapper.str);
}
/*! @brief Constructs an empty hashed string. */
constexpr basic_hashed_string() ENTT_NOEXCEPT
: str{nullptr},
hash{} {}
/**
* @brief Constructs a hashed string from an array of const characters.
*
* Forcing template resolution avoids implicit conversions. An
* human-readable identifier can be anything but a plain, old bunch of
* characters.<br/>
* Example of use:
* @code{.cpp}
* basic_hashed_string<char> hs{"my.png"};
* @endcode
*
* @tparam N Number of characters of the identifier.
* @param curr Human-readable identifer.
*/
template<std::size_t N>
constexpr basic_hashed_string(const value_type (&curr)[N]) ENTT_NOEXCEPT
: str{curr},
hash{helper(curr)} {}
/**
* @brief Explicit constructor on purpose to avoid constructing a hashed
* string directly from a `const value_type *`.
*
* @warning
* The lifetime of the string is not extended nor is it copied.
*
* @param wrapper Helps achieving the purpose by relying on overloading.
*/
explicit constexpr basic_hashed_string(const_wrapper wrapper) ENTT_NOEXCEPT
: str{wrapper.str},
hash{helper(wrapper.str)} {}
/**
* @brief Returns the human-readable representation of a hashed string.
* @return The string used to initialize the instance.
*/
[[nodiscard]] constexpr const value_type *data() const ENTT_NOEXCEPT {
return str;
}
/**
* @brief Returns the numeric representation of a hashed string.
* @return The numeric representation of the instance.
*/
[[nodiscard]] constexpr hash_type value() const ENTT_NOEXCEPT {
return hash;
}
/*! @copydoc data */
[[nodiscard]] constexpr operator const value_type *() const ENTT_NOEXCEPT {
return data();
}
/**
* @brief Returns the numeric representation of a hashed string.
* @return The numeric representation of the instance.
*/
[[nodiscard]] constexpr operator hash_type() const ENTT_NOEXCEPT {
return value();
}
private:
const value_type *str;
hash_type hash;
};
/**
* @brief Deduction guide.
*
* It allows to deduce the character type of the hashed string directly from a
* human-readable identifer provided to the constructor.
*
* @tparam Char Character type.
* @tparam N Number of characters of the identifier.
* @param str Human-readable identifer.
*/
template<typename Char, std::size_t N>
basic_hashed_string(const Char (&str)[N]) -> basic_hashed_string<Char>;
/**
* @brief Compares two hashed strings.
* @tparam Char Character type.
* @param lhs A valid hashed string.
* @param rhs A valid hashed string.
* @return True if the two hashed strings are identical, false otherwise.
*/
template<typename Char>
[[nodiscard]] constexpr bool operator==(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
return lhs.value() == rhs.value();
}
/**
* @brief Compares two hashed strings.
* @tparam Char Character type.
* @param lhs A valid hashed string.
* @param rhs A valid hashed string.
* @return True if the two hashed strings differ, false otherwise.
*/
template<typename Char>
[[nodiscard]] constexpr bool operator!=(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
/**
* @brief Compares two hashed strings.
* @tparam Char Character type.
* @param lhs A valid hashed string.
* @param rhs A valid hashed string.
* @return True if the first element is less than the second, false otherwise.
*/
template<typename Char>
[[nodiscard]] constexpr bool operator<(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
return lhs.value() < rhs.value();
}
/**
* @brief Compares two hashed strings.
* @tparam Char Character type.
* @param lhs A valid hashed string.
* @param rhs A valid hashed string.
* @return True if the first element is less than or equal to the second, false
* otherwise.
*/
template<typename Char>
[[nodiscard]] constexpr bool operator<=(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
return !(rhs < lhs);
}
/**
* @brief Compares two hashed strings.
* @tparam Char Character type.
* @param lhs A valid hashed string.
* @param rhs A valid hashed string.
* @return True if the first element is greater than the second, false
* otherwise.
*/
template<typename Char>
[[nodiscard]] constexpr bool operator>(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
return rhs < lhs;
}
/**
* @brief Compares two hashed strings.
* @tparam Char Character type.
* @param lhs A valid hashed string.
* @param rhs A valid hashed string.
* @return True if the first element is greater than or equal to the second,
* false otherwise.
*/
template<typename Char>
[[nodiscard]] constexpr bool operator>=(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
return !(lhs < rhs);
}
/*! @brief Aliases for common character types. */
using hashed_string = basic_hashed_string<char>;
/*! @brief Aliases for common character types. */
using hashed_wstring = basic_hashed_string<wchar_t>;
inline namespace literals {
/**
* @brief User defined literal for hashed strings.
* @param str The literal without its suffix.
* @return A properly initialized hashed string.
*/
[[nodiscard]] constexpr entt::hashed_string operator"" _hs(const char *str, std::size_t) ENTT_NOEXCEPT {
return entt::hashed_string{str};
}
/**
* @brief User defined literal for hashed wstrings.
* @param str The literal without its suffix.
* @return A properly initialized hashed wstring.
*/
[[nodiscard]] constexpr entt::hashed_wstring operator"" _hws(const wchar_t *str, std::size_t) ENTT_NOEXCEPT {
return entt::hashed_wstring{str};
}
} // namespace literals
} // namespace entt
#endif

59
src/entt/core/ident.hpp Normal file
View File

@@ -0,0 +1,59 @@
#ifndef ENTT_CORE_IDENT_HPP
#define ENTT_CORE_IDENT_HPP
#include <cstddef>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "fwd.hpp"
#include "type_traits.hpp"
namespace entt {
/**
* @brief Types identifiers.
*
* Variable template used to generate identifiers at compile-time for the given
* types. Use the `get` member function to know what's the identifier associated
* to the specific type.
*
* @note
* Identifiers are constant expression and can be used in any context where such
* an expression is required. As an example:
* @code{.cpp}
* using id = entt::identifier<a_type, another_type>;
*
* switch(a_type_identifier) {
* case id::type<a_type>:
* // ...
* break;
* case id::type<another_type>:
* // ...
* break;
* default:
* // ...
* }
* @endcode
*
* @tparam Types List of types for which to generate identifiers.
*/
template<typename... Types>
class identifier {
template<typename Type, std::size_t... Index>
[[nodiscard]] static constexpr id_type get(std::index_sequence<Index...>) {
static_assert(std::disjunction_v<std::is_same<Type, Types>...>, "Invalid type");
return (0 + ... + (std::is_same_v<Type, type_list_element_t<Index, type_list<std::decay_t<Types>...>>> ? id_type{Index} : id_type{}));
}
public:
/*! @brief Unsigned integer type. */
using identifier_type = id_type;
/*! @brief Statically generated unique identifier for the given type. */
template<typename Type>
static constexpr identifier_type type = get<std::decay_t<Type>>(std::index_sequence_for<Types...>{});
};
} // namespace entt
#endif

116
src/entt/core/iterator.hpp Normal file
View File

@@ -0,0 +1,116 @@
#ifndef ENTT_CORE_ITERATOR_HPP
#define ENTT_CORE_ITERATOR_HPP
#include <iterator>
#include <memory>
#include <utility>
#include "../config/config.h"
namespace entt {
/**
* @brief Helper type to use as pointer with input iterators.
* @tparam Type of wrapped value.
*/
template<typename Type>
struct input_iterator_pointer final {
/*! @brief Pointer type. */
using pointer = decltype(std::addressof(std::declval<Type &>()));
/*! @brief Default copy constructor, deleted on purpose. */
input_iterator_pointer(const input_iterator_pointer &) = delete;
/*! @brief Default move constructor. */
input_iterator_pointer(input_iterator_pointer &&) = default;
/**
* @brief Constructs a proxy object by move.
* @param val Value to use to initialize the proxy object.
*/
input_iterator_pointer(Type &&val)
: value{std::move(val)} {}
/**
* @brief Default copy assignment operator, deleted on purpose.
* @return This proxy object.
*/
input_iterator_pointer &operator=(const input_iterator_pointer &) = delete;
/**
* @brief Default move assignment operator.
* @return This proxy object.
*/
input_iterator_pointer &operator=(input_iterator_pointer &&) = default;
/**
* @brief Access operator for accessing wrapped values.
* @return A pointer to the wrapped value.
*/
[[nodiscard]] pointer operator->() ENTT_NOEXCEPT {
return std::addressof(value);
}
private:
Type value;
};
/**
* @brief Utility class to create an iterable object from a pair of iterators.
* @tparam It Type of iterators.
*/
template<typename It>
struct iterable_adaptor final {
/*! @brief Type of the objects returned during iteration. */
using value_type = typename std::iterator_traits<It>::value_type;
/*! @brief Iterator type. */
using iterator = It;
/*! @brief Const iterator type. */
using const_iterator = iterator;
/*! @brief Default constructor. */
iterable_adaptor() = default;
/**
* @brief Creates an iterable object from a pair of iterators.
* @param from Begin iterator.
* @param to End iterator.
*/
iterable_adaptor(It from, It to)
: first{from},
last{to} {}
/**
* @brief Returns an iterator to the beginning.
* @return An iterator to the first element of the range.
*/
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
return first;
}
/**
* @brief Returns an iterator to the end.
* @return An iterator to the element following the last element of the
* range.
*/
[[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
return last;
}
/*! @copydoc begin */
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
return begin();
}
/*! @copydoc end */
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
return end();
}
private:
It first;
It last;
};
} // namespace entt
#endif

108
src/entt/core/memory.hpp Normal file
View File

@@ -0,0 +1,108 @@
#ifndef ENTT_CORE_MEMORY_HPP
#define ENTT_CORE_MEMORY_HPP
#include <cstddef>
#include <limits>
#include <memory>
#include <type_traits>
#include <utility>
#include "../config/config.h"
namespace entt {
/**
* @brief Unwraps fancy pointers, does nothing otherwise (waiting for C++20).
* @tparam Type Pointer type.
* @param ptr Fancy or raw pointer.
* @return A raw pointer that represents the address of the original pointer.
*/
template<typename Type>
[[nodiscard]] constexpr auto to_address(Type &&ptr) ENTT_NOEXCEPT {
if constexpr(std::is_pointer_v<std::remove_const_t<std::remove_reference_t<Type>>>) {
return ptr;
} else {
return to_address(std::forward<Type>(ptr).operator->());
}
}
/**
* @brief Utility function to design allocation-aware containers.
* @tparam Allocator Type of allocator.
* @param lhs A valid allocator.
* @param rhs Another valid allocator.
*/
template<typename Allocator>
constexpr void propagate_on_container_copy_assignment([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value) {
lhs = rhs;
}
}
/**
* @brief Utility function to design allocation-aware containers.
* @tparam Allocator Type of allocator.
* @param lhs A valid allocator.
* @param rhs Another valid allocator.
*/
template<typename Allocator>
constexpr void propagate_on_container_move_assignment([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value) {
lhs = std::move(rhs);
}
}
/**
* @brief Utility function to design allocation-aware containers.
* @tparam Allocator Type of allocator.
* @param lhs A valid allocator.
* @param rhs Another valid allocator.
*/
template<typename Allocator>
constexpr void propagate_on_container_swap([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {
ENTT_ASSERT(std::allocator_traits<Allocator>::propagate_on_container_swap::value || lhs == rhs, "Cannot swap the containers");
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_swap::value) {
using std::swap;
swap(lhs, rhs);
}
}
/**
* @brief Checks whether a value is a power of two or not.
* @param value A value that may or may not be a power of two.
* @return True if the value is a power of two, false otherwise.
*/
[[nodiscard]] inline constexpr bool is_power_of_two(const std::size_t value) ENTT_NOEXCEPT {
return value && ((value & (value - 1)) == 0);
}
/**
* @brief Computes the smallest power of two greater than or equal to a value.
* @param value The value to use.
* @return The smallest power of two greater than or equal to the given value.
*/
[[nodiscard]] inline constexpr std::size_t next_power_of_two(const std::size_t value) ENTT_NOEXCEPT {
ENTT_ASSERT(value < (std::size_t{1u} << (std::numeric_limits<std::size_t>::digits - 1)), "Numeric limits exceeded");
std::size_t curr = value - (value != 0u);
for(int next = 1; next < std::numeric_limits<std::size_t>::digits; next = next * 2) {
curr |= curr >> next;
}
return ++curr;
}
/**
* @brief Fast module utility function (powers of two only).
* @param value A value for which to calculate the modulus.
* @param mod _Modulus_, it must be a power of two.
* @return The common remainder.
*/
[[nodiscard]] inline constexpr std::size_t fast_mod(const std::size_t value, const std::size_t mod) ENTT_NOEXCEPT {
ENTT_ASSERT(is_power_of_two(mod), "Value must be a power of two");
return value & (mod - 1u);
}
} // namespace entt
#endif

View File

@@ -0,0 +1,56 @@
#ifndef ENTT_CORE_MONOSTATE_HPP
#define ENTT_CORE_MONOSTATE_HPP
#include "../config/config.h"
#include "fwd.hpp"
namespace entt {
/**
* @brief Minimal implementation of the monostate pattern.
*
* A minimal, yet complete configuration system built on top of the monostate
* pattern. Thread safe by design, it works only with basic types like `int`s or
* `bool`s.<br/>
* Multiple types and therefore more than one value can be associated with a
* single key. Because of this, users must pay attention to use the same type
* both during an assignment and when they try to read back their data.
* Otherwise, they can incur in unexpected results.
*/
template<id_type>
struct monostate {
/**
* @brief Assigns a value of a specific type to a given key.
* @tparam Type Type of the value to assign.
* @param val User data to assign to the given key.
*/
template<typename Type>
void operator=(Type val) const ENTT_NOEXCEPT {
value<Type> = val;
}
/**
* @brief Gets a value of a specific type for a given key.
* @tparam Type Type of the value to get.
* @return Stored value, if any.
*/
template<typename Type>
operator Type() const ENTT_NOEXCEPT {
return value<Type>;
}
private:
template<typename Type>
inline static ENTT_MAYBE_ATOMIC(Type) value{};
};
/**
* @brief Helper variable template.
* @tparam Value Value used to differentiate between different variables.
*/
template<id_type Value>
inline monostate<Value> monostate_v = {};
} // namespace entt
#endif

29
src/entt/core/tuple.hpp Normal file
View File

@@ -0,0 +1,29 @@
#ifndef ENTT_CORE_TUPLE_HPP
#define ENTT_CORE_TUPLE_HPP
#include <tuple>
#include <type_traits>
#include <utility>
#include "../config/config.h"
namespace entt {
/**
* @brief Utility function to unwrap tuples of a single element.
* @tparam Type Tuple type of any sizes.
* @param value A tuple object of the given type.
* @return The tuple itself if it contains more than one element, the first
* element otherwise.
*/
template<typename Type>
constexpr decltype(auto) unwrap_tuple(Type &&value) ENTT_NOEXCEPT {
if constexpr(std::tuple_size_v<std::remove_reference_t<Type>> == 1u) {
return std::get<0>(std::forward<Type>(value));
} else {
return std::forward<Type>(value);
}
}
} // namespace entt
#endif

267
src/entt/core/type_info.hpp Normal file
View File

@@ -0,0 +1,267 @@
#ifndef ENTT_CORE_TYPE_INFO_HPP
#define ENTT_CORE_TYPE_INFO_HPP
#include <string_view>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "../core/attribute.h"
#include "fwd.hpp"
#include "hashed_string.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
struct ENTT_API type_index final {
[[nodiscard]] static id_type next() ENTT_NOEXCEPT {
static ENTT_MAYBE_ATOMIC(id_type) value{};
return value++;
}
};
template<typename Type>
[[nodiscard]] constexpr auto stripped_type_name() ENTT_NOEXCEPT {
#if defined ENTT_PRETTY_FUNCTION
std::string_view pretty_function{ENTT_PRETTY_FUNCTION};
auto first = pretty_function.find_first_not_of(' ', pretty_function.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX) + 1);
auto value = pretty_function.substr(first, pretty_function.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
return value;
#else
return std::string_view{""};
#endif
}
template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
[[nodiscard]] static constexpr std::string_view type_name(int) ENTT_NOEXCEPT {
constexpr auto value = stripped_type_name<Type>();
return value;
}
template<typename Type>
[[nodiscard]] static std::string_view type_name(char) ENTT_NOEXCEPT {
static const auto value = stripped_type_name<Type>();
return value;
}
template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
[[nodiscard]] static constexpr id_type type_hash(int) ENTT_NOEXCEPT {
constexpr auto stripped = stripped_type_name<Type>();
constexpr auto value = hashed_string::value(stripped.data(), stripped.size());
return value;
}
template<typename Type>
[[nodiscard]] static id_type type_hash(char) ENTT_NOEXCEPT {
static const auto value = [](const auto stripped) {
return hashed_string::value(stripped.data(), stripped.size());
}(stripped_type_name<Type>());
return value;
}
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief Type sequential identifier.
* @tparam Type Type for which to generate a sequential identifier.
*/
template<typename Type, typename = void>
struct ENTT_API type_index final {
/**
* @brief Returns the sequential identifier of a given type.
* @return The sequential identifier of a given type.
*/
[[nodiscard]] static id_type value() ENTT_NOEXCEPT {
static const id_type value = internal::type_index::next();
return value;
}
/*! @copydoc value */
[[nodiscard]] constexpr operator id_type() const ENTT_NOEXCEPT {
return value();
}
};
/**
* @brief Type hash.
* @tparam Type Type for which to generate a hash value.
*/
template<typename Type, typename = void>
struct type_hash final {
/**
* @brief Returns the numeric representation of a given type.
* @return The numeric representation of the given type.
*/
#if defined ENTT_PRETTY_FUNCTION
[[nodiscard]] static constexpr id_type value() ENTT_NOEXCEPT {
return internal::type_hash<Type>(0);
#else
[[nodiscard]] static constexpr id_type value() ENTT_NOEXCEPT {
return type_index<Type>::value();
#endif
}
/*! @copydoc value */
[[nodiscard]] constexpr operator id_type() const ENTT_NOEXCEPT {
return value();
}
};
/**
* @brief Type name.
* @tparam Type Type for which to generate a name.
*/
template<typename Type, typename = void>
struct type_name final {
/**
* @brief Returns the name of a given type.
* @return The name of the given type.
*/
[[nodiscard]] static constexpr std::string_view value() ENTT_NOEXCEPT {
return internal::type_name<Type>(0);
}
/*! @copydoc value */
[[nodiscard]] constexpr operator std::string_view() const ENTT_NOEXCEPT {
return value();
}
};
/*! @brief Implementation specific information about a type. */
class type_info final {
template<typename Type>
friend const type_info &type_id() ENTT_NOEXCEPT;
template<typename Type>
constexpr type_info(std::in_place_type_t<Type>) ENTT_NOEXCEPT
: seq{type_index<std::remove_reference_t<std::remove_const_t<Type>>>::value()},
identifier{type_hash<std::remove_reference_t<std::remove_const_t<Type>>>::value()},
alias{type_name<std::remove_reference_t<std::remove_const_t<Type>>>::value()} {}
public:
/**
* @brief Type index.
* @return Type index.
*/
[[nodiscard]] constexpr id_type index() const ENTT_NOEXCEPT {
return seq;
}
/**
* @brief Type hash.
* @return Type hash.
*/
[[nodiscard]] constexpr id_type hash() const ENTT_NOEXCEPT {
return identifier;
}
/**
* @brief Type name.
* @return Type name.
*/
[[nodiscard]] constexpr std::string_view name() const ENTT_NOEXCEPT {
return alias;
}
private:
id_type seq;
id_type identifier;
std::string_view alias;
};
/**
* @brief Compares the contents of two type info objects.
* @param lhs A type info object.
* @param rhs A type info object.
* @return True if the two type info objects are identical, false otherwise.
*/
[[nodiscard]] inline constexpr bool operator==(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
return lhs.hash() == rhs.hash();
}
/**
* @brief Compares the contents of two type info objects.
* @param lhs A type info object.
* @param rhs A type info object.
* @return True if the two type info objects differ, false otherwise.
*/
[[nodiscard]] inline constexpr bool operator!=(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
/**
* @brief Compares two type info objects.
* @param lhs A valid type info object.
* @param rhs A valid type info object.
* @return True if the first element is less than the second, false otherwise.
*/
[[nodiscard]] constexpr bool operator<(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
return lhs.index() < rhs.index();
}
/**
* @brief Compares two type info objects.
* @param lhs A valid type info object.
* @param rhs A valid type info object.
* @return True if the first element is less than or equal to the second, false
* otherwise.
*/
[[nodiscard]] constexpr bool operator<=(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
return !(rhs < lhs);
}
/**
* @brief Compares two type info objects.
* @param lhs A valid type info object.
* @param rhs A valid type info object.
* @return True if the first element is greater than the second, false
* otherwise.
*/
[[nodiscard]] constexpr bool operator>(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
return rhs < lhs;
}
/**
* @brief Compares two type info objects.
* @param lhs A valid type info object.
* @param rhs A valid type info object.
* @return True if the first element is greater than or equal to the second,
* false otherwise.
*/
[[nodiscard]] constexpr bool operator>=(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
return !(lhs < rhs);
}
/**
* @brief Returns the type info object associated to a given type.
*
* The type doesn't need to be a complete type. If the type is a reference, the
* result refers to the referenced type. In all cases, top-level cv-qualifiers
* are ignored.
*
* @tparam Type Type for which to generate a type info object.
* @return A properly initialized type info object.
*/
template<typename Type>
[[nodiscard]] const type_info &type_id() ENTT_NOEXCEPT {
if constexpr(std::is_same_v<Type, std::remove_cv_t<std::remove_reference_t<Type>>>) {
static type_info instance{std::in_place_type<std::remove_cv_t<std::remove_reference_t<Type>>>};
return instance;
} else {
return type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
}
}
} // namespace entt
#endif

View File

@@ -0,0 +1,678 @@
#ifndef ENTT_CORE_TYPE_TRAITS_HPP
#define ENTT_CORE_TYPE_TRAITS_HPP
#include <cstddef>
#include <iterator>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "fwd.hpp"
namespace entt {
/**
* @brief Utility class to disambiguate overloaded functions.
* @tparam N Number of choices available.
*/
template<std::size_t N>
struct choice_t
// Unfortunately, doxygen cannot parse such a construct.
: /*! @cond TURN_OFF_DOXYGEN */ choice_t<N - 1> /*! @endcond */
{};
/*! @copybrief choice_t */
template<>
struct choice_t<0> {};
/**
* @brief Variable template for the choice trick.
* @tparam N Number of choices available.
*/
template<std::size_t N>
inline constexpr choice_t<N> choice{};
/**
* @brief Identity type trait.
*
* Useful to establish non-deduced contexts in template argument deduction
* (waiting for C++20) or to provide types through function arguments.
*
* @tparam Type A type.
*/
template<typename Type>
struct type_identity {
/*! @brief Identity type. */
using type = Type;
};
/**
* @brief Helper type.
* @tparam Type A type.
*/
template<typename Type>
using type_identity_t = typename type_identity<Type>::type;
/**
* @brief A type-only `sizeof` wrapper that returns 0 where `sizeof` complains.
* @tparam Type The type of which to return the size.
* @tparam The size of the type if `sizeof` accepts it, 0 otherwise.
*/
template<typename Type, typename = void>
struct size_of: std::integral_constant<std::size_t, 0u> {};
/*! @copydoc size_of */
template<typename Type>
struct size_of<Type, std::void_t<decltype(sizeof(Type))>>
: std::integral_constant<std::size_t, sizeof(Type)> {};
/**
* @brief Helper variable template.
* @tparam Type The type of which to return the size.
*/
template<typename Type>
inline constexpr std::size_t size_of_v = size_of<Type>::value;
/**
* @brief Using declaration to be used to _repeat_ the same type a number of
* times equal to the size of a given parameter pack.
* @tparam Type A type to repeat.
*/
template<typename Type, typename>
using unpack_as_type = Type;
/**
* @brief Helper variable template to be used to _repeat_ the same value a
* number of times equal to the size of a given parameter pack.
* @tparam Value A value to repeat.
*/
template<auto Value, typename>
inline constexpr auto unpack_as_value = Value;
/**
* @brief Wraps a static constant.
* @tparam Value A static constant.
*/
template<auto Value>
using integral_constant = std::integral_constant<decltype(Value), Value>;
/**
* @brief Alias template to facilitate the creation of named values.
* @tparam Value A constant value at least convertible to `id_type`.
*/
template<id_type Value>
using tag = integral_constant<Value>;
/**
* @brief A class to use to push around lists of types, nothing more.
* @tparam Type Types provided by the type list.
*/
template<typename... Type>
struct type_list {
/*! @brief Type list type. */
using type = type_list;
/*! @brief Compile-time number of elements in the type list. */
static constexpr auto size = sizeof...(Type);
};
/*! @brief Primary template isn't defined on purpose. */
template<std::size_t, typename>
struct type_list_element;
/**
* @brief Provides compile-time indexed access to the types of a type list.
* @tparam Index Index of the type to return.
* @tparam Type First type provided by the type list.
* @tparam Other Other types provided by the type list.
*/
template<std::size_t Index, typename Type, typename... Other>
struct type_list_element<Index, type_list<Type, Other...>>
: type_list_element<Index - 1u, type_list<Other...>> {};
/**
* @brief Provides compile-time indexed access to the types of a type list.
* @tparam Type First type provided by the type list.
* @tparam Other Other types provided by the type list.
*/
template<typename Type, typename... Other>
struct type_list_element<0u, type_list<Type, Other...>> {
/*! @brief Searched type. */
using type = Type;
};
/**
* @brief Helper type.
* @tparam Index Index of the type to return.
* @tparam List Type list to search into.
*/
template<std::size_t Index, typename List>
using type_list_element_t = typename type_list_element<Index, List>::type;
/**
* @brief Concatenates multiple type lists.
* @tparam Type Types provided by the first type list.
* @tparam Other Types provided by the second type list.
* @return A type list composed by the types of both the type lists.
*/
template<typename... Type, typename... Other>
constexpr type_list<Type..., Other...> operator+(type_list<Type...>, type_list<Other...>) {
return {};
}
/*! @brief Primary template isn't defined on purpose. */
template<typename...>
struct type_list_cat;
/*! @brief Concatenates multiple type lists. */
template<>
struct type_list_cat<> {
/*! @brief A type list composed by the types of all the type lists. */
using type = type_list<>;
};
/**
* @brief Concatenates multiple type lists.
* @tparam Type Types provided by the first type list.
* @tparam Other Types provided by the second type list.
* @tparam List Other type lists, if any.
*/
template<typename... Type, typename... Other, typename... List>
struct type_list_cat<type_list<Type...>, type_list<Other...>, List...> {
/*! @brief A type list composed by the types of all the type lists. */
using type = typename type_list_cat<type_list<Type..., Other...>, List...>::type;
};
/**
* @brief Concatenates multiple type lists.
* @tparam Type Types provided by the type list.
*/
template<typename... Type>
struct type_list_cat<type_list<Type...>> {
/*! @brief A type list composed by the types of all the type lists. */
using type = type_list<Type...>;
};
/**
* @brief Helper type.
* @tparam List Type lists to concatenate.
*/
template<typename... List>
using type_list_cat_t = typename type_list_cat<List...>::type;
/*! @brief Primary template isn't defined on purpose. */
template<typename>
struct type_list_unique;
/**
* @brief Removes duplicates types from a type list.
* @tparam Type One of the types provided by the given type list.
* @tparam Other The other types provided by the given type list.
*/
template<typename Type, typename... Other>
struct type_list_unique<type_list<Type, Other...>> {
/*! @brief A type list without duplicate types. */
using type = std::conditional_t<
std::disjunction_v<std::is_same<Type, Other>...>,
typename type_list_unique<type_list<Other...>>::type,
type_list_cat_t<type_list<Type>, typename type_list_unique<type_list<Other...>>::type>>;
};
/*! @brief Removes duplicates types from a type list. */
template<>
struct type_list_unique<type_list<>> {
/*! @brief A type list without duplicate types. */
using type = type_list<>;
};
/**
* @brief Helper type.
* @tparam Type A type list.
*/
template<typename Type>
using type_list_unique_t = typename type_list_unique<Type>::type;
/**
* @brief Provides the member constant `value` to true if a type list contains a
* given type, false otherwise.
* @tparam List Type list.
* @tparam Type Type to look for.
*/
template<typename List, typename Type>
struct type_list_contains;
/**
* @copybrief type_list_contains
* @tparam Type Types provided by the type list.
* @tparam Other Type to look for.
*/
template<typename... Type, typename Other>
struct type_list_contains<type_list<Type...>, Other>: std::disjunction<std::is_same<Type, Other>...> {};
/**
* @brief Helper variable template.
* @tparam List Type list.
* @tparam Type Type to look for.
*/
template<typename List, typename Type>
inline constexpr bool type_list_contains_v = type_list_contains<List, Type>::value;
/*! @brief Primary template isn't defined on purpose. */
template<typename...>
struct type_list_diff;
/**
* @brief Computes the difference between two type lists.
* @tparam Type Types provided by the first type list.
* @tparam Other Types provided by the second type list.
*/
template<typename... Type, typename... Other>
struct type_list_diff<type_list<Type...>, type_list<Other...>> {
/*! @brief A type list that is the difference between the two type lists. */
using type = type_list_cat_t<std::conditional_t<type_list_contains_v<type_list<Other...>, Type>, type_list<>, type_list<Type>>...>;
};
/**
* @brief Helper type.
* @tparam List Type lists between which to compute the difference.
*/
template<typename... List>
using type_list_diff_t = typename type_list_diff<List...>::type;
/**
* @brief A class to use to push around lists of constant values, nothing more.
* @tparam Value Values provided by the value list.
*/
template<auto... Value>
struct value_list {
/*! @brief Value list type. */
using type = value_list;
/*! @brief Compile-time number of elements in the value list. */
static constexpr auto size = sizeof...(Value);
};
/*! @brief Primary template isn't defined on purpose. */
template<std::size_t, typename>
struct value_list_element;
/**
* @brief Provides compile-time indexed access to the values of a value list.
* @tparam Index Index of the value to return.
* @tparam Value First value provided by the value list.
* @tparam Other Other values provided by the value list.
*/
template<std::size_t Index, auto Value, auto... Other>
struct value_list_element<Index, value_list<Value, Other...>>
: value_list_element<Index - 1u, value_list<Other...>> {};
/**
* @brief Provides compile-time indexed access to the types of a type list.
* @tparam Value First value provided by the value list.
* @tparam Other Other values provided by the value list.
*/
template<auto Value, auto... Other>
struct value_list_element<0u, value_list<Value, Other...>> {
/*! @brief Searched value. */
static constexpr auto value = Value;
};
/**
* @brief Helper type.
* @tparam Index Index of the value to return.
* @tparam List Value list to search into.
*/
template<std::size_t Index, typename List>
inline constexpr auto value_list_element_v = value_list_element<Index, List>::value;
/**
* @brief Concatenates multiple value lists.
* @tparam Value Values provided by the first value list.
* @tparam Other Values provided by the second value list.
* @return A value list composed by the values of both the value lists.
*/
template<auto... Value, auto... Other>
constexpr value_list<Value..., Other...> operator+(value_list<Value...>, value_list<Other...>) {
return {};
}
/*! @brief Primary template isn't defined on purpose. */
template<typename...>
struct value_list_cat;
/*! @brief Concatenates multiple value lists. */
template<>
struct value_list_cat<> {
/*! @brief A value list composed by the values of all the value lists. */
using type = value_list<>;
};
/**
* @brief Concatenates multiple value lists.
* @tparam Value Values provided by the first value list.
* @tparam Other Values provided by the second value list.
* @tparam List Other value lists, if any.
*/
template<auto... Value, auto... Other, typename... List>
struct value_list_cat<value_list<Value...>, value_list<Other...>, List...> {
/*! @brief A value list composed by the values of all the value lists. */
using type = typename value_list_cat<value_list<Value..., Other...>, List...>::type;
};
/**
* @brief Concatenates multiple value lists.
* @tparam Value Values provided by the value list.
*/
template<auto... Value>
struct value_list_cat<value_list<Value...>> {
/*! @brief A value list composed by the values of all the value lists. */
using type = value_list<Value...>;
};
/**
* @brief Helper type.
* @tparam List Value lists to concatenate.
*/
template<typename... List>
using value_list_cat_t = typename value_list_cat<List...>::type;
/*! @brief Same as std::is_invocable, but with tuples. */
template<typename, typename>
struct is_applicable: std::false_type {};
/**
* @copybrief is_applicable
* @tparam Func A valid function type.
* @tparam Tuple Tuple-like type.
* @tparam Args The list of arguments to use to probe the function type.
*/
template<typename Func, template<typename...> class Tuple, typename... Args>
struct is_applicable<Func, Tuple<Args...>>: std::is_invocable<Func, Args...> {};
/**
* @copybrief is_applicable
* @tparam Func A valid function type.
* @tparam Tuple Tuple-like type.
* @tparam Args The list of arguments to use to probe the function type.
*/
template<typename Func, template<typename...> class Tuple, typename... Args>
struct is_applicable<Func, const Tuple<Args...>>: std::is_invocable<Func, Args...> {};
/**
* @brief Helper variable template.
* @tparam Func A valid function type.
* @tparam Args The list of arguments to use to probe the function type.
*/
template<typename Func, typename Args>
inline constexpr bool is_applicable_v = is_applicable<Func, Args>::value;
/*! @brief Same as std::is_invocable_r, but with tuples for arguments. */
template<typename, typename, typename>
struct is_applicable_r: std::false_type {};
/**
* @copybrief is_applicable_r
* @tparam Ret The type to which the return type of the function should be
* convertible.
* @tparam Func A valid function type.
* @tparam Args The list of arguments to use to probe the function type.
*/
template<typename Ret, typename Func, typename... Args>
struct is_applicable_r<Ret, Func, std::tuple<Args...>>: std::is_invocable_r<Ret, Func, Args...> {};
/**
* @brief Helper variable template.
* @tparam Ret The type to which the return type of the function should be
* convertible.
* @tparam Func A valid function type.
* @tparam Args The list of arguments to use to probe the function type.
*/
template<typename Ret, typename Func, typename Args>
inline constexpr bool is_applicable_r_v = is_applicable_r<Ret, Func, Args>::value;
/**
* @brief Provides the member constant `value` to true if a given type is
* complete, false otherwise.
* @tparam Type The type to test.
*/
template<typename Type, typename = void>
struct is_complete: std::false_type {};
/*! @copydoc is_complete */
template<typename Type>
struct is_complete<Type, std::void_t<decltype(sizeof(Type))>>: std::true_type {};
/**
* @brief Helper variable template.
* @tparam Type The type to test.
*/
template<typename Type>
inline constexpr bool is_complete_v = is_complete<Type>::value;
/**
* @brief Provides the member constant `value` to true if a given type is an
* iterator, false otherwise.
* @tparam Type The type to test.
*/
template<typename Type, typename = void>
struct is_iterator: std::false_type {};
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename, typename = void>
struct has_iterator_category: std::false_type {};
template<typename Type>
struct has_iterator_category<Type, std::void_t<typename std::iterator_traits<Type>::iterator_category>>: std::true_type {};
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/*! @copydoc is_iterator */
template<typename Type>
struct is_iterator<Type, std::enable_if_t<!std::is_same_v<std::remove_const_t<std::remove_pointer_t<Type>>, void>>>
: internal::has_iterator_category<Type> {};
/**
* @brief Helper variable template.
* @tparam Type The type to test.
*/
template<typename Type>
inline constexpr bool is_iterator_v = is_iterator<Type>::value;
/**
* @brief Provides the member constant `value` to true if a given type is of the
* required iterator type, false otherwise.
* @tparam Type The type to test.
* @tparam It Required iterator type.
*/
template<typename Type, typename It, typename = void>
struct is_iterator_type: std::false_type {};
/*! @copydoc is_iterator_type */
template<typename Type, typename It>
struct is_iterator_type<Type, It, std::enable_if_t<is_iterator_v<Type> && std::is_same_v<Type, It>>>
: std::true_type {};
/*! @copydoc is_iterator_type */
template<typename Type, typename It>
struct is_iterator_type<Type, It, std::enable_if_t<!std::is_same_v<Type, It>, std::void_t<typename It::iterator_type>>>
: is_iterator_type<Type, typename It::iterator_type> {};
/**
* @brief Helper variable template.
* @tparam Type The type to test.
* @tparam It Required iterator type.
*/
template<typename Type, typename It>
inline constexpr bool is_iterator_type_v = is_iterator_type<Type, It>::value;
/**
* @brief Provides the member constant `value` to true if a given type is both
* an empty and non-final class, false otherwise.
* @tparam Type The type to test
*/
template<typename Type>
struct is_ebco_eligible
: std::conjunction<std::is_empty<Type>, std::negation<std::is_final<Type>>> {};
/**
* @brief Helper variable template.
* @tparam Type The type to test.
*/
template<typename Type>
inline constexpr bool is_ebco_eligible_v = is_ebco_eligible<Type>::value;
/**
* @brief Provides the member constant `value` to true if `Type::is_transparent`
* is valid and denotes a type, false otherwise.
* @tparam Type The type to test.
*/
template<typename Type, typename = void>
struct is_transparent: std::false_type {};
/*! @copydoc is_transparent */
template<typename Type>
struct is_transparent<Type, std::void_t<typename Type::is_transparent>>: std::true_type {};
/**
* @brief Helper variable template.
* @tparam Type The type to test.
*/
template<typename Type>
inline constexpr bool is_transparent_v = is_transparent<Type>::value;
/**
* @brief Provides the member constant `value` to true if a given type is
* equality comparable, false otherwise.
* @tparam Type The type to test.
*/
template<typename Type, typename = void>
struct is_equality_comparable: std::false_type {};
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename, typename = void>
struct has_tuple_size_value: std::false_type {};
template<typename Type>
struct has_tuple_size_value<Type, std::void_t<decltype(std::tuple_size<const Type>::value)>>: std::true_type {};
template<typename Type, std::size_t... Index>
[[nodiscard]] constexpr bool unpack_maybe_equality_comparable(std::index_sequence<Index...>) {
return (is_equality_comparable<std::tuple_element_t<Index, Type>>::value && ...);
}
template<typename>
[[nodiscard]] constexpr bool maybe_equality_comparable(choice_t<0>) {
return true;
}
template<typename Type>
[[nodiscard]] constexpr auto maybe_equality_comparable(choice_t<1>) -> decltype(std::declval<typename Type::value_type>(), bool{}) {
if constexpr(is_iterator_v<Type>) {
return true;
} else if constexpr(std::is_same_v<typename Type::value_type, Type>) {
return maybe_equality_comparable<Type>(choice<0>);
} else {
return is_equality_comparable<typename Type::value_type>::value;
}
}
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<is_complete_v<std::tuple_size<std::remove_const_t<Type>>>, bool> maybe_equality_comparable(choice_t<2>) {
if constexpr(has_tuple_size_value<Type>::value) {
return unpack_maybe_equality_comparable<Type>(std::make_index_sequence<std::tuple_size<Type>::value>{});
} else {
return maybe_equality_comparable<Type>(choice<1>);
}
}
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/*! @copydoc is_equality_comparable */
template<typename Type>
struct is_equality_comparable<Type, std::void_t<decltype(std::declval<Type>() == std::declval<Type>())>>
: std::bool_constant<internal::maybe_equality_comparable<Type>(choice<2>)> {};
/**
* @brief Helper variable template.
* @tparam Type The type to test.
*/
template<typename Type>
inline constexpr bool is_equality_comparable_v = is_equality_comparable<Type>::value;
/**
* @brief Transcribes the constness of a type to another type.
* @tparam To The type to which to transcribe the constness.
* @tparam From The type from which to transcribe the constness.
*/
template<typename To, typename From>
struct constness_as {
/*! @brief The type resulting from the transcription of the constness. */
using type = std::remove_const_t<To>;
};
/*! @copydoc constness_as */
template<typename To, typename From>
struct constness_as<To, const From> {
/*! @brief The type resulting from the transcription of the constness. */
using type = std::add_const_t<To>;
};
/**
* @brief Alias template to facilitate the transcription of the constness.
* @tparam To The type to which to transcribe the constness.
* @tparam From The type from which to transcribe the constness.
*/
template<typename To, typename From>
using constness_as_t = typename constness_as<To, From>::type;
/**
* @brief Extracts the class of a non-static member object or function.
* @tparam Member A pointer to a non-static member object or function.
*/
template<typename Member>
class member_class {
static_assert(std::is_member_pointer_v<Member>, "Invalid pointer type to non-static member object or function");
template<typename Class, typename Ret, typename... Args>
static Class *clazz(Ret (Class::*)(Args...));
template<typename Class, typename Ret, typename... Args>
static Class *clazz(Ret (Class::*)(Args...) const);
template<typename Class, typename Type>
static Class *clazz(Type Class::*);
public:
/*! @brief The class of the given non-static member object or function. */
using type = std::remove_pointer_t<decltype(clazz(std::declval<Member>()))>;
};
/**
* @brief Helper type.
* @tparam Member A pointer to a non-static member object or function.
*/
template<typename Member>
using member_class_t = typename member_class<Member>::type;
} // namespace entt
#endif

101
src/entt/core/utility.hpp Normal file
View File

@@ -0,0 +1,101 @@
#ifndef ENTT_CORE_UTILITY_HPP
#define ENTT_CORE_UTILITY_HPP
#include <utility>
#include "../config/config.h"
namespace entt {
/*! @brief Identity function object (waiting for C++20). */
struct identity {
/*! @brief Indicates that this is a transparent function object. */
using is_transparent = void;
/**
* @brief Returns its argument unchanged.
* @tparam Type Type of the argument.
* @param value The actual argument.
* @return The submitted value as-is.
*/
template<class Type>
[[nodiscard]] constexpr Type &&operator()(Type &&value) const ENTT_NOEXCEPT {
return std::forward<Type>(value);
}
};
/**
* @brief Constant utility to disambiguate overloaded members of a class.
* @tparam Type Type of the desired overload.
* @tparam Class Type of class to which the member belongs.
* @param member A valid pointer to a member.
* @return Pointer to the member.
*/
template<typename Type, typename Class>
[[nodiscard]] constexpr auto overload(Type Class::*member) ENTT_NOEXCEPT {
return member;
}
/**
* @brief Constant utility to disambiguate overloaded functions.
* @tparam Func Function type of the desired overload.
* @param func A valid pointer to a function.
* @return Pointer to the function.
*/
template<typename Func>
[[nodiscard]] constexpr auto overload(Func *func) ENTT_NOEXCEPT {
return func;
}
/**
* @brief Helper type for visitors.
* @tparam Func Types of function objects.
*/
template<class... Func>
struct overloaded: Func... {
using Func::operator()...;
};
/**
* @brief Deduction guide.
* @tparam Func Types of function objects.
*/
template<class... Func>
overloaded(Func...) -> overloaded<Func...>;
/**
* @brief Basic implementation of a y-combinator.
* @tparam Func Type of a potentially recursive function.
*/
template<class Func>
struct y_combinator {
/**
* @brief Constructs a y-combinator from a given function.
* @param recursive A potentially recursive function.
*/
y_combinator(Func recursive)
: func{std::move(recursive)} {}
/**
* @brief Invokes a y-combinator and therefore its underlying function.
* @tparam Args Types of arguments to use to invoke the underlying function.
* @param args Parameters to use to invoke the underlying function.
* @return Return value of the underlying function, if any.
*/
template<class... Args>
decltype(auto) operator()(Args &&...args) const {
return func(*this, std::forward<Args>(args)...);
}
/*! @copydoc operator()() */
template<class... Args>
decltype(auto) operator()(Args &&...args) {
return func(*this, std::forward<Args>(args)...);
}
private:
Func func;
};
} // namespace entt
#endif

View File

@@ -0,0 +1,37 @@
#ifndef ENTT_ENTITY_COMPONENT_HPP
#define ENTT_ENTITY_COMPONENT_HPP
#include <type_traits>
#include "../config/config.h"
namespace entt {
/*! @brief Commonly used default traits for all types. */
struct basic_component_traits {
/*! @brief Pointer stability, default is `false`. */
static constexpr auto in_place_delete = false;
/*! @brief Empty type optimization, default is `ENTT_IGNORE_IF_EMPTY`. */
static constexpr auto ignore_if_empty = ENTT_IGNORE_IF_EMPTY;
/*! @brief Page size, default is `ENTT_PACKED_PAGE`. */
static constexpr auto page_size = ENTT_PACKED_PAGE;
};
/**
* @brief Common way to access various properties of components.
* @tparam Type Type of component.
*/
template<typename Type, typename = void>
struct component_traits: basic_component_traits {
static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Unsupported type");
};
/**
* @brief Helper variable template.
* @tparam Type Type of component.
*/
template<class Type>
inline constexpr bool ignore_as_empty_v = component_traits<Type>::ignore_if_empty &&std::is_empty_v<Type>;
} // namespace entt
#endif

339
src/entt/entity/entity.hpp Normal file
View File

@@ -0,0 +1,339 @@
#ifndef ENTT_ENTITY_ENTITY_HPP
#define ENTT_ENTITY_ENTITY_HPP
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include "../config/config.h"
#include "fwd.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename, typename = void>
struct entt_traits;
template<typename Type>
struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
: entt_traits<std::underlying_type_t<Type>> {};
template<typename Type>
struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
: entt_traits<typename Type::entity_type> {};
template<>
struct entt_traits<std::uint32_t> {
using entity_type = std::uint32_t;
using version_type = std::uint16_t;
static constexpr entity_type entity_mask = 0xFFFFF;
static constexpr entity_type version_mask = 0xFFF;
static constexpr std::size_t entity_shift = 20u;
};
template<>
struct entt_traits<std::uint64_t> {
using entity_type = std::uint64_t;
using version_type = std::uint32_t;
static constexpr entity_type entity_mask = 0xFFFFFFFF;
static constexpr entity_type version_mask = 0xFFFFFFFF;
static constexpr std::size_t entity_shift = 32u;
};
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief Entity traits.
* @tparam Type Type of identifier.
*/
template<typename Type>
class entt_traits: internal::entt_traits<Type> {
using base_type = internal::entt_traits<Type>;
public:
/*! @brief Value type. */
using value_type = Type;
/*! @brief Underlying entity type. */
using entity_type = typename base_type::entity_type;
/*! @brief Underlying version type. */
using version_type = typename base_type::version_type;
/*! @brief Reserved identifier. */
static constexpr entity_type reserved = base_type::entity_mask | (base_type::version_mask << base_type::entity_shift);
/*! @brief Page size, default is `ENTT_SPARSE_PAGE`. */
static constexpr auto page_size = ENTT_SPARSE_PAGE;
/**
* @brief Converts an entity to its underlying type.
* @param value The value to convert.
* @return The integral representation of the given value.
*/
[[nodiscard]] static constexpr entity_type to_integral(const value_type value) ENTT_NOEXCEPT {
return static_cast<entity_type>(value);
}
/**
* @brief Returns the entity part once converted to the underlying type.
* @param value The value to convert.
* @return The integral representation of the entity part.
*/
[[nodiscard]] static constexpr entity_type to_entity(const value_type value) ENTT_NOEXCEPT {
return (to_integral(value) & base_type::entity_mask);
}
/**
* @brief Returns the version part once converted to the underlying type.
* @param value The value to convert.
* @return The integral representation of the version part.
*/
[[nodiscard]] static constexpr version_type to_version(const value_type value) ENTT_NOEXCEPT {
return (to_integral(value) >> base_type::entity_shift);
}
/**
* @brief Constructs an identifier from its parts.
*
* If the version part is not provided, a tombstone is returned.<br/>
* If the entity part is not provided, a null identifier is returned.
*
* @param entity The entity part of the identifier.
* @param version The version part of the identifier.
* @return A properly constructed identifier.
*/
[[nodiscard]] static constexpr value_type construct(const entity_type entity, const version_type version) ENTT_NOEXCEPT {
return value_type{(entity & base_type::entity_mask) | (static_cast<entity_type>(version) << base_type::entity_shift)};
}
/**
* @brief Combines two identifiers in a single one.
*
* The returned identifier is a copy of the first element except for its
* version, which is taken from the second element.
*
* @param lhs The identifier from which to take the entity part.
* @param rhs The identifier from which to take the version part.
* @return A properly constructed identifier.
*/
[[nodiscard]] static constexpr value_type combine(const entity_type lhs, const entity_type rhs) ENTT_NOEXCEPT {
constexpr auto mask = (base_type::version_mask << base_type::entity_shift);
return value_type{(lhs & base_type::entity_mask) | (rhs & mask)};
}
};
/**
* @copydoc entt_traits<Entity>::to_integral
* @tparam Entity The value type.
*/
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::entity_type to_integral(const Entity value) ENTT_NOEXCEPT {
return entt_traits<Entity>::to_integral(value);
}
/**
* @copydoc entt_traits<Entity>::to_entity
* @tparam Entity The value type.
*/
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::entity_type to_entity(const Entity value) ENTT_NOEXCEPT {
return entt_traits<Entity>::to_entity(value);
}
/**
* @copydoc entt_traits<Entity>::to_version
* @tparam Entity The value type.
*/
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::version_type to_version(const Entity value) ENTT_NOEXCEPT {
return entt_traits<Entity>::to_version(value);
}
/*! @brief Null object for all identifiers. */
struct null_t {
/**
* @brief Converts the null object to identifiers of any type.
* @tparam Entity Type of identifier.
* @return The null representation for the given type.
*/
template<typename Entity>
[[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
using entity_traits = entt_traits<Entity>;
return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
}
/**
* @brief Compares two null objects.
* @param other A null object.
* @return True in all cases.
*/
[[nodiscard]] constexpr bool operator==([[maybe_unused]] const null_t other) const ENTT_NOEXCEPT {
return true;
}
/**
* @brief Compares two null objects.
* @param other A null object.
* @return False in all cases.
*/
[[nodiscard]] constexpr bool operator!=([[maybe_unused]] const null_t other) const ENTT_NOEXCEPT {
return false;
}
/**
* @brief Compares a null object and an identifier of any type.
* @tparam Entity Type of identifier.
* @param entity Identifier with which to compare.
* @return False if the two elements differ, true otherwise.
*/
template<typename Entity>
[[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
using entity_traits = entt_traits<Entity>;
return entity_traits::to_entity(entity) == entity_traits::to_entity(*this);
}
/**
* @brief Compares a null object and an identifier of any type.
* @tparam Entity Type of identifier.
* @param entity Identifier with which to compare.
* @return True if the two elements differ, false otherwise.
*/
template<typename Entity>
[[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
return !(entity == *this);
}
};
/**
* @brief Compares a null object and an identifier of any type.
* @tparam Entity Type of identifier.
* @param entity Identifier with which to compare.
* @param other A null object yet to be converted.
* @return False if the two elements differ, true otherwise.
*/
template<typename Entity>
[[nodiscard]] constexpr bool operator==(const Entity entity, const null_t other) ENTT_NOEXCEPT {
return other.operator==(entity);
}
/**
* @brief Compares a null object and an identifier of any type.
* @tparam Entity Type of identifier.
* @param entity Identifier with which to compare.
* @param other A null object yet to be converted.
* @return True if the two elements differ, false otherwise.
*/
template<typename Entity>
[[nodiscard]] constexpr bool operator!=(const Entity entity, const null_t other) ENTT_NOEXCEPT {
return !(other == entity);
}
/*! @brief Tombstone object for all identifiers. */
struct tombstone_t {
/**
* @brief Converts the tombstone object to identifiers of any type.
* @tparam Entity Type of identifier.
* @return The tombstone representation for the given type.
*/
template<typename Entity>
[[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
using entity_traits = entt_traits<Entity>;
return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
}
/**
* @brief Compares two tombstone objects.
* @param other A tombstone object.
* @return True in all cases.
*/
[[nodiscard]] constexpr bool operator==([[maybe_unused]] const tombstone_t other) const ENTT_NOEXCEPT {
return true;
}
/**
* @brief Compares two tombstone objects.
* @param other A tombstone object.
* @return False in all cases.
*/
[[nodiscard]] constexpr bool operator!=([[maybe_unused]] const tombstone_t other) const ENTT_NOEXCEPT {
return false;
}
/**
* @brief Compares a tombstone object and an identifier of any type.
* @tparam Entity Type of identifier.
* @param entity Identifier with which to compare.
* @return False if the two elements differ, true otherwise.
*/
template<typename Entity>
[[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
using entity_traits = entt_traits<Entity>;
return entity_traits::to_version(entity) == entity_traits::to_version(*this);
}
/**
* @brief Compares a tombstone object and an identifier of any type.
* @tparam Entity Type of identifier.
* @param entity Identifier with which to compare.
* @return True if the two elements differ, false otherwise.
*/
template<typename Entity>
[[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
return !(entity == *this);
}
};
/**
* @brief Compares a tombstone object and an identifier of any type.
* @tparam Entity Type of identifier.
* @param entity Identifier with which to compare.
* @param other A tombstone object yet to be converted.
* @return False if the two elements differ, true otherwise.
*/
template<typename Entity>
[[nodiscard]] constexpr bool operator==(const Entity entity, const tombstone_t other) ENTT_NOEXCEPT {
return other.operator==(entity);
}
/**
* @brief Compares a tombstone object and an identifier of any type.
* @tparam Entity Type of identifier.
* @param entity Identifier with which to compare.
* @param other A tombstone object yet to be converted.
* @return True if the two elements differ, false otherwise.
*/
template<typename Entity>
[[nodiscard]] constexpr bool operator!=(const Entity entity, const tombstone_t other) ENTT_NOEXCEPT {
return !(other == entity);
}
/**
* @brief Compile-time constant for null entities.
*
* There exist implicit conversions from this variable to identifiers of any
* allowed type. Similarly, there exist comparision operators between the null
* entity and any other identifier.
*/
inline constexpr null_t null{};
/**
* @brief Compile-time constant for tombstone entities.
*
* There exist implicit conversions from this variable to identifiers of any
* allowed type. Similarly, there exist comparision operators between the
* tombstone entity and any other identifier.
*/
inline constexpr tombstone_t tombstone{};
} // namespace entt
#endif

117
src/entt/entity/fwd.hpp Normal file
View File

@@ -0,0 +1,117 @@
#ifndef ENTT_ENTITY_FWD_HPP
#define ENTT_ENTITY_FWD_HPP
#include <memory>
#include "../core/fwd.hpp"
#include "utility.hpp"
namespace entt {
template<typename Entity, typename = std::allocator<Entity>>
class basic_sparse_set;
template<typename, typename Type, typename = std::allocator<Type>, typename = void>
class basic_storage;
template<typename>
class basic_registry;
template<typename, typename, typename, typename = void>
class basic_view;
template<typename>
class basic_runtime_view;
template<typename, typename, typename, typename>
class basic_group;
template<typename>
class basic_observer;
template<typename>
class basic_organizer;
template<typename, typename...>
struct basic_handle;
template<typename>
class basic_snapshot;
template<typename>
class basic_snapshot_loader;
template<typename>
class basic_continuous_loader;
/*! @brief Default entity identifier. */
enum class entity : id_type {};
/*! @brief Alias declaration for the most common use case. */
using sparse_set = basic_sparse_set<entity>;
/**
* @brief Alias declaration for the most common use case.
* @tparam Args Other template parameters.
*/
template<typename... Args>
using storage = basic_storage<entity, Args...>;
/*! @brief Alias declaration for the most common use case. */
using registry = basic_registry<entity>;
/*! @brief Alias declaration for the most common use case. */
using observer = basic_observer<entity>;
/*! @brief Alias declaration for the most common use case. */
using organizer = basic_organizer<entity>;
/*! @brief Alias declaration for the most common use case. */
using handle = basic_handle<entity>;
/*! @brief Alias declaration for the most common use case. */
using const_handle = basic_handle<const entity>;
/**
* @brief Alias declaration for the most common use case.
* @tparam Args Other template parameters.
*/
template<typename... Args>
using handle_view = basic_handle<entity, Args...>;
/**
* @brief Alias declaration for the most common use case.
* @tparam Args Other template parameters.
*/
template<typename... Args>
using const_handle_view = basic_handle<const entity, Args...>;
/*! @brief Alias declaration for the most common use case. */
using snapshot = basic_snapshot<entity>;
/*! @brief Alias declaration for the most common use case. */
using snapshot_loader = basic_snapshot_loader<entity>;
/*! @brief Alias declaration for the most common use case. */
using continuous_loader = basic_continuous_loader<entity>;
/**
* @brief Alias declaration for the most common use case.
* @tparam Get Types of components iterated by the view.
* @tparam Exclude Types of components used to filter the view.
*/
template<typename Get, typename Exclude = exclude_t<>>
using view = basic_view<entity, Get, Exclude>;
/*! @brief Alias declaration for the most common use case. */
using runtime_view = basic_runtime_view<entity>;
/**
* @brief Alias declaration for the most common use case.
* @tparam Args Other template parameters.
*/
template<typename... Args>
using group = basic_group<entity, Args...>;
} // namespace entt
#endif

904
src/entt/entity/group.hpp Normal file
View File

@@ -0,0 +1,904 @@
#ifndef ENTT_ENTITY_GROUP_HPP
#define ENTT_ENTITY_GROUP_HPP
#include <tuple>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "../core/iterator.hpp"
#include "../core/type_traits.hpp"
#include "component.hpp"
#include "entity.hpp"
#include "fwd.hpp"
#include "sparse_set.hpp"
#include "storage.hpp"
#include "utility.hpp"
namespace entt {
/**
* @brief Group.
*
* Primary template isn't defined on purpose. All the specializations give a
* compile-time error, but for a few reasonable cases.
*/
template<typename, typename, typename, typename>
class basic_group;
/**
* @brief Non-owning group.
*
* A non-owning group returns all entities and only the entities that have at
* least the given components. Moreover, it's guaranteed that the entity list
* is tightly packed in memory for fast iterations.
*
* @b Important
*
* Iterators aren't invalidated if:
*
* * New instances of the given components are created and assigned to entities.
* * The entity currently pointed is modified (as an example, if one of the
* given components is removed from the entity to which the iterator points).
* * The entity currently pointed is destroyed.
*
* In all other cases, modifying the pools iterated by the group in any way
* invalidates all the iterators and using them results in undefined behavior.
*
* @note
* Groups share references to the underlying data structures of the registry
* that generated them. Therefore any change to the entities and to the
* components made by means of the registry are immediately reflected by all the
* groups.<br/>
* Moreover, sorting a non-owning group affects all the instances of the same
* group (it means that users don't have to call `sort` on each instance to sort
* all of them because they _share_ entities and components).
*
* @warning
* Lifetime of a group must not overcome that of the registry that generated it.
* In any other case, attempting to use a group results in undefined behavior.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Get Type of components observed by the group.
* @tparam Exclude Types of components used to filter the group.
*/
template<typename Entity, typename... Get, typename... Exclude>
class basic_group<Entity, owned_t<>, get_t<Get...>, exclude_t<Exclude...>> final {
/*! @brief A registry is allowed to create groups. */
friend class basic_registry<Entity>;
template<typename Comp>
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
using basic_common_type = std::common_type_t<typename storage_type<Get>::base_type...>;
struct extended_group_iterator final {
using difference_type = std::ptrdiff_t;
using value_type = decltype(std::tuple_cat(std::tuple<Entity>{}, std::declval<basic_group>().get({})));
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using iterator_category = std::input_iterator_tag;
extended_group_iterator() = default;
extended_group_iterator(typename basic_common_type::iterator from, const std::tuple<storage_type<Get> *...> &args) ENTT_NOEXCEPT
: it{from},
pools{args} {}
extended_group_iterator &operator++() ENTT_NOEXCEPT {
return ++it, *this;
}
extended_group_iterator operator++(int) ENTT_NOEXCEPT {
extended_group_iterator orig = *this;
return ++(*this), orig;
}
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
const auto entt = *it;
return std::tuple_cat(std::make_tuple(entt), std::get<storage_type<Get> *>(pools)->get_as_tuple(entt)...);
}
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
return operator*();
}
[[nodiscard]] bool operator==(const extended_group_iterator &other) const ENTT_NOEXCEPT {
return other.it == it;
}
[[nodiscard]] bool operator!=(const extended_group_iterator &other) const ENTT_NOEXCEPT {
return !(*this == other);
}
private:
typename basic_common_type::iterator it;
std::tuple<storage_type<Get> *...> pools;
};
basic_group(basic_common_type &ref, storage_type<Get> &...gpool) ENTT_NOEXCEPT
: handler{&ref},
pools{&gpool...} {}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Common type among all storage types. */
using base_type = basic_common_type;
/*! @brief Random access iterator type. */
using iterator = typename base_type::iterator;
/*! @brief Reversed iterator type. */
using reverse_iterator = typename base_type::reverse_iterator;
/*! @brief Iterable group type. */
using iterable = iterable_adaptor<extended_group_iterator>;
/*! @brief Default constructor to use to create empty, invalid groups. */
basic_group() ENTT_NOEXCEPT
: handler{} {}
/**
* @brief Returns a const reference to the underlying handler.
* @return A const reference to the underlying handler.
*/
const base_type &handle() const ENTT_NOEXCEPT {
return *handler;
}
/**
* @brief Returns the storage for a given component type.
* @tparam Comp Type of component of which to return the storage.
* @return The storage for the given component type.
*/
template<typename Comp>
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
return *std::get<storage_type<Comp> *>(pools);
}
/**
* @brief Returns the storage for a given component type.
* @tparam Comp Index of component of which to return the storage.
* @return The storage for the given component type.
*/
template<std::size_t Comp>
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
return *std::get<Comp>(pools);
}
/**
* @brief Returns the number of entities that have the given components.
* @return Number of entities that have the given components.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return *this ? handler->size() : size_type{};
}
/**
* @brief Returns the number of elements that a group has currently
* allocated space for.
* @return Capacity of the group.
*/
[[nodiscard]] size_type capacity() const ENTT_NOEXCEPT {
return *this ? handler->capacity() : size_type{};
}
/*! @brief Requests the removal of unused capacity. */
void shrink_to_fit() {
if(*this) {
handler->shrink_to_fit();
}
}
/**
* @brief Checks whether a group is empty.
* @return True if the group is empty, false otherwise.
*/
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
return !*this || handler->empty();
}
/**
* @brief Returns an iterator to the first entity of the group.
*
* The returned iterator points to the first entity of the group. If the
* group is empty, the returned iterator will be equal to `end()`.
*
* @return An iterator to the first entity of the group.
*/
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
return *this ? handler->begin() : iterator{};
}
/**
* @brief Returns an iterator that is past the last entity of the group.
*
* The returned iterator points to the entity following the last entity of
* the group. Attempting to dereference the returned iterator results in
* undefined behavior.
*
* @return An iterator to the entity following the last entity of the
* group.
*/
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return *this ? handler->end() : iterator{};
}
/**
* @brief Returns an iterator to the first entity of the reversed group.
*
* The returned iterator points to the first entity of the reversed group.
* If the group is empty, the returned iterator will be equal to `rend()`.
*
* @return An iterator to the first entity of the reversed group.
*/
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
return *this ? handler->rbegin() : reverse_iterator{};
}
/**
* @brief Returns an iterator that is past the last entity of the reversed
* group.
*
* The returned iterator points to the entity following the last entity of
* the reversed group. Attempting to dereference the returned iterator
* results in undefined behavior.
*
* @return An iterator to the entity following the last entity of the
* reversed group.
*/
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
return *this ? handler->rend() : reverse_iterator{};
}
/**
* @brief Returns the first entity of the group, if any.
* @return The first entity of the group if one exists, the null entity
* otherwise.
*/
[[nodiscard]] entity_type front() const {
const auto it = begin();
return it != end() ? *it : null;
}
/**
* @brief Returns the last entity of the group, if any.
* @return The last entity of the group if one exists, the null entity
* otherwise.
*/
[[nodiscard]] entity_type back() const {
const auto it = rbegin();
return it != rend() ? *it : null;
}
/**
* @brief Finds an entity.
* @param entt A valid identifier.
* @return An iterator to the given entity if it's found, past the end
* iterator otherwise.
*/
[[nodiscard]] iterator find(const entity_type entt) const {
const auto it = *this ? handler->find(entt) : iterator{};
return it != end() && *it == entt ? it : end();
}
/**
* @brief Returns the identifier that occupies the given position.
* @param pos Position of the element to return.
* @return The identifier that occupies the given position.
*/
[[nodiscard]] entity_type operator[](const size_type pos) const {
return begin()[pos];
}
/**
* @brief Checks if a group is properly initialized.
* @return True if the group is properly initialized, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return handler != nullptr;
}
/**
* @brief Checks if a group contains an entity.
* @param entt A valid identifier.
* @return True if the group contains the given entity, false otherwise.
*/
[[nodiscard]] bool contains(const entity_type entt) const {
return *this && handler->contains(entt);
}
/**
* @brief Returns the components assigned to the given entity.
*
* Prefer this function instead of `registry::get` during iterations. It has
* far better performance than its counterpart.
*
* @warning
* Attempting to use an invalid component type results in a compilation
* error. Attempting to use an entity that doesn't belong to the group
* results in undefined behavior.
*
* @tparam Comp Types of components to get.
* @param entt A valid identifier.
* @return The components assigned to the entity.
*/
template<typename... Comp>
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
ENTT_ASSERT(contains(entt), "Group does not contain entity");
if constexpr(sizeof...(Comp) == 0) {
return std::tuple_cat(std::get<storage_type<Get> *>(pools)->get_as_tuple(entt)...);
} else if constexpr(sizeof...(Comp) == 1) {
return (std::get<storage_type<Comp> *>(pools)->get(entt), ...);
} else {
return std::tuple_cat(std::get<storage_type<Comp> *>(pools)->get_as_tuple(entt)...);
}
}
/**
* @brief Iterates entities and components and applies the given function
* object to them.
*
* The function object is invoked for each entity. It is provided with the
* entity itself and a set of references to non-empty components. The
* _constness_ of the components is as requested.<br/>
* The signature of the function must be equivalent to one of the following
* forms:
*
* @code{.cpp}
* void(const entity_type, Type &...);
* void(Type &...);
* @endcode
*
* @note
* Empty types aren't explicitly instantiated and therefore they are never
* returned during iterations.
*
* @tparam Func Type of the function object to invoke.
* @param func A valid function object.
*/
template<typename Func>
void each(Func func) const {
for(const auto entt: *this) {
if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_group>().get({})))>) {
std::apply(func, std::tuple_cat(std::make_tuple(entt), get(entt)));
} else {
std::apply(func, get(entt));
}
}
}
/**
* @brief Returns an iterable object to use to _visit_ a group.
*
* The iterable object returns tuples that contain the current entity and a
* set of references to its non-empty components. The _constness_ of the
* components is as requested.
*
* @note
* Empty types aren't explicitly instantiated and therefore they are never
* returned during iterations.
*
* @return An iterable object to use to _visit_ the group.
*/
[[nodiscard]] iterable each() const ENTT_NOEXCEPT {
return handler ? iterable{extended_group_iterator{handler->begin(), pools}, extended_group_iterator{handler->end(), pools}}
: iterable{extended_group_iterator{{}, pools}, extended_group_iterator{{}, pools}};
}
/**
* @brief Sort a group according to the given comparison function.
*
* Sort the group so that iterating it with a couple of iterators returns
* entities and components in the expected order. See `begin` and `end` for
* more details.
*
* The comparison function object must return `true` if the first element
* is _less_ than the second one, `false` otherwise. The signature of the
* comparison function should be equivalent to one of the following:
*
* @code{.cpp}
* bool(std::tuple<Component &...>, std::tuple<Component &...>);
* bool(const Component &..., const Component &...);
* bool(const Entity, const Entity);
* @endcode
*
* Where `Component` are such that they are iterated by the group.<br/>
* Moreover, the comparison function object shall induce a
* _strict weak ordering_ on the values.
*
* The sort function object must offer a member function template
* `operator()` that accepts three arguments:
*
* * An iterator to the first element of the range to sort.
* * An iterator past the last element of the range to sort.
* * A comparison function to use to compare the elements.
*
* @tparam Comp Optional types of components to compare.
* @tparam Compare Type of comparison function object.
* @tparam Sort Type of sort function object.
* @tparam Args Types of arguments to forward to the sort function object.
* @param compare A valid comparison function object.
* @param algo A valid sort function object.
* @param args Arguments to forward to the sort function object, if any.
*/
template<typename... Comp, typename Compare, typename Sort = std_sort, typename... Args>
void sort(Compare compare, Sort algo = Sort{}, Args &&...args) {
if(*this) {
if constexpr(sizeof...(Comp) == 0) {
static_assert(std::is_invocable_v<Compare, const entity_type, const entity_type>, "Invalid comparison function");
handler->sort(std::move(compare), std::move(algo), std::forward<Args>(args)...);
} else {
auto comp = [this, &compare](const entity_type lhs, const entity_type rhs) {
if constexpr(sizeof...(Comp) == 1) {
return compare((std::get<storage_type<Comp> *>(pools)->get(lhs), ...), (std::get<storage_type<Comp> *>(pools)->get(rhs), ...));
} else {
return compare(std::forward_as_tuple(std::get<storage_type<Comp> *>(pools)->get(lhs)...), std::forward_as_tuple(std::get<storage_type<Comp> *>(pools)->get(rhs)...));
}
};
handler->sort(std::move(comp), std::move(algo), std::forward<Args>(args)...);
}
}
}
/**
* @brief Sort the shared pool of entities according to the given component.
*
* Non-owning groups of the same type share with the registry a pool of
* entities with its own order that doesn't depend on the order of any pool
* of components. Users can order the underlying data structure so that it
* respects the order of the pool of the given component.
*
* @note
* The shared pool of entities and thus its order is affected by the changes
* to each and every pool that it tracks. Therefore changes to those pools
* can quickly ruin the order imposed to the pool of entities shared between
* the non-owning groups.
*
* @tparam Comp Type of component to use to impose the order.
*/
template<typename Comp>
void sort() const {
if(*this) {
handler->respect(*std::get<storage_type<Comp> *>(pools));
}
}
private:
base_type *const handler;
const std::tuple<storage_type<Get> *...> pools;
};
/**
* @brief Owning group.
*
* Owning groups return all entities and only the entities that have at least
* the given components. Moreover:
*
* * It's guaranteed that the entity list is tightly packed in memory for fast
* iterations.
* * It's guaranteed that the lists of owned components are tightly packed in
* memory for even faster iterations and to allow direct access.
* * They stay true to the order of the owned components and all instances have
* the same order in memory.
*
* The more types of components are owned by a group, the faster it is to
* iterate them.
*
* @b Important
*
* Iterators aren't invalidated if:
*
* * New instances of the given components are created and assigned to entities.
* * The entity currently pointed is modified (as an example, if one of the
* given components is removed from the entity to which the iterator points).
* * The entity currently pointed is destroyed.
*
* In all other cases, modifying the pools iterated by the group in any way
* invalidates all the iterators and using them results in undefined behavior.
*
* @note
* Groups share references to the underlying data structures of the registry
* that generated them. Therefore any change to the entities and to the
* components made by means of the registry are immediately reflected by all the
* groups.
* Moreover, sorting an owning group affects all the instance of the same group
* (it means that users don't have to call `sort` on each instance to sort all
* of them because they share the underlying data structure).
*
* @warning
* Lifetime of a group must not overcome that of the registry that generated it.
* In any other case, attempting to use a group results in undefined behavior.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Owned Types of components owned by the group.
* @tparam Get Types of components observed by the group.
* @tparam Exclude Types of components used to filter the group.
*/
template<typename Entity, typename... Owned, typename... Get, typename... Exclude>
class basic_group<Entity, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> final {
/*! @brief A registry is allowed to create groups. */
friend class basic_registry<Entity>;
template<typename Comp>
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
using basic_common_type = std::common_type_t<typename storage_type<Owned>::base_type..., typename storage_type<Get>::base_type...>;
template<typename>
struct extended_group_iterator;
template<typename... OIt>
struct extended_group_iterator<type_list<OIt...>> final {
using difference_type = std::ptrdiff_t;
using value_type = decltype(std::tuple_cat(std::tuple<Entity>{}, std::declval<basic_group>().get({})));
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using iterator_category = std::input_iterator_tag;
extended_group_iterator() = default;
template<typename... Other>
extended_group_iterator(typename basic_common_type::iterator from, const std::tuple<Other...> &other, const std::tuple<storage_type<Get> *...> &cpools) ENTT_NOEXCEPT
: it{from},
owned{std::get<OIt>(other)...},
get{cpools} {}
extended_group_iterator &operator++() ENTT_NOEXCEPT {
return ++it, (++std::get<OIt>(owned), ...), *this;
}
extended_group_iterator operator++(int) ENTT_NOEXCEPT {
extended_group_iterator orig = *this;
return ++(*this), orig;
}
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
return std::tuple_cat(
std::make_tuple(*it),
std::forward_as_tuple(*std::get<OIt>(owned)...),
std::get<storage_type<Get> *>(get)->get_as_tuple(*it)...);
}
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
return operator*();
}
[[nodiscard]] bool operator==(const extended_group_iterator &other) const ENTT_NOEXCEPT {
return other.it == it;
}
[[nodiscard]] bool operator!=(const extended_group_iterator &other) const ENTT_NOEXCEPT {
return !(*this == other);
}
private:
typename basic_common_type::iterator it;
std::tuple<OIt...> owned;
std::tuple<storage_type<Get> *...> get;
};
basic_group(const std::size_t &extent, storage_type<Owned> &...opool, storage_type<Get> &...gpool) ENTT_NOEXCEPT
: pools{&opool..., &gpool...},
length{&extent} {}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Common type among all storage types. */
using base_type = basic_common_type;
/*! @brief Random access iterator type. */
using iterator = typename base_type::iterator;
/*! @brief Reversed iterator type. */
using reverse_iterator = typename base_type::reverse_iterator;
/*! @brief Iterable group type. */
using iterable = iterable_adaptor<extended_group_iterator<type_list_cat_t<std::conditional_t<ignore_as_empty_v<std::remove_const_t<Owned>>, type_list<>, type_list<decltype(std::declval<storage_type<Owned>>().end())>>...>>>;
/*! @brief Default constructor to use to create empty, invalid groups. */
basic_group() ENTT_NOEXCEPT
: length{} {}
/**
* @brief Returns the storage for a given component type.
* @tparam Comp Type of component of which to return the storage.
* @return The storage for the given component type.
*/
template<typename Comp>
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
return *std::get<storage_type<Comp> *>(pools);
}
/**
* @brief Returns the storage for a given component type.
* @tparam Comp Index of component of which to return the storage.
* @return The storage for the given component type.
*/
template<std::size_t Comp>
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
return *std::get<Comp>(pools);
}
/**
* @brief Returns the number of entities that have the given components.
* @return Number of entities that have the given components.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return *this ? *length : size_type{};
}
/**
* @brief Checks whether a group is empty.
* @return True if the group is empty, false otherwise.
*/
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
return !*this || !*length;
}
/**
* @brief Returns an iterator to the first entity of the group.
*
* The returned iterator points to the first entity of the group. If the
* group is empty, the returned iterator will be equal to `end()`.
*
* @return An iterator to the first entity of the group.
*/
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
return *this ? (std::get<0>(pools)->base_type::end() - *length) : iterator{};
}
/**
* @brief Returns an iterator that is past the last entity of the group.
*
* The returned iterator points to the entity following the last entity of
* the group. Attempting to dereference the returned iterator results in
* undefined behavior.
*
* @return An iterator to the entity following the last entity of the
* group.
*/
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return *this ? std::get<0>(pools)->base_type::end() : iterator{};
}
/**
* @brief Returns an iterator to the first entity of the reversed group.
*
* The returned iterator points to the first entity of the reversed group.
* If the group is empty, the returned iterator will be equal to `rend()`.
*
* @return An iterator to the first entity of the reversed group.
*/
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
return *this ? std::get<0>(pools)->base_type::rbegin() : reverse_iterator{};
}
/**
* @brief Returns an iterator that is past the last entity of the reversed
* group.
*
* The returned iterator points to the entity following the last entity of
* the reversed group. Attempting to dereference the returned iterator
* results in undefined behavior.
*
* @return An iterator to the entity following the last entity of the
* reversed group.
*/
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
return *this ? (std::get<0>(pools)->base_type::rbegin() + *length) : reverse_iterator{};
}
/**
* @brief Returns the first entity of the group, if any.
* @return The first entity of the group if one exists, the null entity
* otherwise.
*/
[[nodiscard]] entity_type front() const {
const auto it = begin();
return it != end() ? *it : null;
}
/**
* @brief Returns the last entity of the group, if any.
* @return The last entity of the group if one exists, the null entity
* otherwise.
*/
[[nodiscard]] entity_type back() const {
const auto it = rbegin();
return it != rend() ? *it : null;
}
/**
* @brief Finds an entity.
* @param entt A valid identifier.
* @return An iterator to the given entity if it's found, past the end
* iterator otherwise.
*/
[[nodiscard]] iterator find(const entity_type entt) const {
const auto it = *this ? std::get<0>(pools)->find(entt) : iterator{};
return it != end() && it >= begin() && *it == entt ? it : end();
}
/**
* @brief Returns the identifier that occupies the given position.
* @param pos Position of the element to return.
* @return The identifier that occupies the given position.
*/
[[nodiscard]] entity_type operator[](const size_type pos) const {
return begin()[pos];
}
/**
* @brief Checks if a group is properly initialized.
* @return True if the group is properly initialized, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return length != nullptr;
}
/**
* @brief Checks if a group contains an entity.
* @param entt A valid identifier.
* @return True if the group contains the given entity, false otherwise.
*/
[[nodiscard]] bool contains(const entity_type entt) const {
return *this && std::get<0>(pools)->contains(entt) && (std::get<0>(pools)->index(entt) < (*length));
}
/**
* @brief Returns the components assigned to the given entity.
*
* Prefer this function instead of `registry::get` during iterations. It has
* far better performance than its counterpart.
*
* @warning
* Attempting to use an invalid component type results in a compilation
* error. Attempting to use an entity that doesn't belong to the group
* results in undefined behavior.
*
* @tparam Comp Types of components to get.
* @param entt A valid identifier.
* @return The components assigned to the entity.
*/
template<typename... Comp>
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
ENTT_ASSERT(contains(entt), "Group does not contain entity");
if constexpr(sizeof...(Comp) == 0) {
return std::tuple_cat(std::get<storage_type<Owned> *>(pools)->get_as_tuple(entt)..., std::get<storage_type<Get> *>(pools)->get_as_tuple(entt)...);
} else if constexpr(sizeof...(Comp) == 1) {
return (std::get<storage_type<Comp> *>(pools)->get(entt), ...);
} else {
return std::tuple_cat(std::get<storage_type<Comp> *>(pools)->get_as_tuple(entt)...);
}
}
/**
* @brief Iterates entities and components and applies the given function
* object to them.
*
* The function object is invoked for each entity. It is provided with the
* entity itself and a set of references to non-empty components. The
* _constness_ of the components is as requested.<br/>
* The signature of the function must be equivalent to one of the following
* forms:
*
* @code{.cpp}
* void(const entity_type, Type &...);
* void(Type &...);
* @endcode
*
* @note
* Empty types aren't explicitly instantiated and therefore they are never
* returned during iterations.
*
* @tparam Func Type of the function object to invoke.
* @param func A valid function object.
*/
template<typename Func>
void each(Func func) const {
for(auto args: each()) {
if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_group>().get({})))>) {
std::apply(func, args);
} else {
std::apply([&func](auto, auto &&...less) { func(std::forward<decltype(less)>(less)...); }, args);
}
}
}
/**
* @brief Returns an iterable object to use to _visit_ a group.
*
* The iterable object returns tuples that contain the current entity and a
* set of references to its non-empty components. The _constness_ of the
* components is as requested.
*
* @note
* Empty types aren't explicitly instantiated and therefore they are never
* returned during iterations.
*
* @return An iterable object to use to _visit_ the group.
*/
[[nodiscard]] iterable each() const ENTT_NOEXCEPT {
using extended_iterator_type = typename iterable::iterator;
iterator last = length ? std::get<0>(pools)->basic_common_type::end() : iterator{};
auto from = extended_iterator_type{last - *length, std::make_tuple((std::get<storage_type<Owned> *>(pools)->end() - *length)...), std::make_tuple(std::get<storage_type<Get> *>(pools)...)};
auto to = extended_iterator_type{last, std::make_tuple((std::get<storage_type<Owned> *>(pools)->end())...), std::make_tuple(std::get<storage_type<Get> *>(pools)...)};
return {std::move(from), std::move(to)};
}
/**
* @brief Sort a group according to the given comparison function.
*
* Sort the group so that iterating it with a couple of iterators returns
* entities and components in the expected order. See `begin` and `end` for
* more details.
*
* The comparison function object must return `true` if the first element
* is _less_ than the second one, `false` otherwise. The signature of the
* comparison function should be equivalent to one of the following:
*
* @code{.cpp}
* bool(std::tuple<Component &...>, std::tuple<Component &...>);
* bool(const Component &, const Component &);
* bool(const Entity, const Entity);
* @endcode
*
* Where `Component` are either owned types or not but still such that they
* are iterated by the group.<br/>
* Moreover, the comparison function object shall induce a
* _strict weak ordering_ on the values.
*
* The sort function object must offer a member function template
* `operator()` that accepts three arguments:
*
* * An iterator to the first element of the range to sort.
* * An iterator past the last element of the range to sort.
* * A comparison function to use to compare the elements.
*
* @tparam Comp Optional types of components to compare.
* @tparam Compare Type of comparison function object.
* @tparam Sort Type of sort function object.
* @tparam Args Types of arguments to forward to the sort function object.
* @param compare A valid comparison function object.
* @param algo A valid sort function object.
* @param args Arguments to forward to the sort function object, if any.
*/
template<typename... Comp, typename Compare, typename Sort = std_sort, typename... Args>
void sort(Compare compare, Sort algo = Sort{}, Args &&...args) const {
auto *cpool = std::get<0>(pools);
if constexpr(sizeof...(Comp) == 0) {
static_assert(std::is_invocable_v<Compare, const entity_type, const entity_type>, "Invalid comparison function");
cpool->sort_n(*length, std::move(compare), std::move(algo), std::forward<Args>(args)...);
} else {
auto comp = [this, &compare](const entity_type lhs, const entity_type rhs) {
if constexpr(sizeof...(Comp) == 1) {
return compare((std::get<storage_type<Comp> *>(pools)->get(lhs), ...), (std::get<storage_type<Comp> *>(pools)->get(rhs), ...));
} else {
return compare(std::forward_as_tuple(std::get<storage_type<Comp> *>(pools)->get(lhs)...), std::forward_as_tuple(std::get<storage_type<Comp> *>(pools)->get(rhs)...));
}
};
cpool->sort_n(*length, std::move(comp), std::move(algo), std::forward<Args>(args)...);
}
[this](auto *head, auto *...other) {
for(auto next = *length; next; --next) {
const auto pos = next - 1;
[[maybe_unused]] const auto entt = head->data()[pos];
(other->swap_elements(other->data()[pos], entt), ...);
}
}(std::get<storage_type<Owned> *>(pools)...);
}
private:
const std::tuple<storage_type<Owned> *..., storage_type<Get> *...> pools;
const size_type *const length;
};
} // namespace entt
#endif

340
src/entt/entity/handle.hpp Normal file
View File

@@ -0,0 +1,340 @@
#ifndef ENTT_ENTITY_HANDLE_HPP
#define ENTT_ENTITY_HANDLE_HPP
#include <tuple>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "../core/type_traits.hpp"
#include "fwd.hpp"
#include "registry.hpp"
namespace entt {
/**
* @brief Non-owning handle to an entity.
*
* Tiny wrapper around a registry and an entity.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Type Types to which to restrict the scope of a handle.
*/
template<typename Entity, typename... Type>
struct basic_handle {
/*! @brief Type of registry accepted by the handle. */
using registry_type = constness_as_t<basic_registry<std::remove_const_t<Entity>>, Entity>;
/*! @brief Underlying entity identifier. */
using entity_type = typename registry_type::entity_type;
/*! @brief Underlying version type. */
using version_type = typename registry_type::version_type;
/*! @brief Unsigned integer type. */
using size_type = typename registry_type::size_type;
/*! @brief Constructs an invalid handle. */
basic_handle() ENTT_NOEXCEPT
: reg{},
entt{null} {}
/**
* @brief Constructs a handle from a given registry and entity.
* @param ref An instance of the registry class.
* @param value A valid identifier.
*/
basic_handle(registry_type &ref, entity_type value) ENTT_NOEXCEPT
: reg{&ref},
entt{value} {}
/**
* @brief Constructs a const handle from a non-const one.
* @tparam Other A valid entity type (see entt_traits for more details).
* @tparam Args Scope of the handle to construct.
* @return A const handle referring to the same registry and the same
* entity.
*/
template<typename Other, typename... Args>
operator basic_handle<Other, Args...>() const ENTT_NOEXCEPT {
static_assert(std::is_same_v<Other, Entity> || std::is_same_v<std::remove_const_t<Other>, Entity>, "Invalid conversion between different handles");
static_assert((sizeof...(Type) == 0 || ((sizeof...(Args) != 0 && sizeof...(Args) <= sizeof...(Type)) && ... && (type_list_contains_v<type_list<Type...>, Args>))), "Invalid conversion between different handles");
return reg ? basic_handle<Other, Args...>{*reg, entt} : basic_handle<Other, Args...>{};
}
/**
* @brief Converts a handle to its underlying entity.
* @return The contained identifier.
*/
[[nodiscard]] operator entity_type() const ENTT_NOEXCEPT {
return entity();
}
/**
* @brief Checks if a handle refers to non-null registry pointer and entity.
* @return True if the handle refers to non-null registry and entity, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return reg && reg->valid(entt);
}
/**
* @brief Checks if a handle refers to a valid entity or not.
* @return True if the handle refers to a valid entity, false otherwise.
*/
[[nodiscard]] bool valid() const {
return reg->valid(entt);
}
/**
* @brief Returns a pointer to the underlying registry, if any.
* @return A pointer to the underlying registry, if any.
*/
[[nodiscard]] registry_type *registry() const ENTT_NOEXCEPT {
return reg;
}
/**
* @brief Returns the entity associated with a handle.
* @return The entity associated with the handle.
*/
[[nodiscard]] entity_type entity() const ENTT_NOEXCEPT {
return entt;
}
/**
* @brief Destroys the entity associated with a handle.
* @sa basic_registry::destroy
*/
void destroy() {
reg->destroy(entt);
}
/**
* @brief Destroys the entity associated with a handle.
* @sa basic_registry::destroy
* @param version A desired version upon destruction.
*/
void destroy(const version_type version) {
reg->destroy(entt, version);
}
/**
* @brief Assigns the given component to a handle.
* @sa basic_registry::emplace
* @tparam Component Type of component to create.
* @tparam Args Types of arguments to use to construct the component.
* @param args Parameters to use to initialize the component.
* @return A reference to the newly created component.
*/
template<typename Component, typename... Args>
decltype(auto) emplace(Args &&...args) const {
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
return reg->template emplace<Component>(entt, std::forward<Args>(args)...);
}
/**
* @brief Assigns or replaces the given component for a handle.
* @sa basic_registry::emplace_or_replace
* @tparam Component Type of component to assign or replace.
* @tparam Args Types of arguments to use to construct the component.
* @param args Parameters to use to initialize the component.
* @return A reference to the newly created component.
*/
template<typename Component, typename... Args>
decltype(auto) emplace_or_replace(Args &&...args) const {
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
return reg->template emplace_or_replace<Component>(entt, std::forward<Args>(args)...);
}
/**
* @brief Patches the given component for a handle.
* @sa basic_registry::patch
* @tparam Component Type of component to patch.
* @tparam Func Types of the function objects to invoke.
* @param func Valid function objects.
* @return A reference to the patched component.
*/
template<typename Component, typename... Func>
decltype(auto) patch(Func &&...func) const {
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
return reg->template patch<Component>(entt, std::forward<Func>(func)...);
}
/**
* @brief Replaces the given component for a handle.
* @sa basic_registry::replace
* @tparam Component Type of component to replace.
* @tparam Args Types of arguments to use to construct the component.
* @param args Parameters to use to initialize the component.
* @return A reference to the component being replaced.
*/
template<typename Component, typename... Args>
decltype(auto) replace(Args &&...args) const {
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
return reg->template replace<Component>(entt, std::forward<Args>(args)...);
}
/**
* @brief Removes the given components from a handle.
* @sa basic_registry::remove
* @tparam Component Types of components to remove.
* @return The number of components actually removed.
*/
template<typename... Component>
size_type remove() const {
static_assert(sizeof...(Type) == 0 || (type_list_contains_v<type_list<Type...>, Component> && ...), "Invalid type");
return reg->template remove<Component...>(entt);
}
/**
* @brief Erases the given components from a handle.
* @sa basic_registry::erase
* @tparam Component Types of components to erase.
*/
template<typename... Component>
void erase() const {
static_assert(sizeof...(Type) == 0 || (type_list_contains_v<type_list<Type...>, Component> && ...), "Invalid type");
reg->template erase<Component...>(entt);
}
/**
* @brief Checks if a handle has all the given components.
* @sa basic_registry::all_of
* @tparam Component Components for which to perform the check.
* @return True if the handle has all the components, false otherwise.
*/
template<typename... Component>
[[nodiscard]] decltype(auto) all_of() const {
return reg->template all_of<Component...>(entt);
}
/**
* @brief Checks if a handle has at least one of the given components.
* @sa basic_registry::any_of
* @tparam Component Components for which to perform the check.
* @return True if the handle has at least one of the given components,
* false otherwise.
*/
template<typename... Component>
[[nodiscard]] decltype(auto) any_of() const {
return reg->template any_of<Component...>(entt);
}
/**
* @brief Returns references to the given components for a handle.
* @sa basic_registry::get
* @tparam Component Types of components to get.
* @return References to the components owned by the handle.
*/
template<typename... Component>
[[nodiscard]] decltype(auto) get() const {
static_assert(sizeof...(Type) == 0 || (type_list_contains_v<type_list<Type...>, Component> && ...), "Invalid type");
return reg->template get<Component...>(entt);
}
/**
* @brief Returns a reference to the given component for a handle.
* @sa basic_registry::get_or_emplace
* @tparam Component Type of component to get.
* @tparam Args Types of arguments to use to construct the component.
* @param args Parameters to use to initialize the component.
* @return Reference to the component owned by the handle.
*/
template<typename Component, typename... Args>
[[nodiscard]] decltype(auto) get_or_emplace(Args &&...args) const {
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
return reg->template get_or_emplace<Component>(entt, std::forward<Args>(args)...);
}
/**
* @brief Returns pointers to the given components for a handle.
* @sa basic_registry::try_get
* @tparam Component Types of components to get.
* @return Pointers to the components owned by the handle.
*/
template<typename... Component>
[[nodiscard]] auto try_get() const {
static_assert(sizeof...(Type) == 0 || (type_list_contains_v<type_list<Type...>, Component> && ...), "Invalid type");
return reg->template try_get<Component...>(entt);
}
/**
* @brief Checks if a handle has components assigned.
* @return True if the handle has no components assigned, false otherwise.
*/
[[nodiscard]] bool orphan() const {
return reg->orphan(entt);
}
/**
* @brief Visits a handle and returns the pools for its components.
*
* The signature of the function should be equivalent to the following:
*
* @code{.cpp}
* void(id_type, const basic_sparse_set<entity_type> &);
* @endcode
*
* Returned pools are those that contain the entity associated with the
* handle.
*
* @tparam Func Type of the function object to invoke.
* @param func A valid function object.
*/
template<typename Func>
void visit(Func &&func) const {
for(auto [id, storage]: reg->storage()) {
if(storage.contains(entt)) {
func(id, storage);
}
}
}
private:
registry_type *reg;
entity_type entt;
};
/**
* @brief Compares two handles.
* @tparam Args Scope of the first handle.
* @tparam Other Scope of the second handle.
* @param lhs A valid handle.
* @param rhs A valid handle.
* @return True if both handles refer to the same registry and the same
* entity, false otherwise.
*/
template<typename... Args, typename... Other>
[[nodiscard]] bool operator==(const basic_handle<Args...> &lhs, const basic_handle<Other...> &rhs) ENTT_NOEXCEPT {
return lhs.registry() == rhs.registry() && lhs.entity() == rhs.entity();
}
/**
* @brief Compares two handles.
* @tparam Args Scope of the first handle.
* @tparam Other Scope of the second handle.
* @param lhs A valid handle.
* @param rhs A valid handle.
* @return False if both handles refer to the same registry and the same
* entity, true otherwise.
*/
template<typename... Args, typename... Other>
[[nodiscard]] bool operator!=(const basic_handle<Args...> &lhs, const basic_handle<Other...> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
/**
* @brief Deduction guide.
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
basic_handle(basic_registry<Entity> &, Entity) -> basic_handle<Entity>;
/**
* @brief Deduction guide.
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
basic_handle(const basic_registry<Entity> &, Entity) -> basic_handle<const Entity>;
} // namespace entt
#endif

156
src/entt/entity/helper.hpp Normal file
View File

@@ -0,0 +1,156 @@
#ifndef ENTT_ENTITY_HELPER_HPP
#define ENTT_ENTITY_HELPER_HPP
#include <type_traits>
#include "../config/config.h"
#include "../core/fwd.hpp"
#include "../core/type_traits.hpp"
#include "../signal/delegate.hpp"
#include "fwd.hpp"
#include "registry.hpp"
namespace entt {
/**
* @brief Converts a registry to a view.
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
struct as_view {
/*! @brief Underlying entity identifier. */
using entity_type = std::remove_const_t<Entity>;
/*! @brief Type of registry to convert. */
using registry_type = constness_as_t<basic_registry<entity_type>, Entity>;
/**
* @brief Constructs a converter for a given registry.
* @param source A valid reference to a registry.
*/
as_view(registry_type &source) ENTT_NOEXCEPT: reg{source} {}
/**
* @brief Conversion function from a registry to a view.
* @tparam Exclude Types of components used to filter the view.
* @tparam Component Type of components used to construct the view.
* @return A newly created view.
*/
template<typename Exclude, typename... Component>
operator basic_view<entity_type, get_t<Component...>, Exclude>() const {
return reg.template view<Component...>(Exclude{});
}
private:
registry_type &reg;
};
/**
* @brief Deduction guide.
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
as_view(basic_registry<Entity> &) -> as_view<Entity>;
/**
* @brief Deduction guide.
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
as_view(const basic_registry<Entity> &) -> as_view<const Entity>;
/**
* @brief Converts a registry to a group.
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
struct as_group {
/*! @brief Underlying entity identifier. */
using entity_type = std::remove_const_t<Entity>;
/*! @brief Type of registry to convert. */
using registry_type = constness_as_t<basic_registry<entity_type>, Entity>;
/**
* @brief Constructs a converter for a given registry.
* @param source A valid reference to a registry.
*/
as_group(registry_type &source) ENTT_NOEXCEPT: reg{source} {}
/**
* @brief Conversion function from a registry to a group.
* @tparam Get Types of components observed by the group.
* @tparam Exclude Types of components used to filter the group.
* @tparam Owned Types of components owned by the group.
* @return A newly created group.
*/
template<typename Get, typename Exclude, typename... Owned>
operator basic_group<entity_type, owned_t<Owned...>, Get, Exclude>() const {
if constexpr(std::is_const_v<registry_type>) {
return reg.template group_if_exists<Owned...>(Get{}, Exclude{});
} else {
return reg.template group<Owned...>(Get{}, Exclude{});
}
}
private:
registry_type &reg;
};
/**
* @brief Deduction guide.
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
as_group(basic_registry<Entity> &) -> as_group<Entity>;
/**
* @brief Deduction guide.
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
as_group(const basic_registry<Entity> &) -> as_group<const Entity>;
/**
* @brief Helper to create a listener that directly invokes a member function.
* @tparam Member Member function to invoke on a component of the given type.
* @tparam Entity A valid entity type (see entt_traits for more details).
* @param reg A registry that contains the given entity and its components.
* @param entt Entity from which to get the component.
*/
template<auto Member, typename Entity = entity>
void invoke(basic_registry<Entity> &reg, const Entity entt) {
static_assert(std::is_member_function_pointer_v<decltype(Member)>, "Invalid pointer to non-static member function");
delegate<void(basic_registry<Entity> &, const Entity)> func;
func.template connect<Member>(reg.template get<member_class_t<decltype(Member)>>(entt));
func(reg, entt);
}
/**
* @brief Returns the entity associated with a given component.
*
* @warning
* Currently, this function only works correctly with the default pool as it
* makes assumptions about how the components are laid out.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Component Type of component.
* @param reg A registry that contains the given entity and its components.
* @param instance A valid component instance.
* @return The entity associated with the given component.
*/
template<typename Entity, typename Component>
Entity to_entity(const basic_registry<Entity> &reg, const Component &instance) {
const auto &storage = reg.template storage<Component>();
const typename basic_registry<Entity>::base_type &base = storage;
const auto *addr = std::addressof(instance);
for(auto it = base.rbegin(), last = base.rend(); it < last; it += ENTT_PACKED_PAGE) {
if(const auto dist = (addr - std::addressof(storage.get(*it))); dist >= 0 && dist < ENTT_PACKED_PAGE) {
return *(it + dist);
}
}
return null;
}
} // namespace entt
#endif

View File

@@ -0,0 +1,436 @@
#ifndef ENTT_ENTITY_OBSERVER_HPP
#define ENTT_ENTITY_OBSERVER_HPP
#include <cstddef>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "../core/type_traits.hpp"
#include "../signal/delegate.hpp"
#include "entity.hpp"
#include "fwd.hpp"
#include "registry.hpp"
#include "storage.hpp"
#include "utility.hpp"
namespace entt {
/*! @brief Grouping matcher. */
template<typename...>
struct matcher {};
/**
* @brief Collector.
*
* Primary template isn't defined on purpose. All the specializations give a
* compile-time error, but for a few reasonable cases.
*/
template<typename...>
struct basic_collector;
/**
* @brief Collector.
*
* A collector contains a set of rules (literally, matchers) to use to track
* entities.<br/>
* Its main purpose is to generate a descriptor that allows an observer to know
* how to connect to a registry.
*/
template<>
struct basic_collector<> {
/**
* @brief Adds a grouping matcher to the collector.
* @tparam AllOf Types of components tracked by the matcher.
* @tparam NoneOf Types of components used to filter out entities.
* @return The updated collector.
*/
template<typename... AllOf, typename... NoneOf>
static constexpr auto group(exclude_t<NoneOf...> = {}) ENTT_NOEXCEPT {
return basic_collector<matcher<type_list<>, type_list<>, type_list<NoneOf...>, AllOf...>>{};
}
/**
* @brief Adds an observing matcher to the collector.
* @tparam AnyOf Type of component for which changes should be detected.
* @return The updated collector.
*/
template<typename AnyOf>
static constexpr auto update() ENTT_NOEXCEPT {
return basic_collector<matcher<type_list<>, type_list<>, AnyOf>>{};
}
};
/**
* @brief Collector.
* @copydetails basic_collector<>
* @tparam Reject Untracked types used to filter out entities.
* @tparam Require Untracked types required by the matcher.
* @tparam Rule Specific details of the current matcher.
* @tparam Other Other matchers.
*/
template<typename... Reject, typename... Require, typename... Rule, typename... Other>
struct basic_collector<matcher<type_list<Reject...>, type_list<Require...>, Rule...>, Other...> {
/*! @brief Current matcher. */
using current_type = matcher<type_list<Reject...>, type_list<Require...>, Rule...>;
/**
* @brief Adds a grouping matcher to the collector.
* @tparam AllOf Types of components tracked by the matcher.
* @tparam NoneOf Types of components used to filter out entities.
* @return The updated collector.
*/
template<typename... AllOf, typename... NoneOf>
static constexpr auto group(exclude_t<NoneOf...> = {}) ENTT_NOEXCEPT {
return basic_collector<matcher<type_list<>, type_list<>, type_list<NoneOf...>, AllOf...>, current_type, Other...>{};
}
/**
* @brief Adds an observing matcher to the collector.
* @tparam AnyOf Type of component for which changes should be detected.
* @return The updated collector.
*/
template<typename AnyOf>
static constexpr auto update() ENTT_NOEXCEPT {
return basic_collector<matcher<type_list<>, type_list<>, AnyOf>, current_type, Other...>{};
}
/**
* @brief Updates the filter of the last added matcher.
* @tparam AllOf Types of components required by the matcher.
* @tparam NoneOf Types of components used to filter out entities.
* @return The updated collector.
*/
template<typename... AllOf, typename... NoneOf>
static constexpr auto where(exclude_t<NoneOf...> = {}) ENTT_NOEXCEPT {
using extended_type = matcher<type_list<Reject..., NoneOf...>, type_list<Require..., AllOf...>, Rule...>;
return basic_collector<extended_type, Other...>{};
}
};
/*! @brief Variable template used to ease the definition of collectors. */
inline constexpr basic_collector<> collector{};
/**
* @brief Observer.
*
* An observer returns all the entities and only the entities that fit the
* requirements of at least one matcher. Moreover, it's guaranteed that the
* entity list is tightly packed in memory for fast iterations.<br/>
* In general, observers don't stay true to the order of any set of components.
*
* Observers work mainly with two types of matchers, provided through a
* collector:
*
* * Observing matcher: an observer will return at least all the living entities
* for which one or more of the given components have been updated and not yet
* destroyed.
* * Grouping matcher: an observer will return at least all the living entities
* that would have entered the given group if it existed and that would have
* not yet left it.
*
* If an entity respects the requirements of multiple matchers, it will be
* returned once and only once by the observer in any case.
*
* Matchers support also filtering by means of a _where_ clause that accepts
* both a list of types and an exclusion list.<br/>
* Whenever a matcher finds that an entity matches its requirements, the
* condition of the filter is verified before to register the entity itself.
* Moreover, a registered entity isn't returned by the observer if the condition
* set by the filter is broken in the meantime.
*
* @b Important
*
* Iterators aren't invalidated if:
*
* * New instances of the given components are created and assigned to entities.
* * The entity currently pointed is modified (as an example, if one of the
* given components is removed from the entity to which the iterator points).
* * The entity currently pointed is destroyed.
*
* In all the other cases, modifying the pools of the given components in any
* way invalidates all the iterators and using them results in undefined
* behavior.
*
* @warning
* Lifetime of an observer doesn't necessarily have to overcome that of the
* registry to which it is connected. However, the observer must be disconnected
* from the registry before being destroyed to avoid crashes due to dangling
* pointers.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
class basic_observer {
using payload_type = std::uint32_t;
template<typename>
struct matcher_handler;
template<typename... Reject, typename... Require, typename AnyOf>
struct matcher_handler<matcher<type_list<Reject...>, type_list<Require...>, AnyOf>> {
template<std::size_t Index>
static void maybe_valid_if(basic_observer &obs, basic_registry<Entity> &reg, const Entity entt) {
if(reg.template all_of<Require...>(entt) && !reg.template any_of<Reject...>(entt)) {
if(!obs.storage.contains(entt)) {
obs.storage.emplace(entt);
}
obs.storage.get(entt) |= (1 << Index);
}
}
template<std::size_t Index>
static void discard_if(basic_observer &obs, basic_registry<Entity> &, const Entity entt) {
if(obs.storage.contains(entt) && !(obs.storage.get(entt) &= (~(1 << Index)))) {
obs.storage.erase(entt);
}
}
template<std::size_t Index>
static void connect(basic_observer &obs, basic_registry<Entity> &reg) {
(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_update<AnyOf>().template connect<&maybe_valid_if<Index>>(obs);
reg.template on_destroy<AnyOf>().template connect<&discard_if<Index>>(obs);
}
static void disconnect(basic_observer &obs, basic_registry<Entity> &reg) {
(reg.template on_destroy<Require>().disconnect(obs), ...);
(reg.template on_construct<Reject>().disconnect(obs), ...);
reg.template on_update<AnyOf>().disconnect(obs);
reg.template on_destroy<AnyOf>().disconnect(obs);
}
};
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, typename... Ignore>
static void maybe_valid_if(basic_observer &obs, basic_registry<Entity> &reg, const Entity entt) {
auto condition = [&reg, entt]() {
if constexpr(sizeof...(Ignore) == 0) {
return reg.template all_of<AllOf..., Require...>(entt) && !reg.template any_of<NoneOf..., Reject...>(entt);
} else {
return reg.template all_of<AllOf..., Require...>(entt) && ((std::is_same_v<Ignore..., NoneOf> || !reg.template any_of<NoneOf>(entt)) && ...) && !reg.template any_of<Reject...>(entt);
}
};
if(condition()) {
if(!obs.storage.contains(entt)) {
obs.storage.emplace(entt);
}
obs.storage.get(entt) |= (1 << Index);
}
}
template<std::size_t Index>
static void discard_if(basic_observer &obs, basic_registry<Entity> &, const Entity entt) {
if(obs.storage.contains(entt) && !(obs.storage.get(entt) &= (~(1 << Index)))) {
obs.storage.erase(entt);
}
}
template<std::size_t Index>
static void connect(basic_observer &obs, basic_registry<Entity> &reg) {
(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, NoneOf>>(obs), ...);
(reg.template on_destroy<AllOf>().template connect<&discard_if<Index>>(obs), ...);
(reg.template on_construct<NoneOf>().template connect<&discard_if<Index>>(obs), ...);
}
static void disconnect(basic_observer &obs, basic_registry<Entity> &reg) {
(reg.template on_destroy<Require>().disconnect(obs), ...);
(reg.template on_construct<Reject>().disconnect(obs), ...);
(reg.template on_construct<AllOf>().disconnect(obs), ...);
(reg.template on_destroy<NoneOf>().disconnect(obs), ...);
(reg.template on_destroy<AllOf>().disconnect(obs), ...);
(reg.template on_construct<NoneOf>().disconnect(obs), ...);
}
};
template<typename... Matcher>
static void disconnect(basic_registry<Entity> &reg, basic_observer &obs) {
(matcher_handler<Matcher>::disconnect(obs, reg), ...);
}
template<typename... Matcher, std::size_t... Index>
void connect(basic_registry<Entity> &reg, std::index_sequence<Index...>) {
static_assert(sizeof...(Matcher) < std::numeric_limits<payload_type>::digits, "Too many matchers");
(matcher_handler<Matcher>::template connect<Index>(*this, reg), ...);
release.template connect<&basic_observer::disconnect<Matcher...>>(reg);
}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Random access iterator type. */
using iterator = typename basic_sparse_set<Entity>::iterator;
/*! @brief Default constructor. */
basic_observer()
: release{},
storage{} {}
/*! @brief Default copy constructor, deleted on purpose. */
basic_observer(const basic_observer &) = delete;
/*! @brief Default move constructor, deleted on purpose. */
basic_observer(basic_observer &&) = delete;
/**
* @brief Creates an observer and connects it to a given registry.
* @tparam Matcher Types of matchers to use to initialize the observer.
* @param reg A valid reference to a registry.
*/
template<typename... Matcher>
basic_observer(basic_registry<entity_type> &reg, basic_collector<Matcher...>)
: basic_observer{} {
connect<Matcher...>(reg, std::index_sequence_for<Matcher...>{});
}
/*! @brief Default destructor. */
~basic_observer() = default;
/**
* @brief Default copy assignment operator, deleted on purpose.
* @return This observer.
*/
basic_observer &operator=(const basic_observer &) = delete;
/**
* @brief Default move assignment operator, deleted on purpose.
* @return This observer.
*/
basic_observer &operator=(basic_observer &&) = delete;
/**
* @brief Connects an observer to a given registry.
* @tparam Matcher Types of matchers to use to initialize the observer.
* @param reg A valid reference to a registry.
*/
template<typename... Matcher>
void connect(basic_registry<entity_type> &reg, basic_collector<Matcher...>) {
disconnect();
connect<Matcher...>(reg, std::index_sequence_for<Matcher...>{});
storage.clear();
}
/*! @brief Disconnects an observer from the registry it keeps track of. */
void disconnect() {
if(release) {
release(*this);
release.reset();
}
}
/**
* @brief Returns the number of elements in an observer.
* @return Number of elements.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return storage.size();
}
/**
* @brief Checks whether an observer is empty.
* @return True if the observer is empty, false otherwise.
*/
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
return storage.empty();
}
/**
* @brief Direct access to the list of entities of the observer.
*
* The returned pointer is such that range `[data(), data() + size())` is
* always a valid range, even if the container is empty.
*
* @note
* Entities are in the reverse order as returned by the `begin`/`end`
* iterators.
*
* @return A pointer to the array of entities.
*/
[[nodiscard]] const entity_type *data() const ENTT_NOEXCEPT {
return storage.data();
}
/**
* @brief Returns an iterator to the first entity of the observer.
*
* The returned iterator points to the first entity of the observer. If the
* container is empty, the returned iterator will be equal to `end()`.
*
* @return An iterator to the first entity of the observer.
*/
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
return storage.basic_sparse_set<entity_type>::begin();
}
/**
* @brief Returns an iterator that is past the last entity of the observer.
*
* The returned iterator points to the entity following the last entity of
* the observer. Attempting to dereference the returned iterator results in
* undefined behavior.
*
* @return An iterator to the entity following the last entity of the
* observer.
*/
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return storage.basic_sparse_set<entity_type>::end();
}
/*! @brief Clears the underlying container. */
void clear() ENTT_NOEXCEPT {
storage.clear();
}
/**
* @brief Iterates entities and applies the given function object to them.
*
* The function object is invoked for each entity.<br/>
* The signature of the function must be equivalent to the following form:
*
* @code{.cpp}
* void(const entity_type);
* @endcode
*
* @tparam Func Type of the function object to invoke.
* @param func A valid function object.
*/
template<typename Func>
void each(Func func) const {
for(const auto entity: *this) {
func(entity);
}
}
/**
* @brief Iterates entities and applies the given function object to them,
* then clears the observer.
*
* @sa each
*
* @tparam Func Type of the function object to invoke.
* @param func A valid function object.
*/
template<typename Func>
void each(Func func) {
std::as_const(*this).each(std::move(func));
clear();
}
private:
delegate<void(basic_observer &)> release;
basic_storage<entity_type, payload_type> storage;
};
} // namespace entt
#endif

View File

@@ -0,0 +1,487 @@
#ifndef ENTT_ENTITY_ORGANIZER_HPP
#define ENTT_ENTITY_ORGANIZER_HPP
#include <algorithm>
#include <cstddef>
#include <type_traits>
#include <utility>
#include <vector>
#include "../container/dense_hash_map.hpp"
#include "../core/type_info.hpp"
#include "../core/type_traits.hpp"
#include "../core/utility.hpp"
#include "fwd.hpp"
#include "helper.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename>
struct is_view: std::false_type {};
template<typename Entity, typename... Component, typename... Exclude>
struct is_view<basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>>>: std::true_type {};
template<typename Type>
inline constexpr bool is_view_v = is_view<Type>::value;
template<typename Type, typename Override>
struct unpack_type {
using ro = std::conditional_t<
type_list_contains_v<Override, std::add_const_t<Type>> || (std::is_const_v<Type> && !type_list_contains_v<Override, std::remove_const_t<Type>>),
type_list<std::remove_const_t<Type>>,
type_list<>>;
using rw = std::conditional_t<
type_list_contains_v<Override, std::remove_const_t<Type>> || (!std::is_const_v<Type> && !type_list_contains_v<Override, std::add_const_t<Type>>),
type_list<Type>,
type_list<>>;
};
template<typename Entity, typename... Override>
struct unpack_type<basic_registry<Entity>, type_list<Override...>> {
using ro = type_list<>;
using rw = type_list<>;
};
template<typename Entity, typename... Override>
struct unpack_type<const basic_registry<Entity>, type_list<Override...>>
: unpack_type<basic_registry<Entity>, type_list<Override...>> {};
template<typename Entity, typename... Component, typename... Exclude, typename... Override>
struct unpack_type<basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>>, type_list<Override...>> {
using ro = type_list_cat_t<type_list<Exclude...>, typename unpack_type<Component, type_list<Override...>>::ro...>;
using rw = type_list_cat_t<typename unpack_type<Component, type_list<Override...>>::rw...>;
};
template<typename Entity, typename... Component, typename... Exclude, typename... Override>
struct unpack_type<const basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>>, type_list<Override...>>
: unpack_type<basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>>, type_list<Override...>> {};
template<typename, typename>
struct resource;
template<typename... Args, typename... Req>
struct resource<type_list<Args...>, type_list<Req...>> {
using args = type_list<std::remove_const_t<Args>...>;
using ro = type_list_cat_t<typename unpack_type<Args, type_list<Req...>>::ro..., typename unpack_type<Req, type_list<>>::ro...>;
using rw = type_list_cat_t<typename unpack_type<Args, type_list<Req...>>::rw..., typename unpack_type<Req, type_list<>>::rw...>;
};
template<typename... Req, typename Ret, typename... Args>
resource<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> free_function_to_resource(Ret (*)(Args...));
template<typename... Req, typename Ret, typename Type, typename... Args>
resource<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource(Ret (*)(Type &, Args...));
template<typename... Req, typename Ret, typename Class, typename... Args>
resource<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource(Ret (Class::*)(Args...));
template<typename... Req, typename Ret, typename Class, typename... Args>
resource<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource(Ret (Class::*)(Args...) const);
template<typename... Req>
resource<type_list<>, type_list<Req...>> to_resource();
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief Utility class for creating a static task graph.
*
* This class offers minimal support (but sufficient in many cases) for creating
* an execution graph from functions and their requirements on resources.<br/>
* Note that the resulting tasks aren't executed in any case. This isn't the
* goal of the tool. Instead, they are returned to the user in the form of a
* graph that allows for safe execution.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
class basic_organizer final {
using callback_type = void(const void *, basic_registry<Entity> &);
using prepare_type = void(basic_registry<Entity> &);
using dependency_type = std::size_t(const bool, const type_info **, const std::size_t);
struct vertex_data final {
std::size_t ro_count{};
std::size_t rw_count{};
const char *name{};
const void *payload{};
callback_type *callback{};
dependency_type *dependency;
prepare_type *prepare{};
const type_info *info{};
};
template<typename Type>
[[nodiscard]] static decltype(auto) extract(basic_registry<Entity> &reg) {
if constexpr(std::is_same_v<Type, basic_registry<Entity>>) {
return reg;
} else if constexpr(internal::is_view_v<Type>) {
return as_view{reg};
} else {
return reg.template ctx_or_set<std::remove_reference_t<Type>>();
}
}
template<typename... Args>
[[nodiscard]] static auto to_args(basic_registry<Entity> &reg, type_list<Args...>) {
return std::tuple<decltype(extract<Args>(reg))...>(extract<Args>(reg)...);
}
template<typename... Type>
static std::size_t fill_dependencies(type_list<Type...>, [[maybe_unused]] const type_info **buffer, [[maybe_unused]] const std::size_t count) {
if constexpr(sizeof...(Type) == 0u) {
return {};
} else {
const type_info *info[sizeof...(Type)]{&type_id<Type>()...};
const auto length = (std::min)(count, sizeof...(Type));
std::copy_n(info, length, buffer);
return length;
}
}
template<typename... RO, typename... RW>
void track_dependencies(std::size_t index, const bool requires_registry, type_list<RO...>, type_list<RW...>) {
dependencies[type_hash<basic_registry<Entity>>::value()].emplace_back(index, requires_registry || (sizeof...(RO) + sizeof...(RW) == 0u));
(dependencies[type_hash<RO>::value()].emplace_back(index, false), ...);
(dependencies[type_hash<RW>::value()].emplace_back(index, true), ...);
}
[[nodiscard]] std::vector<bool> adjacency_matrix() {
const auto length = vertices.size();
std::vector<bool> edges(length * length, false);
// creates the ajacency matrix
for(const auto &deps: dependencies) {
const auto last = deps.second.cend();
auto it = deps.second.cbegin();
while(it != last) {
if(it->second) {
// rw item
if(auto curr = it++; it != last) {
if(it->second) {
edges[curr->first * length + it->first] = true;
} else {
if(const auto next = std::find_if(it, last, [](const auto &elem) { return elem.second; }); next != last) {
for(; it != next; ++it) {
edges[curr->first * length + it->first] = true;
edges[it->first * length + next->first] = true;
}
} else {
for(; it != next; ++it) {
edges[curr->first * length + it->first] = true;
}
}
}
}
} else {
// ro item, possibly only on first iteration
if(const auto next = std::find_if(it, last, [](const auto &elem) { return elem.second; }); next != last) {
for(; it != next; ++it) {
edges[it->first * length + next->first] = true;
}
} else {
it = last;
}
}
}
}
// computes the transitive closure
for(std::size_t vk{}; vk < length; ++vk) {
for(std::size_t vi{}; vi < length; ++vi) {
for(std::size_t vj{}; vj < length; ++vj) {
edges[vi * length + vj] = edges[vi * length + vj] || (edges[vi * length + vk] && edges[vk * length + vj]);
}
}
}
// applies the transitive reduction
for(std::size_t vert{}; vert < length; ++vert) {
edges[vert * length + vert] = false;
}
for(std::size_t vj{}; vj < length; ++vj) {
for(std::size_t vi{}; vi < length; ++vi) {
if(edges[vi * length + vj]) {
for(std::size_t vk{}; vk < length; ++vk) {
if(edges[vj * length + vk]) {
edges[vi * length + vk] = false;
}
}
}
}
}
return edges;
}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Raw task function type. */
using function_type = callback_type;
/*! @brief Vertex type of a task graph defined as an adjacency list. */
struct vertex {
/**
* @brief Constructs a vertex of the task graph.
* @param vtype True if the vertex is a top-level one, false otherwise.
* @param data The data associated with the vertex.
* @param edges The indices of the children in the adjacency list.
*/
vertex(const bool vtype, vertex_data data, std::vector<std::size_t> edges)
: is_top_level{vtype},
node{std::move(data)},
reachable{std::move(edges)} {}
/**
* @brief Fills a buffer with the type info objects for the writable
* resources of a vertex.
* @param buffer A buffer pre-allocated by the user.
* @param length The length of the user-supplied buffer.
* @return The number of type info objects written to the buffer.
*/
size_type ro_dependency(const type_info **buffer, const std::size_t length) const ENTT_NOEXCEPT {
return node.dependency(false, buffer, length);
}
/**
* @brief Fills a buffer with the type info objects for the read-only
* resources of a vertex.
* @param buffer A buffer pre-allocated by the user.
* @param length The length of the user-supplied buffer.
* @return The number of type info objects written to the buffer.
*/
size_type rw_dependency(const type_info **buffer, const std::size_t length) const ENTT_NOEXCEPT {
return node.dependency(true, buffer, length);
}
/**
* @brief Returns the number of read-only resources of a vertex.
* @return The number of read-only resources of the vertex.
*/
size_type ro_count() const ENTT_NOEXCEPT {
return node.ro_count;
}
/**
* @brief Returns the number of writable resources of a vertex.
* @return The number of writable resources of the vertex.
*/
size_type rw_count() const ENTT_NOEXCEPT {
return node.rw_count;
}
/**
* @brief Checks if a vertex is also a top-level one.
* @return True if the vertex is a top-level one, false otherwise.
*/
bool top_level() const ENTT_NOEXCEPT {
return is_top_level;
}
/**
* @brief Returns a type info object associated with a vertex.
* @return A properly initialized type info object.
*/
const type_info &info() const ENTT_NOEXCEPT {
return *node.info;
}
/**
* @brief Returns a user defined name associated with a vertex, if any.
* @return The user defined name associated with the vertex, if any.
*/
const char *name() const ENTT_NOEXCEPT {
return node.name;
}
/**
* @brief Returns the function associated with a vertex.
* @return The function associated with the vertex.
*/
function_type *callback() const ENTT_NOEXCEPT {
return node.callback;
}
/**
* @brief Returns the payload associated with a vertex, if any.
* @return The payload associated with the vertex, if any.
*/
const void *data() const ENTT_NOEXCEPT {
return node.payload;
}
/**
* @brief Returns the list of nodes reachable from a given vertex.
* @return The list of nodes reachable from the vertex.
*/
const std::vector<std::size_t> &children() const ENTT_NOEXCEPT {
return reachable;
}
/**
* @brief Prepares a registry and assures that all required resources
* are properly instantiated before using them.
* @param reg A valid registry.
*/
void prepare(basic_registry<entity_type> &reg) const {
node.prepare ? node.prepare(reg) : void();
}
private:
bool is_top_level;
vertex_data node;
std::vector<std::size_t> reachable;
};
/**
* @brief Adds a free function to the task list.
* @tparam Candidate Function to add to the task list.
* @tparam Req Additional requirements and/or override resource access mode.
* @param name Optional name to associate with the task.
*/
template<auto Candidate, typename... Req>
void emplace(const char *name = nullptr) {
using resource_type = decltype(internal::free_function_to_resource<Req...>(Candidate));
constexpr auto requires_registry = type_list_contains_v<typename resource_type::args, basic_registry<entity_type>>;
callback_type *callback = +[](const void *, basic_registry<entity_type> &reg) {
std::apply(Candidate, to_args(reg, typename resource_type::args{}));
};
vertex_data vdata{
resource_type::ro::size,
resource_type::rw::size,
name,
nullptr,
callback,
+[](const bool rw, const type_info **buffer, const std::size_t length) { return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length); },
+[](basic_registry<entity_type> &reg) { void(to_args(reg, typename resource_type::args{})); },
&type_id<std::integral_constant<decltype(Candidate), Candidate>>()};
track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
vertices.push_back(std::move(vdata));
}
/**
* @brief Adds a free function with payload or a member function with an
* instance to the task list.
* @tparam Candidate Function or member to add to the task list.
* @tparam Req Additional requirements and/or override resource access mode.
* @tparam Type Type of class or type of payload.
* @param value_or_instance A valid object that fits the purpose.
* @param name Optional name to associate with the task.
*/
template<auto Candidate, typename... Req, typename Type>
void emplace(Type &value_or_instance, const char *name = nullptr) {
using resource_type = decltype(internal::constrained_function_to_resource<Req...>(Candidate));
constexpr auto requires_registry = type_list_contains_v<typename resource_type::args, basic_registry<entity_type>>;
callback_type *callback = +[](const void *payload, basic_registry<entity_type> &reg) {
Type *curr = static_cast<Type *>(const_cast<constness_as_t<void, Type> *>(payload));
std::apply(Candidate, std::tuple_cat(std::forward_as_tuple(*curr), to_args(reg, typename resource_type::args{})));
};
vertex_data vdata{
resource_type::ro::size,
resource_type::rw::size,
name,
&value_or_instance,
callback,
+[](const bool rw, const type_info **buffer, const std::size_t length) { return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length); },
+[](basic_registry<entity_type> &reg) { void(to_args(reg, typename resource_type::args{})); },
&type_id<std::integral_constant<decltype(Candidate), Candidate>>()};
track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
vertices.push_back(std::move(vdata));
}
/**
* @brief Adds an user defined function with optional payload to the task
* list.
* @tparam Req Additional requirements and/or override resource access mode.
* @param func Function to add to the task list.
* @param payload User defined arbitrary data.
* @param name Optional name to associate with the task.
*/
template<typename... Req>
void emplace(function_type *func, const void *payload = nullptr, const char *name = nullptr) {
using resource_type = internal::resource<type_list<>, type_list<Req...>>;
track_dependencies(vertices.size(), true, typename resource_type::ro{}, typename resource_type::rw{});
vertex_data vdata{
resource_type::ro::size,
resource_type::rw::size,
name,
payload,
func,
+[](const bool rw, const type_info **buffer, const std::size_t length) { return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length); },
nullptr,
&type_id<void>()};
vertices.push_back(std::move(vdata));
}
/**
* @brief Generates a task graph for the current content.
* @return The adjacency list of the task graph.
*/
std::vector<vertex> graph() {
const auto edges = adjacency_matrix();
// creates the adjacency list
std::vector<vertex> adjacency_list{};
adjacency_list.reserve(vertices.size());
for(std::size_t col{}, length = vertices.size(); col < length; ++col) {
std::vector<std::size_t> reachable{};
const auto row = col * length;
bool is_top_level = true;
for(std::size_t next{}; next < length; ++next) {
if(edges[row + next]) {
reachable.push_back(next);
}
}
for(std::size_t next{}; next < length && is_top_level; ++next) {
is_top_level = !edges[next * length + col];
}
adjacency_list.emplace_back(is_top_level, vertices[col], std::move(reachable));
}
return adjacency_list;
}
/*! @brief Erases all elements from a container. */
void clear() {
dependencies.clear();
vertices.clear();
}
private:
dense_hash_map<id_type, std::vector<std::pair<std::size_t, bool>>, identity> dependencies;
std::vector<vertex_data> vertices;
};
} // namespace entt
#endif

1548
src/entt/entity/registry.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,249 @@
#ifndef ENTT_ENTITY_RUNTIME_VIEW_HPP
#define ENTT_ENTITY_RUNTIME_VIEW_HPP
#include <algorithm>
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>
#include "../config/config.h"
#include "entity.hpp"
#include "fwd.hpp"
#include "sparse_set.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename Type>
class runtime_view_iterator final {
[[nodiscard]] bool valid() const {
return std::all_of(pools->begin(), pools->end(), [entt = *it](const auto *curr) { return curr->contains(entt); })
&& std::none_of(filter->cbegin(), filter->cend(), [entt = *it](const auto *curr) { return curr && curr->contains(entt); });
}
public:
using iterator_type = typename Type::iterator;
using difference_type = typename iterator_type::difference_type;
using value_type = typename iterator_type::value_type;
using pointer = typename iterator_type::pointer;
using reference = typename iterator_type::reference;
using iterator_category = std::bidirectional_iterator_tag;
runtime_view_iterator() ENTT_NOEXCEPT = default;
runtime_view_iterator(const std::vector<const Type *> &cpools, const std::vector<const Type *> &ignore, iterator_type curr) ENTT_NOEXCEPT
: pools{&cpools},
filter{&ignore},
it{curr} {
if(it != (*pools)[0]->end() && !valid()) {
++(*this);
}
}
runtime_view_iterator &operator++() {
while(++it != (*pools)[0]->end() && !valid()) {}
return *this;
}
runtime_view_iterator operator++(int) {
runtime_view_iterator orig = *this;
return ++(*this), orig;
}
runtime_view_iterator &operator--() ENTT_NOEXCEPT {
while(--it != (*pools)[0]->begin() && !valid()) {}
return *this;
}
runtime_view_iterator operator--(int) ENTT_NOEXCEPT {
runtime_view_iterator orig = *this;
return operator--(), orig;
}
[[nodiscard]] pointer operator->() const {
return it.operator->();
}
[[nodiscard]] reference operator*() const {
return *operator->();
}
[[nodiscard]] bool operator==(const runtime_view_iterator &other) const ENTT_NOEXCEPT {
return it == other.it;
}
[[nodiscard]] bool operator!=(const runtime_view_iterator &other) const ENTT_NOEXCEPT {
return !(*this == other);
}
private:
const std::vector<const Type *> *pools;
const std::vector<const Type *> *filter;
iterator_type it;
};
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief Runtime view.
*
* Runtime views iterate over those entities that have at least all the given
* components in their bags. During initialization, a runtime view looks at the
* number of entities available for each component and picks up a reference to
* the smallest set of candidate entities in order to get a performance boost
* when iterate.<br/>
* Order of elements during iterations are highly dependent on the order of the
* underlying data structures. See sparse_set and its specializations for more
* details.
*
* @b Important
*
* Iterators aren't invalidated if:
*
* * New instances of the given components are created and assigned to entities.
* * The entity currently pointed is modified (as an example, if one of the
* given components is removed from the entity to which the iterator points).
* * The entity currently pointed is destroyed.
*
* In all the other cases, modifying the pools of the given components in any
* way invalidates all the iterators and using them results in undefined
* behavior.
*
* @note
* Views share references to the underlying data structures of the registry that
* generated them. Therefore any change to the entities and to the components
* made by means of the registry are immediately reflected by the views, unless
* a pool was missing when the view was built (in this case, the view won't
* have a valid reference and won't be updated accordingly).
*
* @warning
* Lifetime of a view must not overcome that of the registry that generated it.
* In any other case, attempting to use a view results in undefined behavior.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
class basic_runtime_view final {
using basic_common_type = basic_sparse_set<Entity>;
[[nodiscard]] bool valid() const {
return !pools.empty() && pools.front();
}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Bidirectional iterator type. */
using iterator = internal::runtime_view_iterator<basic_common_type>;
/*! @brief Default constructor to use to create empty, invalid views. */
basic_runtime_view() ENTT_NOEXCEPT
: pools{},
filter{} {}
/**
* @brief Constructs a runtime view from a set of storage classes.
* @param cpools The storage for the types to iterate.
* @param epools The storage for the types used to filter the view.
*/
basic_runtime_view(std::vector<const basic_common_type *> cpools, std::vector<const basic_common_type *> epools) ENTT_NOEXCEPT
: pools{std::move(cpools)},
filter{std::move(epools)} {
auto candidate = std::min_element(pools.begin(), pools.end(), [](const auto *lhs, const auto *rhs) {
return (!lhs && rhs) || (lhs && rhs && lhs->size() < rhs->size());
});
// brings the best candidate (if any) on front of the vector
std::rotate(pools.begin(), candidate, pools.end());
}
/**
* @brief Estimates the number of entities iterated by the view.
* @return Estimated number of entities iterated by the view.
*/
[[nodiscard]] size_type size_hint() const {
return valid() ? pools.front()->size() : size_type{};
}
/**
* @brief Returns an iterator to the first entity that has the given
* components.
*
* The returned iterator points to the first entity that has the given
* components. If the view is empty, the returned iterator will be equal to
* `end()`.
*
* @return An iterator to the first entity that has the given components.
*/
[[nodiscard]] iterator begin() const {
return valid() ? iterator{pools, filter, pools[0]->begin()} : iterator{};
}
/**
* @brief Returns an iterator that is past the last entity that has the
* given components.
*
* The returned iterator points to the entity following the last entity that
* has the given components. Attempting to dereference the returned iterator
* results in undefined behavior.
*
* @return An iterator to the entity following the last entity that has the
* given components.
*/
[[nodiscard]] iterator end() const {
return valid() ? iterator{pools, filter, pools[0]->end()} : iterator{};
}
/**
* @brief Checks if a view contains an entity.
* @param entt A valid identifier.
* @return True if the view contains the given entity, false otherwise.
*/
[[nodiscard]] bool contains(const entity_type entt) const {
return valid() && std::all_of(pools.cbegin(), pools.cend(), [entt](const auto *curr) { return curr->contains(entt); })
&& std::none_of(filter.cbegin(), filter.cend(), [entt](const auto *curr) { return curr && curr->contains(entt); });
}
/**
* @brief Iterates entities and applies the given function object to them.
*
* The function object is invoked for each entity. It is provided only with
* the entity itself. To get the components, users can use the registry with
* which the view was built.<br/>
* The signature of the function should be equivalent to the following:
*
* @code{.cpp}
* void(const entity_type);
* @endcode
*
* @tparam Func Type of the function object to invoke.
* @param func A valid function object.
*/
template<typename Func>
void each(Func func) const {
for(const auto entity: *this) {
func(entity);
}
}
private:
std::vector<const basic_common_type *> pools;
std::vector<const basic_common_type *> filter;
};
} // namespace entt
#endif

View File

@@ -0,0 +1,562 @@
#ifndef ENTT_ENTITY_SNAPSHOT_HPP
#define ENTT_ENTITY_SNAPSHOT_HPP
#include <array>
#include <cstddef>
#include <iterator>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "../config/config.h"
#include "../container/dense_hash_map.hpp"
#include "../core/type_traits.hpp"
#include "component.hpp"
#include "entity.hpp"
#include "fwd.hpp"
#include "registry.hpp"
namespace entt {
/**
* @brief Utility class to create snapshots from a registry.
*
* A _snapshot_ can be either a dump of the entire registry or a narrower
* selection of components of interest.<br/>
* This type can be used in both cases if provided with a correctly configured
* output archive.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
class basic_snapshot {
using entity_traits = entt_traits<Entity>;
template<typename Component, typename Archive, typename It>
void get(Archive &archive, std::size_t sz, It first, It last) const {
const auto view = reg->template view<std::add_const_t<Component>>();
archive(typename entity_traits::entity_type(sz));
while(first != last) {
const auto entt = *(first++);
if(reg->template all_of<Component>(entt)) {
std::apply(archive, std::tuple_cat(std::make_tuple(entt), view.get(entt)));
}
}
}
template<typename... Component, typename Archive, typename It, std::size_t... Index>
void component(Archive &archive, It first, It last, std::index_sequence<Index...>) const {
std::array<std::size_t, sizeof...(Index)> size{};
auto begin = first;
while(begin != last) {
const auto entt = *(begin++);
((reg->template all_of<Component>(entt) ? ++size[Index] : 0u), ...);
}
(get<Component>(archive, size[Index], first, last), ...);
}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/**
* @brief Constructs an instance that is bound to a given registry.
* @param source A valid reference to a registry.
*/
basic_snapshot(const basic_registry<entity_type> &source) ENTT_NOEXCEPT
: reg{&source} {}
/*! @brief Default move constructor. */
basic_snapshot(basic_snapshot &&) = default;
/*! @brief Default move assignment operator. @return This snapshot. */
basic_snapshot &operator=(basic_snapshot &&) = default;
/**
* @brief Puts aside all the entities from the underlying registry.
*
* Entities are serialized along with their versions. Destroyed entities are
* taken in consideration as well by this function.
*
* @tparam Archive Type of output archive.
* @param archive A valid reference to an output archive.
* @return An object of this type to continue creating the snapshot.
*/
template<typename Archive>
const basic_snapshot &entities(Archive &archive) const {
const auto sz = reg->size();
archive(typename entity_traits::entity_type(sz + 1u));
archive(reg->released());
for(auto first = reg->data(), last = first + sz; first != last; ++first) {
archive(*first);
}
return *this;
}
/**
* @brief Puts aside the given components.
*
* Each instance is serialized together with the entity to which it belongs.
* Entities are serialized along with their versions.
*
* @tparam Component Types of components to serialize.
* @tparam Archive Type of output archive.
* @param archive A valid reference to an output archive.
* @return An object of this type to continue creating the snapshot.
*/
template<typename... Component, typename Archive>
const basic_snapshot &component(Archive &archive) const {
if constexpr(sizeof...(Component) == 1u) {
const auto view = reg->template view<const Component...>();
(component<Component>(archive, view.rbegin(), view.rend()), ...);
return *this;
} else {
(component<Component>(archive), ...);
return *this;
}
}
/**
* @brief Puts aside the given components for the entities in a range.
*
* Each instance is serialized together with the entity to which it belongs.
* Entities are serialized along with their versions.
*
* @tparam Component Types of components to serialize.
* @tparam Archive Type of output archive.
* @tparam It Type of input iterator.
* @param archive A valid reference to an output archive.
* @param first An iterator to the first element of the range to serialize.
* @param last An iterator past the last element of the range to serialize.
* @return An object of this type to continue creating the snapshot.
*/
template<typename... Component, typename Archive, typename It>
const basic_snapshot &component(Archive &archive, It first, It last) const {
component<Component...>(archive, first, last, std::index_sequence_for<Component...>{});
return *this;
}
private:
const basic_registry<entity_type> *reg;
};
/**
* @brief Utility class to restore a snapshot as a whole.
*
* A snapshot loader requires that the destination registry be empty and loads
* all the data at once while keeping intact the identifiers that the entities
* originally had.<br/>
* An example of use is the implementation of a save/restore utility.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
class basic_snapshot_loader {
using entity_traits = entt_traits<Entity>;
template<typename Type, typename Archive>
void assign(Archive &archive) const {
typename entity_traits::entity_type length{};
archive(length);
entity_type entt{};
if constexpr(ignore_as_empty_v<std::remove_const_t<Type>>) {
while(length--) {
archive(entt);
const auto entity = reg->valid(entt) ? entt : reg->create(entt);
ENTT_ASSERT(entity == entt, "Entity not available for use");
reg->template emplace<Type>(entity);
}
} else {
Type instance{};
while(length--) {
archive(entt, instance);
const auto entity = reg->valid(entt) ? entt : reg->create(entt);
ENTT_ASSERT(entity == entt, "Entity not available for use");
reg->template emplace<Type>(entity, std::move(instance));
}
}
}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/**
* @brief Constructs an instance that is bound to a given registry.
* @param source A valid reference to a registry.
*/
basic_snapshot_loader(basic_registry<entity_type> &source) ENTT_NOEXCEPT
: reg{&source} {
// restoring a snapshot as a whole requires a clean registry
ENTT_ASSERT(reg->empty(), "Registry must be empty");
}
/*! @brief Default move constructor. */
basic_snapshot_loader(basic_snapshot_loader &&) = default;
/*! @brief Default move assignment operator. @return This loader. */
basic_snapshot_loader &operator=(basic_snapshot_loader &&) = default;
/**
* @brief Restores entities that were in use during serialization.
*
* This function restores the entities that were in use during serialization
* and gives them the versions they originally had.
*
* @tparam Archive Type of input archive.
* @param archive A valid reference to an input archive.
* @return A valid loader to continue restoring data.
*/
template<typename Archive>
const basic_snapshot_loader &entities(Archive &archive) const {
typename entity_traits::entity_type length{};
archive(length);
std::vector<entity_type> all(length);
for(std::size_t pos{}; pos < length; ++pos) {
archive(all[pos]);
}
reg->assign(++all.cbegin(), all.cend(), all[0u]);
return *this;
}
/**
* @brief Restores components and assigns them to the right entities.
*
* The template parameter list must be exactly the same used during
* serialization. In the event that the entity to which the component is
* assigned doesn't exist yet, the loader will take care to create it with
* the version it originally had.
*
* @tparam Component Types of components to restore.
* @tparam Archive Type of input archive.
* @param archive A valid reference to an input archive.
* @return A valid loader to continue restoring data.
*/
template<typename... Component, typename Archive>
const basic_snapshot_loader &component(Archive &archive) const {
(assign<Component>(archive), ...);
return *this;
}
/**
* @brief Destroys those entities that have no components.
*
* In case all the entities were serialized but only part of the components
* was saved, it could happen that some of the entities have no components
* once restored.<br/>
* This functions helps to identify and destroy those entities.
*
* @return A valid loader to continue restoring data.
*/
const basic_snapshot_loader &orphans() const {
reg->each([this](const auto entt) {
if(reg->orphan(entt)) {
reg->release(entt);
}
});
return *this;
}
private:
basic_registry<entity_type> *reg;
};
/**
* @brief Utility class for _continuous loading_.
*
* A _continuous loader_ is designed to load data from a source registry to a
* (possibly) non-empty destination. The loader can accommodate in a registry
* more than one snapshot in a sort of _continuous loading_ that updates the
* destination one step at a time.<br/>
* Identifiers that entities originally had are not transferred to the target.
* Instead, the loader maps remote identifiers to local ones while restoring a
* snapshot.<br/>
* An example of use is the implementation of a client-server applications with
* the requirement of transferring somehow parts of the representation side to
* side.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
*/
template<typename Entity>
class basic_continuous_loader {
using entity_traits = entt_traits<Entity>;
void destroy(Entity entt) {
if(const auto it = remloc.find(entt); it == remloc.cend()) {
const auto local = reg->create();
remloc.emplace(entt, std::make_pair(local, true));
reg->destroy(local);
}
}
void restore(Entity entt) {
const auto it = remloc.find(entt);
if(it == remloc.cend()) {
const auto local = reg->create();
remloc.emplace(entt, std::make_pair(local, true));
} else {
if(!reg->valid(remloc[entt].first)) {
remloc[entt].first = reg->create();
}
// set the dirty flag
remloc[entt].second = true;
}
}
template<typename Container>
auto update(int, Container &container)
-> decltype(typename Container::mapped_type{}, void()) {
// map like container
Container other;
for(auto &&pair: container) {
using first_type = std::remove_const_t<typename std::decay_t<decltype(pair)>::first_type>;
using second_type = typename std::decay_t<decltype(pair)>::second_type;
if constexpr(std::is_same_v<first_type, entity_type> && std::is_same_v<second_type, entity_type>) {
other.emplace(map(pair.first), map(pair.second));
} else if constexpr(std::is_same_v<first_type, entity_type>) {
other.emplace(map(pair.first), std::move(pair.second));
} else {
static_assert(std::is_same_v<second_type, entity_type>, "Neither the key nor the value are of entity type");
other.emplace(std::move(pair.first), map(pair.second));
}
}
std::swap(container, other);
}
template<typename Container>
auto update(char, Container &container)
-> decltype(typename Container::value_type{}, void()) {
// vector like container
static_assert(std::is_same_v<typename Container::value_type, entity_type>, "Invalid value type");
for(auto &&entt: container) {
entt = map(entt);
}
}
template<typename Other, typename Type, typename Member>
void update([[maybe_unused]] Other &instance, [[maybe_unused]] Member Type::*member) {
if constexpr(!std::is_same_v<Other, Type>) {
return;
} else if constexpr(std::is_same_v<Member, entity_type>) {
instance.*member = map(instance.*member);
} else {
// maybe a container? let's try...
update(0, instance.*member);
}
}
template<typename Component>
void remove_if_exists() {
for(auto &&ref: remloc) {
const auto local = ref.second.first;
if(reg->valid(local)) {
reg->template remove<Component>(local);
}
}
}
template<typename Other, typename Archive, typename... Type, typename... Member>
void assign(Archive &archive, [[maybe_unused]] Member Type::*...member) {
typename entity_traits::entity_type length{};
archive(length);
entity_type entt{};
if constexpr(ignore_as_empty_v<std::remove_const_t<Other>>) {
while(length--) {
archive(entt);
restore(entt);
reg->template emplace_or_replace<Other>(map(entt));
}
} else {
Other instance{};
while(length--) {
archive(entt, instance);
(update(instance, member), ...);
restore(entt);
reg->template emplace_or_replace<Other>(map(entt), std::move(instance));
}
}
}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/**
* @brief Constructs an instance that is bound to a given registry.
* @param source A valid reference to a registry.
*/
basic_continuous_loader(basic_registry<entity_type> &source) ENTT_NOEXCEPT
: reg{&source} {}
/*! @brief Default move constructor. */
basic_continuous_loader(basic_continuous_loader &&) = default;
/*! @brief Default move assignment operator. @return This loader. */
basic_continuous_loader &operator=(basic_continuous_loader &&) = default;
/**
* @brief Restores entities that were in use during serialization.
*
* This function restores the entities that were in use during serialization
* and creates local counterparts for them if required.
*
* @tparam Archive Type of input archive.
* @param archive A valid reference to an input archive.
* @return A non-const reference to this loader.
*/
template<typename Archive>
basic_continuous_loader &entities(Archive &archive) {
typename entity_traits::entity_type length{};
entity_type entt{};
archive(length);
// discards the head of the list of destroyed entities
archive(entt);
for(std::size_t pos{}, last = length - 1u; pos < last; ++pos) {
archive(entt);
if(const auto entity = entity_traits::to_entity(entt); entity == pos) {
restore(entt);
} else {
destroy(entt);
}
}
return *this;
}
/**
* @brief Restores components and assigns them to the right entities.
*
* The template parameter list must be exactly the same used during
* serialization. In the event that the entity to which the component is
* assigned doesn't exist yet, the loader will take care to create a local
* counterpart for it.<br/>
* Members can be either data members of type entity_type or containers of
* entities. In both cases, the loader will visit them and update the
* entities by replacing each one with its local counterpart.
*
* @tparam Component Type of component to restore.
* @tparam Archive Type of input archive.
* @tparam Type Types of components to update with local counterparts.
* @tparam Member Types of members to update with their local counterparts.
* @param archive A valid reference to an input archive.
* @param member Members to update with their local counterparts.
* @return A non-const reference to this loader.
*/
template<typename... Component, typename Archive, typename... Type, typename... Member>
basic_continuous_loader &component(Archive &archive, Member Type::*...member) {
(remove_if_exists<Component>(), ...);
(assign<Component>(archive, member...), ...);
return *this;
}
/**
* @brief Helps to purge entities that no longer have a conterpart.
*
* Users should invoke this member function after restoring each snapshot,
* unless they know exactly what they are doing.
*
* @return A non-const reference to this loader.
*/
basic_continuous_loader &shrink() {
auto it = remloc.begin();
while(it != remloc.cend()) {
const auto local = it->second.first;
bool &dirty = it->second.second;
if(dirty) {
dirty = false;
++it;
} else {
if(reg->valid(local)) {
reg->destroy(local);
}
it = remloc.erase(it);
}
}
return *this;
}
/**
* @brief Destroys those entities that have no components.
*
* In case all the entities were serialized but only part of the components
* was saved, it could happen that some of the entities have no components
* once restored.<br/>
* This functions helps to identify and destroy those entities.
*
* @return A non-const reference to this loader.
*/
basic_continuous_loader &orphans() {
reg->each([this](const auto entt) {
if(reg->orphan(entt)) {
reg->release(entt);
}
});
return *this;
}
/**
* @brief Tests if a loader knows about a given entity.
* @param entt A valid identifier.
* @return True if `entity` is managed by the loader, false otherwise.
*/
[[nodiscard]] bool contains(entity_type entt) const ENTT_NOEXCEPT {
return (remloc.find(entt) != remloc.cend());
}
/**
* @brief Returns the identifier to which an entity refers.
* @param entt A valid identifier.
* @return The local identifier if any, the null entity otherwise.
*/
[[nodiscard]] entity_type map(entity_type entt) const ENTT_NOEXCEPT {
const auto it = remloc.find(entt);
entity_type other = null;
if(it != remloc.cend()) {
other = it->second.first;
}
return other;
}
private:
dense_hash_map<entity_type, std::pair<entity_type, bool>> remloc;
basic_registry<entity_type> *reg;
};
} // namespace entt
#endif

View File

@@ -0,0 +1,935 @@
#ifndef ENTT_ENTITY_SPARSE_SET_HPP
#define ENTT_ENTITY_SPARSE_SET_HPP
#include <cstddef>
#include <iterator>
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
#include "../config/config.h"
#include "../core/algorithm.hpp"
#include "../core/any.hpp"
#include "../core/memory.hpp"
#include "../core/type_info.hpp"
#include "entity.hpp"
#include "fwd.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename Container>
struct sparse_set_iterator final {
using value_type = typename Container::value_type;
using pointer = typename Container::const_pointer;
using reference = typename Container::const_reference;
using difference_type = typename Container::difference_type;
using iterator_category = std::random_access_iterator_tag;
sparse_set_iterator() ENTT_NOEXCEPT = default;
sparse_set_iterator(const Container &ref, const difference_type idx) ENTT_NOEXCEPT
: packed{std::addressof(ref)},
offset{idx} {}
sparse_set_iterator &operator++() ENTT_NOEXCEPT {
return --offset, *this;
}
sparse_set_iterator operator++(int) ENTT_NOEXCEPT {
sparse_set_iterator orig = *this;
return ++(*this), orig;
}
sparse_set_iterator &operator--() ENTT_NOEXCEPT {
return ++offset, *this;
}
sparse_set_iterator operator--(int) ENTT_NOEXCEPT {
sparse_set_iterator orig = *this;
return operator--(), orig;
}
sparse_set_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
offset -= value;
return *this;
}
sparse_set_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
sparse_set_iterator copy = *this;
return (copy += value);
}
sparse_set_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
return (*this += -value);
}
sparse_set_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
return (*this + -value);
}
[[nodiscard]] reference operator[](const difference_type value) const {
const auto pos = offset - value - 1;
return packed->data()[pos];
}
[[nodiscard]] pointer operator->() const {
const auto pos = offset - 1;
return packed->data() + pos;
}
[[nodiscard]] reference operator*() const {
return *operator->();
}
[[nodiscard]] difference_type index() const ENTT_NOEXCEPT {
return offset;
}
private:
const Container *packed;
difference_type offset;
};
template<typename Type, typename Other>
[[nodiscard]] auto operator-(const sparse_set_iterator<Type> &lhs, const sparse_set_iterator<Other> &rhs) ENTT_NOEXCEPT {
return rhs.index() - lhs.index();
}
template<typename Type, typename Other>
[[nodiscard]] bool operator==(const sparse_set_iterator<Type> &lhs, const sparse_set_iterator<Other> &rhs) ENTT_NOEXCEPT {
return lhs.index() == rhs.index();
}
template<typename Type, typename Other>
[[nodiscard]] bool operator!=(const sparse_set_iterator<Type> &lhs, const sparse_set_iterator<Other> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
template<typename Type, typename Other>
[[nodiscard]] bool operator<(const sparse_set_iterator<Type> &lhs, const sparse_set_iterator<Other> &rhs) ENTT_NOEXCEPT {
return lhs.index() > rhs.index();
}
template<typename Type, typename Other>
[[nodiscard]] bool operator>(const sparse_set_iterator<Type> &lhs, const sparse_set_iterator<Other> &rhs) ENTT_NOEXCEPT {
return lhs.index() < rhs.index();
}
template<typename Type, typename Other>
[[nodiscard]] bool operator<=(const sparse_set_iterator<Type> &lhs, const sparse_set_iterator<Other> &rhs) ENTT_NOEXCEPT {
return !(lhs > rhs);
}
template<typename Type, typename Other>
[[nodiscard]] bool operator>=(const sparse_set_iterator<Type> &lhs, const sparse_set_iterator<Other> &rhs) ENTT_NOEXCEPT {
return !(lhs < rhs);
}
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/*! @brief Sparse set deletion policy. */
enum class deletion_policy : std::uint8_t {
/*! @brief Swap-and-pop deletion policy. */
swap_and_pop = 0u,
/*! @brief In-place deletion policy. */
in_place = 1u
};
/**
* @brief Basic sparse set implementation.
*
* Sparse set or packed array or whatever is the name users give it.<br/>
* Two arrays: an _external_ one and an _internal_ one; a _sparse_ one and a
* _packed_ one; one used for direct access through contiguous memory, the other
* one used to get the data through an extra level of indirection.<br/>
* This is largely used by the registry to offer users the fastest access ever
* to the components. Views and groups in general are almost entirely designed
* around sparse sets.
*
* This type of data structure is widely documented in the literature and on the
* web. This is nothing more than a customized implementation suitable for the
* purpose of the framework.
*
* @note
* Internal data structures arrange elements to maximize performance. There are
* no guarantees that entities are returned in the insertion order when iterate
* a sparse set. Do not make assumption on the order in any case.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Allocator Type of allocator used to manage memory and elements.
*/
template<typename Entity, typename Allocator>
class basic_sparse_set {
using allocator_traits = std::allocator_traits<Allocator>;
using alloc = typename allocator_traits::template rebind_alloc<Entity>;
using alloc_traits = typename std::allocator_traits<alloc>;
using entity_traits = entt_traits<Entity>;
using sparse_container_type = std::vector<typename alloc_traits::pointer, typename alloc_traits::template rebind_alloc<typename alloc_traits::pointer>>;
using packed_container_type = std::vector<Entity, alloc>;
[[nodiscard]] auto sparse_ptr(const Entity entt) const {
const auto pos = static_cast<size_type>(entity_traits::to_entity(entt));
const auto page = pos / entity_traits::page_size;
return (page < sparse.size() && sparse[page]) ? (sparse[page] + fast_mod(pos, entity_traits::page_size)) : nullptr;
}
[[nodiscard]] auto &sparse_ref(const Entity entt) const {
ENTT_ASSERT(sparse_ptr(entt), "Invalid element");
const auto pos = static_cast<size_type>(entity_traits::to_entity(entt));
return sparse[pos / entity_traits::page_size][fast_mod(pos, entity_traits::page_size)];
}
void release_sparse_pages() {
auto page_allocator{packed.get_allocator()};
for(auto &&page: sparse) {
if(page != nullptr) {
std::destroy(page, page + entity_traits::page_size);
alloc_traits::deallocate(page_allocator, page, entity_traits::page_size);
page = nullptr;
}
}
}
protected:
/**
* @brief Returns the element assigned to an entity.
* @return An opaque pointer to the element assigned to the entity.
*/
virtual const void *get_at(const std::size_t) const ENTT_NOEXCEPT {
return nullptr;
}
/*! @brief Swaps two entities in a sparse set. */
virtual void swap_at(const std::size_t, const std::size_t) {}
/*! @brief Moves an entity in a sparse set. */
virtual void move_and_pop(const std::size_t, const std::size_t) {}
/**
* @brief Erase an entity from a sparse set.
* @param entt A valid identifier.
*/
virtual void swap_and_pop(const Entity entt) {
auto &ref = sparse_ref(entt);
const auto pos = static_cast<size_type>(entity_traits::to_entity(ref));
ENTT_ASSERT(packed[pos] == entt, "Invalid identifier");
packed[pos] = packed.back();
auto &elem = sparse_ref(packed.back());
elem = entity_traits::combine(entity_traits::to_integral(ref), entity_traits::to_integral(elem));
// lazy self-assignment guard
ref = null;
// unnecessary but it helps to detect nasty bugs
ENTT_ASSERT((packed.back() = tombstone, true), "");
packed.pop_back();
}
/**
* @brief Erase an entity from a sparse set.
* @param entt A valid identifier.
*/
virtual void in_place_pop(const Entity entt) {
auto &ref = sparse_ref(entt);
const auto pos = static_cast<size_type>(entity_traits::to_entity(ref));
ENTT_ASSERT(packed[pos] == entt, "Invalid identifier");
packed[pos] = std::exchange(free_list, entity_traits::combine(static_cast<typename entity_traits::entity_type>(pos), entity_traits::reserved));
// lazy self-assignment guard
ref = null;
}
/**
* @brief Assigns an entity to a sparse set.
* @param entt A valid identifier.
*/
virtual void try_emplace(const Entity entt, const void * = nullptr) {
const auto pos = static_cast<size_type>(entity_traits::to_entity(entt));
const auto page = pos / entity_traits::page_size;
if(!(page < sparse.size())) {
sparse.resize(page + 1u, nullptr);
}
if(!sparse[page]) {
auto page_allocator{packed.get_allocator()};
sparse[page] = alloc_traits::allocate(page_allocator, entity_traits::page_size);
std::uninitialized_fill(sparse[page], sparse[page] + entity_traits::page_size, null);
}
auto &elem = sparse[page][fast_mod(pos, entity_traits::page_size)];
ENTT_ASSERT(entity_traits::to_version(elem) == entity_traits::to_version(tombstone), "Slot not available");
if(free_list == null) {
elem = entity_traits::combine(static_cast<typename entity_traits::entity_type>(packed.size()), entity_traits::to_integral(entt));
packed.push_back(entt);
} else {
elem = entity_traits::combine(entity_traits::to_integral(free_list), entity_traits::to_integral(entt));
free_list = std::exchange(packed[static_cast<size_type>(entity_traits::to_entity(free_list))], entt);
}
}
public:
/*! @brief Allocator type. */
using allocator_type = Allocator;
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/*! @brief Underlying version type. */
using version_type = typename entity_traits::version_type;
/*! @brief Unsigned integer type. */
using size_type = typename packed_container_type::size_type;
/*! @brief Pointer type to contained entities. */
using pointer = typename packed_container_type::const_pointer;
/*! @brief Random access iterator type. */
using iterator = internal::sparse_set_iterator<packed_container_type>;
/*! @brief Constant random access iterator type. */
using const_iterator = iterator;
/*! @brief Reverse iterator type. */
using reverse_iterator = std::reverse_iterator<iterator>;
/*! @brief Constant reverse iterator type. */
using const_reverse_iterator = reverse_iterator;
/*! @brief Default constructor. */
basic_sparse_set()
: basic_sparse_set{type_id<void>()} {}
/**
* @brief Constructs an empty container with a given allocator.
* @param allocator The allocator to use.
*/
explicit basic_sparse_set(const allocator_type &allocator)
: basic_sparse_set{type_id<void>(), deletion_policy::swap_and_pop, allocator} {}
/**
* @brief Constructs an empty container with the given policy and allocator.
* @param pol Type of deletion policy.
* @param allocator The allocator to use (possibly default-constructed).
*/
explicit basic_sparse_set(deletion_policy pol, const allocator_type &allocator = {})
: basic_sparse_set{type_id<void>(), pol, allocator} {}
/**
* @brief Constructs an empty container with the given policy and allocator.
* @param value Returned value type, if any.
* @param pol Type of deletion policy.
* @param allocator The allocator to use (possibly default-constructed).
*/
explicit basic_sparse_set(const type_info &value, deletion_policy pol = deletion_policy::swap_and_pop, const allocator_type &allocator = {})
: sparse{allocator},
packed{allocator},
info{&value},
free_list{tombstone},
mode{pol} {}
/**
* @brief Move constructor.
* @param other The instance to move from.
*/
basic_sparse_set(basic_sparse_set &&other) ENTT_NOEXCEPT
: sparse{std::move(other.sparse)},
packed{std::move(other.packed)},
info{other.info},
free_list{std::exchange(other.free_list, tombstone)},
mode{other.mode} {}
/**
* @brief Allocator-extended move constructor.
* @param other The instance to move from.
* @param allocator The allocator to use.
*/
basic_sparse_set(basic_sparse_set &&other, const allocator_type &allocator) ENTT_NOEXCEPT
: sparse{std::move(other.sparse), allocator},
packed{std::move(other.packed), allocator},
info{other.info},
free_list{std::exchange(other.free_list, tombstone)},
mode{other.mode} {
ENTT_ASSERT(alloc_traits::is_always_equal::value || packed.get_allocator() == other.packed.get_allocator(), "Copying a sparse set is not allowed");
}
/*! @brief Default destructor. */
virtual ~basic_sparse_set() {
release_sparse_pages();
}
/**
* @brief Move assignment operator.
* @param other The instance to move from.
* @return This sparse set.
*/
basic_sparse_set &operator=(basic_sparse_set &&other) ENTT_NOEXCEPT {
ENTT_ASSERT(alloc_traits::is_always_equal::value || packed.get_allocator() == other.packed.get_allocator(), "Copying a sparse set is not allowed");
release_sparse_pages();
sparse = std::move(other.sparse);
packed = std::move(other.packed);
info = other.info;
free_list = std::exchange(other.free_list, tombstone);
mode = other.mode;
return *this;
}
/**
* @brief Exchanges the contents with those of a given sparse set.
* @param other Sparse set to exchange the content with.
*/
void swap(basic_sparse_set &other) {
using std::swap;
swap(sparse, other.sparse);
swap(packed, other.packed);
swap(info, other.info);
swap(free_list, other.free_list);
swap(mode, other.mode);
}
/**
* @brief Returns the associated allocator.
* @return The associated allocator.
*/
[[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
return packed.get_allocator();
}
/**
* @brief Returns the deletion policy of a sparse set.
* @return The deletion policy of the sparse set.
*/
[[nodiscard]] deletion_policy policy() const ENTT_NOEXCEPT {
return mode;
}
/**
* @brief Returns the next slot available for insertion.
* @return The next slot available for insertion.
*/
[[nodiscard]] size_type slot() const ENTT_NOEXCEPT {
return free_list == null ? packed.size() : static_cast<size_type>(entity_traits::to_entity(free_list));
}
/**
* @brief Increases the capacity of a sparse set.
*
* If the new capacity is greater than the current capacity, new storage is
* allocated, otherwise the method does nothing.
*
* @param cap Desired capacity.
*/
virtual void reserve(const size_type cap) {
packed.reserve(cap);
}
/**
* @brief Returns the number of elements that a sparse set has currently
* allocated space for.
* @return Capacity of the sparse set.
*/
[[nodiscard]] virtual size_type capacity() const ENTT_NOEXCEPT {
return packed.capacity();
}
/*! @brief Requests the removal of unused capacity. */
virtual void shrink_to_fit() {
packed.shrink_to_fit();
}
/**
* @brief Returns the extent of a sparse set.
*
* The extent of a sparse set is also the size of the internal sparse array.
* There is no guarantee that the internal packed array has the same size.
* Usually the size of the internal sparse array is equal or greater than
* the one of the internal packed array.
*
* @return Extent of the sparse set.
*/
[[nodiscard]] size_type extent() const ENTT_NOEXCEPT {
return sparse.size() * entity_traits::page_size;
}
/**
* @brief Returns the number of elements in a sparse set.
*
* The number of elements is also the size of the internal packed array.
* There is no guarantee that the internal sparse array has the same size.
* Usually the size of the internal sparse array is equal or greater than
* the one of the internal packed array.
*
* @return Number of elements.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return packed.size();
}
/**
* @brief Checks whether a sparse set is empty.
* @return True if the sparse set is empty, false otherwise.
*/
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
return packed.empty();
}
/**
* @brief Direct access to the internal packed array.
* @return A pointer to the internal packed array.
*/
[[nodiscard]] pointer data() const ENTT_NOEXCEPT {
return packed.data();
}
/**
* @brief Returns an iterator to the beginning.
*
* The returned iterator points to the first entity of the internal packed
* array. If the sparse set is empty, the returned iterator will be equal to
* `end()`.
*
* @return An iterator to the first entity of the sparse set.
*/
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
const auto pos = static_cast<typename iterator::difference_type>(packed.size());
return iterator{packed, pos};
}
/*! @copydoc begin */
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
return begin();
}
/**
* @brief Returns an iterator to the end.
*
* The returned iterator points to the element following the last entity in
* a sparse set. Attempting to dereference the returned iterator results in
* undefined behavior.
*
* @return An iterator to the element following the last entity of a sparse
* set.
*/
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return iterator{packed, {}};
}
/*! @copydoc end */
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
return end();
}
/**
* @brief Returns a reverse iterator to the beginning.
*
* The returned iterator points to the first entity of the reversed internal
* packed array. If the sparse set is empty, the returned iterator will be
* equal to `rend()`.
*
* @return An iterator to the first entity of the reversed internal packed
* array.
*/
[[nodiscard]] const_reverse_iterator rbegin() const ENTT_NOEXCEPT {
return std::make_reverse_iterator(end());
}
/*! @copydoc rbegin */
[[nodiscard]] const_reverse_iterator crbegin() const ENTT_NOEXCEPT {
return rbegin();
}
/**
* @brief Returns a reverse iterator to the end.
*
* The returned iterator points to the element following the last entity in
* the reversed sparse set. Attempting to dereference the returned iterator
* results in undefined behavior.
*
* @return An iterator to the element following the last entity of the
* reversed sparse set.
*/
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
return std::make_reverse_iterator(begin());
}
/*! @copydoc rend */
[[nodiscard]] const_reverse_iterator crend() const ENTT_NOEXCEPT {
return rend();
}
/**
* @brief Finds an entity.
* @param entt A valid identifier.
* @return An iterator to the given entity if it's found, past the end
* iterator otherwise.
*/
[[nodiscard]] iterator find(const entity_type entt) const ENTT_NOEXCEPT {
return contains(entt) ? --(end() - index(entt)) : end();
}
/**
* @brief Checks if a sparse set contains an entity.
* @param entt A valid identifier.
* @return True if the sparse set contains the entity, false otherwise.
*/
[[nodiscard]] bool contains(const entity_type entt) const ENTT_NOEXCEPT {
const auto elem = sparse_ptr(entt);
constexpr auto cap = entity_traits::to_entity(null);
// testing versions permits to avoid accessing the packed array
return elem && (((~cap & entity_traits::to_integral(entt)) ^ entity_traits::to_integral(*elem)) < cap);
}
/**
* @brief Returns the contained version for an identifier.
* @param entt A valid identifier.
* @return The version for the given identifier if present, the tombstone
* version otherwise.
*/
[[nodiscard]] version_type current(const entity_type entt) const {
const auto elem = sparse_ptr(entt);
constexpr auto fallback = entity_traits::to_version(tombstone);
return elem ? entity_traits::to_version(*elem) : fallback;
}
/**
* @brief Returns the position of an entity in a sparse set.
*
* @warning
* Attempting to get the position of an entity that doesn't belong to the
* sparse set results in undefined behavior.
*
* @param entt A valid identifier.
* @return The position of the entity in the sparse set.
*/
[[nodiscard]] size_type index(const entity_type entt) const ENTT_NOEXCEPT {
ENTT_ASSERT(contains(entt), "Set does not contain entity");
return static_cast<size_type>(entity_traits::to_entity(sparse_ref(entt)));
}
/**
* @brief Returns the entity at specified location, with bounds checking.
* @param pos The position for which to return the entity.
* @return The entity at specified location if any, a null entity otherwise.
*/
[[nodiscard]] entity_type at(const size_type pos) const ENTT_NOEXCEPT {
return pos < packed.size() ? packed[pos] : null;
}
/**
* @brief Returns the entity at specified location, without bounds checking.
* @param pos The position for which to return the entity.
* @return The entity at specified location.
*/
[[nodiscard]] entity_type operator[](const size_type pos) const ENTT_NOEXCEPT {
ENTT_ASSERT(pos < packed.size(), "Position is out of bounds");
return packed[pos];
}
/**
* @brief Returns the element assigned to an entity, if any.
*
* @warning
* Attempting to use an entity that doesn't belong to the sparse set results
* in undefined behavior.
*
* @param entt A valid identifier.
* @return An opaque pointer to the element assigned to the entity, if any.
*/
const void *get(const entity_type entt) const ENTT_NOEXCEPT {
ENTT_ASSERT(contains(entt), "Set does not contain entity");
return get_at(index(entt));
}
/*! @copydoc get */
void *get(const entity_type entt) ENTT_NOEXCEPT {
return const_cast<void *>(std::as_const(*this).get(entt));
}
/**
* @brief Assigns an entity to a sparse set.
*
* @warning
* Attempting to assign an entity that already belongs to the sparse set
* results in undefined behavior.
*
* @param entt A valid identifier.
* @param value Optional opaque value to forward to mixins, if any.
*/
void emplace(const entity_type entt, const void *value = nullptr) {
try_emplace(entt, value);
ENTT_ASSERT(contains(entt), "Emplace did not take place");
}
/**
* @brief Assigns one or more entities to a sparse set.
*
* @warning
* Attempting to assign an entity that already belongs to the sparse set
* results in undefined behavior.
*
* @tparam It Type of input iterator.
* @param first An iterator to the first element of the range of entities.
* @param last An iterator past the last element of the range of entities.
*/
template<typename It>
void insert(It first, It last) {
for(; first != last && free_list != null; ++first) {
emplace(*first);
}
reserve(packed.size() + std::distance(first, last));
for(; first != last; ++first) {
emplace(*first);
}
}
/**
* @brief Erases an entity from a sparse set.
*
* @warning
* Attempting to erase an entity that doesn't belong to the sparse set
* results in undefined behavior.
*
* @param entt A valid identifier.
*/
void erase(const entity_type entt) {
ENTT_ASSERT(contains(entt), "Set does not contain entity");
(mode == deletion_policy::in_place) ? in_place_pop(entt) : swap_and_pop(entt);
ENTT_ASSERT(!contains(entt), "Destruction did not take place");
}
/**
* @brief Erases entities from a set.
*
* @sa erase
*
* @tparam It Type of input iterator.
* @param first An iterator to the first element of the range of entities.
* @param last An iterator past the last element of the range of entities.
*/
template<typename It>
void erase(It first, It last) {
for(; first != last; ++first) {
erase(*first);
}
}
/**
* @brief Removes an entity from a sparse set if it exists.
* @param entt A valid identifier.
* @return True if the entity is actually removed, false otherwise.
*/
bool remove(const entity_type entt) {
return contains(entt) && (erase(entt), true);
}
/**
* @brief Removes entities from a sparse set if they exist.
* @tparam It Type of input iterator.
* @param first An iterator to the first element of the range of entities.
* @param last An iterator past the last element of the range of entities.
* @return The number of entities actually removed.
*/
template<typename It>
size_type remove(It first, It last) {
size_type found{};
for(; first != last; ++first) {
found += remove(*first);
}
return found;
}
/*! @brief Removes all tombstones from the packed array of a sparse set. */
void compact() {
size_type next = packed.size();
for(; next && packed[next - 1u] == tombstone; --next) {}
for(auto *it = &free_list; *it != null && next; it = std::addressof(packed[entity_traits::to_entity(*it)])) {
if(const size_type pos = entity_traits::to_entity(*it); pos < next) {
--next;
move_and_pop(next, pos);
std::swap(packed[next], packed[pos]);
const auto entity = static_cast<typename entity_traits::entity_type>(pos);
sparse_ref(packed[pos]) = entity_traits::combine(entity, entity_traits::to_integral(packed[pos]));
*it = entity_traits::combine(static_cast<typename entity_traits::entity_type>(next), entity_traits::reserved);
for(; next && packed[next - 1u] == tombstone; --next) {}
}
}
free_list = tombstone;
packed.resize(next);
}
/**
* @copybrief swap_at
*
* For what it's worth, this function affects both the internal sparse array
* and the internal packed array. Users should not care of that anyway.
*
* @warning
* Attempting to swap entities that don't belong to the sparse set results
* in undefined behavior.
*
* @param lhs A valid identifier.
* @param rhs A valid identifier.
*/
void swap_elements(const entity_type lhs, const entity_type rhs) {
ENTT_ASSERT(contains(lhs) && contains(rhs), "Set does not contain entities");
auto &entt = sparse_ref(lhs);
auto &other = sparse_ref(rhs);
const auto from = entity_traits::to_entity(entt);
const auto to = entity_traits::to_entity(other);
// basic no-leak guarantee (with invalid state) if swapping throws
swap_at(static_cast<size_type>(from), static_cast<size_type>(to));
entt = entity_traits::combine(to, entity_traits::to_integral(packed[from]));
other = entity_traits::combine(from, entity_traits::to_integral(packed[to]));
std::swap(packed[from], packed[to]);
}
/**
* @brief Sort the first count elements according to the given comparison
* function.
*
* The comparison function object must return `true` if the first element
* is _less_ than the second one, `false` otherwise. The signature of the
* comparison function should be equivalent to the following:
*
* @code{.cpp}
* bool(const Entity, const Entity);
* @endcode
*
* Moreover, the comparison function object shall induce a
* _strict weak ordering_ on the values.
*
* The sort function object must offer a member function template
* `operator()` that accepts three arguments:
*
* * An iterator to the first element of the range to sort.
* * An iterator past the last element of the range to sort.
* * A comparison function to use to compare the elements.
*
* @tparam Compare Type of comparison function object.
* @tparam Sort Type of sort function object.
* @tparam Args Types of arguments to forward to the sort function object.
* @param length Number of elements to sort.
* @param compare A valid comparison function object.
* @param algo A valid sort function object.
* @param args Arguments to forward to the sort function object, if any.
*/
template<typename Compare, typename Sort = std_sort, typename... Args>
void sort_n(const size_type length, Compare compare, Sort algo = Sort{}, Args &&...args) {
ENTT_ASSERT(!(length > packed.size()), "Length exceeds the number of elements");
ENTT_ASSERT(free_list == null, "Partial sorting with tombstones is not supported");
algo(packed.rend() - length, packed.rend(), std::move(compare), std::forward<Args>(args)...);
for(size_type pos{}; pos < length; ++pos) {
auto curr = pos;
auto next = index(packed[curr]);
while(curr != next) {
const auto idx = index(packed[next]);
const auto entt = packed[curr];
swap_at(next, idx);
const auto entity = static_cast<typename entity_traits::entity_type>(curr);
sparse_ref(entt) = entity_traits::combine(entity, entity_traits::to_integral(packed[curr]));
curr = std::exchange(next, idx);
}
}
}
/**
* @brief Sort all elements according to the given comparison function.
*
* @sa sort_n
*
* @tparam Compare Type of comparison function object.
* @tparam Sort Type of sort function object.
* @tparam Args Types of arguments to forward to the sort function object.
* @param compare A valid comparison function object.
* @param algo A valid sort function object.
* @param args Arguments to forward to the sort function object, if any.
*/
template<typename Compare, typename Sort = std_sort, typename... Args>
void sort(Compare compare, Sort algo = Sort{}, Args &&...args) {
compact();
sort_n(packed.size(), std::move(compare), std::move(algo), std::forward<Args>(args)...);
}
/**
* @brief Sort entities according to their order in another sparse set.
*
* Entities that are part of both the sparse sets are ordered internally
* according to the order they have in `other`. All the other entities goes
* to the end of the list and there are no guarantees on their order.<br/>
* In other terms, this function can be used to impose the same order on two
* sets by using one of them as a master and the other one as a slave.
*
* Iterating the sparse set with a couple of iterators returns elements in
* the expected order after a call to `respect`. See `begin` and `end` for
* more details.
*
* @param other The sparse sets that imposes the order of the entities.
*/
void respect(const basic_sparse_set &other) {
compact();
const auto to = other.end();
auto from = other.begin();
for(size_type pos = packed.size() - 1; pos && from != to; ++from) {
if(contains(*from)) {
if(*from != packed[pos]) {
// basic no-leak guarantee (with invalid state) if swapping throws
swap_elements(packed[pos], *from);
}
--pos;
}
}
}
/*! @brief Clears a sparse set. */
void clear() {
for(auto &&entity: *this) {
// honor the modality and filter all tombstones
remove(entity);
}
}
/**
* @brief Returned value type, if any.
* @return Returned value type, if any.
*/
const type_info &type() const ENTT_NOEXCEPT {
return *info;
}
/*! @brief Forwards variables to mixins, if any. */
virtual void bind(any) ENTT_NOEXCEPT {}
private:
sparse_container_type sparse;
packed_container_type packed;
const type_info *info;
entity_type free_list;
deletion_policy mode;
};
} // namespace entt
#endif

1104
src/entt/entity/storage.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
#ifndef ENTT_ENTITY_UTILITY_HPP
#define ENTT_ENTITY_UTILITY_HPP
#include "../core/type_traits.hpp"
namespace entt {
/**
* @brief Alias for exclusion lists.
* @tparam Type List of types.
*/
template<typename... Type>
struct exclude_t: type_list<Type...> {};
/**
* @brief Variable template for exclusion lists.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr exclude_t<Type...> exclude{};
/**
* @brief Alias for lists of observed components.
* @tparam Type List of types.
*/
template<typename... Type>
struct get_t: type_list<Type...> {};
/**
* @brief Variable template for lists of observed components.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr get_t<Type...> get{};
/**
* @brief Alias for lists of owned components.
* @tparam Type List of types.
*/
template<typename... Type>
struct owned_t: type_list<Type...> {};
/**
* @brief Variable template for lists of owned components.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr owned_t<Type...> owned{};
} // namespace entt
#endif

848
src/entt/entity/view.hpp Normal file
View File

@@ -0,0 +1,848 @@
#ifndef ENTT_ENTITY_VIEW_HPP
#define ENTT_ENTITY_VIEW_HPP
#include <algorithm>
#include <array>
#include <iterator>
#include <tuple>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "../core/iterator.hpp"
#include "../core/type_traits.hpp"
#include "component.hpp"
#include "entity.hpp"
#include "fwd.hpp"
#include "sparse_set.hpp"
#include "storage.hpp"
#include "utility.hpp"
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename Type, std::size_t Component, std::size_t Exclude>
class view_iterator final {
[[nodiscard]] bool valid() const {
return ((Component != 0u) || (*it != tombstone))
&& std::apply([entt = *it](const auto *...curr) { return (curr->contains(entt) && ...); }, pools)
&& std::apply([entt = *it](const auto *...curr) { return (!curr->contains(entt) && ...); }, filter);
}
public:
using iterator_type = typename Type::iterator;
using difference_type = typename std::iterator_traits<iterator_type>::difference_type;
using value_type = typename std::iterator_traits<iterator_type>::value_type;
using pointer = typename std::iterator_traits<iterator_type>::pointer;
using reference = typename std::iterator_traits<iterator_type>::reference;
using iterator_category = std::forward_iterator_tag;
view_iterator() ENTT_NOEXCEPT
: it{},
last{},
pools{},
filter{} {}
view_iterator(iterator_type curr, iterator_type to, std::array<const Type *, Component> all_of, std::array<const Type *, Exclude> none_of) ENTT_NOEXCEPT
: it{curr},
last{to},
pools{all_of},
filter{none_of} {
if(it != last && !valid()) {
++(*this);
}
}
view_iterator &operator++() ENTT_NOEXCEPT {
while(++it != last && !valid()) {}
return *this;
}
view_iterator operator++(int) ENTT_NOEXCEPT {
view_iterator orig = *this;
return ++(*this), orig;
}
[[nodiscard]] pointer operator->() const {
return &*it;
}
[[nodiscard]] reference operator*() const {
return *operator->();
}
template<typename LhsType, auto... LhsArgs, typename RhsType, auto... RhsArgs>
friend bool operator==(const view_iterator<LhsType, LhsArgs...> &, const view_iterator<RhsType, RhsArgs...> &) ENTT_NOEXCEPT;
private:
iterator_type it;
iterator_type last;
std::array<const Type *, Component> pools;
std::array<const Type *, Exclude> filter;
};
template<typename LhsType, auto... LhsArgs, typename RhsType, auto... RhsArgs>
[[nodiscard]] bool operator==(const view_iterator<LhsType, LhsArgs...> &lhs, const view_iterator<RhsType, RhsArgs...> &rhs) ENTT_NOEXCEPT {
return lhs.it == rhs.it;
}
template<typename LhsType, auto... LhsArgs, typename RhsType, auto... RhsArgs>
[[nodiscard]] bool operator!=(const view_iterator<LhsType, LhsArgs...> &lhs, const view_iterator<RhsType, RhsArgs...> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
template<typename It, typename... Storage>
struct extended_view_iterator final {
using difference_type = std::ptrdiff_t;
using value_type = decltype(std::tuple_cat(std::make_tuple(*std::declval<It>()), std::declval<Storage>().get_as_tuple({})...));
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using iterator_category = std::input_iterator_tag;
extended_view_iterator() = default;
extended_view_iterator(It from, std::tuple<Storage *...> storage) ENTT_NOEXCEPT
: it{from},
pools{storage} {}
extended_view_iterator &operator++() ENTT_NOEXCEPT {
return ++it, *this;
}
extended_view_iterator operator++(int) ENTT_NOEXCEPT {
extended_view_iterator orig = *this;
return ++(*this), orig;
}
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
return std::apply([entt = *it](auto *...curr) { return std::tuple_cat(std::make_tuple(entt), curr->get_as_tuple(entt)...); }, pools);
}
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
return operator*();
}
template<typename... Lhs, typename... Rhs>
friend bool operator==(const extended_view_iterator<Lhs...> &, const extended_view_iterator<Rhs...> &) ENTT_NOEXCEPT;
private:
It it;
std::tuple<Storage *...> pools;
};
template<typename... Lhs, typename... Rhs>
[[nodiscard]] bool operator==(const extended_view_iterator<Lhs...> &lhs, const extended_view_iterator<Rhs...> &rhs) ENTT_NOEXCEPT {
return lhs.it == rhs.it;
}
template<typename... Lhs, typename... Rhs>
[[nodiscard]] bool operator!=(const extended_view_iterator<Lhs...> &lhs, const extended_view_iterator<Rhs...> &rhs) ENTT_NOEXCEPT {
return !(lhs == rhs);
}
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief View implementation.
*
* Primary template isn't defined on purpose. All the specializations give a
* compile-time error, but for a few reasonable cases.
*/
template<typename, typename, typename, typename>
class basic_view;
/**
* @brief Multi component view.
*
* Multi component views iterate over those entities that have at least all the
* given components in their bags. During initialization, a multi component view
* looks at the number of entities available for each component and uses the
* smallest set in order to get a performance boost when iterate.
*
* @b Important
*
* Iterators aren't invalidated if:
*
* * New instances of the given components are created and assigned to entities.
* * The entity currently pointed is modified (as an example, if one of the
* given components is removed from the entity to which the iterator points).
* * The entity currently pointed is destroyed.
*
* In all other cases, modifying the pools iterated by the view in any way
* invalidates all the iterators and using them results in undefined behavior.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Component Types of components iterated by the view.
* @tparam Exclude Types of components used to filter the view.
*/
template<typename Entity, typename... Component, typename... Exclude>
class basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>> {
template<typename, typename, typename, typename>
friend class basic_view;
template<typename Comp>
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
template<std::size_t... Index>
[[nodiscard]] auto pools_to_array(std::index_sequence<Index...>) const ENTT_NOEXCEPT {
std::size_t pos{};
std::array<const base_type *, sizeof...(Component) - 1u> other{};
(static_cast<void>(std::get<Index>(pools) == view ? void() : void(other[pos++] = std::get<Index>(pools))), ...);
return other;
}
template<std::size_t Comp, std::size_t Other, typename... Args>
[[nodiscard]] auto dispatch_get(const std::tuple<Entity, Args...> &curr) const {
if constexpr(Comp == Other) {
return std::forward_as_tuple(std::get<Args>(curr)...);
} else {
return std::get<Other>(pools)->get_as_tuple(std::get<0>(curr));
}
}
template<std::size_t Comp, typename Func, std::size_t... Index>
void each(Func func, std::index_sequence<Index...>) const {
for(const auto curr: std::get<Comp>(pools)->each()) {
const auto entt = std::get<0>(curr);
if(((sizeof...(Component) != 1u) || (entt != tombstone))
&& ((Comp == Index || std::get<Index>(pools)->contains(entt)) && ...)
&& std::apply([entt](const auto *...cpool) { return (!cpool->contains(entt) && ...); }, filter)) {
if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_view>().get({})))>) {
std::apply(func, std::tuple_cat(std::make_tuple(entt), dispatch_get<Comp, Index>(curr)...));
} else {
std::apply(func, std::tuple_cat(dispatch_get<Comp, Index>(curr)...));
}
}
}
}
template<typename Func, std::size_t... Index>
void pick_and_each(Func func, std::index_sequence<Index...> seq) const {
((std::get<Index>(pools) == view ? each<Index>(std::move(func), seq) : void()), ...);
}
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Common type among all storage types. */
using base_type = std::common_type_t<typename storage_type<Component>::base_type...>;
/*! @brief Bidirectional iterator type. */
using iterator = internal::view_iterator<base_type, sizeof...(Component) - 1u, sizeof...(Exclude)>;
/*! @brief Iterable view type. */
using iterable = iterable_adaptor<internal::extended_view_iterator<iterator, storage_type<Component>...>>;
/*! @brief Default constructor to use to create empty, invalid views. */
basic_view() ENTT_NOEXCEPT
: pools{},
filter{},
view{} {}
/**
* @brief Constructs a multi-type view from a set of storage classes.
* @param component The storage for the types to iterate.
* @param epool The storage for the types used to filter the view.
*/
basic_view(storage_type<Component> &...component, const storage_type<Exclude> &...epool) ENTT_NOEXCEPT
: pools{&component...},
filter{&epool...},
view{(std::min)({&static_cast<const base_type &>(component)...}, [](auto *lhs, auto *rhs) { return lhs->size() < rhs->size(); })} {}
/**
* @brief Creates a new view driven by a given component in its iterations.
* @tparam Comp Type of component used to drive the iteration.
* @return A new view driven by the given component in its iterations.
*/
template<typename Comp>
[[nodiscard]] basic_view use() const ENTT_NOEXCEPT {
basic_view other{*this};
other.view = std::get<storage_type<Comp> *>(pools);
return other;
}
/**
* @brief Creates a new view driven by a given component in its iterations.
* @tparam Comp Index of the component used to drive the iteration.
* @return A new view driven by the given component in its iterations.
*/
template<std::size_t Comp>
[[nodiscard]] basic_view use() const ENTT_NOEXCEPT {
basic_view other{*this};
other.view = std::get<Comp>(pools);
return other;
}
/**
* @brief Returns the leading storage of a view.
* @return The leading storage of the view.
*/
const base_type &handle() const ENTT_NOEXCEPT {
return *view;
}
/**
* @brief Returns the storage for a given component type.
* @tparam Comp Type of component of which to return the storage.
* @return The storage for the given component type.
*/
template<typename Comp>
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
return *std::get<storage_type<Comp> *>(pools);
}
/**
* @brief Returns the storage for a given component type.
* @tparam Comp Index of component of which to return the storage.
* @return The storage for the given component type.
*/
template<std::size_t Comp>
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
return *std::get<Comp>(pools);
}
/**
* @brief Estimates the number of entities iterated by the view.
* @return Estimated number of entities iterated by the view.
*/
[[nodiscard]] size_type size_hint() const ENTT_NOEXCEPT {
return view->size();
}
/**
* @brief Returns an iterator to the first entity of the view.
*
* The returned iterator points to the first entity of the view. If the view
* is empty, the returned iterator will be equal to `end()`.
*
* @return An iterator to the first entity of the view.
*/
[[nodiscard]] iterator begin() const {
return iterator{view->begin(), view->end(), pools_to_array(std::index_sequence_for<Component...>{}), filter};
}
/**
* @brief Returns an iterator that is past the last entity of the view.
*
* The returned iterator points to the entity following the last entity of
* the view. Attempting to dereference the returned iterator results in
* undefined behavior.
*
* @return An iterator to the entity following the last entity of the view.
*/
[[nodiscard]] iterator end() const {
return iterator{view->end(), view->end(), pools_to_array(std::index_sequence_for<Component...>{}), filter};
}
/**
* @brief Returns the first entity of the view, if any.
* @return The first entity of the view if one exists, the null entity
* otherwise.
*/
[[nodiscard]] entity_type front() const {
const auto it = begin();
return it != end() ? *it : null;
}
/**
* @brief Returns the last entity of the view, if any.
* @return The last entity of the view if one exists, the null entity
* otherwise.
*/
[[nodiscard]] entity_type back() const {
auto it = view->rbegin();
for(const auto last = view->rend(); it != last && !contains(*it); ++it) {}
return it == view->rend() ? null : *it;
}
/**
* @brief Finds an entity.
* @param entt A valid identifier.
* @return An iterator to the given entity if it's found, past the end
* iterator otherwise.
*/
[[nodiscard]] iterator find(const entity_type entt) const {
return contains(entt) ? iterator{view->find(entt), view->end(), pools_to_array(std::index_sequence_for<Component...>{}), filter} : end();
}
/**
* @brief Returns the components assigned to the given entity.
* @param entt A valid identifier.
* @return The components assigned to the given entity.
*/
[[nodiscard]] decltype(auto) operator[](const entity_type entt) const {
return get<Component...>(entt);
}
/**
* @brief Checks if a view is properly initialized.
* @return True if the view is properly initialized, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return view != nullptr;
}
/**
* @brief Checks if a view contains an entity.
* @param entt A valid identifier.
* @return True if the view contains the given entity, false otherwise.
*/
[[nodiscard]] bool contains(const entity_type entt) const {
return std::apply([entt](const auto *...curr) { return (curr->contains(entt) && ...); }, pools)
&& std::apply([entt](const auto *...curr) { return (!curr->contains(entt) && ...); }, filter);
}
/**
* @brief Returns the components assigned to the given entity.
*
* @warning
* Attempting to use an entity that doesn't belong to the view results in
* undefined behavior.
*
* @tparam Comp Types of components to get.
* @param entt A valid identifier.
* @return The components assigned to the entity.
*/
template<typename... Comp>
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
ENTT_ASSERT(contains(entt), "View does not contain entity");
if constexpr(sizeof...(Comp) == 0) {
return std::apply([entt](auto *...curr) { return std::tuple_cat(curr->get_as_tuple(entt)...); }, pools);
} else if constexpr(sizeof...(Comp) == 1) {
return (std::get<storage_type<Comp> *>(pools)->get(entt), ...);
} else {
return std::tuple_cat(std::get<storage_type<Comp> *>(pools)->get_as_tuple(entt)...);
}
}
/**
* @brief Returns the components assigned to the given entity.
*
* @warning
* Attempting to use an entity that doesn't belong to the view results in
* undefined behavior.
*
* @tparam First Index of a component to get.
* @tparam Other Indexes of other components to get.
* @param entt A valid identifier.
* @return The components assigned to the entity.
*/
template<std::size_t First, std::size_t... Other>
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
ENTT_ASSERT(contains(entt), "View does not contain entity");
if constexpr(sizeof...(Other) == 0) {
return std::get<First>(pools)->get(entt);
} else {
return std::tuple_cat(std::get<First>(pools)->get_as_tuple(entt), std::get<Other>(pools)->get_as_tuple(entt)...);
}
}
/**
* @brief Iterates entities and components and applies the given function
* object to them.
*
* The function object is invoked for each entity. It is provided with the
* entity itself and a set of references to non-empty components. The
* _constness_ of the components is as requested.<br/>
* The signature of the function must be equivalent to one of the following
* forms:
*
* @code{.cpp}
* void(const entity_type, Type &...);
* void(Type &...);
* @endcode
*
* @tparam Func Type of the function object to invoke.
* @param func A valid function object.
*/
template<typename Func>
void each(Func func) const {
pick_and_each(std::move(func), std::index_sequence_for<Component...>{});
}
/**
* @brief Returns an iterable object to use to _visit_ a view.
*
* The iterable object returns a tuple that contains the current entity and
* a set of references to its non-empty components. The _constness_ of the
* components is as requested.
*
* @return An iterable object to use to _visit_ the view.
*/
[[nodiscard]] iterable each() const ENTT_NOEXCEPT {
return {internal::extended_view_iterator{begin(), pools}, internal::extended_view_iterator{end(), pools}};
}
/**
* @brief Combines two views in a _more specific_ one (friend function).
* @tparam Get Component list of the view to combine with.
* @tparam Excl Filter list of the view to combine with.
* @param other The view to combine with.
* @return A more specific view.
*/
template<typename... Get, typename... Excl>
[[nodiscard]] auto operator|(const basic_view<Entity, get_t<Get...>, exclude_t<Excl...>> &other) const ENTT_NOEXCEPT {
using view_type = basic_view<Entity, get_t<Component..., Get...>, exclude_t<Exclude..., Excl...>>;
return std::make_from_tuple<view_type>(std::tuple_cat(
std::apply([](auto *...curr) { return std::forward_as_tuple(*curr...); }, pools),
std::apply([](auto *...curr) { return std::forward_as_tuple(*curr...); }, other.pools),
std::apply([](const auto *...curr) { return std::forward_as_tuple(static_cast<const storage_type<Exclude> &>(*curr)...); }, filter),
std::apply([](const auto *...curr) { return std::forward_as_tuple(static_cast<const storage_type<Excl> &>(*curr)...); }, other.filter)));
}
private:
std::tuple<storage_type<Component> *...> pools;
std::array<const base_type *, sizeof...(Exclude)> filter;
const base_type *view;
};
/**
* @brief Single component view specialization.
*
* Single component views are specialized in order to get a boost in terms of
* performance. This kind of views can access the underlying data structure
* directly and avoid superfluous checks.
*
* @b Important
*
* Iterators aren't invalidated if:
*
* * New instances of the given component are created and assigned to entities.
* * The entity currently pointed is modified (as an example, the given
* component is removed from the entity to which the iterator points).
* * The entity currently pointed is destroyed.
*
* In all other cases, modifying the pool iterated by the view in any way
* invalidates all the iterators and using them results in undefined behavior.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Component Type of component iterated by the view.
*/
template<typename Entity, typename Component>
class basic_view<Entity, get_t<Component>, exclude_t<>, std::void_t<std::enable_if_t<!component_traits<std::remove_const_t<Component>>::in_place_delete>>> {
template<typename, typename, typename, typename>
friend class basic_view;
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
public:
/*! @brief Underlying entity identifier. */
using entity_type = Entity;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Common type among all storage types. */
using base_type = typename storage_type::base_type;
/*! @brief Random access iterator type. */
using iterator = typename base_type::iterator;
/*! @brief Reversed iterator type. */
using reverse_iterator = typename base_type::reverse_iterator;
/*! @brief Iterable view type. */
using iterable = decltype(std::declval<storage_type>().each());
/*! @brief Default constructor to use to create empty, invalid views. */
basic_view() ENTT_NOEXCEPT
: pools{},
filter{},
view{} {}
/**
* @brief Constructs a single-type view from a storage class.
* @param ref The storage for the type to iterate.
*/
basic_view(storage_type &ref) ENTT_NOEXCEPT
: pools{&ref},
filter{},
view{&ref} {}
/**
* @brief Returns the leading storage of a view.
* @return The leading storage of the view.
*/
const base_type &handle() const ENTT_NOEXCEPT {
return *view;
}
/**
* @brief Returns the storage for a given component type.
* @tparam Comp Type of component of which to return the storage.
* @return The storage for the given component type.
*/
template<typename... Comp>
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
static_assert((std::is_same_v<Comp, Component> && ...), "Invalid component type");
return *std::get<0>(pools);
}
/**
* @brief Returns the storage for a given component type.
* @tparam Comp Index of component of which to return the storage.
* @return The storage for the given component type.
*/
template<std::size_t Comp>
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
return *std::get<Comp>(pools);
}
/**
* @brief Returns the number of entities that have the given component.
* @return Number of entities that have the given component.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return view->size();
}
/**
* @brief Checks whether a view is empty.
* @return True if the view is empty, false otherwise.
*/
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
return view->empty();
}
/**
* @brief Returns an iterator to the first entity of the view.
*
* The returned iterator points to the first entity of the view. If the view
* is empty, the returned iterator will be equal to `end()`.
*
* @return An iterator to the first entity of the view.
*/
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
return view->begin();
}
/**
* @brief Returns an iterator that is past the last entity of the view.
*
* The returned iterator points to the entity following the last entity of
* the view. Attempting to dereference the returned iterator results in
* undefined behavior.
*
* @return An iterator to the entity following the last entity of the view.
*/
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return view->end();
}
/**
* @brief Returns an iterator to the first entity of the reversed view.
*
* The returned iterator points to the first entity of the reversed view. If
* the view is empty, the returned iterator will be equal to `rend()`.
*
* @return An iterator to the first entity of the reversed view.
*/
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
return view->rbegin();
}
/**
* @brief Returns an iterator that is past the last entity of the reversed
* view.
*
* The returned iterator points to the entity following the last entity of
* the reversed view. Attempting to dereference the returned iterator
* results in undefined behavior.
*
* @return An iterator to the entity following the last entity of the
* reversed view.
*/
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
return view->rend();
}
/**
* @brief Returns the first entity of the view, if any.
* @return The first entity of the view if one exists, the null entity
* otherwise.
*/
[[nodiscard]] entity_type front() const {
return empty() ? null : *begin();
}
/**
* @brief Returns the last entity of the view, if any.
* @return The last entity of the view if one exists, the null entity
* otherwise.
*/
[[nodiscard]] entity_type back() const {
return empty() ? null : *rbegin();
}
/**
* @brief Finds an entity.
* @param entt A valid identifier.
* @return An iterator to the given entity if it's found, past the end
* iterator otherwise.
*/
[[nodiscard]] iterator find(const entity_type entt) const {
return contains(entt) ? view->find(entt) : end();
}
/**
* @brief Returns the identifier that occupies the given position.
* @param pos Position of the element to return.
* @return The identifier that occupies the given position.
*/
[[nodiscard]] entity_type operator[](const size_type pos) const {
return begin()[pos];
}
/**
* @brief Returns the component assigned to the given entity.
* @param entt A valid identifier.
* @return The component assigned to the given entity.
*/
[[nodiscard]] decltype(auto) operator[](const entity_type entt) const {
return get<Component>(entt);
}
/**
* @brief Checks if a view is properly initialized.
* @return True if the view is properly initialized, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return view != nullptr;
}
/**
* @brief Checks if a view contains an entity.
* @param entt A valid identifier.
* @return True if the view contains the given entity, false otherwise.
*/
[[nodiscard]] bool contains(const entity_type entt) const {
return view->contains(entt);
}
/**
* @brief Returns the component assigned to the given entity.
*
* @warning
* Attempting to use an entity that doesn't belong to the view results in
* undefined behavior.
*
* @tparam Comp Type or index of the component to get.
* @param entt A valid identifier.
* @return The component assigned to the entity.
*/
template<typename... Comp>
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
ENTT_ASSERT(contains(entt), "View does not contain entity");
if constexpr(sizeof...(Comp) == 0) {
return std::get<0>(pools)->get_as_tuple(entt);
} else {
static_assert(std::is_same_v<Comp..., Component>, "Invalid component type");
return std::get<0>(pools)->get(entt);
}
}
/*! @copydoc get */
template<std::size_t Comp>
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
ENTT_ASSERT(contains(entt), "View does not contain entity");
return std::get<0>(pools)->get(entt);
}
/**
* @brief Iterates entities and components and applies the given function
* object to them.
*
* The function object is invoked for each entity. It is provided with the
* entity itself and a reference to the component if it's a non-empty one.
* The _constness_ of the component is as requested.<br/>
* The signature of the function must be equivalent to one of the following
* forms:
*
* @code{.cpp}
* void(const entity_type, Component &);
* void(Component &);
* @endcode
*
* @tparam Func Type of the function object to invoke.
* @param func A valid function object.
*/
template<typename Func>
void each(Func func) const {
if constexpr(ignore_as_empty_v<std::remove_const_t<Component>>) {
if constexpr(std::is_invocable_v<Func>) {
for(size_type pos{}, last = size(); pos < last; ++pos) {
func();
}
} else {
for(auto entity: *view) {
func(entity);
}
}
} else {
if constexpr(is_applicable_v<Func, decltype(*each().begin())>) {
for(const auto pack: each()) {
std::apply(func, pack);
}
} else {
for(auto &&component: *std::get<0>(pools)) {
func(component);
}
}
}
}
/**
* @brief Returns an iterable object to use to _visit_ a view.
*
* The iterable object returns a tuple that contains the current entity and
* a reference to its component if it's a non-empty one. The _constness_ of
* the component is as requested.
*
* @return An iterable object to use to _visit_ the view.
*/
[[nodiscard]] iterable each() const ENTT_NOEXCEPT {
return std::get<0>(pools)->each();
}
/**
* @brief Combines two views in a _more specific_ one (friend function).
* @tparam Get Component list of the view to combine with.
* @tparam Excl Filter list of the view to combine with.
* @param other The view to combine with.
* @return A more specific view.
*/
template<typename... Get, typename... Excl>
[[nodiscard]] auto operator|(const basic_view<Entity, get_t<Get...>, exclude_t<Excl...>> &other) const ENTT_NOEXCEPT {
using view_type = basic_view<Entity, get_t<Component, Get...>, exclude_t<Excl...>>;
return std::make_from_tuple<view_type>(std::tuple_cat(
std::forward_as_tuple(*std::get<0>(pools)),
std::apply([](auto *...curr) { return std::forward_as_tuple(*curr...); }, other.pools),
std::apply([](const auto *...curr) { return std::forward_as_tuple(static_cast<const typename view_type::template storage_type<Excl> &>(*curr)...); }, other.filter)));
}
private:
std::tuple<storage_type *> pools;
std::array<const base_type *, 0u> filter;
const base_type *view;
};
/**
* @brief Deduction guide.
* @tparam Storage Type of storage classes used to create the view.
* @param storage The storage for the types to iterate.
*/
template<typename... Storage>
basic_view(Storage &...storage) -> basic_view<std::common_type_t<typename Storage::entity_type...>, get_t<constness_as_t<typename Storage::value_type, Storage>...>, exclude_t<>>;
} // namespace entt
#endif

57
src/entt/entt.hpp Normal file
View File

@@ -0,0 +1,57 @@
#include "config/version.h"
#include "container/dense_hash_map.hpp"
#include "container/dense_hash_set.hpp"
#include "core/algorithm.hpp"
#include "core/any.hpp"
#include "core/attribute.h"
#include "core/compressed_pair.hpp"
#include "core/enum.hpp"
#include "core/family.hpp"
#include "core/hashed_string.hpp"
#include "core/ident.hpp"
#include "core/iterator.hpp"
#include "core/memory.hpp"
#include "core/monostate.hpp"
#include "core/tuple.hpp"
#include "core/type_info.hpp"
#include "core/type_traits.hpp"
#include "core/utility.hpp"
#include "entity/component.hpp"
#include "entity/entity.hpp"
#include "entity/group.hpp"
#include "entity/handle.hpp"
#include "entity/helper.hpp"
#include "entity/observer.hpp"
#include "entity/organizer.hpp"
#include "entity/registry.hpp"
#include "entity/runtime_view.hpp"
#include "entity/snapshot.hpp"
#include "entity/sparse_set.hpp"
#include "entity/storage.hpp"
#include "entity/utility.hpp"
#include "entity/view.hpp"
#include "locator/locator.hpp"
#include "meta/adl_pointer.hpp"
#include "meta/container.hpp"
#include "meta/ctx.hpp"
#include "meta/factory.hpp"
#include "meta/meta.hpp"
#include "meta/node.hpp"
#include "meta/pointer.hpp"
#include "meta/policy.hpp"
#include "meta/range.hpp"
#include "meta/resolve.hpp"
#include "meta/template.hpp"
#include "meta/type_traits.hpp"
#include "meta/utility.hpp"
#include "platform/android-ndk-r17.hpp"
#include "poly/poly.hpp"
#include "process/process.hpp"
#include "process/scheduler.hpp"
#include "resource/cache.hpp"
#include "resource/handle.hpp"
#include "resource/loader.hpp"
#include "signal/delegate.hpp"
#include "signal/dispatcher.hpp"
#include "signal/emitter.hpp"
#include "signal/sigh.hpp"

7
src/entt/fwd.hpp Normal file
View File

@@ -0,0 +1,7 @@
#include "container/fwd.hpp"
#include "core/fwd.hpp"
#include "entity/fwd.hpp"
#include "meta/fwd.hpp"
#include "poly/fwd.hpp"
#include "resource/fwd.hpp"
#include "signal/fwd.hpp"

Some files were not shown because too many files have changed in this diff Show More