Namespaced StructDB

master
Marc Gilleron 2022-01-04 21:44:06 +00:00
parent dcbb59b15c
commit 0c290082ff
2 changed files with 11 additions and 12 deletions

View File

@ -4,11 +4,12 @@
#include <core/error/error_macros.h>
#include <vector>
namespace zylann {
// Stores uniquely-identified structs in a packed array.
// Always use the IDs if you want to store a reference somewhere. Addresses aren't stable.
// IDs are made unique with a generation system.
template <typename T>
class StructDB {
template <typename T> class StructDB {
private:
struct Slot {
T data;
@ -129,8 +130,7 @@ public:
return c;
}
template <typename F>
inline void for_each(F f) {
template <typename F> inline void for_each(F f) {
for (size_t i = 0; i < _slots.size(); ++i) {
Slot &s = _slots[i];
if (s.valid) {
@ -139,8 +139,7 @@ public:
}
}
template <typename F>
inline void for_each(F f) const {
template <typename F> inline void for_each(F f) const {
for (size_t i = 0; i < _slots.size(); ++i) {
const Slot &s = _slots[i];
if (s.valid) {
@ -149,8 +148,7 @@ public:
}
}
template <typename F>
inline void for_each_with_id(F f) {
template <typename F> inline void for_each_with_id(F f) {
for (size_t i = 0; i < _slots.size(); ++i) {
Slot &s = _slots[i];
if (s.valid) {
@ -159,8 +157,7 @@ public:
}
}
template <typename F>
inline void for_each_with_id(F f) const {
template <typename F> inline void for_each_with_id(F f) const {
for (size_t i = 0; i < _slots.size(); ++i) {
const Slot &s = _slots[i];
if (s.valid) {
@ -186,4 +183,6 @@ private:
std::vector<Slot> _slots;
};
} // namespace zylann
#endif // VOXEL_STRUCT_DB_H

View File

@ -252,8 +252,8 @@ private:
};
struct World {
StructDB<Volume> volumes;
StructDB<Viewer> viewers;
zylann::StructDB<Volume> volumes;
zylann::StructDB<Viewer> viewers;
// Must be overwritten with a new instance if count changes.
std::shared_ptr<PriorityDependencyShared> shared_priority_dependency;