Exemplo n.º 1
0
        public GameWorldXna(PlanesGame game, GameWorld gameWorld, Rectangle gameFieldRectangle)
            : base(game)
        {
            m_lastFrame    = new RenderTarget2D(game.GraphicsDevice, game.Graphics.PreferredBackBufferWidth, game.Graphics.PreferredBackBufferHeight, false, SurfaceFormat.HdrBlendable, DepthFormat.None);
            m_currentFrame = new RenderTarget2D(game.GraphicsDevice, game.Graphics.PreferredBackBufferWidth, game.Graphics.PreferredBackBufferHeight, false, SurfaceFormat.HdrBlendable, DepthFormat.None);

            m_safeDrawableGameComponents = new ThreadSafeCollection <MyDrawableGameComponent>();

            m_safeParticlesCollection = new ThreadSafeCollection <Particle>();

            m_gameWorld = gameWorld;
            m_gameWorld.GameObjectStatusChanged += GameObjectStatusChanged;
            m_gameWorld.BonusApplied            += BonusApplied;
            m_gameWorld.Explosion += ExplosionDetected;

            //m_backgroundVisiblePartWidth = gameFieldRectangle.Width;
            m_backgroundScale = new Vector2(1.5f, 1.5f); // 50% of width and height will be behind screen bound in every frame

            m_coordinatesTransformer = new CoordinatesTransformer(m_gameWorld.Size, gameFieldRectangle, 180);
            m_coordinatesTransformer.ScaleToFit();

            m_instanceMapper = new InstanceMapper(game, m_coordinatesTransformer);

            m_gameObjectMapping = new Dictionary <GameObject, DrawableGameObject>();
            m_equipmentMapping  = new Dictionary <Equipment, DrawableEquipment>();

            m_soundManager = new SoundManager(game, () => m_coordinatesTransformer.VisibleLogicalRectangle);

            //m_lastFrameRenderTarget = new RenderTarget2D(game.Graphics.GraphicsDevice,
            //    game.Graphics.PreferredBackBufferWidth, game.Graphics.PreferredBackBufferHeight,
            //    false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PlatformContents);

            FillInstanceMapper();
        }
Exemplo n.º 2
0
        public void ReadAndWriteSimultanious()
        {
            int iterations = 500000;

            ThreadSafeCollection <string> comeGetMe = new ThreadSafeCollection <string>(iterations);
            List <long> countsRead = new List <long>();
            long        addCount   = 0;

            Random r = new Random();

            DoReaderWriter(() =>
            {
                countsRead.Add(Interlocked.Read(ref addCount));
            },
                           i =>
            {
                comeGetMe.Add(new string(Enumerable.Repeat(' ', 10).Select(c => (char)r.Next('A', 'Z')).ToArray()));
                Interlocked.Increment(ref addCount);
            },
                           iterations);

            addCount.Should().Be(iterations);
            countsRead.Count.Should().BeGreaterThan(0);
            countsRead.Last().Should().Be(iterations);
            comeGetMe.Count.Should().Be(iterations);
        }
Exemplo n.º 3
0
        public ViewFilter()
        {
            Filter = new Filter();
            Filter.FilterChanged += delegate { RebuildCurrentViewAsync(); };

            Messages = new ThreadSafeCollection<Message>();

            mailbox = VirtualMailBox.Current;
            mailbox.InboxLoadComplete += delegate
                {
                    // Perform a lock-free update on the UI-Thread.
                    // We should be safe because at this point there should be no async tasks
                    // running and all inserts should happen on the UI thread anyway.
                    Messages.Replace(GetMessagesInView(
                        mailbox.Messages.Where(IsMessageVisible).AsQueryable()).ToList());
                };

            signal = new AutoResetEvent(false);
            workerThread = new Thread(RenderView)
                {
                    Name = "View rendering thread",
                    IsBackground = true,
                    Priority = ThreadPriority.Normal
                };

            workerThread.Start();
        }
Exemplo n.º 4
0
        public EscapePodManager(List <EscapePodModel> escapePods)
        {
            EscapePods = new ThreadSafeCollection <EscapePodModel>(escapePods);

            InitializePodForNextPlayer();
            InitializeEscapePodsByPlayerId();
        }
