예제 #1
0
        private static void EnqueueHistory(MyVoxelDataRequest request)
        {
            using (m_historyLock.AcquireExclusiveUsing())
            {
                if (UnculledRequestHistory.Count >= MAX_UNCULLED_HISTORY)
                {
                    UnculledRequestHistory.Dequeue();
                }

                request.Target = null;
                UnculledRequestHistory.Enqueue(request);
            }

            MyConcurrentHashSet <Vector3I> sizes;

            if (!KnownLodSizes.TryGetValue(request.Lod, out sizes))
            {
                sizes = new MyConcurrentHashSet <Vector3I>();
                if (!KnownLodSizes.TryAdd(request.Lod, sizes))
                {
                    sizes = KnownLodSizes[request.Lod];
                }
            }

            sizes.Add(request.maxInLod - request.minInLod + Vector3I.One);
        }
예제 #2
0
 protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions, int passThrough)
 {
     foreach (var activeCursor in cursor.StateMachine.ActiveCursors)
     {
         cursor.StateMachine.DeleteCursor(activeCursor.Id);
     }
 }
        // Cache cursor data, remove cursor, let go when all incoming branch cursors reach the barrier node
        protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions, int passThrough)
        {
            var stateMachine      = cursor.StateMachine;
            var inTransitionIndex = 0;

            for (; inTransitionIndex < InTransitions.Count; inTransitionIndex++)
            {
                if (InTransitions[inTransitionIndex].Id == cursor.LastTransitionTakenId)
                {
                    break;
                }
            }

            Debug.Assert(inTransitionIndex < InTransitions.Count, "Transition not found.");
            Debug.Assert(!m_cursorsFromInEdgesReceived[inTransitionIndex], "More than one cursor from branch received.");

            m_cursorsFromInEdgesReceived[inTransitionIndex] = true;
            stateMachine.DeleteCursor(cursor.Id);

            // Check if all cursors arrived
            foreach (var value in m_cursorsFromInEdgesReceived)
            {
                if (!value)
                {
                    return;
                }
            }

            if (OutTransitions.Count > 0)
            {
                stateMachine.CreateCursor(OutTransitions[0].TargetNode.Name);
            }
        }
예제 #4
0
 public static void ReportServerStatus()
 {
     if (((MyMultiplayer.Static != null) && MyMultiplayer.Static.IsServer) && (MyMultiplayer.Static.MemberCount > 1))
     {
         try
         {
             int gridCount        = 0;
             int blockCount       = 0;
             int movingGridsCount = 0;
             MyConcurrentHashSet <MyEntity> entities = MyEntities.GetEntities();
             foreach (MyEntity entity in entities)
             {
                 if (!(entity is MyCubeGrid))
                 {
                     continue;
                 }
                 gridCount++;
                 blockCount += (entity as MyCubeGrid).BlocksCount;
                 if (((entity as MyCubeGrid).Physics != null) && ((entity as MyCubeGrid).Physics.LinearVelocity != Vector3.Zero))
                 {
                     movingGridsCount++;
                 }
             }
             MyAnalyticsManager.Instance.ReportServerStatus(MyMultiplayer.Static.MemberCount, MyMultiplayer.Static.MemberLimit, Sync.ServerSimulationRatio, entities.Count, gridCount, blockCount, movingGridsCount, MyMultiplayer.Static.HostName, MySession.Static.Scenario.Id.SubtypeName, MySession.Static.Name, (uint)MySession.Static.ElapsedGameTime.TotalSeconds);
         }
         catch (Exception exception)
         {
             MyLog.Default.WriteLine(exception);
         }
     }
 }
 protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough)
 {
     foreach (var activeCursor in cursor.StateMachine.ActiveCursors)
     {
         cursor.StateMachine.DeleteCursor(activeCursor.Id);
     }
 }
 public static void InsertEntity_ImplementationPostfix(long entityId, ref MyConcurrentHashSet <long> ___m_containedEntities, ref MySafeZone __instance)
 {
     if (___m_containedEntities.Contains(entityId))
     {
         return;
     }
     if (MyEntities.TryGetEntityById(entityId, out var top))
     {
         top.SetSafeZone(__instance);
     }
 }
        protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough)
        {
            if(OutTransitions.Count == 0) return;

            var stateMachine = cursor.StateMachine;
            // Remove the current Cursor
            stateMachine.DeleteCursor(cursor.Id);

            // Spawn new cursors for the rest
            for (var i = 0; i < OutTransitions.Count; i++)
                stateMachine.CreateCursor(OutTransitions[i].TargetNode.Name);
        }
예제 #8
0
        public void UpdateBlacklist()
        {
            var blacklist  = MyScriptCompiler.Static.Whitelist.OpenIngameBlacklistBatch();
            var types      = new MyConcurrentHashSet <Type>();
            var memberDict = new MyConcurrentDictionary <Type, List <string> >();

            Parallel.ForEach(PluginSettings.Instance.BlacklistItems, item =>
            {
                if (string.IsNullOrEmpty(item.Type))
                {
                    return;
                }

                var targetType = FindTypeInAllAssemblies(item.Type);
                if (targetType == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(item.Member))
                {
                    lock (types)
                        types.Add(targetType);
                }

                var members = targetType.GetMember(item.Member);
                if (members.Length != 0)
                {
                    if (!memberDict.ContainsKey(targetType))
                    {
                        memberDict.Add(targetType, new List <string>());
                    }
                    memberDict[targetType].Add(item.Member);
                }
            });

            if (types.Count > 0)
            {
                blacklist.AddTypes(types.ToArray());
                foreach (var type in types)
                {
                    Essentials.Log.Info($"Added type {type.Name} to PB blacklist.");
                }
            }
            foreach (var entry in memberDict)
            {
                blacklist.AddMembers(entry.Key, entry.Value.ToArray());
                foreach (var name in entry.Value)
                {
                    Essentials.Log.Info($"Added {entry.Key.Name}.{name} to PB blacklist.");
                }
            }
        }
