コード例 #1
0
        /// <summary>
        /// This constructor is used when creating a new world from scratch.
        /// </summary>
        /// <param name="minTile"></param>
        /// <param name="maxTile"></param>
        /// <param name="minHeight"></param>
        /// <param name="maxHeight"></param>
        /// <param name="defaultHeight"></param>
        public WorldMap(string worldName, CoordXZ minTile, CoordXZ maxTile, float minHeight, float maxHeight, float defaultHeight)
        {
            this.worldName = worldName;
            this.minTile   = minTile;
            this.maxTile   = maxTile;
            this.minHeight = minHeight;
            this.maxHeight = maxHeight;

            emptyOWP         = new List <IObjectWithProperties>();
            layerAndWorldOWP = new List <IObjectWithProperties>();

            properties = new MapProperties(this);

            layers = new Dictionary <string, MapLayer>();

            InitLayers(defaultHeight);

            // create map sections
            sections = new Dictionary <CoordXZ, MapSection>();
            zones    = new Dictionary <string, MapZone>();

            CoordXZ minSection = new CoordXZ(minTile, sectionSize);
            CoordXZ maxSection = new CoordXZ(maxTile, sectionSize);

            for (int z = minSection.z; z <= maxSection.z; z++)
            {
                for (int x = minSection.x; x <= maxSection.x; x++)
                {
                    CoordXZ sectionCoord = new CoordXZ(x, z, sectionSize);
                    sections[sectionCoord] = new MapSection(this, sectionCoord);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Copy a source buffer into the tile.  The buffer must fit within a single
        /// tile.
        /// </summary>
        /// <param name="destCoordIn"></param>
        /// <param name="src"></param>
        public void CopyIn(CoordXZ destCoordIn, MapBuffer src)
        {
            Debug.Assert(metersPerSample == src.MetersPerSample);

            // convert to tile coordinates for this layer
            CoordXZ destTileCoord = new CoordXZ(destCoordIn, tileSize);

            // compute the offset in world coordinates within the
            CoordXZ worldDestCoord     = new CoordXZ(destCoordIn, WorldMap.oneMeter);
            CoordXZ worldDestTileCoord = new CoordXZ(destTileCoord, WorldMap.oneMeter);
            CoordXZ tileOffset         = worldDestCoord - worldDestTileCoord;

            if (TileExists(destTileCoord))
            {
                // load the tile if necessary
                if (!TileLoaded(destTileCoord))
                {
                    LoadTile(destTileCoord);
                }
            }
            else
            {
                // If the tile doesn't exist, then create it.
                CreateTile(destTileCoord);
            }

            // copy the source image into the tile
            tiles[destTileCoord].Copy(tileOffset.x / metersPerSample, tileOffset.z / metersPerSample, src);
        }
コード例 #3
0
        /// <summary>
        /// This constructor is used when creating a new world from scratch.
        /// </summary>
        /// <param name="minTile"></param>
        /// <param name="maxTile"></param>
        /// <param name="minHeight"></param>
        /// <param name="maxHeight"></param>
        /// <param name="defaultHeight"></param>
        public WorldMap(string worldName, CoordXZ minTile, CoordXZ maxTile, float minHeight, float maxHeight, float defaultHeight)
        {
            this.worldName = worldName;
            this.minTile = minTile;
            this.maxTile = maxTile;
            this.minHeight = minHeight;
            this.maxHeight = maxHeight;

            emptyOWP = new List<IObjectWithProperties>();
            layerAndWorldOWP = new List<IObjectWithProperties>();

            properties = new MapProperties(this);

            layers = new Dictionary<string, MapLayer>();

            InitLayers(defaultHeight);

            // create map sections
            sections = new Dictionary<CoordXZ, MapSection>();
            zones = new Dictionary<string, MapZone>();

            CoordXZ minSection = new CoordXZ(minTile, sectionSize);
            CoordXZ maxSection = new CoordXZ(maxTile, sectionSize);

            for (int z = minSection.z; z <= maxSection.z; z++)
            {
                for (int x = minSection.x; x <= maxSection.x; x++)
                {
                    CoordXZ sectionCoord = new CoordXZ(x, z, sectionSize);
                    sections[sectionCoord] = new MapSection(this, sectionCoord);
                }
            }
        }
コード例 #4
0
        protected void UpdateVisible()
        {
            if (worldMap != null)
            {
                MapLayer heightFieldLayer = worldMap.HeightFieldLayer;

                for (int z = minVisibleTile.z; z <= maxVisibleTile.z; z++)
                {
                    for (int x = minVisibleTile.x; x < maxVisibleTile.x; x++)
                    {
                        CoordXZ tileCoord = new CoordXZ(x, z, WorldMap.tileSize);
                        MapTile tile      = worldMap.GetTile(tileCoord);
                        if (tile != null)
                        {
                            ImageGridCell cell = imageGrid.GetCell(x - gridOffset.x, z - gridOffset.z);
                            if (cell == null)
                            {
                                cell = imageGrid.CreateCell(x - gridOffset.x, z - gridOffset.z);
                            }

                            if (cell.Image == null)
                            {
                                cell.Image = currentViewLayer.CreateThumbnail(tileCoord, worldMap.TileSize, imageGrid.CellSize);
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
 public void LoadTile(CoordXZ tileCoord)
 {
     if (!TileLoaded(tileCoord))
     {
         tiles[tileCoord] = LoadTileImpl(tileCoord);
     }
 }
コード例 #6
0
        /// <summary>
        /// Create a new tile and fill it with the default value for the layer
        /// </summary>
        /// <param name="tileCoord"></param>
        /// <returns></returns>
        protected override MapBuffer CreateTileImpl(CoordXZ tileCoord)
        {
            MapBuffer16 buffer = new MapBuffer16(map, samplesPerTile, metersPerSample);

            buffer.Fill(defaultRawValue);

            return(buffer);
        }
コード例 #7
0
        /// <summary>
        /// Create a new tile and fill it with the default value for the layer
        /// </summary>
        /// <param name="tileCoord"></param>
        /// <returns></returns>
        protected override MapBuffer CreateTileImpl(CoordXZ tileCoord)
        {
            MapBuffer buffer = new MapBufferARGB(map, samplesPerTile, metersPerSample);

            buffer.Fill((uint)defaultColor.ToARGB());

            return(buffer);
        }
コード例 #8
0
        public MapTile(WorldMap map, CoordXZ tileCoord)
        {
            this.map = map;
            this.tileCoord = tileCoord;
            zone = null;
            this.dirty = false;

            properties = new MapProperties(this);
        }    
コード例 #9
0
        public MapTile(WorldMap map, CoordXZ tileCoord)
        {
            this.map       = map;
            this.tileCoord = tileCoord;
            zone           = null;
            this.dirty     = false;

            properties = new MapProperties(this);
        }
コード例 #10
0
        public MapTile GetTile(CoordXZ tileCoord)
        {
            // compute coordinates of tile within the section
            CoordXZ localTileCoord = tileCoord - this.tileCoord;

            MapTile tile = tiles[localTileCoord.x, localTileCoord.z];

            return(tile);
        }
コード例 #11
0
        public MapSection GetSection(CoordXZ tileCoord)
        {
            CoordXZ sectionCoord = new CoordXZ(tileCoord, sectionSize);

            if (!sections.ContainsKey(sectionCoord))
            {
                sections[sectionCoord] = new MapSection(this, sectionCoord, worldPath);
            }
            return(sections[sectionCoord]);
        }
コード例 #12
0
        /// <summary>
        /// This constructor is used when creating a new map.  All tiles are null, since
        /// this is a blank world.
        /// </summary>
        /// <param name="map">the map</param>
        /// <param name="sectionCoord">the section coordinate of this object</param>
        public MapSection(WorldMap map, CoordXZ sectionCoord)
        {
            this.sectionCoord = sectionCoord;
            this.map = map;

            tileCoord = new CoordXZ(sectionCoord, map.TileSize);
            dirty = true;
            dirtyChildren = false;

            tiles = new MapTile[map.TilesPerSection, map.TilesPerSection];
        }
コード例 #13
0
        /// <summary>
        /// This constructor is used when creating a new map.  All tiles are null, since
        /// this is a blank world.
        /// </summary>
        /// <param name="map">the map</param>
        /// <param name="sectionCoord">the section coordinate of this object</param>
        public MapSection(WorldMap map, CoordXZ sectionCoord)
        {
            this.sectionCoord = sectionCoord;
            this.map          = map;

            tileCoord     = new CoordXZ(sectionCoord, map.TileSize);
            dirty         = true;
            dirtyChildren = false;

            tiles = new MapTile[map.TilesPerSection, map.TilesPerSection];
        }
コード例 #14
0
        public MapTile CreateTile(CoordXZ tileCoord)
        {
            MapTile tile = new MapTile(this, tileCoord);

            MapSection section = GetSection(tileCoord);

            section.AddTile(tile);

            OnNewTile(tile);

            return(tile);
        }
コード例 #15
0
        public void Flush()
        {
            foreach (KeyValuePair <CoordXZ, MapBuffer> kvp in tiles)
            {
                CoordXZ   tileCoord = kvp.Key;
                MapBuffer buffer    = kvp.Value;

                if ((buffer != null) && buffer.Dirty)
                {
                    buffer.Save(TilePath(tileCoord));
                }
            }
        }
コード例 #16
0
        public bool TileExists(CoordXZ tileCoord)
        {
            if (tiles.ContainsKey(tileCoord))
            {
                return(tiles[tileCoord] != null);
            }
            else if (System.IO.File.Exists(TilePath(tileCoord)))
            {
                return(true);
            }

            return(false);
        }
コード例 #17
0
        /// <summary>
        /// Compute the tile coordinate and sample offset within the tile of a given coordinate
        /// </summary>
        /// <param name="coordIn">The input coordinate</param>
        /// <param name="tileCoord">The tile coordinate</param>
        /// <param name="sampleOffset">Sample offset within the tile</param>
        /// <returns>Whether the input coordinate exactly hits a sample</returns>
        protected bool CoordToTileOffset(CoordXZ coordIn, out CoordXZ tileCoord, out CoordXZ sampleOffset)
        {
            int sampleSize = metersPerSample * map.OneMeter;

            tileCoord = new CoordXZ(coordIn, tileSize);
            CoordXZ sampleCoord     = new CoordXZ(coordIn, sampleSize);
            CoordXZ tileSampleCoord = new CoordXZ(tileCoord, sampleSize);

            sampleOffset = sampleCoord - tileSampleCoord;

            CoordXZ worldIn     = new CoordXZ(coordIn, 1);
            CoordXZ worldSample = new CoordXZ(sampleCoord, 1);

            return(worldIn == worldSample);
        }
コード例 #18
0
        private void newMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (NewMapDialog dlg = new NewMapDialog())
            {
                DialogResult result;

                result = dlg.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                int tw = (dlg.MapWidth + WorldMap.tileSize - 1) / WorldMap.tileSize;
                int th = (dlg.MapHeight + WorldMap.tileSize - 1) / WorldMap.tileSize;

                imageGrid.WidthCells  = tw;
                imageGrid.HeightCells = th;
                imageGrid.Enabled     = true;

                int tx, tz;

                if ((tw <= WorldMap.tilesPerSection) && (th <= WorldMap.tilesPerSection))
                {
                    // if the world fits in a single section, then center it in section 0,0
                    tx = (WorldMap.tilesPerSection - tw) / 2;
                    tz = (WorldMap.tilesPerSection - th) / 2;
                }
                else
                {
                    // if the world doesn't fit in a single section, then center on the origin
                    tx = -tw / 2;
                    tz = -th / 2;
                }

                CoordXZ minTile = new CoordXZ(tx, tz, WorldMap.tileSize);
                CoordXZ maxTile = new CoordXZ(tx + tw - 1, tz + th - 1, WorldMap.tileSize);

                worldMap = new WorldMap(dlg.MapName, minTile, maxTile, dlg.MinTerrainHeight, dlg.MaxTerrainHeight, dlg.DefaultTerrainHeight);

                currentViewLayer = worldMap.GetLayer("heightfield");

                gridOffset = minTile;

                InitTreeView();
            }
        }
コード例 #19
0
        public void UnloadTile(CoordXZ tileCoord)
        {
            if (TileLoaded(tileCoord))
            {
                MapBuffer buffer = tiles[tileCoord];

                if (buffer != null)
                {
                    if (buffer.Dirty)
                    {
                        buffer.Save(TilePath(tileCoord));
                    }
                }

                tiles.Remove(tileCoord);
            }
        }
コード例 #20
0
        /// <summary>
        /// Add a new tile to the section
        /// </summary>
        /// <param name="tile"></param>
        public void AddTile(MapTile tile)
        {
            // compute coordinates of tile within the section
            CoordXZ localTileCoord = tile.TileCoord - tileCoord;

            if (tiles[localTileCoord.x, localTileCoord.z] == null)
            {
                tiles[localTileCoord.x, localTileCoord.z] = tile;
            }
            else
            {
                throw new ArgumentException("AddTile: tile already exists at given coordinate");
            }

            if (tile.Dirty)
            {
                dirtyChildren = true;
            }
        }
コード例 #21
0
        /// <summary>
        /// Create a thumbnail bitmap of the map area
        /// </summary>
        /// <param name="coord"></param>
        /// <param name="worldSize"></param>
        /// <param name="pixelSize"></param>
        /// <returns></returns>
        public System.Drawing.Bitmap CreateThumbnail(CoordXZ coord, int worldSize, int pixelSize)
        {
            int numSamples = worldSize / (metersPerSample * map.OneMeter);

            Debug.Assert(WorldMap.IsPowerOf2(numSamples));
            Debug.Assert(WorldMap.IsPowerOf2(pixelSize));

            CoordXZ tileCoord;
            CoordXZ sampleOffset;

            bool exact = CoordToTileOffset(coord, out tileCoord, out sampleOffset);

            // make sure that coordinate is an exact sample
            Debug.Assert(exact);

            if (!TileLoaded(tileCoord))
            {
                LoadTile(tileCoord);
            }

            MapBuffer tile = tiles[tileCoord];

            return(tile.CreateThumbnail(sampleOffset.x, sampleOffset.z, worldSize / (metersPerSample * map.OneMeter), pixelSize));
        }
コード例 #22
0
        public void LoadMap()
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Title            = "Load Map";
                dlg.DefaultExt       = "mwm";
                dlg.Filter           = "Multiverse World Map files (*.mwm)|*.mwm|All files (*.*)|*.*";
                dlg.RestoreDirectory = true;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    worldMap = new WorldMap(dlg.FileName);

                    currentViewLayer = worldMap.GetLayer("heightfield");

                    gridOffset = worldMap.MinTile;

                    imageGrid.WidthCells  = worldMap.MaxTile.x - worldMap.MinTile.x + 1;
                    imageGrid.HeightCells = worldMap.MaxTile.z - worldMap.MinTile.z + 1;
                    imageGrid.Enabled     = true;

                    InitTreeView();
                }
            }
        }
コード例 #23
0
        /// <summary>
        /// Create a new tile and fill it with the default value for the layer
        /// </summary>
        /// <param name="tileCoord"></param>
        /// <returns></returns>
        protected override MapBuffer CreateTileImpl(CoordXZ tileCoord)
        {
            MapBuffer16 buffer = new MapBuffer16(map, samplesPerTile, metersPerSample);

            buffer.Fill(defaultRawValue);

            return buffer;
        }
コード例 #24
0
        protected void loadLayerHandler(object sender, EventArgs args)
        {
            ToolStripButton button = sender as ToolStripButton;

            MapZone zone = button.Tag as MapZone;

            using (LoadLayerDialog dlg = new LoadLayerDialog())
            {
                DialogResult result;

                dlg.LayerNames = worldMap.LayerNames;

                result = dlg.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                int tilesWidth       = zone.MaxTileCoord.x - zone.MinTileCoord.x + 1;
                int tilesHeight      = zone.MaxTileCoord.z - zone.MinTileCoord.z + 1;
                int zoneWidthMeters  = tilesWidth * worldMap.TileSize / worldMap.OneMeter;
                int zoneHeightMeters = tilesHeight * worldMap.TileSize / worldMap.OneMeter;

                int metersPerPixel = zoneWidthMeters / dlg.LayerMapImage.Width;
                Debug.Assert(metersPerPixel == (zoneHeightMeters / dlg.LayerMapImage.Height));


                int samplesPerTile = WorldMap.metersPerTile / metersPerPixel;

                MapLayer layer = worldMap.GetLayer(dlg.LayerName);

                for (int z = 0; z < tilesHeight; z++)
                {
                    int dz = z + zone.MinTileCoord.z;
                    for (int x = 0; x < tilesWidth; x++)
                    {
                        int dx = x + zone.MinTileCoord.x;

                        CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize);

                        MapBuffer tileMap;

                        if (layer is ColorMapLayer)
                        {
                            ColorMapLayer tmpLayer = layer as ColorMapLayer;

                            tileMap = tmpLayer.CreateCompatibleMapBuffer(dlg.LayerMapImage, metersPerPixel,
                                                                         x * samplesPerTile, z * samplesPerTile, samplesPerTile);
                        }
                        else
                        {
                            ValueMapLayer tmpLayer = layer as ValueMapLayer;
                            tileMap = null;
                        }

                        MapTile tile = worldMap.GetTile(tileCoord);

                        if (tileMap.MetersPerSample != layer.MetersPerSample)
                        {
                            tileMap = tileMap.Scale(worldMap.MetersPerTile / layer.MetersPerSample);
                        }

                        layer.CopyIn(tileCoord, tileMap);
                    }
                }
            }
        }
コード例 #25
0
 public string TilePath(CoordXZ tileCoord)
 {
     return(string.Format("{0}/{1}-{2}({3},{4}).png", map.WorldPath, map.WorldName, layerName, tileCoord.x, tileCoord.z));
 }
コード例 #26
0
        protected void loadLayerHandler(object sender, EventArgs args)
        {
            ToolStripButton button = sender as ToolStripButton;

            MapZone zone = button.Tag as MapZone;

            using (LoadLayerDialog dlg = new LoadLayerDialog())
            {
                DialogResult result;

                dlg.LayerNames = worldMap.LayerNames;

                result = dlg.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                int tilesWidth = zone.MaxTileCoord.x - zone.MinTileCoord.x + 1;
                int tilesHeight = zone.MaxTileCoord.z - zone.MinTileCoord.z + 1;
                int zoneWidthMeters = tilesWidth * worldMap.TileSize / worldMap.OneMeter;
                int zoneHeightMeters = tilesHeight * worldMap.TileSize / worldMap.OneMeter;

                int metersPerPixel = zoneWidthMeters / dlg.LayerMapImage.Width;
                Debug.Assert(metersPerPixel == (zoneHeightMeters / dlg.LayerMapImage.Height));

                int samplesPerTile = WorldMap.metersPerTile / metersPerPixel;

                MapLayer layer = worldMap.GetLayer(dlg.LayerName);

                for (int z = 0; z < tilesHeight; z++)
                {
                    int dz = z + zone.MinTileCoord.z;
                    for (int x = 0; x < tilesWidth; x++)
                    {
                        int dx = x + zone.MinTileCoord.x;

                        CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize);

                        MapBuffer tileMap;

                        if (layer is ColorMapLayer)
                        {
                            ColorMapLayer tmpLayer = layer as ColorMapLayer;

                            tileMap = tmpLayer.CreateCompatibleMapBuffer(dlg.LayerMapImage, metersPerPixel,
                                x * samplesPerTile, z * samplesPerTile, samplesPerTile);
                        }
                        else
                        {
                            ValueMapLayer tmpLayer = layer as ValueMapLayer;
                            tileMap = null;
                        }

                        MapTile tile = worldMap.GetTile(tileCoord);

                        if (tileMap.MetersPerSample != layer.MetersPerSample)
                        {
                            tileMap = tileMap.Scale(worldMap.MetersPerTile / layer.MetersPerSample);
                        }

                        layer.CopyIn(tileCoord, tileMap);
                    }
                }

            }
        }
コード例 #27
0
        private void newMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (NewMapDialog dlg = new NewMapDialog())
            {
                DialogResult result;

                result = dlg.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                int tw = (dlg.MapWidth + WorldMap.tileSize - 1) / WorldMap.tileSize;
                int th = (dlg.MapHeight + WorldMap.tileSize - 1) / WorldMap.tileSize;

                imageGrid.WidthCells = tw;
                imageGrid.HeightCells = th;
                imageGrid.Enabled = true;

                int tx, tz;

                if ((tw <= WorldMap.tilesPerSection) && (th <= WorldMap.tilesPerSection))
                {
                    // if the world fits in a single section, then center it in section 0,0
                    tx = (WorldMap.tilesPerSection - tw) / 2;
                    tz = (WorldMap.tilesPerSection - th) / 2;
                }
                else
                {
                    // if the world doesn't fit in a single section, then center on the origin
                    tx = -tw / 2;
                    tz = -th / 2;
                }

                CoordXZ minTile = new CoordXZ(tx, tz, WorldMap.tileSize);
                CoordXZ maxTile = new CoordXZ(tx + tw - 1, tz + th - 1, WorldMap.tileSize);

                worldMap = new WorldMap(dlg.MapName, minTile, maxTile, dlg.MinTerrainHeight, dlg.MaxTerrainHeight, dlg.DefaultTerrainHeight);

                currentViewLayer = worldMap.GetLayer("heightfield");

                gridOffset = minTile;

                InitTreeView();
            }
        }
コード例 #28
0
        public MapTile GetTile(CoordXZ tileCoord)
        {
            MapSection section = GetSection(tileCoord);

            return(section.GetTile(tileCoord));
        }
コード例 #29
0
        public MapTile GetTile(CoordXZ tileCoord)
        {
            // compute coordinates of tile within the section
            CoordXZ localTileCoord = tileCoord - this.tileCoord;

            MapTile tile = tiles[localTileCoord.x, localTileCoord.z];

            return tile;
        }
コード例 #30
0
        public MapSection GetSection(CoordXZ tileCoord)
        {
            CoordXZ sectionCoord = new CoordXZ(tileCoord, sectionSize);

            if (!sections.ContainsKey(sectionCoord))
            {
                sections[sectionCoord] = new MapSection(this, sectionCoord, worldPath);
            }
            return sections[sectionCoord];
        }
コード例 #31
0
 public MapSection(WorldMap map, CoordXZ sectionCoord, string worldPath)
     : this(map, sectionCoord)
 {
     FromXml(worldPath);
 }
コード例 #32
0
 /// <summary>
 /// Convert the given coordinates to tile coordinates appropriate for this layer
 /// </summary>
 /// <param name="coordIn"></param>
 /// <returns></returns>
 public CoordXZ ToLayerTileCoords(CoordXZ coordIn)
 {
     return(new CoordXZ(coordIn, tileSize));
 }
コード例 #33
0
 protected override MapBuffer LoadTileImpl(CoordXZ tileCoord)
 {
     return(new MapBufferARGB(map, TilePath(tileCoord)));
 }
コード例 #34
0
        /// <summary>
        /// Create a thumbnail bitmap of the map area 
        /// </summary>
        /// <param name="coord"></param>
        /// <param name="worldSize"></param>
        /// <param name="pixelSize"></param>
        /// <returns></returns>
        public System.Drawing.Bitmap CreateThumbnail(CoordXZ coord, int worldSize, int pixelSize)
        {
            int numSamples = worldSize / (metersPerSample * map.OneMeter);

            Debug.Assert(WorldMap.IsPowerOf2(numSamples));
            Debug.Assert(WorldMap.IsPowerOf2(pixelSize));

            CoordXZ tileCoord;
            CoordXZ sampleOffset;

            bool exact = CoordToTileOffset(coord, out tileCoord, out sampleOffset);

            // make sure that coordinate is an exact sample
            Debug.Assert(exact);

            if (!TileLoaded(tileCoord))
            {
                LoadTile(tileCoord);
            }

            MapBuffer tile = tiles[tileCoord];
            return tile.CreateThumbnail(sampleOffset.x, sampleOffset.z, worldSize / (metersPerSample * map.OneMeter), pixelSize);
        }
コード例 #35
0
        /// <summary>
        /// Copy a source buffer into the tile.  The buffer must fit within a single
        /// tile.  
        /// </summary>
        /// <param name="destCoordIn"></param>
        /// <param name="src"></param>
        public void CopyIn(CoordXZ destCoordIn, MapBuffer src)
        {
            Debug.Assert(metersPerSample == src.MetersPerSample);

            // convert to tile coordinates for this layer
            CoordXZ destTileCoord = new CoordXZ(destCoordIn, tileSize);

            // compute the offset in world coordinates within the
            CoordXZ worldDestCoord = new CoordXZ(destCoordIn, WorldMap.oneMeter);
            CoordXZ worldDestTileCoord = new CoordXZ(destTileCoord, WorldMap.oneMeter);
            CoordXZ tileOffset = worldDestCoord - worldDestTileCoord;

            if (TileExists(destTileCoord))
            {
                // load the tile if necessary
                if (!TileLoaded(destTileCoord))
                {
                    LoadTile(destTileCoord);
                }
            }
            else
            {
                // If the tile doesn't exist, then create it.
                CreateTile(destTileCoord);
            }

            // copy the source image into the tile
            tiles[destTileCoord].Copy(tileOffset.x / metersPerSample, tileOffset.z / metersPerSample, src);
        }
コード例 #36
0
        /// <summary>
        /// Create a new tile and fill it with the default value for the layer
        /// </summary>
        /// <param name="tileCoord"></param>
        /// <returns></returns>
        protected override MapBuffer CreateTileImpl(CoordXZ tileCoord)
        {
            MapBuffer buffer = new MapBufferARGB(map, samplesPerTile, metersPerSample);

            buffer.Fill((uint)defaultColor.ToARGB());

            return buffer;
        }
コード例 #37
0
 protected override MapBuffer LoadTileImpl(CoordXZ tileCoord)
 {
     return new MapBuffer16(map, TilePath(tileCoord));
 }
コード例 #38
0
        public MapTile GetTile(CoordXZ tileCoord)
        {
            MapSection section = GetSection(tileCoord);

            return section.GetTile(tileCoord);
        }
コード例 #39
0
 protected void CreateTile(CoordXZ tileCoord)
 {
     tiles[tileCoord] = CreateTileImpl(tileCoord);
 }
コード例 #40
0
 protected abstract MapBuffer CreateTileImpl(CoordXZ tileCoord);
コード例 #41
0
 protected abstract MapBuffer LoadTileImpl(CoordXZ tileCoord);
コード例 #42
0
        /// <summary>
        /// Compute the tile coordinate and sample offset within the tile of a given coordinate
        /// </summary>
        /// <param name="coordIn">The input coordinate</param>
        /// <param name="tileCoord">The tile coordinate</param>
        /// <param name="sampleOffset">Sample offset within the tile</param>
        /// <returns>Whether the input coordinate exactly hits a sample</returns>
        protected bool CoordToTileOffset(CoordXZ coordIn, out CoordXZ tileCoord, out CoordXZ sampleOffset)
        {
            int sampleSize = metersPerSample * map.OneMeter;

            tileCoord = new CoordXZ(coordIn, tileSize);
            CoordXZ sampleCoord = new CoordXZ(coordIn, sampleSize);
            CoordXZ tileSampleCoord = new CoordXZ(tileCoord, sampleSize);

            sampleOffset = sampleCoord - tileSampleCoord;

            CoordXZ worldIn = new CoordXZ(coordIn, 1);
            CoordXZ worldSample = new CoordXZ(sampleCoord, 1);

            return (worldIn == worldSample);
        }
コード例 #43
0
        public void LoadMap()
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Title = "Load Map";
                dlg.DefaultExt = "mwm";
                dlg.Filter = "Multiverse World Map files (*.mwm)|*.mwm|All files (*.*)|*.*";
                dlg.RestoreDirectory = true;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    worldMap = new WorldMap(dlg.FileName);

                    currentViewLayer = worldMap.GetLayer("heightfield");

                    gridOffset = worldMap.MinTile;

                    imageGrid.WidthCells = worldMap.MaxTile.x - worldMap.MinTile.x + 1;
                    imageGrid.HeightCells = worldMap.MaxTile.z - worldMap.MinTile.z + 1;
                    imageGrid.Enabled = true;

                    InitTreeView();
                }
            }
        }
