コード例 #1
0
ファイル: SimulationApp.cs プロジェクト: allisterb/WolfCurses
        public virtual void OnTick(bool systemTick, bool skipDay = false)
        {
            // No ticks allowed if simulation is shutting down.
            if (IsClosing)
            {
                return;
            }

            // Sends commands if queue has any.
            InputManager?.OnTick(systemTick, skipDay);

            // Back buffer for only sending text when changed.
            SceneGraph?.OnTick(systemTick, skipDay);

            // Changes game Windows and state when needed.
            WindowManager?.OnTick(systemTick, skipDay);

            // Rolls virtual dice.
            Random?.OnTick(systemTick, skipDay);

            // System tick is from execution platform, otherwise they are linear simulation ticks.
            if (systemTick)
            {
                _currentTickTime = DateTime.UtcNow;
                var elapsedTicks = _currentTickTime.Ticks - _lastTickTime.Ticks;
                var elapsedSpan  = new TimeSpan(elapsedTicks);

                // Check if more than an entire second has gone by.
                if (!(elapsedSpan.TotalMilliseconds > TICK_INTERVAL))
                {
                    return;
                }

                // Reset last tick time to current time for measuring towards next second tick.
                _lastTickTime = _currentTickTime;

                // Recursive call on ourselves to process non-system ticks.
                OnTick(false, skipDay);
            }
            else
            {
                // Increase the total seconds ticked.
                TotalSecondsTicked++;

                // Fire event for first tick when it occurs, and only then.
                if (TotalSecondsTicked == 1)
                {
                    OnFirstTick();
                }

                // Visual representation of ticking for debugging purposes.
                TickPhase = _spinningPixel.Step();
            }
        }
コード例 #2
0
ファイル: SimulationApp.cs プロジェクト: allisterb/WolfCurses
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:TrailGame.SimulationApp" /> class.
        /// </summary>
        protected SimulationApp()
        {
            // We are not closing...
            IsClosing = false;

            // Date and time the simulation was started, which we use as benchmark for all future time passed.
            _lastTickTime    = DateTime.UtcNow;
            _currentTickTime = DateTime.UtcNow;

            // Visual tick representations for other sub-systems.
            TotalSecondsTicked = 0;

            // Setup spinning pixel to show game is not thread locked.
            _spinningPixel = new SpinningPixel();
            TickPhase      = _spinningPixel.Step();

            // Create modules needed for managing simulation.
            Random        = new Randomizer();
            WindowManager = new WindowManager(this);
            SceneGraph    = new SceneGraph(this);

            // Input manager needs event hook for knowing when buffer is sent.
            InputManager = new InputManager(this);
        }