Skip to content

Commit 70f5239

Browse files
committed
Add vorticity confinement.
1 parent 0096d27 commit 70f5239

13 files changed

Lines changed: 159 additions & 2 deletions

src/client/GameSave.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <algorithm>
1818

1919
constexpr auto currentVersion = UPSTREAM_VERSION.displayVersion;
20-
constexpr auto nextVersion = Version(99, 3);
20+
constexpr auto nextVersion = Version(100, 0);
2121
static_assert(!ALLOW_FAKE_NEWER_VERSION || nextVersion >= currentVersion);
2222

2323
constexpr auto effectiveVersion = ALLOW_FAKE_NEWER_VERSION ? nextVersion : currentVersion;
@@ -630,6 +630,7 @@ void GameSave::readOPS(const std::vector<char> &data)
630630
CheckBsonFieldFloat(iter, "customGravityY", &customGravityY);
631631
CheckBsonFieldInt(iter, "airMode", &airMode);
632632
CheckBsonFieldFloat(iter, "ambientAirTemp", &ambientAirTemp);
633+
CheckBsonFieldFloat(iter, "vorticityCoeff", &vorticityCoeff);
633634
CheckBsonFieldInt(iter, "edgeMode", &edgeMode);
634635
CheckBsonFieldInt(iter, "pmapbits", &pmapbits);
635636
CheckBsonFieldBool(iter, "ensureDeterminism", &ensureDeterminism);
@@ -2583,6 +2584,11 @@ std::pair<bool, std::vector<char>> GameSave::serialiseOPS() const
25832584
bson_append_double(&b, "ambientAirTemp", double(ambientAirTemp));
25842585
RESTRICTVERSION(96, 0);
25852586
}
2587+
if (vorticityCoeff > 0.0001f && vorticityCoeff < 1.0f)
2588+
{
2589+
bson_append_double(&b, "vorticityCoeff", double(vorticityCoeff));
2590+
RESTRICTVERSION(100, 0);
2591+
}
25862592
bson_append_int(&b, "edgeMode", edgeMode);
25872593

25882594
if (stkm.hasData())

src/client/GameSave.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class GameSave
107107
float customGravityY = 0.0f;
108108
int airMode = 0;
109109
float ambientAirTemp = R_TEMP + 273.15f;
110+
float vorticityCoeff = 0.0f;
110111
int edgeMode = 0;
111112
bool wantAuthors = true;
112113

src/gui/game/GameModel.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ GameModel::GameModel(GameView *newView):
6161
colour(255, 0, 0, 255),
6262
edgeMode(EDGE_VOID),
6363
ambientAirTemp(R_TEMP + 273.15f),
64+
vorticityCoeff(0.0f),
6465
decoSpace(DECOSPACE_SRGB),
6566
view(newView)
6667
{
@@ -121,6 +122,17 @@ GameModel::GameModel(GameView *newView):
121122
}
122123
}
123124
sim->air->ambientAirTemp = ambientAirTemp;
125+
126+
vorticityCoeff = 0.1f; // The default for old saves is 0, but use 0.1 for old configs
127+
{
128+
auto vort = prefs.Get("Simulation.VorticityCoeff", vorticityCoeff);
129+
if (0.0f <= vort && vort <= 1.0f)
130+
{
131+
vorticityCoeff = vort;
132+
}
133+
}
134+
sim->air->vorticityCoeff = vorticityCoeff;
135+
124136
decoSpace = prefs.Get("Simulation.DecoSpace", NUM_DECOSPACES, DECOSPACE_SRGB);
125137
sim->SetDecoSpace(decoSpace);
126138
if (prefs.Get("Simulation.NewtonianGravity", false))
@@ -308,6 +320,17 @@ float GameModel::GetAmbientAirTemperature()
308320
return this->ambientAirTemp;
309321
}
310322

