Exemple #1
0
 void Start()
 {
     random       = new Random32(1);
     pieces       = new Piece[capacity];
     particleMesh = new ParticleMesh(meshRenderer, meshFilter, capacity * 2);
     Emit();
 }
Exemple #2
0
        public static void Bool2()
        {
            bool result = true;

            Random32 rng = new Random32(RNG_SEED);

            for (int i = 0; i < NUM_TESTS; i++)
            {
                bool2 x = rng.NextBool2();

                int test = maxmath.first(x);

                int j = 0;
                while (j < 2 && !x[j])
                {
                    j++;
                }

                result &= test == j;
            }

            int testt = maxmath.first(default(bool2));

            Assert.AreEqual(result && maxmath.first(default(bool2)) == 4, true);
        }
Exemple #3
0
        public static void rol_uint8()
        {
            bool     result = true;
            Random32 rng    = new Random32(RNG_SEED);

            for (int i = 0; i < UInt8.NUM_TESTS; i++)
            {
                for (int j = 0; j < NUM_ROTATION_TESTS; j++)
                {
                    int   n    = rng.NextInt();
                    uint8 test = maxmath.rol(UInt8.TestData_LHS[i], n);

                    result &= test.x0 == math.rol(UInt8.TestData_LHS[i].x0, n);
                    result &= test.x1 == math.rol(UInt8.TestData_LHS[i].x1, n);
                    result &= test.x2 == math.rol(UInt8.TestData_LHS[i].x2, n);
                    result &= test.x3 == math.rol(UInt8.TestData_LHS[i].x3, n);
                    result &= test.x4 == math.rol(UInt8.TestData_LHS[i].x4, n);
                    result &= test.x5 == math.rol(UInt8.TestData_LHS[i].x5, n);
                    result &= test.x6 == math.rol(UInt8.TestData_LHS[i].x6, n);
                    result &= test.x7 == math.rol(UInt8.TestData_LHS[i].x7, n);
                }
            }

            Assert.AreEqual(true, result);
        }
Exemple #4
0
        public static void rol_byte16()
        {
            bool     result = true;
            Random32 rng    = new Random32(RNG_SEED);

            for (int i = 0; i < Byte16.NUM_TESTS; i++)
            {
                for (int j = 0; j < NUM_ROTATION_TESTS; j++)
                {
                    int    n    = rng.NextInt();
                    byte16 test = maxmath.rol(Byte16.TestData_LHS[i], n);

                    result &= test.x0 == (byte)math.rol(Byte16.TestData_LHS[i].x0 | (Byte16.TestData_LHS[i].x0 << 8) | (Byte16.TestData_LHS[i].x0 << 16) | (Byte16.TestData_LHS[i].x0 << 24), n);
                    result &= test.x1 == (byte)math.rol(Byte16.TestData_LHS[i].x1 | (Byte16.TestData_LHS[i].x1 << 8) | (Byte16.TestData_LHS[i].x1 << 16) | (Byte16.TestData_LHS[i].x1 << 24), n);
                    result &= test.x2 == (byte)math.rol(Byte16.TestData_LHS[i].x2 | (Byte16.TestData_LHS[i].x2 << 8) | (Byte16.TestData_LHS[i].x2 << 16) | (Byte16.TestData_LHS[i].x2 << 24), n);
                    result &= test.x3 == (byte)math.rol(Byte16.TestData_LHS[i].x3 | (Byte16.TestData_LHS[i].x3 << 8) | (Byte16.TestData_LHS[i].x3 << 16) | (Byte16.TestData_LHS[i].x3 << 24), n);
                    result &= test.x4 == (byte)math.rol(Byte16.TestData_LHS[i].x4 | (Byte16.TestData_LHS[i].x4 << 8) | (Byte16.TestData_LHS[i].x4 << 16) | (Byte16.TestData_LHS[i].x4 << 24), n);
                    result &= test.x5 == (byte)math.rol(Byte16.TestData_LHS[i].x5 | (Byte16.TestData_LHS[i].x5 << 8) | (Byte16.TestData_LHS[i].x5 << 16) | (Byte16.TestData_LHS[i].x5 << 24), n);
                    result &= test.x6 == (byte)math.rol(Byte16.TestData_LHS[i].x6 | (Byte16.TestData_LHS[i].x6 << 8) | (Byte16.TestData_LHS[i].x6 << 16) | (Byte16.TestData_LHS[i].x6 << 24), n);
                    result &= test.x7 == (byte)math.rol(Byte16.TestData_LHS[i].x7 | (Byte16.TestData_LHS[i].x7 << 8) | (Byte16.TestData_LHS[i].x7 << 16) | (Byte16.TestData_LHS[i].x7 << 24), n);
                    result &= test.x8 == (byte)math.rol(Byte16.TestData_LHS[i].x8 | (Byte16.TestData_LHS[i].x8 << 8) | (Byte16.TestData_LHS[i].x8 << 16) | (Byte16.TestData_LHS[i].x8 << 24), n);
                    result &= test.x9 == (byte)math.rol(Byte16.TestData_LHS[i].x9 | (Byte16.TestData_LHS[i].x9 << 8) | (Byte16.TestData_LHS[i].x9 << 16) | (Byte16.TestData_LHS[i].x9 << 24), n);
                    result &= test.x10 == (byte)math.rol(Byte16.TestData_LHS[i].x10 | (Byte16.TestData_LHS[i].x10 << 8) | (Byte16.TestData_LHS[i].x10 << 16) | (Byte16.TestData_LHS[i].x10 << 24), n);
                    result &= test.x11 == (byte)math.rol(Byte16.TestData_LHS[i].x11 | (Byte16.TestData_LHS[i].x11 << 8) | (Byte16.TestData_LHS[i].x11 << 16) | (Byte16.TestData_LHS[i].x11 << 24), n);
                    result &= test.x12 == (byte)math.rol(Byte16.TestData_LHS[i].x12 | (Byte16.TestData_LHS[i].x12 << 8) | (Byte16.TestData_LHS[i].x12 << 16) | (Byte16.TestData_LHS[i].x12 << 24), n);
                    result &= test.x13 == (byte)math.rol(Byte16.TestData_LHS[i].x13 | (Byte16.TestData_LHS[i].x13 << 8) | (Byte16.TestData_LHS[i].x13 << 16) | (Byte16.TestData_LHS[i].x13 << 24), n);
                    result &= test.x14 == (byte)math.rol(Byte16.TestData_LHS[i].x14 | (Byte16.TestData_LHS[i].x14 << 8) | (Byte16.TestData_LHS[i].x14 << 16) | (Byte16.TestData_LHS[i].x14 << 24), n);
                    result &= test.x15 == (byte)math.rol(Byte16.TestData_LHS[i].x15 | (Byte16.TestData_LHS[i].x15 << 8) | (Byte16.TestData_LHS[i].x15 << 16) | (Byte16.TestData_LHS[i].x15 << 24), n);
                }
            }

            Assert.AreEqual(true, result);
        }
    public void Update(
        float deltaTime,
        ref Vector3 billboardUp,
        ref Vector3 billboardRight,
        ref Random32 random)
    {
        velocity *= 1f - (damping * deltaTime);
        float min = -0.5f * randomAccelStrengh;
        float max = -min;
        var   a   = new Vector3(
            random.GetFloat(min, max),
            random.GetFloat(min, max),
            random.GetFloat(min, max));

        Math.Add(ref a, ref constantAccel);
        Math.Madd(ref velocity, ref a, deltaTime);
        Math.Madd(ref position, ref velocity, deltaTime);
        radius *= 1f - (attenuation * deltaTime);
        time   += deltaTime;

        // 頂点座標計算
        const float cos30 = 0.866025403784439f;
        float       rCos30x2 = radius * cos30 * 2f;
        Vector3     tmpUp, tmpRight, upCenter;

        Math.SetMul(out tmpUp, ref billboardUp, radius);
        Math.SetMul(out tmpRight, ref billboardRight, rCos30x2);
        // 上辺はcenter.y - r*sin(30) = r/2
        // 下端はcenter.y + r*cos(30)
        Math.SetAdd(out upCenter, ref position, ref tmpUp);
        Math.SetMsub(out p0, ref position, ref tmpUp, 2f);
        Math.SetSub(out p1, ref upCenter, ref tmpRight);
        Math.SetAdd(out p2, ref upCenter, ref tmpRight);
    }
Exemple #6
0
        public static void Bool4()
        {
            bool result = true;

            Random32 rng = new Random32(RNG_SEED);

            for (int i = 0; i < NUM_TESTS; i++)
            {
                bool4 x = rng.NextBool4();

                int test = 0;

                for (int j = 0; j < 4; j++)
                {
                    if (x[j])
                    {
                        test++;
                    }
                }

                result &= test == maxmath.count(x);
            }

            Assert.AreEqual(true, result);
        }
Exemple #7
0
        public static void ror_ushort8()
        {
            bool     result = true;
            Random32 rng    = new Random32(RNG_SEED);

            for (int i = 0; i < UShort8.NUM_TESTS; i++)
            {
                for (int j = 0; j < NUM_ROTATION_TESTS; j++)
                {
                    int     n    = rng.NextInt();
                    ushort8 test = maxmath.ror(UShort8.TestData_LHS[i], n);

                    result &= test.x0 == (ushort)math.ror(UShort8.TestData_LHS[i].x0 | (UShort8.TestData_LHS[i].x0 << 16), n);
                    result &= test.x1 == (ushort)math.ror(UShort8.TestData_LHS[i].x1 | (UShort8.TestData_LHS[i].x1 << 16), n);
                    result &= test.x2 == (ushort)math.ror(UShort8.TestData_LHS[i].x2 | (UShort8.TestData_LHS[i].x2 << 16), n);
                    result &= test.x3 == (ushort)math.ror(UShort8.TestData_LHS[i].x3 | (UShort8.TestData_LHS[i].x3 << 16), n);
                    result &= test.x4 == (ushort)math.ror(UShort8.TestData_LHS[i].x4 | (UShort8.TestData_LHS[i].x4 << 16), n);
                    result &= test.x5 == (ushort)math.ror(UShort8.TestData_LHS[i].x5 | (UShort8.TestData_LHS[i].x5 << 16), n);
                    result &= test.x6 == (ushort)math.ror(UShort8.TestData_LHS[i].x6 | (UShort8.TestData_LHS[i].x6 << 16), n);
                    result &= test.x7 == (ushort)math.ror(UShort8.TestData_LHS[i].x7 | (UShort8.TestData_LHS[i].x7 << 16), n);
                }
            }

            Assert.AreEqual(true, result);
        }
Exemple #8
0
        public static void uint4()
        {
            Random32 rng = new Random32(135);

            for (uint i = 0; i < 64; i++)
            {
                uint4 x = rng.NextUInt4();

                Assert.AreEqual(new uint4((uint)_intsqrt(x.x), (uint)_intsqrt(x.y), (uint)_intsqrt(x.z), (uint)_intsqrt(x.w)), maxmath.intsqrt(x));
            }
        }
 private Nation RandomAttackNation(Random32 random, List <Nation> nation)
 {
     if (nation.Count > 1)
     {
         return(random.Choice(nation));
     }
     else
     {
         return(nation[0]);
     }
 }
Exemple #10
0
        public static void uint4()
        {
            Random32 rng = new Random32(135);

            for (uint i = 0; i < 64; i++)
            {
                uint4 x = rng.NextUInt4();
                uint4 y = rng.NextUInt4();

                Assert.AreEqual(new uint4((uint)_gcd(x.x, y.x), (uint)_gcd(x.y, y.y), (uint)_gcd(x.z, y.z), (uint)_gcd(x.w, y.w)), maxmath.gcd(x, y));
            }
        }
Exemple #11
0
        public static void int3()
        {
            Random32 rng = new Random32(135);

            for (int i = 0; i < 64; i++)
            {
                int3 x = rng.NextInt3();
                int3 y = rng.NextInt3();

                Assert.AreEqual(new uint3((uint)_gcd(x.x, y.x), (uint)_gcd(x.y, y.y), (uint)_gcd(x.z, y.z)), maxmath.gcd(x, y));
            }
        }