コード例 #44
0
 protected void CreateTile(CoordXZ tileCoord)
 {
     tiles[tileCoord] = CreateTileImpl(tileCoord);
 }
コード例 #45
0
        protected void UpdateVisible()
        {
            if ( worldMap != null ) {
                MapLayer heightFieldLayer = worldMap.HeightFieldLayer;

                for (int z = minVisibleTile.z; z <= maxVisibleTile.z; z++)
                {
                    for (int x = minVisibleTile.x; x < maxVisibleTile.x; x++)
                    {
                        CoordXZ tileCoord = new CoordXZ(x, z, WorldMap.tileSize);
                        MapTile tile = worldMap.GetTile(tileCoord);
                        if (tile != null)
                        {
                            ImageGridCell cell = imageGrid.GetCell(x - gridOffset.x, z - gridOffset.z);
                            if (cell == null)
                            {
                                cell = imageGrid.CreateCell(x - gridOffset.x, z - gridOffset.z);
                            }

                            if (cell.Image == null)
                            {
                                cell.Image = currentViewLayer.CreateThumbnail(tileCoord, worldMap.TileSize, imageGrid.CellSize);
                            }
                        }
                    }
                }
            }
        }
コード例 #46
0
 protected abstract MapBuffer CreateTileImpl(CoordXZ tileCoord);
