public void Map(MappingFunction mappingFunction)
 {
     for (int i = 0; i < _words.Length; i++)
     {
         _words[i] = mappingFunction(_words[i]);
     }
 }
Esempio n. 2
0
        public override object AssignValuesFromObject(object other)
        {
            if (!mappings.ContainsKey(other.GetType()))
            {
                mappings.Add(other.GetType(), (MappingFunction) delegate(object other2)
                {
                    return(this.MapByName(other2));
                });
            }

            if (CanBeAssignedFromType(other.GetType()))
            {
                return(MapByName(other));
            }
            else /* if valid mapping is declared */
            {
                // perform mapping as declared in the mapping function
            }

            MappingFunction map = mappings[other.GetType()] as MappingFunction;

            map(other);

            return(new Dictionary <string, object>());
        }
Esempio n. 3
0
 //TODO : make a physics thread and put this on it
 public FluidSimulation(MappingFunction mappingFunction, Block[] blocks)
 {
     m_mappingFunction = mappingFunction;
     m_blocks = blocks;
     m_containers = new List<FluidContainer>();
     m_solidCell = new FluidCell(FluidCell.CellType.Solid);
     m_addQueue = new Queue<List<FluidCell>>();
     m_cellAccumulator = new List<FluidCell>();
 }
Esempio n. 4
0
 public FluidContainer(MappingFunction mappingFunction, Block[] blocks, FluidCell solidCellReference)
 {
     m_mappingFunction = mappingFunction;
     m_blocks = blocks;
     m_solidCellReference = solidCellReference;
     Update = true;
     Alive = true;
     m_min = new Vector3Int(int.MaxValue, int.MaxValue, int.MaxValue);
     m_max = new Vector3Int(-int.MaxValue, -int.MaxValue, -int.MaxValue);
     Cells = new List<FluidCell>();
     CellDictionary = new Dictionary<long, FluidCell>();
     Updated = new List<FluidCell>();
 }
Esempio n. 5
0
        /// <summary>
        /// Apply a SyntaxElement.MappingFunction to the syntax tree.
        /// </summary>
        /// <param name="mappingFunction">An aribtrary mapping function to be applied to the syntax tree.</param>
        /// <returns>A new object of the enclosing type with the mapping function applied.</returns>
        public override SyntaxElement ApplyMappingFunction(MappingFunction mappingFunction)
        {
            return(new ResourceAccessFact(
                       (PrincipalIdentifier)mappingFunction(this.Resource),
                       (PrincipalIdentifier)mappingFunction(this.Module),
                       (PrincipalIdentifier)mappingFunction(this.Group),

                       (IntegerIdentifier)mappingFunction(this.From),
                       (IntegerIdentifier)mappingFunction(this.To),
                       (IntegerIdentifier)mappingFunction(this.DayOfWeek),

                       (VerbIdentifier)mappingFunction(this.AccessMode),
                       (IntegerIdentifier)mappingFunction(this.Priority)));
        }
