Comments (5)
There isn't any equivalent but nicer version.
World::get
could exist but usually get
happens in systems where you have views and not World
.
(I've added more and more "shortcut methods" to World
, at the beginning everything had to go through views explicitly)
If you don't check for the component then you can use indexing vs[*player_id].dirty = true;
but it'll panic if the player doesn't have the component.
About performance, views are not iterators. View
/ViewMut
are basically references to SparseSet
, a data-structure close to a Vec
. So vs.get
is almost like vec.get
.
from shipyard.
Thanks for the quick reply. I see what you're saying about the sparseset.
How would this work with a function that returns an EntityID
that needs to look for a component? For example, if I wanted to make a get viewshed
function:
fn get_viewshed(entity: EntityID) -> Option<ViewShed> {
self.world.run(|mut vs: ViewMut<Viewshed>| {
return (&mut vs).get(*entity); //this doesn't work, how can I do this?
});
}
Looking further into the documentation, maybe I'm looking for borrow
?
from shipyard.
If you return an owned type then you can do:
fn get_viewshed(&self, entity: EntityID) -> Option<ViewShed> {
self.world.run(|mut vs: ViewMut<Viewshed>| {
(&mut vs).get(*entity).ok().copied() // <- no semi-colon and I'm assuming Viewshed is Copy
}) // <- no semi-colon
}
And yes you could use borrow
instead.
If you want to return a reference to a component then it's basically not possible, you'd need the same kind of types that World::get
would use. Something like Ref
/RefMut
to hold the locks.
View
/ViewMut
are references but also keep locks to make sure it's not possible to break borrow checking rules.
from shipyard.
Ok, thanks. I am starting to see more of how I can use views in my systems to get the info I need. I didn't see anything in docs about run returning the value of the closure, that might be good to add (Or I didn't read well enough)
from shipyard.
World::get
is available on master et I added a mention to the return value for run
.
from shipyard.
Related Issues (20)
- How to know all of the components that some entity has? HOT 1
- [new feature] deleting entity's components temporarily HOT 4
- How to query a entity by a component value, not component type? HOT 1
- Is there any way to add multiple tracking options to component except #[track(All)]? HOT 4
- Workload scheduling re-evaluation
- How to make certain systems always run first? HOT 8
- Help me some lifetime issue.. HOT 3
- Can I run some systems in parallel if UniqueViewMut is thread-safe? HOT 2
- Create a way to easily derive the Label trait HOT 1
- AtomicU64 is not available on 32-bit platforms HOT 6
- Component iteration without modification tracking HOT 2
- Tracking compiles but panics on run HOT 6
- Potential memory leak HOT 2
- Cannot create Unique component with non-sync wgpu properties in WASM demo HOT 4
- Question about EntityId management HOT 3
- Can I get all of the components of the entity? HOT 2
- Better error message for boxed traits in components HOT 1
- Tracking flag error HOT 1
- How to use generic ViewMut with_id? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shipyard.