コード例 #47
0
        private bool NewZonePlacementCallback(bool cancelled, Point location, object arg)
        {
            NewZoneData zoneData = (NewZoneData)arg;

            if (!cancelled)
            {
                // Check to see if the new zone overlaps any existing tiles
                for (int z = 0; z < zoneData.TilesHeight; z++)
                {
                    int dz = z + gridOffset.z + location.Y;
                    for (int x = 0; x < zoneData.TilesWidth; x++)
                    {
                        int dx = x + gridOffset.x + location.X;

                        CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize);
                        MapTile tile = worldMap.GetTile(tileCoord);
                        if (tile != null)
                        {
                            // overlaps existing tiles
                            return false;
                        }
                    }
                }

                MapZone zone = worldMap.CreateZone(zoneData.ZoneName);

                int samplesPerTile = WorldMap.metersPerTile / zoneData.MetersPerSample;

                ValueMapLayer heightFieldLayer = worldMap.HeightFieldLayer as ValueMapLayer;

                for (int z = 0; z < zoneData.TilesHeight; z++)
                {
                    int dz = z + gridOffset.z + location.Y;
                    for (int x = 0; x < zoneData.TilesWidth; x++)
                    {
                        int dx = x + gridOffset.x + location.X;

                        CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize);

                        MapBuffer tileHeightmap = heightFieldLayer.CreateCompatibleMapBuffer(zoneData.Heightmap, zoneData.MetersPerSample,
                            x * samplesPerTile, z * samplesPerTile, samplesPerTile, zoneData.MinHeight, zoneData.MaxHeight);

                        MapTile tile = worldMap.CreateTile(tileCoord);
                        tile.Zone = zone;

                        if (tileHeightmap.MetersPerSample != heightFieldLayer.MetersPerSample)
                        {
                            tileHeightmap = tileHeightmap.Scale(worldMap.MetersPerTile / heightFieldLayer.MetersPerSample);
                        }

                        heightFieldLayer.CopyIn(tileCoord, tileHeightmap);

                        ImageGridCell cell = imageGrid.CreateCell(x + location.X, z + location.Y);

                        cell.Image = currentViewLayer.CreateThumbnail(tileCoord, worldMap.TileSize, imageGrid.CellSize);
                    }
                }

                AddZone(zone);
            }
            return true;
        }
