Esempio n. 1
0
 public void Execute(Entity entity, int index, [ReadOnly] ref MegaChunk c0)
 {
     if (seed > 7)
     {
         commandBuffer.AddSharedComponent(index, entity, forest);
     }
     else
     {
         commandBuffer.AddSharedComponent(index, entity, plain);
     }
 }
Esempio n. 2
0
 public void Execute(int index)
 {
     EntityCommandBuffer.CreateEntity();
     EntityCommandBuffer.AddSharedComponent(Bootstrap.BulletRenderer);
     EntityCommandBuffer.AddComponent(new TransformMatrix());
     EntityCommandBuffer.AddSharedComponent(new MoveForward());
     EntityCommandBuffer.AddComponent(new MoveSpeed {
         speed = 6
     });
     EntityCommandBuffer.AddComponent(Positions[index]);
     EntityCommandBuffer.AddComponent(Rotations[index]);
 }
Esempio n. 3
0
        public void Execute(Entity entity, int jobIndex, ref Translation position, [ReadOnly] ref SpiderTag tag,
                            ref LoadedShotCount loadedShots)
        {
            if (loadedShots.TimeToNextShoot > 0)
            {
                loadedShots.TimeToNextShoot -= DeltaTime;
            }
            else
            {
                if (RandomPicker <= SpiderGamePlayController.Controller.ShootingChance)
                {
                    Entity shot = CommandBuffer.CreateEntity(jobIndex);

                    CommandBuffer.AddComponent(jobIndex, shot, new Translation
                    {
                        Value = new float3(position.Value.x, position.Value.y - 0.2f, position.Value.z)
                    });
                    CommandBuffer.AddComponent(jobIndex, shot, new ShotTag {
                        Character = ChTags.Spider
                    });
                    CommandBuffer.AddComponent(jobIndex, shot, new Scale {
                        Value = 0.1f
                    });
                    CommandBuffer.AddComponent(jobIndex, shot, new LocalToWorld {
                    });
                    CommandBuffer.AddSharedComponent(jobIndex, shot, new RenderMesh
                    {
                        mesh     = GameDetails.GD.Mesh,
                        material = GameDetails.GD.SpiderShotMaterial,
                    });
                }
                loadedShots.TimeToNextShoot = SpiderGamePlayController.Controller.ShootingDelay;
            }
        }
Esempio n. 4
0
        public void Execute(int i)
        {
            commandBuffer.CreateEntity(particleArchetype);
            var rotatorComponent = randomRotators[i * offset];

            var newParticle = BootstrapperParticles.particleTemplate;

            newParticle.velocity = (emitter.emissionDirection + randomDirections[i * offset]) * emitter.initialSpeed;

            commandBuffer.SetComponent(new Position()
            {
                Value = emitterPosition.Value
            });
            commandBuffer.SetComponent(new Rotation()
            {
                Value = quaternion.identity
            });
            commandBuffer.SetComponent(new Scale()
            {
                Value = 1f
            });
            commandBuffer.SetComponent(rotatorComponent);
            commandBuffer.SetComponent(newParticle);
            commandBuffer.AddSharedComponent(BootstrapperParticles.particleLook);
        }
        private void BuildChunkAt(float3 chunkPos, int index)
        {
            Entity en = commandBuffer.CreateEntity(index, archetype);

            commandBuffer.SetComponent(index, en, new MegaChunk
            {
                center     = chunkPos,
                spawnCubes = true,
                entity     = en
            });
            commandBuffer.SetComponent(index, en, new Translation {
                Value = chunkPos
            });
            commandBuffer.SetComponent(index, en, new Rotation {
                Value = quaternion.identity
            });
            commandBuffer.SetComponent(index, en, new LocalToWorld {
            });
            //commandBuffer.AddComponent(index, en, new PhysicsCollider
            //{
            //    Value = Unity.Physics.BoxCollider.Create(bm)
            //});

            commandBuffer.AddSharedComponent(index, en, group);
        }
 public void Execute(int index)
 {
     EntityCommandBuffer.AddSharedComponent(index, Entities[index], new MoveForward());
     EntityCommandBuffer.AddComponent(index, Entities[index], new MoveSpeed {
         Speed = GoStraightBehaviours[index].Speed
     });
 }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            if (Enemies.Length == 0)
            {
                return;
            }

            var randomizers = chunk.GetNativeArray(RandomizerType).Reinterpret <Random>();
            var entities    = chunk.GetNativeArray(EntityType);

            for (int i = 0; i < chunk.Count; i++)
            {
                if (randomizers[i].NextFloat(0f, 1f) >= Aggression)
                {
                    continue;
                }

                var target = Enemies[randomizers[i].NextInt(0, Enemies.Length)];
                CommandBuffer.AddComponent(chunkIndex, entities[i], new CTarget {
                    Value = target
                });
                CommandBuffer.AddSharedComponent(chunkIndex, entities[i], new STargetType {
                    Value = TargetTypes.Enemy
                });
            }
        }
