Skip to content

Commit

Permalink
#63. Celerity: Detect event partial consumption caused by production …
Browse files Browse the repository at this point in the history
…in children views.
  • Loading branch information
KonstantinTomashevich committed Feb 6, 2023
1 parent 5f720ab commit d663181
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
24 changes: 24 additions & 0 deletions Library/Public/Celerity/Public/Celerity/PipelineBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,24 @@ ChangeTracker *TaskConstructor::BindChangeTracker (const StandardLayout::Mapping

void TaskConstructor::RegisterEventProduction (const StandardLayout::Mapping &_eventType) noexcept
{
// Check that message production is not forbidden by parent views.
WorldView *viewToCheck = parent->worldView->parent;

while (viewToCheck)
{
if (viewToCheck->eventProductionForbiddenInChildren.contains (_eventType))
{
parent->anyErrorsDetected = true;
EMERGENCE_LOG (ERROR, "Events of type \"", _eventType.GetName (), "\" can not be produced in world view \"",
parent->worldView->GetName (), "\" as its parent view \"", viewToCheck->GetName (),
"\" forbids production in children views. It usually happens when production would result "
"in partial consumption of events.");
break;
}

viewToCheck = viewToCheck->parent;
}

PipelineBuilder::EventUsageMap &productionMap =
parent->eventProduction[static_cast<std::size_t> (parent->currentPipelineType)];

Expand Down Expand Up @@ -607,6 +625,11 @@ void PipelineBuilder::AddCheckpoint (Memory::UniqueString _name) noexcept
taskRegister.RegisterCheckpoint (_name);
}

void PipelineBuilder::AddCheckpointDependency (Memory::UniqueString _from, Memory::UniqueString _to) noexcept
{
taskRegister.RegisterCheckpointDependency (_from, _to);
}

Flow::TaskRegister::VisualGroupNodePlaced PipelineBuilder::OpenVisualGroup (Container::String _name) noexcept
{
return taskRegister.OpenVisualGroup (std::move (_name));
Expand Down Expand Up @@ -802,6 +825,7 @@ void PipelineBuilder::PostProcessContinuousEventRoutine (const PipelineBuilder::
if (dependsOnAllProducers)
{
// Belongs to "current execution consumers" category.
worldView->eventProductionForbiddenInChildren.emplace (eventType);
continue;
}

Expand Down
4 changes: 4 additions & 0 deletions Library/Public/Celerity/Public/Celerity/PipelineBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ class PipelineBuilder final
/// \invariant Checkpoint name is unique.
void AddCheckpoint (Memory::UniqueString _name) noexcept;

/// \brief Registers external dependency between given checkpoints. Make `_to` dependant of `_from`.
/// \details External checkpoint dependency addition makes it easier to glue together different modules.
void AddCheckpointDependency (Memory::UniqueString _from, Memory::UniqueString _to) noexcept;

/// \brief Calls TaskRegister::OpenVisualGroup for task visual grouping.
Flow::TaskRegister::VisualGroupNodePlaced OpenVisualGroup (Container::String _name) noexcept;

Expand Down
9 changes: 5 additions & 4 deletions Library/Public/Celerity/Public/Celerity/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ WorldView::WorldView (World *_world,
eventSchemeInstances (
{EventSchemeInstance {Memory::Profiler::AllocationGroup {"NormalUpdateEventSchemeInstance"_us}},
EventSchemeInstance {Memory::Profiler::AllocationGroup {"FixedUpdateEventSchemeInstance"_us}},
EventSchemeInstance {Memory::Profiler::AllocationGroup {"CustomPipelinesEventSchemeInstance"_us}}})
EventSchemeInstance {Memory::Profiler::AllocationGroup {"CustomPipelinesEventSchemeInstance"_us}}}),
eventProductionForbiddenInChildren (Memory::Profiler::AllocationGroup::Top ())
{
for (const StandardLayout::Mapping &enforcedType : _config.enforcedTypes)
{
Expand Down Expand Up @@ -257,9 +258,9 @@ TrivialEventTriggerInstanceRow *WorldView::RequestTrivialEventInstances (
TrivialEventTriggerInstanceRow &row = _pool.Acquire ();
for (const TrivialEventTrigger &trigger : *_source)
{
row.EmplaceBack (TrivialEventTriggerInstance {
&trigger,
FindViewForType (trigger.GetEventType ()).localRegistry.InsertShortTerm (trigger.GetEventType ())});
WorldView &view = FindViewForType (trigger.GetEventType ());
row.EmplaceBack (
TrivialEventTriggerInstance {&trigger, view.localRegistry.InsertShortTerm (trigger.GetEventType ())});
}

return &row;
Expand Down
2 changes: 2 additions & 0 deletions Library/Public/Celerity/Public/Celerity/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class WorldView final
Memory::Heap childrenHeap;
Container::Vector<WorldView *> childrenViews;
std::array<EventSchemeInstance, static_cast<std::size_t> (PipelineType::COUNT)> eventSchemeInstances;

Container::HashSet<StandardLayout::Mapping> eventProductionForbiddenInChildren;
};

/// \brief Contains basic configuration for WorldSingleton and TimeSingleton.
Expand Down

0 comments on commit d663181

Please sign in to comment.