コード例 #1
0
 public GroundProbe(Client.Game.Map.Map map)
 {
     this.map = map;
 }
コード例 #2
0
 void LoadDynamicData(Map map, ZipFile mapFile)
 {
     using (var f = mapFile[GetDynamicFileName()].OpenReader())
         map.DynamicData = (MapDynamicData)formatter.Deserialize(f);
     formatter.PersistenceData = null;
 }
コード例 #3
0
 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);
 }
コード例 #4
0
        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);
        }
コード例 #5
0
 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);
 }
コード例 #6
0
 public void RemoveAllFiles(Map map, string filename)
 {
     persisters[GetVersion(filename) - 1].RemoveAllFiles(map, filename);
 }
コード例 #7
0
        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;
        }
コード例 #8
0
        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();
        }
コード例 #9
0
 public virtual void CheckParameters(Map map, Action<String> errors)
 {
 }
コード例 #10
0
        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;
        }
コード例 #11
0
 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
             });
 }
コード例 #12
0
 public Game(Map.Map map)
     : this()
 {
     preLoadedMap = map;
 }
コード例 #13
0
 public GroundProbe(Client.Game.Map.Map map)
 {
     this.map = map;
 }
コード例 #14
0
        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();
        }
コード例 #15
0
 public void Reload(Map map)
 {
     using(var mapFile = new ZipFile(map.MapFileName))
         LoadDynamicData(map, mapFile);
     map.FindMainCharacter();
 }
コード例 #16
0
        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();
        }
コード例 #17
0
 public virtual void RemoveAllFiles(Map map, String filename)
 {
     if (FileSystem.Instance.FileExists(filename))
         FileSystem.Instance.DeleteFile(filename);
 }
コード例 #18
0
        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();
        }
コード例 #19
0
        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);
        }
コード例 #20
0
 public void Reload(Map map)
 {
     persisters[GetVersion(map.MapFileName) - 1].Reload(map);
 }
コード例 #21
0
        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();
        }
コード例 #22
0
 public void Save(Map map, string filename)
 {
     persisters[persisters.Length - 1].Save(map, filename);
 }
コード例 #23
0
 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();
 }
コード例 #24
0
 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);
 }
コード例 #25
0
        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));
        }
コード例 #26
0
 public override void CheckParameters(Map map, Action<string> errors)
 {
     base.CheckParameters(map, errors);
     if(Units == null)
         errors(Name + "| Units property not set");
 }
コード例 #27
0
 public Game(Map.Map map)
     : this()
 {
     preLoadedMap = map;
 }