Esempio n. 8
0
        public void Execute(ref MatterSpawning spawning, ref Position position, ref Rotation rotation)
        {
            entityCommandBuffer.CreateEntity(num);
            entityCommandBuffer.AddSharedComponent(num, Bootstrap.MatterRenderer);
            //entityCommandBuffer.AddComponent(num, new TransformMatrix());
            //entityCommandBuffer.AddSharedComponent(num, new MoveForward());
            var spawnPos = position;

            spawnPos.Value = spawnPos.Value + randomize;
            entityCommandBuffer.AddComponent(num, spawnPos);
            entityCommandBuffer.AddComponent(num, rotation);
            entityCommandBuffer.AddComponent(num, new Scale()
            {
                Value = new float3(1F)
            });
            entityCommandBuffer.AddComponent(num, new MatterObject()
            {
                Mass = mass, Density = 1F
            });
            entityCommandBuffer.AddComponent(num, new DynamicObject()
            {
                velocity = new float3(0, 0, 0), forces = new float3(0, 0, 0)
            });
            entityCommandBuffer.AddComponent(num, new PendingMatter()
            {
                MassToAdd = 0F
            });
        }
 static void Shoot(CharacterTag tag, EntityCommandBuffer.Concurrent CommandBuffer, Translation position, int jobIndex)
 {
     if (tag.Value == ChTags.Cooper)
     {
         Entity shot = CommandBuffer.CreateEntity(jobIndex);
         CommandBuffer.AddComponent(jobIndex, shot, new Translation
         {
             Value = new float3(position.Value.x, position.Value.y + 0.2f, position.Value.z)
         });
         CommandBuffer.AddComponent(jobIndex, shot, new ShotTag {
             Character = ChTags.Cooper
         });
         CommandBuffer.AddComponent(jobIndex, shot, new Scale {
             Value = 0.1f
         });
         CommandBuffer.AddComponent(jobIndex, shot, new LocalToWorld {
         });
         CommandBuffer.AddSharedComponent(jobIndex, shot, new RenderMesh
         {
             mesh     = GameDetails.GD.Mesh,
             material = GameDetails.GD.CooperShotMaterial,
         });
     }
     else
     {
         Entity shot = CommandBuffer.CreateEntity(jobIndex);
         CommandBuffer.AddComponent(jobIndex, shot, new Translation
         {
             Value = new float3(position.Value.x, position.Value.y - 0.2f, position.Value.z)
         });
         CommandBuffer.AddComponent(jobIndex, shot, new ShotTag {
             Character = ChTags.Spider
         });
         CommandBuffer.AddComponent(jobIndex, shot, new Scale {
             Value = 0.1f
         });
         CommandBuffer.AddComponent(jobIndex, shot, new LocalToWorld {
         });
         CommandBuffer.AddSharedComponent(jobIndex, shot, new RenderMesh
         {
             mesh     = GameDetails.GD.Mesh,
             material = GameDetails.GD.SpiderShotMaterial,
         });
     }
 }
Esempio n. 10
0
 public void Execute(int index)
 {
     commandBuffer.CreateEntity(index, sphereArchetype);
     commandBuffer.SetComponent(index, new Scale {
         Value = new float3(1.0f, 1.0f, 1.0f)
     });
     commandBuffer.SetComponent(index, new Position {
         Value = requests[index].origin
     });
     commandBuffer.AddSharedComponent(index, sphereLook);
 }
 public void Execute(int index)
 {
     if (Adds[index] == 1)
     {
         CommandBuffer.AddSharedComponent(Entities[index], new PhysicsObject {
         });
     }
     else
     {
         CommandBuffer.RemoveComponent <PhysicsObject>(Entities[index]);
     }
 }
