minor changes
This commit is contained in:
@@ -31,7 +31,7 @@ struct StdSort {
|
||||
* @param compare A valid comparison function object.
|
||||
*/
|
||||
template<typename It, typename Compare = std::less<>>
|
||||
void operator()(It first, It last, Compare compare = Compare{}) {
|
||||
void operator()(It first, It last, Compare compare = Compare{}) const {
|
||||
std::sort(std::move(first), std::move(last), std::move(compare));
|
||||
}
|
||||
};
|
||||
@@ -51,7 +51,7 @@ struct InsertionSort {
|
||||
* @param compare A valid comparison function object.
|
||||
*/
|
||||
template<typename It, typename Compare = std::less<>>
|
||||
void operator()(It first, It last, Compare compare = Compare{}) {
|
||||
void operator()(It first, It last, Compare compare = Compare{}) const {
|
||||
auto it = first + 1;
|
||||
|
||||
while(it != last) {
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
#define ENTT_CORE_IDENT_HPP
|
||||
|
||||
|
||||
#include<type_traits>
|
||||
#include<cstddef>
|
||||
#include<utility>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include "../config/config.h"
|
||||
|
||||
|
||||
namespace entt {
|
||||
@@ -24,12 +25,12 @@ struct Identifier final: Identifier<Types>... {
|
||||
using identifier_type = std::size_t;
|
||||
|
||||
template<std::size_t... Indexes>
|
||||
constexpr Identifier(std::index_sequence<Indexes...>)
|
||||
constexpr Identifier(std::index_sequence<Indexes...>) ENTT_NOEXCEPT
|
||||
: Identifier<Types>{std::index_sequence<Indexes>{}}...
|
||||
{}
|
||||
|
||||
template<typename Type>
|
||||
constexpr std::size_t get() const {
|
||||
constexpr std::size_t get() const ENTT_NOEXCEPT {
|
||||
return Identifier<std::decay_t<Type>>::get();
|
||||
}
|
||||
};
|
||||
@@ -40,11 +41,11 @@ struct Identifier<Type> {
|
||||
using identifier_type = std::size_t;
|
||||
|
||||
template<std::size_t Index>
|
||||
constexpr Identifier(std::index_sequence<Index>)
|
||||
constexpr Identifier(std::index_sequence<Index>) ENTT_NOEXCEPT
|
||||
: index{Index}
|
||||
{}
|
||||
|
||||
constexpr std::size_t get() const {
|
||||
constexpr std::size_t get() const ENTT_NOEXCEPT {
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
@@ -215,11 +215,6 @@ public:
|
||||
* prototype(registry, entity);
|
||||
* @endcode
|
||||
*
|
||||
* @warning
|
||||
* Attempting to use an invalid entity results in undefined behavior.<br/>
|
||||
* An assertion will abort the execution at runtime in debug mode in case of
|
||||
* invalid entity.
|
||||
*
|
||||
* @param registry A valid reference to a registry.
|
||||
* @return A valid entity identifier.
|
||||
*/
|
||||
@@ -301,11 +296,6 @@ public:
|
||||
* prototype(registry, entity);
|
||||
* @endcode
|
||||
*
|
||||
* @warning
|
||||
* Attempting to use an invalid entity results in undefined behavior.<br/>
|
||||
* An assertion will abort the execution at runtime in debug mode in case of
|
||||
* invalid entity.
|
||||
*
|
||||
* @param registry A valid reference to a registry.
|
||||
* @return A valid entity identifier.
|
||||
*/
|
||||
@@ -320,8 +310,12 @@ private:
|
||||
|
||||
/**
|
||||
* @brief Default prototype
|
||||
*
|
||||
* The default prototype is the best choice for almost all the
|
||||
* applications.<br/>
|
||||
* Users should have a really good reason to choose something different.
|
||||
*/
|
||||
using DefaultPrototype = Prototype<uint32_t>;
|
||||
using DefaultPrototype = Prototype<std::uint32_t>;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Snapshot final {
|
||||
{}
|
||||
|
||||
template<typename Component, typename Archive, typename It>
|
||||
void get(Archive &archive, std::size_t sz, It first, It last) {
|
||||
void get(Archive &archive, std::size_t sz, It first, It last) const {
|
||||
archive(static_cast<Entity>(sz));
|
||||
|
||||
while(first != last) {
|
||||
@@ -61,7 +61,7 @@ class Snapshot final {
|
||||
}
|
||||
|
||||
template<typename... Component, typename Archive, typename It, std::size_t... Indexes>
|
||||
void component(Archive &archive, It first, It last, std::index_sequence<Indexes...>) {
|
||||
void component(Archive &archive, It first, It last, std::index_sequence<Indexes...>) const {
|
||||
std::array<std::size_t, sizeof...(Indexes)> size{};
|
||||
auto begin = first;
|
||||
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
* @return An object of this type to continue creating the snapshot.
|
||||
*/
|
||||
template<typename Archive>
|
||||
Snapshot & entities(Archive &archive) {
|
||||
const Snapshot & entities(Archive &archive) const {
|
||||
archive(static_cast<Entity>(registry.size()));
|
||||
registry.each([&archive](const auto entity) { archive(entity); });
|
||||
return *this;
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
* @return An object of this type to continue creating the snapshot.
|
||||
*/
|
||||
template<typename Archive>
|
||||
Snapshot & destroyed(Archive &archive) {
|
||||
const Snapshot & destroyed(Archive &archive) const {
|
||||
auto size = registry.capacity() - registry.size();
|
||||
archive(static_cast<Entity>(size));
|
||||
auto curr = seed;
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
* @return An object of this type to continue creating the snapshot.
|
||||
*/
|
||||
template<typename Component, typename Archive>
|
||||
Snapshot & component(Archive &archive) {
|
||||
const Snapshot & component(Archive &archive) const {
|
||||
const auto sz = registry.template size<Component>();
|
||||
const auto *entities = registry.template data<Component>();
|
||||
|
||||
@@ -167,8 +167,8 @@ public:
|
||||
* @return An object of this type to continue creating the snapshot.
|
||||
*/
|
||||
template<typename... Component, typename Archive>
|
||||
std::enable_if_t<(sizeof...(Component) > 1), Snapshot &>
|
||||
component(Archive &archive) {
|
||||
std::enable_if_t<(sizeof...(Component) > 1), const Snapshot &>
|
||||
component(Archive &archive) const {
|
||||
using accumulator_type = int[];
|
||||
accumulator_type accumulator = { 0, (component<Component>(archive), 0)... };
|
||||
(void)accumulator;
|
||||
@@ -190,7 +190,7 @@ public:
|
||||
* @return An object of this type to continue creating the snapshot.
|
||||
*/
|
||||
template<typename... Component, typename Archive, typename It>
|
||||
Snapshot & component(Archive &archive, It first, It last) {
|
||||
const Snapshot & component(Archive &archive, It first, It last) const {
|
||||
component<Component...>(archive, first, last, std::make_index_sequence<sizeof...(Component)>{});
|
||||
return *this;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ public:
|
||||
* @return An object of this type to continue creating the snapshot.
|
||||
*/
|
||||
template<typename Tag, typename Archive>
|
||||
Snapshot & tag(Archive &archive) {
|
||||
const Snapshot & tag(Archive &archive) const {
|
||||
const bool has = registry.template has<Tag>();
|
||||
|
||||
// numerical length is forced for tags to facilitate loading
|
||||
@@ -232,8 +232,8 @@ public:
|
||||
* @return An object of this type to continue creating the snapshot.
|
||||
*/
|
||||
template<typename... Tag, typename Archive>
|
||||
std::enable_if_t<(sizeof...(Tag) > 1), Snapshot &>
|
||||
tag(Archive &archive) {
|
||||
std::enable_if_t<(sizeof...(Tag) > 1), const Snapshot &>
|
||||
tag(Archive &archive) const {
|
||||
using accumulator_type = int[];
|
||||
accumulator_type accumulator = { 0, (tag<Tag>(archive), 0)... };
|
||||
(void)accumulator;
|
||||
@@ -273,7 +273,7 @@ class SnapshotLoader final {
|
||||
}
|
||||
|
||||
template<typename Archive>
|
||||
void assure(Archive &archive, bool destroyed) {
|
||||
void assure(Archive &archive, bool destroyed) const {
|
||||
Entity length{};
|
||||
archive(length);
|
||||
|
||||
@@ -285,7 +285,7 @@ class SnapshotLoader final {
|
||||
}
|
||||
|
||||
template<typename Type, typename Archive, typename... Args>
|
||||
void assign(Archive &archive, Args... args) {
|
||||
void assign(Archive &archive, Args... args) const {
|
||||
Entity length{};
|
||||
archive(length);
|
||||
|
||||
@@ -321,7 +321,7 @@ public:
|
||||
* @return A valid loader to continue restoring data.
|
||||
*/
|
||||
template<typename Archive>
|
||||
SnapshotLoader & entities(Archive &archive) {
|
||||
const SnapshotLoader & entities(Archive &archive) const {
|
||||
static constexpr auto destroyed = false;
|
||||
assure(archive, destroyed);
|
||||
return *this;
|
||||
@@ -338,7 +338,7 @@ public:
|
||||
* @return A valid loader to continue restoring data.
|
||||
*/
|
||||
template<typename Archive>
|
||||
SnapshotLoader & destroyed(Archive &archive) {
|
||||
const SnapshotLoader & destroyed(Archive &archive) const {
|
||||
static constexpr auto destroyed = true;
|
||||
assure(archive, destroyed);
|
||||
return *this;
|
||||
@@ -358,7 +358,7 @@ public:
|
||||
* @return A valid loader to continue restoring data.
|
||||
*/
|
||||
template<typename... Component, typename Archive>
|
||||
SnapshotLoader & component(Archive &archive) {
|
||||
const SnapshotLoader & component(Archive &archive) const {
|
||||
using accumulator_type = int[];
|
||||
accumulator_type accumulator = { 0, (assign<Component>(archive), 0)... };
|
||||
(void)accumulator;
|
||||
@@ -379,7 +379,7 @@ public:
|
||||
* @return A valid loader to continue restoring data.
|
||||
*/
|
||||
template<typename... Tag, typename Archive>
|
||||
SnapshotLoader & tag(Archive &archive) {
|
||||
const SnapshotLoader & tag(Archive &archive) const {
|
||||
using accumulator_type = int[];
|
||||
accumulator_type accumulator = { 0, (assign<Tag>(archive, tag_t{}), 0)... };
|
||||
(void)accumulator;
|
||||
@@ -396,7 +396,7 @@ public:
|
||||
*
|
||||
* @return A valid loader to continue restoring data.
|
||||
*/
|
||||
SnapshotLoader & orphans() {
|
||||
const SnapshotLoader & orphans() const {
|
||||
registry.orphans([this](const auto entity) {
|
||||
registry.destroy(entity);
|
||||
});
|
||||
@@ -687,7 +687,7 @@ public:
|
||||
* @param entity An entity identifier.
|
||||
* @return True if `entity` is managed by the loader, false otherwise.
|
||||
*/
|
||||
bool has(entity_type entity) {
|
||||
bool has(entity_type entity) const ENTT_NOEXCEPT {
|
||||
return (remloc.find(entity) != remloc.cend());
|
||||
}
|
||||
|
||||
@@ -703,9 +703,9 @@ public:
|
||||
* @param entity An entity identifier.
|
||||
* @return The identifier to which `entity` refers in the target registry.
|
||||
*/
|
||||
entity_type map(entity_type entity) {
|
||||
entity_type map(entity_type entity) const ENTT_NOEXCEPT {
|
||||
assert(has(entity));
|
||||
return remloc[entity].first;
|
||||
return remloc.find(entity)->second.first;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -115,7 +115,7 @@ class Process {
|
||||
}
|
||||
|
||||
template<State S, typename... Args>
|
||||
void tick(char, tag<S>, Args &&...) {}
|
||||
void tick(char, tag<S>, Args &&...) const ENTT_NOEXCEPT {}
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
* @param args Arguments to use to invoke the underlying function.
|
||||
* @return The value returned by the underlying function.
|
||||
*/
|
||||
Ret operator()(Args... args) {
|
||||
Ret operator()(Args... args) const {
|
||||
return stub.second(stub.first, args...);
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ public:
|
||||
* delivered to the registered listeners. It's responsibility of the users
|
||||
* to reduce at a minimum the time spent in the bodies of the listeners.
|
||||
*/
|
||||
inline void update() {
|
||||
inline void update() const {
|
||||
for(auto pos = wrappers.size(); pos; --pos) {
|
||||
auto &wrapper = wrappers[pos-1];
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include "../config/config.h"
|
||||
#include "../core/family.hpp"
|
||||
|
||||
|
||||
namespace entt {
|
||||
@@ -39,6 +40,8 @@ namespace entt {
|
||||
*/
|
||||
template<typename Derived>
|
||||
class Emitter {
|
||||
using handler_family = Family<struct InternalEmitterHandlerFamily>;
|
||||
|
||||
struct BaseHandler {
|
||||
virtual ~BaseHandler() = default;
|
||||
virtual bool empty() const ENTT_NOEXCEPT = 0;
|
||||
@@ -112,20 +115,9 @@ class Emitter {
|
||||
container_type onL{};
|
||||
};
|
||||
|
||||
static std::size_t next() ENTT_NOEXCEPT {
|
||||
static std::size_t counter = 0;
|
||||
return counter++;
|
||||
}
|
||||
|
||||
template<typename>
|
||||
static std::size_t type() ENTT_NOEXCEPT {
|
||||
static std::size_t value = next();
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename Event>
|
||||
Handler<Event> & handler() ENTT_NOEXCEPT {
|
||||
const std::size_t family = type<Event>();
|
||||
const std::size_t family = handler_family::type<Event>();
|
||||
|
||||
if(!(family < handlers.size())) {
|
||||
handlers.resize(family+1);
|
||||
@@ -304,8 +296,9 @@ public:
|
||||
* results in undefined behavior.
|
||||
*/
|
||||
void clear() ENTT_NOEXCEPT {
|
||||
std::for_each(handlers.begin(), handlers.end(),
|
||||
[](auto &&handler) { if(handler) { handler->clear(); } });
|
||||
std::for_each(handlers.begin(), handlers.end(), [](auto &&handler) {
|
||||
return handler ? handler->clear() : void();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,7 +308,7 @@ public:
|
||||
*/
|
||||
template<typename Event>
|
||||
bool empty() const ENTT_NOEXCEPT {
|
||||
const std::size_t family = type<Event>();
|
||||
const std::size_t family = handler_family::type<Event>();
|
||||
|
||||
return (!(family < handlers.size()) ||
|
||||
!handlers[family] ||
|
||||
@@ -327,8 +320,9 @@ public:
|
||||
* @return True if there are no listeners registered, false otherwise.
|
||||
*/
|
||||
bool empty() const ENTT_NOEXCEPT {
|
||||
return std::all_of(handlers.cbegin(), handlers.cend(),
|
||||
[](auto &&handler) { return !handler || handler->empty(); });
|
||||
return std::all_of(handlers.cbegin(), handlers.cend(), [](auto &&handler) {
|
||||
return !handler || handler->empty();
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -31,7 +31,7 @@ struct Invoker<Ret(Args...), Collector> {
|
||||
|
||||
virtual ~Invoker() = default;
|
||||
|
||||
bool invoke(Collector &collector, proto_type proto, void *instance, Args... args) {
|
||||
bool invoke(Collector &collector, proto_type proto, void *instance, Args... args) const {
|
||||
return collector(proto(instance, args...));
|
||||
}
|
||||
};
|
||||
@@ -44,7 +44,7 @@ struct Invoker<void(Args...), Collector> {
|
||||
|
||||
virtual ~Invoker() = default;
|
||||
|
||||
bool invoke(Collector &, proto_type proto, void *instance, Args... args) {
|
||||
bool invoke(Collector &, proto_type proto, void *instance, Args... args) const {
|
||||
return (proto(instance, args...), true);
|
||||
}
|
||||
};
|
||||
@@ -306,7 +306,7 @@ public:
|
||||
*
|
||||
* @param args Arguments to use to invoke listeners.
|
||||
*/
|
||||
void publish(Args... args) {
|
||||
void publish(Args... args) const {
|
||||
for(auto pos = calls.size(); pos; --pos) {
|
||||
auto &call = calls[pos-1];
|
||||
call.second(call.first, args...);
|
||||
@@ -318,7 +318,7 @@ public:
|
||||
* @param args Arguments to use to invoke listeners.
|
||||
* @return An instance of the collector filled with collected data.
|
||||
*/
|
||||
collector_type collect(Args... args) {
|
||||
collector_type collect(Args... args) const {
|
||||
collector_type collector;
|
||||
|
||||
for(auto &&call: calls) {
|
||||
|
||||
Reference in New Issue
Block a user