Exemple #1
0
 public GroundProbe(Client.Game.Map.Map map)
 {
     this.map = map;
 }
 void LoadDynamicData(Map map, ZipFile mapFile)
 {
     using (var f = mapFile[GetDynamicFileName()].OpenReader())
         map.DynamicData = (MapDynamicData)formatter.Deserialize(f);
     formatter.PersistenceData = null;
 }
 public override void CheckParameters(Map map, Action<string> errors)
 {
     if (map.GetRegion(Region) == null) errors(Name + "| No such region: " + Region);
     if (IsInRegionScript != null) IsInRegionScript.CheckParameters(map, (s) => errors(Name + "[IsInRegionScript]." + s));
     if (IsNotInRegionScript != null) IsNotInRegionScript.CheckParameters(map, (s) => errors(Name + "[IsNotInRegionScript]." + s));
     base.CheckParameters(map, errors);
 }
        public override void CheckParameters(Map map, Action<String> errors)
        {
            if (String.IsNullOrEmpty(Point)) errors(Name + "| Point null or empty");

            if(map.GetRegion(Point) == null)
                if (map.StaticsRoot.GetByName(Point) == null &&
                    map.DynamicsRoot.GetByName(Point) == null) errors(Name + "| No such point: " + Point);

            var type = binder.BindToType(typeof(SpawnScript).Assembly.FullName, SpawnType);
            if (type == null) errors(Name + "| No such type: " + SpawnType);

            base.CheckParameters(map, errors);
        }
 public List<Common.Tuple<string, System.Action>> GetLoadSteps(string mapFilename, SlimDX.Direct3D9.Device device, out Map map)
 {
     return persisters[GetVersion(mapFilename) - 1].GetLoadSteps(mapFilename, device, out map);
 }
 public void RemoveAllFiles(Map map, string filename)
 {
     persisters[GetVersion(filename) - 1].RemoveAllFiles(map, filename);
 }
        public List<Common.Tuple<String, System.Action>> GetLoadSteps(string filename, SlimDX.Direct3D9.Device device, out Map outMap)
        {
            var baseFileName = Path.GetFileName(filename);
            var map = new Map { MapName = baseFileName, MapFileName = Path.GetFullPath(filename) };
            outMap = map;
            var mapFile = new ZipFile(filename);
            map.OnResetDevice = () => OnResetDevice(map);

            var a = new List<Common.Tuple<string, System.Action>>();

            a.Add(new Common.Tuple<string, System.Action>("Loading settings",
                () => map.Settings = LoadSettings(baseFileName, mapFile)));

            a.Add(new Common.Tuple<string, System.Action>("Loading static data", () => LoadStaticData(map, mapFile)));
            a.Add(new Common.Tuple<string, System.Action>("Loading dynamic data", () => LoadDynamicData(map, mapFile)));
            a.Add(new Common.Tuple<string, System.Action>("Loading language data",
                () => map.StringLocalizationStorage = LoadLanguageData(baseFileName, mapFile)));

            a.Add(new Common.Tuple<string, System.Action>("NormalizeStaticDynamicObjects",
                map.NormalizeStaticDynamicObjects));

            a.Add(new Common.Tuple<string, System.Action>("Init scene root", () =>
            {

                foreach (var v in map.DynamicsRoot.Offspring)
                    if (v is GameEntity)
                        ((GameEntity)v).Map = map;

                foreach (var v in map.StaticsRoot.Offspring)
                    if (v is GameEntity)
                        ((GameEntity)v).Map = map;

                map.FindMainCharacter();
            }));

            a.Add(new Common.Tuple<string, System.Action>("Creating ground", () =>
            {
                map.Ground = new Ground();
                map.InitGround();
            }));

            a.Add(new Common.Tuple<string, System.Action>("Loading SplatMap", () => LoadSplatMap(map, device, mapFile)));

            a.Add(new Common.Tuple<string, System.Action>("Loading SplatMap2", () => LoadSplatMap2(map, device, mapFile)));

            a.Add(new Common.Tuple<string, System.Action>("Loading Heightmap", () => LoadHeightmap(map, mapFile)));
            a.Add(new Common.Tuple<string, System.Action>("Constructing ground pieces", () => map.Ground.ConstructPieces(map)));

            a.Add(new Common.Tuple<string, System.Action>("Initializing ground", () =>
            {
                if (map.Ground.SplatMap1 != null && map.Ground.SplatMap2 != null)
                    map.Ground.Init();
            }));

            a.Add(new Common.Tuple<string, System.Action>("Done", () =>
            {
                mapFile.Dispose();
            }));

            return a;
        }
        void LoadStaticData(Map map, ZipFile mapFile)
        {
            #pragma warning disable 612,618
            if (!string.IsNullOrEmpty(map.Settings.StaticDataSourceMap))
                mapFile = new ZipFile(Path.Combine(Path.GetDirectoryName(map.MapFileName), map.Settings.StaticDataSourceMap));
            #pragma warning restore 612,618

            using (var f = mapFile[GetStaticFileName()].OpenReader())
                map.StaticData = (MapStaticData)formatter.Deserialize(f);
            formatter.PersistenceData = null;
            if (!string.IsNullOrEmpty(map.Settings.StaticDataSourceMap))
                mapFile.Dispose();
        }
 public virtual void CheckParameters(Map map, Action<String> errors)
 {
 }
        public static Map New(MapSettings settings, SlimDX.Direct3D9.Device device)
        {
            Map m = new Map
            {
                Settings = settings
            };

            m.Ground = new Ground();
            m.InitGround();
            m.NewSplatMap1(device);
            m.NewSplatMap2(device);
            m.Ground.ConstructPieces(m);
            m.Ground.Init();
            m.MainCharacter = new Units.MainCharacter
            {
                Translation = new Vector3(settings.Size.Width / 2f, settings.Size.Height / 2f, 0),
                Name = "MainCharacter"
            };
            m.DynamicsRoot.AddChild(m.MainCharacter);

            return m;
        }
 public void ConstructPieces(Map map)
 {
     ClearChildren();
     float widthStep = Size.Width / (Heightmap.GetLength(1) - 1);
     float heightStep = Size.Height / (Heightmap.GetLength(0) - 1);
     PieceSize = SnapToHeightmap(PieceSize);
     int npiecesw = (int)Math.Ceiling(Size.Width / PieceSize.Width);
     int npiecesh = (int)Math.Ceiling(Size.Height / PieceSize.Height);
     Pieces = new GroundPiece[npiecesh, npiecesw];
     for (int y = 0; y < npiecesh; y++)
         for (int x = 0; x < npiecesw; x++)
             AddChild(Pieces[y, x] = new GroundPiece
             {
                 Translation = new Vector3(PieceSize.Width * x, PieceSize.Height * y, 0),
                 Size = Common.Math.ToVector2(PieceSize),
                 Map = map
             });
 }
 public Game(Map.Map map)
     : this()
 {
     preLoadedMap = map;
 }
 public GroundProbe(Client.Game.Map.Map map)
 {
     this.map = map;
 }
        void LoadHeightmap(Map map, ZipFile mapFile)
        {
            #pragma warning disable 612,618
            if (!string.IsNullOrEmpty(map.Settings.StaticDataSourceMap))
                mapFile = new ZipFile(Path.Combine(Path.GetDirectoryName(map.MapFileName), map.Settings.StaticDataSourceMap));
            #pragma warning restore 612,618

            if (!mapFile.ContainsEntry(GetHeightmapFileName()))
            {
                if (!string.IsNullOrEmpty(map.Settings.StaticDataSourceMap))
                    mapFile.Dispose();
                return;
            }

            using (var f2 = mapFile[GetHeightmapFileName()].OpenReader())
                DeserializeHieghtmap(map, f2);

            if (!string.IsNullOrEmpty(map.Settings.StaticDataSourceMap))
                mapFile.Dispose();
        }
 public void Reload(Map map)
 {
     using(var mapFile = new ZipFile(map.MapFileName))
         LoadDynamicData(map, mapFile);
     map.FindMainCharacter();
 }
        void LoadSplatMap2(Map map, SlimDX.Direct3D9.Device device, ZipFile mapFile)
        {
            #pragma warning disable 612,618
            if (!string.IsNullOrEmpty(map.Settings.StaticDataSourceMap))
                mapFile = new ZipFile(Path.Combine(Path.GetDirectoryName(map.MapFileName), map.Settings.StaticDataSourceMap));
            #pragma warning restore 612,618

            if (!mapFile.ContainsEntry(GetSplatTexture2FileName()))
            {
                map.NewSplatMap2(device);
                if (!string.IsNullOrEmpty(map.Settings.StaticDataSourceMap))
                    mapFile.Dispose();
                return;
            }

            using (var splat2Stream = mapFile[GetSplatTexture2FileName()].OpenReader())
                map.Ground.SplatMap2 =
                    new Graphics.Content.UnmanagedResource<SlimDX.Direct3D9.Texture, SlimDX.Direct3D10.Texture2D>
                    {
                        Resource9 = SlimDX.Direct3D9.Texture.FromStream(device, splat2Stream)
                    };
            if (!string.IsNullOrEmpty(map.Settings.StaticDataSourceMap))
                mapFile.Dispose();
        }
 public virtual void RemoveAllFiles(Map map, String filename)
 {
     if (FileSystem.Instance.FileExists(filename))
         FileSystem.Instance.DeleteFile(filename);
 }
        void OnResetDevice(Map map)
        {
            if (map.MapName == null) return;

            var mapFile = new ZipFile(map.MapFileName);

            using (var splat1Stream = mapFile[GetSplatTexture1FileName()].OpenReader())
                map.Ground.SplatMap1.Resource9 =
                    SlimDX.Direct3D9.Texture.FromStream(Program.Instance.Device9, splat1Stream);

            using (var splat2Stream = mapFile[GetSplatTexture2FileName()].OpenReader())
                map.Ground.SplatMap2.Resource9 =
                    SlimDX.Direct3D9.Texture.FromStream(Program.Instance.Device9,splat2Stream);

            map.Ground.InitSplatMapValues();
        }
        public void Save(Map map, string filename)
        {
            map.Settings.MapVersion++;
            map.MapName = Path.GetFileName(filename);

            var mapFile = new ZipFile();

            WriteToFile(map, filename, mapFile);

            mapFile.Save(filename);
        }
 public void Reload(Map map)
 {
     persisters[GetVersion(map.MapFileName) - 1].Reload(map);
 }
        protected virtual void DeserializeHieghtmap(Map map, Stream stream)
        {
            // Heightmap serialization method 3
            var d = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(stream);
            d.GetNextEntry();
            var br = new BinaryReader(d);
            var height = br.ReadInt32();
            var width = br.ReadInt32();
            var hm = new Graphics.Software.Texel.R32F[height, width];
            for (var y = 0; y < height; y++)
                for (var x = 0; x < width; x++)
                    hm[y, x] = new Graphics.Software.Texel.R32F(br.ReadSingle());

            map.Ground.Heightmap = hm;
            d.Close();
        }
 public void Save(Map map, string filename)
 {
     persisters[persisters.Length - 1].Save(map, filename);
 }
 protected virtual void SerializeHeightmap(Map map, Stream stream)
 {
     // Heightmap serialization method 3
     var i = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(stream);
     var entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry("Heightmap");
     i.PutNextEntry(entry);
     var bw = new BinaryWriter(i);
     bw.Write(map.Ground.Heightmap.GetLength(0));
     bw.Write(map.Ground.Heightmap.GetLength(1));
     for (var y = 0; y < map.Ground.Heightmap.GetLength(0); y++)
         for (var x = 0; x < map.Ground.Heightmap.GetLength(1); x++)
             bw.Write(map.Ground.Heightmap[y, x].R);
     i.Close();
 }
 public override void CheckParameters(Map map, Action<string> errors)
 {
     foreach (var v in Scripts)
         v.CheckParameters(map, (s) => errors(Name + "." + s));
     base.CheckParameters(map, errors);
 }
        protected virtual void WriteToFile(Map map, string filename, ZipFile mapFile)
        {
            var mapBaseFileName = map.MapName;

            mapFile.AddEntry(GetStaticFileName(), (name, f) =>
                formatter.Serialize(f, map.StaticData));

            mapFile.AddEntry(GetDynamicFileName(), (name, f) =>
                formatter.Serialize(f, map.DynamicData));

            foreach(var language in map.StringLocalizationStorage.GetLanguages())
            {
                string fn = null;
                if(language == "en") fn = "strings.resx";
                else fn = "strings." + language + ".resx";

                mapFile.AddEntry(fn, (name, stream) =>
                    map.StringLocalizationStorage.WriteLanguageToStream(language, stream));
            }

            mapFile.AddEntry(GetSettingsFileName(), (name, f) =>
                formatter.Serialize(f, map.Settings));

            if (map.Ground.SplatMap1 != null)
                mapFile.AddEntry(GetSplatTexture1FileName(), (name, stream) =>
                    SlimDX.Direct3D9.BaseTexture.ToStream(map.Ground.SplatMap1.Resource9,
                        SlimDX.Direct3D9.ImageFileFormat.Png).CopyTo(stream));

            if (map.Ground.SplatMap2 != null)
                mapFile.AddEntry(GetSplatTexture2FileName(), (name, stream) =>
                    SlimDX.Direct3D9.BaseTexture.ToStream(map.Ground.SplatMap2.Resource9,
                        SlimDX.Direct3D9.ImageFileFormat.Png).CopyTo(stream));

            mapFile.AddEntry(GetHeightmapFileName(), (name, stream) =>
                SerializeHeightmap(map, stream));
        }
 public override void CheckParameters(Map map, Action<string> errors)
 {
     base.CheckParameters(map, errors);
     if(Units == null)
         errors(Name + "| Units property not set");
 }
Exemple #27
0
 public Game(Map.Map map)
     : this()
 {
     preLoadedMap = map;
 }