louis-langholtz / PlayRho

An interactive physics engine & library.
zlib License
133 stars 24 forks source link

Set multiple shapes to BodyConf at once #546

Closed opera-aberglund closed 11 months ago

opera-aberglund commented 11 months ago

Desired Behavior:

I want to be able to write something like this to use multiple shapes for a BodyConf

std::vector<ShapeID> shapes
auto bodyConf = BodyConf{}.Use(shapes);

just like how I can call .SetShapes on a Body object. So that would need a new method:

constexpr BodyConf& Use(std::vector<ShapeID> value) noexcept;

Actual Behavior:

I have to write it like this

std::vector<ShapeID> shapes
auto bodyConf = BodyConf{};
for (const auto& shape : shapes) {
  bodyConf.Use(shape);
}

which does not spark joy.

louis-langholtz commented 11 months ago

I like the idea.

Unfortunately, I can't use a C++ standard container type like std::vector to hold these in BodyConf. That's because modifiers like push_back aren't constexpr until C++20. This prevents BodyConf from being a literal type anymore in C++17 - i.e. can't use it with constexpr then.

I may be able to make BodyConf take a view type, like Span, but its data would have to stay in scope until Body got the configuration. Looking into this.

louis-langholtz commented 11 months ago

I didn't like the possible semantics of the BodyConf::Use(ShapeID) when BodyConf held a view. So decided to use a constexpr enhanced container instead. Which in C++17 meant I had to use playrho::ArrayList. And it turned out that type needed some work too which rippled into other code. Anyways, the commit I'm working on merging into master, which you can take an early look at, is commit https://github.com/louis-langholtz/PlayRho/pull/551/commits/3571e96bd0a68e74c778680e90aea176b7946387.

louis-langholtz commented 11 months ago

Addressed with PR: https://github.com/louis-langholtz/PlayRho/pull/551