323+
void GameModel::SetVorticityCoeff(float vorticityCoeff)
324+
{
325+
this->vorticityCoeff = vorticityCoeff;
326+
sim->air->vorticityCoeff = vorticityCoeff;
327+
}
328+
329+
float GameModel::GetVorticityCoeff()
330+
{
331+
return this->vorticityCoeff;
332+
}
333+
311334
void GameModel::SetDecoSpace(int decoSpace)
312335
{
313336
sim->SetDecoSpace(decoSpace);
@@ -736,6 +759,7 @@ void GameModel::SaveToSimParameters(const GameSave &saveData)
736759
sim->customGravityY = saveData.customGravityY;
737760
sim->air->airMode = saveData.airMode;
738761
sim->air->ambientAirTemp = saveData.ambientAirTemp;
762+
sim->air->vorticityCoeff = saveData.vorticityCoeff;
739763
sim->edgeMode = saveData.edgeMode;
740764
sim->legacy_enable = saveData.legacyEnable;
741765
sim->water_equal_test = saveData.waterEEnabled;
@@ -1112,6 +1136,7 @@ void GameModel::ClearSimulation()
11121136
sim->water_equal_test = false;
11131137
sim->SetEdgeMode(edgeMode);
11141138
sim->air->ambientAirTemp = ambientAirTemp;
1139+
sim->air->vorticityCoeff = vorticityCoeff;
11151140

11161141
sim->clear_sim();
11171142
ren->ClearAccumulation();

src/gui/game/GameModel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class GameModel
104104

105105
int edgeMode;
106106
float ambientAirTemp;
107+
float vorticityCoeff;
107108
int decoSpace;
108109

109110
String infoTip;
@@ -162,6 +163,8 @@ class GameModel
162163
}
163164
void SetAmbientAirTemperature(float ambientAirTemp);
164165
float GetAmbientAirTemperature();
166+
void SetVorticityCoeff(float vorticityCoeff);
167+
float GetVorticityCoeff();
165168
void SetDecoSpace(int decoSpace);
166169
int GetDecoSpace();
167170

src/gui/options/OptionsController.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ void OptionsController::SetAmbientAirTemperature(float ambientAirTemp)
6262
model->SetAmbientAirTemperature(ambientAirTemp);
6363
}
6464

65+
void OptionsController::SetVorticityCoeff(float vorticityCoeff)
66+
{
67+
model->SetVorticityCoeff(vorticityCoeff);
68+
}
69+
6570
void OptionsController::SetEdgeMode(int edgeMode)
6671
{
6772
model->SetEdgeMode(edgeMode);

src/gui/options/OptionsController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class OptionsController
2222
void SetCustomGravityY(float y);
2323
void SetAirMode(int airMode);
2424
void SetAmbientAirTemperature(float ambientAirTemp);
25+
void SetVorticityCoeff(float vorticityCoeff);
2526
void SetEdgeMode(int edgeMode);
2627
void SetTemperatureScale(int temperatureScale);
2728
void SetThreadedRendering(bool newThreadedRendering);

src/gui/options/OptionsModel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ void OptionsModel::SetAmbientAirTemperature(float ambientAirTemp)
119119
notifySettingsChanged();
120120
}
121121

122+
float OptionsModel::GetVorticityCoeff()
123+
{
124+
return gModel->GetSimulation()->air->vorticityCoeff;
125+
}
126+
void OptionsModel::SetVorticityCoeff(float vorticityCoeff)
127+
{
128+
GlobalPrefs::Ref().Set("Simulation.VorticityCoeff", vorticityCoeff);
129+
gModel->SetVorticityCoeff(vorticityCoeff);
130+
notifySettingsChanged();
131+
}
132+
122133
int OptionsModel::GetGravityMode()
123134
{
124135
return sim->gravityMode;

src/gui/options/OptionsModel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class OptionsModel
2727
void SetAirMode(int airMode);
2828
float GetAmbientAirTemperature();
2929
void SetAmbientAirTemperature(float ambientAirTemp);
30+
float GetVorticityCoeff();
31+
void SetVorticityCoeff(float vorticityCoeff);
3032
int GetEdgeMode();
3133
void SetEdgeMode(int edgeMode);
3234
int GetTemperatureScale();

src/gui/options/OptionsView.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
138138
scrollPanel->AddChild(label);
139139
currentY += 20;
140140
}
141+
{ // Vorticity coefficient setting
142+
vorticityCoeff = new ui::Textbox(ui::Point(Size.X-95, currentY), ui::Point(80, 16));
143+
vorticityCoeff->SetActionCallback({ [this] {
144+
UpdateVorticityCoeff(vorticityCoeff->GetText(), false);
145+
} });
146+
vorticityCoeff->SetDefocusCallback({ [this] {
147+
UpdateVorticityCoeff(vorticityCoeff->GetText(), true);
148+
}});
149+
vorticityCoeff->SetLimit(9);
150+
scrollPanel->AddChild(vorticityCoeff);
151+
auto *label = new ui::Label(ui::Point(8, currentY), ui::Point(Size.X-105, 16), "Vorticity confinement");
152+
label->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
153+
label->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
154+
scrollPanel->AddChild(label);
155+
currentY += 20;
156+
}
141157
class GravityWindow : public ui::Window
142158
{
143159
void OnTryExit(ExitMethod method) override
@@ -430,6 +446,13 @@ void OptionsView::AmbientAirTempToTextBox(float airTemp)
430446
ambientAirTemp->SetText(sb.Build());
431447
}
432448

