Skip to content

Commit

Permalink
Replace osp::BitVector_t with lgrn::IdSetStl in planeta
Browse files Browse the repository at this point in the history
  • Loading branch information
Capital-Asterisk committed May 25, 2024
1 parent 3f3393f commit b8e9f99
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 144 deletions.
18 changes: 9 additions & 9 deletions src/planet-a/chunk_generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void ChunkScratchpad::resize(ChunkSkeleton const& rChSk)
{
auto const maxSharedVrtx = rChSk.m_sharedIds.capacity();

edgeVertices.resize((rChSk.m_chunkEdgeVrtxCount - 1) * 3);
stitchCmds .resize(rChSk.m_chunkIds.capacity(), {});
osp::bitvector_resize(sharedAdded, maxSharedVrtx);
osp::bitvector_resize(sharedRemoved, maxSharedVrtx);
osp::bitvector_resize(sharedNormalsDirty, maxSharedVrtx);
edgeVertices .resize((rChSk.m_chunkEdgeVrtxCount - 1) * 3);
stitchCmds .resize(rChSk.m_chunkIds.capacity(), {});
sharedAdded .resize(maxSharedVrtx);
sharedRemoved .resize(maxSharedVrtx);
sharedNormalsDirty .resize(maxSharedVrtx);
}

void restitch_check(
Expand Down Expand Up @@ -329,11 +329,11 @@ void subtract_normal_contrib(
break;
}

if (rSkCh.m_sharedIds.exists(rContrib.shared) && ! rChSP.sharedRemoved.test(rContrib.shared.value))
if (rSkCh.m_sharedIds.exists(rContrib.shared) && ! rChSP.sharedRemoved.contains(rContrib.shared))
{
osp::Vector3 &rNormal = rGeom.sharedNormalSum[rContrib.shared];
rNormal -= rContrib.sum;
rChSP.sharedNormalsDirty.set(rContrib.shared.value);
rChSP.sharedNormalsDirty.insert(rContrib.shared);
}
rContrib.sum *= 0.0f;
}
Expand All @@ -354,12 +354,12 @@ void subtract_normal_contrib(
break;
}

if (rSkCh.m_sharedIds.exists(shared) && ! rChSP.sharedRemoved.test(shared.value))
if (rSkCh.m_sharedIds.exists(shared) && ! rChSP.sharedRemoved.contains(shared))
{
Vector3 const &contrib = fillNormalContrib[i];
Vector3 &rNormal = rGeom.sharedNormalSum[shared];
rNormal -= contrib;
rChSP.sharedNormalsDirty.set(shared.value);
rChSP.sharedNormalsDirty.insert(shared);
}
fillNormalContrib[i] *= 0.0f;
}
Expand Down
6 changes: 3 additions & 3 deletions src/planet-a/chunk_generate.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ struct ChunkScratchpad
std::vector<ChunkId> chunksAdded;

/// Recently added shared vertices, position needs to be copied from skeleton
osp::BitVector_t sharedAdded;
lgrn::IdSetStl<SharedVrtxId> sharedAdded;

/// Recently added shared vertices
osp::BitVector_t sharedRemoved;
lgrn::IdSetStl<SharedVrtxId> sharedRemoved;

/// Shared vertices that need to recalculate normals
osp::BitVector_t sharedNormalsDirty;
lgrn::IdSetStl<SharedVrtxId> sharedNormalsDirty;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/planet-a/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct TerrainFaceWriter
fillNormalContrib[local.value] += selectedFaceNormal;
sharedNormalSum [shared.value] += selectedFaceNormal;

rSharedNormalsDirty.set(shared.value);
rSharedNormalsDirty.insert(shared);
}

void fill_add_normal_filled(VertexIdx const vertex)
Expand Down Expand Up @@ -187,7 +187,7 @@ struct TerrainFaceWriter
{
rContrib.shared = shared;
rContrib.sum = osp::Vector3{osp::ZeroInit};
rSharedNormalsDirty.set(shared.value);
rSharedNormalsDirty.insert(shared);
std::advance(contribLast, 1);
LGRN_ASSERT(contribLast != fanNormalContrib.end());
}
Expand All @@ -212,7 +212,7 @@ struct TerrainFaceWriter
osp::Vector3u selectedFaceIndx;
IndxIt_t currentFace;
ContribIt_t contribLast;
osp::BitVector_t &rSharedNormalsDirty;
lgrn::IdSetStl<SharedVrtxId> &rSharedNormalsDirty;
};
static_assert(CFaceWriter<TerrainFaceWriter>, "TerrainFaceWriter must satisfy concept CFaceWriter");

Expand Down
24 changes: 12 additions & 12 deletions src/planet-a/skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ void SubdivTriangleSkeleton::tri_group_resize_fit_ids()

for (int lvl = 0; lvl < this->levelMax+1; ++lvl)
{
osp::bitvector_resize(levels[lvl].hasSubdivedNeighbor, triCapacity);
osp::bitvector_resize(levels[lvl].hasNonSubdivedNeighbor, triCapacity);
levels[lvl].hasSubdivedNeighbor .resize(triCapacity);
levels[lvl].hasNonSubdivedNeighbor.resize(triCapacity);
}
}

Expand Down Expand Up @@ -322,24 +322,24 @@ void SubdivTriangleSkeleton::debug_check_invariants()

