Exemplo n.º 1
0
    void UpdateThread()
    {
        float maxFPS = 100.0f;

        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        while (running)
        {
            stopwatch.Reset();
            stopwatch.Start();

            // Update all the boids
            for (int i = 0; i < boids.Length; i++)
            {
                Boid boid = boids[i];
                boid.force = boid.CalculateForce();
            }
            stopwatch.Stop();
            threadTimeDelta = (float)((double)stopwatch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency);
            threadCount++;
            if (threadTimeDelta < 0.01f)
            {
                Thread.Sleep(10);
                threadTimeDelta = 0.01f;
            }
            threadFPS = 1.0f / threadTimeDelta;
        }
    }