Exemplo n.º 5
0
 public NeptuneRocketModel(NitroxTechType techType, NitroxId id, NitroxVector3 position, NitroxQuaternion rotation, List <InteractiveChildObjectIdentifier> interactiveChildIdentifiers, Optional <NitroxId> dockingBayId, string name, NitroxVector3[] hsb, float health)
     : base(techType, id, position, rotation, interactiveChildIdentifiers, dockingBayId, name, hsb, health)
 {
     CurrentStage    = 0;
     ElevatorUp      = false;
     PreflightChecks = new ThreadSafeCollection <PreflightCheck>();
 }
Exemplo n.º 6
0
 public WorkScheduler(Configuration configuration, IPlatformPerformance performance)
 {
     Configuration = configuration;
     Performance   = performance;
     PendingTasks  = new PendingTasksQueue();
     RunningTasks  = new Dictionary <string, IImageLoaderTask>();
     SimilarTasks  = new ThreadSafeCollection <IImageLoaderTask>();
 }
 public void Setup()
 {
     state = new ThreadSafeCollection <InteractiveChildObjectIdentifier>();
     state.Add(new InteractiveChildObjectIdentifier(new NitroxId(), "/BlablaScene/SomeBlablaContainer/BlaItem"));
     byte[] idBytes = new byte[16];
     random.NextBytes(idBytes);
     state.Add(new InteractiveChildObjectIdentifier(new NitroxId(idBytes), ""));
     state.Add(new InteractiveChildObjectIdentifier(new NitroxId(), " herp "));
 }
Exemplo n.º 8
0
 public void Setup()
 {
     list = new ThreadSafeCollection <string>();
     set  = new ThreadSafeCollection <string>(new HashSet <string>());
     for (int i = 0; i < 10; i++)
     {
         set.Add($"test {i}");
         list.Add($"test {i}");
     }
 }
Exemplo n.º 9
0
        public EscapePodManager(List <EscapePodModel> escapePods, RandomStartGenerator randomStart, string seed)
        {
            EscapePods = new ThreadSafeCollection <EscapePodModel>(escapePods);

            this.seed        = seed;
            this.randomStart = randomStart;

            InitializePodForNextPlayer();
            InitializeEscapePodsByPlayerId();
        }
Exemplo n.º 10
0
        private static void Setup()
        {
            addClientLock    = new Object();
            removeClientLock = new Object();
            broadcastLock    = new Object();

            clientsThreads = new List <Thread>();
            packetStack    = new ConcurrentStack <Packet>();
            clients        = new ThreadSafeCollection <Client>();

            Console.OutputEncoding = Encoding.Unicode;
        }
Exemplo n.º 11
0
 public VehicleModel(NitroxTechType techType, NitroxId id, NitroxVector3 position, NitroxQuaternion rotation, IEnumerable <InteractiveChildObjectIdentifier> interactiveChildIdentifiers, Optional <NitroxId> dockingBayId, string name, NitroxVector3[] hsb, float health)
 {
     TechType = techType;
     Id       = id;
     Position = position;
     Rotation = rotation;
     InteractiveChildIdentifiers = new ThreadSafeCollection <InteractiveChildObjectIdentifier>(interactiveChildIdentifiers);
     DockingBayId = dockingBayId;
     Name         = name;
     HSB          = hsb;
     Health       = health;
 }
Exemplo n.º 12
0
 public Player(ushort id, string name, PlayerContext playerContext, NitroxConnection connection, Vector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <EquippedItemData> equippedItems,
               IEnumerable <EquippedItemData> modules)
 {
     Id                 = id;
     Name               = name;
     PlayerContext      = playerContext;
     this.connection    = connection;
     Position           = position;
     SubRootId          = subRootId;
     GameObjectId       = playerId;
     Permissions        = perms;
     Stats              = stats;
     this.equippedItems = new ThreadSafeCollection <EquippedItemData>(equippedItems);
     this.modules       = new ThreadSafeCollection <EquippedItemData>(modules);
 }
Exemplo n.º 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            ThreadSafeList <string> list = new ThreadSafeList <string>();
            Random rnd = new Random(DateTime.Now.Millisecond);

            for (int i = 0; i < 10; i++)
            {
                list.Add(rnd.Next(1, 20).ToString());
            }
            string[] aa = { "A1", "B2", "C3", "D4" };
            list.AddRange(aa);
            MessageBox.Show("OK");
            list = new ThreadSafeList <string>(aa);
            list.RemoveAll(s => { int zz; return(!int.TryParse(s, out zz)); });
            ThreadSafeCollection <string> cl = new ThreadSafeCollection <string>();
        }
Exemplo n.º 14
0
        public DetailsView()
        {
            using (new CodeTimer("ColumnSearch/Constructor"))
            {
                dock          = new SearchDockControl();
                mailbox       = VirtualMailBox.Current;
                messages      = new ThreadSafeCollection <Message>();
                documents     = new ThreadSafeCollection <Document>();
                persons       = new ThreadSafeCollection <Person>();
                statusUpdates = new ThreadSafeCollection <UserStatus>();

                messagesViewSource = new CollectionViewSource {
                    Source = messages
                };
                messagesViewSource.SortDescriptions.Add(new SortDescription("SortDate", ListSortDirection.Descending));

                documentsViewSource = new CollectionViewSource {
                    Source = documents
                };
                documentsViewSource.SortDescriptions.Add(new SortDescription("Filename", ListSortDirection.Ascending));

                personsViewSource = new CollectionViewSource {
                    Source = persons
                };
                personsViewSource.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

                statusUpdatesViewSource = new CollectionViewSource {
                    Source = statusUpdates
                };
                statusUpdatesViewSource.SortDescriptions.Add(new SortDescription("SortDate", ListSortDirection.Descending));

                InitializeComponent();

                MessagesColumn.OverrideViewSource(messagesViewSource);
                DocumentsColumn.OverrideViewSource(documentsViewSource);
                StatusUpdatesColumn.OverrideViewSource(statusUpdatesViewSource);

                dock.UpdateSearch += delegate
                {
                    LoadData(new ColumnSearchDataHelper {
                        SearchQuery = dock.SearchQuery
                    });
                };

                DataContext = this;
            }
        }
Exemplo n.º 15
0
        public void IterateAndAdd()
        {
            ThreadSafeCollection <int> nums = new ThreadSafeCollection <int>()
            {
                1, 2, 3, 4, 5
            };

            foreach (int num in nums)
            {
                if (num == 3)
                {
                    nums.Add(10);
                }
            }

            nums.Count.ShouldBeEquivalentTo(6);
            nums.Last().ShouldBeEquivalentTo(10);
        }
Exemplo n.º 16
0
 public Player(ushort id, string name, bool isPermaDeath, PlayerContext playerContext, NitroxConnection connection, Vector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <EquippedItemData> equippedItems,
               IEnumerable <EquippedItemData> modules)
 {
     Id                 = id;
     Name               = name;
     IsPermaDeath       = isPermaDeath;
     PlayerContext      = playerContext;
     this.connection    = connection;
     Position           = position;
     SubRootId          = subRootId;
     GameObjectId       = playerId;
     Permissions        = perms;
     Stats              = stats;
     LastStoredPosition = null;
     this.equippedItems = new ThreadSafeCollection <EquippedItemData>(equippedItems);
     this.modules       = new ThreadSafeCollection <EquippedItemData>(modules);
     visibleCells       = new ThreadSafeCollection <AbsoluteEntityCell>(new HashSet <AbsoluteEntityCell>(), false);
 }
Exemplo n.º 17
0
        public Data()
        {
            labels = new ThreadSafeDictionary<string, List<Label>>();

            conversations = new ThreadSafeCollection<Conversation>();
            messages = new ThreadSafeCollection<Message>();
            documents = new ThreadSafeCollection<Document>();
            versions = new ThreadSafeCollection<DocumentVersion>();
            persons = new ThreadSafeCollection<Person>();
            profiles = new ThreadSafeCollection<Profile>();
            statusUpdates = new ThreadSafeCollection<UserStatus>();
            statusUpdateAttachments = new ThreadSafeCollection<UserStatusAttachment>();

            keyedMessages = new Dictionary<long, Message>();
            keyedDocuments = new Dictionary<long, Document>();
            keyedPersons = new Dictionary<long, Person>();
            keyedConversations = new Dictionary<string, Conversation>();
            keyedStatusUpdates = new Dictionary<string, UserStatus>();
            keyedProfiles = new Dictionary<string, Profile>();
        }