if (sktri.children.has_value())
{
LGRN_ASSERTMV(rLvl.hasNonSubdivedNeighbor.test(sktriId.value) == (nonSubdivedNeighbors != 0),
LGRN_ASSERTMV(rLvl.hasNonSubdivedNeighbor.contains(sktriId) == (nonSubdivedNeighbors != 0),
"Incorrectly set hasNonSubdivedNeighbor",
sktriId.value,
int(group.depth),
rLvl.hasNonSubdivedNeighbor.test(sktriId.value),
rLvl.hasNonSubdivedNeighbor.contains(sktriId),
nonSubdivedNeighbors);
LGRN_ASSERTM(rLvl.hasSubdivedNeighbor.test(sktriId.value) == false,
LGRN_ASSERTM(rLvl.hasSubdivedNeighbor.contains(sktriId) == false,
"hasSubdivedNeighbor is only for non-subdivided tris");
}
else
{
LGRN_ASSERTMV(rLvl.hasSubdivedNeighbor.test(sktriId.value) == (subdivedNeighbors != 0),
LGRN_ASSERTMV(rLvl.hasSubdivedNeighbor.contains(sktriId) == (subdivedNeighbors != 0),
"Incorrectly set hasSubdivedNeighbor",
sktriId.value,
int(group.depth),
rLvl.hasSubdivedNeighbor.test(sktriId.value),
rLvl.hasSubdivedNeighbor.contains(sktriId),
subdivedNeighbors);
LGRN_ASSERTM(rLvl.hasNonSubdivedNeighbor.test(sktriId.value) == false,
LGRN_ASSERTM(rLvl.hasNonSubdivedNeighbor.contains(sktriId) == false,
"hasNonSubdivedNeighbor is only for subdivided tris");
}
}
Expand Down Expand Up @@ -369,7 +369,7 @@ void SubdivTriangleSkeleton::debug_check_invariants()
ChunkId ChunkSkeleton::chunk_create(
SkTriId const sktriId,
SubdivTriangleSkeleton &rSkel,
osp::BitVector_t &rSharedAdded,
lgrn::IdSetStl<SharedVrtxId> &rSharedAdded,
osp::ArrayView<MaybeNewId<SkVrtxId>> const edgeLft,
osp::ArrayView<MaybeNewId<SkVrtxId>> const edgeBtm,
osp::ArrayView<MaybeNewId<SkVrtxId>> const edgeRte)
Expand All @@ -383,7 +383,7 @@ ChunkId ChunkSkeleton::chunk_create(
MaybeNewId<SharedVrtxId> const shared = shared_get_or_create(vrtx, rSkel);
if (shared.isNew)
{
rSharedAdded.set(shared.id.value);
rSharedAdded.insert(shared.id);
}
return shared_store(shared.id);
};
Expand Down Expand Up @@ -422,7 +422,7 @@ ChunkId ChunkSkeleton::chunk_create(
void ChunkSkeleton::chunk_remove(
ChunkId const chunkId,
SkTriId const sktriId,
osp::BitVector_t &rSharedRemoved,
lgrn::IdSetStl<SharedVrtxId> &rSharedRemoved,
SubdivTriangleSkeleton &rSkel) noexcept
{
for (SharedVrtxOwner_t& rOwner : shared_vertices_used(chunkId))
Expand All @@ -431,7 +431,7 @@ void ChunkSkeleton::chunk_remove(
auto const status = shared_release(std::exchange(rOwner, {}), rSkel);
if (status.refCount == 0)
{
rSharedRemoved.set(shared.value);
rSharedRemoved.insert(shared);
}
}
m_triToChunk[sktriId] = {};
Expand Down
11 changes: 6 additions & 5 deletions src/planet-a/skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
#include "planeta_types.h"

#include <osp/core/array_view.h>
#include <osp/core/bitvector.h>
#include <osp/core/copymove_macros.h>
#include <osp/core/keyed_vector.h>
#include <osp/core/math_2pow.h>

#include <longeron/id_management/id_set_stl.hpp>

#include <array>
#include <vector>

Expand Down Expand Up @@ -394,10 +395,10 @@ class SubdivTriangleSkeleton
struct Level
{
/// Subdivided triangles that neighbor a non-subdivided one
osp::BitVector_t hasNonSubdivedNeighbor;
lgrn::IdSetStl<SkTriId> hasNonSubdivedNeighbor;

/// Non-subdivided triangles that neighbor a subdivided one
osp::BitVector_t hasSubdivedNeighbor;
lgrn::IdSetStl<SkTriId> hasSubdivedNeighbor;
};

std::array<Level, gc_maxSubdivLevels> levels;
Expand Down Expand Up @@ -482,12 +483,12 @@ class ChunkSkeleton
ChunkId chunk_create(
SkTriId sktriId,
SubdivTriangleSkeleton &rSkel,
osp::BitVector_t &rSharedAdded,
lgrn::IdSetStl<SharedVrtxId> &rSharedAdded,
osp::ArrayView< osp::MaybeNewId<SkVrtxId> > edgeLft,
osp::ArrayView< osp::MaybeNewId<SkVrtxId> > edgeBtm,
osp::ArrayView< osp::MaybeNewId<SkVrtxId> > edgeRte);

void chunk_remove(ChunkId chunkId, SkTriId sktriId, osp::BitVector_t &rSharedRemoved, SubdivTriangleSkeleton& rSkel) noexcept;
void chunk_remove(ChunkId chunkId, SkTriId sktriId, lgrn::IdSetStl<SharedVrtxId> &rSharedRemoved, SubdivTriangleSkeleton& rSkel) noexcept;

/**
* @brief Get shared vertices used by a chunk
Expand Down
Loading

0 comments on commit b8e9f99

Please sign in to comment.