コード例 #1
0
    private IReadOnlyList <object> Visit(Item endItem)
    {
        // For every Item which is the last item of a production, we want to traverse the
        // linked-list of item->item.Previous to get items for all symbols in the production.
        // We get all possible values from each item, and then invoke the production callback
        // for every combination of items in each position. For unambiguous grammars this is
        // O(n). For highly-ambiguous grammars it goes off the rails pretty quick.

        var production = endItem.Production;

        Debug.Assert(endItem.Index == production.Symbols.Count, "This is the end item of this production");

        var key = (production, endItem.ParentState.Number, endItem.CurrentState.Number);

        if (_cache.ContainsKey(key))
        {
            _statistics.DerivationCacheHit++;
            return(_cache[key]);
        }

        var results = GenerateValues(endItem, production);

        _cache.Add(key, results);

        return(results);
    }
コード例 #2
0
 private void AddExpression(Expression expression)
 {
     _addents = _addents.Add(new Addent()
     {
         Multiplier = Rational.One,
         Factors    = new ReadOnlyList <Expression>(expression)
     });
 }
コード例 #3
0
        public Expression ToExpression()
        {
            IReadOnlyList <Addent> addents = Addents;

            if (!Value.IsZero)
            {
                addents = addents.Add(new Addent()
                {
                    Multiplier = Value,
                    Factors    = ReadOnlyList <Expression> .Empty,
                });
            }

            if (addents.Count == 0)
            {
                return(0);
            }
            if (addents.Count == 1)
            {
                return(addents[0].ToExpression());
            }

            IReadOnlyList <Expression> positive = addents.Where(a => !a.IsNegative).Select(a => a.ToExpressionWithoutSign()).ToArray();
            IReadOnlyList <Expression> negative = addents.Where(a => a.IsNegative).Select(a => a.ToExpressionWithoutSign()).ToArray();

            Expression result;

            if (positive.Count > 0)
            {
                if (positive.Count == 1)
                {
                    result = positive[0];
                }
                else
                {
                    result = Operators.Add.Apply(positive);
                }

                result = negative.Aggregate(result, (current, subtract) => current - subtract);
            }
            else
            {
                result = negative.Skip(1).Aggregate(-negative[0], (current, subtract) => current - subtract);
            }

            return(result);
        }
コード例 #4
0
 public override void VisitConstant(Constant constant)
 {
     _factors = _factors.Add(constant);
 }
コード例 #5
0
        public TileSceneRenderData(ITagContainer diContainer, TileScene scene, DeviceBuffer counterBuffer)
        {
            this.diContainer = diContainer;
            this.scene       = scene;
            locationBuffer   = diContainer.GetTag <LocationBuffer>();
            var textureLoader = diContainer.GetTag <IAssetLoader <Texture> >();
            var camera        = diContainer.GetTag <OrthoCamera>();

            var worldLocationRange = locationBuffer.Add(new Location());
            var locationRanges     = new List <DeviceBufferRange>(scene.Objects.Count + 1)
            {
                worldLocationRange
            };

            this.locationRanges = locationRanges;
            worldMaterials      = scene.WorldBuffers.Materials.Select(rwMaterial =>
            {
                IMapMaterial material;
                if (rwMaterial.isTextured)
                {
                    var texMaterial = new MapStandardMaterial(diContainer);
                    (texMaterial.MainTexture.Texture, texMaterial.Sampler.Sampler) = textureLoader.LoadTexture(TextureBasePaths, rwMaterial);
                    material = texMaterial;
                }
                else
                {
                    material = new MapUntexturedMaterial(diContainer);
                }
                material.Projection.BufferRange = camera.ProjectionRange;
                material.View.BufferRange       = camera.ViewRange;
                material.World.Value            = Matrix4x4.Identity;
                material.Uniforms.Ref           = ModelStandardMaterialUniforms.Default;
                material.PixelCounter.Buffer    = counterBuffer;
                AddDisposable(material);
                return(material as IMaterial);
            }).ToList() !;

            objectMaterials = scene.Objects.Select(obj => obj.ClumpBuffers.SubMeshes.Select(subMesh =>
            {
                var objectLocation           = new Location();
                objectLocation.LocalPosition = obj.Position;
                objectLocation.LocalRotation = obj.Rotation;
                var objectLocationRange      = locationBuffer.Add(objectLocation);
                locationRanges.Add(objectLocationRange);

                var rwMaterial = subMesh.Material;
                IMapMaterial material;
                if (rwMaterial.isTextured)
                {
                    var texMaterial = new MapStandardMaterial(diContainer);
                    (texMaterial.MainTexture.Texture, texMaterial.Sampler.Sampler) = textureLoader.LoadTexture(TextureBasePaths, rwMaterial);
                    material = texMaterial;
                }
                else
                {
                    material = new MapUntexturedMaterial(diContainer);
                }
                material.Projection.BufferRange         = camera.ProjectionRange;
                material.View.BufferRange               = camera.ViewRange;
                material.World.BufferRange              = objectLocationRange;
                material.Uniforms.Ref                   = ModelStandardMaterialUniforms.Default;
                material.Uniforms.Ref.vertexColorFactor = 0.0f;
                material.Uniforms.Ref.tint              = rwMaterial.color.ToFColor() * obj.Tint;
                material.PixelCounter.Buffer            = counterBuffer;
                AddDisposable(material);
                return(material as IMaterial);
            }).ToList() as IReadOnlyList <IMaterial>).ToList();
        }