Esempio n. 6
0
	    public void LoadOrCreateChunk(Vector3Int position, Block[] blocks, MappingFunction mappingFunction)
        {
            var pagePositionX = position.X / Page.PageSizeInBlocks;
            var pagePositionY = position.Y / Page.PageSizeInBlocks;
            var pagePositionZ = position.Z / Page.PageSizeInBlocks;
            var pageId = CreatePageId(pagePositionX, pagePositionY, pagePositionZ);
            if (m_pageCache.ContainsPage(pageId))
            {
                var page = m_pageCache.GetPage(pageId);
                CopyPageToChunk(page, position, blocks, mappingFunction);
            }
            else if (m_directory.Pages.Contains(pageId))
            {
                var page = DecompressPage(pageId);
                CopyPageToChunk(page, position, blocks, mappingFunction);
                m_pageCache.InsertPage(page);
            }
            else if (!m_pagesPendingWrite.Contains(pageId))
            {
                m_pagesPendingWrite.Add(pageId);
                var page = new Page(position.X, position.Y, position.Z, pageId);
                var worldPosX = pagePositionX * Page.PageSizeInBlocks;
                var worldPosY = pagePositionY * Page.PageSizeInBlocks;
                var worldPosZ = pagePositionZ * Page.PageSizeInBlocks;
                TerrainGenerator.Instance.GenerateDataForChunk(worldPosX, worldPosY, worldPosZ,
                                                               Page.PageSizeInBlocks, page.Data, (x, y, z) => Page.BlockIndexFromRelativePosition(
                                                                   x - worldPosX, y - worldPosY, z - worldPosZ));

                //BlockDataUtilities.SetupScanDirectedHilbertCurve(Page.PageSizeInBlocks);
               // ChunkCompressor.GetHilbertCurve(32);
                var timer = Stopwatch.StartNew();
                float compressionRatio;
                //ChunkCompressor.ScanDirection scanDir;
                var tree = ChunkCompressor.GetCompressor(Page.PageSizeInBlocks).ConvertArrayToIntervalTree(page.Data,
                    out compressionRatio);
                Console.WriteLine("tree creation time: " + timer.ElapsedMilliseconds);
              //  Console.WriteLine("h: " + scanDir);
              //  Console.WriteLine("tree compresion ratio: " + compressionRatio);
              //  timer.Restart();
            //    var tree2 = ChunkCompressor.ConvertArrayToIntervalTreeLinear(page.Data, Page.PageSizeInBlocks,
            //       out compressionRatio, out scanDir);
                //Console.WriteLine("linear tree creation time: " + timer.ElapsedMilliseconds);
               // Console.WriteLine("l: " + scanDir);
              //  Console.WriteLine("l: " + compressionRatio);

               // tree.

                timer.Restart();
                var res = tree[new Interval(17490)];
                Console.WriteLine("tree query time: " + timer.ElapsedMilliseconds);
                using (var fileStream = new FileStream(Path.Combine(m_dataDirectory, page.PageId + "_tree.page"), FileMode.Create))
                {
                    using (var compressor = new GZipStream(fileStream, CompressionLevel.Optimal))
                    {
                        //Serializer.Serialize(compressor, tree);
                    }
                }
                Console.WriteLine("tree compressionTime time: " + timer.ElapsedMilliseconds);

                timer.Restart();
                CompressPage(page);
                Console.WriteLine("normal compressionTime time: " + timer.ElapsedMilliseconds);

                m_pageCache.InsertPage(page);
                m_directory.Pages.Add(pageId);
                CopyPageToChunk(page, position, blocks, mappingFunction);
                //m_jsonWriter.Write("SaveDirectory", m_directory);
              /*  Task.Run(() =>
                {
                    CompressPage(page);
                    m_pagesPendingWrite.Remove(page.PageId);
                });*/
            }
	    }
Esempio n. 7
0
        private static void CopyCunkToPage(Page page, Vector3Int position, Block[] blocks, MappingFunction mappingFunction)
        {
            var originX = MathUtilities.Modulo(position.X, Page.PageSizeInBlocks);
            var originY = MathUtilities.Modulo(position.Y, Page.PageSizeInBlocks);
            var originZ = MathUtilities.Modulo(position.Z, Page.PageSizeInBlocks);
            for (var x = originX; x < originX + Chunk.SizeInBlocks; x++)
            {
                for (var y = originY; y < originY + Chunk.SizeInBlocks; y++)
                {
                    for (var z = originZ; z < originZ + Chunk.SizeInBlocks; z++)
                    {
                        page.Data[Page.BlockIndexFromRelativePosition(x, y, z)] =
                            blocks[mappingFunction(position.X + x, position.Y + y, position.Z + z)];
                    }
                }
            }
	    }
Esempio n. 8
0
	    public void SaveChunk(Vector3Int position, Block[] blocks, MappingFunction mappingFunction, Action<bool> callback)
        {
            var pagePositionX = position.X >> 6;
            var pagePositionY = position.Y >> 6;
            var pagePositionZ = position.Z >> 6;
	        var pageId = CreatePageId(pagePositionX, pagePositionY, pagePositionZ);
	        if (m_pagesPendingWrite.Contains(pageId))
	        {
                if (callback != null)
                {
                    callback(false);
                }
	        }
	        else
	        {
	            Page page;
	            if (m_pageCache.ContainsPage(pageId))
	            {
                    page = m_pageCache.GetPage(pageId);
                    CopyCunkToPage(page, position, blocks, mappingFunction);
	            }
                else if (m_directory.Pages.Contains(pageId))
                {
                    page = DecompressPage(pageId);
                    CopyCunkToPage(page, position, blocks, mappingFunction);
                    m_pageCache.InsertPage(page);
                }
	            else
	            {
                    page = new Page(position.X, position.Y, position.Z, pageId);
                    for (var x = 0; x < Page.PageSizeInBlocks; x++)
                    {
                        for (var y = 0; y < Page.PageSizeInBlocks; y++)
                        {
                            for (var z = 0; z < Page.PageSizeInBlocks; z++)
                            {
                                page.Data[Page.BlockIndexFromRelativePosition(x, y, z)] =
                                    blocks[mappingFunction(position.X + x, position.Y + y, position.Z + z)];
                            }
                        }
                    }
                    m_pageCache.InsertPage(page);
                    m_directory.Pages.Add(pageId);
                   // m_jsonWriter.Write("SaveDirectory", m_directory);
	            }
	            m_pagesPendingWrite.Add(pageId);
	            Task.Run(() =>
	            {
	                CompressPage(page);
	                if (callback != null)
	                {
	                    callback(true);
	                }
	                m_pagesPendingWrite.Remove(page.PageId);
	            });
	        }
	    }
Esempio n. 9
0
        public void GenerateDataForChunk(int chunkX, int chunkY, int chunkZ, int chunkSize, Block[] blocks, MappingFunction mappingFunction)
	    {
           for (var x  = 0; x < chunkSize; ++x) 
		   {
                var cX = chunkX + x;
			    for (var z = 0; z < chunkSize; ++z) 
			    {
                    var cZ = chunkZ + z;
			        var groundLevel = GetHeight(cX, cZ);
					var detailNoise =  m_detail2.FractalBrownianMotion(cX, cZ, 64, 0, 8);
                    var overhangStart = m_sealevel + MathHelper.Clamp(detailNoise * 4, -1, 1) * 2;
                    var biome = m_biomeGenerator.GetRegionGenerator(cX, cZ);
                    var province = m_provinceGenerator.GetRegionGenerator(cX, cZ);

			        var data = m_populator.CalculateNearestSamplePosition(cX, cZ);
			        /*var color = (ushort)data.Id;*/
			        var riverData = m_riverGenerator.GetRiverData(cX, cZ);

                    if (riverData != null)
			        {
			           /* if (groundLevel < riverData.Position.Y)
			            {
			                Console.Out.WriteLine(x + ", " + z + ": " + (riverData.Position.Y - groundLevel));
			            }*/
			            groundLevel = riverData.Position.Y;
			        }

					for (var y = chunkSize - 1; y >= 0 ; --y)
					{
                        var cY = chunkY + y;
                        Block block;

                        if (cY > groundLevel + 10)
					    {
                            block = new Block(Block.None) {LightSun = CellularLighting<Block>.MaxSun};
					    }
					    else if (cY > groundLevel)
					    {
                            block = new Block(Block.None) { LightSun = CellularLighting<Block>.MinLight };
					    }
                        else if (cY >= groundLevel - m_biomeThickness)
					    {
					        if (cY > overhangStart)
					        {
					            var density = (MathHelper.Clamp(m_volume.FractalBrownianMotion(cX, cY, cZ, 64, 0, 4)*3, -1, 1) + 1)*0.5f;
					            block = density > 0.125 ? biome.Apply((int) groundLevel, cX, cY, cZ) : Block.Empty;
					        }
					        else
					        {
					            block = biome.Apply((int) groundLevel, cX, cY, cZ);
					        }
					    }
					    else
					    {
					        block = province.Apply((int)groundLevel - m_biomeThickness, cX, cY, cZ);
					    }
					  //  var tint = (int) ((detailNoise * 5 + 10));
                     //   block.Color = (ushort)((tint << 8) | (tint << 4) | tint);
					    if (riverData != null && cY <= groundLevel && cY >= groundLevel - 1)
					    {
					        block = new Block(BlockDictionary.Instance.GetBlockIdForName("Water"));
					    }

                        blocks[mappingFunction(cX, cY, cZ)] = block;
					}
                    
                    for (var y = 0; y < chunkSize && chunkY + y < m_sealevel; ++y)
					{		
                        var cY = chunkY + y;
					    var blockIndex = mappingFunction(cX, cY, cZ);
					    if (!blocks[blockIndex].Exists)
					        blocks[blockIndex] = new Block(BlockDictionary.Instance.GetBlockIdForName("Water"));
					}


                    //TODO : redesign populator to be compatible with page loading
			       /* if (Math.Abs(data.Delta.X - cX) < 0.01 && Math.Abs(data.Delta.Y - cZ) < 0.01)
			        {
			            m_populator.PopulateTree(cX, cZ, (int)groundLevel, blocks, mappingFunction);
			        }*/
				}
		    }
            //TODO : query if chunk has all neighbors loaded so we can run our erosion step

            //TODO : after eroding generate structures
	    }