Exemple #12
0
        public static void int4()
        {
            Random32 rng = new Random32(135);

            for (int i = 0; i < 64; i++)
            {
                int4  x = rng.NextInt4();
                uint4 n = rng.NextUInt4();

                Assert.AreEqual(new int4((int)_intpow(x.x, n.x), (int)_intpow(x.y, n.y), (int)_intpow(x.z, n.z), (int)_intpow(x.w, n.w)), maxmath.intpow(x, n));
            }
        }
Exemple #13
0
        public static void ror_byte32()
        {
            bool     result = true;
            Random32 rng    = new Random32(RNG_SEED);

            for (int i = 0; i < Byte32.NUM_TESTS; i++)
            {
                for (int j = 0; j < NUM_ROTATION_TESTS; j++)
                {
                    int    n    = rng.NextInt();
                    byte32 test = maxmath.ror(Byte32.TestData_LHS[i], n);

                    result &= test.x0 == (byte)math.ror(Byte32.TestData_LHS[i].x0 | (Byte32.TestData_LHS[i].x0 << 8) | (Byte32.TestData_LHS[i].x0 << 16) | (Byte32.TestData_LHS[i].x0 << 24), n);
                    result &= test.x1 == (byte)math.ror(Byte32.TestData_LHS[i].x1 | (Byte32.TestData_LHS[i].x1 << 8) | (Byte32.TestData_LHS[i].x1 << 16) | (Byte32.TestData_LHS[i].x1 << 24), n);
                    result &= test.x2 == (byte)math.ror(Byte32.TestData_LHS[i].x2 | (Byte32.TestData_LHS[i].x2 << 8) | (Byte32.TestData_LHS[i].x2 << 16) | (Byte32.TestData_LHS[i].x2 << 24), n);
                    result &= test.x3 == (byte)math.ror(Byte32.TestData_LHS[i].x3 | (Byte32.TestData_LHS[i].x3 << 8) | (Byte32.TestData_LHS[i].x3 << 16) | (Byte32.TestData_LHS[i].x3 << 24), n);
                    result &= test.x4 == (byte)math.ror(Byte32.TestData_LHS[i].x4 | (Byte32.TestData_LHS[i].x4 << 8) | (Byte32.TestData_LHS[i].x4 << 16) | (Byte32.TestData_LHS[i].x4 << 24), n);
                    result &= test.x5 == (byte)math.ror(Byte32.TestData_LHS[i].x5 | (Byte32.TestData_LHS[i].x5 << 8) | (Byte32.TestData_LHS[i].x5 << 16) | (Byte32.TestData_LHS[i].x5 << 24), n);
                    result &= test.x6 == (byte)math.ror(Byte32.TestData_LHS[i].x6 | (Byte32.TestData_LHS[i].x6 << 8) | (Byte32.TestData_LHS[i].x6 << 16) | (Byte32.TestData_LHS[i].x6 << 24), n);
                    result &= test.x7 == (byte)math.ror(Byte32.TestData_LHS[i].x7 | (Byte32.TestData_LHS[i].x7 << 8) | (Byte32.TestData_LHS[i].x7 << 16) | (Byte32.TestData_LHS[i].x7 << 24), n);
                    result &= test.x8 == (byte)math.ror(Byte32.TestData_LHS[i].x8 | (Byte32.TestData_LHS[i].x8 << 8) | (Byte32.TestData_LHS[i].x8 << 16) | (Byte32.TestData_LHS[i].x8 << 24), n);
                    result &= test.x9 == (byte)math.ror(Byte32.TestData_LHS[i].x9 | (Byte32.TestData_LHS[i].x9 << 8) | (Byte32.TestData_LHS[i].x9 << 16) | (Byte32.TestData_LHS[i].x9 << 24), n);
                    result &= test.x10 == (byte)math.ror(Byte32.TestData_LHS[i].x10 | (Byte32.TestData_LHS[i].x10 << 8) | (Byte32.TestData_LHS[i].x10 << 16) | (Byte32.TestData_LHS[i].x10 << 24), n);
                    result &= test.x11 == (byte)math.ror(Byte32.TestData_LHS[i].x11 | (Byte32.TestData_LHS[i].x11 << 8) | (Byte32.TestData_LHS[i].x11 << 16) | (Byte32.TestData_LHS[i].x11 << 24), n);
                    result &= test.x12 == (byte)math.ror(Byte32.TestData_LHS[i].x12 | (Byte32.TestData_LHS[i].x12 << 8) | (Byte32.TestData_LHS[i].x12 << 16) | (Byte32.TestData_LHS[i].x12 << 24), n);
                    result &= test.x13 == (byte)math.ror(Byte32.TestData_LHS[i].x13 | (Byte32.TestData_LHS[i].x13 << 8) | (Byte32.TestData_LHS[i].x13 << 16) | (Byte32.TestData_LHS[i].x13 << 24), n);
                    result &= test.x14 == (byte)math.ror(Byte32.TestData_LHS[i].x14 | (Byte32.TestData_LHS[i].x14 << 8) | (Byte32.TestData_LHS[i].x14 << 16) | (Byte32.TestData_LHS[i].x14 << 24), n);
                    result &= test.x15 == (byte)math.ror(Byte32.TestData_LHS[i].x15 | (Byte32.TestData_LHS[i].x15 << 8) | (Byte32.TestData_LHS[i].x15 << 16) | (Byte32.TestData_LHS[i].x15 << 24), n);
                    result &= test.x16 == (byte)math.ror(Byte32.TestData_LHS[i].x16 | (Byte32.TestData_LHS[i].x16 << 8) | (Byte32.TestData_LHS[i].x16 << 16) | (Byte32.TestData_LHS[i].x16 << 24), n);
                    result &= test.x17 == (byte)math.ror(Byte32.TestData_LHS[i].x17 | (Byte32.TestData_LHS[i].x17 << 8) | (Byte32.TestData_LHS[i].x17 << 16) | (Byte32.TestData_LHS[i].x17 << 24), n);
                    result &= test.x18 == (byte)math.ror(Byte32.TestData_LHS[i].x18 | (Byte32.TestData_LHS[i].x18 << 8) | (Byte32.TestData_LHS[i].x18 << 16) | (Byte32.TestData_LHS[i].x18 << 24), n);
                    result &= test.x19 == (byte)math.ror(Byte32.TestData_LHS[i].x19 | (Byte32.TestData_LHS[i].x19 << 8) | (Byte32.TestData_LHS[i].x19 << 16) | (Byte32.TestData_LHS[i].x19 << 24), n);
                    result &= test.x20 == (byte)math.ror(Byte32.TestData_LHS[i].x20 | (Byte32.TestData_LHS[i].x20 << 8) | (Byte32.TestData_LHS[i].x20 << 16) | (Byte32.TestData_LHS[i].x20 << 24), n);
                    result &= test.x21 == (byte)math.ror(Byte32.TestData_LHS[i].x21 | (Byte32.TestData_LHS[i].x21 << 8) | (Byte32.TestData_LHS[i].x21 << 16) | (Byte32.TestData_LHS[i].x21 << 24), n);
                    result &= test.x22 == (byte)math.ror(Byte32.TestData_LHS[i].x22 | (Byte32.TestData_LHS[i].x22 << 8) | (Byte32.TestData_LHS[i].x22 << 16) | (Byte32.TestData_LHS[i].x22 << 24), n);
                    result &= test.x23 == (byte)math.ror(Byte32.TestData_LHS[i].x23 | (Byte32.TestData_LHS[i].x23 << 8) | (Byte32.TestData_LHS[i].x23 << 16) | (Byte32.TestData_LHS[i].x23 << 24), n);
                    result &= test.x24 == (byte)math.ror(Byte32.TestData_LHS[i].x24 | (Byte32.TestData_LHS[i].x24 << 8) | (Byte32.TestData_LHS[i].x24 << 16) | (Byte32.TestData_LHS[i].x24 << 24), n);
                    result &= test.x25 == (byte)math.ror(Byte32.TestData_LHS[i].x25 | (Byte32.TestData_LHS[i].x25 << 8) | (Byte32.TestData_LHS[i].x25 << 16) | (Byte32.TestData_LHS[i].x25 << 24), n);
                    result &= test.x26 == (byte)math.ror(Byte32.TestData_LHS[i].x26 | (Byte32.TestData_LHS[i].x26 << 8) | (Byte32.TestData_LHS[i].x26 << 16) | (Byte32.TestData_LHS[i].x26 << 24), n);
                    result &= test.x27 == (byte)math.ror(Byte32.TestData_LHS[i].x27 | (Byte32.TestData_LHS[i].x27 << 8) | (Byte32.TestData_LHS[i].x27 << 16) | (Byte32.TestData_LHS[i].x27 << 24), n);
                    result &= test.x28 == (byte)math.ror(Byte32.TestData_LHS[i].x28 | (Byte32.TestData_LHS[i].x28 << 8) | (Byte32.TestData_LHS[i].x28 << 16) | (Byte32.TestData_LHS[i].x28 << 24), n);
                    result &= test.x29 == (byte)math.ror(Byte32.TestData_LHS[i].x29 | (Byte32.TestData_LHS[i].x29 << 8) | (Byte32.TestData_LHS[i].x29 << 16) | (Byte32.TestData_LHS[i].x29 << 24), n);
                    result &= test.x30 == (byte)math.ror(Byte32.TestData_LHS[i].x30 | (Byte32.TestData_LHS[i].x30 << 8) | (Byte32.TestData_LHS[i].x30 << 16) | (Byte32.TestData_LHS[i].x30 << 24), n);
                    result &= test.x31 == (byte)math.ror(Byte32.TestData_LHS[i].x31 | (Byte32.TestData_LHS[i].x31 << 8) | (Byte32.TestData_LHS[i].x31 << 16) | (Byte32.TestData_LHS[i].x31 << 24), n);
                }
            }

            Assert.AreEqual(true, result);
        }
