-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from bot-mne-v-rot/ecs
Partial implementation of the ECS
- Loading branch information
Showing
10 changed files
with
317 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
namespace ecs { | ||
template<Storage S> | ||
std::size_t InvertedStorage<S>::size() const { | ||
return mask.capacity() - storage.size(); | ||
} | ||
|
||
template<Storage S> | ||
std::size_t InvertedStorage<S>::capacity() const { | ||
return mask.capacity(); | ||
} | ||
|
||
template<Storage S> | ||
bool InvertedStorage<S>::empty() const { | ||
return size() == 0; | ||
} | ||
|
||
template<Storage S> | ||
bool InvertedStorage<S>::contains(Id id) const { | ||
return !storage.contains(id); | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::operator[](Id) -> reference { | ||
return dummy; | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::operator[](Id) const -> const_reference { | ||
return dummy; | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::present() const -> const IdSetType & { | ||
return mask; | ||
} | ||
|
||
template<Storage S> | ||
template<typename Ref, typename Ptr> | ||
InvertedStorage<S>::iterator_template<Ref, Ptr>::iterator_template(MaskIterator mask_iterator) | ||
: mask_iterator(mask_iterator) {} | ||
|
||
template<Storage S> | ||
template<typename Ref, typename Ptr> | ||
auto InvertedStorage<S>::iterator_template<Ref, Ptr>::operator*() const -> reference { | ||
return dummy; | ||
} | ||
|
||
template<Storage S> | ||
template<typename Ref, typename Ptr> | ||
auto InvertedStorage<S>::iterator_template<Ref, Ptr>::operator->() const -> pointer { | ||
return &dummy; | ||
} | ||
|
||
template<Storage S> | ||
template<typename Ref, typename Ptr> | ||
auto InvertedStorage<S>::iterator_template<Ref, Ptr>::operator++() -> iterator_template & { | ||
++mask_iterator; | ||
return *this; | ||
} | ||
|
||
template<Storage S> | ||
template<typename Ref, typename Ptr> | ||
auto InvertedStorage<S>::iterator_template<Ref, Ptr>::operator++(int) -> iterator_template { | ||
auto copy = *this; | ||
++(*this); | ||
return copy; | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::begin() -> iterator { | ||
return { mask.begin() }; | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::end() -> iterator { | ||
return { mask.end() }; | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::cbegin() const -> const_iterator { | ||
return { mask.cbegin() }; | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::cend() const -> const_iterator { | ||
return { mask.cend() }; | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::begin() const -> const_iterator { | ||
return cbegin(); | ||
} | ||
|
||
template<Storage S> | ||
auto InvertedStorage<S>::end() const -> const_iterator { | ||
return cend(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#ifndef HIGH_SHIFT_INVERTED_STORAGE_H | ||
#define HIGH_SHIFT_INVERTED_STORAGE_H | ||
|
||
#include "ecs/storage.h" | ||
#include "ecs/id_set.h" | ||
|
||
namespace ecs { | ||
struct EmptyComponent {}; | ||
|
||
template<Storage S> | ||
class InvertedStorage { | ||
public: | ||
using IdSetType = IdSetNot<std::remove_cvref_t<decltype(std::declval<S>().present())>>; | ||
|
||
using value_type = EmptyComponent; | ||
using reference = value_type &; | ||
using const_reference = const value_type &; | ||
using pointer = value_type *; | ||
using const_pointer = const value_type *; | ||
using difference_type = std::ptrdiff_t; | ||
using size_type = std::size_t; | ||
|
||
explicit InvertedStorage(const S &storage) : storage(storage), mask(~storage.present()) {} | ||
|
||
std::size_t size() const; | ||
std::size_t capacity() const; | ||
bool empty() const; | ||
|
||
bool contains(Id id) const; | ||
|
||
reference operator[](Id index); | ||
const_reference operator[](Id index) const; | ||
|
||
const IdSetType &present() const; | ||
|
||
template<typename Ref, typename Ptr> | ||
class iterator_template { | ||
public: | ||
using reference = Ref; | ||
using pointer = Ptr; | ||
using value_type = EmptyComponent; | ||
using difference_type = std::ptrdiff_t; | ||
using iterator_category = std::forward_iterator_tag; | ||
|
||
iterator_template() = default; | ||
iterator_template(const iterator_template &) = default; | ||
iterator_template &operator=(const iterator_template &) = default; | ||
|
||
reference operator*() const; | ||
pointer operator->() const; | ||
|
||
iterator_template &operator++(); | ||
iterator_template operator++(int); | ||
|
||
bool operator==(const iterator_template &other) const = default; | ||
bool operator!=(const iterator_template &other) const = default; | ||
|
||
private: | ||
using MaskIterator = typename IdSetType::const_iterator; | ||
MaskIterator mask_iterator; | ||
EmptyComponent dummy; | ||
|
||
friend InvertedStorage; | ||
explicit iterator_template(MaskIterator mask_iterator); | ||
}; | ||
|
||
using iterator = iterator_template<reference, pointer>; | ||
using const_iterator = iterator_template<const_reference, const_pointer>; | ||
|
||
iterator begin(); | ||
iterator end(); | ||
const_iterator begin() const; | ||
const_iterator end() const; | ||
const_iterator cbegin() const; | ||
const_iterator cend() const; | ||
|
||
private: | ||
IdSetType mask; | ||
const S &storage; | ||
EmptyComponent dummy; | ||
}; | ||
|
||
template<Storage S> | ||
auto operator!(const S &storage) { | ||
return InvertedStorage<S>(storage); | ||
} | ||
} | ||
|
||
#include "ecs/storages/detail/inverted_storage_impl.h" | ||
|
||
#endif //HIGH_SHIFT_INVERTED_STORAGE_H |
Oops, something went wrong.