Skip to content

Commit

Permalink
Fix the busted LineFeatures demo, and rename the ECS namespace to ecs
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Nov 12, 2024
1 parent 1d1ad44 commit 367e7c3
Show file tree
Hide file tree
Showing 28 changed files with 200 additions and 225 deletions.
13 changes: 5 additions & 8 deletions src/apps/rocky_demo/Demo_Decluttering.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ namespace
bool dummy = false;
};

class DeclutterSystem : public ECS::System
class DeclutterSystem
{
public:
DeclutterSystem(entt::registry& registry) : System(registry) { }
DeclutterSystem(entt::registry& in_registry)
: registry(in_registry) { }

entt::registry& registry;
float update_hertz = 1.0f; // updates per second
bool enabled = true;
double buffer_radius = 25.0;
Expand All @@ -41,12 +43,7 @@ namespace
return std::make_shared<DeclutterSystem>(registry);
}

void initializeSystem(Runtime& runtime) override
{
//nop
}

void update(Runtime& runtime) override
void update(Runtime& runtime)
{
total = 0, visible = 0;

Expand Down
19 changes: 9 additions & 10 deletions src/apps/rocky_demo/Demo_Geocoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ auto Demo_Geocoder = [](Application& app)
feature_view.styles.line->color = vsg::vec4{ 1, 1, 0, 1 };
feature_view.styles.line->depth_offset = 9000.0f; //meters

ECS::setVisible(app.registry, entity, false);
//ECS::setVisible(app.registry, feature_view.entity, false);
ecs::setVisible(app.registry, entity, false);
//ecs::setVisible(app.registry, feature_view.entity, false);

// Transform to place the entity:
auto& xform = app.entities.emplace<Transform>(entity);
Expand All @@ -81,7 +81,7 @@ auto Demo_Geocoder = [](Application& app)
{
// hide the placemark:
auto& icon = app.entities.get<Icon>(entity);
ECS::setVisible(app.registry, entity, false);
ecs::setVisible(app.registry, entity, false);

std::string input(input_buf);
geocoding_task = jobs::dispatch([&app, input](jobs::cancelable& c)
Expand Down Expand Up @@ -137,8 +137,8 @@ auto Demo_Geocoder = [](Application& app)
// show the placemark:
if (feature.geometry.type == Geometry::Type::Points)
{
ECS::setVisible(app.registry, entity, true);
ECS::setVisible(app.registry, feature_view.entity, false);
ecs::setVisible(app.registry, entity, true);
ecs::setVisible(app.registry, feature_view.entity, false);
label.style = label_style_point;
}
else
Expand All @@ -151,8 +151,8 @@ auto Demo_Geocoder = [](Application& app)
feature_view.clear(app.entities);
feature_view.features = { copy_of_feature };
feature_view.generate(app.entities, app.mapNode->worldSRS(), app.runtime());
ECS::setVisible(app.registry, entity, true);
ECS::setVisible(app.registry, feature_view.entity, true);
ecs::setVisible(app.registry, entity, true);
ecs::setVisible(app.registry, feature_view.entity, true);
label.style = label_style_area;
}

Expand All @@ -176,9 +176,8 @@ auto Demo_Geocoder = [](Application& app)

app.onNextUpdate([&]()
{
//auto&& [icon, label] = app.entities.get<Icon, Label>(entity);
ECS::setVisible(app.registry, entity, false);
ECS::setVisible(app.registry, feature_view.entity, false);
ecs::setVisible(app.registry, entity, false);
ecs::setVisible(app.registry, feature_view.entity, false);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/apps/rocky_demo/Demo_Icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ auto Demo_Icon = [](Application& app)

if (ImGuiLTable::Begin("icon"))
{
bool visible = ECS::visible(app.registry, entity);
bool visible = ecs::visible(app.registry, entity);
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

auto& icon = app.entities.get<Icon>(entity);

Expand Down
4 changes: 2 additions & 2 deletions src/apps/rocky_demo/Demo_Label.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ auto Demo_Label = [](Application& app)

if (ImGuiLTable::Begin("text"))
{
bool visible = ECS::visible(app.registry, entity);
bool visible = ecs::visible(app.registry, entity);
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

auto& label = app.entities.get<Label>(entity);

Expand Down
8 changes: 4 additions & 4 deletions src/apps/rocky_demo/Demo_Line.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ auto Demo_Line_Absolute = [](Application& app)
const double alt = 10;
for (double lon = -180; lon <= 0.0; lon += 0.25)
{
line.points().emplace_back(lon, -20.0, alt);
line.points.emplace_back(lon, -20.0, alt);
}

// Create a style that we can change dynamically:
Expand All @@ -47,7 +47,7 @@ auto Demo_Line_Absolute = [](Application& app)
{
static bool visible = true;
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

auto& component = app.entities.get<Line>(entity);

Expand Down Expand Up @@ -86,7 +86,7 @@ auto Demo_Line_Relative = [](Application& app)

// Create the line geometry, which will be relative to a transform.
const double size = 500000;
line.points() = {
line.points = {
vsg::dvec3{-size, -size, 0.0},
vsg::dvec3{ size, -size, 0.0},
vsg::dvec3{ 0.0, size, 0.0},
Expand All @@ -106,7 +106,7 @@ auto Demo_Line_Relative = [](Application& app)
{
static bool visible = true;
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

auto& line = app.entities.get<Line>(entity);

Expand Down
4 changes: 2 additions & 2 deletions src/apps/rocky_demo/Demo_LineFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ auto Demo_LineFeatures = [](Application& app)

else if (ImGuiLTable::Begin("Line features"))
{
bool visible = ECS::visible(app.registry, feature_view.entity);
bool visible = ecs::visible(app.registry, feature_view.entity);
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, feature_view.entity, visible);
ecs::setVisible(app.registry, feature_view.entity, visible);

if (feature_view.styles.line.has_value())
{
Expand Down
10 changes: 5 additions & 5 deletions src/apps/rocky_demo/Demo_Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ auto Demo_Mesh_Absolute = [](Application& app)
{
static bool visible = true;
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

auto& mesh = app.entities.get<Mesh>(entity);

Expand Down Expand Up @@ -131,9 +131,9 @@ auto Demo_Mesh_Relative = [](Application& app)

if (ImGuiLTable::Begin("Mesh"))
{
bool visible = ECS::visible(app.registry, entity);
bool visible = ecs::visible(app.registry, entity);
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

auto& mesh = app.entities.get<Mesh>(entity);

Expand Down Expand Up @@ -207,9 +207,9 @@ auto Demo_Mesh_Multi = [](Application& app)

if (ImGuiLTable::Begin("Mesh"))
{
bool visible = ECS::visible(app.registry, entity);
bool visible = ecs::visible(app.registry, entity);
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

auto& mesh = app.entities.get<Mesh>(entity);

Expand Down
4 changes: 2 additions & 2 deletions src/apps/rocky_demo/Demo_Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ auto Demo_Model = [](Application& app)

if (ImGuiLTable::Begin("model"))
{
bool visible = ECS::visible(app.registry, entity);
bool visible = ecs::visible(app.registry, entity);
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

auto& transform = app.entities.get<Transform>(entity);
ImGuiLTable::SliderDouble("Latitude", &transform.position.y, -85.0, 85.0, "%.1lf");
Expand Down
4 changes: 2 additions & 2 deletions src/apps/rocky_demo/Demo_PolygonFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ auto Demo_PolygonFeatures = [](Application& app)

else if (ImGuiLTable::Begin("Polygon features"))
{
bool visible = ECS::visible(app.registry, feature_view.entity);
bool visible = ecs::visible(app.registry, feature_view.entity);
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, feature_view.entity, visible);
ecs::setVisible(app.registry, feature_view.entity, visible);

ImGuiLTable::End();
}
Expand Down
4 changes: 2 additions & 2 deletions src/apps/rocky_demo/Demo_RTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ auto Demo_RTT = [](Application& app)

if (ImGuiLTable::Begin("model"))
{
bool visible = ECS::visible(app.registry, entity);
bool visible = ecs::visible(app.registry, entity);
if (ImGuiLTable::Checkbox("Visible", &visible))
ECS::setVisible(app.registry, entity, visible);
ecs::setVisible(app.registry, entity, visible);

ImGuiLTable::End();
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/rocky_demo/Demo_Tethering.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ auto Demo_Tethering = [](Application& app)

// add an arrow line:
auto& arrow = app.entities.emplace<Line>(entity);
arrow.points() = {
arrow.points = {
vsg::dvec3{ s * 1.5, s * 0.5, 0.0 },
vsg::dvec3{ s * 2.0, 0.0, 0.0 },
vsg::dvec3{ s * 1.5, -s * 0.5, 0.0 }
Expand Down
9 changes: 5 additions & 4 deletions src/apps/rocky_demo/Demo_TrackHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace
std::size_t numChunks = 0;
};

class TrackHistorySystem : public ECS::System
class TrackHistorySystem : public ecs::System
{
public:
TrackHistorySystem(entt::registry& registry) : System(registry) {}
Expand Down Expand Up @@ -103,6 +103,7 @@ namespace
auto& line = registry.emplace<Line>(new_chunk.attach_point);
line.style = track.style;
line.referencePoint = new_chunk.referencePoint;
line.points.reserve(track_chunk_size);

// Tie track visibility to host visibility:
auto& track_visibility = registry.emplace<Visibility>(new_chunk.attach_point);
Expand All @@ -113,7 +114,7 @@ namespace
{
auto prev_chunk = std::prev(std::prev(track.chunks.end()));
auto& prev_line = registry.get<Line>(prev_chunk->attach_point);
line.points().emplace_back(prev_line.points().back());
line.points.emplace_back(prev_line.points.back());
++new_chunk.numPoints;
}

Expand All @@ -125,11 +126,11 @@ namespace
{
auto& line = registry.get<Line>(chunk.attach_point);

if (chunk.numPoints > 0 && line.points().back() == to_vsg((glm::dvec3)(transform.position)))
if (chunk.numPoints > 0 && line.points.back() == to_vsg((glm::dvec3)(transform.position)))
return;

// append the new position:
line.points().emplace_back(to_vsg((glm::dvec3)transform.position));
line.points.emplace_back(to_vsg((glm::dvec3)transform.position));
++chunk.numPoints;
++line.revision;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rocky/vsg/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Application::ctor(int& argc, char** argv)
commandLineStatus = loadMapFile(commandLine[1], *mapNode, instance);
}

ecsManager = ECS::SystemsManagerGroup::create(backgroundServices);
ecsManager = ecs::SystemsManagerGroup::create(backgroundServices);

ecsManager->add<MeshSystemNode>(entities);
ecsManager->add<LineSystemNode>(entities);
Expand Down
2 changes: 1 addition & 1 deletion src/rocky/vsg/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace ROCKY_NAMESPACE
vsg::ref_ptr<vsg::Viewer> viewer;
vsg::ref_ptr<vsg::Group> root;
vsg::ref_ptr<vsg::Group> mainScene;
vsg::ref_ptr<ECS::SystemsManagerGroup> ecsManager;
vsg::ref_ptr<ecs::SystemsManagerGroup> ecsManager;
std::shared_ptr<DisplayManager> displayManager;
BackgroundServices backgroundServices;
bool autoCreateWindow = true;
Expand Down
2 changes: 1 addition & 1 deletion src/rocky/vsg/ECS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ROCKY_ABOUT(entt, ENTT_VERSION);

using namespace ROCKY_NAMESPACE;

ECS::SystemsManagerGroup::SystemsManagerGroup(BackgroundServices& bg)
ecs::SystemsManagerGroup::SystemsManagerGroup(BackgroundServices& bg)
{
vsg::observer_ptr<SystemsManagerGroup> weak_self(this);

Expand Down
Loading

0 comments on commit 367e7c3

Please sign in to comment.