<commit_before>﻿//=======================================================================
// Copyright (c) 2015 <NAME>
// Distributed under the MIT License.
// (See accompanying file LICENSE or copy at
// http://opensource.org/licenses/MIT)
//=======================================================================

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Timers;
using System;

namespace Lockstep
{
    public static class PhysicsManager
    {
        #region User-defined Variables

        public const bool SimulatePhysics = true;
        public const int SimulationSpread = 1;

        static	int VisualSetSpread
        {
            get
            {
                return 2;
            }
        }

        public const int FrameRate = LockstepManager.FrameRate / SimulationSpread;

        static long FixedDeltaTicks
        {
            get
            {
                return (long)((10000000L * VisualSetSpread) / FrameRate);
            }
        }

        #endregion

        #region Counters

        #endregion

        #region Simulation Variables

        public const int MaxSimObjects = 5000;
        public static LSBody[] SimObjects = new LSBody[MaxSimObjects];
        private static Dictionary<int,CollisionPair> CollisionPairs = new Dictionary<int,CollisionPair>(MaxSimObjects);
        public static FastList<CollisionPair> FastCollisionPairs = new FastList<CollisionPair>(MaxSimObjects);
        private static int simulationCount;
        private static int visualSetCount;

        #endregion

        #region Assignment Variables

        public static bool[] SimObjectExists = new bool[MaxSimObjects];
        public static int PeakCount = 0;
        private static FastStack<int> CachedIDs = new FastStack<int>(MaxSimObjects / 8);
        public static int AssimilatedCount = 0;

        #endregion

        #region Visualization

        #endregion

        public static void Setup()
        {
            Partition.Setup();
        }


        public static void Initialize()
        {
            PeakCount = 0;

            CachedIDs.FastClear();
            SimObjectExists.Clear();
            //CollisionPairs.Clear ();
            //SimObjects.Clear ();
            CollisionPair.CurrentCollisionPair = null;

            PeakCount = 0;
            AssimilatedCount = 0;
            simulationCount = SimulationSpread;

            FastCollisionPairs.FastClear();

            Partition.Initialize();
        }


        public static void Simulate()
        {
            simulationCount--;
            if (simulationCount <= 0)
            {
                simulationCount = SimulationSpread;
            } else
            {
                return;
            }


            for (int i = 0; i < PeakCount; i++)
            {
                if (SimObjectExists [i])
                {
                    LSBody b1 = SimObjects [i];
                    b1.EarlySimulate();
                }
            }
            Partition.CheckAndDistributeCollisions();
            for (int i = 0; i < PeakCount; i++)
            {
                if (SimObjectExists [i])
                {
                    LSBody b1 = SimObjects [i];
                    b1.Simulate();
                }
            }

        }

        public static void LateSimulate()
        {
            visualSetCount--;
			
            SetVisuals = visualSetCount <= 0;
			
            if (SetVisuals)
            {
                long curTicks = LockstepManager.Ticks;
                LastDeltaTicks = curTicks - LastSimulateTicks;
                LastSimulateTicks = curTicks;
                visualSetCount = VisualSetSpread;
            }
            for (int i = 0; i < PeakCount; i++)
            {
                if (SimObjectExists [i])
                {
                    SimObjects [i].LateSimulate();
                }
            }

        }

        public static bool SetVisuals;
        public static float LerpTime;
        public static float LerpDamping;
        private static float LerpDampScaler;
        static long LastSimulateTicks;
        static long LastDeltaTicks;

