Skip to content

Commit

Permalink
Optimizes builder execution time, leveraging the fact that timepoints…
Browse files Browse the repository at this point in the history
… are sorted during search.
  • Loading branch information
guillaumeblanc committed Apr 2, 2024
1 parent 119c988 commit f0dbace
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/animation/offline/animation_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ void CopyTimePoints(const span<const float>& _times, float _inv_duration,
}

uint16_t TimePointToIndex(const span<const float>& _timepoints, float _time) {
const float* found = std::find(_timepoints.begin(), _timepoints.end(), _time);
if (found == _timepoints.end()) {
assert(found != _timepoints.end());
}
const float* found =
std::lower_bound(_timepoints.begin(), _timepoints.end(), _time);
assert(found != _timepoints.end() && *found == _time);
const ptrdiff_t distance = found - _timepoints.begin();
assert(distance >= 0 && distance < std::numeric_limits<uint16_t>::max());
return static_cast<uint16_t>(distance);
Expand Down
12 changes: 10 additions & 2 deletions test/animation/offline/animation_builder_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,17 @@ TEST(ManyKeys, SamplingJob) {
raw_animation.tracks[0].translations.push_back(key2);
}

// Track 1 has no key
// Track 1 has lots of keys
{
for (size_t i = 0; i < kMaxKey; ++i) {
const RawAnimation::TranslationKey key = {i * 1.f / kMaxKey,
ozz::math::Float3(0, 0, 0)};
raw_animation.tracks[1].translations.push_back(key);
}
}

// Track 2 has lots of keys
// Track 2 has lots of keys (same timepoints as track 1 as number of
// trackpoints is limited)
{
for (size_t i = 0; i < kMaxKey; ++i) {
const RawAnimation::TranslationKey key = {
Expand Down

0 comments on commit f0dbace

Please sign in to comment.