Exemple #14
0
        public static void Long3()
        {
            bool     result = true;
            Random32 x      = new Random32(47);

            for (long i = 0; i < Tests.Long3.NUM_TESTS; i++)
            {
                bool3 b = x.NextBool3();
                long3 a = maxmath.negate(Tests.Long3.TestData_LHS[i], b);

                result &= math.all(a == (maxmath.select(Tests.Long3.TestData_LHS[i], -Tests.Long3.TestData_LHS[i], b)));
            }

            Assert.AreEqual(true, result);
        }
Exemple #15
0
        public static void Float4()
        {
            bool     result = true;
            Random32 x      = new Random32(47);

            for (int i = 0; i < Tests.Float4.NUM_TESTS; i++)
            {
                bool4  b = x.NextBool4();
                float4 a = maxmath.negate(Tests.Float4.TestData_LHS[i], b);

                result &= math.all(a == (math.select(Tests.Float4.TestData_LHS[i], -Tests.Float4.TestData_LHS[i], b)));
            }

            Assert.AreEqual(true, result);
        }
Exemple #16
0
        public static void Float()
        {
            bool     result = true;
            Random32 x      = new Random32(47);

            for (int i = 0; i < Tests.Float8.NUM_TESTS; i++)
            {
                bool  b = x.NextBool();
                float a = maxmath.negate(Tests.Float8.TestData_LHS[i].x0, b);

                result &= a == (b ? -Tests.Float8.TestData_LHS[i].x0 : Tests.Float8.TestData_LHS[i].x0);
            }

            Assert.AreEqual(true, result);
        }
