New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Entity
(de)serializable
#52
Comments
In an ECS, in theory, an entity is a virtual value. It does not exist and acts as glue for components. From that perspective, I think using In the case of Legion (and other ECS implementations), I propose the following: Your client registers with the server and the server assigns your player a private token (which allows updating your own data - always remember that users are evil by default). At the same time, every player also gets a public token, which all other clients may use for identification (for example to query a player's status). The client may stay connected or make separate calls, and it can use the given token for identification when sending requests to the server. You can store your private token in your global game storage and add a component for all player objects, which holds the public token for them (or add it to you |
Ok, so say I store some kind of I'd rather have a mean to a direct access to a player entity components from an |
This is why legion needs to support component grouping like the EnTT ECS library. Something like an ID component (I generally go with a UUID if it's a lot of potential entities) really should be in it's own bimap and not packed with the rest of the data. |
While waiting for this to happen, what would you suggest to access a given entity in O(1) time ? |
How many unique ID's do you expect? O(1) is hard to get unless you want to allocate an array for all possible values of it or so, which is easy if it's a low amount. Regardless, an array would work, using an id as the index and the value is the entity ID, keep an ID component on the entity for the reverse mapping and make it immutable. Keep a 'free list' (queue or so) of deactivated ID's as entities are destroy'd. |
So basically I'm using |
FWIW I did the separate array + freelist trick, but that was too much back-and-forth for nothing IMHO. I finally resorted to make use legion::entity::Entity;
use serde::{Deserialize, Serialize};
use std::convert::{From, Into};
type EType = u64;
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct Serdent(EType);
impl From<Entity> for Serdent {
fn from(entity: Entity) -> Self {
let etype: EType = unsafe { std::mem::transmute(entity) };
Serdent(etype)
}
}
impl Into<Entity> for Serdent {
fn into(self) -> Entity {
unsafe { std::mem::transmute(self.0) }
}
} |
So I hit some of the same issues trying to implement save states, and while it obviously doesn't make any sense to deserialize entities and use them with the ECS directly, I would like to avoid having to use something like |
Hi,
For a networking game I'd like to use
Entity
as an identification for players (a player client would send to the server anEntity
along other data).If this is sound, would it be possible to make
Entity
(de)serializable to be able to send it in network packets ?The text was updated successfully, but these errors were encountered: