-
-
Notifications
You must be signed in to change notification settings - Fork 62
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 EntityCommandRecorder support new world #143
Comments
Speaking of wishes :-) it would be "so great" to be able to serialize and then de-serialize the recorder content (of course with some kind of hook that does not impact the performance) |
I am curious for the reason you need to constantly synchronise entities from different worlds. When I designed the Some times ago the recorder would actually take a world parameter in the
ha I actually intended to do that when I created the recorder (that's why internally there is an public interface IEntityAction
{
void Execute(in Entity entity);
}
public sealed class SetEntityAction<T> : IEntityAction
{
private readonly T _value;
public SetEntityAction(T value)
{
_value = value;
}
void IEntityAction.Execute(in Entity entity) => entity.Set(_value);
}
public sealed class LightSetEntityAction<T> : IEntityAction
{
private readonly T _value;
public LightSetEntityAction(T value)
{
_value = value;
}
void IEntityAction.Execute(in Entity entity) => entity.Get<T>() = _value;
}
public sealed class RemoveEntityAction<T> : IEntityAction
{
void IEntityAction.Execute(in Entity entity) => entity.Remove<T>();
}
public sealed class EnableEntityAction<T> : IEntityAction
{
void IEntityAction.Execute(in Entity entity) => entity.Enable<T>();
}
public sealed class DisableEntityAction<T> : IEntityAction
{
void IEntityAction.Execute(in Entity entity) => entity.Disable<T>();
}
public sealed class EnableEntityAction : IEntityAction
{
void IEntityAction.Execute(in Entity entity) => entity.Enable();
}
public sealed class DisableEntityAction : IEntityAction
{
void IEntityAction.Execute(in Entity entity) => entity.Disable();
}
public sealed class EntityFactory
{
private readonly IEntityAction[] _actions;
public EntityFactory(params IEntityAction[] actions)
{
_actions = actions;
}
public void Execute(in Entity entity)
{
foreach (IEntityAction action in _actions)
{
action.Execute(entity);
}
}
public Entity Execute(World world)
{
Entity entity = world.CreateEntity();
Execute(entity);
return entity;
}
} I can create a |
I see many use cases for that, a replicated world for spectator mode come to mind first, but you can do 2-way sync for multi-player games, too.
It is a runtime database with entity id, component id and value objects so it should be fine ^^
I really like the idea because normal serialization/de-serialization only handles the creation/addition of entities/components, while the recorder handles that, and more, with deletion/remove/update of entities/components. Why not using the same "back end" implementation I told myself ^^. Of course, we can implement both features at a higher level as usual, separately. |
Also in the synchronization of multiple world context, currently I have to copy one entity from one world to another in order to replay it with the recorder.
It would be nice to make the recorder aware of the world it should replay (override it) to avoid additional copy.
Thanks!
The text was updated successfully, but these errors were encountered: