示例#1
0
        public void ReplaceGpss(IEnumerable <GridGpsSource> gpsSources)
        {
            var sources = DictionaryPool <long, LocalGpsSource> .Create();

            foreach (var src in gpsSources)
            {
                if (TryCreateGps(src, out var localGpsSource))
                {
                    sources[localGpsSource.Id] = localGpsSource;
                }
            }

            // remove GPSs that don't exist anymore
            foreach (var(existingGpsId, _) in _gpsSources.ToArray())
            {
                if (!sources.ContainsKey(existingGpsId))
                {
                    _gpsSources.Remove(existingGpsId);
                    _gpsApi.RemoveLocalGps(existingGpsId);
                }
            }

            // add/update other GPSs
            foreach (var(id, src) in sources)
            {
                _gpsSources[id] = src;
                _gpsApi.AddOrUpdateLocalGps(src);
            }

            DictionaryPool <long, LocalGpsSource> .Release(sources);
        }
        public void SubtractGroup(string groupName)
        {
            Dictionary <string, int> abGroups;

            if (m_ABGroups.TryGetValue(groupName, out abGroups))
            {
                string abName;
                int    count;
                foreach (var kv in abGroups)
                {
                    abName = kv.Key;
                    count  = kv.Value;
                    count  = m_AssetRefer[abName] -= count;
                    if (count <= 0)
                    {
                        m_MappingAssetCache.Remove(abName);
                        m_AssetRefer.Remove(abName);
                        CacheManager.Subtract(abName);
                    }
                }
                DictionaryPool <string, int> .Release(abGroups);

                m_ABGroups.Remove(groupName);
            }
        }
        private void SetSizeRootPoints()
        {
            List <Transform> list = ListPool <Transform> .Get();

            ((Component)this).get_transform().FindMatchLoop("^fish_point_[0-9]+$", ref list);
            if (!((IReadOnlyList <Transform>)list).IsNullOrEmpty <Transform>())
            {
                Dictionary <int, Transform> toRelease = DictionaryPool <int, Transform> .Get();

                int length = 0;
                for (int index = 0; index < list.Count; ++index)
                {
                    Transform transform = list[index];
                    Match     match     = Regex.Match(((Object)transform).get_name(), "[0-9]+");
                    int       result;
                    if (match.Success && int.TryParse(match.Value, out result))
                    {
                        toRelease[result] = transform;
                        length            = Mathf.Max(length, result + 1);
                    }
                }
                this._sizeRootPoints = new Transform[length];
                using (Dictionary <int, Transform> .Enumerator enumerator = toRelease.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        KeyValuePair <int, Transform> current = enumerator.Current;
                        this._sizeRootPoints[current.Key] = current.Value;
                    }
                }
                DictionaryPool <int, Transform> .Release(toRelease);
            }
            ListPool <Transform> .Release(list);
        }
示例#4
0
    // Token: 0x0600867A RID: 34426 RVA: 0x0034A374 File Offset: 0x00348774
    public void CalculateBlendShape()
    {
        if (FBSTarget.Length == 0)
        {
            return;
        }
        var b   = correctOpenMax >= 0f ? correctOpenMax : OpenMax;
        var num = Mathf.Lerp(OpenMin, b, openRate);

        if (0f <= FixedRate)
        {
            num = FixedRate;
        }
        var num2 = 0f;

        if (blendTimeCtrl != null)
        {
            num2 = blendTimeCtrl.Calculate();
        }
        foreach (var fbstargetInfo in FBSTarget)
        {
            var skinnedMeshRenderer = fbstargetInfo.GetSkinnedMeshRenderer();
            var dictionary          = DictionaryPool <int, float> .Get();

            for (var j = 0; j < fbstargetInfo.PtnSet.Length; j++)
            {
                dictionary[fbstargetInfo.PtnSet[j].Close] = 0f;
                dictionary[fbstargetInfo.PtnSet[j].Open]  = 0f;
            }

            var num3 = (int)Mathf.Clamp(num * 100f, 0f, 100f);
            if (num2 != 1f)
            {
                foreach (var num4 in dictBackFace.Keys)
                {
                    dictionary[fbstargetInfo.PtnSet[num4].Close] = dictionary[fbstargetInfo.PtnSet[num4].Close] + dictBackFace[num4] * (100 - num3) * (1f - num2);
                    dictionary[fbstargetInfo.PtnSet[num4].Open]  = dictionary[fbstargetInfo.PtnSet[num4].Open] + dictBackFace[num4] * num3 * (1f - num2);
                }
            }

            foreach (var num5 in dictNowFace.Keys)
            {
                dictionary[fbstargetInfo.PtnSet[num5].Close] = dictionary[fbstargetInfo.PtnSet[num5].Close] + dictNowFace[num5] * (100 - num3) * num2;
                dictionary[fbstargetInfo.PtnSet[num5].Open]  = dictionary[fbstargetInfo.PtnSet[num5].Open] + dictNowFace[num5] * num3 * num2;
            }

            foreach (var keyValuePair in dictionary)
            {
                if (keyValuePair.Key != -1)
                {
                    skinnedMeshRenderer.SetBlendShapeWeight(keyValuePair.Key, keyValuePair.Value);
                }
            }
            DictionaryPool <int, float> .Release(dictionary);
        }
    }
示例#5
0
    public void CalculateBlendShape()
    {
        if (this.FBSTarget.Length == 0)
        {
            return;
        }
        float num1 = Mathf.Lerp(this.OpenMin, (double)this.correctOpenMax >= 0.0 ? this.correctOpenMax : this.OpenMax, this.openRate);

        if (0.0 <= (double)this.FixedRate)
        {
            num1 = this.FixedRate;
        }
        float num2 = 0.0f;

        if (this.blendTimeCtrl != null)
        {
            num2 = this.blendTimeCtrl.Calculate();
        }
        foreach (FBSTargetInfo fbsTargetInfo in this.FBSTarget)
        {
            SkinnedMeshRenderer     skinnedMeshRenderer = fbsTargetInfo.GetSkinnedMeshRenderer();
            Dictionary <int, float> toRelease           = DictionaryPool <int, float> .Get();

            for (int index = 0; index < fbsTargetInfo.PtnSet.Length; ++index)
            {
                toRelease[fbsTargetInfo.PtnSet[index].Close] = 0.0f;
                toRelease[fbsTargetInfo.PtnSet[index].Open]  = 0.0f;
            }
            int num3 = (int)Mathf.Clamp(num1 * 100f, 0.0f, 100f);
            if ((double)num2 != 1.0)
            {
                foreach (int key in this.dictBackFace.Keys)
                {
                    toRelease[fbsTargetInfo.PtnSet[key].Close] = toRelease[fbsTargetInfo.PtnSet[key].Close] + (float)((double)this.dictBackFace[key] * (double)(100 - num3) * (1.0 - (double)num2));
                    toRelease[fbsTargetInfo.PtnSet[key].Open]  = toRelease[fbsTargetInfo.PtnSet[key].Open] + (float)((double)this.dictBackFace[key] * (double)num3 * (1.0 - (double)num2));
                }
            }
            foreach (int key in this.dictNowFace.Keys)
            {
                toRelease[fbsTargetInfo.PtnSet[key].Close] = toRelease[fbsTargetInfo.PtnSet[key].Close] + this.dictNowFace[key] * (float)(100 - num3) * num2;
                toRelease[fbsTargetInfo.PtnSet[key].Open]  = toRelease[fbsTargetInfo.PtnSet[key].Open] + this.dictNowFace[key] * (float)num3 * num2;
            }
            foreach (KeyValuePair <int, float> keyValuePair in toRelease)
            {
                if (keyValuePair.Key == -1)
                {
                    Debug.LogError((object)(((Object)skinnedMeshRenderer.get_sharedMesh()).get_name() + ": 多分、名前が間違ったデータがある"));
                }
                else
                {
                    skinnedMeshRenderer.SetBlendShapeWeight(keyValuePair.Key, keyValuePair.Value);
                }
            }
            DictionaryPool <int, float> .Release(toRelease);
        }
    }