Exemple #17
0
        public static void Double()
        {
            bool     result = true;
            Random32 x      = new Random32(47);

            for (int i = 0; i < Tests.Double4.NUM_TESTS; i++)
            {
                bool   b = x.NextBool();
                double a = maxmath.negate(Tests.Double4.TestData_LHS[i].x, b);

                result &= a == (b ? -Tests.Double4.TestData_LHS[i].x : Tests.Double4.TestData_LHS[i].x);
            }

            Assert.AreEqual(true, result);
        }
Exemple #18
0
        public static void SByte4()
        {
            bool     result = true;
            Random32 x      = new Random32(47);

            for (int i = 0; i < Tests.SByte4.NUM_TESTS; i++)
            {
                sbyte4 t = maxmath.sign(Tests.SByte4.TestData_LHS[i]);

                result &= t.x == ((Tests.SByte4.TestData_LHS[i].x == 0) ? 0 : ((Tests.SByte4.TestData_LHS[i].x < 0) ? -1 : 1));
                result &= t.y == ((Tests.SByte4.TestData_LHS[i].y == 0) ? 0 : ((Tests.SByte4.TestData_LHS[i].y < 0) ? -1 : 1));
                result &= t.z == ((Tests.SByte4.TestData_LHS[i].z == 0) ? 0 : ((Tests.SByte4.TestData_LHS[i].z < 0) ? -1 : 1));
                result &= t.w == ((Tests.SByte4.TestData_LHS[i].w == 0) ? 0 : ((Tests.SByte4.TestData_LHS[i].w < 0) ? -1 : 1));
            }

            Assert.AreEqual(true, result);
        }