Esempio n. 12
0
 public void Execute(int index)
 {
     if (Simulations[index] == 0)
     {
         CommandBuffer.RemoveComponent <PhysicsObject>(Entities[index]);
         CommandBuffer.RemoveComponent <ActiveBody>(Entities[index]);
     }
     else
     {
         CommandBuffer.AddSharedComponent(Entities[index], new PhysicsObject {
             Simulation = Simulations[index]
         });
         CommandBuffer.AddSharedComponent(Entities[index], new ActiveBody
         {
             SleepThreshold = SleepThreshold,
             RestingFramesForCandidacyThreshold = RestingFramesForCandidacyThreshold,
             FramesUnderThresholdCount          = 0,
             IsSleepCandidate = 0
         });
     }
 }
Esempio n. 13
0
 public static void Spawn(ref EntityCommandBuffer.Concurrent cmdBuffer, int x, int y, int type)
 {
     // Debug.Log("Spawn: " + x + ", " + y);
     cmdBuffer.CreateEntity(PowderGame.powderArchetype);
     cmdBuffer.SetComponent(PowderTypes.values[type].creator(new Vector2Int(x, y)));
     cmdBuffer.SetComponent(new Position2D {
         Value = CoordToWorld(x, y)
     });
     cmdBuffer.SetComponent(new Heading2D {
         Value = new float2(0.0f, 1.0f)
     });
     cmdBuffer.AddSharedComponent(PowderTypes.values[type].renderer);
     powderCount++;
 }
Esempio n. 14
0
 public static void Spawn(ref EntityCommandBuffer.Concurrent cmdBuffer, Powder p)
 {
     // Debug.Log("Spawn: " + x + ", " + y);
     cmdBuffer.CreateEntity(PowderGame.powderArchetype);
     cmdBuffer.SetComponent(p);
     cmdBuffer.SetComponent(new Position2D {
         Value = CoordToWorld(p.coord.x, p.coord.y)
     });
     cmdBuffer.SetComponent(new Heading2D {
         Value = new float2(0.0f, 1.0f)
     });
     cmdBuffer.AddSharedComponent(PowderTypes.values[p.type].renderer);
     powderCount++;
 }
