Ejemplo n.º 1
0
        public MapBuffer(WorldMap map, string filename)
        {
            LoadRaw(filename);

            metersPerSample = WorldMap.metersPerTile / numSamples;
            this.map = map;

            dirty = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This constructor builds an empty buffer
        /// </summary>
        /// <param name="size"></param>
        /// <param name="metersPerSample"></param>
        public MapBuffer(WorldMap map, int numSamples, int metersPerSample)
        {
            this.metersPerSample = metersPerSample;
            this.numSamples = numSamples;
            this.map = map;

            InitBuffer();
            dirty = false;
        }
Ejemplo n.º 3
0
        public MapTile(WorldMap map, CoordXZ tileCoord)
        {
            this.map = map;
            this.tileCoord = tileCoord;
            zone = null;
            this.dirty = false;

            properties = new MapProperties(this);
        }    
Ejemplo n.º 4
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];
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Build a buffer from a region of an image, scaling the pixels to the right value range
        /// </summary>
        /// <param name="src"></param>
        /// <param name="metersPerSample"></param>
        /// <param name="sx"></param>
        /// <param name="sz"></param>
        /// <param name="size"></param>
        public MapBuffer(WorldMap map, Image src, int metersPerSample, int sx, int sz, float srcMinHeight, float srcMaxHeight, int size, float destMinHeight, float destMaxHeight)
        {
            Debug.Assert(src.Width >= (sx + size));
            Debug.Assert(src.Height >= (sz + size));
            Debug.Assert(src.BytesPerPixel == BytesPerSample);

            this.metersPerSample = metersPerSample;
            this.numSamples = size;
            this.map = map;

            InitBuffer();

            CopyFromImageRescale(src, sx, sz, srcMinHeight, srcMaxHeight, size, destMinHeight, destMaxHeight);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Build a buffer from a region of an image
        /// </summary>
        /// <param name="src"></param>
        /// <param name="metersPerSample"></param>
        /// <param name="sx"></param>
        /// <param name="sz"></param>
        /// <param name="size"></param>
        public MapBuffer(WorldMap map, Image src, int metersPerSample, int sx, int sz, int size)
        {
            Debug.Assert(src.Width >= (sx + size));
            Debug.Assert(src.Height >= (sz + size));
            Debug.Assert(src.BytesPerPixel == BytesPerSample);

            this.metersPerSample = metersPerSample;
            this.numSamples = size;
            this.map = map;

            InitBuffer();

            CopyFromImage(src, sx, sz, size);
        }
Ejemplo n.º 7
0
        public ValueMapLayer(WorldMap map, string layerName, int metersPerTile, int metersPerSample, 
            float valueBase, float valueRange, uint defaultRawValue, uint maxRaw)
            : base(map, layerName, metersPerTile, metersPerSample)
        {
            Debug.Assert(defaultRawValue <= maxRaw);

            this.valueBase = valueBase;
            this.valueRange = valueRange;
            this.maxRaw = maxRaw;
            fmaxRaw = (float)maxRaw;

            // use the property so that defaultValue gets calculated automatically
            DefaultRawValue = defaultRawValue;
        }
Ejemplo n.º 8
0
        public static MapLayer MapLayerFactory(WorldMap map, XmlReader r)
        {
            for (int i = 0; i < r.AttributeCount; i++)
            {
                r.MoveToAttribute(i);

                if (r.Name == "Type")
                {
                    LayerParser factory = layerParsers[r.Value];

                    if (factory != null)
                    {
                        return factory(map, r);
                    }
                }
            }

            return null;
        }
Ejemplo n.º 9
0
 public ColorMapLayer(WorldMap map, string layerName, int metersPerTile, int metersPerSample, 
     ColorEx defaultColor)
     : base(map, layerName, metersPerTile, metersPerSample)
 {
     this.defaultColor = defaultColor;
 }
Ejemplo n.º 10
0
        public MapLayer(WorldMap map, string layerName, int metersPerTile, int metersPerSample)
        {
            this.map = map;
            this.layerName = layerName;
            this.metersPerTile = metersPerTile;
            this.tileSize = metersPerTile * WorldMap.oneMeter;
            this.metersPerSample = metersPerSample;
            this.samplesPerTile = metersPerTile / metersPerSample;

            tiles = new Dictionary<CoordXZ, MapBuffer>();
            properties = new MapProperties(this);
        }
Ejemplo n.º 11
0
 protected abstract MapBuffer NewBuffer(WorldMap map, int numSamples, int metersPerSample);
Ejemplo n.º 12
0
 protected abstract MapBuffer NewBuffer(WorldMap map, int numSamples, int metersPerSample);
Ejemplo n.º 13
0
 public MapBufferARGB(WorldMap map, int numSamples, int metersPerSample)
     : base(map, numSamples, metersPerSample)
 {
 }
Ejemplo n.º 14
0
 protected override MapBuffer NewBuffer(WorldMap map, int numSamples, int metersPerSample)
 {
     return new MapBufferARGB(map, numSamples, metersPerSample);
 }
Ejemplo n.º 15
0
 public MapBufferARGB(WorldMap map, Image src, int metersPerSample, int sx, int sz, int size)
     : base(map, src, metersPerSample, sx, sz, size)
 {
 }
Ejemplo n.º 16
0
 public MapBufferARGB(WorldMap map, string filename)
     : base(map, filename)
 {
 }
Ejemplo n.º 17
0
 public MapBufferARGB(WorldMap map, int numSamples, int metersPerSample)
     : base(map, numSamples, metersPerSample)
 {
 }
Ejemplo n.º 18
0
 public ValueMapLayer16(WorldMap map, string layerName, int metersPerTile, int metersPerSample,
     float valueBase, float valueRange, float defaultValue)
     : base(map, layerName, metersPerTile, metersPerSample, valueBase, valueRange, 
         (uint)((( defaultValue - valueBase ) / valueRange)* ushort.MaxValue), ushort.MaxValue)
 {
 }
Ejemplo n.º 19
0
 public MapBufferARGB(WorldMap map, Image src, int metersPerSample, int sx, int sz, int size)
     : base(map, src, metersPerSample, sx, sz, size)
 {
 }
Ejemplo n.º 20
0
        protected static MapLayer ParseLayer(WorldMap map, XmlReader r)
        {
            string layerName = null;
            int metersPerTile = 0;
            int metersPerSample = 0;
            float red = 0;
            float green = 0;
            float blue = 0;
            float alpha = 0;

            // parse attributes
            for (int i = 0; i < r.AttributeCount; i++)
            {
                r.MoveToAttribute(i);

                // set the field in this object based on the element we just read
                switch (r.Name)
                {
                    case "Type":
                        break;
                    case "Name":
                        layerName = r.Value;
                        break;
                    case "MetersPerTile":
                        metersPerTile = int.Parse(r.Value);
                        break;
                    case "MetersPerSample":
                        metersPerSample = int.Parse(r.Value);
                        break;
                    case "DefaultColorR":
                        red = float.Parse(r.Value);
                        break;
                    case "DefaultColorG":
                        green = float.Parse(r.Value);
                        break;
                    case "DefaultColorB":
                        blue = float.Parse(r.Value);
                        break;
                    case "DefaultColorA":
                        alpha = float.Parse(r.Value);
                        break;

                }
            }

            r.MoveToElement(); //Moves the reader back to the element node.

            MapLayer layer = new ColorMapLayer(map, layerName, metersPerTile, metersPerSample, new ColorEx(alpha, red, green, blue));

            if (!r.IsEmptyElement)
            {
                // now parse the sub-elements
                while (r.Read())
                {
                    // look for the start of an element
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        // parse that element
                        // save the name of the element
                        string elementName = r.Name;
                        switch (elementName)
                        {
                            case "Property":
                                layer.Properties.ParseProperty(r);
                                break;
                        }
                    }
                    else if (r.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }

            return layer;
        }
        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();
                }
            }
        }