449+
void OptionsView::VorticityCoeffToTextBox(float vorticity)
450+
{
451+
StringBuilder sb;
452+
sb << Format::Precision(2) << vorticity;
453+
vorticityCoeff->SetText(sb.Build());
454+
}
455+
433456
void OptionsView::UpdateStartupRequestStatus()
434457
{
435458
switch (Client::Ref().GetStartupRequestStatus())
@@ -502,6 +525,47 @@ void OptionsView::UpdateAirTemp(String temp, bool isDefocus)
502525
UpdateAmbientAirTempPreview(airTemp, isValid);
503526
}
504527

528+
void OptionsView::UpdateVorticityCoeff(String vort, bool isDefocus)
529+
{
530+
// Parse vorticity and determine validity
531+
float vorticity = 0;
532+
bool isValid;
533+
try
534+
{
535+
vorticity = vort.ToNumber<float>();
536+
isValid = true;
537+
}
538+
catch (const std::exception &ex)
539+
{
540+
isValid = false;
541+
}
542+
543+
// While defocusing, correct out of range vorticity and empty textboxes
544+
if (isDefocus)
545+
{
546+
if (vort.empty())
547+
{
548+
isValid = true;
549+
vorticity = 0.0f;
550+
}
551+
else if (!isValid)
552+
return;
553+
else if (vorticity < 0.0f)
554+
vorticity = 0.0f;
555+
else if (vorticity > 1.0f)
556+
vorticity = 1.0f;
557+
558+
VorticityCoeffToTextBox(vorticity);
559+
}
560+
// Out of range vorticities are invalid, preview should go away
561+
else if (isValid && (vorticity < 0.0f || vorticity > 1.0f))
562+
isValid = false;
563+
564+
// If valid, set vorticity
565+
if (isValid)
566+
c->SetVorticityCoeff(vorticity);
567+
}
568+
505569
void OptionsView::NotifySettingsChanged(OptionsModel * sender)
506570
{
507571
temperatureScale->SetOption(sender->GetTemperatureScale()); // has to happen before AmbientAirTempToTextBox is called
@@ -517,6 +581,11 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
517581
UpdateAmbientAirTempPreview(airTemp, true);
518582
AmbientAirTempToTextBox(airTemp);
519583
}
584+
// Same for vorticity
585+
if (!vorticityCoeff->IsFocused())
586+
{
587+
VorticityCoeffToTextBox(sender->GetVorticityCoeff());
588+
}
520589
gravityMode->SetOption(sender->GetGravityMode());
521590
customGravityX = sender->GetCustomGravityX();
522591
customGravityY = sender->GetCustomGravityY();

src/gui/options/OptionsView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class OptionsView: public ui::Window
2424
ui::DropDown *airMode{};
2525
ui::Textbox *ambientAirTemp{};
2626
ui::Button *ambientAirTempPreview{};
27+
ui::Textbox *vorticityCoeff{};
2728
ui::DropDown *gravityMode{};
2829
ui::DropDown *edgeMode{};
2930
ui::DropDown *temperatureScale{};
@@ -52,6 +53,8 @@ class OptionsView: public ui::Window
5253
void UpdateAmbientAirTempPreview(float airTemp, bool isValid);
5354
void AmbientAirTempToTextBox(float airTemp);
5455
void UpdateAirTemp(String temp, bool isDefocus);
56+
void VorticityCoeffToTextBox(float vorticity);
57+
void UpdateVorticityCoeff(String cort, bool isDefocus);
5558
void UpdateStartupRequestStatus();
5659
public:
5760
OptionsView();

0 commit comments

Comments
 (0)