Exemplo n.º 18
0
        public DetailsView()
        {
            using (new CodeTimer("ColumnSearch/Constructor"))
            {
                dock = new SearchDockControl();
                mailbox = VirtualMailBox.Current;
                messages = new ThreadSafeCollection<Message>();
                documents = new ThreadSafeCollection<Document>();
                persons = new ThreadSafeCollection<Person>();
                statusUpdates = new ThreadSafeCollection<UserStatus>();

                messagesViewSource = new CollectionViewSource { Source = messages };
                messagesViewSource.SortDescriptions.Add(new SortDescription("SortDate", ListSortDirection.Descending));

                documentsViewSource = new CollectionViewSource { Source = documents };
                documentsViewSource.SortDescriptions.Add(new SortDescription("Filename", ListSortDirection.Ascending));

                personsViewSource = new CollectionViewSource { Source = persons };
                personsViewSource.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

                statusUpdatesViewSource = new CollectionViewSource { Source = statusUpdates };
                statusUpdatesViewSource.SortDescriptions.Add(new SortDescription("SortDate", ListSortDirection.Descending));

                InitializeComponent();

                MessagesColumn.OverrideViewSource(messagesViewSource);
                DocumentsColumn.OverrideViewSource(documentsViewSource);
                StatusUpdatesColumn.OverrideViewSource(statusUpdatesViewSource);

                dock.UpdateSearch += delegate
                    {
                        LoadData(new ColumnSearchDataHelper { SearchQuery = dock.SearchQuery });
                    };

                DataContext = this;
            }
        }
        public override void Process(RocketPreflightComplete packet, NitroxServer.Player player)
        {
            Optional <NeptuneRocketModel> opRocket = vehicleManager.GetVehicleModel <NeptuneRocketModel>(packet.Id);

            if (opRocket.HasValue)
            {
                ThreadSafeCollection <PreflightCheck> collection = opRocket.Value.PreflightChecks;

                if (!collection.Contains(packet.FlightCheck))
                {
                    collection.Add(packet.FlightCheck);
                }
                else
                {
                    Log.Error($"{nameof(RocketPreflightCompleteProcessor)}: Received an existing preflight '{packet.FlightCheck}' for rocket '{packet.Id}'");
                }
            }
            else
            {
                Log.Error($"{nameof(RocketPreflightCompleteProcessor)}: Can't find server model for rocket with id {packet.Id}");
            }

            playerManager.SendPacketToOtherPlayers(packet, player);
        }
 public VehicleModel()
 {
     InteractiveChildIdentifiers = new ThreadSafeCollection <InteractiveChildObjectIdentifier>();
     DockingBayId = Optional.Empty;
 }
        public FoldersControl()
        {
            mailbox    = VirtualMailBox.Current;
            viewFilter = ViewFilter.Current;
            labels     = new ThreadSafeCollection <LabelsContainer>();

            LabelsViewSource = new CollectionViewSource {
                Source = labels
            };
            LabelsViewSource.SortDescriptions.Add(new SortDescription("Count", ListSortDirection.Descending));
            LabelsViewSource.View.Filter = IsLabelVisible;

            InitializeComponent();

            signal       = new AutoResetEvent(false);
            workerThread = new Thread(UpdateCounters)
            {
                Name         = "Counter update thread",
                IsBackground = true,
                Priority     = ThreadPriority.BelowNormal
            };

            workerThread.Start();

            DataContext = this;

            VirtualMailBox.Current.LoadComplete += delegate { UpdateCountersAsync(); };

            EventBroker.Subscribe(AppEvents.RebuildOverview, UpdateCountersAsync);
            EventBroker.Subscribe(AppEvents.ReceiveMessagesFinished, UpdateCountersAsync);
            EventBroker.Subscribe(AppEvents.MessageUpdated, UpdateCountersAsync);

            EventBroker.Subscribe(AppEvents.View, delegate(ActivityView view)
            {
                ClientState.Current.ViewController.MoveTo(WellKnownView.Overview);

                // Find the radio-button with the requested view
                LogicalTreeWalker.Walk(this, delegate(RadioButton rb)
                {
                    if (GetActivityView(rb) == view)
                    {
                        rb.IsChecked = true;
                    }
                });

                viewFilter.Filter.CurrentView = view;
                viewFilter.RebuildCurrentViewAsync();

                EventBroker.Publish(AppEvents.RequestFocus);
            });

            EventBroker.Subscribe(AppEvents.View, delegate(Label label)
            {
                EventBroker.Publish(AppEvents.View, ActivityView.Label);

                viewFilter.Filter.Label = label.Labelname;
                viewFilter.RebuildCurrentViewAsync();

                EventBroker.Publish(AppEvents.RequestFocus);
            });

            EventBroker.Subscribe(AppEvents.ShuttingDown, () => Thread.CurrentThread.ExecuteOnUIThread(delegate
            {
                // Save settings during shutdown
                SettingsManager.ClientSettings.AppConfiguration.ShowProductivityColumn = ProductivityExpander.IsExpanded;
                SettingsManager.ClientSettings.AppConfiguration.ShowLabelsColumn       = LabelsExpander.IsExpanded;
                SettingsManager.Save();
            }));

            EventBroker.Subscribe(AppEvents.LabelCreated, (string label) => labels.Add(new LabelsContainer(label)));
        }