コード例 #48
0
 protected abstract MapBuffer LoadTileImpl(CoordXZ tileCoord);
コード例 #49
0
 public string TilePath(CoordXZ tileCoord)
 {
     return string.Format("{0}/{1}-{2}({3},{4}).png", map.WorldPath, map.WorldName, layerName, tileCoord.x, tileCoord.z);
 }
コード例 #50
0
 public bool TileLoaded(CoordXZ tileCoord)
 {
     return(tiles.ContainsKey(tileCoord));
 }
コード例 #51
0
        private bool NewZonePlacementCallback(bool cancelled, Point location, object arg)
        {
            NewZoneData zoneData = (NewZoneData)arg;

            if (!cancelled)
            {
                // Check to see if the new zone overlaps any existing tiles
                for (int z = 0; z < zoneData.TilesHeight; z++)
                {
                    int dz = z + gridOffset.z + location.Y;
                    for (int x = 0; x < zoneData.TilesWidth; x++)
                    {
                        int dx = x + gridOffset.x + location.X;

                        CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize);
                        MapTile tile      = worldMap.GetTile(tileCoord);
                        if (tile != null)
                        {
                            // overlaps existing tiles
                            return(false);
                        }
                    }
                }

                MapZone zone = worldMap.CreateZone(zoneData.ZoneName);

                int samplesPerTile = WorldMap.metersPerTile / zoneData.MetersPerSample;

                ValueMapLayer heightFieldLayer = worldMap.HeightFieldLayer as ValueMapLayer;

                for (int z = 0; z < zoneData.TilesHeight; z++)
                {
                    int dz = z + gridOffset.z + location.Y;
                    for (int x = 0; x < zoneData.TilesWidth; x++)
                    {
                        int dx = x + gridOffset.x + location.X;

                        CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize);

                        MapBuffer tileHeightmap = heightFieldLayer.CreateCompatibleMapBuffer(zoneData.Heightmap, zoneData.MetersPerSample,
                                                                                             x * samplesPerTile, z * samplesPerTile, samplesPerTile, zoneData.MinHeight, zoneData.MaxHeight);

                        MapTile tile = worldMap.CreateTile(tileCoord);
                        tile.Zone = zone;

                        if (tileHeightmap.MetersPerSample != heightFieldLayer.MetersPerSample)
                        {
                            tileHeightmap = tileHeightmap.Scale(worldMap.MetersPerTile / heightFieldLayer.MetersPerSample);
                        }

                        heightFieldLayer.CopyIn(tileCoord, tileHeightmap);

                        ImageGridCell cell = imageGrid.CreateCell(x + location.X, z + location.Y);

                        cell.Image = currentViewLayer.CreateThumbnail(tileCoord, worldMap.TileSize, imageGrid.CellSize);
                    }
                }

                AddZone(zone);
            }
            return(true);
        }
