mirror of
https://github.com/BlackMATov/ecs.hpp.git
synced 2025-12-16 14:11:14 +07:00
remove synchronization primitives (temporarily)
This commit is contained in:
19
ecs.hpp
19
ecs.hpp
@@ -11,7 +11,6 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <mutex>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -680,8 +679,6 @@ namespace ecs_hpp
|
|||||||
template < typename F, typename... Cs >
|
template < typename F, typename... Cs >
|
||||||
void for_joined_components_impl_(const entity& e, F&& f, Cs&&... cs) const;
|
void for_joined_components_impl_(const entity& e, F&& f, Cs&&... cs) const;
|
||||||
private:
|
private:
|
||||||
mutable std::mutex mutex_;
|
|
||||||
|
|
||||||
entity_id last_entity_id_{0u};
|
entity_id last_entity_id_{0u};
|
||||||
std::vector<entity_id> free_entity_ids_;
|
std::vector<entity_id> free_entity_ids_;
|
||||||
detail::sparse_set<entity_id> entity_ids_;
|
detail::sparse_set<entity_id> entity_ids_;
|
||||||
@@ -805,7 +802,6 @@ namespace ecs_hpp
|
|||||||
namespace ecs_hpp
|
namespace ecs_hpp
|
||||||
{
|
{
|
||||||
inline entity registry::create_entity() {
|
inline entity registry::create_entity() {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
if ( !free_entity_ids_.empty() ) {
|
if ( !free_entity_ids_.empty() ) {
|
||||||
auto ent = entity(*this, free_entity_ids_.back());
|
auto ent = entity(*this, free_entity_ids_.back());
|
||||||
entity_ids_.insert(ent.id());
|
entity_ids_.insert(ent.id());
|
||||||
@@ -820,7 +816,6 @@ namespace ecs_hpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool registry::destroy_entity(const entity& ent) {
|
inline bool registry::destroy_entity(const entity& ent) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
remove_all_components_impl_(ent);
|
remove_all_components_impl_(ent);
|
||||||
if ( entity_ids_.unordered_erase(ent.id()) ) {
|
if ( entity_ids_.unordered_erase(ent.id()) ) {
|
||||||
free_entity_ids_.push_back(ent.id());
|
free_entity_ids_.push_back(ent.id());
|
||||||
@@ -830,13 +825,11 @@ namespace ecs_hpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool registry::is_entity_alive(const entity& ent) const noexcept {
|
inline bool registry::is_entity_alive(const entity& ent) const noexcept {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
return is_entity_alive_impl_(ent);
|
return is_entity_alive_impl_(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T, typename... Args >
|
template < typename T, typename... Args >
|
||||||
bool registry::assign_component(const entity& ent, Args&&... args) {
|
bool registry::assign_component(const entity& ent, Args&&... args) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
if ( !is_entity_alive_impl_(ent) ) {
|
if ( !is_entity_alive_impl_(ent) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -848,7 +841,6 @@ namespace ecs_hpp
|
|||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
bool registry::remove_component(const entity& ent) {
|
bool registry::remove_component(const entity& ent) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
if ( !is_entity_alive_impl_(ent) ) {
|
if ( !is_entity_alive_impl_(ent) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -860,7 +852,6 @@ namespace ecs_hpp
|
|||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
bool registry::exists_component(const entity& ent) const noexcept {
|
bool registry::exists_component(const entity& ent) const noexcept {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
if ( !is_entity_alive_impl_(ent) ) {
|
if ( !is_entity_alive_impl_(ent) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -871,13 +862,11 @@ namespace ecs_hpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t registry::remove_all_components(const entity& ent) const noexcept {
|
inline std::size_t registry::remove_all_components(const entity& ent) const noexcept {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
return remove_all_components_impl_(ent);
|
return remove_all_components_impl_(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
T& registry::get_component(const entity& ent) {
|
T& registry::get_component(const entity& ent) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
T* component = find_component_impl_<T>(ent);
|
T* component = find_component_impl_<T>(ent);
|
||||||
if ( component ) {
|
if ( component ) {
|
||||||
return *component;
|
return *component;
|
||||||
@@ -887,7 +876,6 @@ namespace ecs_hpp
|
|||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
const T& registry::get_component(const entity& ent) const {
|
const T& registry::get_component(const entity& ent) const {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
const T* component = find_component_impl_<T>(ent);
|
const T* component = find_component_impl_<T>(ent);
|
||||||
if ( component ) {
|
if ( component ) {
|
||||||
return *component;
|
return *component;
|
||||||
@@ -897,13 +885,11 @@ namespace ecs_hpp
|
|||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
T* registry::find_component(const entity& ent) noexcept {
|
T* registry::find_component(const entity& ent) noexcept {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
return find_component_impl_<T>(ent);
|
return find_component_impl_<T>(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
const T* registry::find_component(const entity& ent) const noexcept {
|
const T* registry::find_component(const entity& ent) const noexcept {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
return find_component_impl_<T>(ent);
|
return find_component_impl_<T>(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -929,7 +915,6 @@ namespace ecs_hpp
|
|||||||
|
|
||||||
template < typename T, typename F >
|
template < typename T, typename F >
|
||||||
void registry::for_each_component(F&& f) {
|
void registry::for_each_component(F&& f) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
detail::component_storage<T>* storage = find_storage_<T>();
|
detail::component_storage<T>* storage = find_storage_<T>();
|
||||||
if ( storage ) {
|
if ( storage ) {
|
||||||
storage->for_each_component(std::forward<F>(f));
|
storage->for_each_component(std::forward<F>(f));
|
||||||
@@ -938,7 +923,6 @@ namespace ecs_hpp
|
|||||||
|
|
||||||
template < typename T, typename F >
|
template < typename T, typename F >
|
||||||
void registry::for_each_component(F&& f) const {
|
void registry::for_each_component(F&& f) const {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
const detail::component_storage<T>* storage = find_storage_<T>();
|
const detail::component_storage<T>* storage = find_storage_<T>();
|
||||||
if ( storage ) {
|
if ( storage ) {
|
||||||
storage->for_each_component(std::forward<F>(f));
|
storage->for_each_component(std::forward<F>(f));
|
||||||
@@ -947,19 +931,16 @@ namespace ecs_hpp
|
|||||||
|
|
||||||
template < typename... Ts, typename F >
|
template < typename... Ts, typename F >
|
||||||
void registry::for_joined_components(F&& f) {
|
void registry::for_joined_components(F&& f) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
for_joined_components_impl_<Ts...>(std::forward<F>(f));
|
for_joined_components_impl_<Ts...>(std::forward<F>(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename... Ts, typename F >
|
template < typename... Ts, typename F >
|
||||||
void registry::for_joined_components(F&& f) const {
|
void registry::for_joined_components(F&& f) const {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
for_joined_components_impl_<Ts...>(std::forward<F>(f));
|
for_joined_components_impl_<Ts...>(std::forward<F>(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T, typename... Args >
|
template < typename T, typename... Args >
|
||||||
void registry::add_system(Args&&... args) {
|
void registry::add_system(Args&&... args) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
|
||||||
systems_.emplace_back(
|
systems_.emplace_back(
|
||||||
std::make_unique<T>(std::forward<Args>(args)...));
|
std::make_unique<T>(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user