Esempio n. 15
0
        //[ReadOnly] ref Firing firing -> [ChangedFilter] ref Firing firing
        public void Execute(Entity entity, int index, [ChangedFilter] ref Firing firing, [ReadOnly] ref LocalToWorld localToWorld, [ReadOnly] ref Rotation rotation)
        {
            var bulletEntity = CommandBuffer.CreateEntity(index);

            CommandBuffer.AddSharedComponent(index, bulletEntity, Bootstrap.Defines.BullerRenderer);
            CommandBuffer.AddComponent(index, bulletEntity, new LocalToWorld
            {
                Value = float4x4.TRS(
                    localToWorld.Position,
                    rotation.Value,
                    new float3(1.0f, 1.0f, 1.0f))
            });
            CommandBuffer.AddComponent(index, bulletEntity, new MoveForward());
        }
        public void Execute(Entity entity, int jobIndex, ref Translation position, [ReadOnly] ref CooperTag tag,
                            ref LoadedShotCount loadedShots, ref TotalShotCount totalRemainingShots)
        {
            if (totalRemainingShots.Value > 0)
            {
                if (loadedShots.Count > 0 && loadedShots.TimeToNextShoot <= 0 && Clicked)
                {
                    Entity shot = CommandBuffer.CreateEntity(jobIndex);

                    CommandBuffer.AddComponent(jobIndex, shot, new Translation
                    {
                        Value = new float3(position.Value.x, position.Value.y + 0.2f, position.Value.z)
                    });
                    CommandBuffer.AddComponent(jobIndex, shot, new ShotTag {
                        Character = ChTags.Cooper
                    });
                    CommandBuffer.AddComponent(jobIndex, shot, new Scale {
                        Value = 0.1f
                    });
                    CommandBuffer.AddComponent(jobIndex, shot, new LocalToWorld {
                    });
                    CommandBuffer.AddSharedComponent(jobIndex, shot, new RenderMesh
                    {
                        mesh     = GameDetails.GD.Mesh,
                        material = GameDetails.GD.CooperShotMaterial,
                    });

                    loadedShots.Count--;
                    totalRemainingShots.Value--;
                    GameDetails.GD.CurrentShots = totalRemainingShots.Value;
                    loadedShots.TimeToNextShoot = CooperGamePlayController.Controller.TimeBetweenShoots;
                }
                else if (loadedShots.TimeToNextShoot > 0)
                {
                    loadedShots.TimeToNextShoot -= DeltaTime;
                }

                if (loadedShots.Count == 0)
                {
                    loadedShots.TimeToNextShoot = CooperGamePlayController.Controller.ReloadingTime;
                    loadedShots.Count           = CooperGamePlayController.Controller.ShotCountPerLoad;
                }
            }
        }
            public void Execute(int index)
            {
                float3 heading = math.up() + GetHeadingDirection(Rotations[index].Value.value);

                Entity projectile = CommandBuffer.CreateEntity(index);

                CommandBuffer.AddComponent(index, projectile, new Projectile {
                    StartTime = Time, Duration = 4f
                });
                CommandBuffer.AddComponent(index, projectile, Positions[index]);
                CommandBuffer.AddComponent(index, projectile, new Velocity());
                CommandBuffer.AddComponent(index, projectile, new MovementSpeed {
                    Value = 10
                });
                CommandBuffer.AddComponent(index, projectile, new Heading {
                    Value = new float2(heading.x, heading.y)
                });
                CommandBuffer.AddSharedComponent(index, projectile, GameplayBootstrap.ProjectileMeshComponent);
            }
    static void SpawnCoin(Translation position, EntityCommandBuffer.Concurrent commandBuffer, int jobIndex)
    {
        Entity coin = commandBuffer.CreateEntity(jobIndex);

        commandBuffer.AddComponent(jobIndex, coin, new Translation {
            Value = position.Value
        });
        commandBuffer.AddComponent(jobIndex, coin, new CoinTag {
        });
        commandBuffer.AddComponent(jobIndex, coin, new Scale {
            Value = GameDetails.GD.CoinSpriteRadius
        });
        commandBuffer.AddComponent(jobIndex, coin, new LocalToWorld {
        });
        commandBuffer.AddComponent(jobIndex, coin, new SinglePlayerTag {
        });
        commandBuffer.AddSharedComponent(jobIndex, coin, new RenderMesh
        {
            mesh     = GameDetails.GD.Mesh,
            material = GameDetails.GD.CoinMaterial,
        });
    }
Esempio n. 19
0
            public void Execute(int index)
            {
                int qtdMarkers   = SpawnData[0].qtdPerCell;
                int flag         = 0;
                int markersAdded = 0;
                NativeList <Position> tempCellMarkers = new NativeList <Position>(qtdMarkers, Allocator.Persistent);

                System.Random r = new System.Random(DateTime.UtcNow.Millisecond);

                for (int i = 0; i < qtdMarkers; i++)
                {
                    //FUTURE: Add a proper 'y' coordinate
                    float x = ((float)r.NextDouble() * 2f - 1f) + cellNames[index].Value.x;
                    float y = 0f;
                    float z = ((float)r.NextDouble() * 2f - 1f) + cellNames[index].Value.z;

                    bool canInstantiate = true;

                    for (int j = 0; j < tempCellMarkers.Length; j++)
                    {
                        float distanceAA = math.distance(new float3(x, y, z), tempCellMarkers[j].Value);
                        if (distanceAA < Settings.experiment.markerRadius)
                        {
                            canInstantiate = false;
                            break;
                        }
                    }

                    if (canInstantiate)
                    {
                        CommandBuffer.CreateEntity(index, MakerArchetype);

                        CommandBuffer.SetComponent(index, new Position
                        {
                            Value = new float3(x, y, z)
                        });
                        CommandBuffer.SetComponent(index, new MarkerData
                        {
                            id = markersAdded
                        });
                        CommandBuffer.AddSharedComponent(index, new MarkerCellName
                        {
                            Value = cellNames[index].Value
                        });
                        //CommandBuffer.AddComponent(index, new Active { active = 1 });

                        markersAdded++;

                        if (Settings.experiment.showMarkers)
                        {
                            CommandBuffer.AddSharedComponent(index, MarkerRenderer);
                        }
                        tempCellMarkers.Add(new Position {
                            Value = new float3(x, y, z)
                        });
                    }
                    else
                    {
                        flag++;
                        i--;
                    }
                    if (flag > qtdMarkers * 2)
                    {
                        flag = 0;
                        break;
                    }
                }
                tempCellMarkers.Dispose();
            }
