Skip to content

Commit

Permalink
Fixing modifier ranges not updating on the right frame.
Browse files Browse the repository at this point in the history
This animation wasn't ending up on the right frame when quickly moving the cursor left->right. This was an error with update cycle order of the text modifier group vs the text object itself. The modifier group needs to always update before the text object!

@JcToon showed this issue to me in the office today...

https://github.com/rive-app/rive/assets/454182/76692e1d-e670-4324-a8ac-8c8ce0748e52

Diffs=
b17671130 Fixing modifier ranges not updating on the right frame. (#5623)

Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
  • Loading branch information
luigi-rosso and luigi-rosso committed Jul 19, 2023
1 parent e5bb6db commit dabe3a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d1f8710f5bfda934cbbb20727fe7ca2d88a15ff8
b176711307aaa8dade145024af8a29a32b48296a
5 changes: 1 addition & 4 deletions include/rive/text/text_modifier_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class TextModifierGroup : public TextModifierGroupBase
{
public:
StatusCode onAddedDirty(CoreContext* context) override;
void buildDependencies() override;

void addModifierRange(TextModifierRange* range);
void addModifier(TextModifier* modifier);
Expand All @@ -29,15 +28,14 @@ class TextModifierGroup : public TextModifierGroupBase
const rive::SimpleArray<rive::Paragraph>& shape,
const SimpleArray<SimpleArray<GlyphLine>>& lines,
const GlyphLookup& glyphLookup);
void computeCoverage();
void computeCoverage(uint32_t textSize);
float glyphCoverage(uint32_t textIndex, uint32_t codePointCount);
float coverage(uint32_t textIndex)
{
assert(textIndex < m_coverage.size());
return m_coverage[textIndex];
}
void transform(float amount, Mat2D& ctm);
void update(ComponentDirt value) override;
TextRun modifyShape(const Text& text, TextRun run, float strength);
void applyShapeModifiers(const Text& text, StyledText& styledText);

Expand Down Expand Up @@ -78,7 +76,6 @@ class TextModifierGroup : public TextModifierGroupBase
std::vector<TextModifier*> m_modifiers;
std::vector<TextShapeModifier*> m_shapeModifiers;
std::vector<float> m_coverage;
uint32_t m_textSize = 0;
rcp<Font> m_variableFont;
std::vector<Font::Coord> m_variationCoords;
std::vector<TextRun> m_nextTextRuns;
Expand Down
17 changes: 14 additions & 3 deletions src/text/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ void Text::buildRenderStyles()
y -= m_lines[0][0].baseline;
minY = y;
}

bool hasModifiers = haveModifiers();
if (hasModifiers)
{
uint32_t textSize = (uint32_t)m_styledText.unichars().size();
for (TextModifierGroup* modifierGroup : m_modifierGroups)
{
modifierGroup->computeCoverage(textSize);
}
}
for (const SimpleArray<GlyphLine>& paragraphLines : m_lines)
{
const Paragraph& paragraph = m_shape[paragraphIndex++];
Expand Down Expand Up @@ -350,7 +360,6 @@ void Text::buildRenderStyles()

RawPath path = font->getPath(glyphId);

bool hasModifiers = haveModifiers();
uint32_t textIndex = 0;
uint32_t glyphCount = 0;
if (hasModifiers)
Expand Down Expand Up @@ -634,13 +643,14 @@ void Text::update(ComponentDirt value)
sizing() == TextSizing::autoWidth ? -1.0f : width(),
(TextAlign)alignValue());
m_glyphLookup.compute(m_modifierStyledText.unichars(), m_modifierShape);
uint32_t textSize = (uint32_t)m_modifierStyledText.unichars().size();
for (TextModifierGroup* group : m_modifierGroups)
{
group->computeRangeMap(m_modifierStyledText.unichars(),
m_modifierShape,
m_modifierLines,
m_glyphLookup);
group->computeCoverage();
group->computeCoverage(textSize);
}
}
if (makeStyled(m_styledText))
Expand All @@ -653,13 +663,14 @@ void Text::update(ComponentDirt value)
if (!precomputeModifierCoverage && haveModifiers())
{
m_glyphLookup.compute(m_styledText.unichars(), m_shape);
uint32_t textSize = (uint32_t)m_styledText.unichars().size();
for (TextModifierGroup* group : m_modifierGroups)
{
group->computeRangeMap(m_styledText.unichars(),
m_shape,
m_lines,
m_glyphLookup);
group->computeCoverage();
group->computeCoverage(textSize);
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/text/text_modifier_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "rive/text/text_modifier_range.hpp"
#include "rive/text/glyph_lookup.hpp"
#include "rive/text/text_style.hpp"
#include "rive/artboard.hpp"
#include <limits>

using namespace rive;
Expand All @@ -25,8 +26,6 @@ StatusCode TextModifierGroup::onAddedDirty(CoreContext* context)
return StatusCode::MissingObject;
}

void TextModifierGroup::buildDependencies() { parent()->addDependent(this); }

void TextModifierGroup::addModifierRange(TextModifierRange* range) { m_ranges.push_back(range); }

void TextModifierGroup::addModifier(TextModifier* modifier)
Expand Down Expand Up @@ -67,14 +66,6 @@ void TextModifierGroup::rangeChanged()
}
}

void TextModifierGroup::update(ComponentDirt value)
{
if (hasDirt(value, ComponentDirt::TextCoverage))
{
computeCoverage();
}
}

/// Clear any cached selector range maps so they can be recomputed after next
/// shaping.
void TextModifierGroup::clearRangeMaps()
Expand All @@ -91,17 +82,26 @@ void TextModifierGroup::computeRangeMap(Span<const Unichar> text,
const SimpleArray<SimpleArray<GlyphLine>>& lines,
const GlyphLookup& glyphLookup)
{
m_textSize = (uint32_t)text.size();
for (TextModifierRange* range : m_ranges)
{
range->computeRange(text, shape, lines, glyphLookup);
}
}

void TextModifierGroup::computeCoverage()
void TextModifierGroup::computeCoverage(uint32_t textSize)
{
if (!hasDirt(ComponentDirt::TextCoverage))
{

return;
}

// Because we're not dependent on anything we need to reset our dirt
// ourselves. We're not in the DAG so we'll never get reset.
m_Dirt = ComponentDirt::None;

// When the text re-shapes, we udpate our coverage values.
m_coverage.resize(m_textSize);
m_coverage.resize(textSize);
std::fill(m_coverage.begin(), m_coverage.end(), 0);
for (TextModifierRange* range : m_ranges)
{
Expand Down

0 comments on commit dabe3a7

Please sign in to comment.