예제 #9
0
 internal MyMultiplayerBase(MySyncLayer syncLayer)
 {
     this.SyncLayer              = syncLayer;
     this.IsConnectionDirect     = true;
     this.IsConnectionAlive      = true;
     this.m_kickedClients        = new ConcurrentDictionary <ulong, int>();
     this.m_bannedClients        = new MyConcurrentHashSet <ulong>();
     this.m_wrongPasswordClients = new Dictionary <ulong, int>();
     this.m_lastKickUpdate       = MySandboxGame.TotalTimeInMilliseconds;
     MyNetworkMonitor.Init();
     MyNetworkReader.SetHandler(0, new NetworkMessageDelegate(this.ControlMessageReceived), new Action <ulong>(this.DisconnectClient));
     this.RegisterControlMessage <MyControlKickClientMsg>(MyControlMessageEnum.Kick, new ControlMessageHandler <MyControlKickClientMsg>(this.OnClientKick), MyMessagePermissions.ToServer | MyMessagePermissions.FromServer);
     this.RegisterControlMessage <MyControlDisconnectedMsg>(MyControlMessageEnum.Disconnected, new ControlMessageHandler <MyControlDisconnectedMsg>(this.OnDisconnectedClient), MyMessagePermissions.ToServer | MyMessagePermissions.FromServer);
     this.RegisterControlMessage <MyControlBanClientMsg>(MyControlMessageEnum.Ban, new ControlMessageHandler <MyControlBanClientMsg>(this.OnClientBan), MyMessagePermissions.ToServer | MyMessagePermissions.FromServer);
     this.RegisterControlMessage <MyControlSendPasswordHashMsg>(MyControlMessageEnum.SendPasswordHash, new ControlMessageHandler <MyControlSendPasswordHashMsg>(this.OnPasswordHash), MyMessagePermissions.ToServer);
     syncLayer.TransportLayer.DisconnectPeerOnError = new Action <ulong>(this.DisconnectClient);
     this.ClientKicked += new Action <ulong>(this.KickClient);
 }
예제 #10
0
        protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions, int passThrough)
        {
            if (OutTransitions.Count == 0)
            {
                return;
            }

            var stateMachine = cursor.StateMachine;

            // Remove the current Cursor
            stateMachine.DeleteCursor(cursor.Id);

            // Spawn new cursors for the rest
            for (var i = 0; i < OutTransitions.Count; i++)
            {
                stateMachine.CreateCursor(OutTransitions[i].TargetNode.Name);
            }
        }
예제 #11
0
        private void CleanupTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var toRemove = new MyConcurrentHashSet <IMyEntity>();
            var entities = new HashSet <IMyEntity>();
            var players  = new List <IMyPlayer>();

            MyAPIGateway.Entities.GetEntities(entities);
            MyAPIGateway.Players.GetPlayers(players);

            MyAPIGateway.Parallel.ForEach(entities, entity =>
            {
                var grid = entity as IMyCubeGrid;
                if (grid == null)
                {
                    return;
                }

                if (grid.BigOwners.Count == 0)
                {
                    toRemove.Add(entity);
                    return;
                }

                if (!grid.BigOwners.Any(o => players.Any(p => p.IdentityId == o)))
                {
                    toRemove.Add(entity);
                }
            });

            if (toRemove.Any())
            {
                MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                {
                    foreach (IMyEntity ent in toRemove)
                    {
                        ent.Close();
                    }

                    Communication.SendServerChat(0, $"Removed {toRemove.Count} grids without online owners");
                });
            }
        }
        // Cache cursor data, remove cursor, let go when all incoming branch cursors reach the barrier node
        protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough)
        {
            var stateMachine = cursor.StateMachine;
            var inTransitionIndex = 0;
            for (; inTransitionIndex < InTransitions.Count; inTransitionIndex++)
                if(InTransitions[inTransitionIndex].Id == cursor.LastTransitionTakenId)
                    break;

            Debug.Assert(inTransitionIndex < InTransitions.Count, "Transition not found."); 
            Debug.Assert(!m_cursorsFromInEdgesReceived[inTransitionIndex], "More than one cursor from branch received.");

            m_cursorsFromInEdgesReceived[inTransitionIndex] = true;
            stateMachine.DeleteCursor(cursor.Id);

            // Check if all cursors arrived
            foreach (var value in m_cursorsFromInEdgesReceived)
                if(!value) return;

            if(OutTransitions.Count > 0)
                stateMachine.CreateCursor(OutTransitions[0].TargetNode.Name);
        }
예제 #13
0
        /// <summary>
        /// Expands current node with given cursor.
        /// First enquedAction is taking place then any valid transition.
        /// Cursor is being transitioned to result of expansion.
        /// Override this for custom behavior.
        /// </summary>
        protected virtual void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions, int passThrough)
        {
            MyStateMachineTransition nextTransition;

            do
            {
                // Try to find best transition across enquedActions
                // Does not need to be evaluated one.
                nextTransition = null;
                var transitions = cursor.Node.OutTransitions;

                if (enquedActions.Count > 0)
                {
                    int bestPriority = int.MaxValue;

                    for (var i = 0; i < transitions.Count; i++)
                    {
                        int transitionPriority = transitions[i].Priority ?? int.MaxValue;
                        if (enquedActions.Contains(transitions[i].Name) && transitionPriority <= bestPriority &&
                            (transitions[i].Conditions.Count == 0 || transitions[i].Evaluate()))
                        {
                            nextTransition = transitions[i];
                            bestPriority   = transitionPriority;
                        }
                    }
                }

                if (nextTransition == null)
                {
                    // Try to find valid transition to next state
                    nextTransition = cursor.Node.QueryNextTransition();
                }

                // Transition into next state
                if (nextTransition != null)
                {
                    cursor.FollowTransition(nextTransition);
                }
            } while (nextTransition != null && cursor.Node.PassThrough && passThrough-- > 0);
        }
