Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more

License

NotificationsYou must be signed in to change notification settings

skypjack/entt

Repository files navigation

EnTT: Gaming meets modern C++

Build StatusCoverageTry onlineDocumentationVcpkg portConan CenterGitter chatDiscord channel

EnTT has been a dream so far, we haven't found a single bug to date and it'ssuper easy to work with

-- Every EnTT User Ever

EnTT is a header-only, tiny and easy to use library for game programming andmuch more written inmodern C++.
Among others, it's usedinMinecraft by Mojang, theArcGIS Runtime SDKs by Esriand the amazingRagdoll.
If you don't see your project in the list, please open an issue, submit a PR oradd the#entt tag to yourtopics! 👍


Do you want tokeep up with changes or do you have aquestion thatdoesn't require you to open an issue?
Join thegitter channel and thediscord server, meet other users like you. Themore we are, the better for everyone.
Don't forget to check theFAQs and thewiki too. Your answers may already bethere.

Do you want to supportEnTT? Consider becoming asponsor or making adonation viaPayPal.
Many thanks tothese people andspecial thanks to:

mojangimgly

Table of Contents

Introduction

The entity-component-system (also known asECS) is an architectural patternused mostly in game development. For further details:

This project started off as a pure entity-component system. Over time thecodebase has grown as more and more classes and functionalities were added.
Here is a brief, yet incomplete list of what it offers today:

  • Built-inRTTI system mostly similar to the standard one.
  • Aconstexpr utility for human-readableresource names.
  • Minimalconfiguration system built using the monostate pattern.
  • Incredibly fastentity-component system with its ownpay for what youuse policy, unconstrained component types with optional pointer stability andhooks for storage customization.
  • Views and groups to iterate entities and components and allow different accesspatterns, fromperfect SoA to fully random.
  • A lot offacilities built on top of the entity-component system to helpthe users and avoid reinventing the wheel.
  • General purposeexecution graph builder for optimal scheduling.
  • The smallest and most basic implementation of aservice locator ever seen.
  • A built-in, non-intrusive and macro-free runtimereflection system.
  • Static polymorphism made simple and within everyone's reach.
  • A few homemade containers, like a sparse set basedhash map.
  • Acooperative scheduler for processes of any type.
  • All that is needed forresource management (cache, loaders, handles).
  • Delegates,signal handlers and a tiny event dispatcher.
  • A general purposeevent emitter as a CRTP idiom based class template.
  • Andmuch more! Check out thewiki.

Consider this list a work in progress as well as the project. The whole API isfully documented in-code for those who are brave enough to read it.
Please, do note that all tools are also DLL-friendly now and run smoothly acrossboundaries.

One thing known to most is thatEnTT is also used inMinecraft.
Given that the game is available literally everywhere, I can confidently saythat the library has been sufficiently tested on every platform that can come tomind.

Code Example

#include<entt/entt.hpp>structposition {float x;float y;};structvelocity {float dx;float dy;};voidupdate(entt::registry &registry) {auto view = registry.view<const position, velocity>();// use a callback    view.each([](constauto &pos,auto &vel) {/* ...*/ });// use an extended callback    view.each([](constauto entity,constauto &pos,auto &vel) {/* ...*/ });// use a range-forfor(auto [entity, pos, vel]: view.each()) {// ...    }// use forward iterators and get only the components of interestfor(auto entity: view) {auto &vel = view.get<velocity>(entity);// ...    }}intmain() {    entt::registry registry;for(auto i =0u; i <10u; ++i) {constauto 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(registry);}

Motivation

I started developingEnTT for thewrong reason: my goal was to design anentity-component system to beat another well known open source library both interms of performance and possibly memory usage.
In the end, I did it, but it wasn't very satisfying. Actually it wasn'tsatisfying at all. The fastest and nothing more, fairly little indeed. When Irealized it, I tried hard to keep intact the great performance ofEnTT and toadd all the features I wanted to see inmy own library at the same time.

Nowadays,EnTT is finally what I was looking for: still faster than itscompetitors, lower memory usage in the average case, a really good API and anamazing set of features. And even more, of course.

Benchmark

For what it's worth, you'llnever see me trying to make other projects lookbad or offer dubious comparisons just to make this library seem cooler.
I leave this activity to others, if they enjoy it (and it seems that some peopleactually like it). I prefer to make better use of my time.

If you are interested, you can compile thebenchmark test in release mode (toenable compiler optimizations, otherwise it would make little sense) by settingtheENTT_BUILD_BENCHMARK option ofCMake toON, then evaluate yourselfwhether you're satisfied with the results or not.

There are also a lot of projects out there that useEnTT as a basis forcomparison (this should already tell you a lot). Many of these benchmarks arecompletely wrong, many others are simply incomplete, good at omitting someinformation and using the wrong function to compare a given feature. Certainlythere are also good ones but they age quickly if nobody updates them, especiallywhen the library they are dealing with is actively developed.
Out of all of them,this seems likethe most up-to-date project and also covers a certain number of libraries. Ican't say exactly whetherEnTT is used correctly or not. However, even if usedpoorly, it should still give the reader an idea of where it's going to operate.

Integration

EnTT is a header-only library. This means that including theentt.hpp headeris enough to include the library as a whole and use it. For those who areinterested only in the entity-component system, consider to include the soleentity/registry.hpp header instead.
It's a matter of adding the following line to the top of a file:

#include<entt/entt.hpp>