示例#6
0
    // Token: 0x0600867A RID: 34426 RVA: 0x0034A374 File Offset: 0x00348774
    public void CalculateBlendShape()
    {
        if (this.FBSTarget.Length == 0)
        {
            return;
        }
        float b   = (this.correctOpenMax >= 0f) ? this.correctOpenMax : this.OpenMax;
        float num = Mathf.Lerp(this.OpenMin, b, this.openRate);

        if (0f <= this.FixedRate)
        {
            num = this.FixedRate;
        }
        float num2 = 0f;

        if (this.blendTimeCtrl != null)
        {
            num2 = this.blendTimeCtrl.Calculate();
        }
        foreach (FBSTargetInfo fbstargetInfo in this.FBSTarget)
        {
            SkinnedMeshRenderer     skinnedMeshRenderer = fbstargetInfo.GetSkinnedMeshRenderer();
            Dictionary <int, float> dictionary          = DictionaryPool <int, float> .Get();

            for (int j = 0; j < fbstargetInfo.PtnSet.Length; j++)
            {
                dictionary[fbstargetInfo.PtnSet[j].Close] = 0f;
                dictionary[fbstargetInfo.PtnSet[j].Open]  = 0f;
            }
            int num3 = (int)Mathf.Clamp(num * 100f, 0f, 100f);
            if (num2 != 1f)
            {
                foreach (int num4 in this.dictBackFace.Keys)
                {
                    dictionary[fbstargetInfo.PtnSet[num4].Close] = dictionary[fbstargetInfo.PtnSet[num4].Close] + this.dictBackFace[num4] * (float)(100 - num3) * (1f - num2);
                    dictionary[fbstargetInfo.PtnSet[num4].Open]  = dictionary[fbstargetInfo.PtnSet[num4].Open] + this.dictBackFace[num4] * (float)num3 * (1f - num2);
                }
            }
            foreach (int num5 in this.dictNowFace.Keys)
            {
                dictionary[fbstargetInfo.PtnSet[num5].Close] = dictionary[fbstargetInfo.PtnSet[num5].Close] + this.dictNowFace[num5] * (float)(100 - num3) * num2;
                dictionary[fbstargetInfo.PtnSet[num5].Open]  = dictionary[fbstargetInfo.PtnSet[num5].Open] + this.dictNowFace[num5] * (float)num3 * num2;
            }
            foreach (KeyValuePair <int, float> keyValuePair in dictionary)
            {
                if (keyValuePair.Key != -1)
                {
                    skinnedMeshRenderer.SetBlendShapeWeight(keyValuePair.Key, keyValuePair.Value);
                }
            }
            DictionaryPool <int, float> .Release(dictionary);
        }
    }
示例#7
0
        /// <summary>
        ///     Generate all shader code from <see cref="GenerateHLSL" /> attribute.
        /// </summary>
        /// <returns>An awaitable task.</returns>
        public static async Task GenerateAll()
        {
            Dictionary <string, List <ShaderTypeGenerator> > sourceGenerators = null;

            try
            {
                // Store per source file path the generator definitions
                sourceGenerators = DictionaryPool <string, List <ShaderTypeGenerator> > .Get();

                // Extract all types with the GenerateHLSL tag
                foreach (var type in TypeCache.GetTypesWithAttribute <GenerateHLSL>())
                {
                    var attr = type.GetCustomAttributes(typeof(GenerateHLSL), false).First() as GenerateHLSL;
                    if (!sourceGenerators.TryGetValue(attr.sourcePath, out var generators))
                    {
                        generators = ListPool <ShaderTypeGenerator> .Get();

                        sourceGenerators.Add(attr.sourcePath, generators);
                    }

                    generators.Add(new ShaderTypeGenerator(type, attr));
                }

                // Generate all files
                await Task.WhenAll(sourceGenerators.Select(async it =>
                                                           await GenerateAsync($"{it.Key}.hlsl", $"{Path.ChangeExtension(it.Key, "custom")}.hlsl", it.Value)));
            }
            finally
            {
                // Make sure we always release pooled resources
                if (sourceGenerators != null)
                {
                    foreach (var pair in sourceGenerators)
                    {
                        ListPool <ShaderTypeGenerator> .Release(pair.Value);
                    }
                    DictionaryPool <string, List <ShaderTypeGenerator> > .Release(sourceGenerators);
                }
            }
        }
示例#8
0
        public void Dispose()
        {
            if (_assetBundleInfoDict != null)
            {
                DictionaryPool <IgnoreCaseString, AssetBundleInfo> .Release(_assetBundleInfoDict);

                _assetBundleInfoDict = null;
            }

            if (_assetbundleDictionary != null)
            {
                DictionaryPool <IgnoreCaseString, GameAssetBundle> .Release(_assetbundleDictionary);

                _assetbundleDictionary = null;
            }

            if (_assetbundleincludes != null)
            {
                foreach (var item in _assetbundleincludes)
                {
                    ListPool <string> .Release(item.Value);
                }

                DictionaryPool <string, List <string> > .Release(_assetbundleincludes);

                _assetbundleincludes = null;
            }


            if (_exceptionHashSet != null)
            {
                HashSetPool <IgnoreCaseString> .Release(_exceptionHashSet);

                _exceptionHashSet = null;
            }
            _remoteinfo = null;
        }
示例#9
0
        public override void EvaluateDynamicMaterialSlots(List <MaterialSlot> inputSlots, List <MaterialSlot> outputSlots)
        {
            var dynamicInputSlotsToCompare = DictionaryPool <DynamicVectorMaterialSlot, ConcreteSlotValueType> .Get();

            var skippedDynamicSlots = ListPool <DynamicVectorMaterialSlot> .Get();

            var dynamicMatrixInputSlotsToCompare = DictionaryPool <DynamicMatrixMaterialSlot, ConcreteSlotValueType> .Get();

            var skippedDynamicMatrixSlots = ListPool <DynamicMatrixMaterialSlot> .Get();

            // iterate the input slots
            {
                foreach (var inputSlot in inputSlots)
                {
                    inputSlot.hasError = false;

                    // if there is a connection
                    var edges = owner.GetEdges(inputSlot.slotReference).ToList();
                    if (!edges.Any())
                    {
                        if (inputSlot is DynamicVectorMaterialSlot)
                        {
                            skippedDynamicSlots.Add(inputSlot as DynamicVectorMaterialSlot);
                        }
                        if (inputSlot is DynamicMatrixMaterialSlot)
                        {
                            skippedDynamicMatrixSlots.Add(inputSlot as DynamicMatrixMaterialSlot);
                        }
                        continue;
                    }

                    // get the output details
                    var outputSlotRef = edges[0].outputSlot;
                    var outputNode    = outputSlotRef.node;
                    if (outputNode == null)
                    {
                        continue;
                    }

                    var outputSlot = outputNode.FindOutputSlot <MaterialSlot>(outputSlotRef.slotId);
                    if (outputSlot == null)
                    {
                        continue;
                    }

                    if (outputSlot.hasError)
                    {
                        inputSlot.hasError = true;
                        continue;
                    }

                    var outputConcreteType = outputSlot.concreteValueType;
                    // dynamic input... depends on output from other node.
                    // we need to compare ALL dynamic inputs to make sure they
                    // are compatable.
                    if (inputSlot is DynamicVectorMaterialSlot)
                    {
                        dynamicInputSlotsToCompare.Add((DynamicVectorMaterialSlot)inputSlot, outputConcreteType);
                        continue;
                    }
                    else if (inputSlot is DynamicMatrixMaterialSlot)
                    {
                        dynamicMatrixInputSlotsToCompare.Add((DynamicMatrixMaterialSlot)inputSlot, outputConcreteType);
                        continue;
                    }
                }

                // and now dynamic matrices
                var dynamicMatrixType = ConvertDynamicMatrixInputTypeToConcrete(dynamicMatrixInputSlotsToCompare.Values);
                foreach (var dynamicKvP in dynamicMatrixInputSlotsToCompare)
                {
                    dynamicKvP.Key.SetConcreteType(dynamicMatrixType);
                }
                foreach (var skippedSlot in skippedDynamicMatrixSlots)
                {
                    skippedSlot.SetConcreteType(dynamicMatrixType);
                }

                // we can now figure out the dynamic slotType
                // from here set all the
                var dynamicType = SlotValueHelper.ConvertMatrixToVectorType(dynamicMatrixType);
                foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                {
                    dynamicKvP.Key.SetConcreteType(dynamicType);
                }
                foreach (var skippedSlot in skippedDynamicSlots)
                {
                    skippedSlot.SetConcreteType(dynamicType);
                }

                bool inputError = inputSlots.Any(x => x.hasError);
                if (inputError)
                {
                    owner.AddConcretizationError(objectId, string.Format("Node {0} had input error", objectId));
                    hasError = true;
                }
                // configure the output slots now
                // their slotType will either be the default output slotType
                // or the above dynanic slotType for dynamic nodes
                // or error if there is an input error
                foreach (var outputSlot in outputSlots)
                {
                    outputSlot.hasError = false;

                    if (inputError)
                    {
                        outputSlot.hasError = true;
                        continue;
                    }

                    if (outputSlot is DynamicVectorMaterialSlot)
                    {
                        (outputSlot as DynamicVectorMaterialSlot).SetConcreteType(dynamicType);
                        continue;
                    }
                    else if (outputSlot is DynamicMatrixMaterialSlot)
                    {
                        (outputSlot as DynamicMatrixMaterialSlot).SetConcreteType(dynamicMatrixType);
                        continue;
                    }
                }

                if (outputSlots.Any(x => x.hasError))
                {
                    owner.AddConcretizationError(objectId, string.Format("Node {0} had output error", objectId));
                    hasError = true;
                }
            }

            CalculateNodeHasError();

            ListPool <DynamicVectorMaterialSlot> .Release(skippedDynamicSlots);

            DictionaryPool <DynamicVectorMaterialSlot, ConcreteSlotValueType> .Release(dynamicInputSlotsToCompare);

            ListPool <DynamicMatrixMaterialSlot> .Release(skippedDynamicMatrixSlots);

            DictionaryPool <DynamicMatrixMaterialSlot, ConcreteSlotValueType> .Release(dynamicMatrixInputSlotsToCompare);
        }
