//--- Class Constructors ---
        static DispatchThreadScheduler()
        {
            // initialize performance counter to read how busy the CPU is
            try {
                _cpus = new PerformanceCounter("Processor", "% Processor Time", "_Total");
                _cpus.NextValue();
            } catch (Exception e) {
                _log.Warn("Unable to read the performance counter Processor/% Processor Time. Likely cause is a corrupted counter. This can be fixed by running 'lodctr /r'. Please refer to http://technet.microsoft.com/en-us/library/bb490926.aspx before attempting this fix", e);
                _cpus = null;
            }

            // read system wide settings
            _threadReserveCount    = ReadAppSetting("reserved-dispatch-threads", 20);
            _minThreadReserveCount = ReadAppSetting("min-reserved-dispatch-threads", _threadReserveCount / 2);

            // TODO (steveb): we should base this on available memory (e.g. total_memory / 2 / 1MB_stack_size_per_thread)
            _maxThreads = ReadAppSetting("max-dispatch-threads", 1000);


            // add maintenance callback
            GlobalClock.AddCallback("DispatchThreadScheduler", Tick);

            // add initial reserve of threads
            CreateThreads(Math.Min(_threadReserveCount, _maxThreads));
        }
        static void Main(string[] args)
        {
            SetupConstants();
            Initializer();

            GlobalClock.GetInstance().Start(1, noOfStations);

            Console.Read();
        }
示例#3
0
 void Awake()
 {
     if (INSTANCE == null)
     {
         INSTANCE = this;
     }
     else
     {
         if (INSTANCE != this)
         {
             Destroy(this);
         }
     }
 }
示例#4
0
        /// <summary>
        /// Shut down all timers related to this factory.
        /// </summary>
        /// <remarks>
        /// Warning: this call is thread-blocking. It will try to execute all pending timers immediately, but
        /// will wait for each timer to complete.
        /// </remarks>
        public void Shutdown()
        {
            lock (_factories) {
                _factories.Remove(this);
            }
            List <KeyValuePair <TaskTimer, TaskEnv> > timers = null;

            // stop the thread timer
            _shutdown = true;
            GlobalClock.RemoveCallback(Tick);
            _owner.Target = null;

            // schedule all queued items for immediate execution
            // Note (arnec): should run the below in a helper so we can respect the timeout on this part as well
            //               (or maybe this should just be part of the thread clean-up)
            lock (_queue) {
                while (_queue.Count > 0)
                {
                    TaskTimer timer = _queue.Dequeue();
                    if (timer.TryLockPending())
                    {
                        // retrieve the associated behavior and reset the timer
                        TaskEnv env = timer.Env;
                        timer.Env = null;
                        timer.SetStatus(TaskTimerStatus.Done);

                        // add timer
                        timers = timers ?? new List <KeyValuePair <TaskTimer, TaskEnv> >();
                        timers.Add(new KeyValuePair <TaskTimer, TaskEnv>(timer, env));
                    }
                }
            }

            // BUGBUGBUG (arnec): we don't actually do anything with timeout, but let every timer take
            // an indefinite time.
            // check if any timers were gathered for immediate execution
            if (timers != null)
            {
                foreach (KeyValuePair <TaskTimer, TaskEnv> entry in timers)
                {
                    entry.Key.Execute(entry.Value);
                }
            }

            _running = false;
        }
示例#5
0
 private void btnStartSimulator_Click(object sender, EventArgs e)
 {
     try
     {
         if (btnSaveSetting.Enabled)
         {
             btnSaveSetting.Enabled = false;
             StartSimulator();
         }
         GlobalClock.GetInstance().Start(_timer, _noOfStations);
         btnStartSimulator.Enabled = false;
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message);
     }
 }
示例#6
0
 private void CleanUp()
 {
     try
     {
         StationShipmentHandler.ShipmentQueuedAtStation  -= UpdateShipmentQueuingAtStation;
         TrainSystemSimulator.TrainProgressEvent         -= UpdateTrackIdWithTrainProgress;
         TrainSystemSimulator.TrainShipmentLoadEvent     -= UpdateShipmentLoadedIntoTrainProgress;
         TrainSystemSimulator.TrainShipmentUnloadEvent   -= UpdateShipmentUnloadedFromTrainProgress;
         TrainSystemSimulator.TrainArrivedAtStationEvent -= UpdateTrainArrivalAtUI;
         TrainSystemSimulator.TrainOtherEvent            -= UpdateTrainOtherEventsAtUI;
         Station.ShipmentDequeuedFromStation             -= UpdateShipmentDequeueFromStation;
         TrainSystemSimulator.GetInstance().CleanUp();
         StationShipmentHandler.GetInstance().CleanUp();
         GlobalClock.GetInstance().Cleanup();
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message);
     }
 }
示例#7
0
        private void init()
        {
            setupSFML();

            appTimer = new Utilities.Timer();
            //ChangeGameState( new cGameScene(this) );


            //Idő szöveg
            timeText               = new Text("", AssetManager.GetFont("pf_tempesta_seven"));
            timeText.Position      = new Vector2f(this.defaultView.Size.X - 500, 30);
            timeText.CharacterSize = 28; // in pixels, not points!
            timeText.FillColor     = Color.White;
            timeText.Style         = Text.Styles.Bold;

            GlobalClock.Start();

            game.Init();

            appRunning = true;
        }
示例#8
0
        private void _init()
        {
            _setUpSFML();

            //resource-ok betöltése (font-ok és textúrák, képek a játékhoz)
            appAssets.LoadResources(Constants.FONT_NAMES);

            m_DeltaTime    = 0.0;
            m_StepTime     = 1.0 / 60.0;
            m_MaxDeltaTime = 0.25; //0.25f
            m_Accumulator  = 0.0;
            m_Time         = 0.0;
            m_FPS          = 0.0;

            m_Timer = new AppTimer();
            //ChangeGameState( new GameScene(this) );

            fpsUpdater = new cRegulator();
            fpsUpdater.resetByPeriodTime(1.0f);


            //Idő szöveg
            timeText               = new Text("", appAssets.GetFont("pf_tempesta_seven"));
            timeText.Position      = new Vector2f(this.defaultView.Size.X - 500, 30);
            timeText.CharacterSize = 28; // in pixels, not points!
            timeText.FillColor     = Color.White;
            timeText.Style         = Text.Styles.Bold;

            GlobalClock.Start();

            // currentState = new GameScene(this);
            // currentState.Enter();

            m_AppRunning = true;

            definiedStates.Add("main-menu", () => { this.SetGameState(new MainMenu(this)); });
            definiedStates.Add("game-scene", () => { this.SetGameState(new GameScene(this)); });

            this.ChangeGameState("main-menu");
        }
示例#9
0
 private TaskTimerFactory(object owner)
 {
     _owner     = new WeakReference(owner);
     _ownerType = owner.GetType();
     GlobalClock.AddCallback("TaskTimerFactory", Tick);
 }
示例#10
0
 //--- Constructors ---
 private TaskTimerFactory()
 {
     _owner     = new WeakReference(this);
     _ownerType = GetType();
     GlobalClock.AddCallback("TaskTimerFactory", Tick);
 }
示例#11
0
 private void Awake()
 {
     m_timeline    = GetComponent <Timeline>();
     m_globalClock = GetComponentInChildren <GlobalClock>();
 }
示例#12
0
 // Start is called before the first frame update
 void Start()
 {
     globalClock = GameObject.Find("Timekeeper").GetComponent <GlobalClock>();
 }