Example #1
0
        void LeoECS()
        {
            _world = new EcsWorld();
            JobMoveSystem.MinSpeed         = param.minSpeed;
            JobMoveSystem.MaxSpeed         = param.maxSpeed;
            JobMoveSystem.BoidScale        = boidScale;
            JobMoveSystem.WallScale        = param.wallScale * 0.5f;
            JobMoveSystem.WallDistance     = param.wallDistance;
            JobMoveSystem.WallWeight       = param.wallWeight;
            JobMoveSystem.NeighborFov      = MathFast.Cos(param.neighborFov * MathFast.Deg2Rad);
            JobMoveSystem.NeighborDistance = param.neighborDistance;
            JobMoveSystem.SeparationWeight = param.separationWeight;
            JobMoveSystem.AlignmentWeight  = param.alignmentWeight;
            JobMoveSystem.CohesionWeight   = param.cohesionWeight;
            JobMoveSystem.EntitiesCount    = boidCount;
            JobMoveSystem.NumBoidsPerJob   = boidCount / System.Environment.ProcessorCount;

            if (BoidsVisualisationSystem._nativeMatrices.IsCreated)
            {
                BoidsVisualisationSystem._nativeMatrices.Dispose();
            }
            BoidsVisualisationSystem._nativeMatrices = new NativeArray <Matrix4x4> (boidCount, Allocator.Persistent);
            BoidsVisualisationSystem._matrices       = new Matrix4x4[boidCount];

            var timeSystem = new TimeSystem();

            _systems = new EcsSystems(_world);
            _systems
            .Add(timeSystem)
            .Add(new BoidsSimulationSystem())
            .Add(new JobMoveSystem())
            .Add(new BoidsVisualisationSystem()
            {
                mesh = mesh, material = material, scale = boidScale
            })
            .Inject(timeSystem)
            .Initialize();
            var random = new RngXorShift(853);

            BoidEntityData.Create(boidCount);

            for (int i = 0; i < boidCount; ++i)
            {
                var initSpeed = param.initSpeed;
                //init them with these default values
                var boid = _world.CreateEntityWith <BoidEntityData> ();
                boid.id       = i;
                boid.Position = new Float3(random.GetFloat(), random.GetFloat(), random.GetFloat());
                var vel = new Float3(random.GetFloat(), random.GetFloat(), random.GetFloat());
                vel.Normalize();
                vel.Scale(initSpeed);
                boid.Velocity     = vel;
                boid.Acceleration = Float3.Zero;
            }
            _world.ProcessDelayedUpdates();
        }
        void LeoECS()
        {
            _world = new EcsWorld();
            ThreadMoveSystem.MinSpeed         = param.minSpeed;
            ThreadMoveSystem.MaxSpeed         = param.maxSpeed;
            ThreadMoveSystem.BoidScale        = boidScale;
            ThreadMoveSystem.WallScale        = param.wallScale * 0.5f;
            ThreadMoveSystem.WallDistance     = param.wallDistance;
            ThreadMoveSystem.WallWeight       = param.wallWeight;
            ThreadMoveSystem.NeighborFov      = MathFast.Cos(param.neighborFov * MathFast.Deg2Rad);
            ThreadMoveSystem.NeighborDistance = param.neighborDistance;
            ThreadMoveSystem.SeparationWeight = param.separationWeight;
            ThreadMoveSystem.AlignmentWeight  = param.alignmentWeight;
            ThreadMoveSystem.CohesionWeight   = param.cohesionWeight;
            ThreadMoveSystem.Neighbours       = new BoidEntityData[boidCount][];
            for (int i = 0; i < boidCount; i++)
            {
                ThreadMoveSystem.Neighbours[i] = new BoidEntityData[boidCount];
            }

            BoidsVisualisationSystem2._matrices = new Matrix4x4[boidCount];

            var timeSystem = new TimeSystem();

            _systems = new EcsSystems(_world);
            _systems
            .Add(timeSystem)
            .Add(new BoidsSimulationSystem())
            .Add(new ThreadMoveSystem())
            .Add(new BoidsVisualisationSystem2()
            {
                mesh = mesh, material = material, scale = boidScale
            })
            // .Add (new BoidsVisualisationSystem () { mesh = mesh, material = material, scale = boidScale })
            .Inject(timeSystem)
            .Initialize();
            var random = new RngXorShift(853);

            for (int i = 0; i < boidCount; ++i)
            {
                var initSpeed = param.initSpeed;
                //init them with these default values
                var boid = _world.CreateEntityWith <BoidEntityData> ();
                boid.position = new Float3(random.GetFloat(), random.GetFloat(), random.GetFloat());
                boid.velocity = new Float3(random.GetFloat(), random.GetFloat(), random.GetFloat());
                boid.velocity.Normalize();
                boid.velocity.Scale(initSpeed);
                boid.acceleration = Float3.Zero;
            }
            _world.ProcessDelayedUpdates();
        }