Esempio n. 1
0
 // ----------------------------------------------------------------------------------------------------------------
 // Determines the appropriate response if a particular button has been pressed.
 private void determineResponse(bool isReplay)
 {
     if (chronometer != null)
     {
         chronometer.Stop();
         chronometer = null;
     }
     if (logic != null)
     {
         logic.deleteBoard();
         logic = null;
     }
     if (sensorOn)
     {
         sensorSwitch(false);
     }
     if (isReplay)
     {
         GlobalApp.BeginActivity(this, typeof(DiceRollsActivity), GlobalApp.getVariableDifficultyName(), Intent.GetIntExtra(GlobalApp.getVariableDifficultyName(), 1), GlobalApp.getVariableChoiceName(), Intent.GetIntExtra(GlobalApp.getVariableChoiceName(), 0));
     }
     else
     {
         GlobalApp.BeginActivity(this, typeof(GameMenuActivity), GlobalApp.getVariableChoiceName(), Intent.GetIntExtra(GlobalApp.getVariableChoiceName(), 0));
     }
 }
        private Measurement MultiInvoke(
            IterationMode mode, int index, Action setupAction, Action targetAction, long invocationCount,
            long operationsPerInvoke)
        {
            var totalOperations = invocationCount * operationsPerInvoke;

            setupAction();
            ClockSpan clockSpan;

            GcCollect();
            if (invocationCount == 1)
            {
                var chronometer = Chronometer.Start();
                targetAction();
                clockSpan = chronometer.Stop();
            }
            else if (invocationCount < int.MaxValue)
            {
                int intInvocationCount = (int)invocationCount;
                var chronometer        = Chronometer.Start();
                RunAction(targetAction, intInvocationCount);
                clockSpan = chronometer.Stop();
            }
            else
            {
                var chronometer = Chronometer.Start();
                RunAction(targetAction, invocationCount);
                clockSpan = chronometer.Stop();
            }
            var measurement = new Measurement(0, mode, index, totalOperations, clockSpan.GetNanoseconds());

            Console.WriteLine(measurement.ToOutputLine());
            GcCollect();
            return(measurement);
        }
Esempio n. 3
0
        [PublicAPI] public IEnumerable <Summary> Run(string[] args = null, IConfig config = null)
        {
            args = args ?? Array.Empty <string>();

            (bool isParsingSuccess, var parsedConfig) = ConfigParser.Parse(args, ConsoleLogger.Default);
            if (!isParsingSuccess)
            {
                return(Enumerable.Empty <Summary>());
            }

            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            var effectiveConfig = ManualConfig.Union(config ?? DefaultConfig.Instance, parsedConfig);

            var filteredBenchmarks = typeParser.Filter(effectiveConfig);

            if (filteredBenchmarks.IsEmpty())
            {
                return(Array.Empty <Summary>());
            }

            summaries.AddRange(BenchmarkRunner.Run(filteredBenchmarks, effectiveConfig));

            int totalNumberOfExecutedBenchmarks = summaries.Sum(summary => summary.GetNumberOfExecutedBenchmarks());

            BenchmarkRunner.LogTotalTime(logger, globalChronometer.GetElapsed().GetTimeSpan(), totalNumberOfExecutedBenchmarks, "Global total time");
            return(summaries);
        }
    void Start()
    {
        timerToStartMovement = new Chronometer(timeToStartMovement);
        timerToStartMovement.Start();

        timerToDestroySpaceship = new Chronometer(timeToDestroySpaceship);
    }
Esempio n. 5
0
        private void BtnTimerPause_clicked(object sender, EventArgs e)
        {
            Chronometer chrono = FindViewById <Chronometer>(Resource.Id.chronoHelper);

            timeWhenStopped = chrono.Base - SystemClock.ElapsedRealtime();
            chrono.Stop();
        }
