Skip to content

Command buffer is slow? #301

Description

@metaphist

I pulled 2.0 and started to modify things in the samples folder to test features. All went well until I tried the command buffer.

Originally I was testing the event bus to trigger a source generated query from a key stroke. That all went fine, but when I tried adding a missing component outside the query via command buffer, all of sudden the event locked everything up for seconds (with 150k entities).

To rule out my changes, I went back to the original sample code and changed the bulk add/remove entity example to use the command buffer instead of world directly - this indeed locks up the system on each update. From what I can see, the add seems to be the culprit, not the playback.

Is this expected?

public sealed class ColorSystem : SystemBase<GameTime>
{
    private readonly QueryDescription _entitiesToChangeColor = new QueryDescription().WithAll<Sprite>();
    private static GameTime? _gameTime;
    private static Random _random;
    private CommandBuffer _commandBuffer;

    public ColorSystem(World world)
        : base(world)
    {
        _random = new Random();
        _commandBuffer = new CommandBuffer();
    }

    public override void Update(in GameTime time)
    {
        _gameTime = time;

        // Modifies the color of all entities fitting the entitiesToChangeColor query.
        World.Query(in _entitiesToChangeColor, (Entity e, ref Sprite sprite) =>
        {
            sprite.Color.R += (byte)(_gameTime.ElapsedGameTime.TotalMilliseconds * 0.08);
            sprite.Color.G += (byte)(_gameTime.ElapsedGameTime.TotalMilliseconds * 0.08);
            sprite.Color.B += (byte)(_gameTime.ElapsedGameTime.TotalMilliseconds * 0.08);

            // A demonstration of bulk adding and removing components.
            // World.Add(in _entitiesToChangeColor, _random.Next());
            // World.Remove<int>(in _entitiesToChangeColor);
            _commandBuffer.Add(e, _random.Next());
            _commandBuffer.Remove<int>(e);
        });

        _commandBuffer.Playback(World);
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions