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
Hello. Im making a GUI prototype based on the ECS architecture using specs.
i would like to modfiy the values of components from outside the world through widgets.
Motivation
Lets says i have Label widget, and i would like to modify its TextComponent's value when i click on a Button widget.
structTextComponent{text:String}structLabel{id:Entity,width:usize,height:usize,x:usize,y:usize,text:TextComponent}implLabel{fntext(&self) -> &TextComponent{&self.text}fnset_text(&mutself,new_text:String){// label has the new value, but world has the old value...// how to notify the world that this entity's component changed ?self.text = TextComponent{text: new_text
}}implbuild(world:&mutWorld) -> Label{
world.register::<TextComponent>();let text = TextComponent::default();let id = world.create_entity().width(text);Label{
id: id,
width:100,
height:75,
x:0,
y:0,
text: text
}}}
Drawbacks
i would like to avoid using Rc> if its possible, it does not scale with lots of entities and has some performance costs
How do games solves this problem ? Im thinking some kinf of messaging system but what libraries are should i use ?
I tried the observer pattern, but its very challenging with rust ownership's system to hold a mutable references of World in each widget.
Unresolved questions
The text was updated successfully, but these errors were encountered:
Why not place the World itself behind an Rc/Arc? They have zero cost access to inner data and all of the important methods on World that you might care about at runtime only require &self.
Description
Hello. Im making a GUI prototype based on the ECS architecture using specs.
i would like to modfiy the values of components from outside the world through widgets.
Motivation
Lets says i have Label widget, and i would like to modify its TextComponent's value when i click on a Button widget.
Drawbacks
i would like to avoid using Rc> if its possible, it does not scale with lots of entities and has some performance costs
How do games solves this problem ? Im thinking some kinf of messaging system but what libraries are should i use ?
I tried the observer pattern, but its very challenging with rust ownership's system to hold a mutable references of World in each widget.
Unresolved questions
The text was updated successfully, but these errors were encountered: