Пример #1
0
        public override void HandleCommand(String[] words)
        {
            if (MyAPIGateway.Multiplayer.MultiplayerActive && !MyAPIGateway.Multiplayer.IsServer)
            {
                Communication.Message("Unable to manually sort in multiplayer.  Sort set to 30 second intervals.");
                return;
            }

            Communication.Message("Starting manual sort ...");
            DateTime start = DateTime.Now;

            CubeGridTracker.TriggerRebuild();
            Inventory.TriggerRebuild();
            Conveyor.TriggerRebuild();
            //Inventory.SortInventory();
            Inventory.NewSortInventory();
            Inventory.ProcessQueue();
            Communication.Message(String.Format("Manual sort completed in {0}ms", (DateTime.Now - start).TotalMilliseconds));
        }
Пример #2
0
        /// <summary>
        /// In order to try to stop from causing the game thread to pause on large sorts, we are going to use a Timer as a ThreadPool.  This may be
        /// extremely unsafe, but the entire sort mostly consists of reads, and any issue on read should safely exception and our state will be
        /// stable as we're just queuing "writes" for the game thread.  If this causes a lot of issues, I'll easily move it all back into the game
        /// thread, but I'd like to see this work.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimerElapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                if (!Inventory.QueueReady)
                {
                    m_sortTimer.Enabled = false;

                    if (Settings.Instance.Enabled)
                    {
                        //if (DateTime.Now - CubeGridTracker.LastRebuild > TimeSpan.FromSeconds(60))
                        CubeGridTracker.TriggerRebuild();

                        // This will need to rebuild every update for now since CustomNameChanged event is
                        // bugged.  This should increase performance once fixed.
                        //if (DateTime.Now - Inventory.LastRebuild > TimeSpan.FromSeconds(30))
                        //if (DateTime.Now - Inventory.LastRebuild > TimeSpan.FromSeconds(2))
                        Inventory.TriggerRebuild();

                        //if (DateTime.Now - Conveyor.LastRebuild > TimeSpan.FromSeconds(30))
                        Conveyor.TriggerRebuild();

                        // No longer sort on the client if we're in multiplayer.
                        if (MyAPIGateway.Multiplayer.MultiplayerActive && !MyAPIGateway.Multiplayer.IsServer)
                        {
                            return;
                        }

                        if (MyAPIGateway.Multiplayer.MultiplayerActive && MyAPIGateway.Multiplayer.IsServer)
                        {
                            /*
                             * List<IMyPlayer> players = new List<IMyPlayer>();
                             * MyAPIGateway.Multiplayer.Players.GetPlayers(players);
                             *
                             * foreach(var item in players)
                             * {
                             *  Inventory.SortInventory(item.PlayerID);
                             * }
                             */

                            Inventory.NewSortInventory();
                        }
                        else
                        {
                            Inventory.NewSortInventory();
                        }

                        //Inventory.SortInventory();
                    }
                }
            }
            finally
            {
                int intervalTime = 2;
                if (MyAPIGateway.Multiplayer.MultiplayerActive)
                {
                    intervalTime = Math.Max(30, Settings.Instance.Interval);
                }
                else
                {
                    intervalTime = Math.Max(2, Settings.Instance.Interval);
                }

                m_sortTimer.Interval = intervalTime * 1000;
                m_sortTimer.Enabled  = true;
            }
        }