protected override void ReadData(BinaryReader reader) { string name = reader.ReadString(); int size = reader.ReadInt32(); float resolution = reader.ReadSingle(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); float[,] map = new float[width, height]; for (int z = 0; z < height; z++) { for (int x = 0; x < width; x++) { map[x, z] = reader.ReadSingle(); } } this.Map = new PlayfieldMap(); this.Map.Name = name; this.Map.SizeClass = size; this.Map.Resolution = resolution; this.Map.HeightMap = map; }
public PlayfieldMapRender(PlayfieldMap map, PlayfieldData data, ImageRenderer renderer) { this.Map = map; this.Data = data; this.Renderer = renderer; }
public PlayfieldMapRender(PlayfieldMap map, PlayfieldData data) : this(map) { this.Data = data; }
public PlayfieldMapRender(PlayfieldMap map) : this() { this.Map = map; }
public PlayfieldMapPacket(PlayfieldMap map) : this() { this.Map = map; }
private void MapPlayfield() { try { Log.Info($"Mapping playfield {this.Playfield?.Name}."); PlayfieldMap map = new PlayfieldMap(); map.Name = this.Playfield.Name; map.Resolution = this.MapResolution; // Probe playfield size by examining entity positions. Log.Info($"Calculating size of {this.Playfield.Name} using entity positions."); float xmin = float.MaxValue, xmax = float.MinValue, zmin = float.MaxValue, zmax = float.MinValue; if (this.Playfield?.Entities?.Values == null) { Log.Warn($"Playfield {this.Playfield.Name} has null entities. Cannot determine map size."); return; } foreach (IEntity entity in this.Playfield?.Entities?.Values) { if (entity == null) { continue; } xmin = Math.Min(xmin, entity.Position.x); xmax = Math.Max(xmax, entity.Position.x); zmin = Math.Min(zmin, entity.Position.z); zmax = Math.Max(zmax, entity.Position.z); } int xBounds = (int)Math.Max(Math.Abs(xmin), Math.Abs(xmax)); int zBounds = (int)Math.Max(Math.Abs(zmin), Math.Abs(zmax)); xBounds = (xBounds > 16000) ? 32000 : (xBounds > 8000) ? 16000 : (xBounds > 4000) ? 8000 : (xBounds > 2000) ? 4000 : 2000; zBounds = (zBounds > 8000) ? 16000 : (zBounds > 4000) ? 8000 : (zBounds > 2000) ? 4000 : (zBounds > 1000) ? 2000 : 1000; this.SizeClass = (int)Math.Log(xBounds / 1000, 2); Log.Info($"Playfield {this.Playfield.Name} is size class {this.SizeClass} and has bounds X: {xBounds}, Z: {zBounds}."); int dataWidth = (int)(xBounds * 2 / map.Resolution); int dataHeight = (int)(zBounds * 2 / map.Resolution); float[,] data = new float[dataWidth, dataHeight]; float pfz; // z-coordinate translated to playfield coordinates. Avoid recalculating it for every x-coordinate. for (int z = 0; z < dataHeight; z++) { pfz = (z * map.Resolution) - zBounds; for (int x = 0; x < dataWidth; x++) { data[x, z] = this.Playfield.GetTerrainHeightAt((x * map.Resolution) - xBounds, pfz) / map.Resolution; } } map.HeightMap = data; this.PlayfieldMap = map; Log.Info($"Mapping of {this.Playfield.Name} is complete. With resolution {map.Resolution}, map is ({dataWidth}, {dataHeight})."); if (this.notifyWhenMapReady != null) { foreach (Action <PlayfieldMap> action in this.notifyWhenMapReady) { action(map); } } this.notifyWhenMapReady = null; } catch (Exception ex) { Log.Warn($"Failed to map {this.Playfield.Name}. Reason: {ex.Message}"); throw; } }