Esempio n. 1
0
        void DoDrawImageCore(Player p, Vec3S32[] marks, DrawArgs dArgs)
        {
            Bitmap bmp = HeightmapGen.DecodeImage(dArgs.Data, p);

            if (bmp == null)
            {
                return;
            }

            ImagePrintDrawOp op = new ImagePrintDrawOp();

            op.LayerMode = dArgs.Layer; op.DualLayer = dArgs.Dual;
            op.CalcState(marks);

            int width  = dArgs.Width == 0 ? bmp.Width  : dArgs.Width;
            int height = dArgs.Height == 0 ? bmp.Height : dArgs.Height;

            Clamp(p, marks, op, ref width, ref height);

            if (width < bmp.Width || height < bmp.Height)
            {
                bmp = Resize(bmp, width, height);
            }

            op.SetLevel(p.level);
            op.Player = p; op.Source = bmp; op.Palette = dArgs.Pal;
            DrawOpPerformer.Do(op, null, p, marks, false);
        }
    private void InitPrefabsAndScripts()
    {
        // Biome/color tuple
        Tuple <uint, uint, uint, uint, uint>      BiomeTuple = new Tuple <uint, uint, uint, uint, uint>(biome_Water, biome_Sand, biome_Grass, biome_Mountain, biome_Snow);
        Tuple <Color, Color, Color, Color, Color> ColorTuple = new Tuple <Color, Color, Color, Color, Color>(texture_WaterColor, texture_SandColor, texture_GrassColor, texture_MountainColor, texture_SnowColor);

        // Heightmap tuples
        Tuple <float, float, float, float, float> heightmapBasesTuple = new Tuple <float, float, float, float, float>(heightmap_WaterBase, heightmap_SandBase, heightmap_GrassBase, heightmap_MountainBase, heightmap_SnowBase);
        Tuple <float, float, float, float, float> heightmapDispTuple  = new Tuple <float, float, float, float, float>(heightmap_WaterDisp, heightmap_SandDisp, heightmap_GrassDisp, heightmap_MountainDisp, heightmap_SnowDisp);

        // Model placer
        GameObject ModelPlacerPrefab = (GameObject)Resources.Load("PipelinePrefabs/ModelPlacerPrefab");

        ModelPlacerInstance = (GameObject)GameObject.Instantiate(ModelPlacerPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        ModelPlacerScript   = ModelPlacerInstance.GetComponent <ModelPlacer>();
        ModelPlacerScript.Init(heightmap_PowerN, block_VertexWidth, biome_HeightmapContentWidth, mp_waterHeight, heightmap_deltaClamp, BiomeTuple, mp_modelsPerBlock, mp_modelPlacementChance);

        // Biome gen
        GameObject BiomeGenPrefab = (GameObject)Resources.Load("PipelinePrefabs/BiomeGenPrefab");

        BiomeGenInstance = (GameObject)GameObject.Instantiate(BiomeGenPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        BiomeGenScript   = BiomeGenInstance.GetComponent <BiomeGen>();
        BiomeGenScript.Init(biome_Dimensions, biome_SeedSpacing, biome_DisplacementDiv, BiomeTuple);

        // Map database
        GameObject MapDatabasePrefab = (GameObject)Resources.Load("PipelinePrefabs/MapDatabasePrefab");

        MapDatabaseInstance = (GameObject)GameObject.Instantiate(MapDatabasePrefab, new Vector3(0, 0, 0), Quaternion.identity);
        MapDatabaseScript   = MapDatabaseInstance.GetComponent <MapDatabase>();
        MapDatabaseScript.Init(heightmap_PowerN, biome_Dimensions, biome_HeightmapContentWidth, block_VertexWidth);

        // Heightmap gen
        GameObject HeightmapGenPrefab = (GameObject)Resources.Load("PipelinePrefabs/HeightmapGenPrefab");

        HeightmapGenInstance = (GameObject)GameObject.Instantiate(HeightmapGenPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        HeightmapGenScript   = HeightmapGenInstance.GetComponent <HeightmapGen>();
        HeightmapGenScript.Init(heightmap_PowerN, BiomeTuple, heightmapBasesTuple, heightmapDispTuple, heightmap_displacementScale, heightmap_deltaScale, heightmap_deltaClamp);;

        // Material gen
        GameObject MaterialGenPrefab = (GameObject)Resources.Load("PipelinePrefabs/MaterialGenPrefab");

        MaterialGenInstance = (GameObject)GameObject.Instantiate(MaterialGenPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        MaterialGenScript   = MaterialGenInstance.GetComponent <MaterialGen>();
        MaterialGenScript.InitTexture(material_Resolution, heightmap_PowerN, BiomeTuple, ColorTuple);

        // Model gen / master terrain
        ModelGenPrefab = (GameObject)Resources.Load("PipelinePrefabs/ModelGenPrefab");
        GameObject MasterTerrainPrefab = (GameObject)Resources.Load("PipelinePrefabs/MasterTerrainPrefab");

        MasterTerrainInstance = (GameObject)GameObject.Instantiate(MasterTerrainPrefab, new Vector3(0, 0, 0), Quaternion.identity);
    }
Esempio n. 3
0
        void DoDrawImageCore(Player p, Vec3S32[] m, DrawArgs dArgs)
        {
            Bitmap bmp = HeightmapGen.ReadBitmap(dArgs.name, "extra/images/", p);

            if (bmp == null)
            {
                return;
            }
            try {
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            } catch (Exception ex) {
                Server.ErrorLog(ex);
                bmp.Dispose();
                return;
            }

            ImagePrintDrawOp op = new ImagePrintDrawOp();

            if (Math.Abs(m[1].X - m[0].X) > Math.Abs(m[1].Z - m[0].Z))
            {
                op.Direction = m[1].X <= m[0].X ? 1 : 0;
            }
            else
            {
                op.Direction = m[1].Z <= m[0].Z ? 3 : 2;
            }

            op.Level    = p.level;
            op.Player   = p;
            op.Source   = bmp;
            op.Layer    = dArgs.layer;
            op.Mode     = dArgs.popType;
            op.Filename = dArgs.name;

            if (op.Layer)
            {
                if (op.Mode == 1)
                {
                    op.Mode = 2;
                }
                if (op.Mode == 3)
                {
                    op.Mode = 4;
                }
            }
            DrawOp.DoDrawOp(op, null, p, m, false);
        }
Esempio n. 4
0
        void DoDrawImageCore(Player p, Vec3S32[] m, DrawArgs dArgs)
        {
            Bitmap bmp = HeightmapGen.ReadBitmap(dArgs.name, "extra/images/", p);

            if (bmp == null)
            {
                return;
            }
            try {
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            } catch (Exception ex) {
                Logger.LogError(ex);
                bmp.Dispose();
                return;
            }

            ImagePrintDrawOp op = new ImagePrintDrawOp();
            int dir;

            if (Math.Abs(m[1].X - m[0].X) > Math.Abs(m[1].Z - m[0].Z))
            {
                dir = m[1].X <= m[0].X ? 1 : 0;
            }
            else
            {
                dir = m[1].Z <= m[0].Z ? 3 : 2;
            }
            op.LayerMode = dArgs.layer; op.DualLayer = dArgs.dualLayered;
            op.CalcState(dir);

            ResizeImage(p, m, op, ref bmp);
            op.SetLevel(p.level);
            op.Player = p; op.Source = bmp;

            op.Palette = dArgs.palette; op.Filename = dArgs.name;
            DrawOpPerformer.Do(op, null, p, m, false);
        }
Esempio n. 5
0
 bool DownloadWebFile(string url, Player p)
 {
     return(HeightmapGen.DownloadImage(url, "extra/images/", p));
 }
Esempio n. 6
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (!Directory.Exists("extra/images/"))
            {
                Directory.CreateDirectory("extra/images/");
            }
            if (message.Length == 0)
            {
                Help(p); return;
            }
            string[] parts = message.SplitSpaces(5);

            DrawArgs dArgs = new DrawArgs();

            dArgs.Pal = ImagePalette.Find("color");
            if (dArgs.Pal == null)
            {
                dArgs.Pal = ImagePalette.Palettes[0];
            }

            if (parts.Length > 1)
            {
                dArgs.Pal = ImagePalette.Find(parts[1]);
                if (dArgs.Pal == null)
                {
                    p.Message("Palette {0} not found.", parts[1]); return;
                }

                if (dArgs.Pal.Entries == null || dArgs.Pal.Entries.Length == 0)
                {
                    p.Message("Palette {0} does not have any entries", dArgs.Pal.Name);
                    p.Message("Use %T/Palette %Sto add entries to it"); return;
                }
            }

            if (parts.Length > 2)
            {
                string mode = parts[2];
                if (mode.CaselessEq("horizontal"))
                {
                    dArgs.Layer = true;
                }
                if (mode.CaselessEq("vertical2layer"))
                {
                    dArgs.Dual = true;
                }
            }

            if (parts.Length > 4)
            {
                if (!CommandParser.GetInt(p, parts[3], "Width", ref dArgs.Width, 1, 1024))
                {
                    return;
                }
                if (!CommandParser.GetInt(p, parts[4], "Height", ref dArgs.Height, 1, 1024))
                {
                    return;
                }
            }

            if (parts[0].IndexOf('.') != -1)
            {
                if (!HeightmapGen.DownloadImage(parts[0], "extra/images/", p))
                {
                    return;
                }
                dArgs.Name = "tempImage_" + p.name;
            }
            else
            {
                dArgs.Name = parts[0];
            }

            if (!File.Exists("extra/images/" + dArgs.Name + ".bmp"))
            {
                p.Message("The URL entered was invalid!"); return;
            }
            p.Message("Place or break two blocks to determine direction.");
            p.MakeSelection(2, "Selecting direction for %SImagePrint", dArgs, DoImage);
        }