Пример #1
0
 public StreamManager(Connection serverConnection, TcpClient streamClient)
 {
     connection         = serverConnection;
     updateThreadObject = new UpdateThread(this, streamClient);
     updateThread       = new Thread(new ThreadStart(updateThreadObject.Main));
     updateThread.Start();
 }
Пример #2
0
        private void Start()
        {
            UpdateThread Updater = new UpdateThread();

            Thread UpdateThread = new Thread(new ThreadStart(Updater.Start));

            UpdateThread.IsBackground = true;
            UpdateThread.Start();

            // Setup ping timer/initial values
            PingTimer.Elapsed += new ElapsedEventHandler(Ping);
            PingTimer.Interval = 10000;
            PingTimer.Enabled  = false;

            Ping_Seq = 1;
            Latency  = 1;

            // Fire up pather

            pather = new Pather.PPather();

            pather.OnStartGlide();


            // Loopdeloop

            Loop();

            // Thread is dead if it gets to this point
            UpdateThread.Abort();


            pather.OnStopGlide();
            pather = null;
        }
Пример #3
0
        public bool UpdateThread(UpdateThread model)
        {
            try
            {
                using (var ctx = new ApplicationDbContext())
                {
                    var entity =
                        ctx
                        .Threads
                        .SingleOrDefault(e => e.Id == model.Id && e.OwnerId == _userId);

                    entity.Name = model.Name;

                    return(ctx.SaveChanges() == 1);
                }
            }
            catch (NullReferenceException)
            {
                return(false);
            }
            catch (ArgumentNullException)
            {
                return(false);
            }
        }
Пример #4
0
        public void Tick(float dtime)
        {
            if (ogg == null)
            {
                return;
            }

            if (Root.Instance.Time - Id.LastBind > 5)
            {
                if (!Idle)
                {
                    Cheetah.Console.WriteLine("suspending video thread.");
                    UpdateThread.Suspend();
                    Idle = true;
                }
            }
            else
            {
                if (Idle)
                {
                    Cheetah.Console.WriteLine("resuming video thread.");
                    UpdateThread.Resume();
                    Idle = false;
                }
                Time += dtime;
                UpdateSurface();
            }
        }
Пример #5
0
 public StreamManager (Connection serverConnection, TcpClient streamClient)
 {
     connection = serverConnection;
     updateThreadObject = new UpdateThread (this, streamClient);
     updateThread = new Thread (new ThreadStart (updateThreadObject.Main));
     updateThread.Start ();
 }
Пример #6
0
        public AudioSession[] GetAudioSessions()
        {
            if (Disposed)
            {
                throw new ObjectDisposedException(nameof(MixerWatcher));
            }

            lock (_disposeLock)
            {
                // Need to be disposed before enumerating again. The order matters.
                _currentSessionEnumerator?.Dispose();
                _currentSessionManager?.Dispose();

                var results = new List <AudioSession>();

                UpdateThread.RunSynchronizedAction(() =>
                {
                    _currentSessionManager    = GetDefaultAudioSessionManager2(DataFlow.Render);
                    _currentSessionEnumerator = _currentSessionManager.GetSessionEnumerator();
                    ProcessBuffer             = Process.GetProcesses();

                    results.AddRange(_currentSessionEnumerator
                                     .Select(x => new AudioSession(x, UpdateThread))
                                     .Where(x => x.CheckSessionIsValid()));
                });

                return(results.ToArray());
            }
        }
Пример #7
0
        /// <summary>
        /// Dispose of the audio manager and frees its audio memory.
        /// </summary>
        public void Dispose()
        {
            try
            {
                RunUpdates = false;
                UpdateThread.Join();
            }
            catch (Exception e)
            { }

            try
            {
                foreach (AudioChannel channel in Channels)
                {
                    try
                    {
                        channel.Dispose();
                    }
                    catch (Exception e1)
                    { }
                }
            }
            catch (Exception e2)
            { }
        }
Пример #8
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            PortValue.Text = Mission.port.ToString();
            IPValue.Text   = Mission.IP;
            bool existed = MissionLocalyExist(Mission.name);

            DatabaseConnector.InitDatabase(@"data\" + Mission.name + ".db");
            timer1.Enabled        = true;
            updateThread          = new UpdateThread();
            MissionNameLabel.Text = Mission.name;
            remebered             = 0;
            if (!existed)
            {
                DatabaseConnector.Query("create table tmp1 (time real, value real)");
                DatabaseConnector.Query("INSERT INTO tmp1 (time, value) VALUES(0,0)");
                DatabaseConnector.Query("create table tmp2 (time real, value real)");
                DatabaseConnector.Query("INSERT INTO tmp2 (time, value) VALUES(0,0)");
                DatabaseConnector.Query("create table press1 (time real, value real)");
                DatabaseConnector.Query("INSERT INTO press1 (time, value) VALUES(0,0)");
                DatabaseConnector.Query("create table press2 (time real, value real)");
                DatabaseConnector.Query("INSERT INTO press2 (time, value) VALUES(0,0)");
                DatabaseConnector.Query("create table gyrox (time real, value real)");
                DatabaseConnector.Query("INSERT INTO gyrox (time, value) VALUES(0,0)");
                DatabaseConnector.Query("create table gyroy (time real, value real)");
                DatabaseConnector.Query("INSERT INTO gyroy (time, value) VALUES(0,0)");
                DatabaseConnector.Query("create table gyroz (time real, value real)");
                DatabaseConnector.Query("INSERT INTO gyroz (time, value) VALUES(0,0)");
                DatabaseConnector.Query("create table Logs (time real, value text)");
                DatabaseConnector.Query("INSERT INTO Logs (time, value) VALUES(0,'0')");
            }
            threads.Add(new Thread(new ThreadStart(updateThread.Run)));
            threads[iterator].Start();
        }
        public override void RunUpdateThread()
        {
            // TODO:  Establish the updating that is required by a reversi game server...
            // 1. Check for empty (but started) games
            // 2. If one player missing...pause game and notify other user
            //      a.  Allow a new player to take over
            // 3. If both players missing... close the gamee?



            Console.WriteLine("- Update thread for server " + Id + " created");
            while (!ShouldShutdown)
            {
                // If we have clients currently connected, check for updates
                if (ConnectedClientModelList.Count > 0)
                {
                    Console.WriteLine("Updating server " + Id);
                    this.Update();
                }

                // Cause the the update thread to sleep for a specified duration
                Thread.Sleep(ServerSettings.ServerUpdatePulseDelay);
            }

            // End the running thread

            UpdateThread.Join();
        }
Пример #10
0
 public override void Unload()
 {
     ThreadRunning = false;
     if (CanInterrupt)
     {
         UpdateThread.Interrupt();
     }
     base.Unload();
 }
Пример #11
0
    //--------------------------------------------------------------------------------------------------------------------------
    // Monobehaviour

    #region Monobehaviour

    // Use this for initialization
    protected virtual void Start()
    {
        instance = this;
        this.CheckForDeviceManager();
        UpdateThread updateThread = new UpdateThread(solver, limitFingers, updateWrist);
        Thread       t            = new Thread(new ThreadStart(updateThread.ThreadProc));

        t.Start();
    }
Пример #12
0
 protected void StopThread()
 {
     ExitThread = true;
     if (Idle)
     {
         UpdateThread.Resume();
     }
     System.Console.WriteLine("stopping video update thread...");
     UpdateThread.Join();
     System.Console.WriteLine("video update thread ended.");
 }
Пример #13
0
        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (UpdateThread != null)
            {
                UpdateThread.Abort();
            }

            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
Пример #14
0
        public void ApplicationPause()
        {
            state = States.PAUSED;
            if (SyncUpdate)
            {
                UpdateThread.Stop();
                NeuralThread.Stop();
            }

            running = false;

            VisualThread.Stop();
        }