Ejemplo n.º 22
0
 public MapBuffer32(WorldMap map, Image src, int metersPerSample, int sx, int sz,
                    float srcMinHeight, float srcMaxHeight, int size, float destMinHeight, float destMaxHeight)
     : base(map, src, metersPerSample, sx, sz, srcMinHeight, srcMaxHeight, size, destMinHeight, destMaxHeight)
 {
 }
Ejemplo n.º 23
0
 public MapBuffer32(WorldMap map, Image src, int metersPerSample, int sx, int sz, 
     float srcMinHeight, float srcMaxHeight, int size, float destMinHeight, float destMaxHeight)
     : base(map, src, metersPerSample, sx, sz, srcMinHeight, srcMaxHeight, size, destMinHeight, destMaxHeight)
 {
 }
Ejemplo n.º 24
0
 public MapBufferARGB(WorldMap map, string filename)
     : base(map, filename)
 {
 }
Ejemplo n.º 25
0
 public MapSection(WorldMap map, CoordXZ sectionCoord, string worldPath)
     : this(map, sectionCoord)
 {
     FromXml(worldPath);
 }
Ejemplo n.º 26
0
 protected override MapBuffer NewBuffer(WorldMap map, int numSamples, int metersPerSample)
 {
     return(new MapBufferARGB(map, numSamples, metersPerSample));
 }
Ejemplo n.º 27
0
 public ColorMapLayer(WorldMap map, string layerName, int metersPerTile, int metersPerSample,
                      ColorEx defaultColor)
     : base(map, layerName, metersPerTile, metersPerSample)
 {
     this.defaultColor = defaultColor;
 }
        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();
            }
        }
Ejemplo n.º 29
0
        protected static MapLayer ParseLayer(WorldMap map, XmlReader r)
        {
            string layerName       = null;
            int    metersPerTile   = 0;
            int    metersPerSample = 0;
            float  red             = 0;
            float  green           = 0;
            float  blue            = 0;
            float  alpha           = 0;

            // parse attributes
            for (int i = 0; i < r.AttributeCount; i++)
            {
                r.MoveToAttribute(i);

                // set the field in this object based on the element we just read
                switch (r.Name)
                {
                case "Type":
                    break;

                case "Name":
                    layerName = r.Value;
                    break;

                case "MetersPerTile":
                    metersPerTile = int.Parse(r.Value);
                    break;

                case "MetersPerSample":
                    metersPerSample = int.Parse(r.Value);
                    break;

                case "DefaultColorR":
                    red = float.Parse(r.Value);
                    break;

                case "DefaultColorG":
                    green = float.Parse(r.Value);
                    break;

                case "DefaultColorB":
                    blue = float.Parse(r.Value);
                    break;

                case "DefaultColorA":
                    alpha = float.Parse(r.Value);
                    break;
                }
            }

            r.MoveToElement(); //Moves the reader back to the element node.

            MapLayer layer = new ColorMapLayer(map, layerName, metersPerTile, metersPerSample, new ColorEx(alpha, red, green, blue));

            if (!r.IsEmptyElement)
            {
                // now parse the sub-elements
                while (r.Read())
                {
                    // look for the start of an element
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        // parse that element
                        // save the name of the element
                        string elementName = r.Name;
                        switch (elementName)
                        {
                        case "Property":
                            layer.Properties.ParseProperty(r);
                            break;
                        }
                    }
                    else if (r.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }

            return(layer);
        }