Compare commits
23 Commits
5045b4421e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f324122874 | |||
| f932ae1bcd | |||
| c41cdd57c4 | |||
| e653f23a42 | |||
| 6acccefa0a | |||
| 28ada065a6 | |||
| ea34b8ecc0 | |||
| 4462573267 | |||
| 0b97027e00 | |||
| d9bde10c3c | |||
| 2e4fc22263 | |||
| 202e71d97e | |||
| a119e92bf6 | |||
| da3afd22fc | |||
| abf948a310 | |||
| 2cd6a757dc | |||
| 4ce265e722 | |||
| 572e02956c | |||
| de99d54ad6 | |||
| 2bcdeecb81 | |||
| 7f31c8c3d5 | |||
| 882a12862e | |||
| 7b2845ee01 |
@@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Godot.NET.Sdk/4.3.0">
|
<Project Sdk="Godot.NET.Sdk/4.5.1">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
12
FOU.csproj.old.1
Normal file
12
FOU.csproj.old.1
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Godot.NET.Sdk/4.4.1">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="benchmark.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="UI\" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
1
Scenes/FPSLabel.cs.uid
Normal file
1
Scenes/FPSLabel.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://d3cbk8f7lckbr
|
||||||
@@ -3,13 +3,10 @@ using Godot;
|
|||||||
|
|
||||||
public partial class PerfDetails : Label
|
public partial class PerfDetails : Label
|
||||||
{
|
{
|
||||||
[Export]
|
|
||||||
public bool ShowDetails = true;
|
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
Text = "";
|
Text = "";
|
||||||
if (!ShowDetails) return;
|
if (!Main.Instance.DebugMode) return;
|
||||||
|
|
||||||
int activeElements = 0;
|
int activeElements = 0;
|
||||||
foreach (Chunk c in Main.Instance.Level.GetChunks())
|
foreach (Chunk c in Main.Instance.Level.GetChunks())
|
||||||
|
|||||||
1
Scenes/PerfDetails.cs.uid
Normal file
1
Scenes/PerfDetails.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://52grhydeyy0t
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Reflection;
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
public partial class SettingsController : VBoxContainer
|
public partial class SettingsController : VBoxContainer
|
||||||
@@ -18,7 +17,7 @@ public partial class SettingsController : VBoxContainer
|
|||||||
slSize.Value = main.BrushSize;
|
slSize.Value = main.BrushSize;
|
||||||
|
|
||||||
slRain.ValueChanged += OnRainValueChanged;
|
slRain.ValueChanged += OnRainValueChanged;
|
||||||
slRain.Value = main.RainAmount;
|
slRain.Value = main.rainAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSizeValueChanged(double value) {
|
private void OnSizeValueChanged(double value) {
|
||||||
|
|||||||
1
Scenes/SettingsController.cs.uid
Normal file
1
Scenes/SettingsController.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dxmkbb5f1t368
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://cf34vk5r055dx"]
|
[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" uid="uid://cmvvubxfvdca7" path="res://Scripts/Main.cs" id="1_k1i8e"]
|
||||||
[ext_resource type="Script" path="res://Scenes/FPSLabel.cs" id="2_8cb7y"]
|
[ext_resource type="Script" uid="uid://d3cbk8f7lckbr" path="res://Scenes/FPSLabel.cs" id="2_8cb7y"]
|
||||||
[ext_resource type="Script" path="res://Scenes/SettingsController.cs" id="3_a4w6m"]
|
[ext_resource type="Script" uid="uid://dxmkbb5f1t368" 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://52grhydeyy0t" path="res://Scenes/PerfDetails.cs" id="3_u2p48"]
|
||||||
|
|
||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Node2D"]
|
||||||
script = ExtResource("1_k1i8e")
|
script = ExtResource("1_k1i8e")
|
||||||
DebugVisualization = true
|
DebugMode = true
|
||||||
BrushSize = 2
|
BrushSize = 4
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
@@ -84,6 +84,13 @@ custom_minimum_size = Vector2(150, 0)
|
|||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 8
|
size_flags_horizontal = 8
|
||||||
size_flags_vertical = 1
|
size_flags_vertical = 1
|
||||||
max_value = 5.0
|
max_value = 10.0
|
||||||
step = 0.01
|
step = 0.01
|
||||||
value = 1.0
|
value = 1.0
|
||||||
|
|
||||||
|
[node name="ToolbarMarginContainer2" parent="CanvasLayer/TopUI" instance=ExtResource("5_kry3j")]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_left = 860.0
|
||||||
|
offset_top = 5.0
|
||||||
|
offset_right = 1060.0
|
||||||
|
offset_bottom = 69.0
|
||||||
|
|||||||
@@ -54,42 +54,36 @@ public class Chunk {
|
|||||||
if (toAddElements.Count > 0) {
|
if (toAddElements.Count > 0) {
|
||||||
foreach (Element addElement in toAddElements) {
|
foreach (Element addElement in toAddElements) {
|
||||||
activeElements.Add(addElement);
|
activeElements.Add(addElement);
|
||||||
addElement.SetDebugColor(Colors.Green);
|
addElement.SetDebugColor(addElement.Color * 1.5f);
|
||||||
}
|
}
|
||||||
toAddElements.Clear();
|
toAddElements.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetElementActive(Element e, bool active) {
|
public void SetElementActive(Element e, bool active) {
|
||||||
if (e.GetType() == typeof(Element) && active) return;
|
if (e.GetType() == typeof(Element)) return;
|
||||||
|
|
||||||
if (active) AddToChunk(e);
|
if (active) AddToChunk(e);
|
||||||
else RemoveFromChunk(e);
|
else RemoveFromChunk(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WritePixel<T>(int x, int y, int size) {
|
public void WritePixel<T>(int x, int y) {
|
||||||
int halfsize = size/2;
|
if (x < 0 || x >= sizeX || y < 0 || y >= sizeY) {
|
||||||
|
GD.PrintErr($"Out of bounds for chunk: {x}:{y}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
|
object o = Activator.CreateInstance(type, x, y, this);
|
||||||
|
|
||||||
for (int i = -halfsize; i <= halfsize; i++) {
|
// check if not empty and overwrite not allowed:
|
||||||
for (int j = -halfsize; j <= halfsize; j++) {
|
if (!Elements[x,y].IsEmpty() && !Main.Instance.AllowOverwrite) {
|
||||||
int X = Mathf.Clamp(x + i, 0, sizeX-1);
|
return;
|
||||||
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;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Elements[x, y].Chunk.RemoveFromChunk(Elements[x, y]);
|
||||||
|
Elements[x, y] = o as Element;
|
||||||
|
Elements[x, y].Active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ActiveElementsCount() {
|
public int ActiveElementsCount() {
|
||||||
@@ -144,6 +138,9 @@ public class Chunk {
|
|||||||
if (what.Chunk != swapTo.Chunk) {
|
if (what.Chunk != swapTo.Chunk) {
|
||||||
what.Chunk.RemoveFromChunk(what);
|
what.Chunk.RemoveFromChunk(what);
|
||||||
swapTo.Chunk.AddToChunk(what);
|
swapTo.Chunk.AddToChunk(what);
|
||||||
|
|
||||||
|
swapTo.Chunk.RemoveFromChunk(swapTo);
|
||||||
|
what.Chunk.AddToChunk(swapTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Element temp = new Element(what);
|
Element temp = new Element(what);
|
||||||
|
|||||||
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
|
||||||
@@ -2,29 +2,33 @@
|
|||||||
|
|
||||||
namespace FOU.Scripts.Elements;
|
namespace FOU.Scripts.Elements;
|
||||||
|
|
||||||
public class Element {
|
public class Element{
|
||||||
|
|
||||||
public Chunk Chunk;
|
public Chunk Chunk;
|
||||||
public Vector2I Position;
|
public Vector2I Position;
|
||||||
|
public int Density;
|
||||||
|
|
||||||
protected int Density;
|
|
||||||
protected int DiffuseSpeed = 10;
|
protected int DiffuseSpeed = 10;
|
||||||
protected Color color = Colors.Black;
|
protected Color color = Colors.Black;
|
||||||
protected const int MAX_DIFFUSE_SPEED = 100;
|
protected const int MAX_DIFFUSE_SPEED = 100;
|
||||||
protected const int STEPS_UNTIL_INACTIVE = 500;
|
protected const int STEPS_UNTIL_INACTIVE = 500;
|
||||||
|
|
||||||
protected const float MAX_COLOR_VARIANCE = 0.1f;
|
|
||||||
protected static readonly Vector2I VERTICAL_OPPOSITE = new Vector2I(-1, 1);
|
protected static readonly Vector2I VERTICAL_OPPOSITE = new Vector2I(-1, 1);
|
||||||
protected int lastMove = 0;
|
private const float MAX_COLOR_VARIANCE = 0.1f;
|
||||||
|
|
||||||
private bool active = false;
|
private bool active = false;
|
||||||
|
private bool markedForUpdate = true;
|
||||||
private int lastUpdate = -1;
|
private int lastUpdate = -1;
|
||||||
|
private int lastMove = 0;
|
||||||
private Color originalColor;
|
private Color originalColor;
|
||||||
|
|
||||||
public Element(Element e) {
|
public Element(Element e) {
|
||||||
Position = e.Position;
|
Position = e.Position;
|
||||||
Chunk = e.Chunk;
|
Chunk = e.Chunk;
|
||||||
lastMove = Engine.GetFramesDrawn();
|
Active = e.active;
|
||||||
|
lastMove = e.lastMove;
|
||||||
|
lastUpdate = e.lastUpdate;
|
||||||
|
Chunk.SetElementActive(this, Active);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element(int x, int y, Chunk chunk) {
|
public Element(int x, int y, Chunk chunk) {
|
||||||
@@ -32,17 +36,21 @@ public class Element {
|
|||||||
Position.Y = y;
|
Position.Y = y;
|
||||||
Chunk = chunk;
|
Chunk = chunk;
|
||||||
lastMove = Engine.GetFramesDrawn();
|
lastMove = Engine.GetFramesDrawn();
|
||||||
Active = false;
|
Chunk.SetElementActive(this, Active);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Active {
|
public bool Active {
|
||||||
get => active;
|
get => active;
|
||||||
set {
|
set {
|
||||||
if (active == value) return;
|
if (active == value) return;
|
||||||
|
|
||||||
active = value;
|
active = value;
|
||||||
Chunk.SetElementActive(this, value);
|
Chunk.SetElementActive(this, value);
|
||||||
// SetDebugColor(value, new Color(0.2f, 0.2f, 0.2f));
|
|
||||||
|
if (active) {
|
||||||
|
Moved();
|
||||||
|
} else {
|
||||||
|
ResetColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,9 +64,13 @@ public class Element {
|
|||||||
public virtual bool Update() {
|
public virtual bool Update() {
|
||||||
if (!Active) return false;
|
if (!Active) return false;
|
||||||
|
|
||||||
if (lastUpdate == Engine.GetFramesDrawn()) return false; // already updated this frame
|
int frame = Engine.GetFramesDrawn();
|
||||||
lastUpdate = Engine.GetFramesDrawn();
|
if (lastMove + STEPS_UNTIL_INACTIVE < frame)
|
||||||
|
Active = false;
|
||||||
|
if (lastUpdate == frame)
|
||||||
|
return false; // already updated this frame
|
||||||
|
|
||||||
|
lastUpdate = frame;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,23 +78,7 @@ public class Element {
|
|||||||
return $"{GetType()} {Position}[{Chunk.Index}] {active}";
|
return $"{GetType()} {Position}[{Chunk.Index}] {active}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Tick() {
|
protected virtual void Tick() { }
|
||||||
Vector2I randomDirection = RandomDirectionDown();
|
|
||||||
|
|
||||||
if (Chunk.IsEmpty(Position + Vector2I.Down))
|
|
||||||
Chunk.Swap(this, Position + Vector2I.Down);
|
|
||||||
|
|
||||||
else if (Chunk.IsEmpty(Position + randomDirection))
|
|
||||||
Chunk.Swap(this, Position + randomDirection);
|
|
||||||
|
|
||||||
else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
|
|
||||||
Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE);
|
|
||||||
|
|
||||||
if (GD.Randi() % MAX_DIFFUSE_SPEED > DiffuseSpeed) return; // ascend slower
|
|
||||||
|
|
||||||
if (Chunk.Get(Position + randomDirection)?.Density < Density)
|
|
||||||
Chunk.Swap(this, Position + Vector2I.Down);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Vector2I RandomDirectionDown() {
|
protected Vector2I RandomDirectionDown() {
|
||||||
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
||||||
@@ -91,6 +87,13 @@ public class Element {
|
|||||||
+ (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection);
|
+ (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <returns>-1, 0 or 1</returns>
|
||||||
|
protected Vector2I RandomDirection() {
|
||||||
|
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
||||||
|
|
||||||
|
return (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection);
|
||||||
|
}
|
||||||
|
|
||||||
protected Color AddColorVariance(Color baseColor) {
|
protected Color AddColorVariance(Color baseColor) {
|
||||||
Color c = baseColor;
|
Color c = baseColor;
|
||||||
c.R += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
|
c.R += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
|
||||||
@@ -103,15 +106,29 @@ public class Element {
|
|||||||
|
|
||||||
public void ResetColor() {
|
public void ResetColor() {
|
||||||
color = originalColor;
|
color = originalColor;
|
||||||
|
MarkForUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDebugColor(Color color) {
|
public void SetDebugColor(Color color) {
|
||||||
if (!Main.Instance.DebugVisualization) return;
|
if (!Main.Instance.DebugMode) return;
|
||||||
|
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Moved() {
|
public void Moved() {
|
||||||
lastMove = Engine.GetFramesDrawn();
|
lastMove = Engine.GetFramesDrawn();
|
||||||
|
MarkForUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsMarkedForUpdate() {
|
||||||
|
return markedForUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MarkForUpdate(bool mark = true) {
|
||||||
|
markedForUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEmpty() {
|
||||||
|
return GetType() == typeof(Element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
Scripts/Elements/Element.cs.uid
Normal file
1
Scripts/Elements/Element.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://b5lme1c4rx15n
|
||||||
@@ -5,18 +5,19 @@ namespace FOU.Scripts.Elements;
|
|||||||
public abstract class Liquid : Element {
|
public abstract class Liquid : Element {
|
||||||
public const int MAX_VERTICAL_SPREAD = 3;
|
public const int MAX_VERTICAL_SPREAD = 3;
|
||||||
|
|
||||||
protected Liquid(int x, int y, ref Chunk chunk) : base(x, y, chunk) { }
|
protected Liquid(int x, int y, ref Chunk chunk) : base(x, y, chunk) {
|
||||||
|
MarkForUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Update() {
|
public override bool Update() {
|
||||||
if (!base.Update()) return false;
|
if (!base.Update()) return false;
|
||||||
if (lastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
|
|
||||||
|
|
||||||
Tick();
|
Tick();
|
||||||
|
|
||||||
return true; // not necessarily end, subclasses could do some more things
|
return true; // not necessarily end, subclasses could do some more things
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Tick() {
|
protected virtual void Tick() {
|
||||||
Vector2I randomDirection = RandomDirectionDown();
|
Vector2I randomDirection = RandomDirectionDown();
|
||||||
if (randomDirection.Y != 0)
|
if (randomDirection.Y != 0)
|
||||||
randomDirection *= Vector2I.Left * (int)(GD.Randi() % MAX_VERTICAL_SPREAD);
|
randomDirection *= Vector2I.Left * (int)(GD.Randi() % MAX_VERTICAL_SPREAD);
|
||||||
|
|||||||
1
Scripts/Elements/Liquid.cs.uid
Normal file
1
Scripts/Elements/Liquid.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bqx36wisy7127
|
||||||
@@ -3,14 +3,40 @@
|
|||||||
namespace FOU.Scripts.Elements;
|
namespace FOU.Scripts.Elements;
|
||||||
|
|
||||||
public abstract class Solid : Element {
|
public abstract class Solid : Element {
|
||||||
protected Solid(int x, int y, ref Chunk chunk) : base(x, y, chunk) { }
|
protected Solid(int x, int y, ref Chunk chunk) : base(x, y, chunk) {
|
||||||
|
MarkForUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Update() {
|
public override bool Update() {
|
||||||
if (!base.Update()) return false;
|
if (!base.Update()) return false;
|
||||||
if (lastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
|
|
||||||
|
|
||||||
Tick();
|
Tick();
|
||||||
|
|
||||||
return true; // not necessarily end, subclasses could do some more things
|
return true; // not necessarily end, subclasses could do some more things
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void Tick() {
|
||||||
|
Vector2I randomDirection = RandomDirectionDown();
|
||||||
|
|
||||||
|
// fall speed reduction:
|
||||||
|
if (GD.Randi() % MAX_DIFFUSE_SPEED > DiffuseSpeed) return; // descend slower
|
||||||
|
|
||||||
|
if (Chunk.IsEmpty(Position + Vector2I.Down))
|
||||||
|
Chunk.Swap(this, Position + Vector2I.Down);
|
||||||
|
|
||||||
|
else if (Chunk.IsEmpty(Position + Vector2I.Down + randomDirection))
|
||||||
|
Chunk.Swap(this, Position + Vector2I.Down + randomDirection);
|
||||||
|
|
||||||
|
else if (Chunk.IsEmpty(Position + Vector2I.Down + randomDirection * VERTICAL_OPPOSITE))
|
||||||
|
Chunk.Swap(this, Position + Vector2I.Down + randomDirection * VERTICAL_OPPOSITE);
|
||||||
|
|
||||||
|
// density check
|
||||||
|
if (Chunk.Get(Position + Vector2I.Down)?.Density < Density)
|
||||||
|
Chunk.Swap(this, Position + Vector2I.Down);
|
||||||
|
else if (Chunk.Get(Position + Vector2I.Down + randomDirection)?.Density < Density)
|
||||||
|
Chunk.Swap(this, Position + Vector2I.Down + randomDirection);
|
||||||
|
else if (Chunk.Get(Position + Vector2I.Down + randomDirection * VERTICAL_OPPOSITE)?.Density < Density)
|
||||||
|
Chunk.Swap(this, Position + Vector2I.Down + randomDirection * VERTICAL_OPPOSITE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
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
|
||||||
116
Scripts/Level.cs
116
Scripts/Level.cs
@@ -11,8 +11,8 @@ public class Level {
|
|||||||
private Chunk[,] chunks;
|
private Chunk[,] chunks;
|
||||||
private Image image;
|
private Image image;
|
||||||
|
|
||||||
private int chunksX;
|
private int chunksPerX;
|
||||||
private int chunksY;
|
private int chunksPerY;
|
||||||
|
|
||||||
// per chunk:
|
// per chunk:
|
||||||
private int chunkResX;
|
private int chunkResX;
|
||||||
@@ -22,34 +22,34 @@ public class Level {
|
|||||||
|
|
||||||
public Level(Main main, int sizeX, int sizeY) {
|
public Level(Main main, int sizeX, int sizeY) {
|
||||||
Resolution = new Vector2I(sizeX, sizeY);
|
Resolution = new Vector2I(sizeX, sizeY);
|
||||||
chunksX = main.ChunksPerAxis;
|
chunksPerX = main.ChunksPerAxis;
|
||||||
chunksY = main.ChunksPerAxis;
|
chunksPerY = main.ChunksPerAxis;
|
||||||
|
|
||||||
chunkResX = sizeX / chunksX;
|
chunkResX = sizeX / chunksPerX;
|
||||||
chunkResY = sizeY / chunksY;
|
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);
|
image = Image.CreateEmpty(sizeX, sizeY, false, Image.Format.Rgb8);
|
||||||
|
|
||||||
chunks = new Chunk[chunksX, chunksY];
|
chunks = new Chunk[chunksPerX, chunksPerY];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
// create all chunks
|
// create all chunks
|
||||||
for (int x = 0; x < chunksX; x++) {
|
for (int x = 0; x < chunksPerX; x++) {
|
||||||
for (int y = 0; y < chunksY; y++) {
|
for (int y = 0; y < chunksPerY; y++) {
|
||||||
chunks[x, y] = new Chunk(chunkResX, chunkResY, index++);
|
chunks[x, y] = new Chunk(chunkResX, chunkResY, index++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign neighbors
|
// assign neighbors
|
||||||
for (int x = 0; x < chunksX; x++) {
|
for (int x = 0; x < chunksPerX; x++) {
|
||||||
for (int y = 0; y < chunksY; y++) {
|
for (int y = 0; y < chunksPerY; y++) {
|
||||||
|
|
||||||
if (y > 0) chunks[x, y].NeighborN = chunks[x, y-1];
|
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 > 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() {
|
public void StartBenchmark() {
|
||||||
GD.Print("benchmark");
|
GD.Print("benchmark");
|
||||||
for (int x = 0; x < chunksX; x++) {
|
for (int x = 0; x < chunksPerX; x++) {
|
||||||
for (int y = 0; y < chunksY; y++) {
|
for (int y = 0; y < chunksPerY; y++) {
|
||||||
chunks[x, y].WritePixel<Dirt>(chunkResX/2, chunkResY/2, 100);
|
WritePixel<Dirt>((x * chunkResX) + chunkResX/2, (y * chunkResY) + chunkResY/2, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,23 +84,91 @@ public class Level {
|
|||||||
int rainDrops = (int)Math.Round(rainAmount);
|
int rainDrops = (int)Math.Round(rainAmount);
|
||||||
|
|
||||||
for (int i = 0; i <= rainDrops; i++) {
|
for (int i = 0; i <= rainDrops; i++) {
|
||||||
if (GD.Randf() < rainAmount)
|
if (GD.Randf() < rainAmount) {
|
||||||
WritePixel<Water>((int)(GD.Randi() % (chunkResX * chunksX)), 0, 1);
|
int d = (int)(GD.Randi() % (chunkResX * chunksPerX));
|
||||||
|
if (GetElement(d, 0).IsEmpty())
|
||||||
|
WritePixel<Water>(d, 0, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WritePixel<T>(int x, int y, int size) {
|
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;
|
||||||
|
|
||||||
|
int startPtX = x % chunkResX;
|
||||||
|
int startPtY = y % chunkResY;
|
||||||
|
|
||||||
|
for (int i = -halfsize; i <= halfsize; i++) {
|
||||||
|
for (int j = -halfsize; j <= halfsize; j++) {
|
||||||
|
|
||||||
|
// calculate in-chunk coordinates
|
||||||
|
int iteratorX = i;
|
||||||
|
int iteratorY = j;
|
||||||
|
int ptX = startPtX;
|
||||||
|
int ptY = startPtY;
|
||||||
|
|
||||||
|
// calculate chunk to write to
|
||||||
|
int chunkX = x/chunkResX;
|
||||||
|
|
||||||
|
// left of chunk
|
||||||
|
if (startPtX + iteratorX < 0) {
|
||||||
|
chunkX--;
|
||||||
|
iteratorX = chunkResX + startPtX + iteratorX;
|
||||||
|
ptX = startPtX + iteratorX;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ptX = startPtX + iteratorX;
|
||||||
|
}
|
||||||
|
if (startPtX + iteratorX >= chunkResX) {
|
||||||
|
chunkX++;
|
||||||
|
ptX = startPtX + iteratorX - chunkResX;
|
||||||
|
}
|
||||||
|
int chunkY = y/chunkResY;
|
||||||
|
|
||||||
|
// above chunk
|
||||||
|
if (startPtY + iteratorY < 0) {
|
||||||
|
chunkY--;
|
||||||
|
ptY = chunkResY + (startPtY + iteratorY);
|
||||||
|
} else {
|
||||||
|
ptY = startPtY + iteratorY;
|
||||||
|
}
|
||||||
|
if (startPtY + iteratorY >= chunkResY) {
|
||||||
|
chunkY++;
|
||||||
|
ptY = startPtY + iteratorY - chunkResY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore everything outside
|
||||||
|
if (chunkX < 0) continue;
|
||||||
|
if (chunkX >= chunksPerX) continue;
|
||||||
|
if (chunkY < 0) continue;
|
||||||
|
if (chunkY >= chunksPerY) continue;
|
||||||
|
|
||||||
|
chunks[chunkX, chunkY].WritePixel<T>(ptX, ptY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element GetElement(int x, int y) {
|
||||||
|
if (x < 0 || x > chunkResX * chunkResX) return null;
|
||||||
|
if (y < 0 || y > chunkResY * chunkResY) return null;
|
||||||
|
|
||||||
|
return chunks[x / chunkResX, y / chunkResY].Elements[x % chunkResX, y % chunkResY];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image DrawLevel() {
|
public Image DrawLevel() {
|
||||||
for (int cx = 0; cx < chunksX; cx++) {
|
// chunk
|
||||||
for (int cy = 0; cy < chunksY; cy++) {
|
for (int cx = 0; cx < chunksPerX; cx++) {
|
||||||
|
for (int cy = 0; cy < chunksPerY; cy++) {
|
||||||
|
|
||||||
|
// pixel in chunk
|
||||||
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
|
// 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);
|
|
||||||
|
if (chunks[cx, cy].Elements[x, y].IsMarkedForUpdate()) {
|
||||||
|
image.SetPixel(cx * chunkResX + x, cy * chunkResY + y, chunks[cx, cy].Elements[x, y].Color);
|
||||||
|
chunks[cx, cy].Elements[x, y].MarkForUpdate(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
Scripts/Level.cs.uid
Normal file
1
Scripts/Level.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bkwbjagt8s01s
|
||||||
@@ -3,19 +3,27 @@ using FOU.Scripts.Elements;
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
public partial class Main : Node2D {
|
public partial class Main : Node2D {
|
||||||
[Export] public bool DebugVisualization = false;
|
[Export] public bool DebugMode = false;
|
||||||
|
[Export] public bool AllowOverwrite = true;
|
||||||
|
|
||||||
[Export] public int BrushSize = 5;
|
[Export] public int BrushSize = 5;
|
||||||
[Export] public float TextureResolution = 0.5f;
|
[Export] public float TextureResolution = 0.5f;
|
||||||
[Export] public int ChunksPerAxis = 2;
|
[Export] public int ChunksPerAxis = 2;
|
||||||
[Export] public float RainAmount = 0;
|
[Export] public float rainAmount = 0;
|
||||||
|
|
||||||
public static Main Instance;
|
public static Main Instance;
|
||||||
public Level Level;
|
public Level Level;
|
||||||
|
|
||||||
private TextureRect mLevelDrawer;
|
private TextureRect mLevelDrawer;
|
||||||
private bool enableRain;
|
private bool enableRain;
|
||||||
private float rainAmount;
|
|
||||||
|
public float RainAmount {
|
||||||
|
get => rainAmount;
|
||||||
|
set {
|
||||||
|
rainAmount = value;
|
||||||
|
Level?.SetRainAmount(rainAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
Level = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution),
|
Level = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution),
|
||||||
@@ -26,8 +34,13 @@ public partial class Main : Node2D {
|
|||||||
Instance = this;
|
Instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _PhysicsProcess(double delta) {
|
||||||
|
base._PhysicsProcess(delta);
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Process(double delta) {
|
public override void _Process(double delta) {
|
||||||
Level.Update();
|
Level.Update();
|
||||||
|
mLevelDrawer.Texture?.Dispose();
|
||||||
mLevelDrawer.Texture = ImageTexture.CreateFromImage(Level.DrawLevel());
|
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
|
## Settings
|
||||||
|
|
||||||
- Texture Resolution: 0.5
|
- Texture Resolution: 0.5
|
||||||
- CHunks per Axis: 2
|
- CHunks per Axis: 2
|
||||||
- Rain Amount: 0
|
- Rain Amount: 0
|
||||||
|
|
||||||
## Measurements:
|
## Measurements:
|
||||||
|
|
||||||
### original (no optimization):
|
### original (no optimization):
|
||||||
|
|
||||||
- idle: 42 - 44 fps
|
- idle: 42 - 44 fps
|
||||||
- benchmark: 24 fps minimum
|
- benchmark: 24 fps minimum
|
||||||
|
|
||||||
### only active:
|
### performance-improvements (71db6513f22094e7dd67bd32c7ab86b326f9ad9e)
|
||||||
- idle: 100 fps
|
|
||||||
- benchmark: 36 fps minimum
|
- idle before: 89
|
||||||
|
- benchmark: 33
|
||||||
|
- idle after: 75
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ config_version=5
|
|||||||
|
|
||||||
config/name="FOU"
|
config/name="FOU"
|
||||||
run/main_scene="res://Scenes/main.tscn"
|
run/main_scene="res://Scenes/main.tscn"
|
||||||
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
|
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
[dotnet]
|
[dotnet]
|
||||||
|
|||||||
Reference in New Issue
Block a user