Esempio n. 6
0
        public void Start(MainViewModel viewModel, IPlayablePuzzle puzzle)
        {
            this.Vm             = viewModel;
            this.PlayablePuzzle = puzzle;
            this.Grid           = this.PlayablePuzzle.Grid.Map(puzzlesquare => new PuzzleSquareViewModel(puzzlesquare)).Copy();
            this.Chronometer    = new Chronometer();

            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(250);
            timer.Tick    += (o, s) =>
            {
                if (IsSolved.Value)
                {
                    timer.Stop();
                    Chronometer.Pause();
                }
                else
                {
                    Chronometer.Tick();
                }
            };
            timer.Start();

            this.Chronometer.Start();
        }
        public void HardwareTimerKindTest()
        {
            var expected = new StringBuilder();
            var actual   = new StringBuilder();
            var diff     = new StringBuilder();
            Action <long, HardwareTimerKind> check = (freq, expectedKind) =>
            {
                var actualKind = Chronometer.GetHardwareTimerKind(freq);
                var message    = actualKind == expectedKind ? "" : " [ERROR]";
                expected.AppendLine($"{freq}: {expectedKind}");
                actual.AppendLine($"{freq}: {actualKind}");
                diff.AppendLine($"{freq}: Expected = {expectedKind}; Actual = {actualKind}{message}");
            };

            check(64, HardwareTimerKind.System);   // Common min frequency of GetSystemTimeAsFileTime
            check(1000, HardwareTimerKind.System); // Common work frequency of GetSystemTimeAsFileTime
            check(2000, HardwareTimerKind.System); // Common max frequency of GetSystemTimeAsFileTime
            check(2143477, HardwareTimerKind.Tsc);
            check(2728067, HardwareTimerKind.Tsc);
            check(3507519, HardwareTimerKind.Tsc);
            check(3579545, HardwareTimerKind.Acpi);
            check(14318180, HardwareTimerKind.Hpet);
            check(10000000, HardwareTimerKind.Unknown); // Common value for Mono and VirtualBox

            output.WriteLine(diff.ToString());

            Assert.Equal(expected.ToString(), actual.ToString());
        }
Esempio n. 8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public Widget()
 {
     _chronometer = new Chronometer(Engine.Chronometer);
     Position     = new Vector2f();
     Hue          = Engine.DefaultHue;
     Enabled      = true;
 }
Esempio n. 9
0
        private Measurement MultiInvoke <T>(IterationMode mode, int index, Action setupAction, Func <T> targetAction, Action cleanupAction, long invocationCount, long operationsPerInvoke, GarbageCollection garbageCollectionSettings, T returnHolder = default(T))
        {
            var totalOperations = invocationCount * operationsPerInvoke;

            setupAction();
            ClockSpan clockSpan;

            GcCollect(garbageCollectionSettings);
            if (invocationCount == 1)
            {
                var chronometer = Chronometer.Start();
                returnHolder = targetAction();
                clockSpan    = chronometer.Stop();
            }
            else if (invocationCount < int.MaxValue)
            {
                int intInvocationCount = (int)invocationCount;
                var chronometer        = Chronometer.Start();
                RunAction(targetAction, intInvocationCount);
                clockSpan = chronometer.Stop();
            }
            else
            {
                var chronometer = Chronometer.Start();
                RunAction(targetAction, invocationCount);
                clockSpan = chronometer.Stop();
            }
            multiInvokeReturnHolder = returnHolder;
            var measurement = new Measurement(0, mode, index, totalOperations, clockSpan.GetNanoseconds());

            Console.WriteLine(measurement.ToOutputLine());
            GcCollect(garbageCollectionSettings);
            return(measurement);
        }
Esempio n. 10
0
        private void Start()
        {
            gameOverText.enabled = false;
            leaveBut.onClick.AddListener(leaveScene);
            decChrono = new Chronometer();
            decChrono.Start();
            GameController controller = new GameController();

            controller.playerHealth = 10;
            controller.playerFood   = 100;
            Planet planet = new Planet(true, true, true, true, 20);

            noOxygen     = !planet.withOxigen();
            playerFood   = controller.playerFood;
            playerHealth = controller.playerHealth;
            playerFuel   = controller.playerFuel;
            playerWater  = controller.playerWater;
            playerOxygen = controller.playerWater;

            foodSlider.maxValue   = controller.maxFood;
            fuelSlider.maxValue   = controller.maxFuel;
            waterSlider.maxValue  = controller.maxWater;
            oxygenSlider.maxValue = controller.maxOxygen;
            healthSlider.maxValue = controller.maxHealth;


            m_Rigidbody2D.gravityScale = planet.getGravityScale();
        }
Esempio n. 11
0
        /// <summary>
        /// Initial function call when activity loads
        /// </summary>
        /// <param name="bundle"></param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            IsOver = false; // game not over
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Game);

            // Grab UI Componets
            _mineTable             = FindViewById <TableLayout>(Resource.Id.mineTableLayout);
            MinesRemainingTextView = FindViewById <TextView>(Resource.Id.minesRemaining);
            Timer = FindViewById <Chronometer>(Resource.Id.chronometer);
            //var height = int.Parse((FindViewById<EditText>(Resource.Id.editTextHeight)).Text);
            //var width = int.Parse((FindViewById<EditText>(Resource.Id.editTextWidth)).Text);
            //var numMines = int.Parse((FindViewById<EditText>(Resource.Id.editTextMines)).Text);

            var numMines = int.Parse(Intent.GetStringExtra("mines") ?? "5");
            var height   = int.Parse(Intent.GetStringExtra("height") ?? "11");
            var width    = int.Parse(Intent.GetStringExtra("width") ?? "6");

            NumFlags = numMines;

            // Create new engine with current game settings
            _gameEngine = new Engine(height, width, numMines);
            SetMinesText();
            PopulateTable();
            _run          = true;  // Set runner thread to loop
            _runnerThread = new Thread(new ThreadStart(Runner));
            _runnerThread.Start(); // start runner
        }
