From 7287c93bcecf2ca996356a4537f2121fc53cc7ae Mon Sep 17 00:00:00 2001 From: JotaJazzCL <181486793+JotaJazz@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:05:18 -0300 Subject: [PATCH 1/2] curve: don't return keyframes at the searched time in last_before With a hint before the searched time, last_before walked past keyframes at exactly that time and returned the last of them, although it returns the last keyframe before the time. With a hint at or after the time it was already correct, so the result depended on the hint. Fixes #1827 Co-Authored-By: Claude Opus 5.5 --- libopenage/curve/keyframe_container.h | 8 +++--- libopenage/curve/tests/curve_types.cpp | 37 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/libopenage/curve/keyframe_container.h b/libopenage/curve/keyframe_container.h index 8434942058..34f0d4c06d 100644 --- a/libopenage/curve/keyframe_container.h +++ b/libopenage/curve/keyframe_container.h @@ -399,14 +399,14 @@ KeyframeContainer::last_before(const time::time_t &time, const elem_ptr end = this->container.size(); if (at != end and this->container.at(at).time() < time) { - // walk to the right until the time is larget than the searched - while (at != end and this->container.at(at).time() <= time) { + // walk to the right until the time is at least the searched one + while (at != end and this->container.at(at).time() < time) { ++at; } - // go one back, because we want the last element that is <= time + // go one back, because we want the last element that is < time --at; } - else { // idx == end or idx->time > time + else { // idx == end or idx->time >= time // walk to the left until the element time is smaller than the searched time while (at > 0 and (at == end or this->container.at(at).time() >= time)) { --at; diff --git a/libopenage/curve/tests/curve_types.cpp b/libopenage/curve/tests/curve_types.cpp index 935aa7141d..ccf0d81836 100644 --- a/libopenage/curve/tests/curve_types.cpp +++ b/libopenage/curve/tests/curve_types.cpp @@ -84,6 +84,37 @@ void curve_types() { TESTEQUALS(c.get(c.last(10, ie)).val(), 2); TESTEQUALS(c.get(c.last(47, ie)).val(), 2); + // last_before() must not depend on the hint + TESTEQUALS(c.get(c.last_before(0, ib)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, ib)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, ib)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, ib)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, ib)).time(), 10); + + TESTEQUALS(c.get(c.last_before(0, p0)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, p0)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, p0)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, p0)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, p0)).time(), 10); + + TESTEQUALS(c.get(c.last_before(0, p1)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, p1)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, p1)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, p1)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, p1)).time(), 10); + + TESTEQUALS(c.get(c.last_before(0, p2)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, p2)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, p2)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, p2)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, p2)).time(), 10); + + TESTEQUALS(c.get(c.last_before(0, ie)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, ie)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, ie)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, ie)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, ie)).time(), 10); + // Now test the basic erase() function // Delete the 1-element, new values should be [-inf:0, 0:0, 10:2] c.erase(c.last(1)); @@ -165,6 +196,12 @@ void curve_types() { TESTEQUALS(it->val(), 25); } + // the last of several keyframes before the time, from both sides + TESTEQUALS(c.get(c.last_before(1, 1)).val(), 12); + TESTEQUALS(c.get(c.last_before(1, c.size())).val(), 12); + TESTEQUALS(c.get(c.last_before(2, 1)).val(), 15); + TESTEQUALS(c.get(c.last_before(2, c.size())).val(), 15); + // TODO: test c.insert_overwrite and c.insert_after KeyframeContainer c2; From bfd7c5fe7b6f6ba038182ec2a269aedeed9d4cb6 Mon Sep 17 00:00:00 2001 From: Rene Turcios <95189389+CloudCorpRecords@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:39:45 +0000 Subject: [PATCH 2/2] util: fix OrderedSet.intersection_update for OrderedSet and dict args Use a match statement on the argument type, and discard while iterating over a snapshot of the keys. Also add Rene Turcios to the authors list in copying.md. Signed-off-by: Rene Turcios <95189389+CloudCorpRecords@users.noreply.github.com> --- copying.md | 1 + openage/util/ordered_set.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/copying.md b/copying.md index cf5ff6fed7..b0961cbae0 100644 --- a/copying.md +++ b/copying.md @@ -175,6 +175,7 @@ _the openage authors_ are: | Deniz Kökden | denizkoekden | koekdendeniz à gmail dawt com | | Sergey Bronnikov | ligurio | estetus à gmail dawt com | | Nicolas Inostroza | JotaJazz | 181486793+jotajazz à users dawt noreply dawt github dawt com | +| Rene Turcios | CloudCorpRecords | 95189389+cloudcorprecords à users dawt noreply dawt github dawt com | If you're a first-time committer, add yourself to the above list. This is not just for legal reasons, but also to keep an overview of all those nicknames. diff --git a/openage/util/ordered_set.py b/openage/util/ordered_set.py index 8b012cf799..bff8e3888d 100644 --- a/openage/util/ordered_set.py +++ b/openage/util/ordered_set.py @@ -84,12 +84,16 @@ def intersection_update(self, other): """ Only keep elements that are both in self and other. """ - keys_self = set(self.ordered_set.keys()) - keys_other = set(other.keys()) - intersection = keys_self & keys_other - - for elem in self: - if elem not in intersection: + match other: + case OrderedSet(): + other_set = set(other.ordered_set.keys()) + case dict(): + other_set = set(other.keys()) + case _: + other_set = set(other) + + for elem in list(self.ordered_set.keys()): + if elem not in other_set: self.discard(elem) def union(self, other):