diff --git a/SpriteFontPlus/src/obj/Debug/net45/.NETFramework,Version=v4.5.AssemblyAttributes.cs b/SpriteFontPlus/src/obj/Debug/net45/.NETFramework,Version=v4.5.AssemblyAttributes.cs --- a/SpriteFontPlus/src/obj/Debug/net45/.NETFramework,Version=v4.5.AssemblyAttributes.cs +++ b/SpriteFontPlus/src/obj/Debug/net45/.NETFramework,Version=v4.5.AssemblyAttributes.cs @@ -1,4 +1,4 @@ // using System; using System.Reflection; -[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")] +// [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")] diff --git a/isometric-park-fna/CellMap.cs b/isometric-park-fna/CellMap.cs --- a/isometric-park-fna/CellMap.cs +++ b/isometric-park-fna/CellMap.cs @@ -164,6 +164,45 @@ yield return this.cells[x - 1][y+1]; } } + + public System.Collections.Generic.IEnumerable<(int, int)> iterate_neighbor_cell_locations(int x, int y) + + { + //iterates over neighbors (clockwise starting at noon/midnight) + if (inBounds(x, y + 1)) + { + yield return (x - 1, y); + } + if (inBounds(x + 1, y + 1)) + { + yield return (x + 1, y + 1); + } + if (inBounds(x + 1, y)) + { + yield return (x + 1, y); + } + if (inBounds(x + 1, y - 1)) + { + yield return (x + 1, y - 1); + } + if (inBounds(x, y - 1)) + { + yield return (x, y - 1); + } + if (inBounds(x - 1, y-1)) + { + yield return (x - 1, y-1); + } + if (inBounds(x - 1, y)) + { + yield return (x - 1, y); + } + if (inBounds(x - 1, y + 1)) + { + yield return (x - 1, y+1); + } + } + public System.Collections.Generic.IEnumerable iterate_neighbors(int x, int y) { diff --git a/isometric-park-fna/Engines/SimulationBridgeEngine.cs b/isometric-park-fna/Engines/SimulationBridgeEngine.cs --- a/isometric-park-fna/Engines/SimulationBridgeEngine.cs +++ b/isometric-park-fna/Engines/SimulationBridgeEngine.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Collections.Generic; @@ -72,28 +73,6 @@ // this.simulation.PreserveCells.Clear(); - var preserve_cells = new HashSet(); - var count = 0; - - foreach (ref readonly var entity in ReadEntities()) { - ref readonly var areaComponent = ref GetComponent(entity); - - foreach (var square in areaComponent.squares) { - preserve_cells.Add(this.simulation.map.cells[(int)square.X][(int)square.Y]); - } - } - - for (int i = 0; i < this.simulation.PreserveCounts.GetLength(0); i++) { - for (int j = 0; j < this.simulation.PreserveCounts.GetLength(0); j++) { - count = 0; - foreach (var cell in this.simulation.map.iterate_neighbor_cells(i, j)) { - if (preserve_cells.Contains(cell)) { - count++; - } - } - this.simulation.PreserveCounts[i, j] = count; - } - } foreach (ref readonly var entity in ReadEntities()) { @@ -133,6 +112,62 @@ } for (int i = ticksToSend; i > 0; i--) { + +#region calculate_preserve_cells + var preserve_cells = new HashSet(); + var preserve_cell_coordinates = new HashSet<(int, int)>(); + var count = 0; + + Stopwatch iterPreserves = new Stopwatch(); + iterPreserves.Start(); + + foreach (ref readonly var entity in ReadEntities()) { + ref readonly var areaComponent = ref GetComponent(entity); + + foreach (var square in areaComponent.squares) { + preserve_cells.Add(this.simulation.map.cells[(int)square.X][(int)square.Y]); + preserve_cell_coordinates.Add(((int)square.X, (int)square.Y)); + } + } + iterPreserves.Stop(); + Logging.Info(String.Format("Preserve entities: {0:F3}", iterPreserves.Elapsed.TotalMilliseconds.ToString())); + + + Stopwatch iterCells = new Stopwatch(); + iterCells.Start(); + + //This takes about 30ms versus the .0002 ms with no preserve. + //When the map is filled up with preserve, about 35ms and 9ms. + //With a handful of cells, it's more like 0.8ms + /* + for (int j = 0; j < this.simulation.PreserveCounts.GetLength(0); j++) { + for (int k = 0; k < this.simulation.PreserveCounts.GetLength(0); k++) { + count = 0; + foreach (var cell in this.simulation.map.iterate_neighbor_cells(j, k)) { + if (preserve_cells.Contains(cell)) { + count++; + } + } + this.simulation.PreserveCounts[j, k] = count; + } + } + //*/ + + //* + foreach ((var x, var y) in preserve_cell_coordinates) { + foreach ((var newx, var newy) in this.simulation.map.iterate_neighbor_cell_locations(x, y)) { + + this.simulation.PreserveCounts[newx, newy] += 1; + } + + } + //*/ + + + iterCells.Stop(); + Logging.Info(String.Format("Cell loop: {0:F3}", iterCells.Elapsed.TotalMilliseconds.ToString())); + +#endregion SendMessage(new TickMessage { SimulationDateTime = simulation.DateTime }); //For now: SendMessage(new SpawnContractMessage