示例#1
0
            public static ProjectileStruct CreateProjectileStruct(ref FileStruct.TSAreaProjectile tsAreaProjectile)
            {
                ProjectileStruct ss = new ProjectileStruct();

                ss.resProjectile = Utils.CharsToString(tsAreaProjectile.resProjectile).ToUpper();
                ss.blockOffset   = tsAreaProjectile.blockOffset;
                ss.blockSize     = tsAreaProjectile.blockSize;
                ss.location      = tsAreaProjectile.projLoc;
                return(ss);
            }
示例#2
0
    private void Awake()
    {
        for (int i = 0; i < count; ++i)
        {
            projectileStructs[i] = new ProjectileStruct();
        }
        Shuffle(projectileStructs);

        for (int i = 0; i < count; ++i)
        {
            projectileClasses[i] = new ProjectileClass();
        }
        Shuffle(projectileClasses);
    }
示例#3
0
    void Start()
    {
        const int count = 10000000;

        ProjectileStruct[] projectileStructs = new ProjectileStruct[count];
        ProjectileClass[]  projectileClasses = new ProjectileClass[count];
        for (int i = 0; i < count; ++i)
        {
            //class
            projectileClasses[i]          = new ProjectileClass();
            projectileClasses[i].Velocity = UnityEngine.Random.onUnitSphere;
            //struct
            projectileStructs[i].Velocity = UnityEngine.Random.onUnitSphere;
        }
        // Shuffle to simulate objects being destroyed and created anew
        Shuffle(projectileStructs);
        Shuffle(projectileClasses);

        System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
        for (int i = 0; i < count; ++i)
        {
            UpdateProjectile(ref projectileStructs[i], 0.5f);
        }
        long structTime = sw.ElapsedMilliseconds;

        sw.Reset();
        sw.Start();
        for (int i = 0; i < count; ++i)
        {
            UpdateProjectile(projectileClasses[i], 0.5f);
        }
        long classTime = sw.ElapsedMilliseconds;

        string report = string.Format("Struct: {0}, Class: {1}", structTime, classTime);

        Debug.Log(report);
    }
示例#4
0
 void UpdateProjectile(ref ProjectileStruct projectile, float time)
 {
     projectile.Position += projectile.Velocity * time;
 }