Beispiel #1
0
 private static void VisitFunctionParam(IFunctionDefinition function, ParamDefinition param)
 {
     if (errorRegex.IsMatch(param.Name) &&
         param.Type.Name == "byte" &&
         param.Type.Modifies.Count == 2 &&
         param.Type.Modifies[0] == TypeDefinition.ModifyType.Pointer &&
         param.Type.Modifies[1] == TypeDefinition.ModifyType.Pointer &&
         param.Modify == ParamDefinition.ModifyType.None)
     {
         param.Type = new TypeDefinition {
             Name = "NativeString"
         };
         param.Modify = ParamDefinition.ModifyType.Out;
         return;
     }
     if (param.Type.Name == "bool")
     {
         param.Attrs = new[] { "MarshalAs(UnmanagedType.Bool)" };
         return;
     }
     if (param.Type.Name == "byte" &&
         param.Type.Modifies.Count == 1 &&
         (param.Type.Modifies[0] == TypeDefinition.ModifyType.ConstPointer || param.Type.Modifies[0] == TypeDefinition.ModifyType.Pointer) &&
         param.Modify == ParamDefinition.ModifyType.None)
     {
         param.Type = new TypeDefinition {
             Name = "string"
         };
         param.Attrs = new[] { "MarshalAs(UnmanagedType.LPStr)" };
         return;
     }
 }
 public CreatePropNode()
     : base(ResourceType, ResourceTag)
 {
     this.mPropActor = null;
     this.mPropParam = null;
     this.mPropKey = new RK();
 }
Beispiel #3
0
        protected ParamDefinition[] GetAssetDataAsInputs(bool skipUnchangable = false)
        {
            List <ParamDefinition> inputs = new List <ParamDefinition>();

            foreach (var assetPropInfo in _assetData.GetAssetProperties())
            {
                var paramInfo = _assetData.GetGHParameterInfo(assetPropInfo);
                if (paramInfo is null)
                {
                    continue;
                }

                if (skipUnchangable && !paramInfo.Modifiable)
                {
                    continue;
                }

                var param = (IGH_Param)Activator.CreateInstance(paramInfo.ParamType);
                param.Name        = paramInfo.Name;
                param.NickName    = paramInfo.NickName;
                param.Description = paramInfo.Description;
                param.Access      = paramInfo.ParamAccess;
                param.Optional    = paramInfo.Optional;

                inputs.Add(ParamDefinition.FromParam(param));
            }

            return(inputs.ToArray());
        }
Beispiel #4
0
 public ParamCommand(ActorSuffix suffix,
                     ParamDefinition newValue)
 {
     this.mSuffix = suffix;
     this.mOldVal = suffix.mParam.GetValue();
     this.mNewVal = newValue;
     this.mLabel  = "Set Param of Actor Suffix";
 }
Beispiel #5
0
 public ActorSuffix(SlotBuilder sb,
                    ActorDefinition actor, ParamDefinition param)
 {
     if (sb == null)
     {
         throw new ArgumentNullException("sb");
     }
     this.mSB    = sb;
     this.mActor = new RefToActor(sb.mScene, actor);
     this.mParam = new RefToParam(sb.mScene, param);
 }
Beispiel #6
0
 public DefParam(ParamDefinition param, StateMachineScene scene)
 {
     if (param == null)
     {
         throw new ArgumentNullException("param");
     }
     if (scene == null)
     {
         throw new ArgumentNullException("scene");
     }
     this.mParam = param;
     this.mScene = scene;
 }
        private ParamDefinition[] GetFieldsAsInputs()
        {
            List <ParamDefinition> inputs = new List <ParamDefinition>();

            var param = new Parameters.AppearanceAsset();

            param.Name        = ComponentInfo.Name;
            param.NickName    = ComponentInfo.NickName;
            param.Description = ComponentInfo.Description;
            param.Access      = GH_ParamAccess.item;

            inputs.Add(ParamDefinition.FromParam(param));
            inputs.AddRange(GetAssetDataAsInputs(skipUnchangable: true));
            return(inputs.ToArray());
        }
