Skip to content
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

Array curve #1724

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Array curve #1724

wants to merge 1 commit into from

Conversation

jere8184
Copy link
Contributor

@jere8184 jere8184 commented Dec 3, 2024

solves #1678

@heinezen heinezen marked this pull request as draft December 3, 2024 21:38
// std::array<Keyframe<T>, size> get_all(const time::time_t& t, const size_t hint) const;


size_t size() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make this method constexpr since it returns Size which is known at compile time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can even make it consteval but I think that doesn't work on class methods.

@@ -12,6 +12,7 @@ add_sources(libopenage
queue.cpp
queue_filter_iterator.cpp
segmented.cpp
array.cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the list of files should be sorted alphabetically

@@ -0,0 +1,10 @@
// Copyright 2017-2024 the openage authors. See copying.md for legal info.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copyright year format is {created}-{last changed}. Since you created the file in 2024, it should be 2024-2024

@@ -0,0 +1,159 @@
// Copyright 2017-2024 the openage authors. See copying.md for legal info.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2017-2024 the openage authors. See copying.md for legal info.
// Copyright 2024-2024 the openage authors. See copying.md for legal info.


size_t size() const;

const Keyframe<T> &frame(const time::time_t &t, const size_t index) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should never expose Keyframe references directly. The reasoning here is that a Keyframe may be dumped to file or deleted for optimization purposes over time. Therefore, you should return a pair instead, like in

virtual std::pair<time::time_t, const T> frame(const time::time_t &time) const;

const Keyframe<T> &frame(const time::time_t &t, const size_t index) const;


const Keyframe<T> &next_frame(const time::time_t &t, const size_t index) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here


private:
container_t container;
mutable size_t last_hit_index = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this member supposed to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it acts as a hint, for KeyframeContainer operations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what is the hit index intended to be used for? From what I can see, it's an index into a KeyframeContainer, but there are Size KeyframeContainers in the array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array of hints?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm okay I think I understand now what this is used for. An array of hints (one for each container) would work better, yes.

Comment on lines 142 to 144
for (int i = 0; i < Size; i++) {
this->container[i].sync(other, start);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are iterating through all element, you should use a range-based for-loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a mistake, here
I forgot to Index other as well.

@jere8184
Copy link
Contributor Author

is there any chance array curve should be an array of base curves instead of an array of key frame containers?

@heinezen
Copy link
Member

is there any chance array curve should be an array of base curves instead of an array of key frame containers?

The base curves would have a bunch of duplicate info that we would want to avoid, e.g. they would all have shared pointer to the event loop, their own IDs, and ID strings. Basically, the curve array container should only have this information once.

namespace curve {

template <typename T, size_t Size>
class Array {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the class should inherit from event::EventEntity like all curve types.

@heinezen
Copy link
Member

would making the base curves store references to these shared fields solve this issue?

Then the IDs wouldn't be unique which would be a problem for the event system. Since all curves are event entities, duplicating the information would either lead to all contained curves being updated or worse, only one curve being tracked by the event loop. It would also be a waste of space, since we have to store a bunch of redundant data which is what we want to avoid with a dedicated Array class.

Also, BaseCurve is an interface and should not be instantiated. It doesn't make sense to use it as a container because KeyframeContainer mostly fulfills that jopb already.

@jere8184 jere8184 marked this pull request as ready for review December 15, 2024 22:31
@jere8184 jere8184 force-pushed the array_curve branch 3 times, most recently from 79e5549 to f68ec30 Compare December 21, 2024 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants