Repository navigation
Replies: 1 comment
|
I've replied to this on discord already, where it was a numbered list of concerns/questions, expand below for that reply Discord reply
As the person who implemented them:
I want to point out that the main reason for the way I do believe theres value in some of the things you propose, but i'd urge you to consider alternative implementations instead of trying to shoehorn In general: I think the better way forward is to decide on a design on how to solve the actual issues with bsn!/Scenes that this is attempting to solve. Its also likely ongoing work has already resolved some of this. |
Uh oh!
There was an error while loading. Please reload this page.
Problem
SceneEntityReferences provide the very powerful utility of cross-scene entity references in scene construction, but are presently unwieldy without thebsn!macro, and when using thebsn!macro and the#Namenotation, they cannot reference across scenesPresently,
SceneEntityReferencewraps around aHashed<InnerSceneEntityReference>, which has the following definition:The fields
file,line,column, andruntimeare not particularly meaningful outside ofbsn!invocations;file,lineandcolumnare tied to a singular invocation site, one not present absent macros, and the_call_idthatruntimeis set to goes entirely unused withoutbsn!. To use it manually would entail constructions such asSceneEntityReference::new(("", 0, 0), n, 0), which is rather unwieldy. Within the goal ofbsn!as an optional macro, it would be appropriate to make the great utility ofSceneEntityReferences accessible without macros.These fields then contribute to the inability of cross-macro references. Contrary to what one would reasonably expect from the following code,
entity2does not end up as the child ofentity1:Because the
InnerSceneEntityReferencefields are contingent on the macro invocation, the#Names in entity1 and entity2 expand to differentSceneEntityReferences and cannot be used to cross-reference.Potential Solutions and Challenges
Looking through the code, it appears that the fields of
InnerSceneEntityReferenceare only meaningfully used in theDisplayimpl and theHashimpl. As such, it would be certainly feasible to refactor fields exclusive to debug info given that they get in the way of ergonomics.I imagine
InnerSceneEntityReferencecan be encoded entirely as an&'static str(or aString, I'm not sure) for a name, with an additionalu64for an index to distinguish with the same name, with the following definition:The
namecan operate similarly to theidattribute of an HTML item, although when unqualified, it comes with the risk of collisions.Within the current system, the above code would assign unique
SceneEntityReferences to each element, owing to the increment of the call id, but introducing the assumption of a unique name within the scene would break scene composition within the construction of children.One possible approach is to have the
#Scenenotation be annotated differently for macro-scoped and scene-scoped references, perhaps something like#Scene:for scene-scoped so as to leave the present macro-scoped functionality intact, and then#Scene:Nto indicateNas the fixed index. For macro-scoped names, the globalCALL_IDis the index. Scene-scoped names have the index as 0, unless N is specified, in which that becomes the index.Outside the
bsn!macro,SceneEntityReferencewould be constructed simply with a constructor,SceneEntityReference::new(name: &'static str, index: u64).I hope a change like this would make the ergonomics of entity references within scenes more effective. This is the first time I've attempted to contribute to Bevy (or any open source project for that matter), so feedback on this proposal would be greatly appreciated.
All reactions