コード例 #1
0
        /// <summary>
        /// Instantiates the modular types.
        /// </summary>
        internal void InstantiateModularTypes()
        {
            modularRefs.Clear();
            Components.Clear();
            Sequence_CreateOccluder.Clear();
            Sequence_OnNetworkInitialized.Clear();
            Sequence_OnNetworkPreUpdate.Clear();
            Sequence_Start.Clear();

            log.debug("Instantiate " + modularTypes.Count);
            foreach (Type type in modularTypes)
            {
                if (type == typeof(CNMBodyComponent))
                {
                    log.debug("Skipping type " + type.Name);
                    continue;
                }
                AttachComponent(type);
            }
            foreach (SequenceList <MethodInfo> methodList in methodsSequence.Values)
            {
                foreach (MethodInfo method in methodList.Early)
                {
                    if (!modularRefs.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.EARLY);
                }
                foreach (MethodInfo method in methodList.Late)
                {
                    if (!modularRefs.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.LATE);
                }
                foreach (MethodInfo method in methodList.Post)
                {
                    if (!modularRefs.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.POST);
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///Clear 的测试
        ///</summary>
        public void ClearTestHelper <T>()
        {
            int size = 10;                                        // TODO: 初始化为适当的值
            SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值


            target.Append(default(T));

            target.Clear();

            Assert.AreEqual(-1, target.Last);

            Assert.AreEqual(0, target.GetLength());

            //Assert.IsNull(target.Data);
        }
コード例 #3
0
        public void Test()
        {
            SequenceList <int> list = new SequenceList <int>(5);

            // 1, 2, 3, 4
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            Assert.Equal(4, list.Length);
            Assert.Equal(2, list[1]);

            // 1, 2, 3, 4
            // 1, 2, 3, 5
            list[3] = 5;
            Assert.Equal(4, list.Length);
            Assert.Equal(5, list[3]);

            // 1,    2, 3, 5
            // 1, 8, 2, 3, 5
            list.Insert(1, 8);
            Assert.Equal(5, list.Length);
            Assert.Equal(8, list[1]);
            Assert.Equal(2, list[2]);

            // 1, 8, 2, 3, 5
            // 1,    2, 3, 5
            int removedItem = list.RemoveAt(1);

            Assert.Equal(4, list.Length);
            Assert.Equal(8, removedItem);
            Assert.Equal(2, list[1]);

            list.Clear();
            Assert.Equal(0, list.Length);
        }
コード例 #4
0
        /// <summary>
        /// Instantiates the modular types.
        /// </summary>
        public void InstantiateModularTypes()
        {
            LoadModularTypes();
            modularRefs.Clear();
            this.Components = new List <ModularCommNetVesselComponent>();
            Sequence_Awake.Clear();
            Sequence_OnAwake.Clear();
            Sequence_OnStart.Clear();
            Sequence_OnDestroy.Clear();
            Sequence_OnGoOffRails.Clear();
            Sequence_OnGoOnRails.Clear();
            Sequence_OnLoad.Clear();
            Sequence_OnSave.Clear();
            Sequence_Update.Clear();
            Sequence_OnNetworkInitialized.Clear();
            Sequence_OnNetworkPreUpdate.Clear();
            Sequence_OnNetworkPostUpdate.Clear();
            Sequence_CalculatePlasmaMult.Clear();
            Sequence_UpdateComm.Clear();
            Sequence_CreateControlConnection.Clear();
            Sequence_GetBestTransmitter.Clear();
            Sequence_GetControlLevel.Clear();
            Sequence_OnMapFocusChange.Clear();
            Sequence_GetSignalStrengthModifier.Clear();

            log.debug("Instantiate " + modularTypes.Count);
            foreach (Type type in modularTypes)
            {
                if (type == typeof(ModularCommNetVesselComponent))
                {
                    log.debug("Skipping type " + type.Name);
                    continue;
                }
                AttachComponent(type);
            }
            foreach (SequenceList <MethodInfo> methodList in methodsSequence.Values)
            {
                foreach (MethodInfo method in methodList.Early)
                {
                    if (!modularRefs.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.EARLY);
                }
                foreach (MethodInfo method in methodList.Late)
                {
                    if (!modularRefs.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.LATE);
                }
                foreach (MethodInfo method in methodList.Post)
                {
                    if (!modularRefs.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.POST);
                }
            }
        }
コード例 #5
0
        public CommNetManagerNetwork()
        {
            if (Instance != null)
            {
                log.warning("CommNetManagerNetwork.Instance was not null.");
            }
            Instance = this;

            commNetworks.Clear();
            Sequence_SetNodeConnection.Clear();
            Sequence_Add_CommNode.Clear();
            Sequence_Add_Occluder.Clear();
            Sequence_Connect.Clear();
            Sequence_CreateShortestPathTree.Clear();
            Sequence_Disconnect.Clear();
            Sequence_FindClosestControlSource.Clear();
            Sequence_FindClosestWhere.Clear();
            Sequence_FindHome.Clear();
            Sequence_FindPath.Clear();
            Sequence_GetLinkPoints.Clear();
            Sequence_PostUpdateNodes.Clear();
            Sequence_PreUpdateNodes.Clear();
            Sequence_Rebuild.Clear();
            Sequence_Remove_CommNode.Clear();
            Sequence_Remove_Occluder.Clear();
            Sequence_TestOcclusion.Clear();
            Sequence_TryConnect.Clear();
            Sequence_UpdateNetwork.Clear();
            Sequence_UpdateShortestPath.Clear();
            Sequence_UpdateShortestWhere.Clear();

            if (!methodsLoaded)
            {
                CommNetManagerNetwork.Initiate();
            }
            log.debug(networkTypes.Count);
            foreach (Type type in networkTypes)
            {
                if (type == typeof(CommNetwork) || type == typeof(CommNetManagerNetwork))
                {
                    log.debug("Skipping type " + type.Name);
                    continue;
                }
                CommNetwork typeNetworkInstance = null;
                try
                {
                    typeNetworkInstance = Activator.CreateInstance(type) as CommNetwork;
                }
                catch (Exception ex)
                {
                    log.error("Encountered an exception while calling the constructor for " + type.Name);
                    log.error(ex);
                }
                if (typeNetworkInstance != null)
                {
                    commNetworks.Add(type, typeNetworkInstance);
                    log.info("Activated an instance of type: " + type.Name);
                }
                else
                {
                    log.warning("Failed to activate " + type.Name);
                }
            }
            foreach (SequenceList <MethodInfo> methodList in methodsSequence.Values)
            {
                foreach (MethodInfo method in methodList.Early)
                {
                    if (!commNetworks.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.EARLY);
                }
                foreach (MethodInfo method in methodList.Late)
                {
                    if (!commNetworks.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.LATE);
                }
                foreach (MethodInfo method in methodList.Post)
                {
                    if (!commNetworks.ContainsKey(methodTypes[method]))
                    {
                        log.warning("No instance of the CommNetwork type (" + methodTypes[method].DeclaringType.FullName.ToString() + ") was instantiated.");
                        continue;
                    }
                    ParseDelegates(method.Name, method, CNMAttrSequence.options.POST);
                }
            }
        }