Skip to content

Commit

Permalink
refactor the ecs classes a bit, and streamline the create-or-update f…
Browse files Browse the repository at this point in the history
…or icons and labels
  • Loading branch information
gwaldron committed Nov 19, 2024
1 parent ba710ad commit ee253ca
Show file tree
Hide file tree
Showing 21 changed files with 922 additions and 847 deletions.
31 changes: 12 additions & 19 deletions src/rocky/GDALElevationLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ namespace
template<typename T>
Status openOnThisThread(
const T* layer,
std::shared_ptr<GDAL::Driver>& driver,
GDAL::Driver& driver,
Profile* profile,
DataExtentList* out_dataExtents,
const IOOptions& io)
{
driver = std::make_shared<GDAL::Driver>();

if (layer->maxDataLevel().has_value())
driver->maxDataLevel = layer->maxDataLevel();
driver.maxDataLevel = layer->maxDataLevel();

if (layer->noDataValue().has_value())
driver->noDataValue = layer->noDataValue();
driver.noDataValue = layer->noDataValue();
if (layer->minValidValue().has_value())
driver->minValidValue = layer->minValidValue();
driver.minValidValue = layer->minValidValue();
if (layer->maxValidValue().has_value())
driver->maxValidValue = layer->maxValidValue();
driver.maxValidValue = layer->maxValidValue();

Status status = driver->open(
Status status = driver.open(
layer->name(),
layer,
layer->tileSize(),
Expand All @@ -48,9 +46,9 @@ namespace
if (status.failed())
return status;

if (driver->profile().valid() && profile != nullptr)
if (driver.profile().valid() && profile != nullptr)
{
*profile = driver->profile();
*profile = driver.profile();
}

return StatusOK;
Expand Down Expand Up @@ -119,12 +117,7 @@ GDALElevationLayer::openImplementation(const IOOptions& io)

DataExtentList dataExtents;

Status s = openOnThisThread(
this,
driver,
&profile,
&dataExtents,
io);
Status s = openOnThisThread(this, driver, &profile, &dataExtents, io);

if (s.failed())
return s;
Expand Down Expand Up @@ -156,16 +149,16 @@ GDALElevationLayer::createHeightfieldImplementation(const TileKey& key, const IO
return status();

auto& driver = _drivers.value();
if (driver == nullptr)
if (!driver.isOpen())
{
// calling openImpl with NULL params limits the setup
// since we already called this during openImplementation
openOnThisThread(this, driver, nullptr, nullptr, io);
}

if (driver)
if (driver.isOpen())
{
auto r = driver->createImage(key, tileSize(), io);
auto r = driver.createImage(key, tileSize(), io);

if (r.status.ok())
{
Expand Down
2 changes: 1 addition & 1 deletion src/rocky/GDALElevationLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace ROCKY_NAMESPACE
//! Called by the constructors
void construct(const std::string& JSON, const IOOptions& io);

mutable util::ThreadLocal<std::shared_ptr<GDAL::Driver>> _drivers;
mutable util::ThreadLocal<GDAL::Driver> _drivers;
friend class GDAL::Driver;
};

Expand Down
12 changes: 1 addition & 11 deletions src/rocky/GDALImageLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ namespace
Status openOnThisThread(
const T* layer,
GDAL::Driver& driver,
//std::shared_ptr<GDAL::Driver>& driver,
Profile* profile,
DataExtentList* out_dataExtents,
const IOOptions& io)
{
Log()->info("Opening GDAL driver on thread {}", std::hash<std::thread::id>{}(std::this_thread::get_id()));

//driver = std::make_shared<GDAL::Driver>();

if (layer->maxDataLevel().has_value())
{
driver.maxDataLevel = layer->maxDataLevel();
Expand Down Expand Up @@ -121,12 +116,7 @@ GDALImageLayer::openImplementation(const IOOptions& io)

DataExtentList dataExtents;

Status s = openOnThisThread(
this,
driver,
&profile,
&dataExtents,
io);
Status s = openOnThisThread(this, driver, &profile, &dataExtents, io);

if (s.failed())
return s;
Expand Down
2 changes: 0 additions & 2 deletions src/rocky/vsg/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
* MIT License
*/
#include "Application.h"
#include "MapNode.h"
#include "MapManipulator.h"
#include "SkyNode.h"
#include "json.h"
#include "engine/MeshSystem.h"
#include "engine/LineSystem.h"
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 @@ -7,7 +7,7 @@
#include <rocky/vsg/InstanceVSG.h>
#include <rocky/vsg/MapNode.h>
#include <rocky/vsg/SkyNode.h>
#include <rocky/vsg/ECS.h>
#include <rocky/vsg/ECSNodes.h>
#include <rocky/vsg/DisplayManager.h>

#include <vsg/app/Viewer.h>
Expand Down
78 changes: 0 additions & 78 deletions src/rocky/vsg/ECS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,5 @@
*/
#include "ECS.h"

ROCKY_ABOUT(entt, ENTT_VERSION);

using namespace ROCKY_NAMESPACE;

ecs::SystemsManagerGroup::SystemsManagerGroup(ecs::Registry& reg, BackgroundServices& bg) :
_registry(reg)
{
vsg::observer_ptr<SystemsManagerGroup> weak_self(this);

auto entity_compiler = [weak_self](jobs::cancelable& cancelable)
{
Log()->info("Entity compiler thread starting up.");
while (!cancelable.canceled())
{
vsg::ref_ptr<SystemsManagerGroup> self(weak_self);
if (!self)
break;

// normally this will be signaled to wake up, but the timeout will
// assure that we don't wait forever during shutdown.
if (self->buildInput.wait(std::chrono::milliseconds(1000)))
{
ecs::BuildBatch batch;

if (self->buildInput.pop(batch))
{
// a group to combine all compiles into one operation
auto group = vsg::Group::create();

for(auto& item : batch.items)
{
batch.system->invokeCreateOrUpdate(item, *batch.runtime);

if (item.new_node)
{
group->addChild(item.new_node);
}
}

// compile everything (creates any new vulkan objects)
if (group->children.size() > 0)
{
// compile all the results at once:
batch.runtime->compile(group);

// queue the results so the merger will pick em up
// (in SystemsManagerGroup::update)
self->buildOutput.emplace(std::move(batch));
}
}
}
}
Log()->info("Entity compiler thread terminating.");
};

bg.start("rocky::entity_compiler", entity_compiler);
}


void
ecs::SystemsManagerGroup::update(Runtime& runtime)
{
// update all systems
for (auto& system : systems)
{
system->update(runtime);
}

// process any new nodes that were compiled
ecs::BuildBatch batch;
while (buildOutput.pop(batch))
{
auto [lock, registry] = _registry.read();

for (auto& item : batch.items)
{
batch.system->mergeCreateOrUpdateResults(registry, item, runtime);
}
}
}
Loading

0 comments on commit ee253ca

Please sign in to comment.