-
Notifications
You must be signed in to change notification settings - Fork 28
constant-text-fade-duration #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Enorovan
wants to merge
4
commits into
master
Choose a base branch
from
constant-text-fade-duration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0830b05
constant-text-fade-duration: refactor glyph progress calculation and …
Enorovan 5a4ac9d
fixup! constant-text-fade-duration: refactor glyph progress calculati…
Enorovan b64b6e7
fixup! constant-text-fade-duration: refactor glyph progress calculati…
Enorovan 0ef220f
fixup! constant-text-fade-duration: refactor glyph progress calculati…
Enorovan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,14 @@ namespace Impacto { | |
| using namespace Profile::ConfigSystem; | ||
| using namespace Profile::Dialogue; | ||
|
|
||
| static float CalcLinearProgress(float progress, float startProgress, | ||
| float endProgress) { | ||
| if (endProgress <= startProgress) | ||
| return progress >= endProgress ? 1.0f : 0.0f; | ||
| return std::clamp((progress - startProgress) / (endProgress - startProgress), | ||
| 0.0f, 1.0f); | ||
| } | ||
|
|
||
| void TypewriterEffect::Start(const bool voiced) { | ||
| DurationIn = 1.0f; | ||
| Voiced = voiced; | ||
|
|
@@ -90,41 +98,36 @@ TypewriterEffect::ParallelBlock TypewriterEffect::GetParallelBlock( | |
| } | ||
| } | ||
|
|
||
| std::pair<float, float> TypewriterEffect::GetGlyphWritingProgresses( | ||
| const size_t glyph) { | ||
| const ParallelBlock block = GetParallelBlock(glyph); | ||
| std::pair<float, float> GetWritingProgresses(const size_t glyphNo, | ||
| const size_t glyphCount, | ||
| const float totalProgress) { | ||
| if (glyphCount == 0 || totalProgress <= 0.0f) return {0.0f, 1.0f}; | ||
|
|
||
| const size_t parallelBlockGlyphNo = glyph - block.Start; | ||
| const float glyphFadeProgress = std::min(TextFadeInDuration, totalProgress); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // We start displaying a glyph after the previous one is 25% opaque, hence | ||
| // totalDisplayTime = glyphCount * (0.25 * glyphDisplayTime) + | ||
| // glyphDisplayTime * 0.75 | ||
| float startTime = 0.0f; | ||
| if (glyphCount > 1 && totalProgress > glyphFadeProgress) { | ||
| const float glyphStartInterval = | ||
| (totalProgress - glyphFadeProgress) / (glyphCount - 1); | ||
| startTime = glyphStartInterval * glyphNo; | ||
| } | ||
|
|
||
| constexpr float singleGlyphDuration = 1.0f; | ||
| constexpr float glyphPropagateProgress = 0.25f; | ||
| constexpr float glyphPropagateDuration = | ||
| singleGlyphDuration * glyphPropagateProgress; | ||
| const float totalDuration = | ||
| block.Size * glyphPropagateDuration + | ||
| (1.0f - glyphPropagateProgress) * singleGlyphDuration; | ||
| const float endTime = std::min(startTime + glyphFadeProgress, totalProgress); | ||
|
|
||
| const float startTime = glyphPropagateDuration * parallelBlockGlyphNo; | ||
| const float endTime = startTime + singleGlyphDuration; | ||
| return {startTime / totalProgress, endTime / totalProgress}; | ||
| } | ||
|
|
||
| return {startTime / totalDuration, endTime / totalDuration}; | ||
| std::pair<float, float> TypewriterEffect::GetGlyphWritingProgresses( | ||
| const size_t glyph) { | ||
| const ParallelBlock block = GetParallelBlock(glyph); | ||
|
|
||
| return GetWritingProgresses(glyph - block.Start, block.Size, 1.0f); | ||
| } | ||
|
|
||
| float TypewriterEffect::CalcOpacity(size_t glyph) { | ||
| if (glyph < FirstGlyph) return 1.0f; | ||
| if (glyph >= FirstGlyph + GlyphCount) return 0.0f; | ||
|
|
||
| if (!IsCancelled && | ||
| Profile::ConfigSystem::TextSpeed >= | ||
| Profile::ConfigSystem::TextSpeedBounds.y && | ||
| !(Voiced && Profile::ConfigSystem::SyncVoice)) { | ||
| return Progress; | ||
| } | ||
|
|
||
| const auto [startProgress, endProgress] = GetGlyphWritingProgresses(glyph); | ||
|
|
||
| if (IsCancelled) { | ||
|
|
@@ -142,13 +145,12 @@ float TypewriterEffect::CalcOpacity(size_t glyph) { | |
| // Translucent glyphs fade in further, in addition to the opacity they | ||
| // already had | ||
| const float glyphProgressBeforeCancellation = | ||
| (ProgressOnCancel - startProgress) / (endProgress - startProgress); | ||
| CalcLinearProgress(ProgressOnCancel, startProgress, endProgress); | ||
| return glyphProgressBeforeCancellation + | ||
| cancelProgress * (1.0f - glyphProgressBeforeCancellation); | ||
| } | ||
|
|
||
| return std::clamp((Progress - startProgress) / (endProgress - startProgress), | ||
| 0.0f, 1.0f); | ||
| return CalcLinearProgress(Progress, startProgress, endProgress); | ||
| } | ||
|
|
||
| float TypewriterEffect::CalcRubyOpacity(const size_t rubyGlyphId, | ||
|
|
@@ -180,27 +182,14 @@ float TypewriterEffect::CalcRubyOpacity(const size_t rubyGlyphId, | |
| } | ||
|
|
||
| const float baseProgressLength = baseEndProgress - baseStartProgress; | ||
|
|
||
| // We start displaying a glyph after the previous one is 25% opaque, hence | ||
| // totalDisplayTime = glyphCount * (0.25 * glyphDisplayTime) + | ||
| // glyphDisplayTime * 0.75 | ||
|
|
||
| constexpr float singleGlyphDuration = 1.0f; | ||
| constexpr float glyphPropagateProgress = 0.25f; | ||
| constexpr float glyphPropagateDuration = | ||
| singleGlyphDuration * glyphPropagateProgress; | ||
| const float totalDuration = | ||
| chunk.Length * glyphPropagateDuration + | ||
| (1.0f - glyphPropagateProgress) * singleGlyphDuration; | ||
|
|
||
| const float glyphStartTime = glyphPropagateDuration * rubyGlyphId; | ||
| const float glyphEndTime = glyphStartTime + singleGlyphDuration; | ||
| const auto [glyphStartProgressInBase, glyphEndProgressInBase] = | ||
| GetWritingProgresses(rubyGlyphId, chunk.Length, baseProgressLength); | ||
|
|
||
| // Convert back to progress-space | ||
| const float startProgress = | ||
| baseStartProgress + (glyphStartTime / totalDuration) * baseProgressLength; | ||
| baseStartProgress + glyphStartProgressInBase * baseProgressLength; | ||
| const float endProgress = | ||
| baseStartProgress + (glyphEndTime / totalDuration) * baseProgressLength; | ||
| baseStartProgress + glyphEndProgressInBase * baseProgressLength; | ||
|
|
||
| if (IsCancelled) { | ||
| if (ProgressOnCancel >= endProgress) return 1.0f; | ||
|
|
@@ -210,12 +199,11 @@ float TypewriterEffect::CalcRubyOpacity(const size_t rubyGlyphId, | |
| if (ProgressOnCancel <= startProgress) return cancelProgress; | ||
|
|
||
| const float glyphProgressBeforeCancellation = | ||
| (ProgressOnCancel - startProgress) / (endProgress - startProgress); | ||
| CalcLinearProgress(ProgressOnCancel, startProgress, endProgress); | ||
| return glyphProgressBeforeCancellation + | ||
| cancelProgress * (1.0f - glyphProgressBeforeCancellation); | ||
| } | ||
|
|
||
| return std::clamp((Progress - startProgress) / (endProgress - startProgress), | ||
| 0.0f, 1.0f); | ||
| return CalcLinearProgress(Progress, startProgress, endProgress); | ||
| } | ||
| } // namespace Impacto | ||
| } // namespace Impacto | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.