/// <summary>
        /// Gets the specified <see cref="List{T}"/>.
        /// </summary>
        /// <value>
        /// The <see cref="List{T}"/>.
        /// </value>
        /// <param name="sequence">The sublist.</param>
        /// <returns></returns>
        public List <T> this[CNMAttrSequence.options sequence]
        {
            get
            {
                switch (sequence)
                {
                case CNMAttrSequence.options.EARLY: return(this.Early);

                case CNMAttrSequence.options.LATE: return(this.Late);

                case CNMAttrSequence.options.POST: return(this.Post);

                default: return(null);
                }
            }
        }
Exemple #2
0
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            CNMHomeComponent instance = modularRefs[methodTypes[method]];

    #if DEBUG
            Debug.LogFormat("CNMHome: Parsing {0} from {1} as {2}.", methodName, instance.GetType().Name, sequence);
    #endif

            try
            {
                switch (methodName)
                {
                case "CreateNode":
                    Sequence_CreateNode.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkInitialized":
                    Sequence_OnNetworkInitialized.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkPreUpdate":
                    Sequence_OnNetworkPreUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "Start":
                    Sequence_Start.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "Update":
                    Sequence_Update.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                default:
    #if DEBUG
                    log.warning("The method passed (" + methodName + ") was not a standard CommNet method.");
    #endif
                    return;
                }
                log.debug("Successfully parsed " + methodName + " from type " + instance.GetType().Name);
            }
            catch (Exception ex)
            {
                log.error("Encountered an error creating a delegate for " + methodName + " from type " + instance.GetType().Name);
                log.error(ex);
            }
        }
        /// <summary>
        /// Removes all elements from sublist of the <see cref="SequenceList{T}"/>.
        /// </summary>
        public virtual void Clear(CNMAttrSequence.options sequence)
        {
            switch (sequence)
            {
            case CNMAttrSequence.options.EARLY:
                this.Early.Clear();
                dirty[0] = true;
                break;

            case CNMAttrSequence.options.LATE:
                this.Late.Clear();
                dirty[1] = true;
                break;

            case CNMAttrSequence.options.POST:
                this.Post.Clear();
                dirty[2] = true;
                break;
            }
            dirty[3] = true;
        }
        /// <summary>
        /// Removes the first instance of an object from the specified sublist of the <see cref="SequenceList{T}"/>.
        /// </summary>
        /// <param name="sequence">The sublist.</param>
        /// <param name="obj">The object to remove.</param>
        public virtual void Remove(CNMAttrSequence.options sequence, T obj)
        {
            switch (sequence)
            {
            case CNMAttrSequence.options.EARLY:
                this.Early.Remove(obj);
                dirty[0] = true;
                break;

            case CNMAttrSequence.options.LATE:
                this.Late.Remove(obj);
                dirty[1] = true;
                break;

            case CNMAttrSequence.options.POST:
                this.Post.Remove(obj);
                dirty[2] = true;
                break;
            }
            dirty[3] = true;
        }
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            ModularCommNetVesselComponent instance = modularRefs[methodTypes[method]];

    #if DEBUG
            if (andOrList.ContainsKey(method))
            {
                Debug.LogFormat("ModularCommNetVessel: Parsing {0} from {1} as {2} with {3}.", methodName, instance.GetType().Name, sequence, andOrList[method]);
            }
            else
            {
                Debug.LogFormat("ModularCommNetVessel: Parsing {0} from {1} as {2}.", methodName, instance.GetType().Name, sequence);
            }
    #endif

            try
            {
                switch (methodName)
                {
                case "Awake":
                    Sequence_Awake.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnAwake":
                    Sequence_OnAwake.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnStart":
                    Sequence_OnStart.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnDestroy":
                    Sequence_OnDestroy.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnGoOffRails":
                    Sequence_OnGoOffRails.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnGoOnRails":
                    Sequence_OnGoOnRails.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnLoad":
                    Sequence_OnLoad.Add(sequence, Delegate.CreateDelegate(typeof(Action <ConfigNode>), instance, method) as Action <ConfigNode>, instance);
                    break;

                case "OnSave":
                    Sequence_OnSave.Add(sequence, Delegate.CreateDelegate(typeof(Action <ConfigNode>), instance, method) as Action <ConfigNode>, instance);
                    break;

                case "Update":
                    Sequence_Update.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "OnNetworkInitialized":
                    Sequence_OnNetworkInitialized.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkPreUpdate":
                    Sequence_OnNetworkPreUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkPostUpdate":
                    Sequence_OnNetworkPostUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "CalculatePlasmaMult":
                    Sequence_CalculatePlasmaMult.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "UpdateComm":
                    Sequence_UpdateComm.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "CreateControlConnection":
                    Sequence_CreateControlConnection.Add(sequence, Delegate.CreateDelegate(typeof(Func <bool>), instance, method) as Func <bool>, new Pair <CNMAttrAndOr.options, ModularCommNetVesselComponent>(andOrList[method], instance));
                    break;

                case "GetBestTransmitter":
                    Sequence_GetBestTransmitter.Add(sequence, Delegate.CreateDelegate(typeof(Func <IScienceDataTransmitter>), instance, method) as Func <IScienceDataTransmitter>, instance);
                    break;

                case "GetControlLevel":
                    Sequence_GetControlLevel.Add(sequence, Delegate.CreateDelegate(typeof(Func <Vessel.ControlLevel>), instance, method) as Func <Vessel.ControlLevel>, instance);
                    break;

                case "OnMapFocusChange":
                    Sequence_OnMapFocusChange.Add(sequence, Delegate.CreateDelegate(typeof(Action <MapObject>), instance, method) as Action <MapObject>);
                    break;

                case "GetSignalStrengthModifier":
                    Sequence_GetSignalStrengthModifier.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, double>), instance, method) as Func <CommNode, double>, instance);
                    break;

                default:
    #if DEBUG
                    log.warning("The method passed (" + methodName + ") was not a standard CommNet method.");
    #endif
                    return;
                }
                log.debug("Successfully parsed " + methodName + " from type " + instance.GetType().Name);
            }
            catch (Exception ex)
            {
                log.error("Encountered an error creating a delegate for " + methodName + " from type " + instance.GetType().Name);
                log.error(ex);
            }
        }
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            CommNetwork networkInstance = commNetworks[methodTypes[method]];

    #if DEBUG
            if (andOrList.ContainsKey(method))
            {
                Debug.LogFormat("CommNetManager: Parsing {0} from {1} as {2} with {3}.", methodName, networkInstance.GetType().Name, sequence, andOrList[method]);
            }
            else
            {
                Debug.LogFormat("CommNetManager: Parsing {0} from {1} as {2}.", methodName, networkInstance.GetType().Name, sequence);
            }
    #endif
            try
            {
                switch (methodName)
                {
                case "SetNodeConnection":
                    Sequence_SetNodeConnection.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, bool>), networkInstance, method) as Func <CommNode, CommNode, bool>, andOrList[method]);
                    break;

                case "Add_CommNode":
                    Sequence_Add_CommNode.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode>), networkInstance, method) as Func <CommNode, CommNode>);
                    break;

                case "Add_Occluder":
                    Sequence_Add_Occluder.Add(sequence, Delegate.CreateDelegate(typeof(Func <Occluder, Occluder>), networkInstance, method) as Func <Occluder, Occluder>);
                    break;

                case "Connect":
                    Sequence_Connect.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, double, CommLink>), networkInstance, method) as Func <CommNode, CommNode, double, CommLink>);
                    break;

                case "CreateShortestPathTree":
                    Sequence_CreateShortestPathTree.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode>), networkInstance, method) as Action <CommNode, CommNode>);
                    break;

                case "Disconnect":
                    Sequence_Disconnect.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode, bool>), networkInstance, method) as Action <CommNode, CommNode, bool>, andOrList[method]);
                    break;

                case "FindClosestControlSource":
                    Sequence_FindClosestControlSource.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, bool>), networkInstance, method) as Func <CommNode, CommPath, bool>, andOrList[method]);
                    break;

                case "FindClosestWhere":
                    Sequence_FindClosestWhere.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, Func <CommNode, CommNode, bool>, CommNode>), networkInstance, method) as Func <CommNode, CommPath, Func <CommNode, CommNode, bool>, CommNode>);
                    break;

                case "FindHome":
                    Sequence_FindHome.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, bool>), networkInstance, method) as Func <CommNode, CommPath, bool>, andOrList[method]);
                    break;

                case "FindPath":
                    Sequence_FindPath.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, CommNode, bool>), networkInstance, method) as Func <CommNode, CommPath, CommNode, bool>, andOrList[method]);
                    break;

                case "GetLinkPoints":
                    Sequence_GetLinkPoints.Add(sequence, Delegate.CreateDelegate(typeof(Action <List <Vector3> >), networkInstance, method) as Action <List <Vector3> >);
                    break;

                case "PostUpdateNodes":
                    Sequence_PostUpdateNodes.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "PreUpdateNodes":
                    Sequence_PreUpdateNodes.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "Rebuild":
                    Sequence_Rebuild.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "Remove_CommNode":
                    Sequence_Remove_CommNode.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, bool>), networkInstance, method) as Func <CommNode, bool>, andOrList[method]);
                    break;

                case "Remove_Occluder":
                    Sequence_Remove_Occluder.Add(sequence, Delegate.CreateDelegate(typeof(Func <Occluder, bool>), networkInstance, method) as Func <Occluder, bool>, andOrList[method]);
                    break;

                case "TestOcclusion":
                    Sequence_TestOcclusion.Add(sequence, Delegate.CreateDelegate(typeof(Func <Vector3d, Occluder, Vector3d, Occluder, double, bool>), networkInstance, method) as Func <Vector3d, Occluder, Vector3d, Occluder, double, bool>, andOrList[method]);
                    break;

                case "TryConnect":
                    Sequence_TryConnect.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, double, bool, bool, bool, bool>), networkInstance, method) as Func <CommNode, CommNode, double, bool, bool, bool, bool>, andOrList[method]);
                    break;

                case "UpdateNetwork":
                    Sequence_UpdateNetwork.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "UpdateShortestPath":
                    Sequence_UpdateShortestPath.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode, CommLink, double, CommNode, CommNode>), networkInstance, method) as Action <CommNode, CommNode, CommLink, double, CommNode, CommNode>);
                    break;

                case "UpdateShortestWhere":
                    Sequence_UpdateShortestWhere.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, CommLink, double, CommNode, Func <CommNode, CommNode, bool>, CommNode>), networkInstance, method) as Func <CommNode, CommNode, CommLink, double, CommNode, Func <CommNode, CommNode, bool>, CommNode>);
                    break;

                default:
    #if DEBUG
                    log.warning("The method passed (" + methodName + ") was not a standard CommNet method.");
    #endif
                    return;
                }
                log.debug("Successfully parsed " + methodName + " from type " + networkInstance.GetType().Name);
            }
            catch (Exception ex)
            {
                log.error("Encountered an error creating a delegate for " + methodName + " from type " + networkInstance.GetType().Name);
                log.error(ex);
            }
        }