You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My Bevy application includes a technology tree. Each technology uses the same code for determining when its requirements are met and tracking the research progress using a standard ECS approach. But, my difficulty arises when the technologies are researched because each one needs custom code for when that happens.
I admit I have done object-oriented programming for most of my development career so my thoughts immediately went to an object-oriented approach for this. I did then try to find an ECS approach but came up empty. And then I also ran into roadblocks with an object-oriented approach.
If anyone has a more ECS-style approach, I would be open to it. But, the problem is that I am going from generic system for all technologies to specific code for a given technology and so, at the very least, you would need to spawn a technology-specific Event class or attach a technology-specific Component class to some entity that I could then build a system to Query on and I think I need at least a little tiny bit of object-oriented code for this.
For that, I was thinking about a Resource with a HashMap of a technology id to an implementation of a Trait where the Trait would have nothing but one method to add a specific Component to an Entity. It seemed like a simple thing to do but does not seem possible.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My Bevy application includes a technology tree. Each technology uses the same code for determining when its requirements are met and tracking the research progress using a standard ECS approach. But, my difficulty arises when the technologies are researched because each one needs custom code for when that happens.
I admit I have done object-oriented programming for most of my development career so my thoughts immediately went to an object-oriented approach for this. I did then try to find an ECS approach but came up empty. And then I also ran into roadblocks with an object-oriented approach.
If anyone has a more ECS-style approach, I would be open to it. But, the problem is that I am going from generic system for all technologies to specific code for a given technology and so, at the very least, you would need to spawn a technology-specific Event class or attach a technology-specific Component class to some entity that I could then build a system to Query on and I think I need at least a little tiny bit of object-oriented code for this.
For that, I was thinking about a Resource with a HashMap of a technology id to an implementation of a Trait where the Trait would have nothing but one method to add a specific Component to an Entity. It seemed like a simple thing to do but does not seem possible.
This produced:
error[E0277]:
(dyn InnovationTypeTrait + 'static)
cannot be sent between threads safelyI attempted a few things like adding an unsafe Sync trait to InnovationTypeTrait but had no luck.
I then thought all I really needed was a single lambda function. So, I tried a HashMap pointing to a lambda:
But. for some reason I can't fathom, I can't use "mut" in a lambda:
Patterns aren't allowed in function pointer types [E0561]
Beta Was this translation helpful? Give feedback.
All reactions