Use the line below to include only the entity-component system instead:

#include<entt/entity/registry.hpp>

Then pass the proper-I argument to the compiler to add thesrc directory tothe include paths.

Requirements

To be able to useEnTT, users must provide a full-featured compiler thatsupports at least C++17.
The requirements below are mandatory to compile the tests and to extract thedocumentation:

  • CMake version 3.7 or later.
  • Doxygen version 1.8 or later.

Alternatively,Bazel is also supported as a build system(credits tozaucy who offered to maintain it).
In the documentation below I'll still refer toCMake, this being the officialbuild system of the library.

CMake

To useEnTT from aCMake project, just link an existing target to theEnTT::EnTT alias.
The library offers everything you need for locating (as infind_package),embedding (as inadd_subdirectory), fetching (as inFetchContent) or usingit in many of the ways that you can think of and that involveCMake.
Covering all possible cases would require a treatise and not a simple READMEfile, but I'm confident that anyone reading this section also knows what it'sabout and can useEnTT from aCMake project without problems.

Natvis support

When usingCMake, just enable the optionENTT_INCLUDE_NATVIS and enjoyit.
Otherwise, most of the tools are covered via Natvis and all files can be foundin thenatvis directory, divided by module.
If you spot errors or have suggestions, any contribution is welcome!

Packaging Tools

EnTT is available for some of the most known packaging tools. In particular:

  • Conan, the C/C++ PackageManager for Developers.

  • vcpkg, Microsoft VC++ PackagingTool.
    You can download and installEnTT in just a few simple steps:

    $ git clone https://github.com/Microsoft/vcpkg.git$ cd vcpkg$ ./bootstrap-vcpkg.sh$ ./vcpkg integrate install$ vcpkg install entt

    Or you can use theexperimental feature to test the latest changes:

    vcpkg install entt[experimental] --head

    TheEnTT port invcpkg is kept up to date by Microsoft team members andcommunity contributors.
    If the version is out of date, pleasecreate an issue or pull request on thevcpkg repository.

  • Homebrew, the missing packagemanager for macOS.
    Available as a homebrew formula. Just type the following to install it:

    brew install skypjack/entt/entt
  • build2, build toolchain for developing and packaging Cand C++ code.
    In order to use theentt package in abuild2project, add the following line or a similar one to themanifest file:

    depends: entt ^3.0.0

    Also check that the configuration refers to a valid repository, so that thepackage can be found bybuild2:

    • cppget.org, the open-source community centralrepository, accessible ashttps://pkg.cppget.org/1/stable.

    • Package source repository:accessible as eitherhttps://github.com/build2-packaging/entt.git orssh://git@github.com/build2-packaging/entt.git.Feel free toreport issues withthis package.

    Both can be used withbpkg add-repo or added in a projectrepositories.manifest. See the officialdocumentationfor more details.

  • bzlmod, Bazel's externaldependency management system.
    To use theentt module in abazel project, add the following to yourMODULE.bazel file:

    bazel_dep(name="entt",version="3.12.2")

    EnTT will now be available as@entt (short for@entt//:entt) to be usedin yourcc_* ruledeps.

Consider this list a work in progress and help me to make it longer if you like.

pkg-config

EnTT also supportspkg-config (for some definition ofsupports at least).A suitable file calledentt.pc is generated and installed in a properdirectory when runningCMake.
This should also make it easier to use with tools such asMeson or similar.

Documentation

The documentation is based ondoxygen. To build it:

$ cd build$ cmake .. -DENTT_BUILD_DOCS=ON$ make

The API reference is created in HTML format in thebuild/docs/html directory.To navigate it with your favorite browser:

$ cd build$ your_favorite_browser docs/html/index.html

The same version is also availableonlinefor the latest release, that is the last stable tag.
Moreover, there exists awiki dedicatedto the project where users can find all related documentation pages.

Tests

To compile and run the tests,EnTT requiresgoogletest.
cmake downloads and compiles the library before compiling anything else. Inorder to build the tests, set theCMake optionENTT_BUILD_TESTING toON.

To build the most basic set of tests:

  • $ cd build
  • $ cmake -DENTT_BUILD_TESTING=ON ..
  • $ make
  • $ make test

Note that benchmarks are not part of this set.

EnTT in Action

EnTT is widely used in private and commercial applications. I cannot evenmention most of them because of some signatures I put on some documents timeago. Fortunately, there are also people who took the time to implement opensource projects based onEnTT and did not hold back when it came todocumenting them.

Here you can find anincomplete list of games, applications and articles that can be used as areference.

If you know of other resources out there that are aboutEnTT, feel free toopen an issue or a PR and I'll be glad to add them to the list.

Contributors

Requests for features, PRs, suggestions and feedback are highly appreciated.

If you find you can help and want to contribute to the project with yourexperience or you do want to get part of the project for some other reason, feelfree to contact me directly (you can find the mail in theprofile).
I can't promise that each and every contribution will be accepted, but I canassure that I'll do my best to take them all as soon as possible.

If you decide to participate, please see the guidelines forcontributingbefore to create issues or pull requests.
Take also a look at thecontributors list toknow who has participated so far.

License

Code and documentation Copyright (c) 2017-2025 Michele Caini.
Colorful logo Copyright (c) 2018-2021 Richard Caseres.

Code released underthe MIT license.
Documentation released underCC BY 4.0.
All logos released underCC BY-SA 4.0.


[8]ページ先頭

©2009-2025 Movatter.jp