Exemplo n.º 22
0
 protected VehicleModel()
 {
     // Constructor for serialization. Has to be "protected" for json serialization.
     InteractiveChildIdentifiers = new ThreadSafeCollection <InteractiveChildObjectIdentifier>();
     DockingBayId = Optional.Empty;
 }
Exemplo n.º 23
0
 public VehicleModel()
 {
     // For serialization purposes
     InteractiveChildIdentifiers = new ThreadSafeCollection <InteractiveChildObjectIdentifier>();
     DockingBayId = Optional.Empty;
 }
 public ConnectionWindow(ThreadSafeCollection <NetConnectionInfo> info, string processName)
 {
     InitializeComponent();
     Title             = processName;
     List1.ItemsSource = info;
 }
Exemplo n.º 25
0
        public FoldersControl()
        {
            mailbox = VirtualMailBox.Current;
            viewFilter = ViewFilter.Current;
            labels = new ThreadSafeCollection<LabelsContainer>();

            LabelsViewSource = new CollectionViewSource { Source = labels };
            LabelsViewSource.SortDescriptions.Add(new SortDescription("Count", ListSortDirection.Descending));
            LabelsViewSource.View.Filter = IsLabelVisible;

            InitializeComponent();

            signal = new AutoResetEvent(false);
            workerThread = new Thread(UpdateCounters)
            {
                Name = "Counter update thread",
                IsBackground = true,
                Priority = ThreadPriority.BelowNormal
            };

            workerThread.Start();

            DataContext = this;

            VirtualMailBox.Current.LoadComplete += delegate { UpdateCountersAsync(); };

            EventBroker.Subscribe(AppEvents.RebuildOverview, UpdateCountersAsync);
            EventBroker.Subscribe(AppEvents.ReceiveMessagesFinished, UpdateCountersAsync);
            EventBroker.Subscribe(AppEvents.MessageUpdated, UpdateCountersAsync);

            EventBroker.Subscribe(AppEvents.View, delegate(ActivityView view)
                {
                    ClientState.Current.ViewController.MoveTo(WellKnownView.Overview);

                    // Find the radio-button with the requested view
                    LogicalTreeWalker.Walk(this, delegate(RadioButton rb)
                        {
                            if (GetActivityView(rb) == view)
                                rb.IsChecked = true;
                        });

                    viewFilter.Filter.CurrentView = view;
                    viewFilter.RebuildCurrentViewAsync();

                    EventBroker.Publish(AppEvents.RequestFocus);
                });

            EventBroker.Subscribe(AppEvents.View, delegate(Label label)
                {
                    EventBroker.Publish(AppEvents.View, ActivityView.Label);

                    viewFilter.Filter.Label = label.Labelname;
                    viewFilter.RebuildCurrentViewAsync();

                    EventBroker.Publish(AppEvents.RequestFocus);
                });

            EventBroker.Subscribe(AppEvents.ShuttingDown, () => Thread.CurrentThread.ExecuteOnUIThread(delegate
                {
                    // Save settings during shutdown
                    SettingsManager.ClientSettings.AppConfiguration.ShowProductivityColumn = ProductivityExpander.IsExpanded;
                    SettingsManager.ClientSettings.AppConfiguration.ShowLabelsColumn = LabelsExpander.IsExpanded;
                    SettingsManager.Save();
                }));

            EventBroker.Subscribe(AppEvents.LabelCreated, (string label) => labels.Add(new LabelsContainer(label)));
        }