Exemple #19
0
        public static void Bool16()
        {
            Random32 rng = new Random32(RNG_SEED);

            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                int    r = rng.NextInt(0, ushort.MaxValue + 1);
                bool16 x = maxmath.tobool16(r);

                for (int j = 0; j < 4; j++)
                {
                    result &= x[j] == System.Convert.ToBoolean((r >> j) & 1);
                }
            }

            Assert.AreEqual(true, result);
        }
Exemple #20
0
        public static void uint8()
        {
            Random32 rng = new Random32(135);

            for (uint i = 0; i < 64; i++)
            {
                uint8 x = rng.NextUInt8();

                Assert.AreEqual(new uint8((uint)_intsqrt(x.x0),
                                          (uint)_intsqrt(x.x1),
                                          (uint)_intsqrt(x.x2),
                                          (uint)_intsqrt(x.x3),
                                          (uint)_intsqrt(x.x4),
                                          (uint)_intsqrt(x.x5),
                                          (uint)_intsqrt(x.x6),
                                          (uint)_intsqrt(x.x7)),
                                maxmath.intsqrt(x));
            }
        }
Exemple #21
0
        public static void rol_ulong2()
        {
            bool     result = true;
            Random32 rng    = new Random32(RNG_SEED);

            for (int i = 0; i < ULong2.NUM_TESTS; i++)
            {
                for (int j = 0; j < NUM_ROTATION_TESTS; j++)
                {
                    int    n    = rng.NextInt();
                    ulong2 test = maxmath.rol(ULong2.TestData_LHS[i], n);

                    result &= test.x == math.rol(ULong2.TestData_LHS[i].x, n);
                    result &= test.y == math.rol(ULong2.TestData_LHS[i].y, n);
                }
            }

            Assert.AreEqual(true, result);
        }
Exemple #22
0
        public static void int8()
        {
            Random32 rng = new Random32(135);

            for (int i = 0; i < 64; i++)
            {
                int8  x = rng.NextInt8();
                uint8 n = rng.NextUInt8();

                Assert.AreEqual(new int8((int)_intpow(x.x0, n.x0),
                                         (int)_intpow(x.x1, n.x1),
                                         (int)_intpow(x.x2, n.x2),
                                         (int)_intpow(x.x3, n.x3),
                                         (int)_intpow(x.x4, n.x4),
                                         (int)_intpow(x.x5, n.x5),
                                         (int)_intpow(x.x6, n.x6),
                                         (int)_intpow(x.x7, n.x7)),
                                maxmath.intpow(x, n));
            }
        }