Пример #15
0
        public virtual void TestStressDeleteQueue()
        {
            DocumentsWriterDeleteQueue queue = new DocumentsWriterDeleteQueue();
            ISet <Term> uniqueValues         = new JCG.HashSet <Term>();
            int         size = 10000 + Random.Next(500) * RANDOM_MULTIPLIER;

            int?[] ids = new int?[size];
            for (int i = 0; i < ids.Length; i++)
            {
                ids[i] = Random.Next();
                uniqueValues.Add(new Term("id", ids[i].ToString()));
            }
            CountdownEvent latch      = new CountdownEvent(1);
            AtomicInt32    index      = new AtomicInt32(0);
            int            numThreads = 2 + Random.Next(5);

            UpdateThread[] threads = new UpdateThread[numThreads];
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new UpdateThread(queue, index, ids, latch);
                threads[i].Start();
            }
            latch.Signal();
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Join();
            }

            foreach (UpdateThread updateThread in threads)
            {
                DeleteSlice slice = updateThread.Slice;
                queue.UpdateSlice(slice);
                BufferedUpdates deletes = updateThread.Deletes;
                slice.Apply(deletes, BufferedUpdates.MAX_INT32);
                assertEquals(uniqueValues, new JCG.HashSet <Term>(deletes.terms.Keys));
            }
            queue.TryApplyGlobalSlice();
            ISet <Term> frozenSet = new JCG.HashSet <Term>();

            foreach (Term t in queue.FreezeGlobalBuffer(null).GetTermsEnumerable())
            {
                BytesRef bytesRef = new BytesRef();
                bytesRef.CopyBytes(t.Bytes);
                frozenSet.Add(new Term(t.Field, bytesRef));
            }
            Assert.AreEqual(0, queue.NumGlobalTermDeletes, "num deletes must be 0 after freeze");
            Assert.AreEqual(uniqueValues.Count, frozenSet.Count);
            assertEquals(uniqueValues, frozenSet);
        }
Пример #16
0
        public override void SetUp()
        {
            storage = new TemporaryNativeStorage("realm-benchmark");
            storage.DeleteDirectory(string.Empty);

            realm = new RealmAccess(storage, "client");

            realm.Run(r =>
            {
                realm.Write(c => c.Add(TestResources.CreateTestBeatmapSetInfo(rulesets: new[] { new OsuRuleset().RulesetInfo })));
            });

            updateThread = new UpdateThread(() => { }, null);
            updateThread.Start();
        }
Пример #17
0
        public void Init(LaunchState state, InitialiseSettings settings)
        {
            LaunchState = state;
            Settings    = settings;
            ActiveWorld = new World();

            Settings.Context.MakeCurrent(null);
            SystemManager.LoadSystems(new CoreSystemLoader());
            EntityManager.RegisterSystem(Renderer);

            SystemManager.InitialiseSystems(EntityManager, EventManager, ResourceManager, ActiveWorld);

            UpdateThread.Start();
            RenderThread.Start();
        }
Пример #18
0
 public static void Check()
 {
     Process[] UcsOpen = Process.GetProcessesByName("UCS.exe");
     if (UcsOpen.Length != 0)
     {
         foreach (var Process in Process.GetProcessesByName("UCS.exe"))
         {
             Process.Kill();
         }
         UpdateThread.Start();
     }
     else if (UcsOpen.Length == 0)
     {
         UpdateThread.Start();
     }
 }
Пример #19
0
        public void Dispose()
        {
            if (Disposed)
            {
                return;
            }

            lock (_disposeLock)
            {
                Disposed = true;

                _currentSessionEnumerator?.Dispose();
                _currentSessionManager?.Dispose();
                UpdateThread.Dispose();
            }
        }
Пример #20
0
        // This class is a simple launcher for your actual code in PluginCode.cs
        //
        // We make use of non-volatile data and threading to let your work run in another
        // thread, making Rainmeter nice and responsive.  Checks are automatically performed
        // so that overlapping of execution does not occur.

        // Default values of a blank string for GetUpdate() and zero for Update()/Update2()
        // are returned.

        public UInt32 Update(Rainmeter.Settings Plugin, UInt32 id)
        {
            bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_U_AlreadyRunning", false);

            if (!bAlreadyRunning)
            {
                UpdateThread thread_details = new UpdateThread(Plugin.Instances[id]);
                Thread       thread         = new Thread(new ThreadStart(thread_details.Go));
                thread.Start();
            }

            try
            {
                return((UInt32)Plugin.Instances[id].GetTempValue("__RMT_U_LastValue", 0));
            }
            catch
            {
                return(0);
            }
        }
Пример #21
0
        public IHttpActionResult Put(UpdateThread thread)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateThreadService();

            if (service == null)
            {
                return(BadRequest());
            }

            if (!service.UpdateThread(thread))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Пример #22
0
 public RealTimeMultipleSensorPlayer(IClock timeProvider)
 {
     _timeProvider = timeProvider;
     _updateThread = new UpdateThread(this);
 }
Пример #23
0
 public void Exit()
 {
     UpdateThread.Exit();
     RenderThread.Exit();
     SystemManager.ExitSystems();
 }
