Exemplo n.º 1
0
        public void Execute()
        {
            for (int i = 0; i < CreateCount; i++)
            {
                var entity = CommandBuffer.CreateEntity(_playerArchetype);
                CommandBuffer.SetSharedComponent(entity, new RenderMesh()
                {
                    mesh     = SceneManager.GetInstance().CapsuleMesh,
                    material = SceneManager.GetInstance()
                               .PlayerMaterials[Random.NextInt(0, SceneManager.GetInstance().PlayerMaterials.Length)]
                });

                var translation = new Translation
                {
                    Value = new float3(Random.NextInt(0, SceneManager.GetInstance().Width), 3,
                                       Random.NextInt(0, SceneManager.GetInstance().Height))
                };

                CommandBuffer.SetComponent(entity, translation);

                CommandBuffer.SetComponent(entity, new PlayerComponent()
                {
                    TargetPosition = translation.Value
                });
            }
        }
Exemplo n.º 2
0
        public void Execute(Entity entity, int index, ref PlayerComponent playerComponent, ref Translation translation)
        {
            if (!SceneManager.GetInstance().IsInited)
            {
                return;
            }
            var map = SceneManager.GetInstance().Map;

            // Check Collision
            var x = translation.Value.x;
            var z = translation.Value.z;

            if (SceneManager.GetInstance().Map == null || float.IsNaN(x) || float.IsNaN(z))
            {
                return;
            }

            if (map[(int)x][(int)z] != ObstacleType.Floor)
            {
                CommandBuffer.DestroyEntity(index, entity);
                return;
            }

            for (int i = 0; i < Entities.Length; i++)
            {
                if (!Entities[i].Equals(entity))
                {
                    if (math.length(Translations[i].Value - translation.Value) < 0.5f)
                    {
                        CommandBuffer.DestroyEntity(index, entity);
                        return;
                    }
                }
            }

            // Check Target Reached
            if (math.abs(x - playerComponent.TargetPosition.x) < 0.5f && math.abs(z - playerComponent.TargetPosition.z) < 0.5f)
            {
                if (Random.NextBool())
                {
                    playerComponent.TargetPosition.x = Random.NextInt(0, SceneManager.GetInstance().Width);
                }
                else
                {
                    playerComponent.TargetPosition.z = Random.NextInt(0, SceneManager.GetInstance().Height);
                }
            }

            // Move!
            translation.Value += math.normalize(playerComponent.TargetPosition - translation.Value) * SceneManager.GetInstance().Speed;
        }
Exemplo n.º 3
0
 public void Update()
 {
     for (var i = 0; i < _tenants; i++)
     {
         PowerUsage += _random.NextInt(12, 24);
     }
 }
Exemplo n.º 4
0
 public Data(MBuilding building)
 {
     _random    = new Unity.Mathematics.Random(1);
     _tenants   = building.floors * _random.NextInt(20, 500);
     PowerUsage = 0;
     Debug.Log(_tenants);
 }
Exemplo n.º 5
0
        public void Execute(Entity entity, int index, ref DustTrail trail, ref CartoonBody c1, ref LocalToWorld l0)
        {
            trail.m_CurrentTime += deltaTime;

            var coinflip = new Unity.Mathematics.Random(12345);
            var outcome  = coinflip.NextInt(0, 1);

            if (trail.m_CurrentTime > trail.Rate || outcome.Equals(1))
            {
                if (!PlayerInput.Move.Equals(float2.zero))
                {
                    var   rand    = new Unity.Mathematics.Random(12345);
                    float f1      = (float)rand.NextInt(-2, 2);
                    var   intRand = rand.NextInt(trail.MinAmount, trail.MaxAmount + 5);

                    for (int i = 0; i < intRand; i++)
                    {
                        var dust           = CommandBuffer.Instantiate(index, trail.DustPrefabEntity);
                        var PositionOffset = new float3(0, -0.5f, 0);

                        CommandBuffer.SetComponent(index, dust, new Translation {
                            Value = l0.Position + PositionOffset
                        });
                        var localToWorld = new LocalToWorld
                        {
                            Value = float4x4.TRS(new float3(l0.Position + PositionOffset),
                                                 quaternion.LookRotationSafe(l0.Forward, math.up()),
                                                 new float3(0.30f, 0.30f, 0.30f))
                        };


                        CommandBuffer.SetComponent(index, dust, new LocalToWorld
                        {
                            Value = localToWorld.Value
                        });

                        var seed = rand.NextUInt(1, 100) + (uint)i;
                        CommandBuffer.AddComponent(index, dust, new Seed {
                            Value = seed
                        });
                    }

                    trail.m_CurrentTime = 0;
                }
            }
        }
Exemplo n.º 6
0
            public void Update()
            {
                var random = new Unity.Mathematics.Random(1);

                for (var i = 0; i < _tenants; i++)
                {
                    PowerUsage += random.NextInt(12, 24);
                }
            }
        private void Move(ref Translation translation, ref PlayerComponent playerComponent)
        {
            int x, y;

            switch (playerComponent.direction)
            {
            case 0:
                x = 0;
                y = 1;
                break;

            case 1:
                x = 1;
                y = 0;
                break;

            case 2:
                x = 0;
                y = -1;
                break;

            default:
                x = -1;
                y = 0;
                break;
            }
            int targetX = Mathf.RoundToInt(translation.Value.x) + x;
            int targetY = Mathf.RoundToInt(translation.Value.y) + y;

            if (targetX < 0 || targetX >= 100 || targetY < 0 || targetY >= 100 ||
                treeMap[targetX + targetY * 100])
            {
                //var rnd = new Unity.Mathematics.Random(BaseSeed);
                playerComponent.direction = random.NextInt(0, 4);
                //playerComponent.direction = (playerComponent.direction + 1) % 4;
                translation.Value = new float3(Mathf.RoundToInt(translation.Value.x), Mathf.RoundToInt(translation.Value.y), translation.Value.z);
                Move(ref translation, ref playerComponent);
            }
            else
            {
                translation.Value += new float3(x, y, 0f) * 5f * deltaTime;
            }
        }
Exemplo n.º 8
0
    static void RunningSumTestCase(uint seed, int length, RunningSum scalar, RunningSum simd)
    {
        Unity.Mathematics.Random rng = new Unity.Mathematics.Random(seed);
        var arrayScalar = new int[length];
        var arraySimd   = new int[length];

        for (int i = 0; i < length; i++)
            arrayScalar[i] = arraySimd[i] = rng.NextInt();

        fixed(int *outputPtr = arrayScalar)
        scalar(outputPtr, length);

        fixed(int *outputPtr = arraySimd)
        simd(outputPtr, length);

        for (int i = 0; i < length; i++)
        {
            Assert.AreEqual(arrayScalar[i], arraySimd[i], $"SIMD version failed with seed {seed} with input length {length}: Different output at index {i}");
        }
    }
Exemplo n.º 9
0
 public int Act(ref WindjermanGameState gs, NativeList <int> availableActions)
 {
     return(availableActions[rdm.NextInt(0, availableActions.Length)]);
 }