Proposal to move the responsibilities of the Box3DWorld over to an interface - #6
Open
quattage wants to merge 2 commits into
Open
Proposal to move the responsibilities of the Box3DWorld over to an interface#6quattage wants to merge 2 commits into
quattage wants to merge 2 commits into
Conversation
Owner
|
Hello. Thanks for the PR! I like the idea of interface introducing. But I need find time and think about this changes in general 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is contains an API addition that allows users to optionally provide their own
Box3DWorldimplementation and instance.To do this, I've added two new constructs: the
IBox3DWorldinterface, and theWorldProviderdelegate. API users are granted the freedom to implement their ownIBox3DWorldwhile supplying an instance usingWorldProvider. All internal references toBox3DWorld.Instancehave been replaced withIBox3DWorld.Get, whileBox3DWorldandBox3DEditorSimulationare now both implementing subclasses ofIBox3DWorldThis allows worlds to be context-dependent while still easily maintaining the one-world-per-scene rule enforced by the singleton, but API users now have the option to break this rule should they so choose.
For integration's sake, the default implementation of
WorldProviderdefers toBox3DWorld.Instance, so this PR can act as a drop-in replacement with very few breaking changes to API users' code.This change could cause some issues, since it allows API users the freedom to supply their own (potentially stale) worlds. To deal with problems caused by this, all implementing Box3D objects (primarily Box3DBody) no longer store a local reference to the Box3DWorld. They query for it using IBox3DWorld.Get() and immediately test for validity whenever the reference is needed. I think the flexibility of this system is worth the tiny bit of added overhead here, but I may have been a bit hasty with the implementation in some areas.
Let me know if this could use some improving or tweaking to better fit the API style you're going for. This PR does not include changes to the Samples, so I'd need to address those.