Пример #24
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (null == _item)
            {
                return;
            }
            _listSampleNum     = new List <TextBox>();
            _listJudgmentReult = new List <TextBox>();
            _listStandardValue = new List <TextBox>();
            _listtextNongdu    = new List <TextBox>();

            int sampleNum = _item.SampleNum;
            int holeUse   = 0;

            // 添加布局
            for (int i = 0; i < Global.deviceHole.HmCount; ++i)
            {
                UIElement element = GenerateChannelLayout(i, String.Format("{0:D5}", sampleNum), _item.Hole[i].SampleName);
                WrapPanelChannel.Children.Add(element);
                if (_item.Hole[i].Use)
                {
                    holeUse += 1;
                    sampleNum++;
                    _listSampleNum.Add(UIUtils.GetChildObject <TextBox>(element, "sampleNum"));
                    _listJudgmentReult.Add(UIUtils.GetChildObject <TextBox>(element, "textJugmentResult"));
                    _listStandardValue.Add(UIUtils.GetChildObject <TextBox>(element, "textStandValue"));
                    _listtextNongdu.Add(UIUtils.GetChildObject <TextBox>(element, "textNongdu"));
                }
                else
                {
                    element.Visibility = System.Windows.Visibility.Collapsed;
                    _listSampleNum.Add(null);
                    _listJudgmentReult.Add(null);
                    _listStandardValue.Add(null);
                    _listtextNongdu.Add(null);
                }
            }

            if (holeUse < 4)
            {
                if (holeUse == 1)
                {
                    this.WrapPanelChannel.Width = 190;
                }
                else if (holeUse == 2)
                {
                    this.WrapPanelChannel.Width = 380;
                }
                else if (holeUse == 3)
                {
                    this.WrapPanelChannel.Width = 570;
                }
            }

            _canvases    = UIUtils.GetChildObjects <Canvas>(WrapPanelChannel, "rootCanvas");
            _listTime    = UIUtils.GetChildObjects <Label>(WrapPanelChannel, "labelTime");
            _listUA      = UIUtils.GetChildObjects <Label>(WrapPanelChannel, "labelUA");
            _listMV      = UIUtils.GetChildObjects <Label>(WrapPanelChannel, "labelMV");
            _listStage   = UIUtils.GetChildObjects <Label>(WrapPanelChannel, "labelStage");
            _listDensity = UIUtils.GetChildObjects <Label>(WrapPanelChannel, "labelDensity");

            _updateThread = new UpdateThread(this);
            _updateThread.Start();

            if (Global.typeName.Equals("dhx"))
            {
                lbTitle.Content = "电化学检测";
            }
        }
