Skip to content

Commit

Permalink
EnTT v3 (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Sep 30, 2018
1 parent f71a4d5 commit d81cb7f
Show file tree
Hide file tree
Showing 63 changed files with 2,656 additions and 4,112 deletions.
26 changes: 4 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ 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: gcc
addons:
Expand All @@ -22,22 +15,11 @@ matrix:
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: linux
compiler: clang
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['clang-5.0', 'libstdc++-4.9-dev']
env: COMPILER=clang++-5.0
- os: osx
osx_image: xcode8.3
compiler: clang
env: COMPILER=clang++
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0']
packages: ['clang-6.0', 'g++-7']
env: COMPILER=clang++-6.0
- os: osx
osx_image: xcode9.4
osx_image: xcode10
compiler: clang
env: COMPILER=clang++
- os: linux
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endif()
# Project configuration
#

project(EnTT VERSION 2.7.3)
project(EnTT VERSION 3.0.0)

include(GNUInstallDirs)

Expand Down Expand Up @@ -100,7 +100,7 @@ if(HAS_LIBCPP)
target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
endif()

target_compile_features(EnTT INTERFACE cxx_std_14)
target_compile_features(EnTT INTERFACE cxx_std_17)

#
# Install EnTT
Expand Down
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,50 +86,50 @@ been sufficiently tested so far.
#include <entt/entt.hpp>
#include <cstdint>

struct Position {
struct position {
float x;
float y;
};

struct Velocity {
struct velocity {
float dx;
float dy;
};

void update(entt::DefaultRegistry &registry) {
auto view = registry.view<Position, Velocity>();
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 &velocity = view.get<Velocity>(entity);
auto &vel = view.get<velocity>(entity);

velocity.dx = 0.;
velocity.dy = 0.;
vel.dx = 0.;
vel.dy = 0.;

// ...
}
}

void update(std::uint64_t dt, entt::DefaultRegistry &registry) {
registry.view<Position, Velocity>().each([dt](auto entity, auto &position, auto &velocity) {
void update(std::uint64_t dt, entt::registry &registry) {
registry.view<position, velocity>().each([dt](const auto, auto &pos, auto &vel) {
// gets all the components of the view at once ...

position.x += velocity.dx * dt;
position.y += velocity.dy * dt;
pos.x += vel.dx * dt;
pos.y += vel.dy * dt;

// ...
});
}

int main() {
entt::DefaultRegistry registry;
entt::registry registry;
std::uint64_t dt = 16;

for(auto i = 0; i < 10; ++i) {
auto entity = registry.create();
registry.assign<Position>(entity, i * 1.f, i * 1.f);
if(i % 2 == 0) { registry.assign<Velocity>(entity, i * .1f, i * .1f); }
registry.assign<position>(entity, i * 1.f, i * 1.f);
if(i % 2 == 0) { registry.assign<velocity>(entity, i * .1f, i * .1f); }
}

update(dt, registry);
Expand Down Expand Up @@ -209,13 +209,15 @@ open an issue to discuss your idea.
## Requirements
To be able to use `EnTT`, users must provide a full-featured compiler that
supports at least C++14.<br/>
supports at least C++17.<br/>
The requirements below are mandatory to compile the tests and to extract the
documentation:
* CMake version 3.2 or later.
* Doxygen version 1.8 or later.
If you are looking for a C++14 version of `EnTT`, check out the git tag `cpp14`.
## Library
`EnTT` is a header-only library. This means that including the `entt.hpp` header
Expand Down Expand Up @@ -351,7 +353,8 @@ 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 seriously.

If you decide to participate, please see the guidelines for
[contributing](docs/CONTRIBUTING.md) before to create issues or pull requests.<br/>
[contributing](docs/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.
Expand Down
7 changes: 1 addition & 6 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@
* optimize for empty components, it would be a mid improvement in terms of memory usage
* can we do more for shared libraries? who knows... see #144
* work stealing job system (see #100)
* make view copyable/moveable
* reflection system (maybe)
* C++17. That's all.
* AOB
* lower case names (?)
* tag_t and the others, create constexpr var
* use delegate within sink, it reduces the boilerplate in C++14, it shrinks the API of sink in C++17
* composable looper so as to pack erased systems, compose runners at different rates and run them at once in the loop
44 changes: 22 additions & 22 deletions docs/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ There are plenty of different solutions out there and I could have used one of
them. However, I decided to spend my time to define a compact and versatile tool
that fully embraces what the modern C++ has to offer.

The _result of my efforts_ is the `Identifier` class template:
The _result of my efforts_ is the `identifier` class template:

```cpp
#include <ident.hpp>

// defines the identifiers for the given types
using ID = entt::Identifier<AType, AnotherType>;
using id = entt::identifier<a_type, another_type>;

// ...

switch(aTypeIdentifier) {
case ID::get<AType>():
switch(a_type_identifier) {
case id::type<a_type>:
// ...
break;
case ID::get<AnotherType>():
case id::type<another_type>:
// ...
break;
default:
// ...
}
```

This is all what the class template has to offer: a static `get` member function
that returns a numerical identifier for the given type. It can be used in any
This is all what the class template has to offer: a `type` inline variable that
contains a numerical 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 the
Expand All @@ -62,12 +62,12 @@ a type has to be removed, one can just use a placeholder to left the other
identifiers unchanged:

```cpp
template<typename> struct IgnoreType {};
template<typename> struct ignore_type {};

using ID = entt::Identifier<
ATypeStillValid,
IgnoreType<ATypeNoLongerValid>,
AnotherTypeStillValid
using id = entt::identifier<
a_type_still_valid,
ignore_type<a_type_no_longer_valid>,
another_type_still_valid
>;
```

Expand All @@ -81,21 +81,21 @@ There are plenty of different solutions out there and I could have used one of
them. In fact, I adapted the most common one to my requirements and used it
extensively within the entire library.

It's the `Family` class. Here is an example of use directly from the
It's the `family` class. Here is an example of use directly from the
entity-component system:

```cpp
using component_family = entt::Family<struct InternalRegistryComponentFamily>;
using component_family = entt::family<struct internal_registry_component_family>;

// ...

template<typename Component>
component_type component() const noexcept {
return component_family::type<Component>();
return component_family::type<Component>;
}
```

This is all what a _family_ has to offer: a `type` member function that returns
This is all what a _family_ has to offer: a `type` inline variable that contains
a numerical identifier for the given type.

Please, note that identifiers aren't guaranteed to be the same for every run.
Expand All @@ -116,11 +116,11 @@ used carefully.
Example of use:

```cpp
auto load(entt::HashedString::hash_type resource) {
auto load(entt::hashed_string::hash_type resource) {
// uses the numeric representation of the resource to load and return it
}

auto resource = load(entt::HashedString{"gui/background"});
auto resource = load(entt::hashed_string{"gui/background"});
```
There is also a _user defined literal_ dedicated to hashed strings to make them
Expand Down Expand Up @@ -157,11 +157,11 @@ they will probably incur in unexpected results.
Example of use:

```cpp
entt::Monostate<entt::HashedString{"mykey"}>{} = true;
entt::Monostate<"mykey"_hs>{} = 42;
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::HashedString{"mykey"}>{};
const bool b = entt::monostate<"mykey"_hs>{};
const int i = entt::monostate<entt::hashed_string{"mykey"}>{};
```
Loading

0 comments on commit d81cb7f

Please sign in to comment.