Compare commits
2 Commits
5045b4421e
...
7f31c8c3d5
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f31c8c3d5 | |||
| 882a12862e |
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Godot.NET.Sdk/4.3.0">
|
||||
<Project Sdk="Godot.NET.Sdk/4.4.1">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
1
Scenes/FPSLabel.cs.uid
Normal file
1
Scenes/FPSLabel.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d3cbk8f7lckbr
|
||||
1
Scenes/PerfDetails.cs.uid
Normal file
1
Scenes/PerfDetails.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://52grhydeyy0t
|
||||
1
Scenes/SettingsController.cs.uid
Normal file
1
Scenes/SettingsController.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dxmkbb5f1t368
|
||||
@@ -1,14 +1,15 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cf34vk5r055dx"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Main.cs" id="1_k1i8e"]
|
||||
[ext_resource type="Script" path="res://Scenes/FPSLabel.cs" id="2_8cb7y"]
|
||||
[ext_resource type="Script" path="res://Scenes/SettingsController.cs" id="3_a4w6m"]
|
||||
[ext_resource type="Script" path="res://Scenes/PerfDetails.cs" id="3_u2p48"]
|
||||
[ext_resource type="Script" uid="uid://cmvvubxfvdca7" path="res://Scripts/Main.cs" id="1_k1i8e"]
|
||||
[ext_resource type="Script" uid="uid://d3cbk8f7lckbr" path="res://Scenes/FPSLabel.cs" id="2_8cb7y"]
|
||||
[ext_resource type="Script" uid="uid://dxmkbb5f1t368" path="res://Scenes/SettingsController.cs" id="3_a4w6m"]
|
||||
[ext_resource type="Script" uid="uid://52grhydeyy0t" path="res://Scenes/PerfDetails.cs" id="3_u2p48"]
|
||||
|
||||
[node name="Main" type="Node2D"]
|
||||
script = ExtResource("1_k1i8e")
|
||||
DebugVisualization = true
|
||||
BrushSize = 2
|
||||
RainAmount = 1.0
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
|
||||
@@ -67,29 +67,23 @@ public class Chunk {
|
||||
else RemoveFromChunk(e);
|
||||
}
|
||||
|
||||
public void WritePixel<T>(int x, int y, int size) {
|
||||
int halfsize = size/2;
|
||||
public void WritePixel<T>(int x, int y) {
|
||||
if (x < 0 || x >= sizeX || y < 0 || y >= sizeY) {
|
||||
GD.PrintErr($"Out of bounds for chunk: {x}:{y}");
|
||||
return;
|
||||
}
|
||||
|
||||
Type type = typeof(T);
|
||||
object o = Activator.CreateInstance(type, x, y, this);
|
||||
|
||||
for (int i = -halfsize; i <= halfsize; i++) {
|
||||
for (int j = -halfsize; j <= halfsize; j++) {
|
||||
int X = Mathf.Clamp(x + i, 0, sizeX-1);
|
||||
int Y = Mathf.Clamp(y + j, 0, sizeY-1);
|
||||
object o = Activator.CreateInstance(type, X, Y, this);
|
||||
|
||||
// check if not empty:
|
||||
if (Elements[X,Y].GetType() != typeof(Element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (Elements[X,Y].GetType() != type) {
|
||||
Elements[X, Y].Chunk.RemoveFromChunk(Elements[X, Y]);
|
||||
Elements[X, Y] = o as Element;
|
||||
Elements[X, Y].Active = true;
|
||||
// }
|
||||
}
|
||||
// check if not empty:
|
||||
if (Elements[x,y].GetType() != typeof(Element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Elements[x, y].Chunk.RemoveFromChunk(Elements[x, y]);
|
||||
Elements[x, y] = o as Element;
|
||||
Elements[x, y].Active = true;
|
||||
}
|
||||
|
||||
public int ActiveElementsCount() {
|
||||
|
||||
1
Scripts/Chunk.cs.uid
Normal file
1
Scripts/Chunk.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://r17upkbkmfiy
|
||||
1
Scripts/Elements/Dirt.cs.uid
Normal file
1
Scripts/Elements/Dirt.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://80esqy0cardd
|
||||
1
Scripts/Elements/Element.cs.uid
Normal file
1
Scripts/Elements/Element.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b5lme1c4rx15n
|
||||
1
Scripts/Elements/Liquid.cs.uid
Normal file
1
Scripts/Elements/Liquid.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bqx36wisy7127
|
||||
1
Scripts/Elements/Solid.cs.uid
Normal file
1
Scripts/Elements/Solid.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ur56t06r7n4l
|
||||
1
Scripts/Elements/Water.cs.uid
Normal file
1
Scripts/Elements/Water.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://k8id5egjc7x8
|
||||
@@ -11,8 +11,8 @@ public class Level {
|
||||
private Chunk[,] chunks;
|
||||
private Image image;
|
||||
|
||||
private int chunksX;
|
||||
private int chunksY;
|
||||
private int chunksPerX;
|
||||
private int chunksPerY;
|
||||
|
||||
// per chunk:
|
||||
private int chunkResX;
|
||||
@@ -22,34 +22,34 @@ public class Level {
|
||||
|
||||
public Level(Main main, int sizeX, int sizeY) {
|
||||
Resolution = new Vector2I(sizeX, sizeY);
|
||||
chunksX = main.ChunksPerAxis;
|
||||
chunksY = main.ChunksPerAxis;
|
||||
chunksPerX = main.ChunksPerAxis;
|
||||
chunksPerY = main.ChunksPerAxis;
|
||||
|
||||
chunkResX = sizeX / chunksX;
|
||||
chunkResY = sizeY / chunksY;
|
||||
chunkResX = sizeX / chunksPerX;
|
||||
chunkResY = sizeY / chunksPerY;
|
||||
|
||||
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksX*chunksY} chunks ({chunkResX} * {chunkResY})");
|
||||
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksPerX*chunksPerY} chunks ({chunkResX} * {chunkResY})");
|
||||
|
||||
image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8);
|
||||
|
||||
chunks = new Chunk[chunksX, chunksY];
|
||||
chunks = new Chunk[chunksPerX, chunksPerY];
|
||||
int index = 0;
|
||||
// create all chunks
|
||||
for (int x = 0; x < chunksX; x++) {
|
||||
for (int y = 0; y < chunksY; y++) {
|
||||
for (int x = 0; x < chunksPerX; x++) {
|
||||
for (int y = 0; y < chunksPerY; y++) {
|
||||
chunks[x, y] = new Chunk(chunkResX, chunkResY, index++);
|
||||
}
|
||||
}
|
||||
|
||||
// assign neighbors
|
||||
for (int x = 0; x < chunksX; x++) {
|
||||
for (int y = 0; y < chunksY; y++) {
|
||||
for (int x = 0; x < chunksPerX; x++) {
|
||||
for (int y = 0; y < chunksPerY; y++) {
|
||||
|
||||
if (y > 0) chunks[x, y].NeighborN = chunks[x, y-1];
|
||||
if (y < chunksY-1) chunks[x, y].NeighborS = chunks[x, y+1];
|
||||
if (y < chunksPerY-1) chunks[x, y].NeighborS = chunks[x, y+1];
|
||||
|
||||
if (x > 0) chunks[x, y].NeighborE = chunks[x-1, y];
|
||||
if (x < chunksX-1) chunks[x, y].NeighborW = chunks[x+1, y];
|
||||
if (x < chunksPerX-1) chunks[x, y].NeighborW = chunks[x+1, y];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,9 +67,9 @@ public class Level {
|
||||
|
||||
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);
|
||||
for (int x = 0; x < chunksPerX; x++) {
|
||||
for (int y = 0; y < chunksPerY; y++) {
|
||||
WritePixel<Dirt>(x * chunkResX/2, y * chunkResY/2, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,17 +85,66 @@ public class Level {
|
||||
|
||||
for (int i = 0; i <= rainDrops; i++) {
|
||||
if (GD.Randf() < rainAmount)
|
||||
WritePixel<Water>((int)(GD.Randi() % (chunkResX * chunksX)), 0, 1);
|
||||
WritePixel<Water>((int)(GD.Randi() % (chunkResX * chunksPerX)), 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void WritePixel<T>(int x, int y, int size) {
|
||||
chunks[x/chunkResX, y/chunkResY].WritePixel<T>(x % chunkResX, y % chunkResY, size);
|
||||
int halfsize = size/2;
|
||||
|
||||
for (int i = -halfsize; i <= halfsize; i++) {
|
||||
for (int j = 0; j < 1; j++) {
|
||||
// for (int j = -halfsize; j <= halfsize; j++) {
|
||||
// calculate in-chunk coordinates
|
||||
int inChunkX = x % chunkResX;
|
||||
int inChunkY = y % chunkResY;
|
||||
int brushX = i;
|
||||
int brushY = j;
|
||||
|
||||
// calculate chunk to write to
|
||||
int chunkX = x/chunkResX;
|
||||
if (inChunkX + i < 0) {
|
||||
chunkX--;
|
||||
// 320 -22
|
||||
brushX = chunkResX + inChunkX + i;
|
||||
inChunkX = chunkResX - inChunkX;
|
||||
} else if (inChunkX + i >= chunkResX) {
|
||||
chunkX++;
|
||||
inChunkX = 0;
|
||||
brushX = i % chunkResX;
|
||||
}
|
||||
inChunkX += brushX;
|
||||
|
||||
if (chunkX < 0 || chunkX >= chunksPerX) {
|
||||
GD.PrintErr($"Trying to write out of bounds: {x}:{y}");
|
||||
return;
|
||||
}
|
||||
|
||||
int chunkY = y/chunkResY;
|
||||
if (inChunkY + j < 0) {
|
||||
chunkY--;
|
||||
brushY = chunkResY - (inChunkY + j);
|
||||
inChunkY = chunkResY - inChunkY;
|
||||
} else if (inChunkY + j >= chunkResY) {
|
||||
chunkY++;
|
||||
inChunkY = 0;
|
||||
brushY = j % chunkResY;
|
||||
}
|
||||
inChunkY += brushY;
|
||||
|
||||
if (chunkY < 0 || chunkY >= chunksPerY) {
|
||||
GD.PrintErr($"Trying to write out of bounds: {x}:{y}");
|
||||
return;
|
||||
}
|
||||
|
||||
chunks[chunkX, chunkY].WritePixel<T>(inChunkX, inChunkY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Image DrawLevel() {
|
||||
for (int cx = 0; cx < chunksX; cx++) {
|
||||
for (int cy = 0; cy < chunksY; cy++) {
|
||||
for (int cx = 0; cx < chunksPerX; cx++) {
|
||||
for (int cy = 0; cy < chunksPerY; cy++) {
|
||||
|
||||
for (int x = 0; x < chunkResX; x++) {
|
||||
for (int y = 0; y < chunkResY; y++) {
|
||||
|
||||
1
Scripts/Level.cs.uid
Normal file
1
Scripts/Level.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bkwbjagt8s01s
|
||||
@@ -26,8 +26,12 @@ public partial class Main : Node2D {
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void _Process(double delta) {
|
||||
public override void _PhysicsProcess(double delta) {
|
||||
base._PhysicsProcess(delta);
|
||||
Level.Update();
|
||||
}
|
||||
|
||||
public override void _Process(double delta) {
|
||||
mLevelDrawer.Texture = ImageTexture.CreateFromImage(Level.DrawLevel());
|
||||
}
|
||||
|
||||
|
||||
1
Scripts/Main.cs.uid
Normal file
1
Scripts/Main.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cmvvubxfvdca7
|
||||
@@ -1,15 +1,22 @@
|
||||
# Benchmark
|
||||
# Benchmark
|
||||
|
||||
Start from editor not rider!
|
||||
|
||||
## 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
|
||||
### performance-improvements (71db6513f22094e7dd67bd32c7ab86b326f9ad9e)
|
||||
|
||||
- idle before: 89
|
||||
- benchmark: 33
|
||||
- idle after: 75
|
||||
|
||||
@@ -12,7 +12,7 @@ config_version=5
|
||||
|
||||
config/name="FOU"
|
||||
run/main_scene="res://Scenes/main.tscn"
|
||||
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
|
||||
config/features=PackedStringArray("4.4", "C#", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[dotnet]
|
||||
|
||||
Reference in New Issue
Block a user