Пример #25
0
        private void window_keydown(object sender, KeyEventArgs e)
        {
            if (keydown.Contains(e.KeyCode) || e.KeyCode == Keys.NumLock || e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.Menu)
            {
                return;
            }
            else
            {
                keydown.Add(e.KeyCode);
            }

            Keys ekey = e.KeyCode;

            if (e.KeyCode == Keys.Delete)
            {
                ekey = Keys.Decimal;
            }
            else if (e.KeyCode == Keys.Insert)
            {
                ekey = Keys.NumPad0;
            }
            else if (e.KeyCode == Keys.Clear)
            {
                ekey = Keys.NumPad5;
            }

            else if (e.KeyCode == Keys.F2)
            {
                ContrastMode = !ContrastMode;
                return;
            }
            else if (e.KeyCode == Keys.F3)
            {
                if (state == States.NEWGAME && Neat.All.Count < 24)
                {
                    OpenFileDialog dialog = new OpenFileDialog();
                    dialog.Filter           = "Bot files (*.bot)|*.bot|All files (*.*)|*.*";
                    dialog.RestoreDirectory = true;

                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        List <byte> bytes = new List <byte>(File.ReadAllBytes(dialog.FileName));
                        Neat.remove(bytes, 8);

                        Neat n = Neat.decompile(bytes);
                        n.SetupGenZero();
                        n.AddKey();

                        IKey.UpdateAll();
                        Map.SetMaxPoints();

                        // Set color
                        Program.HEADS[n.Key].color = n.color.GetValueOrDefault(Entities.Head.GenerateColor());
                    }
                }
                return;
            }
            else if (e.KeyCode == Keys.F1)
            {
                if (state != States.NEWGAME)
                {
                    return;
                }
                if (ActiveKeys.Count > 0)
                {
                    new AI(ActiveKeys[ActiveKeys.Count - 1]);
                    MVP.Flash($"AI added to {HEADS[ActiveKeys[ActiveKeys.Count - 1]].DisplayKey}");
                    HEADS[ActiveKeys[ActiveKeys.Count - 1]].DisplayKey = "AI";
                }
                return;
            }
            else if (e.KeyCode == Keys.F4 && !e.Alt)
            {
                if (state == States.NEWGAME)
                {
                    if (Neat.All.Count > 0)
                    {
                        Neat toRemove = Neat.All.Last();
                        toRemove.Remove();
                        IKey.UpdateAll();
                    }
                    Map.SetMaxPoints();
                }
                return;
            }
            else if (e.KeyCode == Keys.F9 && e.Alt)
            {
                if (ActiveKeys.Count == 0 || InactiveKeys.Count == 0)
                {
                    return;
                }

                HEADS[InactiveKeys[0]].Reward(0, ActiveKeys[0]);
                HEADS[ActiveKeys[0]].Die();
                return;
            }
            else if (e.KeyCode == Keys.F10)
            {
                if (SyncUpdate)
                {
                    SyncUpdate = false;
                    UpdateThread.Stop();
                    NeuralThread.Stop();
                    StartAsyncUpdate();
                }
                else
                {
                    SyncUpdate = true;
                    UpdateThread.Start();
                    NeuralThread.Start();
                }
                return;
            }
            else if (e.KeyCode == Keys.F7)
            {
                SlowMo = true;
                return;
            }
            else if (e.KeyCode == Keys.F8)
            {
                SpeedMo = true;
                return;
            }
            else if (e.KeyCode == Keys.F11)
            {
                FullScreen = !FullScreen;
                if (FullScreen)
                {
                    Width           = Screen.PrimaryScreen.Bounds.Width;
                    FormBorderStyle = FormBorderStyle.None;
                    WindowState     = FormWindowState.Maximized;
                    Cursor.Hide();
                }
                else
                {
                    Width           = 1024;
                    Height          = 600;
                    FormBorderStyle = FormBorderStyle.Sizable;
                    WindowState     = FormWindowState.Normal;
                    Cursor.Show();
                }
                return;
            }

            else if (e.KeyCode == Keys.F12)
            {
                if (!e.Alt)
                {
                    if (map is BotArena)
                    {
                        List <byte> bytes = new List <byte>();
                        bytes.AddRange(((BotArena)map).GetGeneration());
                        foreach (Neat bot in ((BotArena)map).bots)
                        {
                            bytes.AddRange(Neat.compile(bot));
                        }

                        SaveFileDialog dialog = new SaveFileDialog();
                        dialog.Filter           = "Bot files (*.bot)|*.bot|All files (*.*)|*.*";
                        dialog.RestoreDirectory = true;

                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            File.WriteAllBytes(dialog.FileName, bytes.ToArray());
                        }
                    }
                    else if (ActiveKeys.Count == 0)
                    {
                        Cursor.Show();
                        OpenFileDialog dialog = new OpenFileDialog();
                        dialog.Filter           = "Bot files (*.bot)|*.bot|All files (*.*)|*.*";
                        dialog.RestoreDirectory = true;

                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            List <byte> bytes = new List <byte>(File.ReadAllBytes(dialog.FileName));

                            BotArena arena = new BotArena(BotArena.Type.MAX_POINTS);
                            arena.SetGeneration(bytes);
                            map = arena;

                            while (bytes.Count > 0)
                            {
                                arena.bots.Add(Neat.decompile(bytes));
                            }

                            arena.AddBots(false);
                            Map.StartGame();

                            Ingame = true;
                            state  = States.INGAME;
                        }
                        if (FullScreen)
                        {
                            Cursor.Hide();
                        }
                    }
                }
                else if (state == States.NEWGAME && !TutorialActive)
                {
                    if (ActiveKeys.Count != 1)
                    {
                        return;
                    }
                    TUTO           = new Tutorial(Map);
                    TutorialActive = true;
                    Map.StartGame();
                    if (SyncUpdate)
                    {
                        NeuralThread.Start();
                    }
                }
                return;
                // trigger tutorial
            }
            else if (e.KeyCode == Keys.F6)
            {
                if (ActiveKeys.Count != 0)
                {
                    return;
                }

                BotArena arena = new BotArena(7, BotArena.Type.MAX_POINTS);                 /// <   -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

                map = arena;
                arena.AddBots(false);
                Map.StartGame();

                Ingame = true;
                state  = States.INGAME;

                return;
                // trigger bot arena
            }
            else if (e.KeyCode == Keys.F5)
            {
                if (state != States.NEWGAME)
                {
                    return;
                }
                switch (Gamemode)
                {
                case Gamemodes.CLASSIC:
                    MVP.SetText("Red chaos");
                    Gamemode = Gamemodes.CHAOS_RED;
                    foreach (Head head in HEADS.Values)
                    {
                        head.NewColor(true);
                    }
                    break;

                case Gamemodes.CHAOS_RED:
                    MVP.SetText("Rainbow chaos");
                    Gamemode = Gamemodes.CHAOS_RAINBOW;
                    foreach (Head head in HEADS.Values)
                    {
                        head.NewColor();
                    }
                    break;

                case Gamemodes.CHAOS_RAINBOW:
                    MVP.SetText("King of the hill");
                    foreach (Head head in HEADS.Values)
                    {
                        head.NewColor(false);
                    }
                    Map.MaxOrbs = 7;
                    Gamemode    = Gamemodes.KING_OF_THE_HILL;
                    break;

                case Gamemodes.KING_OF_THE_HILL:
                    MVP.SetText("Hidden");
                    Map.MaxOrbs = 8;
                    Gamemode    = Gamemodes.HIDDEN;
                    break;

                case Gamemodes.HIDDEN:
                    MVP.SetText("Yeet Mode");
                    Gamemode       = Gamemodes.YEET_MODE;
                    Map.blastSpawn = BlastSpawn.RARE;
                    break;

                case Gamemodes.YEET_MODE:
                    MVP.SetText("Classic");
                    Map.MaxOrbs = 255;
                    Gamemode    = Gamemodes.CLASSIC;
                    break;
                }

                UpdateColors?.Invoke();
                return;
            }

            switch (state)
            {
            case States.NEWGAME:
                //add new player
                if (e.KeyCode == Keys.Enter && ActiveKeys.Count > 0)                           // (re)start game
                {
                    if (e.Shift)
                    {
                        Map.ResumeGame();
                    }
                    else
                    {
                        Map.StartGame();
                    }
                    if (SyncUpdate)
                    {
                        NeuralThread.Start();
                    }
                    Ingame = true;
                    state  = States.INGAME;
                }
                else if (e.KeyCode == Keys.Escape)                             // clear all keys
                {
                    HashSet <Neat> NeatCopy = new HashSet <Neat>(Neat.All);
                    foreach (Neat neat in NeatCopy)
                    {
                        neat.Remove();
                    }
                    HashSet <Head> HeadCopy = new HashSet <Head>(HEADS.Values);
                    foreach (Head head in HeadCopy)
                    {
                        head.Remove();
                    }
                    Map.MaxPoints = 0;
                    Leader        = Keys.None;
                }
                else if (0 <= e.KeyValue && e.KeyValue < 256)                             //add key
                {
                    lock (ActiveLock) {
                        if (ActiveKeys.Contains(ekey))
                        {
                            HEADS[ekey].Remove();
                        }
                        else
                        {
                            if (HEADSOnPause.ContainsKey(ekey))
                            {
                                HEADS.Add(ekey, new Head(HEADSOnPause[ekey]));
                            }
                            else
                            {
                                HEADS.Add(ekey, new Head(ekey));
                            }
                            ActiveKeys.Add(ekey);
                            Map.SetMaxPoints();
                        }
                    }
                    IKey.UpdateAll();
                }
                break;

            case States.INGAME:
                if (e.KeyCode == Keys.Escape)                           //pause game
                {
                    ApplicationPause();
                }
                else if (ActiveKeys.Contains(ekey))                             //default action
                {
                    HEADS[ekey].Action();
                }
                break;

            case States.PAUSED:
                if (e.KeyCode == Keys.Escape)                           // unpause
                {
                    state  = States.INGAME;
                    Ingame = true;
                    if (SyncUpdate)
                    {
                        UpdateThread.Start();
                        NeuralThread.Start();
                    }
                    else
                    {
                        StartAsyncUpdate();
                    }
                    VisualThread.Start();
                    //ForcePaused = false;
                }
                else if (e.KeyCode == Keys.Enter)                             // let players join
                {
                    HEADSOnPause.Clear();
                    foreach (KeyValuePair <Keys, Head> player in HEADS)
                    {
                        HEADSOnPause.Add(player.Key, player.Value);
                    }
                    Map.EndGame();
                    Map.Clear();
                    Map.phase = Phases.NONE;
                    state     = States.NEWGAME;
                    MVP.Show("Prepare!");
                    lock (ActiveLock) foreach (Keys key in ActiveKeys)
                        {
                            HEADS[key].v = IVector.Up;
                        }
                    Ingame = false;
                    VisualThread.Start();
                    if (SyncUpdate)
                    {
                        UpdateThread.Start();
                    }
                    else
                    {
                        StartAsyncUpdate();
                    }
                }
                break;
            }
        }