Exemple #23
0
        public static void uint8()
        {
            Random32 rng = new Random32(135);

            for (uint i = 0; i < 64; i++)
            {
                uint8 x = rng.NextUInt8();
                uint8 y = rng.NextUInt8();

                Assert.AreEqual(new uint8((uint)_gcd(x.x0, y.x0),
                                          (uint)_gcd(x.x1, y.x1),
                                          (uint)_gcd(x.x2, y.x2),
                                          (uint)_gcd(x.x3, y.x3),
                                          (uint)_gcd(x.x4, y.x4),
                                          (uint)_gcd(x.x5, y.x5),
                                          (uint)_gcd(x.x6, y.x6),
                                          (uint)_gcd(x.x7, y.x7)),
                                maxmath.gcd(x, y));
            }
        }
Exemple #24
0
        public static void int8()
        {
            Random32 rng = new Random32(135);

            for (int i = 0; i < 64; i++)
            {
                int8 x = rng.NextInt8();
                int8 y = rng.NextInt8();

                Assert.AreEqual(new int8((int)math.lzcnt(x.x0),
                                         (int)math.lzcnt(x.x1),
                                         (int)math.lzcnt(x.x2),
                                         (int)math.lzcnt(x.x3),
                                         (int)math.lzcnt(x.x4),
                                         (int)math.lzcnt(x.x5),
                                         (int)math.lzcnt(x.x6),
                                         (int)math.lzcnt(x.x7)),
                                maxmath.lzcnt(x));
            }
        }
Exemple #25
0
        public static void Bool4()
        {
            bool result = true;

            Random32 rng = new Random32(RNG_SEED);

            for (int i = 0; i < NUM_TESTS; i++)
            {
                bool4 x = rng.NextBool4();

                int test = maxmath.last(x);

                int j = 3;
                while (j != -1 && !x[j])
                {
                    j--;
                }

                result &= test == j;
            }

            Assert.AreEqual(result && maxmath.last(default(bool4)) == -1, true);
        }
Exemple #26
0
 public Job(Particle[] particles, int jobIndex, ParticleRenderer renderer)
 {
     this.particles = particles;
     this.renderer  = renderer;
     this.random    = new Random32(jobIndex);
 }
Exemple #27
0
    void Start()
    {
        debugUi = DebugUiManager.Create(
            mainCamera,
            textShader,
            texturedShader,
            font,
            768,
            432,
            1f,
            100);
        debugUi.Add(new FrameTimeGauge(100f, 20f, null), 0f, 0f, DebugUi.AlignX.Right);

        var toggle = new DebugUiToggle("Thread");

        toggle.onChange = on =>
        {
            threadEnabled = on;
        };
        debugUi.Add(toggle, 0f, 20f, DebugUi.AlignX.Right);

        var button = new DebugUiButton("Fire");

        button.onClick = () =>
        {
            Fire();
        };
        debugUi.Add(button, 0f, -50f, DebugUi.AlignX.Right, DebugUi.AlignY.Bottom);

        button         = new DebugUiButton("Fire16");
        button.onClick = () =>
        {
            Fire(16);
        };
        debugUi.Add(button, 0f, 0f, DebugUi.AlignX.Right, DebugUi.AlignY.Bottom);

        random           = new Random32(0);
        cameraController = new CameraController(mainCamera);
        targetOrigin     = target.transform.position;
        beams            = new Beam[64];
        for (int i = 0; i < beams.Length; i++)
        {
            beams[i] = new Beam();
        }
        particles = new Particle[particleCapacity];
        for (int i = 0; i < particles.Length; i++)
        {
            particles[i].position = new Vector3(1000f, 1000f, -1000f);
            particles[i].time     = -float.MaxValue;
        }

        var threadCount = SystemInfo.processorCount;
        var jobCount    = threadCount * 3;

        threadPool        = new ThreadPool(threadCount, jobCount);
        jobs              = new Job[jobCount];
        particleRenderers = new ParticleRenderer[jobCount];
        int rendererCapacity = (particleCapacity + jobCount - 1) / jobCount;

        for (int i = 0; i < jobCount; i++)
        {
            particleRenderers[i] = Instantiate(particleRendererPrefab, gameObject.transform, false);
            particleRenderers[i].Initialize(mainCamera, rendererCapacity);
            jobs[i] = new Job(particles, i, particleRenderers[i]);
        }

        Update();         // 初回
        LateUpdate();
        cameraController.Converge();
    }