Comments (4)
@torkleyy I instead used draw batch feature of bracket lib to do the console printing from the system. I just made a rendering dispatcher and run it within my draw method of whichever state I am in.
https://github.com/lecoqjacob/blood_oath/blob/main/src/ecs/systems/render/renderer.rs
from specs.
I think I'm missing some context here, but if you just need mutable access to something from a system, that shouldn't be a problem, you can just use Write<'a, BTerm>
(although I'm not sure what BTerm
is).
Some games / game engines even use a second World
and Dispatcher
, and copy data from their main world to a rendering world in order to render the frame while processing data for the next frame (of course you still need to synchronize and extract data in that case).
from specs.
Definitely lacks context, my fault. I will try to get a minimum-viable example (I tried https://play.rust-lang.org but specs
is not available), but in the meantime here's some context in case it helps.
The problem is not access from the system, but insertion into the world.
pub struct MyGame {
world: World,
dispatcher: Dispatcher<'static, 'static>,
}
// This trait is from my framework
//
// Notice that `GameState` requires `Self: 'static` which is why my dispatcher is `<'static, 'static>`
impl GameState for MyGame {
fn tick(&mut self, ctx: &mut Foo) {
// Here `ctx` would escape out of the function
self.world.insert(ctx);
self.dispatcher.dispatch(&mut self.world);
self.world.maintain();
self.world.remove::<&mut Foo>();
}
}
I think I can fix this by building the dispatcher once per tick and just storing the ctx
in the render system struct (via with_thread_local
), but that seems hacky. Any alternative I'm missing that still allows me using Dispatcher
?
from specs.
Oh are you forced to use the GameState
? Because yes you're not gonna be able to store a non-static reference in World
.
If you cannot get ownership of ctx
you can either use [World::exec
] to run a system as a closure:
pub struct MyGame {
world: World,
dispatcher: Dispatcher<'static, 'static>,
}
// This trait is from my framework
//
// Notice that `GameState` requires `Self: 'static` which is why my dispatcher is `<'static, 'static>`
impl GameState for MyGame {
fn tick(&mut self, ctx: &mut Foo) {
self.dispatcher.dispatch(&mut self.world);
self.world.exec(|components: ReadStorage<Component>, other: WriteStorage<Other>| {
ctx.do_something();
});
self.world.maintain();
}
}
or, if you want to put your rendering systems into the dispatcher, serialize required input from ctx
into appropriate resources in World
and record writes to ctx
in components / resources and apply them after dispatching.
However, I recommend you check if you can get ownership of ctx: Foo
, possibly by not making use of GameState
. Then you can just insert it into World
.
from specs.
Related Issues (20)
- DispatcherBuilder::contains HOT 1
- This is a HUGE issue! HOT 2
- Thank you! HOT 1
- How do I access all entities with a certain component? HOT 5
- How do I get the Entity that a Component belongs to? HOT 1
- How to get an entt like view of entities within a system? HOT 2
- How do I create a system that also has the capacity to remove entities? HOT 1
- Migrate to Rust 2021
- [Question] Is it possible to group components together (to all be accessed by 1 system) HOT 3
- `EntityResBuilder` does not implement `Builder` HOT 1
- Specs vs legion HOT 2
- ecs_bench_suite fragmented_iter unexpectedly slow
- Add necessity of feature flag serde to api documentation for saveload HOT 2
- LazyUpdate::exec uses a &mut ref? HOT 1
- specs uses shred 0.13.0, which depends on mopa HOT 1
- Re-add support for dynamic components (for scripting) HOT 1
- 0.19.0 Release? HOT 1
- ahash 7.5 dep yanked HOT 2
- Compilation fails due to outdated depencendy on ahash 0.7.7 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 specs.