bantdit / enttx Goto Github PK
View Code? Open in Web Editor NEWCompile-time and header-only Entity-Component-System library.
Compile-time and header-only Entity-Component-System library.
There is no meaning of existence of methods like 'EntityManager::createMany'. Consider to replace all 'EntityManager::createMany' methods to overloaded instances of 'EntityManager::create' method.
Consider to refactor 'Entity::index()' and 'Entity::version()' methods to
class Entity {
public:
// ...
auto index() const -> uint32_t { return static_cast<uint32_t>(id_ & INDEX_MASK); }
auto version() const -> uint32_t { return static_cast<uint32_t>(id_ >> VERSION_SHIFT_VALUE); }
private:
static auto constexpr INDEX_MASK{ 0xffffffffUL };
static auto constexpr VERSION_SHIFT_VALUE{ 32UL };
// ...
};
I. e., replace methods below
template<size_t COUNT>
auto createMany(std::array<Entity, COUNT>& entities, size_t count = 0) -> std::array<Entity, COUNT>&;
template<size_t COUNT>
auto createMany(std::array<Entity, COUNT>&& entities, size_t count = 0) -> std::array<Entity, COUNT>&&;
auto createMany(std::vector<Entity>& entities, size_t count = 0) -> std::vector<Entity>&;
auto createMany(std::vector<Entity>&& entities, size_t count = 0) -> std::vector<Entity>&&;
to one
template<class T, typename std::enable_if_t<is_container_v<std::decay_t<T>>>...>
auto createMany(T &&entities, size_t count = 0)
{
static_assert(std::is_same_v<typename std::decay_t<T>::value_type, Entity>, "'entities' must contain 'Entity' instances");
return _createMany(std::forward<T>(entities), count > 0 ? count : std::size(entities));
}
A little MPL helper function might be like follow one
template<class C>
constexpr bool is_iterable_v = is_iterable<C>::value;
template<class C, class = void>
struct is_container : std::false_type {};
template<class C>
struct is_container<C, std::void_t<decltype(std::size(std::declval<C>()), std::data(std::declval<C>()))>> : std::true_type {};
template<class C>
constexpr bool is_container_v = is_container<C>::value;
Consider to get rid of references to 'Entity' class instances, e. g. replace this
bool operator==(Entity const& rhs) const { return id_ == rhs.id_; }
to
bool operator==(Entity rhs) const { return id_ == rhs.id_; }
Consider to make trivial methods 'noexcept', e. g. replace this
bool operator==(Entity const& rhs) const { return id_ == rhs.id_; }
to
bool operator==(Entity const& rhs) const noexcept { return id_ == rhs.id_; }
There is no need to define custom default constructor like this
Entity()
: id_{ std::numeric_limits<uint64_t>::max() }
{}
Way better for interface if you replace it to
class Entity {
public:
Entity() noexcept = default;
private:
uint64_t id_{ std::numeric_limits<uint64_t>::max() };
};
Consider to make trivial methods 'constexpr', e. g. replace this
bool operator==(Entity const& rhs) const { return id_ == rhs.id_; }
to
bool constexpr operator==(Entity const& rhs) const { return id_ == rhs.id_; }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.