示例#10
0
        private void SaveTrackingFile()
        {
            Logger.DebugLogDebug($"{nameof(SaveTrackingFile)} fired");
            if (!SavePending)
            {
                return;
            }
            if (TrackLastLoadedSceneFile == null)
            {
                throw new NullReferenceException($"{nameof(TrackLastLoadedSceneFile)} should not be null");
            }

            var prefix  = Path.Combine(Paths.CachePath, Path.GetFileName(TrackLastLoadedSceneFile));
            var newFile = string.Concat(prefix, Path.GetRandomFileName());
            var oldFile = string.Concat(prefix, Path.GetRandomFileName());

            var relativeScenes = DictionaryPool <string, string> .Get();

            try
            {
                foreach (var entry in LastLoadedScenes)
                {
                    relativeScenes[SceneRelativePathCache.Get(entry.Key)] =
                        Path.GetFileName(entry.Value);
                }

                lock (SavePendingLock)
                {
                    if (!SavePending)
                    {
                        return;
                    }

                    try
                    {
                        using (var fileStream = new FileStream(newFile, FileMode.Create))
                            using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
                            {
                                streamWriter.Write(GUID);
                                streamWriter.Write(TrackingFileEntrySplit[0]);
                                streamWriter.Write(Version);
                                streamWriter.Write(TrackingFileEntrySplit[0]);
                                streamWriter.Write(relativeScenes.Count);
                                streamWriter.Write(TrackingFileEntrySplit[0]);
                                streamWriter.Write('\n');
                                foreach (var entry in relativeScenes)
                                {
                                    streamWriter.Write(entry.Key);
                                    streamWriter.Write(TrackingFileEntrySplit[0]);
                                    streamWriter.Write(entry.Value);
                                    streamWriter.Write('\n');
                                }
                            }

                        File.Move(TrackLastLoadedSceneFile, oldFile);
                        File.Move(newFile, TrackLastLoadedSceneFile);
                        File.Delete(oldFile);
                        SavePending = false;
                        Logger.DebugLogDebug($"Updated {TrackLastLoadedSceneFile}");
                    }
                    catch (Exception err)
                    {
                        if (!File.Exists(oldFile))
                        {
                            throw;
                        }
                        Logger.LogException(err, this,
                                            $"{nameof(SaveTrackingFile)}: Error encountered, restoring {TrackLastLoadedSceneFile}");

                        File.Copy(oldFile, TrackLastLoadedSceneFile);

                        throw;
                    }
                    finally
                    {
                        if (File.Exists(oldFile))
                        {
                            File.Delete(oldFile);
                        }
                        if (File.Exists(newFile))
                        {
                            File.Delete(newFile);
                        }
                    }
                }
            }
            finally
            {
                DictionaryPool <string, string> .Release(relativeScenes);
            }
        }
示例#11
0
        // Internal validation
        // -------------------------------------------------

        public override void EvaluateDynamicMaterialSlots()
        {
            var dynamicInputSlotsToCompare = DictionaryPool <DynamicValueMaterialSlot, ConcreteSlotValueType> .Get();

            var skippedDynamicSlots = ListPool <DynamicValueMaterialSlot> .Get();

            // iterate the input slots
            using (var tempSlots = PooledList <MaterialSlot> .Get())
            {
                GetInputSlots(tempSlots);
                foreach (var inputSlot in tempSlots)
                {
                    inputSlot.hasError = false;

                    // if there is a connection
                    var edges = owner.GetEdges(inputSlot.slotReference).ToList();
                    if (!edges.Any())
                    {
                        if (inputSlot is DynamicValueMaterialSlot)
                        {
                            skippedDynamicSlots.Add(inputSlot as DynamicValueMaterialSlot);
                        }
                        continue;
                    }

                    // get the output details
                    var outputSlotRef = edges[0].outputSlot;
                    var outputNode    = owner.GetNodeFromGuid(outputSlotRef.nodeGuid);
                    if (outputNode == null)
                    {
                        continue;
                    }

                    var outputSlot = outputNode.FindOutputSlot <MaterialSlot>(outputSlotRef.slotId);
                    if (outputSlot == null)
                    {
                        continue;
                    }

                    if (outputSlot.hasError)
                    {
                        inputSlot.hasError = true;
                        continue;
                    }

                    var outputConcreteType = outputSlot.concreteValueType;
                    // dynamic input... depends on output from other node.
                    // we need to compare ALL dynamic inputs to make sure they
                    // are compatable.
                    if (inputSlot is DynamicValueMaterialSlot)
                    {
                        dynamicInputSlotsToCompare.Add((DynamicValueMaterialSlot)inputSlot, outputConcreteType);
                        continue;
                    }
                }

                m_MultiplyType = GetMultiplyType(dynamicInputSlotsToCompare.Values);

                // Resolve dynamics depending on matrix/vector configuration
                switch (m_MultiplyType)
                {
                // If all matrix resolve as per dynamic matrix
                case MultiplyType.Matrix:
                    var dynamicMatrixType = ConvertDynamicMatrixInputTypeToConcrete(dynamicInputSlotsToCompare.Values);
                    foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                    {
                        dynamicKvP.Key.SetConcreteType(dynamicMatrixType);
                    }
                    foreach (var skippedSlot in skippedDynamicSlots)
                    {
                        skippedSlot.SetConcreteType(dynamicMatrixType);
                    }
                    break;

                // If mixed handle differently:
                // Iterate all slots and set their concretes based on their edges
                // Find matrix slot and convert its type to a vector type
                // Reiterate all slots and set non matrix slots to the vector type
                case MultiplyType.Mixed:
                    foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                    {
                        SetConcreteValueTypeFromEdge(dynamicKvP.Key);
                    }
                    MaterialSlot          matrixSlot = GetMatrixSlot();
                    ConcreteSlotValueType vectorType = SlotValueHelper.ConvertMatrixToVectorType(matrixSlot.concreteValueType);
                    foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                    {
                        if (dynamicKvP.Key != matrixSlot)
                        {
                            dynamicKvP.Key.SetConcreteType(vectorType);
                        }
                    }
                    foreach (var skippedSlot in skippedDynamicSlots)
                    {
                        skippedSlot.SetConcreteType(vectorType);
                    }
                    break;

                // If all vector resolve as per dynamic vector
                default:
                    var dynamicVectorType = ConvertDynamicVectorInputTypeToConcrete(dynamicInputSlotsToCompare.Values);
                    foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                    {
                        dynamicKvP.Key.SetConcreteType(dynamicVectorType);
                    }
                    foreach (var skippedSlot in skippedDynamicSlots)
                    {
                        skippedSlot.SetConcreteType(dynamicVectorType);
                    }
                    break;
                }

                tempSlots.Clear();
                GetInputSlots(tempSlots);
                bool inputError = tempSlots.Any(x => x.hasError);
                if (inputError)
                {
                    owner.AddConcretizationError(guid, string.Format("Node {0} had input error", guid));
                    hasError = true;
                }
                // configure the output slots now
                // their slotType will either be the default output slotType
                // or the above dynanic slotType for dynamic nodes
                // or error if there is an input error
                tempSlots.Clear();
                GetOutputSlots(tempSlots);
                foreach (var outputSlot in tempSlots)
                {
                    outputSlot.hasError = false;

                    if (inputError)
                    {
                        outputSlot.hasError = true;
                        continue;
                    }

                    if (outputSlot is DynamicValueMaterialSlot)
                    {
                        // Apply similar logic to output slot
                        switch (m_MultiplyType)
                        {
                        // As per dynamic matrix
                        case MultiplyType.Matrix:
                            var dynamicMatrixType = ConvertDynamicMatrixInputTypeToConcrete(dynamicInputSlotsToCompare.Values);
                            (outputSlot as DynamicValueMaterialSlot).SetConcreteType(dynamicMatrixType);
                            break;

                        // Mixed configuration
                        // Find matrix slot and convert type to vector
                        // Set output concrete to vector
                        case MultiplyType.Mixed:
                            MaterialSlot          matrixSlot = GetMatrixSlot();
                            ConcreteSlotValueType vectorType = SlotValueHelper.ConvertMatrixToVectorType(matrixSlot.concreteValueType);
                            (outputSlot as DynamicValueMaterialSlot).SetConcreteType(vectorType);
                            break;

                        // As per dynamic vector
                        default:
                            var dynamicVectorType = ConvertDynamicVectorInputTypeToConcrete(dynamicInputSlotsToCompare.Values);
                            (outputSlot as DynamicValueMaterialSlot).SetConcreteType(dynamicVectorType);
                            break;
                        }
                        continue;
                    }
                }

                tempSlots.Clear();
                GetOutputSlots(tempSlots);
                if (tempSlots.Any(x => x.hasError))
                {
                    owner.AddConcretizationError(guid, string.Format("Node {0} had output error", guid));
                    hasError = true;
                }
            }

            CalculateNodeHasError();

            ListPool <DynamicValueMaterialSlot> .Release(skippedDynamicSlots);

            DictionaryPool <DynamicValueMaterialSlot, ConcreteSlotValueType> .Release(dynamicInputSlotsToCompare);
        }
示例#12
0
        internal static void ExportSelected(LocaleIdentifier source, string dir, string name, XliffVersion version, Dictionary <StringTableCollection, HashSet <int> > collectionsWithSelectedIndexes, ITaskReporter reporter = null)
        {
            var documents = DictionaryPool <LocaleIdentifier, IXliffDocument> .Get();

            try
            {
                // Used for reporting
                int   totalTasks = collectionsWithSelectedIndexes.Sum(c => c.Value.Count);
                float taskStep   = 1.0f / (totalTasks * 2.0f);
                float progress   = 0;
                reporter?.Start($"Exporting {totalTasks} String Tables to XLIFF", string.Empty);

                foreach (var kvp in collectionsWithSelectedIndexes)
                {
                    var stringTableCollection = kvp.Key;
                    var sourceTable           = stringTableCollection.GetTable(source) as StringTable;
                    if (sourceTable == null)
                    {
                        var message = $"Collection {stringTableCollection.TableCollectionName} does not contain a table for the source language {source}";
                        reporter?.Fail(message);
                        throw new Exception(message);
                    }

                    foreach (var stringTableIndex in kvp.Value)
                    {
                        var stringTable = stringTableCollection.StringTables[stringTableIndex];

                        reporter?.ReportProgress($"Generating document for {stringTable.name}", progress);
                        progress += taskStep;

                        if (!documents.TryGetValue(stringTable.LocaleIdentifier, out var targetDoc))
                        {
                            targetDoc = CreateDocument(source, stringTable.LocaleIdentifier, version);
                            documents[stringTable.LocaleIdentifier] = targetDoc;
                        }

                        AddTableToDocument(targetDoc, sourceTable, stringTable);
                    }
                }

                // Now write the files
                foreach (var doc in documents)
                {
                    var cleanName = CleanFileName(name);
                    var fileName  = $"{cleanName}_{doc.Key.Code}.xlf";
                    var filePath  = Path.Combine(dir, fileName);

                    reporter?.ReportProgress($"Writing {fileName}", progress);
                    progress += taskStep;
                    using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                    {
                        doc.Value.Serialize(stream);
                    }
                }

                reporter?.Completed($"Finished exporting");
            }
            catch (Exception e)
            {
                reporter?.Fail(e.Message);
                throw;
            }
            finally
            {
                DictionaryPool <LocaleIdentifier, IXliffDocument> .Release(documents);
            }
        }
示例#13
0
        public void RegisterReplacementsForNames(params string[] origNames)
        {
            var needsTranslation = ListPool <string> .Get();

            try
            {
                needsTranslation.Capacity = origNames.Length;

                var fastReplacements = DictionaryPool <string, string> .Get();

                try
                {
                    foreach (var origString in origNames)
                    {
                        if (TranslationHelper.TryTranslateName(NameScope.DefaultNameScope, origString,
                                                               out var translatedString))
                        {
                            //fastReplacements[origString] = origString;
                            fastReplacements[translatedString] = translatedString;
                        }
                        else
                        {
                            needsTranslation.Add(origString);
                        }
                    }

                    if (fastReplacements.Count > 0)
                    {
                        RegisterReplacementStrings(fastReplacements);
                    }
                }
                finally
                {
                    DictionaryPool <string, string> .Release(fastReplacements);
                }

                foreach (var toTranslate in needsTranslation)
                {
                    void ResultHandler(ITranslationResult result)
                    {
                        var replacements = DictionaryPool <string, string> .Get();

                        try
                        {
                            if (!TranslationHelper.NameNeedsTranslation(toTranslate, NameScope.DefaultNameScope))
                            {
                                replacements[toTranslate] = toTranslate;
                            }

                            if (result.Succeeded)
                            {
                                replacements[result.TranslatedText] = result.TranslatedText;
                            }

                            RegisterReplacementStrings(replacements);
                        }
                        finally
                        {
                            DictionaryPool <string, string> .Release(replacements);
                        }
                    }

                    GeBoAPI.Instance.AutoTranslationHelper.TranslateAsync(toTranslate,
                                                                          NameScope.DefaultNameScope.TranslationScope, ResultHandler);
                }
            }
            finally
            {
                ListPool <string> .Release(needsTranslation);
            }
        }
示例#14
0
        private void HandleDirectionMove(Direction scanDirection, Vector2Int negativeEndPosition, Vector2Int positiveEndPosition, Stack <Command> tickCommands, bool canBounce)
        {
            var scanDisplacement = DirectionUtils.DirectionToDisplacement(scanDirection);

            var impactBlocks = DictionaryPool <Block, int> .Get();

            for (var position = negativeEndPosition + scanDisplacement; position != positiveEndPosition; position += scanDisplacement)
            {
                var blocks = m_logicGameManager.Map[position.x, position.y];
                foreach (var block in blocks)
                {
                    if (!HasAttribute(block, AttributeCategory.Move) || !DirectionUtils.IsParallel(scanDirection, block.direction))
                    {
                        continue;
                    }
                    var impactDirection    = 1;
                    var impactDisplacement = scanDisplacement;
                    if (block.direction != scanDirection)
                    {
                        impactDirection    = 2;
                        impactDisplacement = Vector2Int.zero - scanDisplacement;
                    }
                    impactBlocks[block] = impactBlocks.GetOrDefault(block, 0) | impactDirection;
                    if (HasAttribute(block, AttributeCategory.Push))
                    {
                        for (var pushPosition = position + impactDisplacement; m_logicGameManager.InMap(pushPosition); pushPosition += impactDisplacement)
                        {
                            var pushBlocks = m_logicGameManager.Map[pushPosition.x, pushPosition.y];
                            var hasPush    = false;
                            foreach (var pushBlock in pushBlocks)
                            {
                                if (HasAttribute(pushBlock, AttributeCategory.Push))
                                {
                                    impactBlocks[pushBlock] = impactBlocks.GetOrDefault(pushBlock, 0) | impactDirection;
                                    hasPush = true;
                                }
                            }
                            if (!hasPush)
                            {
                                break;
                            }
                        }
                    }
                    if (HasAttribute(block, AttributeCategory.Pull))
                    {
                        for (var pullPosition = position - impactDisplacement; m_logicGameManager.InMap(pullPosition); pullPosition -= impactDisplacement)
                        {
                            var pullBlocks = m_logicGameManager.Map[pullPosition.x, pullPosition.y];
                            var hasPull    = false;
                            foreach (var pullBlock in pullBlocks)
                            {
                                if (HasAttribute(pullBlock, AttributeCategory.Pull))
                                {
                                    impactBlocks[pullBlock] = impactBlocks.GetOrDefault(pullBlock, 0) | impactDirection;
                                    hasPull = true;
                                }
                            }
                            if (!hasPull)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            for (var position = positiveEndPosition - scanDisplacement; position != negativeEndPosition; position -= scanDisplacement)
            {
                var blocks = m_logicGameManager.Map[position.x, position.y];
                foreach (var block in blocks)
                {
                    if (impactBlocks.GetOrDefault(block, 0) == 3)
                    {
                        impactBlocks[block] = 0;
                    }
                }
            }

            HandlePreMove(impactBlocks, scanDisplacement, tickCommands);

            {
                var stopPosition = positiveEndPosition - scanDisplacement;
                {
                    var blocks = m_logicGameManager.Map[stopPosition.x, stopPosition.y];
                    foreach (var block in blocks)
                    {
                        var impact = 0;
                        if (impactBlocks.TryGetValue(block, out impact))
                        {
                            impactBlocks[block] &= ~1;
                        }
                    }
                }
            }
            {
                var stopPosition = negativeEndPosition + scanDisplacement;
                {
                    var blocks = m_logicGameManager.Map[stopPosition.x, stopPosition.y];
                    foreach (var block in blocks)
                    {
                        var impact = 0;
                        if (impactBlocks.TryGetValue(block, out impact))
                        {
                            impactBlocks[block] &= ~2;
                        }
                    }
                }
            }
            for (var position = positiveEndPosition - scanDisplacement; position != negativeEndPosition + scanDisplacement; position -= scanDisplacement)
            {
                var hasStop = false;
                {
                    var blocks = m_logicGameManager.Map[position.x, position.y];
                    foreach (var block in blocks)
                    {
                        if (HasAttribute(block, AttributeCategory.Stop) || HasAttribute(block, AttributeCategory.Pull) || HasAttribute(block, AttributeCategory.Push))
                        {
                            if (impactBlocks.GetOrDefault(block, 0) != 1)
                            {
                                hasStop = true;
                                break;
                            }
                        }
                    }
                }
                if (hasStop)
                {
                    var stopPosition = position - scanDisplacement;
                    {
                        var blocks = m_logicGameManager.Map[stopPosition.x, stopPosition.y];
                        foreach (var block in blocks)
                        {
                            var impact = 0;
                            if (impactBlocks.TryGetValue(block, out impact))
                            {
                                impactBlocks[block] &= ~1;
                            }
                        }
                    }
                }
            }
            for (var position = negativeEndPosition + scanDisplacement; position != positiveEndPosition - scanDisplacement; position += scanDisplacement)
            {
                var hasStop = false;
                {
                    var blocks = m_logicGameManager.Map[position.x, position.y];
                    foreach (var block in blocks)
                    {
                        if (HasAttribute(block, AttributeCategory.Stop) || HasAttribute(block, AttributeCategory.Pull) || HasAttribute(block, AttributeCategory.Push))
                        {
                            if (impactBlocks.GetOrDefault(block, 0) != 2)
                            {
                                hasStop = true;
                                break;
                            }
                        }
                    }
                }
                if (hasStop)
                {
                    var stopPosition = position + scanDisplacement;
                    {
                        var blocks = m_logicGameManager.Map[stopPosition.x, stopPosition.y];
                        foreach (var block in blocks)
                        {
                            var impact = 0;
                            if (impactBlocks.TryGetValue(block, out impact))
                            {
                                impactBlocks[block] &= ~2;
                            }
                        }
                    }
                }
            }

            foreach (var impactBlockPair in impactBlocks)
            {
                var block  = impactBlockPair.Key;
                var impact = impactBlockPair.Value;

                if (canBounce)
                {
                    if (HasAttribute(block, AttributeCategory.Move) && impact == 0)
                    {
                        block.direction = DirectionUtils.GetOppositeDirection(block.direction);
                    }
                }
                else
                {
                    if (impact == 1)
                    {
                        PerformMoveBlockCommand(block, scanDirection, 1, tickCommands);
                    }
                    else if (impact == 2)
                    {
                        PerformMoveBlockCommand(block, DirectionUtils.GetOppositeDirection(scanDirection), 1, tickCommands);
                    }
                }
            }

            DictionaryPool <Block, int> .Release(impactBlocks);
        }
        public override void ValidateNode()
        {
            var isInError    = false;
            var errorMessage = k_validationErrorMessage;

            var dynamicInputSlotsToCompare = DictionaryPool <DynamicVectorMaterialSlot, ConcreteSlotValueType> .Get();

            var skippedDynamicSlots = ListPool <DynamicVectorMaterialSlot> .Get();

            var dynamicMatrixInputSlotsToCompare = DictionaryPool <DynamicMatrixMaterialSlot, ConcreteSlotValueType> .Get();

            var skippedDynamicMatrixSlots = ListPool <DynamicMatrixMaterialSlot> .Get();

            // iterate the input slots
            s_TempSlots.Clear();
            GetInputSlots(s_TempSlots);
            foreach (var inputSlot in s_TempSlots)
            {
                inputSlot.hasError = false;

                // if there is a connection
                var edges = owner.GetEdges(inputSlot.slotReference).ToList();
                if (!edges.Any())
                {
                    if (inputSlot is DynamicVectorMaterialSlot)
                    {
                        skippedDynamicSlots.Add(inputSlot as DynamicVectorMaterialSlot);
                    }
                    if (inputSlot is DynamicMatrixMaterialSlot)
                    {
                        skippedDynamicMatrixSlots.Add(inputSlot as DynamicMatrixMaterialSlot);
                    }
                    continue;
                }

                // get the output details
                var outputSlotRef = edges[0].outputSlot;
                var outputNode    = owner.GetNodeFromGuid(outputSlotRef.nodeGuid);
                if (outputNode == null)
                {
                    continue;
                }

                var outputSlot = outputNode.FindOutputSlot <MaterialSlot>(outputSlotRef.slotId);
                if (outputSlot == null)
                {
                    continue;
                }

                if (outputSlot.hasError)
                {
                    inputSlot.hasError = true;
                    continue;
                }

                var outputConcreteType = outputSlot.concreteValueType;
                // dynamic input... depends on output from other node.
                // we need to compare ALL dynamic inputs to make sure they
                // are compatable.
                if (inputSlot is DynamicVectorMaterialSlot)
                {
                    dynamicInputSlotsToCompare.Add((DynamicVectorMaterialSlot)inputSlot, outputConcreteType);
                    continue;
                }
                else if (inputSlot is DynamicMatrixMaterialSlot)
                {
                    dynamicMatrixInputSlotsToCompare.Add((DynamicMatrixMaterialSlot)inputSlot, outputConcreteType);
                    continue;
                }
            }

            // and now dynamic matrices
            var dynamicMatrixType = ConvertDynamicMatrixInputTypeToConcrete(dynamicMatrixInputSlotsToCompare.Values);

            foreach (var dynamicKvP in dynamicMatrixInputSlotsToCompare)
            {
                dynamicKvP.Key.SetConcreteType(dynamicMatrixType);
            }
            foreach (var skippedSlot in skippedDynamicMatrixSlots)
            {
                skippedSlot.SetConcreteType(dynamicMatrixType);
            }

            // we can now figure out the dynamic slotType
            // from here set all the
            var dynamicType = SlotValueHelper.ConvertMatrixToVectorType(dynamicMatrixType);

            foreach (var dynamicKvP in dynamicInputSlotsToCompare)
            {
                dynamicKvP.Key.SetConcreteType(dynamicType);
            }
            foreach (var skippedSlot in skippedDynamicSlots)
            {
                skippedSlot.SetConcreteType(dynamicType);
            }

            s_TempSlots.Clear();
            GetInputSlots(s_TempSlots);
            var inputError = s_TempSlots.Any(x => x.hasError);

            // configure the output slots now
            // their slotType will either be the default output slotType
            // or the above dynanic slotType for dynamic nodes
            // or error if there is an input error
            s_TempSlots.Clear();
            GetOutputSlots(s_TempSlots);
            foreach (var outputSlot in s_TempSlots)
            {
                outputSlot.hasError = false;

                if (inputError)
                {
                    outputSlot.hasError = true;
                    continue;
                }

                if (outputSlot is DynamicVectorMaterialSlot)
                {
                    (outputSlot as DynamicVectorMaterialSlot).SetConcreteType(dynamicType);
                    continue;
                }
                else if (outputSlot is DynamicMatrixMaterialSlot)
                {
                    (outputSlot as DynamicMatrixMaterialSlot).SetConcreteType(dynamicMatrixType);
                    continue;
                }
            }

            isInError |= inputError;
            s_TempSlots.Clear();
            GetOutputSlots(s_TempSlots);
            isInError |= s_TempSlots.Any(x => x.hasError);
            isInError |= CalculateNodeHasError(ref errorMessage);
            isInError |= ValidateConcretePrecision(ref errorMessage);
            hasError   = isInError;

            if (isInError)
            {
                ((GraphData)owner).AddValidationError(tempId, errorMessage);
            }
            else
            {
                ++version;
            }

            ListPool <DynamicVectorMaterialSlot> .Release(skippedDynamicSlots);

            DictionaryPool <DynamicVectorMaterialSlot, ConcreteSlotValueType> .Release(dynamicInputSlotsToCompare);

            ListPool <DynamicMatrixMaterialSlot> .Release(skippedDynamicMatrixSlots);

            DictionaryPool <DynamicMatrixMaterialSlot, ConcreteSlotValueType> .Release(dynamicMatrixInputSlotsToCompare);
        }
        public List <Callback> GenerateDependencyGraph()
        {
            var callbacks     = GetCallbacks();
            var packageLookup = DictionaryPool <string, List <Callback> > .Get();

            var assemblyLookup = DictionaryPool <string, List <Callback> > .Get();

            var classLookup = DictionaryPool <Type, Callback> .Get();

            // First generate our lookups for class, assembly and package.
            foreach (var cb in callbacks)
            {
                classLookup[cb.classType] = cb;

                var assemblyName = cb.classType.Assembly.GetName().Name;
                if (!assemblyLookup.TryGetValue(assemblyName, out var assemblies))
                {
                    assemblies = new List <Callback>();
                    assemblyLookup[assemblyName] = assemblies;
                }
                assemblies.Add(cb);

                var package = cb.packageName;
                if (package != null)
                {
                    if (!packageLookup.TryGetValue(package, out var packages))
                    {
                        packages = new List <Callback>();
                        packageLookup[package] = packages;
                    }
                    packages.Add(cb);
                }
            }

            // Sort the methods so that the output order is deterministic.
            callbacks.Sort();

            // Now connect the dependency graph nodes
            foreach (var dependency in callbacks)
            {
                // Dependency by class
                foreach (var runAfter in dependency.GetCustomAttributes <RunAfterClassAttribute>())
                {
                    // Ignore classes that may not exist in the project
                    if (runAfter.classType == null)
                    {
                        continue;
                    }

                    if (classLookup.TryGetValue(runAfter.classType, out var runAfterMethodInfo))
                    {
                        dependency.AddIncomingConnection(runAfterMethodInfo);
                    }
                }
                foreach (var runBefore in dependency.GetCustomAttributes <RunBeforeClassAttribute>())
                {
                    // Ignore classes that may not exist in the project
                    if (runBefore.classType == null)
                    {
                        continue;
                    }

                    if (classLookup.TryGetValue(runBefore.classType, out var runBeforeMethodInfo))
                    {
                        dependency.AddOutgoingConnection(runBeforeMethodInfo);
                    }
                }

                // Dependency by package
                foreach (var runAfter in dependency.GetCustomAttributes <RunAfterPackageAttribute>())
                {
                    if (packageLookup.TryGetValue(runAfter.packageName, out var runAfterMethodInfos))
                    {
                        dependency.AddIncomingConnections(runAfterMethodInfos);
                    }
                }
                foreach (var runBefore in dependency.GetCustomAttributes <RunBeforePackageAttribute>())
                {
                    if (packageLookup.TryGetValue(runBefore.packageName, out var runBeforeMethodInfos))
                    {
                        dependency.AddOutgoingConnections(runBeforeMethodInfos);
                    }
                }

                // Dependency by Assembly
                foreach (var runAfter in dependency.GetCustomAttributes <RunAfterAssemblyAttribute>())
                {
                    if (assemblyLookup.TryGetValue(runAfter.assemblyName, out var runAfterMethodInfos))
                    {
                        dependency.AddIncomingConnections(runAfterMethodInfos);
                    }
                }
                foreach (var runBefore in dependency.GetCustomAttributes <RunBeforeAssemblyAttribute>())
                {
                    if (assemblyLookup.TryGetValue(runBefore.assemblyName, out var runBeforeMethodInfos))
                    {
                        dependency.AddOutgoingConnections(runBeforeMethodInfos);
                    }
                }
            }

            DictionaryPool <string, List <Callback> > .Release(packageLookup);

            DictionaryPool <string, List <Callback> > .Release(assemblyLookup);

            DictionaryPool <Type, Callback> .Release(classLookup);

            return(callbacks);
        }
示例#17
0
        internal static GenericMenu BuildPopupList(Object target, UnityEventBase dummyEvent, SerializedProperty listener)
        {
            //special case for components... we want all the game objects targets there!
            var targetToUse = target;

            if (targetToUse is Component)
            {
                targetToUse = (target as Component).gameObject;
            }

            // find the current event target...
            var methodName = listener.FindPropertyRelative(kMethodNamePath);

            var menu = new GenericMenu();

            menu.AddItem(new GUIContent(kNoFunctionString),
                         string.IsNullOrEmpty(methodName.stringValue),
                         ClearEventFunction,
                         new UnityEventFunction(listener, null, null, PersistentListenerMode.EventDefined));

            if (targetToUse == null)
            {
                return(menu);
            }

            menu.AddSeparator("");

            // figure out the signature of this delegate...
            // The property at this stage points to the 'container' and has the field name
            Type delegateType = dummyEvent.GetType();

            // check out the signature of invoke as this is the callback!
            MethodInfo delegateMethod         = delegateType.GetMethod("Invoke");
            var        delegateArgumentsTypes = delegateMethod.GetParameters().Select(x => x.ParameterType).ToArray();

            var duplicateNames = DictionaryPool <string, int> .Get();

            var duplicateFullNames = DictionaryPool <string, int> .Get();

            GeneratePopUpForType(menu, targetToUse, targetToUse.GetType().Name, listener, delegateArgumentsTypes);
            duplicateNames[targetToUse.GetType().Name] = 0;
            if (targetToUse is GameObject)
            {
                Component[] comps = (targetToUse as GameObject).GetComponents <Component>();

                // Collect all the names and record how many times the same name is used.
                foreach (Component comp in comps)
                {
                    var duplicateIndex = 0;
                    if (duplicateNames.TryGetValue(comp.GetType().Name, out duplicateIndex))
                    {
                        duplicateIndex++;
                    }
                    duplicateNames[comp.GetType().Name] = duplicateIndex;
                }

                foreach (Component comp in comps)
                {
                    if (comp == null)
                    {
                        continue;
                    }

                    var    compType       = comp.GetType();
                    string targetName     = compType.Name;
                    int    duplicateIndex = 0;

                    // Is this name used multiple times? If so then use the full name plus an index if there are also duplicates of this. (case 1309997)
                    if (duplicateNames[compType.Name] > 0)
                    {
                        if (duplicateFullNames.TryGetValue(compType.FullName, out duplicateIndex))
                        {
                            targetName = $"{compType.FullName} ({duplicateIndex})";
                        }
                        else
                        {
                            targetName = compType.FullName;
                        }
                    }
                    GeneratePopUpForType(menu, comp, targetName, listener, delegateArgumentsTypes);
                    duplicateFullNames[compType.FullName] = duplicateIndex + 1;
                }

                DictionaryPool <string, int> .Release(duplicateNames);

                DictionaryPool <string, int> .Release(duplicateFullNames);
            }
            return(menu);
        }
示例#18
0
 public void Dispose()
 {
     DictionaryPool.Release(Dictionary);
 }
示例#19
0
        private void SettingInventoryFilter()
        {
            Manager.Resources resources = !Singleton <Manager.Resources> .IsInstance() ? (Manager.Resources)null : Singleton <Manager.Resources> .Instance;

            PlayerActor playerActor = !Singleton <Manager.Map> .IsInstance() ? (PlayerActor)null : Singleton <Manager.Map> .Instance.Player;

            if (Object.op_Equality((Object)resources, (Object)null) || Object.op_Equality((Object)playerActor, (Object)null))
            {
                return;
            }
            PetHomePoint.HomeKind kind = this._currentPetHomePoint.Kind;
            Dictionary <int, List <ValueTuple <ItemIDKeyPair, int> > > petItemInfoTable = resources.AnimalTable.PetItemInfoTable;
            int key = (int)kind;

            InventoryFacadeViewer.ItemFilter[] itemFilter1 = (InventoryFacadeViewer.ItemFilter[])null;
            if (!this._itemFilterTable.TryGetValue(key, out itemFilter1))
            {
                List <ValueTuple <ItemIDKeyPair, int> > valueTupleList;
                petItemInfoTable.TryGetValue(key, out valueTupleList);
                if (!((IReadOnlyList <ValueTuple <ItemIDKeyPair, int> >)valueTupleList).IsNullOrEmpty <ValueTuple <ItemIDKeyPair, int> >())
                {
                    Dictionary <int, List <int> > toRelease = DictionaryPool <int, List <int> > .Get();

                    using (List <ValueTuple <ItemIDKeyPair, int> > .Enumerator enumerator = valueTupleList.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            ItemIDKeyPair itemIdKeyPair = (ItemIDKeyPair)enumerator.Current.Item1;
                            List <int>    intList1;
                            if (!toRelease.TryGetValue(itemIdKeyPair.categoryID, out intList1) || intList1 == null)
                            {
                                List <int> intList2 = ListPool <int> .Get();

                                toRelease[itemIdKeyPair.categoryID] = intList2;
                                intList1 = intList2;
                            }
                            intList1.Add(itemIdKeyPair.itemID);
                        }
                    }
                    InventoryFacadeViewer.ItemFilter[] itemFilter2 = new InventoryFacadeViewer.ItemFilter[toRelease.Count];
                    int index1 = 0;
                    foreach (KeyValuePair <int, List <int> > keyValuePair in toRelease)
                    {
                        int[] IDs = new int[keyValuePair.Value.Count];
                        for (int index2 = 0; index2 < IDs.Length; ++index2)
                        {
                            IDs[index2] = keyValuePair.Value[index2];
                        }
                        itemFilter2[index1] = new InventoryFacadeViewer.ItemFilter(keyValuePair.Key, IDs);
                        ++index1;
                    }
                    List <int> list = toRelease.Keys.ToList <int>();
                    for (int index2 = 0; index2 < list.Count; ++index2)
                    {
                        ListPool <int> .Release(toRelease[list[index2]]);
                    }
                    DictionaryPool <int, List <int> > .Release(toRelease);

                    this._itemFilterTable[key] = itemFilter2;
                    this._inventoryUI.SetItemFilter(itemFilter2);
                }
                else
                {
                    this._itemFilterTable[key] = this._emptyFilter;
                    this._inventoryUI.SetItemFilter(this._emptyFilter);
                }
            }
            else
            {
                this._inventoryUI.SetItemFilter(itemFilter1);
            }
        }
示例#20
0
        // Internal validation
        // -------------------------------------------------

        public override void ValidateNode()
        {
            var isInError = false;

            // all children nodes needs to be updated first
            // so do that here
            var slots = ListPool <MaterialSlot> .Get();

            GetInputSlots(slots);
            foreach (var inputSlot in slots)
            {
                inputSlot.hasError = false;

                var edges = owner.GetEdges(inputSlot.slotReference);
                foreach (var edge in edges)
                {
                    var fromSocketRef = edge.outputSlot;
                    var outputNode    = owner.GetNodeFromGuid(fromSocketRef.nodeGuid);
                    if (outputNode == null)
                    {
                        continue;
                    }

                    outputNode.ValidateNode();
                    if (outputNode.hasError)
                    {
                        isInError = true;
                    }
                }
            }
            ListPool <MaterialSlot> .Release(slots);

            var dynamicInputSlotsToCompare = DictionaryPool <DynamicValueMaterialSlot, ConcreteSlotValueType> .Get();

            var skippedDynamicSlots = ListPool <DynamicValueMaterialSlot> .Get();

            // iterate the input slots
            s_TempSlots.Clear();
            GetInputSlots(s_TempSlots);
            foreach (var inputSlot in s_TempSlots)
            {
                // if there is a connection
                var edges = owner.GetEdges(inputSlot.slotReference).ToList();
                if (!edges.Any())
                {
                    if (inputSlot is DynamicValueMaterialSlot)
                    {
                        skippedDynamicSlots.Add(inputSlot as DynamicValueMaterialSlot);
                    }
                    continue;
                }

                // get the output details
                var outputSlotRef = edges[0].outputSlot;
                var outputNode    = owner.GetNodeFromGuid(outputSlotRef.nodeGuid);
                if (outputNode == null)
                {
                    continue;
                }

                var outputSlot = outputNode.FindOutputSlot <MaterialSlot>(outputSlotRef.slotId);
                if (outputSlot == null)
                {
                    continue;
                }

                if (outputSlot.hasError)
                {
                    inputSlot.hasError = true;
                    continue;
                }

                var outputConcreteType = outputSlot.concreteValueType;
                // dynamic input... depends on output from other node.
                // we need to compare ALL dynamic inputs to make sure they
                // are compatable.
                if (inputSlot is DynamicValueMaterialSlot)
                {
                    dynamicInputSlotsToCompare.Add((DynamicValueMaterialSlot)inputSlot, outputConcreteType);
                    continue;
                }

                // if we have a standard connection... just check the types work!
                if (!ImplicitConversionExists(outputConcreteType, inputSlot.concreteValueType))
                {
                    inputSlot.hasError = true;
                }
            }

            m_MultiplyType = GetMultiplyType(dynamicInputSlotsToCompare.Values);

            // Resolve dynamics depending on matrix/vector configuration
            switch (m_MultiplyType)
            {
            // If all matrix resolve as per dynamic matrix
            case MultiplyType.Matrix:
                var dynamicMatrixType = ConvertDynamicMatrixInputTypeToConcrete(dynamicInputSlotsToCompare.Values);
                foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                {
                    dynamicKvP.Key.SetConcreteType(dynamicMatrixType);
                }
                foreach (var skippedSlot in skippedDynamicSlots)
                {
                    skippedSlot.SetConcreteType(dynamicMatrixType);
                }
                break;

            // If mixed handle differently:
            // Iterate all slots and set their concretes based on their edges
            // Find matrix slot and convert its type to a vector type
            // Reiterate all slots and set non matrix slots to the vector type
            case MultiplyType.Mixed:
                foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                {
                    SetConcreteValueTypeFromEdge(dynamicKvP.Key);
                }
                MaterialSlot          matrixSlot = GetMatrixSlot();
                ConcreteSlotValueType vectorType = SlotValueHelper.ConvertMatrixToVectorType(matrixSlot.concreteValueType);
                foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                {
                    if (dynamicKvP.Key != matrixSlot)
                    {
                        dynamicKvP.Key.SetConcreteType(vectorType);
                    }
                }
                foreach (var skippedSlot in skippedDynamicSlots)
                {
                    skippedSlot.SetConcreteType(vectorType);
                }
                break;

            // If all vector resolve as per dynamic vector
            default:
                var dynamicVectorType = ConvertDynamicInputTypeToConcrete(dynamicInputSlotsToCompare.Values);
                foreach (var dynamicKvP in dynamicInputSlotsToCompare)
                {
                    dynamicKvP.Key.SetConcreteType(dynamicVectorType);
                }
                foreach (var skippedSlot in skippedDynamicSlots)
                {
                    skippedSlot.SetConcreteType(dynamicVectorType);
                }
                break;
            }

            s_TempSlots.Clear();
            GetInputSlots(s_TempSlots);
            var inputError = s_TempSlots.Any(x => x.hasError);

            // configure the output slots now
            // their slotType will either be the default output slotType
            // or the above dynanic slotType for dynamic nodes
            // or error if there is an input error
            s_TempSlots.Clear();
            GetOutputSlots(s_TempSlots);
            foreach (var outputSlot in s_TempSlots)
            {
                outputSlot.hasError = false;

                if (inputError)
                {
                    outputSlot.hasError = true;
                    continue;
                }

                if (outputSlot is DynamicValueMaterialSlot)
                {
                    // Apply similar logic to output slot
                    switch (m_MultiplyType)
                    {
                    // As per dynamic matrix
                    case MultiplyType.Matrix:
                        var dynamicMatrixType = ConvertDynamicMatrixInputTypeToConcrete(dynamicInputSlotsToCompare.Values);
                        (outputSlot as DynamicValueMaterialSlot).SetConcreteType(dynamicMatrixType);
                        break;

                    // Mixed configuration
                    // Find matrix slot and convert type to vector
                    // Set output concrete to vector
                    case MultiplyType.Mixed:
                        MaterialSlot          matrixSlot = GetMatrixSlot();
                        ConcreteSlotValueType vectorType = SlotValueHelper.ConvertMatrixToVectorType(matrixSlot.concreteValueType);
                        (outputSlot as DynamicValueMaterialSlot).SetConcreteType(vectorType);
                        break;

                    // As per dynamic vector
                    default:
                        var dynamicVectorType = ConvertDynamicInputTypeToConcrete(dynamicInputSlotsToCompare.Values);
                        (outputSlot as DynamicValueMaterialSlot).SetConcreteType(dynamicVectorType);
                        break;
                    }
                    continue;
                }
            }

            isInError |= inputError;
            s_TempSlots.Clear();
            GetOutputSlots(s_TempSlots);
            isInError |= s_TempSlots.Any(x => x.hasError);
            isInError |= CalculateNodeHasError();
            hasError   = isInError;

            if (!hasError)
            {
                ++version;
            }

            ListPool <DynamicValueMaterialSlot> .Release(skippedDynamicSlots);

            DictionaryPool <DynamicValueMaterialSlot, ConcreteSlotValueType> .Release(dynamicInputSlotsToCompare);
        }
示例#21
0
        private static void FreeHUpdateUI()
        {
            // for 3P the character names show in one extra place that the standard check doesn't cover.
            // easiest to just update each time.
            var freeHScene = Object.FindObjectOfType <FreeHScene>();

            if (freeHScene == null)
            {
                return;
            }
            var member = Traverse.Create(freeHScene).Field <FreeHScene.Member>("member")?.Value;

            if (member == null)
            {
                return;
            }

            Action <string> GetUpdateUIField(string fieldName)
            {
                void Callback(string value)
                {
                    if (string.IsNullOrEmpty(value) || freeHScene == null)
                    {
                        return;
                    }
                    var field = Traverse.Create(freeHScene).Field <TextMeshProUGUI>(fieldName)?.Value;

                    if (field == null)
                    {
                        return;
                    }
                    field.text = value;
                }

                return(Callback);
            }

            Action <string> GetUpdateTextCallback(string path)
            {
                void Callback(string value)
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        return;
                    }

                    var obj = GameObject.Find(path);

                    if (obj == null)
                    {
                        return;
                    }
                    var uiText = obj.GetComponent <Text>();

                    if (uiText == null)
                    {
                        return;
                    }
                    uiText.text = value;
                }

                return(Callback);
            }

            var callbackMap = DictionaryPool <SaveData.Heroine, List <Action <string> > > .Get();

            try
            {
                if (member.resultHeroine.HasValue && member.resultHeroine.Value != null)
                {
                    if (!callbackMap.TryGetValue(member.resultHeroine.Value, out var callbacks))
                    {
                        callbackMap[member.resultHeroine.Value] =
                            callbacks = GeBoCommon.Utilities.ListPool <Action <string> > .Get();
                    }

                    callbacks.Add(GetUpdateUIField("textFemaleName1"));
                }

                if (member.resultPartner.HasValue && member.resultPartner.Value != null)
                {
                    if (!callbackMap.TryGetValue(member.resultPartner.Value, out var callbacks))
                    {
                        callbackMap[member.resultPartner.Value] =
                            callbacks = GeBoCommon.Utilities.ListPool <Action <string> > .Get();
                    }

                    callbacks.Add(GetUpdateUIField("textFemaleName2"));
                }

                // leaving traverse to work with earlier versions
                var resultDarkHeroine = Traverse.Create(member)
                                        .Field <ReactiveProperty <SaveData.Heroine> >("resultDarkHeroine")?.Value;
                if (resultDarkHeroine != null && resultDarkHeroine.HasValue && resultDarkHeroine.Value != null)
                {
                    if (!callbackMap.TryGetValue(resultDarkHeroine.Value, out var callbacks))
                    {
                        callbackMap[resultDarkHeroine.Value] =
                            callbacks = GeBoCommon.Utilities.ListPool <Action <string> > .Get();
                    }

                    callbacks.Add(
                        // ReSharper disable once StringLiteralTypo
                        GetUpdateTextCallback("/FreeHScene/Canvas/Panel/Dark/FemaleInfomation/Name/TextMeshPro Text"));
                }

                foreach (var entry in callbackMap)
                {
                    foreach (var heroineChaFile in entry.Key.GetRelatedChaFiles())
                    {
                        heroineChaFile.TranslateFullName(
                            translated =>
                        {
                            foreach (var callback in entry.Value)
                            {
                                try
                                {
                                    callback(translated);
                                }
                                catch (Exception err)
                                {
                                    Logger.LogException(err, freeHScene, nameof(FreeHUpdateUI));
                                }
                            }
                        });
                    }
                }
            }
            finally
            {
                foreach (var entry in callbackMap)
                {
                    GeBoCommon.Utilities.ListPool <Action <string> > .Release(entry.Value);
                }
                DictionaryPool <SaveData.Heroine, List <Action <string> > > .Release(callbackMap);
            }
        }
示例#22
0
        public virtual void ValidateNode()
        {
            var isInError = false;

            // all children nodes needs to be updated first
            // so do that here
            var slots = ListPool <MaterialSlot> .Get();

            GetInputSlots(slots);
            foreach (var inputSlot in slots)
            {
                inputSlot.hasError = false;

                var edges = owner.GetEdges(inputSlot.slotReference);
                foreach (var edge in edges)
                {
                    var fromSocketRef = edge.outputSlot;
                    var outputNode    = owner.GetNodeFromGuid(fromSocketRef.nodeGuid);
                    if (outputNode == null)
                    {
                        continue;
                    }

                    outputNode.ValidateNode();
                    if (outputNode.hasError)
                    {
                        isInError = true;
                    }
                }
            }
            ListPool <MaterialSlot> .Release(slots);

            var dynamicInputSlotsToCompare = DictionaryPool <DynamicVectorMaterialSlot, ConcreteSlotValueType> .Get();

            var skippedDynamicSlots = ListPool <DynamicVectorMaterialSlot> .Get();

            var dynamicMatrixInputSlotsToCompare = DictionaryPool <DynamicMatrixMaterialSlot, ConcreteSlotValueType> .Get();

            var skippedDynamicMatrixSlots = ListPool <DynamicMatrixMaterialSlot> .Get();

            // iterate the input slots
            s_TempSlots.Clear();
            GetInputSlots(s_TempSlots);
            foreach (var inputSlot in s_TempSlots)
            {
                // if there is a connection
                var edges = owner.GetEdges(inputSlot.slotReference).ToList();
                if (!edges.Any())
                {
                    if (inputSlot is DynamicVectorMaterialSlot)
                    {
                        skippedDynamicSlots.Add(inputSlot as DynamicVectorMaterialSlot);
                    }
                    if (inputSlot is DynamicMatrixMaterialSlot)
                    {
                        skippedDynamicMatrixSlots.Add(inputSlot as DynamicMatrixMaterialSlot);
                    }
                    continue;
                }

                // get the output details
                var outputSlotRef = edges[0].outputSlot;
                var outputNode    = owner.GetNodeFromGuid(outputSlotRef.nodeGuid);
                if (outputNode == null)
                {
                    continue;
                }

                var outputSlot = outputNode.FindOutputSlot <MaterialSlot>(outputSlotRef.slotId);
                if (outputSlot == null)
                {
                    continue;
                }

                if (outputSlot.hasError)
                {
                    inputSlot.hasError = true;
                    continue;
                }

                var outputConcreteType = outputSlot.concreteValueType;
                // dynamic input... depends on output from other node.
                // we need to compare ALL dynamic inputs to make sure they
                // are compatable.
                if (inputSlot is DynamicVectorMaterialSlot)
                {
                    dynamicInputSlotsToCompare.Add((DynamicVectorMaterialSlot)inputSlot, outputConcreteType);
                    continue;
                }
                else if (inputSlot is DynamicMatrixMaterialSlot)
                {
                    dynamicMatrixInputSlotsToCompare.Add((DynamicMatrixMaterialSlot)inputSlot, outputConcreteType);
                    continue;
                }

                // if we have a standard connection... just check the types work!
                if (!ImplicitConversionExists(outputConcreteType, inputSlot.concreteValueType))
                {
                    inputSlot.hasError = true;
                }
            }

            // we can now figure out the dynamic slotType
            // from here set all the
            var dynamicType = ConvertDynamicInputTypeToConcrete(dynamicInputSlotsToCompare.Values);

            foreach (var dynamicKvP in dynamicInputSlotsToCompare)
            {
                dynamicKvP.Key.SetConcreteType(dynamicType);
            }
            foreach (var skippedSlot in skippedDynamicSlots)
            {
                skippedSlot.SetConcreteType(dynamicType);
            }

            // and now dynamic matrices
            var dynamicMatrixType = ConvertDynamicMatrixInputTypeToConcrete(dynamicMatrixInputSlotsToCompare.Values);

            foreach (var dynamicKvP in dynamicMatrixInputSlotsToCompare)
            {
                dynamicKvP.Key.SetConcreteType(dynamicMatrixType);
            }
            foreach (var skippedSlot in skippedDynamicMatrixSlots)
            {
                skippedSlot.SetConcreteType(dynamicMatrixType);
            }

            s_TempSlots.Clear();
            GetInputSlots(s_TempSlots);
            var inputError = s_TempSlots.Any(x => x.hasError);

            // configure the output slots now
            // their slotType will either be the default output slotType
            // or the above dynanic slotType for dynamic nodes
            // or error if there is an input error
            s_TempSlots.Clear();
            GetOutputSlots(s_TempSlots);
            foreach (var outputSlot in s_TempSlots)
            {
                outputSlot.hasError = false;

                if (inputError)
                {
                    outputSlot.hasError = true;
                    continue;
                }

                if (outputSlot is DynamicVectorMaterialSlot)
                {
                    (outputSlot as DynamicVectorMaterialSlot).SetConcreteType(dynamicType);
                    continue;
                }
                else if (outputSlot is DynamicMatrixMaterialSlot)
                {
                    (outputSlot as DynamicMatrixMaterialSlot).SetConcreteType(dynamicMatrixType);
                    continue;
                }
            }

            isInError |= inputError;
            s_TempSlots.Clear();
            GetOutputSlots(s_TempSlots);
            isInError |= s_TempSlots.Any(x => x.hasError);
            isInError |= CalculateNodeHasError();
            hasError   = isInError;

            if (!hasError)
            {
                ++version;
            }

            ListPool <DynamicVectorMaterialSlot> .Release(skippedDynamicSlots);

            DictionaryPool <DynamicVectorMaterialSlot, ConcreteSlotValueType> .Release(dynamicInputSlotsToCompare);

            ListPool <DynamicMatrixMaterialSlot> .Release(skippedDynamicMatrixSlots);

            DictionaryPool <DynamicMatrixMaterialSlot, ConcreteSlotValueType> .Release(dynamicMatrixInputSlotsToCompare);
        }
示例#23
0
        private void HandleDirectionYou(Direction moveDirection, Vector2Int negativeEndPosition, Vector2Int positiveEndPosition, Stack <Command> tickCommands)
        {
            var displacement = DirectionUtils.DirectionToDisplacement(moveDirection);

            var impactBlocks = DictionaryPool <Block, int> .Get();

            for (var position = negativeEndPosition + displacement; position != positiveEndPosition; position += displacement)
            {
                var hasYou = false;
                {
                    var blocks = m_logicGameManager.Map[position.x, position.y];
                    foreach (var block in blocks)
                    {
                        if (HasAttribute(block, AttributeCategory.You))
                        {
                            impactBlocks[block] = impactBlocks.GetOrDefault(block, 0) | 1;
                            hasYou = true;
                        }
                    }
                }
                if (hasYou)
                {
                    for (var pullPosition = position - displacement; m_logicGameManager.InMap(pullPosition); pullPosition -= displacement)
                    {
                        var blocks  = m_logicGameManager.Map[pullPosition.x, pullPosition.y];
                        var hasPull = false;
                        foreach (var block in blocks)
                        {
                            if (HasAttribute(block, AttributeCategory.Pull))
                            {
                                impactBlocks[block] = impactBlocks.GetOrDefault(block, 0) | 1;
                                hasPull             = true;
                            }
                        }
                        if (!hasPull)
                        {
                            break;
                        }
                    }
                    for (var pushPosition = position + displacement; m_logicGameManager.InMap(pushPosition); pushPosition += displacement)
                    {
                        var blocks  = m_logicGameManager.Map[pushPosition.x, pushPosition.y];
                        var hasPush = false;
                        foreach (var block in blocks)
                        {
                            if (HasAttribute(block, AttributeCategory.Push))
                            {
                                impactBlocks[block] = impactBlocks.GetOrDefault(block, 0) | 1;
                                hasPush             = true;
                            }
                        }
                        if (!hasPush)
                        {
                            break;
                        }
                    }
                }
            }

            HandlePreMove(impactBlocks, displacement, tickCommands);

            {
                var stopPosition = positiveEndPosition - displacement;
                {
                    var blocks = m_logicGameManager.Map[stopPosition.x, stopPosition.y];
                    foreach (var block in blocks)
                    {
                        var impact = 0;
                        if (impactBlocks.TryGetValue(block, out impact))
                        {
                            impactBlocks[block] = 0;
                        }
                    }
                }
            }
            for (var position = positiveEndPosition - displacement; position != negativeEndPosition + displacement; position -= displacement)
            {
                var hasStop = false;
                {
                    var blocks = m_logicGameManager.Map[position.x, position.y];
                    foreach (var block in blocks)
                    {
                        if (HasAttribute(block, AttributeCategory.Stop) || HasAttribute(block, AttributeCategory.Pull) || HasAttribute(block, AttributeCategory.Push))
                        {
                            if (impactBlocks.GetOrDefault(block, 0) == 0)
                            {
                                hasStop = true;
                                break;
                            }
                        }
                    }
                }
                if (hasStop)
                {
                    var stopPosition = position - displacement;
                    {
                        var blocks = m_logicGameManager.Map[stopPosition.x, stopPosition.y];
                        foreach (var block in blocks)
                        {
                            var impact = 0;
                            if (impactBlocks.TryGetValue(block, out impact))
                            {
                                impactBlocks[block] = 0;
                            }
                        }
                    }
                }
            }

            foreach (var impactBlockPair in impactBlocks)
            {
                var block  = impactBlockPair.Key;
                var impact = impactBlockPair.Value;

                if (impact == 1)
                {
                    PerformMoveBlockCommand(block, moveDirection, 1, tickCommands);
                }
            }

            DictionaryPool <Block, int> .Release(impactBlocks);
        }