🛠️🐜 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.

411 lines
16 KiB

  1. ![EnTT: Gaming meets modern C++](https://user-images.githubusercontent.com/1812216/42513718-ee6e98d0-8457-11e8-9baf-8d83f61a3097.png)
  2. <!--
  3. @cond TURN_OFF_DOXYGEN
  4. -->
  5. [![GitHub version](https://badge.fury.io/gh/skypjack%2Fentt.svg)](http://badge.fury.io/gh/skypjack%2Fentt)
  6. [![LoC](https://tokei.rs/b1/github/skypjack/entt)](https://github.com/skypjack/entt)
  7. [![Build Status](https://travis-ci.org/skypjack/entt.svg?branch=master)](https://travis-ci.org/skypjack/entt)
  8. [![Build status](https://ci.appveyor.com/api/projects/status/rvhaabjmghg715ck?svg=true)](https://ci.appveyor.com/project/skypjack/entt)
  9. [![Coverage Status](https://coveralls.io/repos/github/skypjack/entt/badge.svg?branch=master)](https://coveralls.io/github/skypjack/entt?branch=master)
  10. [![Gitter chat](https://badges.gitter.im/skypjack/entt.png)](https://gitter.im/skypjack/entt)
  11. [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/skypjack)
  12. `EnTT` is a header-only, tiny and easy to use library for game programming and
  13. much more written in **modern C++**, mainly known for its innovative
  14. **entity-component-system (ECS)** model.<br/>
  15. [Among others](https://github.com/skypjack/entt/wiki/EnTT-in-Action), it's used
  16. in [**Minecraft**](https://minecraft.net/en-us/attribution/) by Mojang, the
  17. [**ArcGIS Runtime SDKs**](https://developers.arcgis.com/arcgis-runtime/) by Esri
  18. and [**The Forge**](https://github.com/ConfettiFX/The-Forge) by Confetti. Read
  19. on to find out what it can offer you.
  20. ---
  21. Do you want to **keep up with changes** or do you have a **question** that
  22. doesn't require you to open an issue?<br/>
  23. Join the [gitter channel](https://gitter.im/skypjack/entt) and meet other users
  24. like you. The more we are, the better for everyone.
  25. If you use `EnTT` and you want to say thanks or support the project, please
  26. **consider becoming a patron**:
  27. [![Patreon](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/bePatron?c=1772573)
  28. [Many thanks](https://skypjack.github.io/patreon/) to those who supported me and
  29. still support me today.
  30. # Table of Contents
  31. * [Introduction](#introduction)
  32. * [Code Example](#code-example)
  33. * [Motivation](#motivation)
  34. * [Performance](#performance)
  35. * [Build Instructions](#build-instructions)
  36. * [Requirements](#requirements)
  37. * [Library](#library)
  38. * [Documentation](#documentation)
  39. * [Tests](#tests)
  40. * [Packaging Tools](#packaging-tools)
  41. * [EnTT in Action](#entt-in-action)
  42. * [Contributors](#contributors)
  43. * [License](#license)
  44. * [Support](#support)
  45. * [Patreon](#patreon)
  46. * [Donation](#donation)
  47. * [Hire me](#hire-me)
  48. <!--
  49. @endcond TURN_OFF_DOXYGEN
  50. -->
  51. # Introduction
  52. The entity-component-system (also known as _ECS_) is an architectural pattern
  53. used mostly in game development. For further details:
  54. * [Entity Systems Wiki](http://entity-systems.wikidot.com/)
  55. * [Evolve Your Hierarchy](http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/)
  56. * [ECS on Wikipedia](https://en.wikipedia.org/wiki/Entity%E2%80%93component%E2%80%93system)
  57. This project started off as a pure entity-component system. Over time the
  58. codebase has grown as more and more classes and functionalities were added.<br/>
  59. Here is a brief, yet incomplete list of what it offers today:
  60. * Statically generated integer **identifiers for types** (assigned either at
  61. compile-time or at runtime).
  62. * A `constexpr` utility for **human readable resource identifiers**.
  63. * A minimal **configuration system** built using the monostate pattern.
  64. * An incredibly fast **entity-component system** based on sparse sets, with its
  65. own _pay for what you use_ policy to adjust performance and memory usage
  66. according to the users' requirements.
  67. * Views and groups to iterate entities and components and allow different access
  68. patterns, from **perfect SoA** to fully random.
  69. * A lot of **facilities** built on top of the entity-component system to support
  70. the users and avoid reinventing the wheel (dependencies, snapshot, actor class
  71. for those who aren't confident with the architecture and so on).
  72. * The smallest and most basic implementation of a **service locator** ever seen.
  73. * A built-in, non-intrusive and macro-free **runtime reflection system**.
  74. * A **cooperative scheduler** for processes of any type.
  75. * All that is needed for **resource management** (cache, loaders, handles).
  76. * **Delegates**, **signal handlers** (with built-in support for collectors) and
  77. a tiny **event dispatcher** for immediate and delayed events to integrate in
  78. loops.
  79. * A general purpose **event emitter** as a CRTP idiom based class template.
  80. * And **much more**! Check out the
  81. [**wiki**](https://github.com/skypjack/entt/wiki).
  82. Consider this list a work in progress as well as the project. The whole API is
  83. fully documented in-code for those who are brave enough to read it.
  84. Currently, `EnTT` is tested on Linux, Microsoft Windows and OSX. It has proven
  85. to work also on both Android and iOS.<br/>
  86. Most likely it won't be problematic on other systems as well, but it hasn't been
  87. sufficiently tested so far.
  88. ## Code Example
  89. ```cpp
  90. #include <entt/entt.hpp>
  91. #include <cstdint>
  92. struct position {
  93. float x;
  94. float y;
  95. };
  96. struct velocity {
  97. float dx;
  98. float dy;
  99. };
  100. void update(entt::registry &registry) {
  101. auto view = registry.view<position, velocity>();
  102. for(auto entity: view) {
  103. // gets only the components that are going to be used ...
  104. auto &vel = view.get<velocity>(entity);
  105. vel.dx = 0.;
  106. vel.dy = 0.;
  107. // ...
  108. }
  109. }
  110. void update(std::uint64_t dt, entt::registry &registry) {
  111. registry.view<position, velocity>().each([dt](auto &pos, auto &vel) {
  112. // gets all the components of the view at once ...
  113. pos.x += vel.dx * dt;
  114. pos.y += vel.dy * dt;
  115. // ...
  116. });
  117. }
  118. int main() {
  119. entt::registry registry;
  120. std::uint64_t dt = 16;
  121. for(auto i = 0; i < 10; ++i) {
  122. auto entity = registry.create();
  123. registry.assign<position>(entity, i * 1.f, i * 1.f);
  124. if(i % 2 == 0) { registry.assign<velocity>(entity, i * .1f, i * .1f); }
  125. }
  126. update(dt, registry);
  127. update(registry);
  128. // ...
  129. }
  130. ```
  131. ## Motivation
  132. I started developing `EnTT` for the _wrong_ reason: my goal was to design an
  133. entity-component system to beat another well known open source solution both in
  134. terms of performance and possibly memory usage.<br/>
  135. In the end, I did it, but it wasn't very satisfying. Actually it wasn't
  136. satisfying at all. The fastest and nothing more, fairly little indeed. When I
  137. realized it, I tried hard to keep intact the great performance of `EnTT` and to
  138. add all the features I wanted to see in *my own library* at the same time.
  139. Nowadays, `EnTT` is finally what I was looking for: still faster than its
  140. _competitors_, lower memory usage in the average case, a really good API and an
  141. amazing set of features. And even more, of course.
  142. ## Performance
  143. As it stands right now, `EnTT` is just fast enough for my requirements when
  144. compared to my first choice (it was already amazingly fast actually).<br/>
  145. Below is a comparison between the two (both of them compiled with GCC 7.3.0 on a
  146. Dell XPS 13 from mid 2014):
  147. | Benchmark | EntityX (compile-time) | EnTT |
  148. |-----------|-------------|-------------|
  149. | Create 1M entities | 0.0147s | **0.0046s** |
  150. | Destroy 1M entities | 0.0053s | **0.0045s** |
  151. | 1M entities, one component | 0.0012s | **1.9e-07s** |
  152. | 1M entities, two components | 0.0012s | **3.8e-07s** |
  153. | 1M entities, two components<br/>Half of the entities have all the components | 0.0009s | **3.8e-07s** |
  154. | 1M entities, two components<br/>One of the entities has all the components | 0.0008s | **1.0e-06s** |
  155. | 1M entities, five components | 0.0010s | **7.0e-07s** |
  156. | 1M entities, ten components | 0.0011s | **1.2e-06s** |
  157. | 1M entities, ten components<br/>Half of the entities have all the components | 0.0010s | **1.2e-06s** |
  158. | 1M entities, ten components<br/>One of the entities has all the components | 0.0008s | **1.2e-06s** |
  159. | Sort 150k entities, one component<br/>Arrays are in reverse order | - | **0.0036s** |
  160. | Sort 150k entities, enforce permutation<br/>Arrays are in reverse order | - | **0.0005s** |
  161. | Sort 150k entities, one component<br/>Arrays are almost sorted, std::sort | - | **0.0035s** |
  162. | Sort 150k entities, one component<br/>Arrays are almost sorted, insertion sort | - | **0.0007s** |
  163. Note: The default version of `EntityX` (`master` branch) wasn't added to the
  164. comparison because it's already much slower than its compile-time counterpart.
  165. Pretty interesting results, aren't them? In fact, these benchmarks are the ones
  166. used by `EntityX` to show _how fast it is_. To be honest, they aren't so good
  167. and these results shouldn't be taken too seriously (indeed they are completely
  168. unrealistic).<br/>
  169. The proposed entity-component system is incredibly fast to iterate entities,
  170. this is a fact. The compiler can make a lot of optimizations because of how
  171. `EnTT` works, even more when components aren't used at all. This is exactly the
  172. case for these benchmarks. On the other hand, if we consider real world cases,
  173. `EnTT` is somewhere between a bit and much faster than the other solutions
  174. around when users also access the components and not just the entities, although
  175. it isn't as fast as reported by these benchmarks.<br/>
  176. This is why they are completely wrong and cannot be used to evaluate any of the
  177. entity-component-system libraries out there.
  178. The choice to use `EnTT` should be based on its carefully designed API, its
  179. set of features and the general performance, not because some single benchmark
  180. shows it to be the fastest tool available.
  181. In the future I'll likely try to get even better performance while still adding
  182. new features, mainly for fun.<br/>
  183. If you want to contribute and/or have suggestions, feel free to make a PR or
  184. open an issue to discuss your idea.
  185. # Build Instructions
  186. ## Requirements
  187. To be able to use `EnTT`, users must provide a full-featured compiler that
  188. supports at least C++17.<br/>
  189. The requirements below are mandatory to compile the tests and to extract the
  190. documentation:
  191. * CMake version 3.2 or later.
  192. * Doxygen version 1.8 or later.
  193. If you are looking for a C++14 version of `EnTT`, check out the git tag `cpp14`.
  194. ## Library
  195. `EnTT` is a header-only library. This means that including the `entt.hpp` header
  196. is enough to include the library as a whole and use it. For those who are
  197. interested only in the entity-component system, consider to include the sole
  198. `entity/registry.hpp` header instead.<br/>
  199. It's a matter of adding the following line to the top of a file:
  200. ```cpp
  201. #include <entt/entt.hpp>
  202. ```
  203. Use the line below to include only the entity-component system instead:
  204. ```cpp
  205. #include <entt/entity/registry.hpp>
  206. ```
  207. Then pass the proper `-I` argument to the compiler to add the `src` directory to
  208. the include paths.
  209. ## Documentation
  210. The documentation is based on [doxygen](http://www.doxygen.nl/).
  211. To build it:
  212. $ cd build
  213. $ cmake .. -DBUILD_DOCS=ON
  214. $ make
  215. The API reference will be created in HTML format within the directory
  216. `build/docs/html`. To navigate it with your favorite browser:
  217. $ cd build
  218. $ your_favorite_browser docs/html/index.html
  219. <!--
  220. @cond TURN_OFF_DOXYGEN
  221. -->
  222. It's also available [online](https://skypjack.github.io/entt/) for the latest
  223. version.<br/>
  224. Finally, there exists a [wiki](https://github.com/skypjack/entt/wiki) dedicated
  225. to the project where users can find all related documentation pages.
  226. <!--
  227. @endcond TURN_OFF_DOXYGEN
  228. -->
  229. ## Tests
  230. To compile and run the tests, `EnTT` requires *googletest*.<br/>
  231. `cmake` will download and compile the library before compiling anything else.
  232. In order to build the tests, set the CMake option `BUILD_TESTING` to `ON`.
  233. To build the most basic set of tests:
  234. * `$ cd build`
  235. * `$ cmake -DBUILD_TESTING=ON ..`
  236. * `$ make`
  237. * `$ make test`
  238. Note that benchmarks are not part of this set.
  239. # Packaging Tools
  240. `EnTT` is available for some of the most known packaging tools. In particular:
  241. * [`Conan`](https://bintray.com/skypjack/conan/entt%3Askypjack/_latestVersion),
  242. the C/C++ Package Manager for Developers.
  243. * [`Homebrew`](https://github.com/skypjack/homebrew-entt), the missing package
  244. manager for macOS.<br/>
  245. Available as a homebrew formula. Just type the following to install it:
  246. ```
  247. brew install skypjack/entt/entt
  248. ```
  249. * [`vcpkg`](https://github.com/Microsoft/vcpkg/tree/master/ports/entt),
  250. Microsoft VC++ Packaging Tool.
  251. Consider this list a work in progress and help me to make it longer.
  252. <!--
  253. @cond TURN_OFF_DOXYGEN
  254. -->
  255. # EnTT in Action
  256. `EnTT` is widely used in private and commercial applications. I cannot even
  257. mention most of them because of some signatures I put on some documents time
  258. ago. Fortunately, there are also people who took the time to implement open
  259. source projects based on `EnTT` and did not hold back when it came to
  260. documenting them.
  261. [Here](https://github.com/skypjack/entt/wiki/EnTT-in-Action) you can find an
  262. incomplete list of games, applications and articles that can be used as a
  263. reference.
  264. If you know of other resources out there that are about `EnTT`, feel free to
  265. open an issue or a PR and I'll be glad to add them to the list.
  266. # Contributors
  267. `EnTT` was written initially as a faster alternative to other well known and
  268. open source entity-component systems. Nowadays this library is moving its first
  269. steps. Much more will come in the future and hopefully I'm going to work on it
  270. for a long time.<br/>
  271. Requests for features, PR, suggestions ad feedback are highly appreciated.
  272. If you find you can help me and want to contribute to the project with your
  273. experience or you do want to get part of the project for some other reasons,
  274. feel free to contact me directly (you can find the mail in the
  275. [profile](https://github.com/skypjack)).<br/>
  276. I can't promise that each and every contribution will be accepted, but I can
  277. assure that I'll do my best to take them all seriously.
  278. If you decide to participate, please see the guidelines for
  279. [contributing](CONTRIBUTING.md) before to create issues or pull
  280. requests.<br/>
  281. Take also a look at the
  282. [contributors list](https://github.com/skypjack/entt/blob/master/AUTHORS) to
  283. know who has participated so far.
  284. <!--
  285. @endcond TURN_OFF_DOXYGEN
  286. -->
  287. # License
  288. Code and documentation Copyright (c) 2017-2019 Michele Caini.<br/>
  289. Logo Copyright (c) 2018-2019 Richard Caseres.
  290. Code released under
  291. [the MIT license](https://github.com/skypjack/entt/blob/master/LICENSE).
  292. Documentation released under
  293. [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).<br/>
  294. Logo released under
  295. [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).
  296. <!--
  297. @cond TURN_OFF_DOXYGEN
  298. -->
  299. # Support
  300. ## Patreon
  301. Become a [patron](https://www.patreon.com/bePatron?c=1772573) and get access to
  302. extra content, help me spend more time on the projects you love and create new
  303. ones for you. Your support will help me to continue the work done so far and
  304. make it more professional and feature-rich every day.<br/>
  305. It takes very little to
  306. [become a patron](https://www.patreon.com/bePatron?c=1772573) and thus help the
  307. software you use every day. Don't miss the chance.
  308. ## Donation
  309. Developing and maintaining `EnTT` takes some time and lots of coffee. I'd like
  310. to add more and more functionalities in future and turn it in a full-featured
  311. solution.<br/>
  312. If you want to support this project, you can offer me an espresso. I'm from
  313. Italy, we're used to turning the best coffee ever in code. If you find that
  314. it's not enough, feel free to support me the way you prefer.<br/>
  315. Take a look at the donation button at the top of the page for more details or
  316. just click [here](https://www.paypal.me/skypjack).
  317. ## Hire me
  318. If you start using `EnTT` and need help, if you want a new feature and want me
  319. to give it the highest priority, if you have any other reason to contact me:
  320. do not hesitate. I'm available for hiring.<br/>
  321. Feel free to take a look at my [profile](https://github.com/skypjack) and
  322. contact me by mail.
  323. <!--
  324. @endcond TURN_OFF_DOXYGEN
  325. -->