Пример #26
0
        private void Start()
        {
            UpdateThread Updater = new UpdateThread();

            Thread UpdateThread = new Thread(new ThreadStart(Updater.Start));
            UpdateThread.IsBackground = true;
            UpdateThread.Start();

            // Setup ping timer/initial values
            PingTimer.Elapsed += new ElapsedEventHandler(Ping);
            PingTimer.Interval = 10000;
            PingTimer.Enabled = false;

            Ping_Seq = 1;
            Latency = 1;

            // Fire up pather

            pather = new Pather.PPather();

            pather.OnStartGlide();


            // Loopdeloop

            Loop();

            // Thread is dead if it gets to this point
            UpdateThread.Abort();


            pather.OnStopGlide();
            pather = null;

        }
Пример #27
0
 public void Dispose()
 {
     DirectoryModel = null;
     UpdateThread.Abort();
 }
        public virtual void TestStressDeleteQueue()
        {
            DocumentsWriterDeleteQueue queue = new DocumentsWriterDeleteQueue();
            HashSet<Term> uniqueValues = new HashSet<Term>();
            int size = 10000 + Random().Next(500) * RANDOM_MULTIPLIER;
            int?[] ids = new int?[size];
            for (int i = 0; i < ids.Length; i++)
            {
                ids[i] = Random().Next();
                uniqueValues.Add(new Term("id", ids[i].ToString()));
            }
            CountDownLatch latch = new CountDownLatch(1);
            AtomicInteger index = new AtomicInteger(0);
            int numThreads = 2 + Random().Next(5);
            UpdateThread[] threads = new UpdateThread[numThreads];
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new UpdateThread(queue, index, ids, latch);
                threads[i].Start();
            }
            latch.countDown();
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Join();
            }

            foreach (UpdateThread updateThread in threads)
            {
                DeleteSlice slice = updateThread.Slice;
                queue.UpdateSlice(slice);
                BufferedUpdates deletes = updateThread.Deletes;
                slice.Apply(deletes, BufferedUpdates.MAX_INT);
                Assert.AreEqual(uniqueValues, deletes.Terms_Nunit().Keys);
            }
            queue.TryApplyGlobalSlice();
            HashSet<Term> frozenSet = new HashSet<Term>();
            foreach (Term t in queue.FreezeGlobalBuffer(null).TermsIterable())
            {
                BytesRef bytesRef = new BytesRef();
                bytesRef.CopyBytes(t.Bytes());
                frozenSet.Add(new Term(t.Field(), bytesRef));
            }
            Assert.AreEqual(0, queue.NumGlobalTermDeletes(), "num deletes must be 0 after freeze");
            Assert.AreEqual(uniqueValues.Count, frozenSet.Count);
            Assert.AreEqual(uniqueValues, frozenSet);
        }
