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

Document Entity/Component Usage for Fortress and beyond #805

Open
3 tasks
adlarkin opened this issue May 5, 2021 · 6 comments
Open
3 tasks

Document Entity/Component Usage for Fortress and beyond #805

adlarkin opened this issue May 5, 2021 · 6 comments
Labels
documentation Improvements or additions to documentation

Comments

@adlarkin
Copy link
Contributor

adlarkin commented May 5, 2021

As mentioned in #628, documentation for how to use the EntityComponentManager (and consequentially, how to use Entities/Components) is lacking. While #628 proposes a lot of good things to document, it's likely that some of the documentation will change starting in Fortress once #711 is addressed.

At the time of this writing, the following items should be addressed (as more items come to mind, we can either add to this comment or create additional comments in this issue):

  • Deprecate Component::Data(). This may also require deprecation of Component::operator= so that users don't use this instead
  • Extend classes like Model so that more common/beginner-friendly use cases don't require dealing with the ECM
  • Stick to either adding/removing components that aren't needed each iteration, or to "zeroing them out", but not both (perhaps we can make better use of EntityComponentManager::ComponentState)
@adlarkin adlarkin added the documentation Improvements or additions to documentation label May 5, 2021
@adlarkin adlarkin self-assigned this May 5, 2021
@diegoferigo
Copy link
Contributor

Deprecate Component::Data(). This may also require deprecation of Component::operator= so that users don't use this instead

I'm a bit worried by this change. If a component stores a big chunk of data (say, an image), being able to directly access the component's storage in r/w (i.e. for setting the value) could be relevant for performance. Is there any other way to prevent allocating a temporary object like what could happen when using Component::SetData?

The use case I have in mind is when the data type of the component differs from the data type of the caller. It's kind of related to #494.

@chapulina
Copy link
Contributor

Good point, there may be use cases when the caller wants to modify the data without necessarily creating a new object. Like how you could now do:

poseComp->Data().SetX(10);

We haven't been doing that a lot internally, but it is a good pattern for performance.

For context, the reason we'd like to force users to go through SetData is to make it easier to set the changed state. But maybe we can recommend SetData for intermediate users, while advanced users can use Data() and be sure to use SetChangedState correctly afterwards.

@diegoferigo
Copy link
Contributor

For context, the reason we'd like to force users to go through SetData is to make it easier to set the changed state. But maybe we can recommend SetData for intermediate users, while advanced users can use Data() and be sure to use SetChangedState correctly afterwards.

Thanks for providing this piece of information, now it makes even more sense. I like a lot the idea of automatically updating the state of the component when calling Component::SetData, especially after the last changes that optimized performance. I recently faced some problem due to that, and I found out that manually calling EntityComponentManager::SetChanged was necessary. If this approach goes through, keeping this advanced usage available would be great.

@chapulina
Copy link
Contributor

Deprecate Component::Data().

Given the discussion above, I suggest we don't deprecate that, and instead document that SetData is recommended, but if one must use Data, they should remember to also call SetChanged.

Extend classes like Model

This is captured in #325

Stick to either adding/removing components that aren't needed each iteration, or to "zeroing them out", but not both

With the new view implementation in #856, removing components is not very costly. So we could use that. I'm reluctant to updating the components that are currently zeroed out though, because that will force downstream users to update their code when migrating.

@adlarkin
Copy link
Contributor Author

adlarkin commented Aug 4, 2021

Given the discussion above, I suggest we don't deprecate that, and instead document that SetData is recommended, but if one must use Data, they should remember to also call SetChanged.

Sounds good to me 👍 are we currently expecting for users to call SetChanged after calling Data, or will this be a new expectation starting in Fortress? I believe there are places scattered across the codebase that call Data without calling SetChanged. I'm assuming this change would take place in Fortress since one could argue that it's a behavioral change.

With the new view implementation in #856, removing components is not very costly. So we could use that. I'm reluctant to updating the components that are currently zeroed out though, because that will force downstream users to update their code when migrating.

Agreed 👍 once we merge #856, we can tell users that removing/re-adding components is okay.

@chapulina
Copy link
Contributor

chapulina commented Sep 15, 2021

Tasks from #787:

  • Documenting on the Physics system that it won't function correctly unless entities are created in the proper order. That is, parents must be created before their children.
  • Write a tutorial with examples of how to create entities using the create service (recommended way) or the SdfEntityCreator / EntityComponentManager APIs (advanced usage, and users should be careful about the order in which entities are created).

@adlarkin adlarkin removed their assignment Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants