added benchmark function
added .txt for benchmark results fixed generating level message
This commit is contained in:
@@ -3,4 +3,7 @@
|
|||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="benchmark.txt" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -22,8 +22,6 @@ public class Level {
|
|||||||
private float rainAmount = 0;
|
private float rainAmount = 0;
|
||||||
|
|
||||||
public Level(Main main, int sizeX, int sizeY) {
|
public Level(Main main, int sizeX, int sizeY) {
|
||||||
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksX*chunksY} chunks ({chunkResX} * {chunkResY})");
|
|
||||||
|
|
||||||
Resolution = new Vector2I(sizeX, sizeY);
|
Resolution = new Vector2I(sizeX, sizeY);
|
||||||
chunksX = main.ChunksPerAxis;
|
chunksX = main.ChunksPerAxis;
|
||||||
chunksY = main.ChunksPerAxis;
|
chunksY = main.ChunksPerAxis;
|
||||||
@@ -31,6 +29,8 @@ public class Level {
|
|||||||
chunkResX = sizeX / chunksX;
|
chunkResX = sizeX / chunksX;
|
||||||
chunkResY = sizeY / chunksY;
|
chunkResY = sizeY / chunksY;
|
||||||
|
|
||||||
|
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksX*chunksY} chunks ({chunkResX} * {chunkResY})");
|
||||||
|
|
||||||
image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8);
|
image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8);
|
||||||
|
|
||||||
chunks = new Chunk[chunksX, chunksY];
|
chunks = new Chunk[chunksX, chunksY];
|
||||||
@@ -66,6 +66,15 @@ public class Level {
|
|||||||
rainAmount = amount;
|
rainAmount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void StartBenchmark() {
|
||||||
|
GD.Print("benchmark");
|
||||||
|
for (int x = 0; x < chunksX; x++) {
|
||||||
|
for (int y = 0; y < chunksY; y++) {
|
||||||
|
chunks[x, y].WritePixel<Dirt>(chunkResX/2, chunkResY/2, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void MakeItRain() {
|
private void MakeItRain() {
|
||||||
if (rainAmount < .1f) return;
|
if (rainAmount < .1f) return;
|
||||||
|
|
||||||
@@ -87,6 +96,7 @@ public class Level {
|
|||||||
|
|
||||||
for (int x = 0; x < chunkResX; x++) {
|
for (int x = 0; x < chunkResX; x++) {
|
||||||
for (int y = 0; y < chunkResY; y++) {
|
for (int y = 0; y < chunkResY; y++) {
|
||||||
|
// TODO: multithreading here! use Chunk.DrawLevel() and stitch images together
|
||||||
image.SetPixel(cx*chunkResX + x, cy*chunkResY + y, chunks[cx,cy].Elements[x, y].Color);
|
image.SetPixel(cx*chunkResX + x, cy*chunkResY + y, chunks[cx,cy].Elements[x, y].Color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ public partial class Main : Node2D {
|
|||||||
|
|
||||||
mLevel.WritePixel<Dirt>((int)mappedX, (int)mappedY, BrushSize);
|
mLevel.WritePixel<Dirt>((int)mappedX, (int)mappedY, BrushSize);
|
||||||
}
|
}
|
||||||
} else base._UnhandledInput(@event);
|
} else if (@event is InputEventKey keyEvent && keyEvent.Pressed) {
|
||||||
|
if (keyEvent.Keycode == Key.F9)
|
||||||
|
mLevel.StartBenchmark();
|
||||||
|
}
|
||||||
|
else base._UnhandledInput(@event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
benchmark.txt
Normal file
15
benchmark.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Benchmark
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
- Texture Resolution: 0.5
|
||||||
|
- CHunks per Axis: 2
|
||||||
|
- Rain Amount: 0
|
||||||
|
|
||||||
|
## Measurements:
|
||||||
|
### original (no optimization):
|
||||||
|
- idle: 42 - 44 fps
|
||||||
|
- benchmark: 24 fps minimum
|
||||||
|
|
||||||
|
### only active:
|
||||||
|
- idle: 100 fps
|
||||||
|
- benchmark: 36 fps minimum
|
||||||
Reference in New Issue
Block a user