        public static void Visualize()
        {
            float smoothDeltaTime = Mathf.Max(Time.unscaledDeltaTime, 1f / 256);
            LerpDampScaler = Mathf.Lerp(LerpDampScaler, (4f / 64) / smoothDeltaTime, Time.deltaTime);
            LerpDamping = Time.unscaledDeltaTime * LerpDampScaler;
            LerpDamping *= Time.timeScale;
            long curTicks = LockstepManager.Ticks;<commit_msg>Improve interpolation<commit_after>﻿//=======================================================================
// Copyright (c) 2015 <NAME>
// Distributed under the MIT License.
// (See accompanying file LICENSE or copy at
// http://opensource.org/licenses/MIT)
//=======================================================================

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Timers;
using System;

namespace Lockstep
{
    public static class PhysicsManager
    {
        #region User-defined Variables

        public const bool SimulatePhysics = true;
        public const int SimulationSpread = 1;

        static	int VisualSetSpread
        {
            get
            {
                return 2;
            }
        }

        public const int FrameRate = LockstepManager.FrameRate / SimulationSpread;

        static long FixedDeltaTicks
        {
            get
            {
                return (long)((10000000L * VisualSetSpread) / FrameRate);
            }
        }

        #endregion

        #region Counters

        #endregion

        #region Simulation Variables

        public const int MaxSimObjects = 5000;
        public static LSBody[] SimObjects = new LSBody[MaxSimObjects];
        private static Dictionary<int,CollisionPair> CollisionPairs = new Dictionary<int,CollisionPair>(MaxSimObjects);
        public static FastList<CollisionPair> FastCollisionPairs = new FastList<CollisionPair>(MaxSimObjects);
        private static int simulationCount;
        private static int visualSetCount;

        #endregion

        #region Assignment Variables

        public static bool[] SimObjectExists = new bool[MaxSimObjects];
        public static int PeakCount = 0;
        private static FastStack<int> CachedIDs = new FastStack<int>(MaxSimObjects / 8);
        public static int AssimilatedCount = 0;

        #endregion

        #region Visualization

        #endregion

        public static void Setup()
        {
            Partition.Setup();
        }


        public static void Initialize()
        {
            PeakCount = 0;

            CachedIDs.FastClear();
            SimObjectExists.Clear();
            //CollisionPairs.Clear ();
            //SimObjects.Clear ();
            CollisionPair.CurrentCollisionPair = null;

            PeakCount = 0;
            AssimilatedCount = 0;
            simulationCount = SimulationSpread;

            FastCollisionPairs.FastClear();

            Partition.Initialize();
        }


        public static void Simulate()
        {
            simulationCount--;
            if (simulationCount <= 0)
            {
                simulationCount = SimulationSpread;
            } else
            {
                return;
            }


            for (int i = 0; i < PeakCount; i++)
            {
                if (SimObjectExists [i])
                {
                    LSBody b1 = SimObjects [i];
                    b1.EarlySimulate();
                }
            }
            Partition.CheckAndDistributeCollisions();
            for (int i = 0; i < PeakCount; i++)
            {
                if (SimObjectExists [i])
                {
                    LSBody b1 = SimObjects [i];
                    b1.Simulate();
                }
            }

        }

        public static void LateSimulate()
        {
            visualSetCount--;
			
            SetVisuals = visualSetCount <= 0;
			
            if (SetVisuals)
            {
                long curTicks = LockstepManager.Ticks;
                LastDeltaTicks = curTicks - LastSimulateTicks;
                LastSimulateTicks = curTicks;
                visualSetCount = VisualSetSpread;
            }
            for (int i = 0; i < PeakCount; i++)
            {
                if (SimObjectExists [i])
                {
                    SimObjects [i].LateSimulate();
                }
            }

        }

        public static bool SetVisuals {get; private set;}
        public static float LerpTime {get ;private set;}
        public static float LerpDamping {get; private set;}
        private static float LerpDampScaler;
        static long LastSimulateTicks;
        static long LastDeltaTicks;

        public static void Visualize()
        {
            float smoothDeltaTime = Mathf.Max(Time.unscaledDeltaTime, 1f / 256);
            LerpDampScaler = .3f / smoothDeltaTime;
            LerpDamping = Time.unscaledDeltaTime * LerpDampScaler;
            LerpDamping *= Time.timeScale;
            long curTicks = LockstepManager.Ticks;
{'fraction_non_alphanumeric': 0.10352350823606414, 'fraction_numerical': 0.008508781498854588, 'mean_word_length': 1.5861777150916785, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7240636', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2199, 'n_words': 568}