-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimulationSettings.pde
More file actions
139 lines (118 loc) · 3.54 KB
/
SimulationSettings.pde
File metadata and controls
139 lines (118 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import java.nio.file.Path;
import java.nio.file.Paths;
public SimulationSettings settingsInstance = new SimulationSettings();
class SimulationSettings
{
public static final int MAX_HEIGHT = 255;
public static final float GRAVITY = 2f;
public int dropletSoftLimit;
public float initialSpeed;
public float initialWater;
public float inertia;
public float sedimentCapacityFactor = 4f;
public float minSedimentCapacity = .01f;
public float erodeSpeed;
public float depositSpeed;
public float evaporateSpeed;
public int maxDropletLifetime;
public boolean running;
public boolean showWater;
public boolean showWaterSources;
public boolean logToConsole;
private MouseMode mouseMode;
public ValueBrush activeBrush; // Just a pointer to the brush for the current mode
public ValueBrush waterBrush;
public ValueBrush terrainBrush;
public ValueBrush resistanceBrush;
public Gradient displayGradient;
public int displayScale;
private boolean displayScaleChanged;
private String sourceHeightmapPath;
private String sourceHeightmapFilename;
private PImage sourceHeightmap;
private PImage sourceWatermap;
private int width, height;
public String getSourceHeightmapFilename() { return sourceHeightmapFilename; }
public PImage getSourceHeightmap() { return sourceHeightmap; }
public int getWidth() { return width; }
public int getHeight() { return height; }
public int getDisplayWidth() { return width * displayScale; }
public int getDisplayHeight() { return height * displayScale; }
public void setSourceHeightmap(String sourceHeightmapPath)
{
// This should throw an exception if path is invalid, before any fields are actually assigned
Path testPath = Paths.get(sourceHeightmapPath);
Path testFile = testPath.getFileName();
this.sourceHeightmapPath = testPath.toString();
sourceHeightmapFilename = testFile.toString();
sourceHeightmap = loadImage(this.sourceHeightmapPath);
sourceWatermap = sourceHeightmap.copy();
ColorConverter.GchannelToValue(sourceHeightmap);
ColorConverter.BchannelToValue(sourceWatermap);
this.width = sourceHeightmap.width;
this.height = sourceHeightmap.height;
}
public MouseMode getMouseMode() { return mouseMode; }
public void setMouseMode(MouseMode mode)
{
mouseMode = mode;
switch(mouseMode)
{
case WATERSOURCE:
activeBrush = waterBrush;
break;
case HEIGHT:
activeBrush = terrainBrush;
break;
case ROCK:
activeBrush = resistanceBrush;
break;
case DEBUG:
// TODO add debug brush?
activeBrush = terrainBrush;
break;
}
}
}
class SimulationData
{
public Terrain terrain;
public WaterErosion water;
public PGraphics canvas;
private int simulationStep;
private int dropletCount;
private int stepsInLastSec;
private int stepsCountEndTime;
private int lastStepRate;
private int mouseX, mouseY;
public SimulationData(SimulationSettings settings)
{
terrain = new Terrain(settings.getSourceHeightmap());
water = new WaterErosion(settings, this);
canvas = createGraphics(settings.getWidth(), settings.getHeight());
simulationStep = 0;
stepsCountEndTime = millis() + 1000;
lastStepRate = 0;
}
public int getSimulationStep() { return simulationStep; }
public int getLastStepRate() { return lastStepRate; }
public int getDropletCount() { return dropletCount; }
public void incrementSimulationStep()
{
if (stepsCountEndTime <= millis())
{
stepsCountEndTime = millis() + 1000;
lastStepRate = stepsInLastSec;
stepsInLastSec = 0;
}
simulationStep++;
stepsInLastSec++;
}
}
public enum MouseMode
{
WATERSOURCE,
HEIGHT,
ROCK,
DEBUG
}