Exemplo n.º 1
0
        private bool Visit(ActorComponent n)
        {
            if (m_Perm.Contains(n))
            {
                return(true);
            }
            if (m_Temp.Contains(n))
            {
                Console.WriteLine("Dependency cycle!");
                return(false);
            }

            m_Temp.Add(n);

            IList <ActorComponent> dependents = n.m_Dependents;

            if (dependents != null)
            {
                foreach (ActorComponent d in dependents)
                {
                    if (!Visit(d))
                    {
                        return(false);
                    }
                }
            }
            m_Perm.Add(n);
            m_Order.Insert(0, n);

            return(true);
        }
Exemplo n.º 2
0
 public void Copy(ActorComponent component, Actor resetActor)
 {
     m_Name      = component.m_Name;
     m_Actor     = resetActor;
     m_ParentIdx = component.m_ParentIdx;
     m_Idx       = component.m_Idx;
 }
Exemplo n.º 3
0
        public virtual void Advance(float seconds)
        {
            if ((m_Flags & Flags.IsDirty) != 0)
            {
                const int MaxSteps = 100;
                int       step     = 0;
                int       count    = m_DependencyOrder.Count;
                while ((m_Flags & Flags.IsDirty) != 0 && step < MaxSteps)
                {
                    m_Flags &= ~Flags.IsDirty;
                    // Track dirt depth here so that if something else marks dirty, we restart.
                    for (int i = 0; i < count; i++)
                    {
                        ActorComponent component = m_DependencyOrder[i];
                        m_DirtDepth = (uint)i;
                        byte d = component.m_DirtMask;
                        if (d == 0)
                        {
                            continue;
                        }
                        component.m_DirtMask = 0;
                        component.Update(d);
                        if (m_DirtDepth < i)
                        {
                            break;
                        }
                    }
                    step++;
                }
            }

            if ((m_Flags & Flags.IsImageDrawOrderDirty) != 0)
            {
                m_Flags &= ~Flags.IsImageDrawOrderDirty;

                if (m_ImageNodes != null)
                {
                    Array.Sort <ActorImage>(m_ImageNodes, sm_ImageDrawOrderComparer);
                    // Mark draw index.
                    for (int i = 0; i < m_ImageNodes.Length; i++)
                    {
                        m_ImageNodes[i].DrawIndex = i;
                    }
                }
            }
            if ((m_Flags & Flags.IsVertexDeformDirty) != 0)
            {
                m_Flags &= ~Flags.IsVertexDeformDirty;
                for (int i = 0; i < m_ImageNodeCount; i++)
                {
                    ActorImage imageNode = m_ImageNodes[i];
                    if (imageNode != null && imageNode.IsVertexDeformDirty)
                    {
                        imageNode.IsVertexDeformDirty = false;
                        UpdateVertexDeform(imageNode);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static ActorComponent Read(Actor actor, BinaryReader reader, ActorComponent component = null)
        {
            component.m_Actor     = actor;
            component.m_Name      = Actor.ReadString(reader);
            component.m_ParentIdx = reader.ReadUInt16();

            return(component);
        }
Exemplo n.º 5
0
        public static ActorConstraint Read(Actor actor, BinaryReader reader, ActorConstraint component)
        {
            ActorComponent.Read(actor, reader, component);
            component.m_Strength  = reader.ReadSingle();
            component.m_IsEnabled = reader.ReadByte() == 1;

            return(component);
        }
Exemplo n.º 6
0
        public override void ResolveComponentIndices(ActorComponent[] components)
        {
            ActorComponent component = components[ParentIdx];

            if (component != null)
            {
                component.AddCustomIntProperty(this);
            }
        }
Exemplo n.º 7
0
 public IList <ActorComponent> Sort(ActorComponent root)
 {
     m_Order = new List <ActorComponent>();
     if (!Visit(root))
     {
         return(null);
     }
     return(m_Order);
 }
Exemplo n.º 8
0
 public static CustomFloatProperty Read(Actor actor, BinaryReader reader, CustomFloatProperty property = null)
 {
     if (property == null)
     {
         property = new CustomFloatProperty();
     }
     ActorComponent.Read(actor, reader, property);
     property.Value = reader.ReadSingle();
     return(property);
 }
Exemplo n.º 9
0
 public static CustomBooleanProperty Read(Actor actor, BinaryReader reader, CustomBooleanProperty property = null)
 {
     if (property == null)
     {
         property = new CustomBooleanProperty();
     }
     ActorComponent.Read(actor, reader, property);
     property.Value = reader.ReadByte() == 1;
     return(property);
 }
Exemplo n.º 10
0
 public static CustomStringProperty Read(Actor actor, BinaryReader reader, CustomStringProperty property = null)
 {
     if (property == null)
     {
         property = new CustomStringProperty();
     }
     ActorComponent.Read(actor, reader, property);
     property.Value = Actor.ReadString(reader);
     return(property);
 }
Exemplo n.º 11
0
        public static ActorComponent Read(Actor actor, BinaryReader reader, ActorEvent component = null)
        {
            if (component == null)
            {
                component = new ActorEvent();
            }

            ActorComponent.Read(actor, reader, component);

            return(component);
        }
Exemplo n.º 12
0
 public override void ResolveComponentIndices(ActorComponent[] components)
 {
     base.ResolveComponentIndices(components);
     if (m_TargetIdx != 0)
     {
         m_Target = components[m_TargetIdx];
         if (m_Target != null)
         {
             m_Actor.AddDependency(m_Parent, m_Target);
         }
     }
 }
Exemplo n.º 13
0
        public static ActorJellyBone Read(Actor actor, BinaryReader reader, ActorJellyBone node = null)
        {
            if (node == null)
            {
                node = new ActorJellyBone();
            }

            // The Jelly Bone has a specialized read that doesn't go down the typical node path, this is because majority of the transform properties
            // of the Jelly Bone are controlled by the Jelly Controller and are unnecessary for serialization.
            ActorComponent.Read(actor, reader, node);
            node.m_Opacity = reader.ReadSingle();
            node.m_IsCollapsedVisibility = reader.ReadByte() == 1;
            return(node);
        }
Exemplo n.º 14
0
        public bool AddDependency(ActorComponent a, ActorComponent b)
        {
            IList <ActorComponent> dependents = b.m_Dependents;

            if (dependents == null)
            {
                b.m_Dependents = dependents = new List <ActorComponent>();
            }
            if (dependents.Contains(a))
            {
                return(false);
            }
            dependents.Add(a);
            return(true);
        }
Exemplo n.º 15
0
        public static JellyComponent Read(Actor actor, BinaryReader reader, JellyComponent node = null)
        {
            if (node == null)
            {
                node = new JellyComponent();
            }

            ActorComponent.Read(actor, reader, node);

            node.m_EaseIn       = reader.ReadSingle();
            node.m_EaseOut      = reader.ReadSingle();
            node.m_ScaleIn      = reader.ReadSingle();
            node.m_ScaleOut     = reader.ReadSingle();
            node.m_InTargetIdx  = reader.ReadUInt16();
            node.m_OutTargetIdx = reader.ReadUInt16();

            return(node);
        }
Exemplo n.º 16
0
        public static ActorNode Read(Actor actor, BinaryReader reader, ActorNode node = null)
        {
            if (node == null)
            {
                node = new ActorNode();
            }
            ActorComponent.Read(actor, reader, node);
            Actor.ReadFloat32Array(reader, node.m_Translation.Values);
            node.m_Rotation = reader.ReadSingle();
            Actor.ReadFloat32Array(reader, node.m_Scale.Values);
            node.m_Opacity = reader.ReadSingle();

            if (actor.Version >= 13)
            {
                node.m_IsCollapsedVisibility = reader.ReadByte() == 1;
            }

            return(node);
        }
Exemplo n.º 17
0
        public bool AddDirt(ActorComponent component, byte value, bool recurse = false)
        {
            if ((component.m_DirtMask & value) == value)
            {
                // Already marked.
                return(false);
            }

            // Make sure dirt is set before calling anything that can set more dirt.
            byte dirt = (byte)(component.m_DirtMask | value);

            component.m_DirtMask = dirt;

            m_Flags |= Flags.IsDirty;

            component.OnDirty(dirt);

            // If the order of this component is less than the current dirt depth, update the dirt depth
            // so that the update loop can break out early and re-run (something up the tree is dirty).
            if (component.m_GraphOrder < m_DirtDepth)
            {
                m_DirtDepth = component.m_GraphOrder;
            }
            if (!recurse)
            {
                return(true);
            }
            IList <ActorComponent> dependents = component.m_Dependents;

            if (dependents != null)
            {
                foreach (ActorComponent d in dependents)
                {
                    AddDirt(d, value, recurse);
                }
            }

            return(true);
        }
Exemplo n.º 18
0
        public void Copy(Actor actor)
        {
            m_Animations      = actor.m_Animations;
            m_Flags           = actor.m_Flags;
            m_MaxTextureIndex = actor.m_MaxTextureIndex;
            m_ImageNodeCount  = actor.m_ImageNodeCount;
            m_NodeCount       = actor.m_NodeCount;

            if (actor.ComponentCount != 0)
            {
                m_Components = new ActorComponent[actor.ComponentCount];
            }
            if (m_NodeCount != 0)            // This will always be at least 1.
            {
                m_Nodes = new ActorNode[m_NodeCount];
            }
            if (m_ImageNodeCount != 0)
            {
                m_ImageNodes = new ActorImage[m_ImageNodeCount];
            }

            if (actor.ComponentCount != 0)
            {
                int idx    = 0;
                int imgIdx = 0;
                int ndIdx  = 0;

                foreach (ActorComponent component in actor.Components)
                {
                    if (component == null)
                    {
                        m_Components[idx++] = null;
                        continue;
                    }
                    ActorComponent instanceComponent = component.MakeInstance(this);
                    m_Components[idx++] = instanceComponent;
                    ActorNode nodeInstance = instanceComponent as ActorNode;
                    if (nodeInstance != null)
                    {
                        m_Nodes[ndIdx++] = nodeInstance;
                    }

                    ActorImage imageInstance = instanceComponent as ActorImage;
                    if (imageInstance != null)
                    {
                        m_ImageNodes[imgIdx++] = imageInstance;
                    }
                }
            }

            m_Root = m_Components[0] as ActorNode;

            foreach (ActorComponent component in m_Components)
            {
                if (m_Root == component || component == null)
                {
                    continue;
                }
                component.ResolveComponentIndices(m_Components);
            }

            foreach (ActorComponent component in m_Components)
            {
                if (m_Root == component || component == null)
                {
                    continue;
                }
                component.CompleteResolve();
            }

            SortDependencies();
        }
Exemplo n.º 19
0
        private void ReadComponentsBlock(BlockReader block)
        {
            int componentCount = block.ReadUInt16();

            m_Components    = new ActorComponent[componentCount + 1];
            m_Components[0] = m_Root;

            // Guaranteed from the exporter to be in index order.
            BlockReader nodeBlock = null;

            int componentIndex = 1;

            m_NodeCount = 1;
            while ((nodeBlock = block.ReadNextBlock()) != null)
            {
                ActorComponent component = null;
                if (Enum.IsDefined(typeof(BlockTypes), nodeBlock.BlockType))
                {
                    BlockTypes type = (BlockTypes)nodeBlock.BlockType;
                    switch (type)
                    {
                    case BlockTypes.ActorNode:
                        component = ActorNode.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorBone:
                        component = ActorBone.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorRootBone:
                        component = ActorRootBone.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorImage:
                        m_ImageNodeCount++;
                        component = ActorImage.Read(this, nodeBlock, makeImageNode());
                        if ((component as ActorImage).TextureIndex > m_MaxTextureIndex)
                        {
                            m_MaxTextureIndex = (component as ActorImage).TextureIndex;
                        }
                        break;

                    case BlockTypes.ActorIKTarget:
                        component = ActorIKTarget.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorEvent:
                        component = ActorEvent.Read(this, nodeBlock);
                        break;

                    case BlockTypes.CustomIntProperty:
                        component = CustomIntProperty.Read(this, nodeBlock);
                        break;

                    case BlockTypes.CustomFloatProperty:
                        component = CustomFloatProperty.Read(this, nodeBlock);
                        break;

                    case BlockTypes.CustomStringProperty:
                        component = CustomStringProperty.Read(this, nodeBlock);
                        break;

                    case BlockTypes.CustomBooleanProperty:
                        component = CustomBooleanProperty.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderRectangle:
                        component = ActorColliderRectangle.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderTriangle:
                        component = ActorColliderTriangle.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderCircle:
                        component = ActorColliderCircle.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderPolygon:
                        component = ActorColliderPolygon.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderLine:
                        component = ActorColliderLine.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorNodeSolo:
                        component = ActorNodeSolo.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorJellyBone:
                        component = ActorJellyBone.Read(this, nodeBlock);
                        break;

                    case BlockTypes.JellyComponent:
                        component = JellyComponent.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorIKConstraint:
                        component = ActorIKConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorDistanceConstraint:
                        component = ActorDistanceConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorTranslationConstraint:
                        component = ActorTranslationConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorScaleConstraint:
                        component = ActorScaleConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorRotationConstraint:
                        component = ActorRotationConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorTransformConstraint:
                        component = ActorTransformConstraint.Read(this, nodeBlock);
                        break;
                    }
                }
                if (component is ActorNode)
                {
                    m_NodeCount++;
                }

                m_Components[componentIndex] = component;
                if (component != null)
                {
                    component.Idx = (ushort)(componentIndex);
                }
                componentIndex++;
            }

            m_ImageNodes = new ActorImage[m_ImageNodeCount];
            m_Nodes      = new ActorNode[m_NodeCount];
            m_Nodes[0]   = m_Root;

            // Resolve nodes.
            int imgIdx = 0;
            int anIdx  = 0;

            ActorComponent[] components = m_Components;
            for (int i = 1; i <= componentCount; i++)
            {
                ActorComponent c = components[i];
                // Nodes can be null if we read from a file version that contained nodes that we don't interpret in this runtime.
                if (c != null)
                {
                    c.ResolveComponentIndices(components);
                }

                ActorImage ain = c as ActorImage;
                if (ain != null)
                {
                    m_ImageNodes[imgIdx++] = ain;
                }

                ActorNode an = c as ActorNode;
                if (an != null)
                {
                    m_Nodes[anIdx++] = an;
                }
            }

            for (int i = 1; i <= componentCount; i++)
            {
                ActorComponent c = components[i];
                if (c != null)
                {
                    c.CompleteResolve();
                }
            }

            SortDependencies();
        }