Skip to content

Commit

Permalink
Merge pull request #285 from Lamakaio/update-lgrn
Browse files Browse the repository at this point in the history
Replace osp::BitVector_t with lgrn::IdSetStl
  • Loading branch information
Capital-Asterisk authored May 31, 2024
2 parents 6cba389 + cbc2dbd commit a76e382
Show file tree
Hide file tree
Showing 28 changed files with 163 additions and 170 deletions.
8 changes: 3 additions & 5 deletions src/adera/drawing_gl/flat_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ struct ArgsForSyncDrawEntFlat

inline void sync_drawent_flat(osp::draw::DrawEnt ent, ArgsForSyncDrawEntFlat const args)
{
auto const entInt = std::size_t(ent);

bool const hasMaterial = args.hasMaterial.test(entInt);
bool const hasMaterial = args.hasMaterial.contains(ent);
bool const hasTexture = (args.diffuse.size() > std::size_t(ent))
&& (args.diffuse[ent].m_glId != lgrn::id_null<osp::draw::TexGlId>());

Expand All @@ -92,7 +90,7 @@ inline void sync_drawent_flat(osp::draw::DrawEnt ent, ArgsForSyncDrawEntFlat con

if (args.pStorageTransparent != nullptr)
{
auto value = (hasMaterial && args.transparent.test(entInt))
auto value = (hasMaterial && args.transparent.contains(ent))
? std::make_optional(osp::draw::EntityToDraw{&draw_ent_flat, {&args.rData, pShader}})
: std::nullopt;

Expand All @@ -101,7 +99,7 @@ inline void sync_drawent_flat(osp::draw::DrawEnt ent, ArgsForSyncDrawEntFlat con

if (args.pStorageOpaque != nullptr)
{
auto value = (hasMaterial && args.opaque.test(entInt))
auto value = (hasMaterial && args.opaque.contains(ent))
? std::make_optional(osp::draw::EntityToDraw{&draw_ent_flat, {&args.rData, pShader}})
: std::nullopt;

Expand Down
7 changes: 3 additions & 4 deletions src/adera/drawing_gl/phong_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ struct ArgsForSyncDrawEntPhong

inline void sync_drawent_phong(osp::draw::DrawEnt ent, ArgsForSyncDrawEntPhong const args)
{
auto const entInt = std::size_t(ent);

bool const hasMaterial = args.hasMaterial.test(entInt);
bool const hasMaterial = args.hasMaterial.contains(ent);
bool const hasTexture = (args.diffuse.size() > std::size_t(ent)) && (args.diffuse[ent].m_glId != lgrn::id_null<osp::draw::TexGlId>());

PhongGL *pShader = hasTexture
Expand All @@ -93,7 +92,7 @@ inline void sync_drawent_phong(osp::draw::DrawEnt ent, ArgsForSyncDrawEntPhong c

if (args.pStorageTransparent != nullptr)
{
auto value = (hasMaterial && args.transparent.test(entInt))
auto value = (hasMaterial && args.transparent.contains(ent))
? std::make_optional(osp::draw::EntityToDraw{&draw_ent_phong, {&args.rData, pShader}})
: std::nullopt;

Expand All @@ -102,7 +101,7 @@ inline void sync_drawent_phong(osp::draw::DrawEnt ent, ArgsForSyncDrawEntPhong c

if (args.pStorageOpaque != nullptr)
{
auto value = (hasMaterial && args.opaque.test(entInt))
auto value = (hasMaterial && args.opaque.contains(ent))
? std::make_optional(osp::draw::EntityToDraw{&draw_ent_phong, {&args.rData, pShader}})
: std::nullopt;

Expand Down
2 changes: 1 addition & 1 deletion src/adera/drawing_gl/visualizer_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ inline void sync_drawent_visualizer(
ACtxDrawMeshVisualizer& rData)
{
bool alreadyAdded = rStorage.contains(ent);
if (hasMaterial.test(std::size_t(ent)))
if (hasMaterial.contains(ent))
{
if ( ! alreadyAdded)
{
Expand Down
6 changes: 3 additions & 3 deletions src/osp/activescene/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@

#include "active_ent.h"

#include "../core/bitvector.h"
#include "../core/keyed_vector.h"
#include "../core/math_types.h"
#include "../core/storage.h"

#include <longeron/id_management/null.hpp>
#include <longeron/id_management/registry_stl.hpp> // for lgrn::IdRegistryStl
#include <longeron/id_management/registry_stl.hpp>
#include <longeron/id_management/id_set_stl.hpp>

#include <string>

namespace osp::active
{

using ActiveEntVec_t = std::vector<ActiveEnt>;
using ActiveEntSet_t = BitVector_t;
using ActiveEntSet_t = lgrn::IdSetStl<ActiveEnt>;

/**
* @brief Component for transformation (in meters)
Expand Down
4 changes: 2 additions & 2 deletions src/osp/activescene/physics_fn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void SysPhysics::calculate_subtree_mass_center(
rMassPos += childTf.translation() * childMass.m_mass;
}

if (rCtxPhys.m_hasColliders.test(std::size_t(child)))
if (rCtxPhys.m_hasColliders.contains(child))
{
calculate_subtree_mass_center(rTf, rCtxPhys, rScnGraph, child, rMassPos, rTotalMass, childTf);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ void SysPhysics::calculate_subtree_mass_inertia(
rInertiaTensor += transform_inertia_tensor(inertiaTensor, childMass.m_mass, offset, childTf.rotation());
}

if (rCtxPhys.m_hasColliders.test(std::size_t(child)))
if (rCtxPhys.m_hasColliders.contains(child))
{
calculate_subtree_mass_inertia(rTf, rCtxPhys, rScnGraph, child, rInertiaTensor, childTf);
}
Expand Down
6 changes: 3 additions & 3 deletions src/osp/activescene/prefab_fn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void SysPrefabInit::init_info(

if (parents[i] == -1)
{
rPrefabs.roots.set(std::size_t(ent));
rPrefabs.roots.insert(ent);
}
}

Expand Down Expand Up @@ -222,11 +222,11 @@ void SysPrefabInit::init_physics(
= [&rHasColliders = rCtxPhys.m_hasColliders, ents, objects, parents]
(auto const& self, int objectId, ActiveEnt ent) -> void
{
if (rHasColliders.test(std::size_t(ent)))
if (rHasColliders.contains(ent))
{
return; // HasColliders bit already set, this means all ancestors have it set too
}
rHasColliders.set(std::size_t(ent));
rHasColliders.insert(ent);

int const parentId = parents[objectId];

Expand Down
19 changes: 10 additions & 9 deletions src/osp/drawing/drawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "draw_ent.h"

#include "../core/bitvector.h"
#include "../core/copymove_macros.h"
#include "../core/id_map.h"
#include "../core/keyed_vector.h"
Expand All @@ -35,18 +34,20 @@
#include "../core/storage.h"

#include "../activescene/active_ent.h"
#include "../activescene/basic.h"

#include <Magnum/Magnum.h>
#include <Magnum/Math/Color.h>

#include <longeron/id_management/refcount.hpp>
#include <longeron/id_management/registry_stl.hpp> // for lgrn::IdRegistryStl
#include <longeron/id_management/registry_stl.hpp>
#include <longeron/id_management/id_set_stl.hpp>

namespace osp::draw
{

using DrawEntVec_t = std::vector<DrawEnt>;
using DrawEntSet_t = BitVector_t;
using DrawEntSet_t = lgrn::IdSetStl<DrawEnt>;

struct Material
{
Expand Down Expand Up @@ -122,9 +123,9 @@ struct ACtxSceneRender
{
std::size_t const size = m_drawIds.capacity();

bitvector_resize(m_opaque, size);
bitvector_resize(m_transparent, size);
bitvector_resize(m_visible, size);
m_opaque.resize(size);
m_transparent.resize(size);
m_visible.resize(size);

m_drawTransform .resize(size);
m_color .resize(size, {1.0f, 1.0f, 1.0f, 1.0f}); // Default white
Expand All @@ -133,13 +134,13 @@ struct ACtxSceneRender

for (uint32_t matInt : m_materialIds.bitview().zeros())
{
bitvector_resize(m_materials[MaterialId(matInt)].m_ents, size);
m_materials[MaterialId(matInt)].m_ents.resize(size);
}
}

void resize_active(std::size_t const size)
{
bitvector_resize(m_needDrawTf, size);
m_needDrawTf.resize(size);
m_activeToDraw .resize(size, lgrn::id_null<DrawEnt>());
drawTfObserverEnable.resize(size, 0);
}
Expand All @@ -151,7 +152,7 @@ struct ACtxSceneRender
DrawEntSet_t m_visible;
DrawEntColors_t m_color;

DrawEntSet_t m_needDrawTf;
active::ActiveEntSet_t m_needDrawTf;
KeyedVec<active::ActiveEnt, DrawEnt> m_activeToDraw;

KeyedVec<active::ActiveEnt, uint16_t> drawTfObserverEnable;
Expand Down
8 changes: 4 additions & 4 deletions src/osp/drawing/drawing_fn.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ void SysRender::needs_draw_transforms(
active::ActiveEntSet_t& rNeedDrawTf,
active::ActiveEnt ent)
{
rNeedDrawTf.set(ent.value);
rNeedDrawTf.insert(ent);

active::ActiveEnt const parentEnt = scnGraph.m_entParent[ent];

if ( parentEnt != lgrn::id_null<active::ActiveEnt>()
&& ! rNeedDrawTf.test(std::size_t(parentEnt)) )
&& ! rNeedDrawTf.contains(parentEnt) )
{
SysRender::needs_draw_transforms(scnGraph, rNeedDrawTf, parentEnt);
}
Expand All @@ -234,7 +234,7 @@ void SysRender::update_draw_transforms(
{
active::ActiveEnt const ent = *first;

if (args.needDrawTf.test(ent.value))
if (args.needDrawTf.contains(ent))
{
update_draw_transforms_recurse(args, ent, identity, true, func);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ void SysRender::update_draw_transforms_recurse(

for (ActiveEnt entChild : SysSceneGraph::children(args.scnGraph, ent))
{
if (args.needDrawTf.test(std::size_t(entChild)))
if (args.needDrawTf.contains(entChild))
{
update_draw_transforms_recurse(args, entChild, entDrawTf, depth + 1, func);
}
Expand Down
22 changes: 9 additions & 13 deletions src/osp/drawing/prefab_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ void SysPrefabDraw::resync_drawents(
ACtxDrawing& rDrawing,
ACtxSceneRender& rScnRender)
{
for (std::size_t const rootInt : rPrefabs.roots.ones())
for (ActiveEnt const root : rPrefabs.roots)
{
auto const root = ActiveEnt::from_index(rootInt);

PrefabInstanceInfo const &rRootInfo = rPrefabs.instanceInfo[root];

LGRN_ASSERT(rRootInfo.prefab != lgrn::id_null<PrefabId>());
Expand Down Expand Up @@ -130,7 +128,7 @@ void SysPrefabDraw::init_mesh_texture_material(
= [&parents, &ents, &rDrawing, &needDrawTf = rScnRender.m_needDrawTf]
(auto&& self, int const object, ActiveEnt const ent) noexcept -> void
{
needDrawTf.set(ent.value);
needDrawTf.insert(ent);

int const parentObj = parents[object];

Expand Down Expand Up @@ -176,13 +174,13 @@ void SysPrefabDraw::init_mesh_texture_material(
}
}

rScnRender.m_opaque.set(drawEnt.value);
rScnRender.m_visible.set(drawEnt.value);
rScnRender.m_opaque.insert(drawEnt);
rScnRender.m_visible.insert(drawEnt);

if (material != lgrn::id_null<MaterialId>())
{
rScnRender.m_materials[material].m_dirty.push_back(drawEnt);
rScnRender.m_materials[material].m_ents.set(drawEnt.value);
rScnRender.m_materials[material].m_ents.insert(drawEnt);
}
}

Expand All @@ -200,10 +198,8 @@ void SysPrefabDraw::resync_mesh_texture_material(
ACtxSceneRender& rScnRender,
MaterialId material)
{
for (std::size_t const rootInt : rPrefabs.roots.ones())
for (ActiveEnt const root : rPrefabs.roots)
{
auto const root = ActiveEnt::from_index(rootInt);

PrefabInstanceInfo const &rRootInfo = rPrefabs.instanceInfo[root];

LGRN_ASSERT(rRootInfo.prefab != lgrn::id_null<PrefabId>());
Expand Down Expand Up @@ -248,13 +244,13 @@ void SysPrefabDraw::resync_mesh_texture_material(
}
}

rScnRender.m_opaque.set(drawEnt.value);
rScnRender.m_visible.set(drawEnt.value);
rScnRender.m_opaque.insert(drawEnt);
rScnRender.m_visible.insert(drawEnt);

if (material != lgrn::id_null<MaterialId>())
{
rScnRender.m_materials[material].m_dirty.push_back(drawEnt);
rScnRender.m_materials[material].m_ents.set(drawEnt.value);
rScnRender.m_materials[material].m_ents.insert(drawEnt);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/osp/drawing_gl/rendergl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void SysRenderGL::draw_group(
{
for (auto const& [ent, toDraw] : entt::basic_view{group.entities}.each())
{
if (visible.test(std::size_t(ent)))
if (visible.contains(ent))
{
toDraw.draw(ent, viewProj, toDraw.data);
}
Expand Down
6 changes: 3 additions & 3 deletions src/osp/link/machines.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#pragma once

#include "../core/array_view.h"
#include "../core/bitvector.h"
#include "../core/global_id.h"
#include "../core/keyed_vector.h"

#include <longeron/containers/intarray_multimap.hpp>
#include <longeron/containers/bit_view.hpp>
#include <longeron/id_management/registry_stl.hpp>
#include <longeron/id_management/id_set_stl.hpp>

#include <atomic>
#include <vector>
Expand Down Expand Up @@ -81,10 +81,10 @@ struct MachineUpdater
{
alignas(64) std::atomic<bool> requestMachineUpdateLoop {false};

BitVector_t machTypesDirty;
lgrn::IdSetStl<MachTypeId> machTypesDirty;

// [MachTypeId][MachLocalId]
osp::KeyedVec<MachTypeId, BitVector_t> localDirty;
osp::KeyedVec<MachTypeId, lgrn::IdSetStl<MachLocalId>> localDirty;
};

struct MachinePair
Expand Down
8 changes: 4 additions & 4 deletions src/osp/link/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ using SignalValues_t = std::vector<VALUE_T>;
template <typename VALUE_T>
struct UpdateNodes
{
BitVector_t nodeDirty;
lgrn::IdSetStl<NodeId> nodeDirty;
SignalValues_t<VALUE_T> nodeNewValues;

bool dirty{false};

void assign(NodeId node, VALUE_T value)
{
dirty = true;
nodeDirty.set(node);
nodeDirty.insert(node);
nodeNewValues[node] = std::forward<VALUE_T>(value);
}
};
Expand Down Expand Up @@ -75,10 +75,10 @@ bool update_signal_nodes(
somethingNotified = true;

// A machine of type "junc.m_type" has new values to read
rUpdMach.machTypesDirty.set(junc.type);
rUpdMach.machTypesDirty.insert(junc.type);

// Specify using local Id on which machine needs to update
rUpdMach.localDirty[junc.type].set(junc.local);
rUpdMach.localDirty[junc.type].insert(junc.local);
}
}
}
Expand Down
Loading

0 comments on commit a76e382

Please sign in to comment.