Esempio n. 20
0
            public void Execute(int index)
            {
                int doNotFreeze = 0;

                var    spawnList = parBuffer[index];
                float3 origin    = spawnList.spawnOrigin;
                float2 dim       = spawnList.spawnDimensions;

                int   qtdAgtTotal = spawnList.qtdAgents;
                int   maxZ        = (int)(origin.z + dim.y);
                int   maxX        = (int)(origin.x + dim.x);
                int   minZ        = (int)origin.z;
                int   minX        = (int)origin.x;
                float maxSpeed    = spawnList.maxSpeed;

                int startID = AgentAtCellQuantity[index] + LastIDUsed;

                int CellX = minX + 1;
                int CellZ = minZ + 1;
                int CellY = 0;

                System.Random r = new System.Random(DateTime.UtcNow.Millisecond);

                //Debug.Log(spawnList.goal);

                for (int i = startID; i < qtdAgtTotal + startID; i++)
                {
                    if (doNotFreeze > qtdAgtTotal)
                    {
                        doNotFreeze = 0;
                    }

                    float x = (float)r.NextDouble() * (maxX - minX) + minX;
                    float z = (float)r.NextDouble() * (maxZ - minZ) + minZ;
                    float y = 0;

                    float3 g = spawnList.goal;

                    CommandBuffer.CreateEntity(index, AgentArchetype);
                    CommandBuffer.SetComponent(index, new Position {
                        Value = new float3(x, y, z)
                    });
                    CommandBuffer.SetComponent(index, new Rotation {
                        Value = Quaternion.identity
                    });
                    CommandBuffer.SetComponent(index, new AgentData
                    {
                        ID       = i,
                        MaxSpeed = maxSpeed / Settings.experiment.FramesPerSecond,
                        Radius   = 1f
                    });
                    CommandBuffer.SetComponent(index, new AgentStep
                    {
                        delta = float3.zero
                    });
                    CommandBuffer.SetComponent(index, new AgentGoal {
                        SubGoal = g, EndGoal = g
                    });
                    CommandBuffer.SetComponent(index, new Counter {
                        Value = 0
                    });
                    CommandBuffer.SetComponent(index, new NormalLifeData
                    {
                        confort          = 0,
                        stress           = 0,
                        agtStrAcumulator = 0f,
                        movStrAcumulator = 0f,
                        incStress        = 0f
                    });

                    CommandBuffer.SetComponent <BioCrowdsAnchor>(index, new BioCrowdsAnchor {
                        Pivot = float3.zero
                    });

                    CommandBuffer.AddSharedComponent(index, AgentRenderer);
                    CommandBuffer.AddSharedComponent(index, new AgentCloudID {
                        CloudID = spawnList.cloud
                    });
                }
            }
