Some way to make a snapshot of part of the world
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 215
- PR merge metrics
- No merged PRs in 30d
Description
## Description
I'd like to have some way to get a lightweight snapshot of part of the world state for later use. I'm not entirely sure about the form which would be best, though (I'm not really talking about full saves).
## Motivation
I have two things in mind.
First is, I'd like to separate the game logic update from rendering. Right now, the canonical usage of specs seems to be something like:
```rust
let mut dispatcher = DispatcherBuilder::new()
.with(PhysicsSystem, "physics", &[])
.with_thread_local(RenderSystem)
.build();
loop {
dispatcher.dispatch(&mut world);
}
```
However, I'd like to be able to have one thread that does only the rendering while some other thread (or the whole threadpool) does the updates. That way, if rendering is slow, the game logic would still be able to keep up nevertheless, just some frames would be skipped. So I'd like to take a snapshot of all the entities that can be drawn and their positions after each logic-update, store this snapshot somewhere (eg. in a global Arc). The renderer thread would take the latest exported thread and render that.
Another use case I see is a game where communication would be slow. You'd see the events that happened far away only if a unit came from there, but it would only be able to show the state at the time it was there, not the current one. Such thing would need the units to „remember“ some older states (small parts of them, actually).
I'm thinking something in lines of having component storages based on the `im` crate might help with that, and being able to somehow take the snapshot and import it into another copy of the world… but I don't have concrete ideas. Or are there some other ways I'm overlooking?
## Drawbacks
* Is it a breaking change?
If it was only adding few more storage types, possibly behind a feature flag, then it shouldn't be breaking.
* Can it impact performance, learnability, etc?
Probably, but only when these snapshots would be used ‒ at least when used, such storages might need more memory and be slower.
## Unresolved questions
Well, how it would actually look like specifically 😇
---
Please indicate here if you'd like to work on this ticket once it's been approved. Feel free to delete this section if not.
Yes, but I'd probably need some help/guidance with designing the API and approval first.
Contributor guide
Assessment
This issue has not been assessed yet.