🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

427 lines
16 KiB

  1. ![EnTT: Gaming meets modern C++](https://user-images.githubusercontent.com/1812216/103550016-90752280-4ea8-11eb-8667-12ed2219e137.png)
  2. <!--
  3. @cond TURN_OFF_DOXYGEN
  4. -->
  5. [![Build Status](https://github.com/skypjack/entt/workflows/build/badge.svg)](https://github.com/skypjack/entt/actions)
  6. [![Coverage](https://codecov.io/gh/skypjack/entt/branch/master/graph/badge.svg)](https://codecov.io/gh/skypjack/entt)
  7. [![Try online](https://img.shields.io/badge/try-online-brightgreen)](https://godbolt.org/z/zxW73f)
  8. [![Documentation](https://img.shields.io/badge/docs-docsforge-blue)](http://entt.docsforge.com/)
  9. [![Gitter chat](https://badges.gitter.im/skypjack/entt.png)](https://gitter.im/skypjack/entt)
  10. [![Discord channel](https://img.shields.io/discord/707607951396962417?logo=discord)](https://discord.gg/5BjPWBd)
  11. [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/skypjack)
  12. > `EnTT` has been a dream so far, we haven't found a single bug to date and it's
  13. > super easy to work with
  14. `EnTT` is a header-only, tiny and easy to use library for game programming and
  15. much more written in **modern C++**.<br/>
  16. [Among others](https://github.com/skypjack/entt/wiki/EnTT-in-Action), it's used
  17. in [**Minecraft**](https://minecraft.net/en-us/attribution/) by Mojang, the
  18. [**ArcGIS Runtime SDKs**](https://developers.arcgis.com/arcgis-runtime/) by Esri
  19. and the amazing [**Ragdoll**](https://ragdolldynamics.com/).<br/>
  20. If you don't see your project in the list, please open an issue, submit a PR or
  21. add the [#entt](https://github.com/topics/entt) tag to your _topics_! :+1:
  22. ---
  23. Do you want to **keep up with changes** or do you have a **question** that
  24. doesn't require you to open an issue?<br/>
  25. Join the [gitter channel](https://gitter.im/skypjack/entt) and the
  26. [discord server](https://discord.gg/5BjPWBd), meet other users like you. The
  27. more we are, the better for everyone.<br/>
  28. Don't forget to check the
  29. [FAQs](https://github.com/skypjack/entt/wiki/Frequently-Asked-Questions) and the
  30. [wiki](https://github.com/skypjack/entt/wiki) too. Your answers may already be
  31. there.
  32. Do you want to support `EnTT`? Consider becoming a
  33. [**sponsor**](https://github.com/users/skypjack/sponsorship).
  34. Many thanks to [these people](https://skypjack.github.io/sponsorship/) and
  35. **special** thanks to:
  36. [![mojang](https://user-images.githubusercontent.com/1812216/106253145-67ca1980-6217-11eb-9c0b-d93561b37098.png)](https://mojang.com)
  37. [![imgly](https://user-images.githubusercontent.com/1812216/106253726-271ed000-6218-11eb-98e0-c9c681925770.png)](https://img.ly/)
  38. # Table of Contents
  39. * [Introduction](#introduction)
  40. * [Code Example](#code-example)
  41. * [Motivation](#motivation)
  42. * [Performance](#performance)
  43. * [Integration](#integration)
  44. * [Requirements](#requirements)
  45. * [CMake](#cmake)
  46. * [Natvis support](#natvis-support)
  47. * [Packaging Tools](#packaging-tools)
  48. * [pkg-config](#pkg-config)
  49. * [Documentation](#documentation)
  50. * [Tests](#tests)
  51. * [EnTT in Action](#entt-in-action)
  52. * [Contributors](#contributors)
  53. * [License](#license)
  54. <!--
  55. @endcond TURN_OFF_DOXYGEN
  56. -->
  57. # Introduction
  58. The entity-component-system (also known as _ECS_) is an architectural pattern
  59. used mostly in game development. For further details:
  60. * [Entity Systems Wiki](http://entity-systems.wikidot.com/)
  61. * [Evolve Your Hierarchy](http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/)
  62. * [ECS on Wikipedia](https://en.wikipedia.org/wiki/Entity%E2%80%93component%E2%80%93system)
  63. This project started off as a pure entity-component system. Over time the
  64. codebase has grown as more and more classes and functionalities were added.<br/>
  65. Here is a brief, yet incomplete list of what it offers today:
  66. * Built-in **RTTI system** mostly similar to the standard one.
  67. * A `constexpr` utility for human readable **resource names**.
  68. * Minimal **configuration system** built using the monostate pattern.
  69. * Incredibly fast **entity-component system** with its own _pay for what you
  70. use_ policy.
  71. * Views and groups to iterate entities and components and allow different access
  72. patterns, from **perfect SoA** to fully random.
  73. * A lot of **facilities** built on top of the entity-component system to help
  74. the users and avoid reinventing the wheel.
  75. * The smallest and most basic implementation of a **service locator** ever seen.
  76. * A built-in, non-intrusive and macro-free runtime **reflection system**.
  77. * **Static polymorphism** made simple and within everyone's reach.
  78. * A few homemade containers, like a sparse set based **hash map**.
  79. * A **cooperative scheduler** for processes of any type.
  80. * All that is needed for **resource management** (cache, loaders, handles).
  81. * Delegates, **signal handlers** and a tiny event dispatcher.
  82. * A general purpose **event emitter** as a CRTP idiom based class template.
  83. * And **much more**! Check out the
  84. [**wiki**](https://github.com/skypjack/entt/wiki).
  85. Consider these lists a work in progress as well as the project. The whole API is
  86. fully documented in-code for those who are brave enough to read it.<br/>
  87. Please, do note that all tools are also DLL-friendly now and run smoothly across
  88. boundaries.
  89. One thing known to most is that `EnTT` is also used in **Minecraft**.<br/>
  90. Given that the game is available literally everywhere, I can confidently say
  91. that the library has been sufficiently tested on every platform that can come to
  92. mind.
  93. ## Code Example
  94. ```cpp
  95. #include <entt/entt.hpp>
  96. struct position {
  97. float x;
  98. float y;
  99. };
  100. struct velocity {
  101. float dx;
  102. float dy;
  103. };
  104. void update(entt::registry &registry) {
  105. auto view = registry.view<const position, velocity>();
  106. // use a callback
  107. view.each([](const auto &pos, auto &vel) { /* ... */ });
  108. // use an extended callback
  109. view.each([](const auto entity, const auto &pos, auto &vel) { /* ... */ });
  110. // use a range-for
  111. for(auto [entity, pos, vel]: view.each()) {
  112. // ...
  113. }
  114. // use forward iterators and get only the components of interest
  115. for(auto entity: view) {
  116. auto &vel = view.get<velocity>(entity);
  117. // ...
  118. }
  119. }
  120. int main() {
  121. entt::registry registry;
  122. for(auto i = 0u; i < 10u; ++i) {
  123. const auto entity = registry.create();
  124. registry.emplace<position>(entity, i * 1.f, i * 1.f);
  125. if(i % 2 == 0) { registry.emplace<velocity>(entity, i * .1f, i * .1f); }
  126. }
  127. update(registry);
  128. }
  129. ```
  130. ## Motivation
  131. I started developing `EnTT` for the _wrong_ reason: my goal was to design an
  132. entity-component system to beat another well known open source library both in
  133. terms of performance and possibly memory usage.<br/>
  134. In the end, I did it, but it wasn't very satisfying. Actually it wasn't
  135. satisfying at all. The fastest and nothing more, fairly little indeed. When I
  136. realized it, I tried hard to keep intact the great performance of `EnTT` and to
  137. add all the features I wanted to see in *my own library* at the same time.
  138. Nowadays, `EnTT` is finally what I was looking for: still faster than its
  139. _competitors_, lower memory usage in the average case, a really good API and an
  140. amazing set of features. And even more, of course.
  141. ## Performance
  142. The proposed entity-component system is incredibly fast to iterate entities and
  143. components, this is a fact. Some compilers make a lot of optimizations because
  144. of how `EnTT` works, some others aren't that good. In general, if we consider
  145. real world cases, `EnTT` is somewhere between a bit and much faster than many of
  146. the other solutions around, although I couldn't check them all for obvious
  147. reasons.
  148. If you are interested, you can compile the `benchmark` test in release mode (to
  149. enable compiler optimizations, otherwise it would make little sense) by setting
  150. the `ENTT_BUILD_BENCHMARK` option of `CMake` to `ON`, then evaluate yourself
  151. whether you're satisfied with the results or not.
  152. Honestly I got tired of updating the README file whenever there is an
  153. improvement.<br/>
  154. There are already a lot of projects out there that use `EnTT` as a basis for
  155. comparison (this should already tell you a lot). Many of these benchmarks are
  156. completely wrong, many others are simply incomplete, good at omitting some
  157. information and using the wrong function to compare a given feature. Certainly
  158. there are also good ones but they age quickly if nobody updates them, especially
  159. when the library they are dealing with is actively developed.
  160. The choice to use `EnTT` should be based on its carefully designed API, its
  161. set of features and the general performance, **not** because some single
  162. benchmark shows it to be the fastest tool available.
  163. In the future I'll likely try to get even better performance while still adding
  164. new features, mainly for fun.<br/>
  165. If you want to contribute and/or have suggestions, feel free to make a PR or
  166. open an issue to discuss your idea.
  167. # Integration
  168. `EnTT` is a header-only library. This means that including the `entt.hpp` header
  169. is enough to include the library as a whole and use it. For those who are
  170. interested only in the entity-component system, consider to include the sole
  171. `entity/registry.hpp` header instead.<br/>
  172. It's a matter of adding the following line to the top of a file:
  173. ```cpp
  174. #include <entt/entt.hpp>
  175. ```
  176. Use the line below to include only the entity-component system instead:
  177. ```cpp
  178. #include <entt/entity/registry.hpp>
  179. ```
  180. Then pass the proper `-I` argument to the compiler to add the `src` directory to
  181. the include paths.
  182. ## Requirements
  183. To be able to use `EnTT`, users must provide a full-featured compiler that
  184. supports at least C++17.<br/>
  185. The requirements below are mandatory to compile the tests and to extract the
  186. documentation:
  187. * `CMake` version 3.7 or later.
  188. * `Doxygen` version 1.8 or later.
  189. Alternatively, [Bazel](https://bazel.build) is also supported as a build system
  190. (credits to [zaucy](https://github.com/zaucy) who offered to maintain it).<br/>
  191. In the documentation below I'll still refer to `CMake`, this being the official
  192. build system of the library.
  193. ## CMake
  194. To use `EnTT` from a `CMake` project, just link an existing target to the
  195. `EnTT::EnTT` alias.<br/>
  196. The library offers everything you need for locating (as in `find_package`),
  197. embedding (as in `add_subdirectory`), fetching (as in `FetchContent`) or using
  198. it in many of the ways that you can think of and that involve `CMake`.<br/>
  199. Covering all possible cases would require a treaty and not a simple README file,
  200. but I'm confident that anyone reading this section also knows what it's about
  201. and can use `EnTT` from a `CMake` project without problems.
  202. ## Natvis support
  203. When using `CMake`, just enable the option `ENTT_INCLUDE_NATVIS` and enjoy
  204. it.<br/>
  205. Otherwise, most of the tools are covered via Natvis and all files can be found
  206. in the `natvis` directory, divided by module.<br/>
  207. If you spot errors or have suggestions, any contribution is welcome!
  208. ## Packaging Tools
  209. `EnTT` is available for some of the most known packaging tools. In particular:
  210. * [`Conan`](https://github.com/conan-io/conan-center-index), the C/C++ Package
  211. Manager for Developers.
  212. * [`vcpkg`](https://github.com/Microsoft/vcpkg), Microsoft VC++ Packaging
  213. Tool.<br/>
  214. You can download and install `EnTT` in just a few simple steps:
  215. ```
  216. $ git clone https://github.com/Microsoft/vcpkg.git
  217. $ cd vcpkg
  218. $ ./bootstrap-vcpkg.sh
  219. $ ./vcpkg integrate install
  220. $ vcpkg install entt
  221. ```
  222. Or you can use the `experimental` feature to test the latest changes:
  223. ```
  224. vcpkg install entt[experimental] --head
  225. ```
  226. The `EnTT` port in `vcpkg` is kept up to date by Microsoft team members and
  227. community contributors.<br/>
  228. If the version is out of date, please
  229. [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the
  230. `vcpkg` repository.
  231. * [`Homebrew`](https://github.com/skypjack/homebrew-entt), the missing package
  232. manager for macOS.<br/>
  233. Available as a homebrew formula. Just type the following to install it:
  234. ```
  235. brew install skypjack/entt/entt
  236. ```
  237. * [`build2`](https://build2.org), build toolchain for developing and packaging C
  238. and C++ code.<br/>
  239. In order to use the [`entt`](https://cppget.org/entt) package in a `build2`
  240. project, add the following line or a similar one to the `manifest` file:
  241. ```
  242. depends: entt ^3.0.0
  243. ```
  244. Also check that the configuration refers to a valid repository, so that the
  245. package can be found by `build2`:
  246. * [`cppget.org`](https://cppget.org), the open-source community central
  247. repository, accessible as `https://pkg.cppget.org/1/stable`.
  248. * [Package source repository](https://github.com/build2-packaging/entt):
  249. accessible as either `https://github.com/build2-packaging/entt.git` or
  250. `ssh://git@github.com/build2-packaging/entt.git`.
  251. Feel free to [report issues](https://github.com/build2-packaging/entt) with
  252. this package.
  253. Both can be used with `bpkg add-repo` or added in a project
  254. `repositories.manifest`. See the official
  255. [documentation](https://build2.org/build2-toolchain/doc/build2-toolchain-intro.xhtml#guide-repositories)
  256. for more details.
  257. Consider this list a work in progress and help me to make it longer if you like.
  258. ## pkg-config
  259. `EnTT` also supports `pkg-config` (for some definition of _supports_ at least).
  260. A suitable file called `entt.pc` is generated and installed in a proper
  261. directory when running `CMake`.<br/>
  262. This should also make it easier to use with tools such as `Meson` or similar.
  263. # Documentation
  264. The documentation is based on [doxygen](http://www.doxygen.nl/). To build it:
  265. $ cd build
  266. $ cmake .. -DENTT_BUILD_DOCS=ON
  267. $ make
  268. The API reference will be created in HTML format within the directory
  269. `build/docs/html`. To navigate it with your favorite browser:
  270. $ cd build
  271. $ your_favorite_browser docs/html/index.html
  272. <!--
  273. @cond TURN_OFF_DOXYGEN
  274. -->
  275. The same version is also available [online](https://skypjack.github.io/entt/)
  276. for the latest release, that is the last stable tag. If you are looking for
  277. something more pleasing to the eye, consider reading the nice-looking version
  278. available on [docsforge](https://entt.docsforge.com/): same documentation, much
  279. more pleasant to read.<br/>
  280. Moreover, there exists a [wiki](https://github.com/skypjack/entt/wiki) dedicated
  281. to the project where users can find all related documentation pages.
  282. <!--
  283. @endcond TURN_OFF_DOXYGEN
  284. -->
  285. # Tests
  286. To compile and run the tests, `EnTT` requires *googletest*.<br/>
  287. `cmake` will download and compile the library before compiling anything else.
  288. In order to build the tests, set the `CMake` option `ENTT_BUILD_TESTING` to
  289. `ON`.
  290. To build the most basic set of tests:
  291. * `$ cd build`
  292. * `$ cmake -DENTT_BUILD_TESTING=ON ..`
  293. * `$ make`
  294. * `$ make test`
  295. Note that benchmarks are not part of this set.
  296. <!--
  297. @cond TURN_OFF_DOXYGEN
  298. -->
  299. # EnTT in Action
  300. `EnTT` is widely used in private and commercial applications. I cannot even
  301. mention most of them because of some signatures I put on some documents time
  302. ago. Fortunately, there are also people who took the time to implement open
  303. source projects based on `EnTT` and did not hold back when it came to
  304. documenting them.
  305. [Here](https://github.com/skypjack/entt/wiki/EnTT-in-Action) you can find an
  306. incomplete list of games, applications and articles that can be used as a
  307. reference.
  308. If you know of other resources out there that are about `EnTT`, feel free to
  309. open an issue or a PR and I'll be glad to add them to the list.
  310. # Contributors
  311. Requests for features, PRs, suggestions ad feedback are highly appreciated.
  312. If you find you can help and want to contribute to the project with your
  313. experience or you do want to get part of the project for some other reason, feel
  314. free to contact me directly (you can find the mail in the
  315. [profile](https://github.com/skypjack)).<br/>
  316. I can't promise that each and every contribution will be accepted, but I can
  317. assure that I'll do my best to take them all as soon as possible.
  318. If you decide to participate, please see the guidelines for
  319. [contributing](CONTRIBUTING.md) before to create issues or pull
  320. requests.<br/>
  321. Take also a look at the
  322. [contributors list](https://github.com/skypjack/entt/blob/master/AUTHORS) to
  323. know who has participated so far.
  324. <!--
  325. @endcond TURN_OFF_DOXYGEN
  326. -->
  327. # License
  328. Code and documentation Copyright (c) 2017-2022 Michele Caini.<br/>
  329. Colorful logo Copyright (c) 2018-2021 Richard Caseres.
  330. Code released under
  331. [the MIT license](https://github.com/skypjack/entt/blob/master/LICENSE).<br/>
  332. Documentation released under
  333. [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).<br/>
  334. All logos released under
  335. [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).