Skip to content

Commit

Permalink
Merge pull request #281 from Capital-Asterisk/update-lgrn
Browse files Browse the repository at this point in the history
Update Longeron++ submodule
  • Loading branch information
Capital-Asterisk authored May 29, 2024
2 parents a5c4ea4 + b8e9f99 commit c42ed31
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 180 deletions.
4 changes: 2 additions & 2 deletions src/osp/core/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ResId Resources::create(ResTypeId const typeId, PkgId const pkgId, SharedString
assert(rPkg.m_resTypeOwn.size() > std::size_t(typeId));
PerPkgResType &rPkgType = rPkg.m_resTypeOwn[std::size_t(typeId)];
rPkgType.m_owned.resize(rPerResType.m_resIds.capacity());
rPkgType.m_owned.set(std::size_t(newResId));
rPkgType.m_owned.insert(newResId);

// Track name
auto const& [newIt, success] = rPkgType.m_nameToResId.emplace(std::move(name), newResId);
Expand Down Expand Up @@ -80,7 +80,7 @@ SharedString const& Resources::name(ResTypeId const typeId, ResId const resId) c
return rPerResType.m_resNames[std::size_t(resId)];
}

lgrn::IdRegistry<ResId> const& Resources::ids(ResTypeId const typeId) const noexcept
lgrn::IdRegistryStl<ResId> const& Resources::ids(ResTypeId const typeId) const noexcept
{
return get_type(typeId).m_resIds;
}
Expand Down
19 changes: 12 additions & 7 deletions src/osp/core/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
*/
#pragma once

#include "copymove_macros.h"
#include "shared_string.h"
#include "resourcetypes.h"

#include <longeron/id_management/registry.hpp>
#include <longeron/id_management/id_set_stl.hpp>
#include <longeron/id_management/refcount.hpp>
#include <longeron/id_management/registry_stl.hpp>

#include <entt/core/family.hpp>
#include <entt/core/any.hpp>
Expand All @@ -48,7 +50,7 @@ class Resources

struct PerResType
{
lgrn::IdRegistry<ResId> m_resIds;
lgrn::IdRegistryStl<ResId> m_resIds;
lgrn::RefCount<int> m_resRefs;
std::vector<res_data_type_t> m_resDataTypes;
std::vector<entt::any> m_resData;
Expand All @@ -59,7 +61,7 @@ class Resources

struct PerPkgResType
{
lgrn::HierarchicalBitset<uint64_t> m_owned;
lgrn::IdSetStl<ResId> m_owned;
std::unordered_map< SharedString, ResId, std::hash<SharedString>, std::equal_to<> > m_nameToResId;
};

Expand All @@ -70,6 +72,9 @@ class Resources

public:

Resources() = default;
OSP_MOVE_ONLY_CTOR_ASSIGN(Resources);

/**
* @brief Resize to fit a certain number of resource types
*
Expand Down Expand Up @@ -103,7 +108,7 @@ class Resources
*/
[[nodiscard]] SharedString const& name(ResTypeId typeId, ResId resId) const noexcept;

[[nodiscard]] lgrn::IdRegistry<ResId> const& ids(ResTypeId typeId) const noexcept;
[[nodiscard]] lgrn::IdRegistryStl<ResId> const& ids(ResTypeId typeId) const noexcept;

[[nodiscard]] ResIdOwner_t owner_create(ResTypeId typeId, ResId resId) noexcept;

Expand Down Expand Up @@ -201,9 +206,9 @@ class Resources
template <typename T>
res_container_t<T> const& get_container(PerResType const &rPerResType, ResTypeId typeId) const;

std::vector<PerResType> m_perResType;
lgrn::IdRegistry<PkgId> m_pkgIds;
std::vector<PerPkg> m_pkgData;
std::vector<PerResType> m_perResType;
lgrn::IdRegistryStl<PkgId> m_pkgIds;
std::vector<PerPkg> m_pkgData;
};

template<typename T>
Expand Down
6 changes: 3 additions & 3 deletions src/osp/drawing_gl/rendergl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <Magnum/Trade/MeshData.h>
#include <Magnum/Trade/ImageData.h>

#include <longeron/id_management/registry.hpp>
#include <longeron/id_management/registry_stl.hpp>

namespace osp::draw
{
Expand Down Expand Up @@ -65,11 +65,11 @@ struct RenderGL
Magnum::GL::Framebuffer m_fbo{Corrade::NoCreate};

// Renderer-space GL Textures
lgrn::IdRegistry<TexGlId> m_texIds;
lgrn::IdRegistryStl<TexGlId> m_texIds;
TexGlStorage_t m_texGl;

// Renderer-space GL Meshes
lgrn::IdRegistry<MeshGlId> m_meshIds;
lgrn::IdRegistryStl<MeshGlId> m_meshIds;
MeshGlStorage_t m_meshGl;

// Associate GL Texture Ids with resources
Expand Down
9 changes: 8 additions & 1 deletion src/osp/tasks/top_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "tasks.h"
#include "top_utils.h"
#include "top_worker.h"

#include "../core/unpack.h"

Expand All @@ -38,7 +39,13 @@
#include <vector>

#define OSP_AUX_DCDI_C(session, topData, count, ...) \
session.m_data.resize(count); \
session.m_data.resize(count, lgrn::id_null<osp::TopDataId>()); \
for (osp::TopDataId const id : session.m_data) \
{ \
LGRN_ASSERTM(id == lgrn::id_null<osp::TopDataId>(),\
"Can't replace existing TopDataId. " \
"You likely meant to use GET_DATA_IDS instead of CREATE_DATA_IDS?");\
} \
osp::top_reserve(topData, 0, session.m_data.begin(), session.m_data.end()); \
auto const [__VA_ARGS__] = osp::unpack<count>(session.m_data)
#define OSP_AUX_DCDI_B(x) x
Expand Down
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 c42ed31

Please sign in to comment.