Esempio n. 12
0
        private IEnumerable <Summary> RunBenchmarks(string[] args, IConfig config)
        {
            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            if (ShouldDisplayOptions(args))
            {
                DisplayOptions();
                return(Enumerable.Empty <Summary>());
            }

            var  effectiveConfig = ManualConfig.Union(config ?? DefaultConfig.Instance, ManualConfig.Parse(args));
            bool join            = args.Any(arg => arg.EqualsWithIgnoreCase("--join"));

            var benchmarks = typeParser.MatchingTypesWithMethods(args)
                             .Select(typeWithMethods =>
                                     typeWithMethods.AllMethodsInType
                        ? BenchmarkConverter.TypeToBenchmarks(typeWithMethods.Type, effectiveConfig)
                        : BenchmarkConverter.MethodsToBenchmarks(typeWithMethods.Type, typeWithMethods.Methods, effectiveConfig))
                             .ToArray();

            summaries.AddRange(BenchmarkRunner.Run(benchmarks, effectiveConfig, summaryPerType: !join));

            var clockSpan = globalChronometer.GetElapsed();

            BenchmarkRunner.LogTotalTime(logger, clockSpan.GetTimeSpan(), "Global total time");
            return(summaries);
        }
Esempio n. 13
0
        private IEnumerable <Summary> RunBenchmarks(string[] args)
        {
            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();
            var config            = ManualConfig.Union(DefaultConfig.Instance, ManualConfig.Parse(args));

            for (int i = 0; i < Types.Length; i++)
            {
                var type = Types[i];
                if (args.Any(arg => type.Name.ToLower().StartsWith(arg.ToLower())) || args.Contains("#" + i) || args.Contains("" + i) || args.Contains("*"))
                {
                    logger.WriteLineHeader("Target type: " + type.Name);
                    summaries.Add(BenchmarkRunner.Run(type, config));
                    logger.NewLine();
                }
            }
            // TODO: move this logic to the RunUrl method
#if CLASSIC
            if (args.Length > 0 && (args[0].StartsWith("http://") || args[0].StartsWith("https://")))
            {
                var url  = args[0];
                Uri uri  = new Uri(url);
                var name = uri.IsFile ? Path.GetFileName(uri.LocalPath) : "URL";
                summaries.Add(BenchmarkRunner.RunUrl(url, config));
            }
#endif
            var clockSpan = globalChronometer.Stop();
            BenchmarkRunner.LogTotalTime(logger, clockSpan.GetTimeSpan(), "Global total time");
            return(summaries);
        }
Esempio n. 14
0
        public IEnumerable <Summary> Run(string[] args = null, IConfig config = null)
        {
            args = args ?? Array.Empty <string>();

            if (ShouldDisplayOptions(args))
            {
                DisplayOptions();
                return(Enumerable.Empty <Summary>());
            }

            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            var  effectiveConfig = ManualConfig.Union(config ?? DefaultConfig.Instance, ManualConfig.Parse(args));
            bool join            = args.Any(arg => arg.EqualsWithIgnoreCase("--join"));

            var benchmarks = Filter(effectiveConfig);

            summaries.AddRange(BenchmarkRunner.Run(benchmarks, effectiveConfig, summaryPerType: !join));

            var totalNumberOfExecutedBenchmarks = summaries.Sum(summary => summary.GetNumberOfExecutedBenchmarks());

            BenchmarkRunner.LogTotalTime(logger, globalChronometer.GetElapsed().GetTimeSpan(), totalNumberOfExecutedBenchmarks, "Global total time");
            return(summaries);
        }
    void Start()
    {
        levelClock         = new Chronometer(timeLimit, this);
        timerToChangeScene = new Chronometer(timeToExit);

        IsPlayerAlive = true;

        if (firstRunScene)
        {
            if (languageSelected != CurrentLevelLanguage)
            {
                CurrentLevelLanguage = languageSelected;
            }

            if (difficultySelected != CurrentLevelDifficulty)
            {
                CurrentLevelDifficulty = difficultySelected;
            }
        }
        else
        {
            languageSelected   = CurrentLevelLanguage;
            difficultySelected = CurrentLevelDifficulty;
        }
    }