コード例 #52
0
 /// <summary>
 /// Convert the given coordinates to tile coordinates appropriate for this layer
 /// </summary>
 /// <param name="coordIn"></param>
 /// <returns></returns>
 public CoordXZ ToLayerTileCoords(CoordXZ coordIn)
 {
     return new CoordXZ(coordIn, tileSize);
 }
コード例 #53
0
 public void LoadTile(CoordXZ tileCoord)
 {
     if (!TileLoaded(tileCoord))
     {
         tiles[tileCoord] = LoadTileImpl(tileCoord);
     }
 }
コード例 #54
0
        public void UnloadTile(CoordXZ tileCoord)
        {
            if (TileLoaded(tileCoord))
            {
                MapBuffer buffer = tiles[tileCoord];

                if (buffer != null)
                {
                    if (buffer.Dirty)
                    {
                        buffer.Save(TilePath(tileCoord));
                    }
                }

                tiles.Remove(tileCoord);
            }
        }
コード例 #55
0
        public bool TileExists(CoordXZ tileCoord)
        {
            if (tiles.ContainsKey(tileCoord))
            {
                return ( tiles[tileCoord] != null );
            }
            else if (System.IO.File.Exists(TilePath(tileCoord)))
            {
                return true;
            }

            return false;
        }
コード例 #56
0
 public bool TileLoaded(CoordXZ tileCoord)
 {
     return tiles.ContainsKey(tileCoord);
 }
コード例 #57
0
 public MapSection(WorldMap map, CoordXZ sectionCoord, string worldPath)
     : this(map, sectionCoord)
 {
     FromXml(worldPath);
 }
コード例 #58
0
        public MapTile CreateTile(CoordXZ tileCoord)
        {
            MapTile tile = new MapTile(this, tileCoord);

            MapSection section = GetSection(tileCoord);

            section.AddTile(tile);

            OnNewTile(tile);

            return tile;
        }