Esempio n. 10
0
        public Chunk(Vector3Int chunkCachePosition, Block[] blocks, MappingFunction mappingFunction, GetNeighborChunk getNeighborChunk)
        {
            ChunkState = ChunkState.AwaitingGenerate; // set initial state to awaiting generation.
            ChunkCachePosition = chunkCachePosition; // set the relative position.
            m_blocks = blocks;
            m_mappingFunction = mappingFunction;
            m_getNeighborChunk = getNeighborChunk;

            // calculate the real world position.
            Position = new Vector3Int(ChunkCachePosition.X * SizeInBlocks,
                                           ChunkCachePosition.Y * SizeInBlocks,
                                           ChunkCachePosition.Z * SizeInBlocks);

            // calculate bounding-box.
            BoundingBox = new BoundingBox(new Vector3(Position.X, Position.Y, Position.Z),
                                          new Vector3(Position.X + SizeInBlocks, Position.Y + SizeInBlocks,
                                                      Position.Z + SizeInBlocks));
            #if DEBUG
            MainEngine.GetEngineInstance().DebugOnlyDebugManager.RegisterInGameDebuggable(this);
            #endif
        }
Esempio n. 11
0
 /// <summary>
 /// Apply a SyntaxElement.MappingFunction to the syntax tree.
 /// </summary>
 /// <param name="mappingFunction">An aribtrary mapping function to be applied to the syntax tree.</param>
 /// <returns>A new object of the enclosing type with the mapping function applied.</returns>
 public override SyntaxElement ApplyMappingFunction(MappingFunction mappingFunction)
 {
     return(new UserGroupMembershipFact(
                (PrincipalIdentifier)mappingFunction(this.User),
                (PrincipalIdentifier)mappingFunction(this.Group)));
 }
Esempio n. 12
0
 /// <summary>
 /// Apply a SyntaxElement.MappingFunction to the syntax tree.
 /// </summary>
 /// <param name="mappingFunction">An aribtrary mapping function to be applied to the syntax tree.</param>
 /// <returns>A new object of the enclosing type with the mapping function applied.</returns>
 public override SyntaxElement ApplyMappingFunction(MappingFunction mappingFunction)
 {
     return new UserGroupMembershipFact(
         (PrincipalIdentifier)mappingFunction(this.User),
         (PrincipalIdentifier)mappingFunction(this.Group));
 }
Esempio n. 13
0
        /// <summary>
        /// Apply a SyntaxElement.MappingFunction to the syntax tree.
        /// </summary>
        /// <param name="mappingFunction">An aribtrary mapping function to be applied to the syntax tree.</param>
        /// <returns>A new object of the enclosing type with the mapping function applied.</returns>
        public override SyntaxElement ApplyMappingFunction(MappingFunction mappingFunction)
        {
            return new ResourceAccessFact(
                (PrincipalIdentifier)mappingFunction(this.Resource),
                (PrincipalIdentifier)mappingFunction(this.Module),
                (PrincipalIdentifier)mappingFunction(this.Group),

                (IntegerIdentifier)mappingFunction(this.From),
                (IntegerIdentifier)mappingFunction(this.To),
                (IntegerIdentifier)mappingFunction(this.DayOfWeek),

                (VerbIdentifier)mappingFunction(this.AccessMode),
                (IntegerIdentifier)mappingFunction(this.Priority));
        }