Comments (8)
Since a Bevy Entity
contains a generational index, Bevy already guarantees it will never re-issue an Entity
such that two independent entities have equal ID's. Because of that, why not use the Entity
as a discriminant for the Rollback
component, but hidden. With regards to this earlier comment, just don't use the Entity
within a Rollback
for anything other than the comparison and equality of two Rollback
components.
Yes this means the Entity
of an entity and the Entity
within a Rollback
might not be equal after a rollback, but I don't think that matters, since the integer currently used within Rollback
isn't equal to the entity Entity
either.
/// Add this component to all entities you want to be loaded/saved on rollback.
#[derive(Component, Hash, PartialEq, Eq, Clone, Copy, Debug)]
pub struct RollbackFlag(Entity);
/// An `EntityCommand` which adds a `RollbackFlag` component to an entity.
pub struct Rollback;
impl EntityCommand for Rollback {
fn write(self, id: Entity, world: &mut World) {
world.entity_mut(id).insert(RollbackFlag(id));
}
}
/* snip */
app
// ...
.add_startup_system(|mut commands: Commands| {
commands
.spawn(TransformBundle::from_transform(Transform::from_xyz(
1., 2., 3.,
)))
.add(Rollback);
})
// ...
This would defer the ID problem back to how Bevy itself handles running out of entity IDs, which seems like a more appropriate location to deal with this issue.
from bevy_ggrs.
That sounds exactly like the smart solution this issue asked for!
from bevy_ggrs.
Why not use the Entity
? Isn't it the perfect "unique identifier per entities"? Or am I missing something?
Is the rollback ID used as a mapping of entity->entity between different hosts? If so, I would discourage using RollbackIdProvider
or warn users about entity mapping. Since a correct mapping of entities is easier when the id is derived from the actual identity of the spawned entity (if I spawn "wall3" manually, I know to give it a unique ID, while it seems non-trivial in case where I use an incremental counter).
from bevy_ggrs.
When entities are respawned or deleted after a rollback (and newly created when replaying frames after a rollback), they will have a different Entity component compared to before, making impossible to keep track of them when having to rollback again.
For this, another id is necessary that is able to track entities over time. All of this is handled in the plugin, but the solution of handing out the networking Ids is very minimal currently.
The RollbackId is not meant to be consistent between clients.
from bevy_ggrs.
Thank you for the quick answer. I was looking at a way to get a unique id for the Rollback
component in an immutable context. I ended up asking myself "how to get a unique id per entity?" And I had to ask here what were the design consideration for the Rollback
id, since the question had "use Entity
" as an obvious answer.
from bevy_ggrs.
Maybe we could use Bevy's Entities
allocator. it's essentially there to solve a similar problem of needing to be able to allocate unique indexes for items, while still being able to free and re-use them later to avoid running out of u32's.
Side question: if the entities are different while rolling back and forward, does that mean I can't depend on entities uniquely representing my entities if I use this plugin?
For instance, if I had an Inventory
component that was a struct Inventory(Vec<Entity>)
, would the Entity
's stored in that component become invalidated after rolling back and forth? Or not really, because if I sync the Inventory
component, as well as the items in it, then the that would follow the rewind and fast-forward, so if they ended up with new Entities in a replay, then they Inventory
would also be updated accordingly.
( Yeah, I'm thinking that's fine after typing that out... )
from bevy_ggrs.
To answer your side question:
GGRS rewinds by loading an old state and overwriting current values. When loading a snapshot, items that have been deleted will have to be recreated and thus get a new entity id. In the same time, your inventory will be overwritten with the entity id vector it had at that point in time. These IDs will then probably be invalid.
from bevy_ggrs.
That sounds exactly like the smart solution this issue asked for!
Thanks! I've created a pull request with the change as I described above. Please feel free to make any changes you think are appropriate to better align with the rest of the project.
from bevy_ggrs.
Related Issues (20)
- Potential Scalability Refactor HOT 6
- Sessions `.with_desync_detection(DesyncDetection::On)` always reports false positives HOT 1
- Integration Tests incorrect HOT 2
- More idiomatic component/resource checksums for float types?
- Adding non-rollbacked children to rollbacked entities break the hierarchy HOT 1
- Desync detection appears to compare the checksum of predicted frames to confirmed frames HOT 8
- Sprite Component doesn't get respawned after rollback HOT 5
- panic: `Rollback requested was not created using AddRollbackCommand!`
- When rollbacks happen across entity spawning, desyncs are reported HOT 1
- Despawned entities are not restored HOT 2
- Convenient way to end a session HOT 5
- Checksums are not portable HOT 5
- [Question] How to sync elapsed time since startup among peers? HOT 4
- 3d example, and other questions HOT 4
- Update entity IDs in Children/Parent components on rollback. HOT 2
- Update to Bevy 0.13
- Document idiomatic way to sort rollback related queries
- Synctest session doesn't detect all desyncs that it could/should
- Adding players after p2p session already started HOT 3
- Support synchronizing parts of world state, since Rust isn't deterministic.
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 bevy_ggrs.