Esempio n. 21
0
            public void Execute(int index)
            {
                int doNotFreeze = 0;

                float3 cellPos = WindowManager.Crowds2Clouds(CellName[index].Value);


                int ind = GridConverter.Position2CellID(cellPos);


                Parameters spawnList;
                bool       keepgoing = parBuffer.TryGetValue(ind, out spawnList);

                if (!keepgoing)
                {
                    return;
                }
                float3 convertedOrigin = WindowManager.Clouds2Crowds(spawnList.spawnOrigin);
                float2 dim             = spawnList.spawnDimensions;

                int   qtdAgtTotal = spawnList.qtdAgents;
                int   maxZ        = (int)(convertedOrigin.z + dim.y);
                int   maxX        = (int)(convertedOrigin.x + dim.x);
                int   minZ        = (int)convertedOrigin.z;
                int   minX        = (int)convertedOrigin.x;
                float maxSpeed    = spawnList.maxSpeed;

                //Debug.Log(" MAX MIN " + new int4(maxZ, minZ, maxX, minX));

                int startID = AgentAtCellQuantity[index] + LastIDUsed;


                System.Random r = new System.Random(DateTime.UtcNow.Millisecond);

                int CellX = minX + 1;
                int CellZ = minZ + 1;
                int CellY = 0;

                //Debug.Log("ConvertedOrigin:" + convertedOrigin + "CELL: " + CellX + " " + CellZ);

                //Problema total agents
                for (int i = startID; i < qtdAgtTotal + startID; i++)
                {
                    //Debug.Log("Agent id : " + i);

                    if (doNotFreeze > qtdAgtTotal)
                    {
                        doNotFreeze = 0;
                        //maxZ += 2;
                        //maxX += 2;
                    }

                    float x = (float)r.NextDouble() * (maxX - minX) + minX;
                    float z = (float)r.NextDouble() * (maxZ - minZ) + minZ;
                    float y = 0;
                    //Debug.Log("AGENT: " + x + " " + z);



                    float3 g = WindowManager.Clouds2Crowds(spawnList.goal);

                    //x = UnityEngine.Random.Range(x - 0.99f, x + 0.99f);
                    //float y = 0f;
                    //z = UnityEngine.Random.Range(z - 0.99f, z + 0.99f);



                    CommandBuffer.CreateEntity(index, AgentArchetype);
                    CommandBuffer.SetComponent(index, new Position {
                        Value = new float3(x, y, z)
                    });
                    CommandBuffer.SetComponent(index, new Rotation {
                        Value = Quaternion.identity
                    });
                    //Debug.Log(maxSpeed / Settings.experiment.FramesPerSecond);
                    CommandBuffer.SetComponent(index, new AgentData
                    {
                        ID       = i,
                        MaxSpeed = maxSpeed + (maxSpeed /* (float)(r.NextDouble() */ * 0.2f),// / Settings.experiment.FramesPerSecond,
                        Radius   = 1f
                    });
                    CommandBuffer.SetComponent(index, new AgentStep
                    {
                        delta = float3.zero
                    });
                    CommandBuffer.SetComponent(index, new Rotation
                    {
                        Value = quaternion.identity
                    });
                    CommandBuffer.SetComponent(index, new CellName {
                        Value = new int3(CellX, CellY, CellZ)
                    });
                    CommandBuffer.SetComponent(index, new AgentGoal {
                        SubGoal = g, EndGoal = g
                    });
                    //entityManager.AddComponent(newAgent, ComponentType.FixedArray(typeof(int), qtdMarkers));
                    //TODO:Normal Life stuff change
                    CommandBuffer.SetComponent(index, new Counter {
                        Value = 0
                    });
                    CommandBuffer.SetComponent(index, new NormalLifeData
                    {
                        confort          = 0,
                        stress           = 0,
                        agtStrAcumulator = 0f,
                        movStrAcumulator = 0f,
                        incStress        = 0f
                    });

                    CommandBuffer.SetComponent <BioCrowdsAnchor>(index, new BioCrowdsAnchor {
                        Pivot = WindowManager.instance.originBase
                    });

                    CommandBuffer.AddSharedComponent(index, AgentRenderer);
                    CommandBuffer.AddSharedComponent(index, new AgentCloudID {
                        CloudID = spawnList.cloud
                    });
                }
            }
Esempio n. 22
0
 public void Execute([ReadOnly] ref RealVoice realVoice)
 {
     CommandBuffer.AddSharedComponent(realVoice.SourceEntity, new StopRequest());
     CommandBuffer.RemoveComponent <StopRequest>(realVoice.VoiceEntity);
 }
Esempio n. 23
0
 public void AddSharedComponent <T>(T component) where T : struct, ISharedComponentData
 {
     _ecb.AddSharedComponent(_jobIndex, _entity, component);
 }
 public void Execute(int index)
 {
     CommandBuffer.AddSharedComponent(Entities[index], new SharedBinaryState {
     });
 }
Esempio n. 25
0
 void IJobParallelFor.Execute(int i)
 {
     CommandBuffer.AddSharedComponent(Instances[i], ECSBootstrapper.humanRenderer);
     CommandBuffer.RemoveComponent <HumanJustInstanced>(Instances[i]);
 }