예제 #14
0
        /// <summary>
        /// Expands current node with given cursor.
        /// First enquedAction is taking place then any valid transition.
        /// Cursor is being transitioned to result of expansion.
        /// Override this for custom behavior.
        /// </summary>
        protected virtual void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough)
        {
            MyStateMachineTransition nextTransition;

            do
            {
                // Try to find best transition across enquedActions
                // Does not need to be evaluated one.
                nextTransition = null;
                var transitions = cursor.Node.OutTransitions;

                if (enquedActions.Count > 0)
                {
                    int bestPriority = int.MaxValue;

                    for (var i = 0; i < transitions.Count; i++)
                    {
                        int transitionPriority = transitions[i].Priority ?? int.MaxValue;
                        if (enquedActions.Contains(transitions[i].Name) && transitionPriority <= bestPriority &&
                            (transitions[i].Conditions.Count == 0 || transitions[i].Evaluate()))
                        {
                            nextTransition = transitions[i];
                            bestPriority = transitionPriority;
                        }
                    }
                }

                if (nextTransition == null)
                {
                    // Try to find valid transition to next state
                    nextTransition = cursor.Node.QueryNextTransition();
                }

                // Transition into next state
                if (nextTransition != null)
                    cursor.FollowTransition(nextTransition);

            } while (nextTransition != null && cursor.Node.PassThrough && passThrough-- > 0);   
        }
