Exemplo n.º 1
0
        /// <summary>Removes the specified system from this manager.</summary>
        /// <param name="system">The system to remove.</param>
        /// <returns>Whether the system was successfully removed.</returns>
        public bool RemoveSystem(AbstractSystem system)
        {
            // Make sure we have a valid system.
            Debug.Assert(system != null);

            // Get type ID for that system.
            var systemTypeId = GetSystemTypeId(system.GetType());

            // Check if we even have that system.
            if (_systemsByTypeId[systemTypeId] == null)
            {
                return(false);
            }

            // Unregister the system.
            _systems.Remove(system);

            while (systemTypeId != 0)
            {
                _systemsByTypeId[systemTypeId] = null;
                systemTypeId = SystemHierarchy[systemTypeId];
            }

            system.Manager = null;

            foreach (var messageType in GetMessageCallbackTypes(system.GetType()))
            {
                RebuildMessageDispatcher(messageType);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>Adds a copy of the specified system.</summary>
        /// <param name="system">The system to copy.</param>
        public void CopySystem(AbstractSystem system)
        {
            var systemTypeId = GetSystemTypeId(system.GetType());

            if (_systemsByTypeId[systemTypeId] == null)
            {
                AddSystem(system.NewInstance());
            }
            Debug.Assert(_systemsByTypeId[systemTypeId] != null);
            system.CopyInto(_systemsByTypeId[systemTypeId]);
        }
Exemplo n.º 3
0
        /// <summary>Add the specified system to this manager.</summary>
        /// <param name="system">The system to add.</param>
        /// <returns>This manager, for chaining.</returns>
        public IManager AddSystem(AbstractSystem system)
        {
            // Get type ID for that system.
            var systemTypeId = GetSystemTypeId(system.GetType());

            // Don't allow adding the same system twice.
            if (_systemsByTypeId[systemTypeId] != null)
            {
                throw new ArgumentException("You can not add more than one system of a single type.");
            }

            // Look for message callbacks in the system. This throws if a callback signature is invalid,
            // which is why we want to do this before registering the system.
            var messageTypes = GetMessageCallbackTypes(system.GetType());

            // Add to general list, for serialization and hashing and general iteration.
            _systems.Add(system);

            // Register the system by type, for fast lookup.
            while (systemTypeId != 0)
            {
                _systemsByTypeId[systemTypeId] = system;
                systemTypeId = SystemHierarchy[systemTypeId];
            }

            // Set the manager so that the system knows it belongs to us.
            system.Manager = this;

            // Rebuild message dispatchers for all changed types.
            foreach (var messageType in messageTypes)
            {
                RebuildMessageDispatcher(messageType);
            }

            // Tell the system it was added.
            system.OnAddedToManager();

            return(this);
        }
Exemplo n.º 4
0
            /// <summary>Add the specified system to this manager.</summary>
            /// <param name="system">The system to add.</param>
            /// <returns>This manager, for chaining.</returns>
            public IManager AddSystem(AbstractSystem system)
            {
                if (_tss.CurrentFrame > 0)
                {
                    throw new InvalidOperationException("Cannot add systems after simulation has started.");
                }

                if (system.GetType().IsDefined(typeof(PresentationOnlyAttribute), true))
                {
                    // Only insert in leading simulation.
                    _tss.LeadingSimulation.Manager.AddSystem(system);
                }
                else
                {
                    // Insert in all simulations.
                    foreach (var state in _tss._simulations)
                    {
                        state.Manager.CopySystem(system);
                    }
                }

                return(this);
            }
Exemplo n.º 5
0
 public void AddSystem(AbstractSystem system)
 {
     this.systems.Add(system.GetType().Name, system);
 }