Esempio n. 16
0
    void Start()
    {
        chronometerGO     = GameObject.FindObjectOfType <Chronometer>().gameObject;
        chronometerScript = chronometerGO.GetComponent <Chronometer>();

        soundFxGO     = GameObject.FindObjectOfType <SoundFx>().gameObject;
        soundFxScript = soundFxGO.GetComponent <SoundFx>();
    }
Esempio n. 17
0
        public async Task SetCannotBeAttackedUntil(int seconds, int id = 0)
        {
            Chronometer chronometer = await this.GetChronometer(id);

            chronometer.CannotBeAttackedUntil = DateTime.UtcNow.AddSeconds(seconds);

            await this.context.SaveChangesAsync();
        }
Esempio n. 18
0
        public async Task <TViewModel> GetCurrentHeroChronometerViewModel <TViewModel>()
        {
            Chronometer chronometer = await this.GetChronometer();

            TViewModel viewModel = this.mapper.Map <TViewModel>(chronometer);

            return(viewModel);
        }
Esempio n. 19
0
        public async Task GetChronometerWithoutIdParameterShouldReturnCorrectChronometer()
        {
            // Act
            Chronometer actual = await this.chronometerService.GetChronometer(0);

            // Assert
            Assert.Equal(this.hero.Chronometer, actual);
        }
Esempio n. 20
0
 // constructor
 public Watch(int cyclesToTick)
 {
     cronometro = new Chronometer(cyclesToTick, true);
     stopwatch  = new Stopwatch();
     stopwatch.Start();
     timer = new Stopwatch();
     timer.Start();
 }
Esempio n. 21
0
        private void TimerReset()
        {
            Chronometer chrono = FindViewById <Chronometer>(Resource.Id.chronoHelper);

            chrono.Stop();
            chrono.Base     = SystemClock.ElapsedRealtime();
            timeWhenStopped = 0;
        }
Esempio n. 22
0
 public ChronometerControl(Chronometer chronometer, long maxTime)
 {
     this.chronometer             = chronometer;
     this.maxTime                 = maxTime;
     currentTime                  = maxTime;
     chronometer.CountDown        = true;
     chronometer.ChronometerTick += Chronometer_ChronometerTick;
 }
 public void StartTimer()
 {
     this.timer          = new DispatcherTimer();
     this.timer.Tick    += new EventHandler(TimerTick);
     this.timer.Interval = new TimeSpan(0, 0, 0, 0, 10);
     this.timer.Start();
     this.Chronometer = new Chronometer();
     Chronometer.Start();
 }
Esempio n. 24
0
        public void Start()
        {
            if (_startedClock.HasValue)
            {
                throw new InvalidOperationException("The manual timing has already been started.");
            }

            _startedClock = Chronometer.Start();
        }
Esempio n. 25
0
    void Start()
    {
        lastRaffleEnemies   = raffleEnemies;
        IsRaffleEnemies     = raffleEnemies;
        lastIsRaffleEnemies = IsRaffleEnemies;

        newEnemyTimer = new Chronometer(GetRandomTimeByDifficulty(), this);
        newEnemyTimer.Start();
    }
    void Start()
    {
        durationTimer = new Chronometer(lifeTime, this);
        durationTimer.Start();

        if (VibrateManager.Enable)
        {
            Handheld.Vibrate();
        }
    }
Esempio n. 27
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            long elapsed1 = 0;
            long elapsed2 = 0;

            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.MainActivity);

            // controls
            Switch      s1 = FindViewById <Switch>(Resource.Id.Person1Switch);
            Chronometer c1 = FindViewById <Chronometer>(Resource.Id.Person1Chronometer);

            s1.CheckedChange += (sender, e) =>
            {
                if (e.IsChecked)
                {
                    c1.Base = SystemClock.ElapsedRealtime() - elapsed1;
                    c1.Start();
                }
                else
                {
                    c1.Stop();
                    elapsed1 = SystemClock.ElapsedRealtime() - c1.Base;
                }
            };

            Switch      s2 = FindViewById <Switch>(Resource.Id.Person2Switch);
            Chronometer c2 = FindViewById <Chronometer>(Resource.Id.Person2Chronometer);

            s2.CheckedChange += (sender, e) =>
            {
                if (e.IsChecked)
                {
                    c2.Base = SystemClock.ElapsedRealtime() - elapsed2;
                    c2.Start();
                }
                else
                {
                    c2.Stop();
                    elapsed2 = SystemClock.ElapsedRealtime() - c2.Base;
                }
            };

            Button reset = FindViewById <Button>(Resource.Id.ResetButton);

            reset.Click += (sender, e) =>
            {
                s1.Checked = s2.Checked = false;
                c1.Base    = c2.Base = SystemClock.ElapsedRealtime();
                c1.Stop();
                c2.Stop();
                elapsed1 = elapsed2 = 0;
            };
        }