Пример #29
0
        // This class is a simple launcher for your actual code in PluginCode.cs
        //
        // We make use of non-volatile data and threading to let your work run in another
        // thread, making Rainmeter nice and responsive.  Checks are automatically performed
        // so that overlapping of execution does not occur.
        // Default values of a blank string for GetUpdate() and zero for Update()/Update2()
        // are returned.
        public UInt32 Update(Rainmeter.Settings Plugin, UInt32 id)
        {
            bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_U_AlreadyRunning", false);
            if (!bAlreadyRunning)
            {
                UpdateThread thread_details = new UpdateThread(Plugin.Instances[id]);
                Thread thread = new Thread(new ThreadStart(thread_details.Go));
                thread.Start();
            }

            try
            {
                return (UInt32)Plugin.Instances[id].GetTempValue("__RMT_U_LastValue", 0);
            }
            catch
            {
                return 0;
            }
        }
Пример #30
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            initializeScreen();
            Settings.initialize(this);

            #if XBOX
            Settings.getInstance().IsUsingMouse_ = false;
            #else
            if (GamePad.GetState(PlayerIndex.One).IsConnected)
            {
                Settings.getInstance().IsUsingMouse_ = false;
            }
            else
            {
                Settings.getInstance().IsUsingMouse_ = true;
            }
            #endif

            try
            {
                // Debugging - Uncomment this line to try PC version as if it
                //  were running with the Redistributable runtime in which
                //  GamerServices is not available
                // Note that this is not a truly accurate test, as there could
                //  be lurking calls to GamerServices outside of a block which
                //  tests Settings.IsGamerServicesAllowed_ prior to using
                // throw new Exception();

                GamerServicesComponent gsc = new GamerServicesComponent(this);
                gsc.Initialize();
                this.Components.Add(gsc);
                Settings.getInstance().IsGamerServicesAllowed_ = true;
            }
            catch
            {
                Settings.getInstance().IsGamerServicesAllowed_ = false;
            }

            // creating EngineStateStart must come AFTER setting the
            //  IsGamerServicesAllowed_ member of Settings
            this.engineState_ = new EngineStateSplash(this);

            int tiles = (int)((GraphicsDevice.Viewport.Height / 15) * (GraphicsDevice.Viewport.Width / 15) * 1.2);
            tiles += 350;

            DrawBuffer.initialize(tiles, spriteBatch_);
            DrawBuffer_ = DrawBuffer.getInstance();
            UpdateThread_ = new UpdateThread(this, engineState_);
            RenderThread_ = new RenderThread();
            UpdateThread_.Controls_ = Controls_;
            UpdateThread_.startThread();
        }