Beispiel #8
0
            public static ParamDefinition FromParam <T>(GH_PersistentParam <T> param, ParamVisibility relevance, object defaultValue)
                where T : class, IGH_Goo, new()
            {
                var def = new ParamDefinition(param, relevance);

                if (def.Param is GH_PersistentParam <T> persistentParam)
                {
                    var data = new T();
                    if (!data.CastFrom(defaultValue))
                    {
                        throw new InvalidCastException();
                    }

                    persistentParam.PersistentData.Append(data);
                }

                return(def);
            }
Beispiel #9
0
        private ParamDefinition[] GetInputs()
        {
            var inputs = new List <ParamDefinition>()
            {
                ParamDefinition.Create <Parameters.ThermalAsset>(
                    name: ComponentInfo.Name,
                    nickname: ComponentInfo.NickName,
                    description: ComponentInfo.Description,
                    access: GH_ParamAccess.item
                    ),
            };

            foreach (ParamDefinition param in GetAssetDataAsInputs(skipUnchangable: true))
            {
                if (param.Param.Name != "Name" && param.Param.Name != "Type")
                {
                    inputs.Add(param);
                }
            }

            return(inputs.ToArray());
        }
Beispiel #10
0
        protected ParamDefinition[] GetAssetDataAsOutputs()
        {
            List <ParamDefinition> outputs = new List <ParamDefinition>();

            foreach (var assetPropInfo in _assetData.GetAssetProperties())
            {
                var paramInfo = _assetData.GetGHParameterInfo(assetPropInfo);
                if (paramInfo is null)
                {
                    continue;
                }

                var param = (IGH_Param)Activator.CreateInstance(paramInfo.ParamType);
                param.Name        = paramInfo.Name;
                param.NickName    = paramInfo.NickName;
                param.Description = paramInfo.Description;
                param.Access      = paramInfo.ParamAccess;

                outputs.Add(ParamDefinition.FromParam(param));
            }

            return(outputs.ToArray());
        }
 public ActorSuffix(ActorDefinition actor, ParamDefinition param)
 {
     this.Actor = actor;
     this.Param = param;
 }
Beispiel #12
0
        public override void UpdateVisualization()
        {
            if (this.mScene.StateView == null)
            {
                return;
            }
            SizeF size;
            float w = 20;
            float h = 15;

            Graphics      g  = this.mScene.StateView.CreateGraphics();
            StringBuilder sb = new StringBuilder();

            ActorDefinition ad = this.mPropNode.PropActor;

            /*this.mActorString = "A: " + (ad == null ? "" : ad.Name);
             * //w = Math.Max(w, kAGW * this.mActorString.Length + 4);
             * size = g.MeasureString(this.mActorString, TextFont);
             * w = Math.Max(w, size.Width + 5);/* */
            sb.AppendLine(string.Concat("A: ", (ad == null ? "" : ad.Name)));

            ParamDefinition pd = this.mPropNode.PropParam;

            /*this.mParamString = "P: " + (pd == null ? "" : pd.Name);
             * //w = Math.Max(w, kAGW * this.mParamString.Length + 4);
             * size = g.MeasureString(this.mParamString, TextFont);
             * w = Math.Max(w, size.Width + 5);/* */
            sb.AppendLine(string.Concat("P: ", (pd == null ? "" : pd.Name)));

            IResourceKey rk = this.mPropNode.PropKey;

            /*this.mKeyString = "K: " + rk.ToString();
             * string name;
             * if (KeyNameReg.TryFindName(rk.Instance, out name))
             * {
             *  this.mKeyString += string.Concat(" ", name);
             * }
             * //w = Math.Max(w, kAGW * this.mKeyString.Length + 4);
             * size = g.MeasureString(this.mKeyString, TextFont);
             * w = Math.Max(w, size.Width + 5);/* */
            sb.Append(string.Concat("K: ", rk.ToString()));
            string name;

            if (KeyNameReg.TryFindName(rk.Instance, out name))
            {
                sb.Append(string.Concat(" ", name));
            }

            this.mTextString = sb.ToString();
            size             = g.MeasureString(this.mTextString, sTextFont);
            w = Math.Max(w, size.Width + 5);
            h = Math.Max(h, size.Height + 5);

            this.mEntryAnchor.SetPosition(0, h / 2);
            this.mTargetAnchor.SetPosition(w, h / 2);

            if (this.mBorderPath == null)
            {
                this.mBorderPath = new GraphicsPath();
            }
            this.mBorderPath.Reset();
            AddRoundedRectangle(this.mBorderPath, 0, 0, w, h, 5);

            float bbp = 2 * AnchorPoint.Radius;

            this.BoundingBox = new RectangleF(
                -bbp, -bbp, w + 2 * bbp, h + 2 * bbp);
        }
Beispiel #13
0
 protected override void VisitDelegateParam(DelegateDefinition @delegate, ParamDefinition param)
 {
     base.VisitDelegateParam(@delegate, param);
     VisitFunctionParam(@delegate, param);
 }
Beispiel #14
0
 public bool RemoveParamDefinition(ParamDefinition param)
 {
     int index = this.mParamDefinitions.IndexOf(param);
     if (index < 0)
     {
         return false;
     }
     this.mParamDefinitions.RemoveAt(index);
     return true;
 }
Beispiel #15
0
 public bool AddParamDefinition(ParamDefinition param)
 {
     if (this.mParamDefinitions.Contains(param))
     {
         return false;
     }
     this.mParamDefinitions.Add(param);
     return true;
 }
Beispiel #16
0
 protected override void VisitFunctionParam(FunctionDefinition function, ParamDefinition param)
 {
     base.VisitFunctionParam(function, param);
     VisitFunctionParam(function, param);
 }
 public void AddNamespaceSlotSuffix(ActorDefinition targetNamespace,
     ParamDefinition suffixParameter)
 {
     this.mActorSuffixList.Add(
         new ActorSuffix(targetNamespace, suffixParameter));
 }
Beispiel #18
0
 public DefParam(ParamDefinition param, StateMachineScene scene)
 {
     this.mParam = param ?? throw new ArgumentNullException("param");
     this.mScene = scene ?? throw new ArgumentNullException("scene");
 }
Beispiel #19
0
        public StateMachine(GenericRCOLResource jazzResource)
            : this("")
        {
            if (jazzResource == null)
            {
                throw new ArgumentNullException("jazzResource");
            }
            GenericRCOLResource.ChunkEntryList chunkEntries
                = jazzResource.ChunkEntries;
            if (chunkEntries == null || chunkEntries.Count == 0)
            {
                throw new ArgumentException(
                    "RCOL Resource is empty", "jazzResource");
            }
            KeyNameReg.RefreshKeyNameMaps();
            uint hash;
            string name;
            int i, j, index = -1;
            State state;
            ActorDefinition ad;
            ParamDefinition pd;
            DecisionGraphNode dgn;
            JazzStateMachine jazzSM = null;
            GenericRCOLResource.ChunkEntry ce;
            AChunkObject[] chunks = new AChunkObject[chunkEntries.Count];
            List<ActorDefinition> actorDefs = new List<ActorDefinition>();
            List<ParamDefinition> paramDefs = new List<ParamDefinition>();

            #region Phase 1: Instantiate Chunks and Copy over value fields
            for (i = 0; i < chunkEntries.Count; i++)
            {
                ce = chunkEntries[i];
                hash = ce.TGIBlock.ResourceType;
                switch (hash)
                {
                    case PlayAnimationNode.ResourceType:
                        JazzPlayAnimationNode jpan
                            = ce.RCOLBlock as JazzPlayAnimationNode;
                        PlayAnimationNode lan = new PlayAnimationNode();
                        lan.ClipKey = new RK(jpan.ClipResource);
                        lan.TrackMaskKey = new RK(jpan.TkmkResource);
                        // lan.SlotSetup copied over later
                        lan.AdditiveClipKey
                            = new RK(jpan.AdditiveClipResource);
                        lan.ClipPattern = jpan.Animation;
                        lan.AdditiveClipPattern = jpan.AdditiveAnimation;
                        lan.Flags = jpan.AnimationNodeFlags;
                        lan.Priority = jpan.AnimationPriority1;
                        lan.BlendInTime = jpan.BlendInTime;
                        lan.BlendOutTime = jpan.BlendOutTime;
                        lan.Speed = jpan.Speed;
                        // lan.Actor set later
                        lan.TimingPriority = jpan.TimingPriority;
                        chunks[i] = lan;
                        break;
                    case StopAnimationNode.ResourceType:
                        JazzStopAnimationNode jsan
                            = ce.RCOLBlock as JazzStopAnimationNode;
                        StopAnimationNode san = new StopAnimationNode();
                        san.Flags = jsan.AnimationFlags;
                        san.Priority = jsan.AnimationPriority1;
                        san.BlendInTime = jsan.BlendInTime;
                        san.BlendOutTime = jsan.BlendOutTime;
                        san.Speed = jsan.Speed;
                        // san.Actor set later
                        san.TimingPriority = jsan.TimingPriority;
                        chunks[i] = san;
                        break;
                    case ActorOperationNode.ResourceType:
                        JazzActorOperationNode jaon
                            = ce.RCOLBlock as JazzActorOperationNode;
                        ActorOperationNode aon
                            = new ActorOperationNode(jaon.ActorOp);
                        // aon.Target set later
                        aon.Operand = jaon.Operand != 0;
                        chunks[i] = aon;
                        break;
                    case CreatePropNode.ResourceType:
                        JazzCreatePropNode jcpn
                            = ce.RCOLBlock as JazzCreatePropNode;
                        CreatePropNode cpn = new CreatePropNode();
                        // cpn.PropActor set later
                        // cpn.PropParameter set later
                        cpn.PropKey = new RK(jcpn.PropResource);
                        chunks[i] = cpn;
                        break;
                    case RandomNode.ResourceType:
                        JazzRandomNode jrand
                            = ce.RCOLBlock as JazzRandomNode;
                        RandomNode rand = new RandomNode();
                        // rand.Slices set later
                        rand.Flags = jrand.Properties;
                        chunks[i] = rand;
                        break;
                    case SelectOnParameterNode.ResourceType:
                        // sopn.Parameter set later
                        // sopn.Cases set later
                        chunks[i] = new SelectOnParameterNode();
                        break;
                    case SelectOnDestinationNode.ResourceType:
                        // sodn.Cases set later
                        chunks[i] = new SelectOnDestinationNode();
                        break;
                    case NextStateNode.ResourceType:
                        // nsn.NextState set later
                        chunks[i] = new NextStateNode();
                        break;
                    case DecisionGraph.ResourceType:
                        // dg.State set later
                        // dg.DecisionMakers set later
                        // dg.EntryPoints set later
                        chunks[i] = new DecisionGraph();
                        break;
                    case State.ResourceType:
                        JazzState js = ce.RCOLBlock as JazzState;
                        hash = js.NameHash;
                        if (!KeyNameReg.TryFindName(hash, out name))
                            name = KeyNameReg.UnhashName(hash);
                        state = new State(name);
                        state.Flags = js.Properties;
                        // state.DecisionGraph set later
                        // state.Transitions set later
                        state.AwarenessOverlayLevel
                            = js.AwarenessOverlayLevel;
                        chunks[i] = state;
                        break;
                    case ParamDefinition.ResourceType:
                        JazzParameterDefinition jpd
                            = ce.RCOLBlock as JazzParameterDefinition;
                        hash = jpd.NameHash;
                        if (!KeyNameReg.TryFindName(hash, out name))
                            name = KeyNameReg.UnhashName(hash);
                        pd = new ParamDefinition(name);

                        hash = jpd.DefaultValue;
                        if (!KeyNameReg.TryFindName(hash, out name))
                            name = KeyNameReg.UnhashName(hash);
                        pd.DefaultValue = name;
                        chunks[i] = pd;
                        paramDefs.Add(pd);
                        break;
                    case ActorDefinition.ResourceType:
                        JazzActorDefinition jad
                            = ce.RCOLBlock as JazzActorDefinition;
                        hash = jad.NameHash;
                        if (!KeyNameReg.TryFindName(hash, out name))
                            name = KeyNameReg.UnhashName(hash);
                        ad = new ActorDefinition(name);
                        chunks[i] = ad;
                        actorDefs.Add(ad);
                        break;
                    case StateMachine.ResourceType:
                        if (index != -1)
                        {
                            throw new Exception(
                                "More than one State Machine in RCOL");
                        }
                        index = i;
                        jazzSM = ce.RCOLBlock as JazzStateMachine;
                        hash = jazzSM.NameHash;
                        if (hash == 0)
                        {
                            name = null;
                            this.bNameIsHash = true;
                        }
                        else if (!KeyNameReg.TryFindName(hash, out name))
                        {
                            name = KeyNameReg.UnhashName(hash);
                            this.bNameIsHash = true;
                        }
                        else
                        {
                            this.bNameIsHash = false;
                        }
                        this.mName = name;
                        this.mNameHash = hash;
                        // this.mActorDefinitions set later
                        // this.mParameterDefinitions set later
                        // this.mStates set later
                        this.mFlags = jazzSM.Properties;
                        this.mDefaultPriority = jazzSM.AutomationPriority;
                        this.mAwarenessOverlayLevel
                            = jazzSM.AwarenessOverlayLevel;
                        chunks[i] = this;
                        break;
                }
            }
            if (index == -1)
            {
                throw new Exception("RCOL does not contain a Jazz Graph");
            }
            #endregion

            #region Phase 2: Copy over fields referencing other chunks
            for (i = 0; i < chunkEntries.Count; i++)
            {
                ce = chunkEntries[i];
                switch (ce.TGIBlock.ResourceType)
                {
                    case PlayAnimationNode.ResourceType:
                        JazzPlayAnimationNode jpan
                            = ce.RCOLBlock as JazzPlayAnimationNode;
                        PlayAnimationNode lan
                            = chunks[i] as PlayAnimationNode;
                        index = jpan.ActorDefinitionIndex.TGIBlockIndex;
                        lan.Actor = index < 0
                            ? null : chunks[index + 1] as ActorDefinition;
                        break;
                    case StopAnimationNode.ResourceType:
                        JazzStopAnimationNode jsan
                            = ce.RCOLBlock as JazzStopAnimationNode;
                        StopAnimationNode san
                            = chunks[i] as StopAnimationNode;
                        index = jsan.ActorDefinitionIndex.TGIBlockIndex;
                        san.Actor = index < 0
                            ? null : chunks[index + 1] as ActorDefinition;
                        break;
                    case ActorOperationNode.ResourceType:
                        JazzActorOperationNode jaon
                            = ce.RCOLBlock as JazzActorOperationNode;
                        ActorOperationNode aon
                            = chunks[i] as ActorOperationNode;
                        index = jaon.ActorDefinitionIndex.TGIBlockIndex;
                        aon.Actor = index < 0
                            ? null : chunks[index + 1] as ActorDefinition;
                        break;
                    case CreatePropNode.ResourceType:
                        JazzCreatePropNode jcpn
                            = ce.RCOLBlock as JazzCreatePropNode;
                        CreatePropNode cpn = chunks[i] as CreatePropNode;
                        index = jcpn.ActorDefinitionIndex.TGIBlockIndex;
                        cpn.PropActor = index < 0
                            ? null : chunks[index + 1] as ActorDefinition;
                        index = jcpn.ParameterDefinitionIndex.TGIBlockIndex;
                        cpn.PropParam = index < 0
                            ? null : chunks[index + 1] as ParamDefinition;
                        break;
                    case RandomNode.ResourceType:
                        JazzRandomNode jrand = ce.RCOLBlock as JazzRandomNode;
                        RandomNode rand = chunks[i] as RandomNode;
                        RandomNode.Slice slice;
                        List<RandomNode.Slice> slices = rand.Slices;
                        foreach (JazzRandomNode.Outcome oc in jrand.Outcomes)
                        {
                            slice = new RandomNode.Slice(oc.Weight);
                            foreach (GenericRCOLResource.ChunkReference cr
                                in oc.DecisionGraphIndexes)
                            {
                                index = cr.TGIBlockIndex;
                                dgn = index < 0 ? null
                                    : chunks[index + 1] as DecisionGraphNode;
                                slice.Targets.Add(dgn);
                            }
                            slices.Add(slice);
                        }
                        break;
                    case SelectOnParameterNode.ResourceType:
                        JazzSelectOnParameterNode jsopn
                            = ce.RCOLBlock as JazzSelectOnParameterNode;
                        SelectOnParameterNode sopn
                            = chunks[i] as SelectOnParameterNode;
                        index = jsopn.ParameterDefinitionIndex.TGIBlockIndex;
                        sopn.Parameter = index < 0 ? null
                            : chunks[index + 1] as ParamDefinition;
                        foreach (JazzSelectOnParameterNode.Match mp
                            in jsopn.Matches)
                        {
                            hash = mp.TestValue;
                            if (!KeyNameReg.TryFindName(hash, out name))
                                name = KeyNameReg.UnhashName(hash);
                            foreach (GenericRCOLResource.ChunkReference cr
                                in mp.DecisionGraphIndexes)
                            {
                                index = cr.TGIBlockIndex;
                                dgn = index < 0 ? null
                                    : chunks[index + 1] as DecisionGraphNode;
                                sopn.AddCaseTarget(name, dgn);
                            }
                        }
                        break;
                    case SelectOnDestinationNode.ResourceType:
                        JazzSelectOnDestinationNode jsodn
                            = ce.RCOLBlock as JazzSelectOnDestinationNode;
                        SelectOnDestinationNode sodn
                            = chunks[i] as SelectOnDestinationNode;
                        foreach (JazzSelectOnDestinationNode.Match md
                            in jsodn.Matches)
                        {
                            index = md.StateIndex.TGIBlockIndex;
                            state = index < 0 ? null
                                : chunks[index + 1] as State;
                            foreach (GenericRCOLResource.ChunkReference cr
                                in md.DecisionGraphIndexes)
                            {
                                index = cr.TGIBlockIndex;
                                dgn = index < 0 ? null
                                    : chunks[index + 1] as DecisionGraphNode;
                                sodn.AddCaseTarget(state, dgn);
                            }
                        }
                        break;
                    case NextStateNode.ResourceType:
                        JazzNextStateNode jnsn
                            = ce.RCOLBlock as JazzNextStateNode;
                        NextStateNode nsn = chunks[i] as NextStateNode;
                        index = jnsn.StateIndex.TGIBlockIndex;
                        nsn.NextState = index < 0 ? null
                            : chunks[index + 1] as State;
                        break;
                    case DecisionGraph.ResourceType:
                        JazzDecisionGraph jdg
                            = ce.RCOLBlock as JazzDecisionGraph;
                        DecisionGraph dg = chunks[i] as DecisionGraph;
                        foreach (GenericRCOLResource.ChunkReference dm
                            in jdg.OutboundDecisionGraphIndexes)
                        {
                            index = dm.TGIBlockIndex;
                            dgn = index < 0 ? null
                                : chunks[index + 1] as DecisionGraphNode;
                            dg.AddDecisionMaker(dgn);
                        }
                        foreach (GenericRCOLResource.ChunkReference ep
                            in jdg.InboundDecisionGraphIndexes)
                        {
                            index = ep.TGIBlockIndex;
                            dgn = index < 0 ? null
                                : chunks[index + 1] as DecisionGraphNode;
                            dg.AddEntryPoint(dgn);
                        }
                        break;
                    case State.ResourceType:
                        State transition;
                        JazzState js = ce.RCOLBlock as JazzState;
                        state = chunks[i] as State;
                        index = js.DecisionGraphIndex.TGIBlockIndex;
                        state.DecisionGraph = index < 0 ? null
                            : chunks[index + 1] as DecisionGraph;
                        foreach (GenericRCOLResource.ChunkReference trans
                            in js.OutboundStateIndexes)
                        {
                            index = trans.TGIBlockIndex;
                            transition = index < 0 ? null
                                : chunks[index + 1] as State;
                            state.AddTransition(transition);
                        }
                        break;
                    case ParamDefinition.ResourceType:
                    case ActorDefinition.ResourceType:
                        break;
                    case StateMachine.ResourceType:
                        jazzSM = ce.RCOLBlock as JazzStateMachine;
                        foreach (GenericRCOLResource.ChunkReference jad
                            in jazzSM.ActorDefinitionIndexes)
                        {
                            index = jad.TGIBlockIndex;
                            ad = index < 0 ? null
                                : chunks[index + 1] as ActorDefinition;
                            this.AddActorDefinition(ad);
                        }
                        foreach (GenericRCOLResource.ChunkReference jpd
                            in jazzSM.PropertyDefinitionIndexes)
                        {
                            index = jpd.TGIBlockIndex;
                            pd = index < 0 ? null
                                : chunks[index + 1] as ParamDefinition;
                            this.AddParamDefinition(pd);
                        }
                        foreach (GenericRCOLResource.ChunkReference jst
                            in jazzSM.StateIndexes)
                        {
                            index = jst.TGIBlockIndex;
                            state = index < 0  ? null
                                : chunks[index + 1] as State;
                            this.AddState(state);
                        }
                        break;
                }
            }
            #endregion

            #region Phase 3: Copy over animation slots and Find "Extras"
            for (i = 0; i < chunkEntries.Count; i++)
            {
                ce = chunkEntries[i];
                switch (ce.TGIBlock.ResourceType)
                {
                    case PlayAnimationNode.ResourceType:
                        JazzPlayAnimationNode jpan
                            = ce.RCOLBlock as JazzPlayAnimationNode;
                        PlayAnimationNode lan
                            = chunks[i] as PlayAnimationNode;
                        SlotSetupBuilder ssb = lan.SlotSetup;
                        foreach (JazzPlayAnimationNode.ActorSlot slot
                            in jpan.ActorSlots)
                        {
                            ssb.AddSlotAssignment(slot.ChainId, slot.SlotId,
                                slot.ActorNameHash, slot.SlotNameHash);
                        }
                        foreach (JazzPlayAnimationNode.ActorSuffix suffix
                            in jpan.ActorSuffixes)
                        {
                            hash = suffix.ActorNameHash;
                            ad = null;
                            if (hash != 0)
                            {
                                index = -1;
                                for (i = actorDefs.Count - 1;
                                     i >= 0 && index == -1; i--)
                                {
                                    ad = actorDefs[i];
                                    if (ad.NameHash == hash)
                                    {
                                        index = i;
                                    }
                                }
                                if (index < 0)
                                {
                                    if (!KeyNameReg.TryFindName(hash, out name))
                                        name = KeyNameReg.UnhashName(hash);
                                    ad = new ActorDefinition(name);
                                    actorDefs.Add(ad);
                                    this.mExtraActors.Add(ad);
                                }
                            }
                            hash = suffix.SuffixHash;
                            pd = null;
                            if (hash != 0)
                            {
                                index = -1;
                                for (i = paramDefs.Count - 1;
                                     i >= 0 && index == -1; i--)
                                {
                                    pd = paramDefs[i];
                                    if (pd.NameHash == hash)
                                    {
                                        index = i;
                                    }
                                }
                                if (index < 0)
                                {
                                    if (!KeyNameReg.TryFindName(hash, out name))
                                        name = KeyNameReg.UnhashName(hash);
                                    pd = new ParamDefinition(name);
                                    paramDefs.Add(pd);
                                    this.mExtraParams.Add(pd);
                                }
                            }
                            ssb.AddNamespaceSlotSuffix(ad, pd);
                        }
                        break;
                    case State.ResourceType:
                        state = chunks[i] as State;
                        index = this.mStates.IndexOf(state);
                        if (index < 0)
                        {
                            this.mExtraStates.Add(state);
                        }
                        break;
                    case ParamDefinition.ResourceType:
                        pd = chunks[i] as ParamDefinition;
                        index = this.mParamDefinitions.IndexOf(pd);
                        if (index < 0)
                        {
                            this.mExtraParams.Add(pd);
                        }
                        break;
                    case ActorDefinition.ResourceType:
                        ad = chunks[i] as ActorDefinition;
                        index = this.mActorDefinitions.IndexOf(ad);
                        if (index < 0)
                        {
                            this.mExtraActors.Add(ad);
                        }
                        break;
                }
            }
            #endregion

            #region Phase 4: Copy over Animation CLIP Namespace Map
            RK rk;
            List<RK> rks = this.SlurpReferencedRKs();
            List<uint> foldedClipInstances = new List<uint>(rks.Count);
            for (i = rks.Count - 1; i >= 0; i--)
            {
                rk = rks[i];
                if (rk.TID == 0x6b20c4f3)
                {
                    hash = (uint)((rk.IID >> 0x20) ^ (rk.IID & 0xffffffff));
                    foldedClipInstances.Add(hash);
                }
                else
                {
                    rks.RemoveAt(i);
                }
            }
            index = 0;
            Anim animation;
            Anim[] animations = new Anim[jazzSM.Animations.Count];
            foreach (JazzStateMachine.Animation anim in jazzSM.Animations)
            {
                hash = anim.NameHash;
                if (!foldedClipInstances.Contains(hash))
                {
                    animation = new Anim();
                    animation.SrcFileHash = hash;
                    if (KeyNameReg.TryFindName(hash, out name))
                    {
                        animation.SrcFileName = name;
                        animation.SrcFileIsValid = true;
                    }
                    else
                    {
                        animation.SrcFileName
                            = KeyNameReg.UnhashName(hash);
                        animation.SrcFileIsValid = false;
                    }
                    hash = anim.Actor1Hash;
                    if (KeyNameReg.TryFindName(hash, out name))
                    {
                        animation.Namespace = name;
                    }
                    else
                    {
                        animation.Namespace
                            = string.Concat("0x", hash.ToString("X8"));
                    }
                    hash = anim.Actor2Hash;
                    ad = null;
                    if (hash != 0)
                    {
                        j = -1;
                        for (i = actorDefs.Count - 1; i >= 0 && j < 0; i--)
                        {
                            ad = actorDefs[i];
                            if (ad.NameHash == hash)
                            {
                                j = i;
                            }
                        }
                        if (j < 0)
                        {
                            if (!KeyNameReg.TryFindName(hash, out name))
                                name = KeyNameReg.UnhashName(hash);
                            ad = new ActorDefinition(name);
                            actorDefs.Add(ad);
                            this.mExtraActors.Add(ad);
                        }
                    }
                    animation.Actor = ad;
                    animations[index++] = animation;
                }
            }
            ulong clipHash;
            Dictionary<ulong, string> keyNameMap
                = new Dictionary<ulong, string>();
            for (i = index - 1; i >= 0; i--)
            {
                animation = animations[i];
                this.mNamespaceMap.SetNamespaceMap(
                    animation.SrcFileName,
                    animation.Namespace,
                    animation.Actor);
                if (animation.SrcFileIsValid)
                {
                    clipHash = FNVHash.HashString64(animation.SrcFileName);
                    keyNameMap[clipHash] = animation.SrcFileName;
                }
            }
            // Update the Key to Filename Map of the Namespace Map
            SortedDictionary<RK, string> k2fn
                = this.mNamespaceMap.KeyToFilenameMap;
            k2fn.Clear();
            for (i = rks.Count - 1; i >= 0; i--)
            {
                rk = rks[i];
                if (keyNameMap.TryGetValue(rk.IID, out name) ||
                    KeyNameReg.TryFindName(rk.IID, out name))
                {
                    k2fn[rk] = name;
                }
            }
            #endregion
        }
Beispiel #20
0
 public void SetUp()
 {
     mSut = new ParamDefinition(Substitute.For <IElementConfiguration>());
 }