public MapBase(RawMap rawMap) { this.rawMap = rawMap; Tile = new TileCollection(rawMap); Npc = new MapNpcPresetCollection(rawMap); }
public static Map Load( string name, GameObject mapRoot, MeshFilter tilePool, FieldTile fieldPrototype, FieldTile verticalFieldPrototype, FieldCollider fieldColliderPrototype, WalkerBehavior walkerPrototype, Action <Map, MeshFilter, int, int> onEachTile ) { string path = Path.Combine(MapLoader.MapJsonDirectory, name); TextAsset asset = Resources.Load <TextAsset>(path); if (asset == null) { Debug.Log("could not load map file: " + path); return(new Map()); } // JsonUtility does not support nested array DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Map)); RawMap raw = JsonUtility.FromJson <RawMap>(asset.text); MapLoader.RawMapToMap(raw, out MapLoader.currentMap); MapLoader.currentMap.height = (int)Mathf.Floor(MapLoader.currentMap.terrains[0].Length / MapLoader.currentMap.width) + 1; MapLoader.InstantiateFields(mapRoot, tilePool, fieldPrototype, verticalFieldPrototype, fieldColliderPrototype, onEachTile); MapLoader.InstantiateWalkerBehaviors(mapRoot, walkerPrototype); return(MapLoader.currentMap); }
public ColorMap <ushort> Process(RawMap <ushort> map) { var res = new ColorMapUshort(map.Width / 2, map.Height / 2, map.MaxBits); var c = new ushort[4]; var pix = res.GetPixel(); for (var y = 0; y < res.Height; y++) { var raw = map.GetRow(y * 2); for (var x = 0; x < res.Width; x++) { c[0] = raw.Value; c[1] = raw.GetRel(+1, +0); c[2] = raw.GetRel(0, +1); c[3] = raw.GetRel(+1, +1); pix[0] = c[3]; pix[1] = c[1]; pix[2] = c[0]; pix.MoveNext(); raw.MoveNext(); raw.MoveNext(); } } return(res); }
public void Part1Example5() { var raw = new RawMap(new List <string> { ".#..##.###...#######", "##.############..##.", ".#.######.########.#", ".###.#######.####.#.", "#####.##.#.##.###.##", "..#####..#.#########", "####################", "#.####....###.#.#.##", "##.#################", "#####.##.###..####..", "..######..##.#######", "####.##.####...##..#", ".#####..#.######.###", "##...#.##########...", "#.##########.#######", ".####.#.###.###.#.##", "....##.##.###..#####", ".#.#.###########.###", "#.#.#.#####.####.###", "###.##.####.##.#..##" }); var map = new Map(raw); var(asteroid, visible) = map.FindBestLocation(); asteroid.Position.Should().BeEquivalentTo(new Coordinates(11, 13)); visible.Should().Be(210); }
public MapBase(string mapID) { rawMap = new RawMap(mapID); rawMap.MaxX = 19; rawMap.MaxY = 14; rawMap.Tile = new DataManager.Maps.Tile[rawMap.MaxX + 1, rawMap.MaxY + 1]; }
private void SaveMap(string fileOpened) { mapFile.Data = new float[mapFile.Width * mapFile.Height]; for (int y = 0; y < mapFile.Height; y++) { for (int x = 0; x < mapFile.Width; x++) { mapFile.Data[x + y * mapFile.Width] = ForegroundGame.Map.altitudeData[x, y]; } } string fullpath = Path.GetFullPath(Application.StartupPath + @"\..\data\Maps"); /*foreach (MapModel mapmodel in mapFile.Models) { * mapmodel.file = PathHandling.RelativePath(fullpath,mapmodel.file); * mapmodel.Position = mapmodel.model.Position; * mapmodel.Orientation = mapmodel.model.Orientation; * mapmodel.Scale = mapmodel.model.Scale; * }*/ RawMap.Save(mapFile, fileOpened); Texture2DDescription desc = new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm, Width = mapFile.Width, Height = mapFile.Height, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Usage = ResourceUsage.Staging, }; Texture2D tex = new Texture2D(Display.device, desc); string pathz; if (renderWindow1.modifiedTextureMap) { Display.context.CopyResource(ForegroundGame.Map.TextureMap.Tex, tex); pathz = Path.Combine(Resources.Main_Path, "Maps\\" + fileOpened + "\\_textureMap.png"); Texture2D.ToFile(Display.context, tex, ImageFileFormat.Png, pathz); renderWindow1.modifiedTextureMap = false; } if (renderWindow1.modifiedColorMap) { Display.context.CopyResource(ForegroundGame.Map.ColorMap.Tex, tex); pathz = Path.Combine(Resources.Main_Path, "Maps\\" + fileOpened + "\\_colorMap.png"); Texture2D.ToFile(Display.context, tex, ImageFileFormat.Png, pathz); renderWindow1.modifiedColorMap = false; } tex.Dispose(); }
public void LoadTextures(RawMap file) { string[] texturesWithNormal = new string[file.Textures.Length * 2]; for (uint i = 0; i < file.Textures.Length; i++) { texturesWithNormal[i * 2] = "Maps/Shared/" + file.Textures[i]; texturesWithNormal[i * 2 + 1] = "Maps/Shared/" + file.Textures[i] + "_bump"; } ForegroundGame.Map.TextureArray = Resources.GetTextureArray(texturesWithNormal); }
public TileCollection(RawMap rawMap) { this.rawMap = rawMap; tiles = new Tile[rawMap.MaxX + 1, rawMap.MaxY + 1]; if (rawMap.Tile != null) { for (int x = 0; x <= MaxX; x++) { for (int y = 0; y <= MaxY; y++) { if (rawMap.Tile[x, y] == null) { rawMap.Tile[x, y] = new DataManager.Maps.Tile(); } tiles[x, y] = new Tile(rawMap.Tile[x, y]); } } } }
public TileCollection(RawMap rawMap, int maxX, int maxY) { this.rawMap = rawMap; rawMap.MaxX = maxX; rawMap.MaxY = maxY; rawMap.Tile = new DataManager.Maps.Tile[MaxX + 1, MaxY + 1]; tiles = new Tile[MaxX + 1, MaxY + 1]; for (int x = 0; x <= MaxX; x++) { for (int y = 0; y <= MaxY; y++) { if (rawMap.Tile[x, y] == null) { rawMap.Tile[x, y] = new DataManager.Maps.Tile(); } tiles[x, y] = new Tile(rawMap.Tile[x, y]); } } }
private System.Windows.Forms.Control ShowImage(sFile file) { #region Palette BinaryReader br = new BinaryReader(File.OpenRead(file.path)); br.ReadUInt32(); // 4 Bytes Stupid uint num_colors = 256; byte[] pal = br.ReadBytes((int)num_colors * 2); Color[] colors = Actions.BGR555ToColor(pal); PaletteBase palette = new RawPalette(colors, false, ColorFormat.colors256, file.name); br.ReadUInt32(); // 4 Bytes Stupid #endregion #region Map NTFS[] map_info = new NTFS[1024]; for (int i = 0; i < 1024; i++) { ushort value = br.ReadUInt16(); map_info[i] = Actions.MapInfo(value); } MapBase map = new RawMap(map_info, 256, 192, false, file.name); #endregion #region Tiles uint size_section = (uint)(br.ReadUInt32() * 64); Console.WriteLine("Size section: " + size_section.ToString("x")); byte[] readsize = br.ReadBytes((int)size_section); ImageBase image = new RawImage(readsize, TileForm.Horizontal, ColorFormat.colors256, 256, 192, false, file.name); #endregion br.Close(); pluginHost.Set_Palette(palette); pluginHost.Set_Image(image); pluginHost.Set_Map(map); return(new ImageControl(pluginHost, image, palette, map)); }
public MainWindow() { InitializeComponent(); Title = this.Text; Main.Form = this; this.AllowDrop = true; this.DragEnter += new DragEventHandler(Form_DragEnter); this.DragDrop += new DragEventHandler(Form_DragDrop); renderWindow1.MouseUp += new MouseEventHandler(Window_MouseUp); renderWindow1.MouseDown += new MouseEventHandler(Window_MouseDown); renderWindow1.MouseMove += new MouseEventHandler(Window_MouseMove); renderWindow1.MouseWheel += new MouseEventHandler(Window_MouseWheel); renderWindow1.MouseHover += new EventHandler(Window_MouseHover); renderWindow1.MouseEnter += new EventHandler(Window_MouseHover); renderWindow1.KeyDown += new KeyEventHandler(Window_KeyDown); renderWindow1.KeyUp += new KeyEventHandler(Window_KeyUp); mapFile = RawMap.Load(OpenedFile); this.Text = Title + " - " + OpenedFile; }
public RawImageFile(RawMap <T> raw) { Raw = raw; }
private IColorMap ProcessFilters(RawMap <ushort> map, IIAutoAdjustableFilter autoFilter = null) { var indColorFilter = new List <IndependentComponentColorToColorFilter <float, float> >(); var indVectorFilter = new List <IndependentComponentVectorToVectorFilter>(); IColorMap currentMap = map; foreach (var filter in _filters) { #if DEBUG if (currentMap is ColorMapFloat) { var m = currentMap as ColorMapFloat; if (m.Rgb.Any(float.IsNaN)) { throw new Exception(); } } #endif if (filter == null) { throw new ArgumentNullException("filter"); } if (filter == autoFilter) { if (filter is IAutoAdjustableFilter <ColorMapFloat> ) { if (currentMap is ColorMapUshort) { currentMap = ApplyIndependentColorToFloatFilters((ColorMapUshort)currentMap, indColorFilter); } ((IAutoAdjustableFilter <ColorMapFloat>)autoFilter).AutoAdjust((ColorMapFloat)currentMap); } else if (filter is IAutoAdjustableFilter <VectorMap> ) { if (currentMap is ColorMapUshort) { currentMap = ApplyIndependentColorToVectorFilters((ColorMapUshort)currentMap, indVectorFilter); } ((IAutoAdjustableFilter <VectorMap>)autoFilter).AutoAdjust((VectorMap)currentMap); } else { throw new NotSupportedException("Not supported AutoAdjust Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } return(currentMap); } if (currentMap is RawBGGRMap <ushort> ) { if (filter is IRawToColorMap16Filter <RawBGGRMap <ushort>, ushort> ) { currentMap = ApplyRawBGGRToColorMapFilter((RawBGGRMap <ushort>)currentMap, (IRawToColorMap16Filter <RawBGGRMap <ushort>, ushort>)filter); } else { throw new NotSupportedException("Not supported Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } } else if (currentMap is ColorMapUshort) { if (filter is IndependentComponentColorToColorFilter <float, float> ) { indColorFilter.Add((IndependentComponentColorToColorFilter <float, float>)filter); } else if (filter is IndependentComponentVectorToVectorFilter) { indVectorFilter.Add((IndependentComponentVectorToVectorFilter)filter); } else if (filter is ColorToColorFilter <float, byte> ) { currentMap = ApplyIndependentColorFiltersWithRGB((ColorMapUshort)currentMap, indColorFilter, (IndependentComponentColorToColorFilter <float, byte>)filter); } else if (filter is ColorToColorFilter <float, float> ) { currentMap = ApplyIndependentColorToFloatFilters((ColorMapUshort)currentMap, indColorFilter); ApplySingleFilterInplace((ColorMap <float>)currentMap, (ColorToColorFilter <float, float>)filter); } else if (filter is VectorToColorFilter <byte> ) { currentMap = ApplyIndependentVectorFiltersWithRGB((ColorMapUshort)currentMap, indVectorFilter, (IndependentComponentVectorToColorFilter <byte>)filter); } else if (filter is VectorToVectorFilter) { currentMap = ApplyIndependentColorToVectorFilters((ColorMapUshort)currentMap, indVectorFilter); ApplySingleFilterInplace((VectorMap)currentMap, (VectorToVectorFilter)filter); } else { throw new NotSupportedException("Not supported Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } } else if (currentMap is ColorMapFloat) { if (filter is ColorToColorFilter <float, float> ) { ApplySingleFilterInplace((ColorMapFloat)currentMap, (ColorToColorFilter <float, float>)filter); } else if (filter is ColorToColorFilter <float, byte> ) { currentMap = ConvertToRGB((ColorMapFloat)currentMap, (ColorToColorFilter <float, byte>)filter); } else { throw new NotSupportedException("Not supported Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } } else if (currentMap is VectorMap) { if (filter is VectorToVectorFilter) { ApplySingleFilterInplace((VectorMap)currentMap, (VectorToVectorFilter)filter); } else if (filter is VectorToColorFilter <byte> ) { currentMap = ConvertToRGB((VectorMap)currentMap, (VectorToColorFilter <byte>)filter); } else { throw new NotSupportedException("Not supported Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } } else { throw new NotSupportedException("Not supported Map: " + currentMap.GetType()); } } return(currentMap); }
public override void Initialize() { instance = this; ShaderManager.Add("VS_Debug", Resources.GetShader("VS", "VS", "Debug.fx")).SetInputLayout(VertexColor.Elements); ShaderManager.Add("PS_Debug", Resources.GetShader("PS", "PS", "Debug.fx")); ShaderManager.Add("VS_UI3D", Resources.GetShader("VS", "VS", "UI3D.fx")).SetInputLayout(VertexTextureColor.Elements); ShaderManager.Add("PS_UI3D", Resources.GetShader("PS", "PS", "UI3D.fx")); ShaderManager.Add("VS_Model", Resources.GetShader("VS", "VS", "Model.fx")).SetInputLayout(VertexTextureColor.Elements); ShaderManager.Add("PS_Model", Resources.GetShader("PS", "PS", "Model.fx")); ShaderManager.Add("VS_Terrain", Resources.GetShader("VS", "VS", "Terrain.fx")).SetInputLayout(VertexTexture.Elements); ShaderManager.Add("PS_Terrain", Resources.GetShader("PS", "PS", "Terrain.fx")); ShaderManager.Add("VS_Water", Resources.GetShader("VS", "VS", "Water.fx")).SetInputLayout(VertexTexture.Elements); ShaderManager.Add("PS_Water", Resources.GetShader("PS", "PS", "Water.fx")); SceneManager.Initialize(); InputManager.AssignKey("up", new[] { "Z" }); InputManager.AssignKey("down", new[] { "S" }); InputManager.AssignKey("left", new[] { "Q" }); InputManager.AssignKey("right", new[] { "D" }); InputManager.AssignKey("zoom_in", new[] { "Add" }); InputManager.AssignKey("zoom_out", new[] { "Subtract" }); //--------------------------------------------------------------------------------------------------- RawMap mapFile; string mapname = "(2) Germanium Island"; mapFile = RawMap.Load(mapname); ForegroundGame.Map = new TerrainInfo(); ForegroundGame.Map.width = mapFile.Width; ForegroundGame.Map.height = mapFile.Height; ForegroundGame.Map.altitudeData = new float[mapFile.Width, mapFile.Height]; for (int y = 0; y < mapFile.Height; y++) { for (int x = 0; x < mapFile.Width; x++) { float h = mapFile.Data[x + y * mapFile.Width]; ForegroundGame.Map.altitudeData[x, y] = h; if (h > ForegroundGame.Map.maxAltitude) { ForegroundGame.Map.maxAltitude = h; } } } ForegroundGame.Map.accessibilityArray = mapFile.Accessibilty_Array; GlobalConstantVars.SunColor = mapFile.Sun_Color; GlobalConstantVars.SunDirection.X = (float)Math.Sin(mapFile.Sun_Rotation) * (float)Math.Cos(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Y = (float)Math.Sin(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Z = (float)Math.Cos(mapFile.Sun_Rotation) * (float)Math.Cos(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Normalize(); GlobalConstantVars.AmbientColor = new Vector4(mapFile.Ambient_Color, mapFile.Ambient); ForegroundGame.Map.waterColor = new Vector4(mapFile.Water_Color, mapFile.Water_Density); ForegroundGame.Map.waterLevel = mapFile.Water_Level; ForegroundGame.Map.WaterBump = Resources.GetTexture("Maps/Shared/wave"); ForegroundGame.Map.ColorMap = Resources.GetTexture("Maps/" + mapname + "/_colorMap.png", false); ForegroundGame.Map.TextureMap = Resources.GetTexture("Maps/" + mapname + "/_textureMap.png", false); ForegroundGame.Map.Shore = RageEngine.ContentPipeline.Resources.GetTexture("Maps/Shared/shore.jpg"); ForegroundGame.Map.Clouds = RageEngine.ContentPipeline.Resources.GetTexture("Maps/Shared/clouds.jpg"); string[] texturesWithNormal = new string[mapFile.Textures.Length * 2]; for (uint i = 0; i < mapFile.Textures.Length; i++) { texturesWithNormal[i * 2] = "Maps/Shared/" + mapFile.Textures[i]; texturesWithNormal[i * 2 + 1] = "Maps/Shared/" + mapFile.Textures[i] + "_bump"; } ForegroundGame.Map.TextureArray = Resources.GetTextureArray(texturesWithNormal); ForegroundGame.Map.Load(); var Map_Dimensions = new Point3D(ForegroundGame.Map.width, 1000, ForegroundGame.Map.height); var Map_Division = new Point3D(100, 1, 100); BackgroundGame.IntObjsLQDB = new LocalityQueryProximityDatabase <InteractiveObject>(Map_Dimensions, Map_Division); BackgroundGame.MapSpace = new MapSpace(ForegroundGame.Map); terrain = new Terrain(ForegroundGame.Map); SceneManager.Add(terrain); ForegroundGame.TerrainDebug = new TerrainDebug(ForegroundGame.Map); SceneManager.Add(ForegroundGame.TerrainDebug); SceneManager.Add(new TerrainWater(ForegroundGame.Map)); //-------------------------------------------------------------------------------------------------- ForegroundGame.startegicIcons = Resources.GetTexture("Textures/startegicIcon.png", false); ForegroundGame.selectionBrackets = Resources.GetTexture("Textures/selectionBrackets.png", false); ForegroundGame.unitPlaceholder = Resources.GetTexture("Textures/unitplaceholder.png", false); camera = new TopDownCamera(); SceneManager.Camera = camera; uitest = new WebWindow(200, Display.Height, "UI/InGame/index.html"); uitest.position.X = Display.Width - 200; uitest.Bind("GlobalBuildClick", _globalBuildClick); uitest.Bind("BuildClick", _globalBuildClick); InputManager.MouseDown += new Action <MouseInputEventArgs>(Input_MouseDown); InputManager.MouseUp += new Action <MouseInputEventArgs>(Input_MouseUp); InputManager.MouseMove += new Action <MouseInputEventArgs>(Input_MouseMove); InputManager.Wheel += new Action <MouseInputEventArgs>(Input_Wheel); ForegroundGame.IntObjsManager = new InteractiveObject2DManager(); SceneManager.Add(ForegroundGame.IntObjsManager); BlueprintIntObject.Initialize(); //BlueprintProjectile.Initialize("Scripts/Projectiles/"); int column = 0, line = 0; for (int i = 0; i < 200; i++) { if (line > 17) { column++; line = 0; } InteractiveObject obj = BackgroundGame.Scripts_IObjects.Make <InteractiveObject>("Engy", new Type[2] { typeof(InteractiveObject), typeof(BlueprintIntObject) }, null, BlueprintIntObject.Find("Engy")); //new Engy(null,BlueprintIntObject.list); obj.Init(0, new FVector2((fint)(150 + column * 2), (fint)(100 + line * 2)), 0); BackgroundGame.IntObjs.Add(obj); line++; } camera.ZoomLevel = 50; camera.Position = new Vector2(170, 120); Task.Factory.StartNew(UpdateThread, TaskCreationOptions.LongRunning); ForegroundGame.timer.Start(); }
public void Read(string file) { BinaryReader br = new BinaryReader(File.OpenRead(file)); // Header uint paletaOffset = br.ReadUInt32() * 4; uint tileOffset = br.ReadUInt32() * 4; uint mapOffset = br.ReadUInt32() * 4; ColorFormat depth; br.BaseStream.Position = mapOffset; if (br.ReadUInt32() == 0x01) { depth = ColorFormat.colors256; } else { depth = ColorFormat.colors16; } // Palette Color[][] colors; if (paletaOffset == 0x00) // No palette { depth = ColorFormat.colors16; colors = new Color[defaultPaletteData.Length / 0x20][]; for (int i = 0; i < colors.Length; i++) { Byte[] data = new Byte[0x20]; Array.Copy(defaultPaletteData, i * 0x20, data, 0, 0x20); colors[i] = Actions.BGR555ToColor(data); } goto Tile; } br.BaseStream.Position = paletaOffset; uint pCabeceraSize = br.ReadUInt32() * 4; uint pSize = br.ReadUInt32() * 4; if (pSize - 0x08 == 0x0200) { depth = ColorFormat.colors256; } else if (pSize - 0x08 == 0x20) { depth = ColorFormat.colors16; } colors = new Color[depth == ColorFormat.colors16 ? (pSize - 0x08) / 0x20 : 1][]; uint pal_length = (depth == ColorFormat.colors16) ? 0x20 : pSize - 0x08; for (int i = 0; i < colors.Length; i++) { colors[i] = Actions.BGR555ToColor(br.ReadBytes((int)pal_length)); } // Tile data Tile: br.BaseStream.Position = tileOffset; uint tCabeceraSize = br.ReadUInt32() * 4; uint tSize = br.ReadUInt32() * 4; byte[] tiles = br.ReadBytes((int)(tSize - 0x08)); image = new RawImage(tiles, TileForm.Horizontal, depth, 0x40, tiles.Length / 0x40, false, fileName); // Map if (mapOffset == 0x00) { hasMap = false; goto End; } hasMap = true; br.BaseStream.Position = mapOffset; uint mCabeceraSize = br.ReadUInt32() * 4; uint[] mSize = new uint[(int)mCabeceraSize / 4]; for (int i = 0; i < mSize.Length; i++) { mSize[i] = (br.ReadUInt32() * 4) - mCabeceraSize - 4; } maps = new MapBase[mSize.Length]; for (int i = 0; i < maps.Length; i++) { ushort width = (ushort)(br.ReadUInt16() * 8); ushort height = (ushort)(br.ReadUInt16() * 8); NTFS[] map; if (i != 0) { map = new NTFS[((mSize[i] - mSize[i - 1]) - 4) / 2]; } else { map = new NTFS[(mSize[i] - 4) / 2]; } for (int j = 0; j < map.Length; j++) { map[j] = Actions.MapInfo(br.ReadUInt16()); } maps[i] = new RawMap(map, width, height, false, fileName); } End: br.Close(); palette = new RawPalette(colors, false, depth, fileName); }
//{ // {ColorComponent.G, ColorComponent.B}, // {ColorComponent.R,ColorComponent.G} //}; public ColorMap <ushort> Process(RawMap <ushort> map) { var res = new ColorMapUshort(map.Width, map.Height, map.MaxBits + 2); var pix = res.GetPixel(); var file = map.GetPixel(); for (var x = 0; x < res.Width; x++) { pix.MoveNext(); file.MoveNext(); } for (var y = 1; y < res.Height - 1; y++) { pix.MoveNext(); file.MoveNext(); for (var x = 1; x < res.Width - 1; x++) { var component = _componentsMap[(y + 0) % 2, (x + 0) % 2]; var invertRb = ((x % 2) ^ (y % 2)) == 0; switch (component) { case ColorComponent.R: pix[0] = (ushort)(file.Value << 2); pix[1] = (ushort) ((file.GetRel(-1, 0) + file.GetRel(+1, 0) + file.GetRel(0, -1) + file.GetRel(0, +1))); pix[2] = (ushort) ((file.GetRel(-1, -1) + file.GetRel(+1, -1) + file.GetRel(-1, +1) + file.GetRel(+1, +1))); break; case ColorComponent.G: pix[(invertRb) ? 2 : 0] = (ushort)((file.GetRel(-1, 0) + file.GetRel(+1, 0)) << 1); pix[1] = (ushort)(file.Value << 2); pix[(invertRb) ? 0 : 2] = (ushort)((file.GetRel(0, -1) + file.GetRel(0, +1)) << 1); break; case ColorComponent.B: pix[0] = (ushort) ((file.GetRel(-1, -1) + file.GetRel(+1, -1) + file.GetRel(-1, +1) + file.GetRel(+1, +1))); pix[1] = (ushort) ((file.GetRel(-1, 0) + file.GetRel(+1, 0) + file.GetRel(0, -1) + file.GetRel(0, +1))); pix[2] = (ushort)(file.Value << 2); break; } pix.MoveNext(); file.MoveNext(); } pix.MoveNext(); file.MoveNext(); } for (var x = 0; x < res.Width; x++) { pix.MoveNext(); file.MoveNext(); } return(res); }
public void LoadMap(RawMap mapFile) { GlobalConstantVars.SunColor = mapFile.Sun_Color; GlobalConstantVars.SunDirection.X = (float)Math.Sin(mapFile.Sun_Rotation) * (float)Math.Cos(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Y = (float)Math.Sin(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Z = (float)Math.Cos(mapFile.Sun_Rotation) * (float)Math.Cos(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Normalize(); GlobalConstantVars.AmbientColor = new Vector4(mapFile.Ambient_Color, mapFile.Ambient); ForegroundGame.Map = new TerrainInfo(); ForegroundGame.Map.width = mapFile.Width; ForegroundGame.Map.height = mapFile.Height; ForegroundGame.Map.altitudeData = new float[mapFile.Width, mapFile.Height]; for (int y = 0; y < mapFile.Height; y++) { for (int x = 0; x < mapFile.Width; x++) { float h = mapFile.Data[x + y * mapFile.Width]; ForegroundGame.Map.altitudeData[x, y] = h; if (h > ForegroundGame.Map.maxAltitude) { ForegroundGame.Map.maxAltitude = h; } } } ForegroundGame.Map.accessibilityArray = mapFile.Accessibilty_Array; GlobalConstantVars.SunColor = mapFile.Sun_Color; GlobalConstantVars.SunDirection.X = (float)Math.Sin(mapFile.Sun_Rotation) * (float)Math.Cos(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Y = (float)Math.Sin(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Z = (float)Math.Cos(mapFile.Sun_Rotation) * (float)Math.Cos(mapFile.Sun_Height); GlobalConstantVars.SunDirection.Normalize(); GlobalConstantVars.AmbientColor = new Vector4(mapFile.Ambient_Color, mapFile.Ambient); ForegroundGame.Map.waterColor = new Vector4(mapFile.Water_Color, mapFile.Water_Density); ForegroundGame.Map.waterLevel = mapFile.Water_Level; ForegroundGame.Map.WaterBump = Resources.GetTexture("Maps/Shared/wave"); ForegroundGame.Map.ColorMap = Resources.GetTexture("Maps/" + mapFile.MainPath + "/_colorMap.png", false); ForegroundGame.Map.TextureMap = Resources.GetTexture("Maps/" + mapFile.MainPath + "/_textureMap.png", false); ForegroundGame.Map.Shore = RageEngine.ContentPipeline.Resources.GetTexture("Maps/Shared/shore.jpg"); ForegroundGame.Map.Clouds = RageEngine.ContentPipeline.Resources.GetTexture("Maps/Shared/clouds.jpg"); string[] texturesWithNormal = new string[mapFile.Textures.Length * 2]; for (uint i = 0; i < mapFile.Textures.Length; i++) { texturesWithNormal[i * 2] = "Maps/Shared/" + mapFile.Textures[i]; texturesWithNormal[i * 2 + 1] = "Maps/Shared/" + mapFile.Textures[i] + "_bump"; } ForegroundGame.Map.TextureArray = Resources.GetTextureArray(texturesWithNormal); ForegroundGame.Map.Load(); //----------------------------- form.mapName.Text = mapFile.Name; form.mapAuthor.Text = mapFile.Author; form.mapDesc.Text = mapFile.Description; form.waterLevel.Value = (decimal)ForegroundGame.Map.waterLevel; form.waterDensity.Value = (decimal)mapFile.Water_Density * 100; form.AmbientLight.Value = (decimal)(mapFile.Ambient * 100); form.sunHeight.Value = (int)(mapFile.Sun_Height * 90 / GameUtils.PiOver2); form.sunRotation.Value = (int)(mapFile.Sun_Rotation * 180 / GameUtils.Pi); //-------------------------------------------------------------------------------------- modifiedColorMap = modifiedTextureMap = false; //-------------------------------------------------------------------------------------- Texture2DDescription descHM = new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R8G8B8A8_UNorm, Width = ForegroundGame.Map.width, Height = ForegroundGame.Map.height, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, }; drawableTexture = new Texture2D(Display.device, descHM); drawableRenderTarget = new RenderTargetView(Display.device, drawableTexture); Terrain = new EditorTerrain(ForegroundGame.Map); TerrainWater = new TerrainWater(ForegroundGame.Map); ForegroundGame.TerrainDecals = new DecalManager(ForegroundGame.Map); //------------------ ForegroundGame.TerrainDebug = new TerrainDebug(ForegroundGame.Map); SceneManager.Add(Terrain); SceneManager.Add(ForegroundGame.TerrainDebug); SceneManager.Add(ForegroundGame.TerrainDecals); SceneManager.Add(TerrainWater); camera.target = new Vector3(ForegroundGame.Map.width / 2, 0, ForegroundGame.Map.height / 2); ForegroundGame.Map.GetHeight(camera.target, ref camera.target.Y); camera.UpdatePosition(); }
public void AutoAdjust(RawMap<ushort> map, IIAutoAdjustableFilter autoFilter) { ProcessFilters(map, autoFilter); }
public RGB8Map RawMapToRGB(RawMap <ushort> map) { var currentMap = ProcessFilters(map); return((RGB8Map)currentMap); }
private IColorMap ProcessFilters(RawMap<ushort> map, IIAutoAdjustableFilter autoFilter = null) { var indColorFilter = new List<IndependentComponentColorToColorFilter<float, float>>(); var indVectorFilter = new List<IndependentComponentVectorToVectorFilter>(); IColorMap currentMap = map; foreach (var filter in _filters) { #if DEBUG if (currentMap is ColorMapFloat) { var m = currentMap as ColorMapFloat; if (m.Rgb.Any(float.IsNaN)) throw new Exception(); } #endif if (filter == null) throw new ArgumentNullException("filter"); if (filter == autoFilter) { if (filter is IAutoAdjustableFilter<ColorMapFloat>) { if (currentMap is ColorMapUshort) { currentMap = ApplyIndependentColorToFloatFilters((ColorMapUshort)currentMap, indColorFilter); } ((IAutoAdjustableFilter<ColorMapFloat>)autoFilter).AutoAdjust((ColorMapFloat)currentMap); } else if (filter is IAutoAdjustableFilter<VectorMap>) { if (currentMap is ColorMapUshort) { currentMap = ApplyIndependentColorToVectorFilters((ColorMapUshort)currentMap, indVectorFilter); } ((IAutoAdjustableFilter<VectorMap>)autoFilter).AutoAdjust((VectorMap)currentMap); } else throw new NotSupportedException("Not supported AutoAdjust Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); return currentMap; } if (currentMap is RawBGGRMap<ushort>) { if (filter is IRawToColorMap16Filter<RawBGGRMap<ushort>, ushort>) { currentMap = ApplyRawBGGRToColorMapFilter((RawBGGRMap<ushort>)currentMap, (IRawToColorMap16Filter<RawBGGRMap<ushort>, ushort>)filter); } else { throw new NotSupportedException("Not supported Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } } else if (currentMap is ColorMapUshort) { if (filter is IndependentComponentColorToColorFilter<float, float>) { indColorFilter.Add((IndependentComponentColorToColorFilter<float, float>)filter); } else if (filter is IndependentComponentVectorToVectorFilter) { indVectorFilter.Add((IndependentComponentVectorToVectorFilter)filter); } else if (filter is ColorToColorFilter<float, byte>) { currentMap = ApplyIndependentColorFiltersWithRGB((ColorMapUshort)currentMap, indColorFilter, (IndependentComponentColorToColorFilter<float, byte>)filter); } else if (filter is ColorToColorFilter<float, float>) { currentMap = ApplyIndependentColorToFloatFilters((ColorMapUshort)currentMap, indColorFilter); ApplySingleFilterInplace((ColorMap<float>)currentMap, (ColorToColorFilter<float, float>)filter); } else if (filter is VectorToColorFilter<byte>) { currentMap = ApplyIndependentVectorFiltersWithRGB((ColorMapUshort)currentMap, indVectorFilter, (IndependentComponentVectorToColorFilter<byte>)filter); } else if (filter is VectorToVectorFilter) { currentMap = ApplyIndependentColorToVectorFilters((ColorMapUshort)currentMap, indVectorFilter); ApplySingleFilterInplace((VectorMap)currentMap, (VectorToVectorFilter)filter); } else throw new NotSupportedException("Not supported Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } else if (currentMap is ColorMapFloat) { if (filter is ColorToColorFilter<float, float>) { ApplySingleFilterInplace((ColorMapFloat)currentMap, (ColorToColorFilter<float, float>)filter); } else if (filter is ColorToColorFilter<float, byte>) { currentMap = ConvertToRGB((ColorMapFloat)currentMap, (ColorToColorFilter<float, byte>)filter); } else throw new NotSupportedException("Not supported Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } else if (currentMap is VectorMap) { if (filter is VectorToVectorFilter) { ApplySingleFilterInplace((VectorMap)currentMap, (VectorToVectorFilter)filter); } else if (filter is VectorToColorFilter<byte>) { currentMap = ConvertToRGB((VectorMap)currentMap, (VectorToColorFilter<byte>)filter); } else throw new NotSupportedException("Not supported Filter: " + filter.GetType() + " for Map: " + currentMap.GetType()); } else { throw new NotSupportedException("Not supported Map: " + currentMap.GetType()); } } return currentMap; }
public Format Read2(sFile file) { string ext = ""; if (file.size >= 4) { using (BinaryReader br = new BinaryReader(File.OpenRead(file.path))) { ext = new String(Encoding.ASCII.GetChars(br.ReadBytes(4))); br.Close(); } } // Palette if (file.name.ToUpper().EndsWith(".NTFP") || file.name.ToUpper().EndsWith(".PLT")) { RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } else if (ext == "RLCN") { PaletteBase palette = new NCLR(file.path, file.id, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } else if (ext == "NCCL") { NCCL palette = new NCCL(file.path, file.id, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } else if (file.name.ToUpper().EndsWith(".NBFP")) { RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } else if (file.name.ToUpper().EndsWith(".NCL.L") && ext[0] != '\x10') { RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } // Tile ColorFormat depth = ColorFormat.colors256; if (pluginHost.Get_Palette().Loaded) { depth = pluginHost.Get_Palette().Depth; } if (file.name.ToUpper().EndsWith(".NTFT")) { RawImage image = new RawImage(file.path, file.id, TileForm.Lineal, depth, true, 0, -1, file.name); pluginHost.Set_Image(image); return(Format.Tile); } else if (ext == "RGCN" || ext == "RBCN") { NCGR ncgr = new NCGR(file.path, file.id, file.name); pluginHost.Set_Image(ncgr); return(Format.Tile); } else if (ext == "NCCG") { NCCG image = new NCCG(file.path, file.id, file.name); pluginHost.Set_Image(image); return(Format.Tile); } else if (file.name.ToUpper().EndsWith(".NBFC") || file.name.ToUpper().EndsWith(".CHAR")) { RawImage image = new RawImage(file.path, file.id, TileForm.Horizontal, depth, true, 0, -1, file.name); pluginHost.Set_Image(image); return(Format.Tile); } else if (file.name.ToUpper().EndsWith(".NCG.L") && ext[0] != '\x10') { RawImage image = new RawImage(file.path, file.id, TileForm.Horizontal, depth, true, 0, -1, file.name); pluginHost.Set_Image(image); return(Format.Tile); } // Map if (file.name.ToUpper().EndsWith(".NBFS")) { RawMap map = new RawMap(file.path, file.id, 0, -1, true, file.name); pluginHost.Set_Map(map); return(Format.Map); } else if (ext == "RCSN") { NSCR nscr = new NSCR(file.path, file.id, file.name); pluginHost.Set_Map(nscr); return(Format.Map); } else if (ext == "NCSC") { NCSC map = new NCSC(file.path, file.id, file.name); pluginHost.Set_Map(map); return(Format.Map); } else if (file.name.ToUpper().EndsWith(".NSC.L") && ext[0] != '\x10') { RawMap map = new RawMap(file.path, file.id, 0, -1, true, file.name); pluginHost.Set_Map(map); return(Format.Map); } // Sprite if (ext == "NCOB") { NCOB sprite = new NCOB(file.path, file.id, file.name); pluginHost.Set_Sprite(sprite); pluginHost.Set_Image(sprite.Image); return(Format.Cell); } else if (ext == "RECN") { NCER ncer = new NCER(file.path, file.id, file.name); pluginHost.Set_Sprite(ncer); return(Format.Cell); } // Animation if (ext == "RNAN") { nanr = new NANR(pluginHost, file.path, file.id); return(Format.Animation); } return(Format.Unknown); }
public RGB8Map RawMapToRGB(RawMap<ushort> map) { var currentMap = ProcessFilters(map); return (RGB8Map)currentMap; }
// TODO: I really want DataContractJsonSerializer for WebGL private static void RawMapToMap(RawMap raw, out Map map) { map = new Map(); map.name = raw.name; map.width = raw.width; map.height = raw.height; map.walkers = new Walker[] { raw.walker }; map.fields = new int[raw.floors][]; // TODO: reflection { int[] floor = new int[raw.fields0.Length]; for (int i = 0; i < raw.fields0.Length; i++) { floor[i] = raw.fields0[i]; } map.fields[0] = floor; } { int[] floor = new int[raw.fields1.Length]; for (int i = 0; i < raw.fields1.Length; i++) { floor[i] = raw.fields1[i]; } map.fields[1] = floor; } { int[] floor = new int[raw.fields2.Length]; for (int i = 0; i < raw.fields2.Length; i++) { floor[i] = raw.fields2[i]; } map.fields[2] = floor; } map.terrains = new int[raw.floors][]; { int[] floor = new int[raw.terrains0.Length]; for (int i = 0; i < raw.terrains0.Length; i++) { floor[i] = raw.terrains0[i]; } map.terrains[0] = floor; } { int[] floor = new int[raw.terrains1.Length]; for (int i = 0; i < raw.terrains1.Length; i++) { floor[i] = raw.terrains1[i]; } map.terrains[1] = floor; } { int[] floor = new int[raw.terrains2.Length]; for (int i = 0; i < raw.terrains2.Length; i++) { floor[i] = raw.terrains2[i]; } map.terrains[2] = floor; } map.verticalFields = new int[raw.floors][][]; { int[][] floor = new int[raw.verticalFields0.Length][]; for (int i = 0; i < raw.verticalFields0.Length; i++) { string square = raw.verticalFields0[i]; string[] aspectStrs = square.Split(','); int[] aspects = new int[aspectStrs.Length]; for (int j = 0; j < aspectStrs.Length; j++) { if (aspectStrs[j] == "") { break; } aspects[j] = Int32.Parse(aspectStrs[j]); } floor[i] = aspects; } map.verticalFields[0] = floor; } { int[][] floor = new int[raw.verticalFields1.Length][]; for (int i = 0; i < raw.verticalFields1.Length; i++) { string square = raw.verticalFields1[i]; string[] aspectStrs = square.Split(','); int[] aspects = new int[aspectStrs.Length]; for (int j = 0; j < aspectStrs.Length; j++) { if (aspectStrs[j] == "") { break; } aspects[j] = Int32.Parse(aspectStrs[j]); } floor[i] = aspects; } map.verticalFields[1] = floor; } { int[][] floor = new int[raw.verticalFields2.Length][]; for (int i = 0; i < raw.verticalFields2.Length; i++) { string square = raw.verticalFields2[i]; string[] aspectStrs = square.Split(','); int[] aspects = new int[aspectStrs.Length]; for (int j = 0; j < aspectStrs.Length; j++) { if (aspectStrs[j] == "") { break; } aspects[j] = Int32.Parse(aspectStrs[j]); } floor[i] = aspects; } map.verticalFields[2] = floor; } }
public void AutoAdjust(RawMap <ushort> map, IIAutoAdjustableFilter autoFilter) { ProcessFilters(map, autoFilter); }