public void SetToggleConfig(ManagedUpdatesBehaviour component, ObjectToggleConfig toggleConfig)
 {
     component.gameObject.SetActive(toggleConfig.HasFlag(ObjectToggleConfig.GameObjectActive));
     component.enabled                  = toggleConfig.HasFlag(ObjectToggleConfig.ComponentEnabled);
     component.updateConfig.update      = toggleConfig.HasFlag(ObjectToggleConfig.Update);
     component.updateConfig.fixedUpdate = toggleConfig.HasFlag(ObjectToggleConfig.FixedUpdate);
 }
        private static void RunToggleTest(FakeEnvironment env, ObjectToggleConfig initialConfig, ObjectToggleConfig finalConfig)
        {
            // Arrange
            TestBasicManagedUpdatesComponent[] components;
            env.InstantiateManagedComponents <TestBasicManagedUpdatesComponent>(
                out components,
                TestData.DEFAULT_GROUP_NAME,
                initialConfig
                );

            FakeEnvironment.GetExpectedUpdateFlagsFromConfig(
                finalConfig,
                out bool updateExpectedFinal,
                out bool fixedUpdateExpectedFinal
                );

            // Act
            ManagedUpdatesBehaviour component = components[0];

            env.SetToggleConfig(component, finalConfig);

            // Assert
            env.system.FindComponent(component.GetInstanceID(), out bool updateFound, out bool fixedUpdateFound);
            Assert.That(
                (updateExpectedFinal == updateFound) && (fixedUpdateExpectedFinal == fixedUpdateFound),
                $"Configuration's expected state was not reflected in the system.\n" +
                $"Update Expected/Result: {updateExpectedFinal}/{updateFound}\n" +
                $"FixedUpdate Expected/Result: {fixedUpdateExpectedFinal}/{fixedUpdateFound}"
                );
        }
Esempio n. 3
0
        private void Add(ManagedUpdatesBehaviour node, ManagedUpdatesBehaviour prev, ManagedUpdatesBehaviour next)
        {
            node.nextFixedUpdate     = next;
            node.previousFixedUpdate = prev;

            next.previousFixedUpdate = node;
            prev.nextFixedUpdate     = node;
        }
 private T InstantiateManagedUpdateGameObject <T>(
     ManagedExecutionGroup group,
     ObjectToggleConfig config,
     Transform parent = null) where T : ManagedUpdatesBehaviour
 {
     return(ManagedUpdatesBehaviour.Create <T>(
                new ManagedUpdatesBehaviour.Config(
                    group,
                    config.HasFlag(ObjectToggleConfig.Update),
                    config.HasFlag(ObjectToggleConfig.FixedUpdate)),
                config.HasFlag(ObjectToggleConfig.GameObjectActive),
                config.HasFlag(ObjectToggleConfig.ComponentEnabled),
                parent
                ));
 }
Esempio n. 5
0
        internal override void AddToTail(ManagedUpdatesBehaviour component)
        {
            if (!ReferenceEquals(component.nextFixedUpdate, null) || !ReferenceEquals(component.previousFixedUpdate, null))
            {
                return;
            }
            count++;

            if (ReferenceEquals(head, null))
            {
                head = component;
                head.previousFixedUpdate = head;
                head.nextFixedUpdate     = head;
                return;
            }

            Add(component, head.previousFixedUpdate, head);
        }
Esempio n. 6
0
        internal override void AddToTail(ManagedUpdatesBehaviour component)
        {
            // TODO: Miscreant: Only need to check once of these references. Since the lists are circular, if one of these refs is null, both must be null.
            if (!ReferenceEquals(component.nextUpdate, null) || !ReferenceEquals(component.previousUpdate, null))
            {
                return;
            }
            count++;

            if (ReferenceEquals(head, null))
            {
                head = component;
                head.previousUpdate = head;
                head.nextUpdate     = head;
                return;
            }

            Add(component, head.previousUpdate, head);
        }
Esempio n. 7
0
        internal override void Remove(ManagedUpdatesBehaviour component)
        {
            // Only need to check one of the link references. Since the lists are circular, if one of these refs is null, both must be null.
            if (ReferenceEquals(component.nextFixedUpdate, null))
            {
                return;
            }
            count--;

            if (count == 0)
            {
                // TODO: MIscreant: Elegantly handle "current" field  when removing the last element in the list. Need to work out semantics there, too.
                head.previousFixedUpdate = null;
                head.nextFixedUpdate     = null;
                head = null;
                return;
            }

            if (ReferenceEquals(component, head))
            {
                head = head.nextFixedUpdate;
            }

            component.nextFixedUpdate.previousFixedUpdate = component.previousFixedUpdate;
            component.previousFixedUpdate.nextFixedUpdate = component.nextFixedUpdate;

            // This specifically handles the case where a component destroys itself from any type of managed update callback. By resetting 'current' to the
            // previous link, 'current' will not be null when 'Advance()' is called, and we'll process the expected next link during the next iteration.
            // Since it was the 'current' update callback that brought us here, there's no danger of accidentally processing 'current' a second time.
            if (ReferenceEquals(current, component))
            {
                current = component.previousFixedUpdate;
            }

            component.previousFixedUpdate = null;
            component.nextFixedUpdate     = null;
        }