Esempio n. 28
0
        private IEnumerable <Summary> RunBenchmarks(string[] args, IConfig config)
        {
            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            if (ShouldDisplayOptions(args))
            {
                DisplayOptions();
                return(Enumerable.Empty <Summary>());
            }

            var  effectiveConfig = ManualConfig.Union(config ?? DefaultConfig.Instance, ManualConfig.Parse(args));
            bool join            = args.Any(arg => arg.EqualsWithIgnoreCase("--join"));

            if (join)
            {
                var typesWithMethods = typeParser.MatchingTypesWithMethods(args);
                var benchmarks       = typesWithMethods.SelectMany(typeWithMethods =>
                                                                   typeWithMethods.AllMethodsInType
                        ? BenchmarkConverter.TypeToBenchmarks(typeWithMethods.Type, effectiveConfig)
                        : BenchmarkConverter.MethodsToBenchmarks(typeWithMethods.Type, typeWithMethods.Methods, effectiveConfig)).ToArray();
                summaries.Add(BenchmarkRunner.Run(benchmarks, effectiveConfig));
            }
            else
            {
                foreach (var typeWithMethods in typeParser.MatchingTypesWithMethods(args))
                {
                    logger.WriteLineHeader("Target type: " + typeWithMethods.Type.Name);
                    if (typeWithMethods.AllMethodsInType)
                    {
                        summaries.Add(BenchmarkRunner.Run(typeWithMethods.Type, effectiveConfig));
                    }
                    else
                    {
                        summaries.Add(BenchmarkRunner.Run(typeWithMethods.Type, typeWithMethods.Methods, effectiveConfig));
                    }
                    logger.WriteLine();
                }
            }

            // TODO: move this logic to the RunUrl method
#if CLASSIC
            if (args.Length > 0 && (args[0].StartsWith("http://") || args[0].StartsWith("https://")))
            {
                var url  = args[0];
                Uri uri  = new Uri(url);
                var name = uri.IsFile ? Path.GetFileName(uri.LocalPath) : "URL";
                summaries.Add(BenchmarkRunner.RunUrl(url, effectiveConfig));
            }
#endif

            var clockSpan = globalChronometer.Stop();
            BenchmarkRunnerCore.LogTotalTime(logger, clockSpan.GetTimeSpan(), "Global total time");
            return(summaries);
        }
Esempio n. 29
0
    public void OnReachTimeGoal()
    {
        newEnemyTimer = new Chronometer(GetRandomTimeByDifficulty(), this);

        if (raffleEnemies)
        {
            InitializeEnemies();
        }

        newEnemyTimer.Start();
    }
Esempio n. 30
0
 public void TestSplit()
 {
     Chronometer chrono = new Chronometer();
     chrono.Start();
     Thread.Sleep(100);
     Assert.Greater((int)chrono.GetSplit().Ticks, 920000,
         "Chrono is running slow.");
     Thread.Sleep(100);
     int ticks = (int)chrono.GetSplit().Ticks;
     Assert.Greater(ticks, 920000, "Chrono is running slow second time.");
 }
Esempio n. 31
0
        public async Task <Chronometer> GetChronometer(int id = 0)
        {
            if (id == 0)
            {
                id = (await this.heroService.GetHero()).ChronometerId;
            }

            Chronometer chronometer = await this.context.Chronometers.FindAsync(id);

            return(chronometer);
        }
Esempio n. 32
0
 public void TestReset()
 {
     Chronometer chrono = new Chronometer();
     chrono.Start();
     Thread.Sleep(100);
     Assert.Greater((int)chrono.GetSplit().Ticks, 920000,
         "Chrono is running slow.");
     chrono.Reset();
     Thread.Sleep(50);
     TimeSpan split = chrono.GetSplit();
     Assert.Greater((int)split.Ticks, 430000, "Chrono is running slow after reset.");
 }
Esempio n. 33
0
 public void TestSplitMS()
 {
     Chronometer chrono = new Chronometer();
     chrono.Start();
     Thread.Sleep(100);
     Assert.Greater(Convert.ToDouble(chrono.GetSplitMilliseconds().Split(' ')[0]), 92.0,
         "Chrono is running slow.");
 }