예제 #15
0
        public string SendHttpResponseResponse(HttpListenerRequest request)
        {
            StringBuilder sb     = new StringBuilder();
            JsonWriter    writer = new JsonWriter(sb);

            switch (request.Url.AbsolutePath)
            {
            //case "/gc/collect/0":
            //    GC.Collect(0);
            //    break;
            //case "/gc/collect/1":
            //    GC.Collect(1);
            //    break;
            //case "/gc/collect/2":
            //    GC.Collect(2);
            //    break;
            case "/metrics/v1/server":
                int    usedPCU            = 0;
                int    maxPlayers         = 0;
                int    maxFactionCount    = 0;
                int    maxFloatingObjects = 0;
                int    maxGridSize        = 0;
                int    maxBlocksPerPlayer = 0;
                string blockLimit         = "";
                int    totalPCU           = 0;
                int    modCount           = 0;
                if (MySession.Static != null)
                {
                    if (MySession.Static.GlobalBlockLimits != null)
                    {
                        usedPCU = MySession.Static.GlobalBlockLimits.PCUBuilt;
                    }
                    maxPlayers         = MySession.Static.MaxPlayers;
                    maxFactionCount    = MySession.Static.MaxFactionsCount;
                    maxFloatingObjects = MySession.Static.MaxFloatingObjects;
                    maxGridSize        = MySession.Static.MaxGridSize;
                    maxBlocksPerPlayer = MySession.Static.MaxBlocksPerPlayer;
                    totalPCU           = MySession.Static.TotalPCU;
                    modCount           = MySession.Static.Mods.Count;
                    switch (MySession.Static.BlockLimitsEnabled)
                    {
                    case MyBlockLimitsEnabledEnum.GLOBALLY:
                        blockLimit = "globally";
                        break;

                    case MyBlockLimitsEnabledEnum.NONE:
                        blockLimit = "none";
                        break;

                    case MyBlockLimitsEnabledEnum.PER_FACTION:
                        blockLimit = "faction";
                        break;

                    case MyBlockLimitsEnabledEnum.PER_PLAYER:
                        blockLimit = "player";
                        break;
                    }
                }
                writer.WriteObjectStart();
                writer.WritePropertyName("Version");
                writer.Write(MyFinalBuildConstants.APP_VERSION_STRING_DOTS.ToString());
                writer.WritePropertyName("ServerName");
                writer.Write(MySandboxGame.ConfigDedicated.ServerName);
                writer.WritePropertyName("WorldName");
                writer.Write(MySandboxGame.ConfigDedicated.WorldName);
                writer.WritePropertyName("IsReady");
                writer.Write(MySession.Static != null && MySession.Static.Ready);
                writer.WritePropertyName("SimSpeed");
                writer.Write(Sync.ServerSimulationRatio);
                writer.WritePropertyName("SimulationCpuLoad");
                writer.Write((float)(int)Sync.ServerCPULoad);
                writer.WritePropertyName("TotalTime");
                writer.Write(MySandboxGame.TotalTimeInMilliseconds / 1000);
                writer.WritePropertyName("Players");
                writer.Write((Sync.Clients != null) ? (Sync.Clients.Count - 1) : 0);
                writer.WritePropertyName("UsedPCU");
                writer.Write(usedPCU);
                writer.WritePropertyName("MaxPlayers");
                writer.Write(maxPlayers);
                writer.WritePropertyName("MaxFactionsCount");
                writer.Write(maxFactionCount);
                writer.WritePropertyName("MaxFloatingObjects");
                writer.Write(maxFloatingObjects);
                writer.WritePropertyName("MaxGridSize");
                writer.Write(maxGridSize);
                writer.WritePropertyName("MaxBlocksPerPlayer");
                writer.Write(maxBlocksPerPlayer);
                writer.WritePropertyName("BlockLimitsEnabled");
                writer.Write(blockLimit);
                writer.WritePropertyName("TotalPCU");
                writer.Write(totalPCU);
                writer.WritePropertyName("ModCount");
                writer.Write(modCount);
                writer.WritePropertyName("SaveDuration");
                writer.Write(saveDuration);
                writer.WriteObjectEnd();
                break;

            case "/metrics/v1/load":
                writer.WriteArrayStart();
                LoadEvent loadEv;
                while (!loadEvents.Empty)
                {
                    if (loadEvents.TryDequeueBack(out loadEv))
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("ServerCPULoad");
                        writer.Write(loadEv.ServerCPULoad);
                        writer.WritePropertyName("ServerCPULoadSmooth");
                        writer.Write(loadEv.ServerCPULoadSmooth);
                        writer.WritePropertyName("ServerSimulationRatio");
                        writer.Write(loadEv.ServerSimulationRatio);
                        writer.WritePropertyName("ServerThreadLoad");
                        writer.Write(loadEv.ServerThreadLoad);
                        writer.WritePropertyName("ServerThreadLoadSmooth");
                        writer.Write(loadEv.ServerThreadLoadSmooth);
                        writer.WritePropertyName("MillisecondsInThePast");
                        writer.Write((DateTime.Now - loadEv.Occurred).TotalMilliseconds);
                        writer.WriteObjectEnd();
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/process":
                System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
                writer.WriteObjectStart();
                writer.WritePropertyName("PrivateMemorySize64");
                writer.Write(currentProcess.PrivateMemorySize64);
                writer.WritePropertyName("VirtualMemorySize64");
                writer.Write(currentProcess.VirtualMemorySize64);
                writer.WritePropertyName("WorkingSet64");
                writer.Write(currentProcess.WorkingSet64);
                writer.WritePropertyName("NonpagedSystemMemorySize64");
                writer.Write(currentProcess.NonpagedSystemMemorySize64);
                writer.WritePropertyName("PagedMemorySize64");
                writer.Write(currentProcess.PagedMemorySize64);
                writer.WritePropertyName("PagedSystemMemorySize64");
                writer.Write(currentProcess.PagedSystemMemorySize64);
                writer.WritePropertyName("PeakPagedMemorySize64");
                writer.Write(currentProcess.PeakPagedMemorySize64);
                writer.WritePropertyName("PeakVirtualMemorySize64");
                writer.Write(currentProcess.PeakVirtualMemorySize64);
                writer.WritePropertyName("PeakWorkingSet64");
                writer.Write(currentProcess.PeakWorkingSet64);
                writer.WritePropertyName("GCLatencyMode");
                writer.Write((int)System.Runtime.GCSettings.LatencyMode);
                writer.WritePropertyName("GCIsServerGC");
                writer.Write(System.Runtime.GCSettings.IsServerGC);
                writer.WritePropertyName("GCTotalMemory");
                writer.Write(GC.GetTotalMemory(false));
                writer.WritePropertyName("GCMaxGeneration");
                writer.Write(GC.MaxGeneration);
                writer.WritePropertyName("GCCollectionCount0");
                writer.Write(GC.CollectionCount(0));
                writer.WritePropertyName("GCCollectionCount1");
                writer.Write(GC.CollectionCount(1));
                writer.WritePropertyName("GCCollectionCount2");
                writer.Write(GC.CollectionCount(2));
                writer.WriteObjectEnd();
                break;

            case "/metrics/v1/events":
                writer.WriteArrayStart();
                Event ev;
                while (!events.Empty)
                {
                    if (events.TryDequeueBack(out ev))
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("Type");
                        writer.Write(ev.Type);
                        writer.WritePropertyName("Text");
                        writer.Write(ev.Text);
                        writer.WritePropertyName("Tags");
                        writer.WriteArrayStart();
                        foreach (var tag in ev.Tags)
                        {
                            writer.Write(tag);
                        }
                        writer.WriteArrayEnd();
                        writer.WritePropertyName("SecondsInThePast");
                        writer.Write((DateTime.Now - ev.Occurred).TotalSeconds);
                        writer.WriteObjectEnd();
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/players":
                writer.WriteArrayStart();
                PlayerEvent playerEv;
                while (!playerEvents.Empty)
                {
                    if (playerEvents.TryDequeueBack(out playerEv))
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("Type");
                        writer.Write(playerEv.Type);
                        writer.WritePropertyName("SteamId");
                        writer.Write(playerEv.SteamId);
                        writer.WritePropertyName("MillisecondsInThePast");
                        writer.Write((DateTime.Now - playerEv.Occurred).TotalMilliseconds);
                        writer.WriteObjectEnd();
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/grids":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    ICollection <MyPlayer>         onlinePlayers = MySession.Static.Players.GetOnlinePlayers();
                    MyConcurrentHashSet <MyEntity> entities      = MyEntities.GetEntities();

                    Type      type  = typeof(MyEntities);
                    FieldInfo info  = type.GetField("m_entitiesForUpdateOnce", BindingFlags.NonPublic | BindingFlags.Static);
                    object    value = info.GetValue(null);
                    CachingList <MyEntity> m_entitiesForUpdateOnce = value as CachingList <MyEntity>;
                    List <long>            x_entitiesForUpdateOnce = new List <long>();

                    info  = type.GetField("m_entitiesForUpdate", BindingFlags.NonPublic | BindingFlags.Static);
                    value = info.GetValue(null);
                    MyDistributedUpdater <ConcurrentCachingList <MyEntity>, MyEntity> m_entitiesForUpdate = value as MyDistributedUpdater <ConcurrentCachingList <MyEntity>, MyEntity>;
                    List <long> x_entitiesForUpdate = new List <long>();

                    info  = type.GetField("m_entitiesForUpdate10", BindingFlags.NonPublic | BindingFlags.Static);
                    value = info.GetValue(null);
                    MyDistributedUpdater <CachingList <MyEntity>, MyEntity> m_entitiesForUpdate10 = value as MyDistributedUpdater <CachingList <MyEntity>, MyEntity>;
                    List <long> x_entitiesForUpdate10 = new List <long>();

                    info  = type.GetField("m_entitiesForUpdate100", BindingFlags.NonPublic | BindingFlags.Static);
                    value = info.GetValue(null);
                    MyDistributedUpdater <CachingList <MyEntity>, MyEntity> m_entitiesForUpdate100 = value as MyDistributedUpdater <CachingList <MyEntity>, MyEntity>;
                    List <long> x_entitiesForUpdate100 = new List <long>();

                    info  = type.GetField("m_entitiesForSimulate", BindingFlags.NonPublic | BindingFlags.Static);
                    value = info.GetValue(null);
                    MyDistributedUpdater <CachingList <MyEntity>, MyEntity> m_entitiesForSimulate = value as MyDistributedUpdater <CachingList <MyEntity>, MyEntity>;
                    List <long> x_entitiesForSimulate = new List <long>();

                    Torch.InvokeBlocking(() =>
                    {
                        x_entitiesForUpdateOnce = m_entitiesForUpdateOnce.Select((x) => x.EntityId).ToList();
                        x_entitiesForUpdate     = m_entitiesForUpdate.List.Select((x) => x.EntityId).ToList();
                        x_entitiesForUpdate10   = m_entitiesForUpdate10.List.Select((x) => x.EntityId).ToList();
                        x_entitiesForUpdate100  = m_entitiesForUpdate100.List.Select((x) => x.EntityId).ToList();
                        x_entitiesForSimulate   = m_entitiesForSimulate.List.Select((x) => x.EntityId).ToList();
                    });

                    bool IsConcealed(MyCubeGrid grid)
                    {
                        int NeedsUpdateMatches = 0;
                        int RegistedMatches    = 0;

                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.BEFORE_NEXT_FRAME) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForUpdateOnce.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }
                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.EACH_FRAME) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForUpdate.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }
                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.EACH_10TH_FRAME) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForUpdate10.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }
                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.EACH_100TH_FRAME) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForUpdate100.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }
                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.SIMULATE) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForSimulate.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }

                        return(NeedsUpdateMatches > 0 && RegistedMatches == 0);
                    }

                    foreach (MyEntity item in entities)
                    {
                        MyCubeGrid myCubeGrid = item as MyCubeGrid;
                        if (myCubeGrid != null && !myCubeGrid.Closed && myCubeGrid.Physics != null)
                        {
                            long   steamId       = 0L;
                            string displayName   = string.Empty;
                            string factionTag    = string.Empty;
                            string factionName   = string.Empty;
                            long   groupEntityId = 0L;
                            if (myCubeGrid.BigOwners.Count > 0)
                            {
                                steamId = myCubeGrid.BigOwners[0];

                                MyIdentity myIdentity = MySession.Static.Players.TryGetIdentity(steamId);
                                if (myIdentity != null)
                                {
                                    displayName = myIdentity.DisplayName;
                                }

                                IMyFaction myFaction = MySession.Static.Factions.TryGetPlayerFaction(steamId);
                                if (myFaction != null)
                                {
                                    factionTag  = myFaction.Tag;
                                    factionName = myFaction.Name;
                                }
                            }

                            foreach (var group in MyCubeGridGroups.Static.Physical.Groups)
                            {
                                bool found = false;

                                foreach (var node in group.Nodes)
                                {
                                    if (node.NodeData != myCubeGrid)
                                    {
                                        continue;
                                    }

                                    groupEntityId = group.Nodes.OrderByDescending(x => x.NodeData.BlocksCount).First().NodeData.EntityId;
                                    found         = true;
                                    break;
                                }

                                if (found)
                                {
                                    break;
                                }
                            }

                            int conveyorInventoryBlockCount = 0;
                            int conveyorEndpointBlockCount  = 0;
                            int conveyorLineCount           = 0;
                            int conveyorConnectorCount      = 0;
                            if (myCubeGrid?.GridSystems?.ConveyorSystem != null)
                            {
                                type = myCubeGrid.GridSystems.ConveyorSystem.GetType();
                                conveyorInventoryBlockCount = (type.GetField("m_inventoryBlocks", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(myCubeGrid.GridSystems.ConveyorSystem) as HashSet <MyCubeBlock>).Count;
                                conveyorEndpointBlockCount  = (type.GetField("m_conveyorEndpointBlocks", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(myCubeGrid.GridSystems.ConveyorSystem) as HashSet <IMyConveyorEndpointBlock>).Count;
                                conveyorLineCount           = (type.GetField("m_lines", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(myCubeGrid.GridSystems.ConveyorSystem) as HashSet <MyConveyorLine>).Count;
                                conveyorConnectorCount      = (type.GetField("m_connectors", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(myCubeGrid.GridSystems.ConveyorSystem) as HashSet <MyShipConnector>).Count;
                            }

                            writer.WriteObjectStart();
                            writer.WritePropertyName("DisplayName");
                            writer.Write(myCubeGrid.DisplayName);
                            writer.WritePropertyName("EntityId");
                            writer.Write(myCubeGrid.EntityId);
                            writer.WritePropertyName("PhysicsGroupEntityId");
                            writer.Write(groupEntityId);
                            writer.WritePropertyName("GridSize");
                            writer.Write(myCubeGrid.GridSizeEnum == MyCubeSize.Large ? "Large" : "Small");
                            writer.WritePropertyName("BlocksCount");
                            writer.Write(myCubeGrid.BlocksCount);
                            writer.WritePropertyName("Mass");
                            writer.Write(myCubeGrid.Physics.Mass);
                            writer.WritePropertyName("LinearSpeed");
                            writer.Write(myCubeGrid.Physics.LinearVelocity.Length());
                            writer.WritePropertyName("DistanceToPlayer");
                            writer.Write(MySession.GetPlayerDistance(myCubeGrid, onlinePlayers));
                            writer.WritePropertyName("OwnerSteamId");
                            writer.Write(steamId);
                            writer.WritePropertyName("OwnerDisplayName");
                            writer.Write(displayName);
                            writer.WritePropertyName("OwnerFactionTag");
                            writer.Write(factionTag);
                            writer.WritePropertyName("OwnerFactionName");
                            writer.Write(factionName);
                            writer.WritePropertyName("IsPowered");
                            writer.Write(myCubeGrid.GridSystems.ResourceDistributor.ResourceStateByType(MyResourceDistributorComponent.ElectricityId, withRecompute: false) != MyResourceStateEnum.NoPower);
                            writer.WritePropertyName("PCU");
                            writer.Write(myCubeGrid.BlocksPCU);
                            writer.WritePropertyName("IsConcealed");
                            writer.Write(IsConcealed(myCubeGrid));
                            writer.WritePropertyName("DampenersEnabled");
                            writer.Write(myCubeGrid.DampenersEnabled);
                            writer.WritePropertyName("IsStatic");
                            writer.Write(myCubeGrid.Physics.IsStatic);
                            writer.WritePropertyName("ConveyorSystemInventoryBlockCount");
                            writer.Write(conveyorInventoryBlockCount);
                            writer.WritePropertyName("ConveyorSystemEndpointBlockCount");
                            writer.Write(conveyorEndpointBlockCount);
                            writer.WritePropertyName("ConveyorSystemLineCount");
                            writer.Write(conveyorLineCount);
                            writer.WritePropertyName("ConveyorSystemConnectorCount");
                            writer.Write(conveyorConnectorCount);
                            writer.WriteObjectEnd();
                        }
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/asteroids":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    MyConcurrentHashSet <MyEntity> entities = MyEntities.GetEntities();
                    foreach (MyEntity item in entities)
                    {
                        MyVoxelBase myVoxelBase = item as MyVoxelBase;
                        if (myVoxelBase != null && !(myVoxelBase is MyPlanet) && !myVoxelBase.Closed)
                        {
                            writer.WriteObjectStart();
                            writer.WritePropertyName("DisplayName");
                            writer.Write(myVoxelBase.StorageName);
                            writer.WritePropertyName("EntityId");
                            writer.Write(myVoxelBase.EntityId);
                            writer.WriteObjectEnd();
                        }
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/planets":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    MyConcurrentHashSet <MyEntity> entities = MyEntities.GetEntities();
                    foreach (MyEntity item in entities)
                    {
                        MyPlanet myPlanet = item as MyPlanet;
                        if (myPlanet != null && !myPlanet.Closed)
                        {
                            string storageName = myPlanet.StorageName;
                            long   entityId    = myPlanet.EntityId;
                            writer.WriteObjectStart();
                            writer.WritePropertyName("DisplayName");
                            writer.Write(storageName);
                            writer.WritePropertyName("EntityId");
                            writer.Write(entityId);
                            writer.WriteObjectEnd();
                        }
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/floatingObjects":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    ICollection <MyPlayer>         onlinePlayers = MySession.Static.Players.GetOnlinePlayers();
                    MyConcurrentHashSet <MyEntity> entities      = MyEntities.GetEntities();
                    foreach (MyEntity item in entities)
                    {
                        MyFloatingObject     myFloatingObject     = item as MyFloatingObject;
                        MyInventoryBagEntity myInventoryBagEntity = item as MyInventoryBagEntity;
                        if (myFloatingObject != null || myInventoryBagEntity != null)
                        {
                            string value  = string.Empty;
                            long   value2 = 0L;
                            string value3 = string.Empty;
                            float  value4 = 0f;
                            float  value5 = 0f;
                            float  value6 = 0f;
                            string value7 = string.Empty;
                            if (myFloatingObject != null)
                            {
                                if (myFloatingObject.Closed || myFloatingObject.Physics == null)
                                {
                                    continue;
                                }
                                value  = myFloatingObject.DisplayName;
                                value2 = myFloatingObject.EntityId;
                                value3 = "FloatingObject";
                                value4 = myFloatingObject.Physics.Mass;
                                value5 = myFloatingObject.Physics.LinearVelocity.Length();
                                value6 = MySession.GetPlayerDistance(myFloatingObject, onlinePlayers);
                                var def = MyDefinitionManager.Static.GetPhysicalItemDefinition(new MyDefinitionId(myFloatingObject.Item.Content.TypeId, myFloatingObject.Item.Content.SubtypeId));
                                value7 = def.DisplayNameText;
                            }
                            else if (myInventoryBagEntity != null)
                            {
                                if (myInventoryBagEntity.Closed || myInventoryBagEntity.Physics == null)
                                {
                                    continue;
                                }
                                value  = myInventoryBagEntity.DisplayName;
                                value2 = myInventoryBagEntity.EntityId;
                                value3 = "Bag";
                                value4 = myInventoryBagEntity.Physics.Mass;
                                value5 = myInventoryBagEntity.Physics.LinearVelocity.Length();
                                value6 = MySession.GetPlayerDistance(myInventoryBagEntity, onlinePlayers);
                                value7 = "Bag";
                            }
                            writer.WriteObjectStart();
                            writer.WritePropertyName("DisplayName");
                            writer.Write(value);
                            writer.WritePropertyName("EntityId");
                            writer.Write(value2);
                            writer.WritePropertyName("Kind");
                            writer.Write(value3);
                            writer.WritePropertyName("Mass");
                            writer.Write(value4);
                            writer.WritePropertyName("LinearSpeed");
                            writer.Write(value5);
                            writer.WritePropertyName("DistanceToPlayer");
                            writer.Write(value6);
                            writer.WritePropertyName("TypeDisplayName");
                            writer.Write(value7);
                            writer.WriteObjectEnd();
                        }
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/factions":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    List <MyFaction> factions = MySession.Static.Factions.Select((x) => x.Value).ToList();
                    foreach (MyFaction myfaction in factions)
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("AcceptHumans");
                        writer.Write(myfaction.AcceptHumans);
                        writer.WritePropertyName("AutoAcceptMember");
                        writer.Write(myfaction.AutoAcceptMember);
                        writer.WritePropertyName("AutoAcceptPeace");
                        writer.Write(myfaction.AutoAcceptPeace);
                        writer.WritePropertyName("EnableFriendlyFire");
                        writer.Write(myfaction.EnableFriendlyFire);
                        writer.WritePropertyName("FactionId");
                        writer.Write(myfaction.FactionId);
                        writer.WritePropertyName("FounderId");
                        writer.Write(myfaction.FounderId);
                        writer.WritePropertyName("MemberCount");
                        writer.Write(myfaction.Members.Count);
                        writer.WritePropertyName("Name");
                        writer.Write(myfaction.Name);
                        writer.WritePropertyName("Tag");
                        writer.Write(myfaction.Tag);
                        writer.WritePropertyName("NPCOnly");
                        writer.Write(myfaction.Members.All((x) => MySession.Static.Players.IdentityIsNpc(x.Value.PlayerId)));
                        writer.WriteObjectEnd();
                    }
                }
                writer.WriteArrayEnd();
                break;
            }

            return(sb.ToString());
        }
예제 #16
0
 // Should stay internal, we do not want to anything outside of StateMachines to use
 // Expand methods.
 internal void Expand(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions)
 {
     ExpandInternal(cursor, enquedActions, 100);
 }
예제 #17
0
 // Should stay internal, we do not want to anything outside of StateMachines to use
 // Expand methods.
 internal void Expand(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions)
 {
     ExpandInternal(cursor, enquedActions, 100);
 }
예제 #18
0
        public static List <MyEntityListInfoItem> GetEntityList(MyEntityTypeEnum selectedType)
        {
            MyConcurrentHashSet <MyEntity> entities      = MyEntities.GetEntities();
            List <MyEntityListInfoItem>    list          = new List <MyEntityListInfoItem>(entities.Count);
            ICollection <MyPlayer>         onlinePlayers = MySession.Static.Players.GetOnlinePlayers();

            switch (selectedType)
            {
            case MyEntityTypeEnum.Grids:
            case MyEntityTypeEnum.SmallGrids:
            case MyEntityTypeEnum.LargeGrids:
                foreach (MyCubeGrid grid in entities)
                {
                    if (grid == null)
                    {
                        continue;
                    }
                    if (((selectedType != MyEntityTypeEnum.LargeGrids) || (grid.GridSizeEnum != MyCubeSize.Small)) && ((((selectedType != MyEntityTypeEnum.SmallGrids) || (grid.GridSizeEnum != MyCubeSize.Large)) && (!grid.Closed && (grid.Physics != null))) && ReferenceEquals(MyGridPhysicalHierarchy.Static.GetRoot(grid), grid)))
                    {
                        CreateListInfoForGrid(grid, out m_gridItem);
                        AccountChildren(grid);
                        list.Add(m_gridItem);
                    }
                }
                return(list);

            case MyEntityTypeEnum.Characters:
                break;

            case MyEntityTypeEnum.FloatingObjects:
                foreach (MyEntity entity in entities)
                {
                    MyFloatingObject obj2 = entity as MyFloatingObject;
                    if (obj2 != null)
                    {
                        if (obj2.Closed)
                        {
                            continue;
                        }
                        if (obj2.Physics == null)
                        {
                            continue;
                        }
                        list.Add(new MyEntityListInfoItem(obj2.DisplayName, obj2.EntityId, 0, 0, obj2.Physics.Mass, obj2.PositionComp.GetPosition(), obj2.Physics.LinearVelocity.Length(), MySession.GetPlayerDistance(obj2, onlinePlayers), "", 0L, 0f, 0f));
                    }
                    MyInventoryBagEntity entity2 = entity as MyInventoryBagEntity;
                    if (((entity2 != null) && !entity2.Closed) && (entity2.Physics != null))
                    {
                        MyIdentity identity2   = MySession.Static.Players.TryGetIdentity(entity2.OwnerIdentityId);
                        string     ownerName   = "";
                        float      ownerLogin  = 0f;
                        float      ownerLogout = 0f;
                        if (identity2 != null)
                        {
                            ownerName   = identity2.DisplayName;
                            ownerLogin  = (int)(DateTime.Now - identity2.LastLoginTime).TotalSeconds;
                            ownerLogout = (int)(DateTime.Now - identity2.LastLogoutTime).TotalSeconds;
                        }
                        list.Add(new MyEntityListInfoItem(entity2.DisplayName, entity2.EntityId, 0, 0, entity2.Physics.Mass, entity2.PositionComp.GetPosition(), entity2.Physics.LinearVelocity.Length(), MySession.GetPlayerDistance(entity2, onlinePlayers), ownerName, entity2.OwnerIdentityId, ownerLogin, ownerLogout));
                    }
                }
                return(list);

            case MyEntityTypeEnum.Planets:
                foreach (MyPlanet planet in entities)
                {
                    if (planet == null)
                    {
                        continue;
                    }
                    if (!planet.Closed)
                    {
                        list.Add(new MyEntityListInfoItem(planet.StorageName, planet.EntityId, 0, 0, 0f, planet.PositionComp.GetPosition(), 0f, MySession.GetPlayerDistance(planet, onlinePlayers), "", 0L, 0f, 0f));
                    }
                }
                return(list);

            case MyEntityTypeEnum.Asteroids:
                foreach (MyVoxelBase base2 in entities)
                {
                    if (base2 == null)
                    {
                        continue;
                    }
                    if (!(base2 is MyPlanet) && !base2.Closed)
                    {
                        list.Add(new MyEntityListInfoItem(base2.StorageName, base2.EntityId, 0, 0, 0f, base2.PositionComp.GetPosition(), 0f, MySession.GetPlayerDistance(base2, onlinePlayers), "", 0L, 0f, 0f));
                    }
                }
                return(list);

            default:
                throw new ArgumentOutOfRangeException();
            }
            foreach (MyIdentity identity in MySession.Static.Players.GetAllIdentities())
            {
                MyPlayer.PlayerId id;
                string            displayName = identity.DisplayName;
                if (Sync.Players.TryGetPlayerId(identity.IdentityId, out id))
                {
                    MyPlayer player = null;
                    if (!Sync.Players.TryGetPlayerById(id, out player))
                    {
                        object[] objArray1 = new object[] { displayName, " (", MyTexts.Get(MyCommonTexts.OfflineStatus), ")" };
                        displayName = string.Concat(objArray1);
                    }
                }
                if (identity.Character != null)
                {
                    list.Add(new MyEntityListInfoItem(displayName, identity.Character.EntityId, 0, 0, identity.Character.CurrentMass, identity.Character.PositionComp.GetPosition(), identity.Character.Physics.LinearVelocity.Length(), 0f, identity.DisplayName, identity.IdentityId, (float)((int)(DateTime.Now - identity.LastLoginTime).TotalSeconds), (float)((int)(DateTime.Now - identity.LastLogoutTime).TotalSeconds)));
                }
                else
                {
                    foreach (long num in identity.SavedCharacters)
                    {
                        MyCharacter character;
                        if (MyEntities.TryGetEntityById <MyCharacter>(num, out character, false))
                        {
                            list.Add(new MyEntityListInfoItem(displayName, num, 0, 0, character.CurrentMass, character.PositionComp.GetPosition(), character.Physics.LinearVelocity.Length(), 0f, identity.DisplayName, identity.IdentityId, (float)((int)(DateTime.Now - identity.LastLoginTime).TotalSeconds), (float)((int)(DateTime.Now - identity.LastLogoutTime).TotalSeconds)));
                        }
                    }
                }
            }
            return(list);
        }
예제 #19
0
        public static List <IMySlimBlock> GetBlocksContactingVoxel(IMyCubeGrid grid, MyPlanet planet, out byte voxelType)
        {
            Vector3D[] corners = grid.WorldAABB.GetCorners();
            if (corners.All(c => Vector3D.DistanceSquared(c, planet.GetClosestSurfacePointGlobal(c)) > 2500))
            {
                voxelType = 0;
                return(new List <IMySlimBlock>());
            }

            Vector3D planetPos = planet.PositionComp.GetPosition();

            var result = new MyConcurrentHashSet <IMySlimBlock>();
            var blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks);
            byte id = 0;

            MyAPIGateway.Parallel.ForEach(blocks, block =>
            {
                try
                {
                    var b = block.GetPosition();
                    Vector3D closestSurfacePoint = planet.GetClosestSurfacePointGlobal(ref b);

                    if (Vector3D.DistanceSquared(planetPos, closestSurfacePoint) > Vector3D.DistanceSquared(planetPos, b))
                    {
                        var hits = new List <IHitInfo>();
                        MyAPIGateway.Physics.CastRay(b, closestSurfacePoint, hits);
                        foreach (IHitInfo hit in hits)
                        {
                            if (hit.HitEntity is IMyVoxelBase)
                            {
                                closestSurfacePoint = hit.Position;
                            }
                        }
                    }

                    double cd = Vector3D.DistanceSquared(b, closestSurfacePoint);
                    if (cd > 200)
                    {
                        return;
                    }

                    if (cd > 6.25)
                    {
                        BoundingBoxD box;
                        block.GetWorldBoundingBox(out box, true);
                        Vector3D[] bc = box.GetCorners();
                        if (bc.All(c => Vector3D.DistanceSquared(c, planet.GetClosestSurfacePointGlobal(c)) > 6.25))
                        {
                            return;
                        }
                    }

                    MyVoxelMaterialDefinition mat = planet.GetMaterialAt_R(ref closestSurfacePoint);
                    if (Config.VOXEL_IDS.ContainsKey(mat.Index))
                    {
                        result.Add(block);
                    }
                    id = mat.Index;
                }
                catch
                {
                    //meh!
                }
            });
            voxelType = id;
            return(result.ToList());

            /*
             * var chunks = new HashSet<Vector3I[]>();
             *
             * int chunkSize = grid.GridSizeEnum == MyCubeSize.Large ? 3 : 5;
             * for (int x = grid.Min.X; x < grid.Max.X + chunkSize; x += chunkSize)
             * {
             *  for (int y = grid.Min.Y; y < grid.Max.Y + chunkSize; y += chunkSize)
             *  {
             *      for (int z = grid.Min.Z; z < grid.Max.Z + chunkSize; z += chunkSize)
             *      {
             *          chunks.Add(new[]
             *                     {
             *                         new Vector3I(x, y, z),
             *                         new Vector3I(x + chunkSize, y, z),
             *                         new Vector3I(x, y + chunkSize, z),
             *                         new Vector3I(x, y, z + chunkSize),
             *                         new Vector3I(x + chunkSize, y + chunkSize, z),
             *                         new Vector3I(x + chunkSize, y, z + chunkSize),
             *                         new Vector3I(x, y + chunkSize, z + chunkSize),
             *                         new Vector3I(x + chunkSize, y + chunkSize, z + chunkSize),
             *                     });
             *      }
             *  }
             * }
             *
             * MyAPIGateway.Parallel.ForEach(chunks, chunk =>
             *                                    {
             *                                        var success = false;
             *                                        foreach (Vector3I pos in chunk)
             *                                        {
             *                                            Vector3D d = grid.GridIntegerToWorld(pos);
             *                                            Vector3D s = planet.GetClosestSurfacePointGlobal(ref d);
             *                                            if (Vector3D.DistanceSquared(d, s) > 6.25)
             *                                                continue;
             *
             *                                            if (!Config.VOXEL_IDS.ContainsKey(planet.GetMaterialAt_R(ref s).Index))
             *                                                continue;
             *                                            success = true;
             *                                            break;
             *                                        }
             *
             *                                        if (!success)
             *                                            return;
             *
             *                                        foreach (Vector3I pos in chunk)
             *                                        {
             *                                            IMySlimBlock block = grid.GetCubeBlock(pos);
             *                                            if (block != null)
             *                                                result.Add(block);
             *                                        }
             *                                    });
             *
             * return result.ToList();
             */
        }
예제 #20
0
 public ConcurrentUniqueQueue()
 {
     _hashSet = new MyConcurrentHashSet <T>();
     _queue   = new ConcurrentQueue <T>();
 }
        private static void EnqueueHistory(MyVoxelDataRequest request)
        {
            using (m_historyLock.AcquireExclusiveUsing())
            {
                if (UnculledRequestHistory.Count >= MAX_UNCULLED_HISTORY)
                {
                    UnculledRequestHistory.Dequeue();
                }

                request.Target = null;
                UnculledRequestHistory.Enqueue(request);
            }

            MyConcurrentHashSet<Vector3I> sizes;
            if (!KnownLodSizes.TryGetValue(request.Lod, out sizes))
            {
                sizes = new MyConcurrentHashSet<Vector3I>();
                if (!KnownLodSizes.TryAdd(request.Lod, sizes))
                {
                    sizes = KnownLodSizes[request.Lod];
                }

            }

            sizes.Add(request.maxInLod - request.minInLod + Vector3I.One);
        }