ensure invalidated values are removed

When a node receives an InvalidateCache signal, it will
automatically signal its outputs to discard any cached values in
the invalidated time range
This commit is contained in:
itsmattkc
2019-11-17 12:31:10 +09:00
parent 863525c595
commit 35802d37b0
3 changed files with 21 additions and 0 deletions
+7
View File
@@ -83,6 +83,13 @@ void Node::InvalidateCache(const rational &start_range, const rational &end_rang
{
Q_UNUSED(from)
foreach (NodeParam* param, params_) {
if (param->type() == NodeParam::kOutput) {
NodeOutput* output = static_cast<NodeOutput*>(param);
output->drop_cached_values_overlapping(TimeRange(start_range, end_range));
}
}
SendInvalidateCache(start_range, end_range);
}
+13
View File
@@ -58,3 +58,16 @@ void NodeOutput::drop_cached_values()
{
cached_values_.clear();
}
void NodeOutput::drop_cached_values_overlapping(const TimeRange &time)
{
QHash<TimeRange, QVariant>::iterator i = cached_values_.begin();
while (i != cached_values_.end()) {
if (i.key().OverlapsWith(time)) {
i = cached_values_.erase(i);
} else {
i++;
}
}
}
+1
View File
@@ -46,6 +46,7 @@ public:
QVariant get_cached_value(const TimeRange& time);
void cache_value(const TimeRange& time, const QVariant& value);
void drop_cached_values();
void drop_cached_values_overlapping(const TimeRange& time);
private:
QHash<TimeRange, QVariant> cached_values_;