diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-22 12:14:26 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-22 12:14:26 +0100 |
commit | c26d3ecfe9779e9cce13edfd981246c146c6f3a1 (patch) | |
tree | 5e5ca5a628f19731b42558f22d6bc2d10f20422a /gfx/gl/instanceVertices.h | |
parent | Fix the instancing maintenance (diff) | |
download | ilt-c26d3ecfe9779e9cce13edfd981246c146c6f3a1.tar.bz2 ilt-c26d3ecfe9779e9cce13edfd981246c146c6f3a1.tar.xz ilt-c26d3ecfe9779e9cce13edfd981246c146c6f3a1.zip |
Streamline the instancing maintenance
Diffstat (limited to 'gfx/gl/instanceVertices.h')
-rw-r--r-- | gfx/gl/instanceVertices.h | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h index 036b48e..cf4f0ae 100644 --- a/gfx/gl/instanceVertices.h +++ b/gfx/gl/instanceVertices.h @@ -25,7 +25,7 @@ public: ~InstanceProxy() { if (instances) { - instances->release(*this); + instances->release(index); } } @@ -33,7 +33,7 @@ public: operator=(InstanceProxy && other) { if (instances) { - instances->release(*this); + instances->release(index); } instances = std::exchange(other.instances, nullptr); index = other.index; @@ -87,8 +87,6 @@ public: } private: - friend InstanceVertices; - InstanceVertices<T> * instances; std::size_t index; }; @@ -131,23 +129,19 @@ protected: friend InstanceProxy; void - release(const InstanceProxy & p) + release(const size_t pidx) { // Destroy p's object - at(p.index).~T(); - if (next-- > index[p.index]) { + at(pidx).~T(); + if (next-- > index[pidx]) { // Remember p.index is free index now - unused.push_back(p.index); + unused.push_back(pidx); // Move last object into p's slot - new (&at(p.index)) T {std::move(data[next])}; + new (&at(pidx)) T {std::move(data[next])}; (data[next]).~T(); - for (auto & i : index) { - if (i == next) { - i = index[p.index]; - break; - } - } - index[p.index] = 100000; + *std::find(index.begin(), index.end(), next) = index[pidx]; + // Not strictly required, but needed for uniqueness unit test assertion + index[pidx] = static_cast<size_t>(-1); } else { index.pop_back(); |