Пример #31
0
        private void SocketDataRecieved(IAsyncResult e)
        {
            RecieveStruct state = (RecieveStruct)e.AsyncState;
            int           ecode = 0;

            try
            {
                ecode = state.sock.EndReceive(e);
            }
            catch (SocketException) {
                sockets.Remove(state.sock);
                return;
            }
            catch (ObjectDisposedException) {
                sockets.Remove(state.sock);
                return;
            }
            if (ecode == 0)
            {
                //We should NEVER get zero data.
                sockets.Remove(state.sock);
                return;
            }
            WSPacket packet;

            try
            {
                packet = DecodePacket(state.buffer, state.sock);
            }
            catch (Exception) {
                CloseSocket(state.sock);
                return;
            }
            if (packet.opcode == OPCODE_INTERNAL_FAIL)
            {
                //Decoder could not get any more data from the packet, so the connection must be terminated.
                sockets.Remove(state.sock);
                return;
            }
            if (packet.lastPacket)
            {
                if (fragments.ContainsKey(state.sock))
                {
                    byte[] lastPacket = fragments[state.sock];
                    byte[] buffer     = new byte[lastPacket.Length + packet.binaryData.Length];
                    Array.Copy(lastPacket, buffer, lastPacket.Length);
                    Array.Copy(packet.binaryData, 0, buffer, lastPacket.Length, packet.binaryData.Length);
                    fragments[state.sock] = buffer;
                    packet.binaryData     = buffer;
                    if (packet.opcode == OPCODE_TEXT)
                    {
                        packet.textData = Encoding.UTF8.GetString(packet.binaryData);
                    }
                    fragments.Remove(state.sock);
                }
                packet.sender = state.sock;
                //Do something with the packet.
                if (packet.opcode == OPCODE_CLOSE)
                {
                    state.sock.Close();
                }
                else if (packet.opcode == OPCODE_PING)
                {
                    WSPacket newpack = new WSPacket();
                    packet.opcode     = 0xA;
                    packet.length     = 0;
                    packet.lastPacket = true;
                    byte[] newdata = EncodePacket(newpack);
                    state.sock.BeginSend(newdata, 0, newdata.Length, SocketFlags.None, SocketDataSent, state);
                }
                else
                {
                    processingQueue.Enqueue(packet);
                    if (CanInterrupt)
                    {
                        UpdateThread.Interrupt();
                    }
                }
            }
            else
            {
                if (!fragments.ContainsKey(state.sock))
                {
                    fragments.Add(state.sock, packet.binaryData);
                }
                else
                {
                    byte[] lastPacket = fragments[state.sock];
                    byte[] buffer     = new byte[lastPacket.Length + packet.binaryData.Length];
                    lastPacket.CopyTo(buffer, 0);
                    packet.binaryData.CopyTo(buffer, lastPacket.Length);
                    fragments[state.sock] = buffer;
                }
            }

            if (state.sock.Connected)
            {
                state.sock.BeginReceive(state.buffer, 0, WSREADSIZE, SocketFlags.None, SocketDataRecieved, state);
            }
        }