Skip to content

Commit

Permalink
Hooked up repeating bounds to GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasEriksen committed Sep 7, 2022
1 parent 4ccefd0 commit 1890160
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 63 deletions.
Binary file modified LeifProject/bin/windows/libleifparticle.dll
Binary file not shown.
Binary file added LeifProject/bin/x11/libleifparticle.so
Binary file not shown.
16 changes: 11 additions & 5 deletions LeifProject/gui/GUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ signal audio_file_selected(path)
signal music_stop
signal volume_changed(val)
signal preset_selected(name)
signal boundaries_enabled_toggle(value)
signal boundaries_changed(new_val)
signal world_size_changed(new_size)
signal viscosity_changed(value)
signal particle_count_applied(red, green, white, blue)
Expand All @@ -23,6 +23,7 @@ onready var red_count_spinbox = $VBoxContainer/Split/GeneralContainer/ParticleSe
onready var green_count_spinbox = $VBoxContainer/Split/GeneralContainer/ParticleSettingsContainer/HBoxContainer2/GreenCountSpinBox
onready var white_count_spinbox = $VBoxContainer/Split/GeneralContainer/ParticleSettingsContainer/HBoxContainer3/WhiteCountSpinBox
onready var blue_count_spinbox = $VBoxContainer/Split/GeneralContainer/ParticleSettingsContainer/HBoxContainer4/BlueCountSpinBox
onready var boundaries_button = $VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/BoundariesButton
onready var rules_container = $VBoxContainer/Split/RuleContainer
onready var red_count_color_rect = $VBoxContainer/Split/GeneralContainer/ParticleSettingsContainer/HBoxContainer/ColorRect
onready var green_count_color_rect = $VBoxContainer/Split/GeneralContainer/ParticleSettingsContainer/HBoxContainer2/ColorRect
Expand All @@ -39,6 +40,11 @@ func _ready() -> void:
green_count_color_rect.color = Globals.GREEN_COLOR
white_count_color_rect.color = Globals.WHITE_COLOR
blue_count_color_rect.color = Globals.BLUE_COLOR
boundaries_button.clear()
boundaries_button.add_item("No bounds", Globals.BOUNDS_DISABLED)
boundaries_button.add_item("Strict bounds", Globals.BOUNDS_STRICT)
boundaries_button.add_item("Repeating bounds", Globals.BOUNDS_REPEATING)
boundaries_button.select(Globals.BOUNDS_STRICT)
update_load_menu()

func _process(_delta):
Expand Down Expand Up @@ -120,10 +126,6 @@ func _on_CountApplyButton_pressed():
)


func _on_BoundariesButton_toggled(button_pressed):
emit_signal("boundaries_enabled_toggle", button_pressed)


func _on_RandomButton_pressed():
emit_signal("randomize_rules")

Expand Down Expand Up @@ -193,3 +195,7 @@ func _on_RuleContainer_range_updated(index: int, value: float):

func _on_ViscositySlider_value_changed(value):
emit_signal("viscosity_changed", value)


func _on_BoundariesButton_item_selected(index):
emit_signal("boundaries_changed", index)
78 changes: 39 additions & 39 deletions LeifProject/gui/GUI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ tracks/2/keys = {
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = 780.0
margin_right = 17280.0
margin_bottom = 10500.0
margin_right = 19200.0
margin_bottom = 11580.0
theme = ExtResource( 3 )
script = ExtResource( 2 )

Expand Down Expand Up @@ -213,121 +213,121 @@ margin_bottom = 256.0

[node name="PresetContainer" type="VBoxContainer" parent="VBoxContainer/Split/GeneralContainer"]
margin_left = 293.0
margin_right = 648.0
margin_right = 663.0
margin_bottom = 256.0
size_flags_horizontal = 3

[node name="Label" type="Label" parent="VBoxContainer/Split/GeneralContainer/PresetContainer"]
margin_right = 355.0
margin_right = 370.0
margin_bottom = 24.0
text = "Presets"
align = 1

[node name="HSeparator" type="HSeparator" parent="VBoxContainer/Split/GeneralContainer/PresetContainer"]
margin_top = 28.0
margin_right = 355.0
margin_right = 370.0
margin_bottom = 32.0

[node name="PresetListContainer" type="ScrollContainer" parent="VBoxContainer/Split/GeneralContainer/PresetContainer"]
margin_top = 36.0
margin_right = 355.0
margin_right = 370.0
margin_bottom = 192.0
rect_min_size = Vector2( 160, 0 )
size_flags_vertical = 3
follow_focus = true

[node name="PresetList" type="ItemList" parent="VBoxContainer/Split/GeneralContainer/PresetContainer/PresetListContainer"]
margin_right = 355.0
margin_right = 370.0
margin_bottom = 156.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="SaveButton" type="Button" parent="VBoxContainer/Split/GeneralContainer/PresetContainer"]
margin_top = 196.0
margin_right = 355.0
margin_right = 370.0
margin_bottom = 224.0
size_flags_horizontal = 3
text = "Save"

[node name="ImportButtons" type="HBoxContainer" parent="VBoxContainer/Split/GeneralContainer/PresetContainer"]
margin_top = 228.0
margin_right = 355.0
margin_right = 370.0
margin_bottom = 256.0

[node name="ImportButton" type="Button" parent="VBoxContainer/Split/GeneralContainer/PresetContainer/ImportButtons"]
margin_right = 175.0
margin_right = 183.0
margin_bottom = 28.0
size_flags_horizontal = 3
text = "Import"

[node name="ExportButton" type="Button" parent="VBoxContainer/Split/GeneralContainer/PresetContainer/ImportButtons"]
margin_left = 179.0
margin_right = 355.0
margin_left = 187.0
margin_right = 370.0
margin_bottom = 28.0
size_flags_horizontal = 3
text = "Export"

[node name="VSeparator4" type="VSeparator" parent="VBoxContainer/Split/GeneralContainer"]
margin_left = 652.0
margin_right = 656.0
margin_left = 667.0
margin_right = 671.0
margin_bottom = 256.0

[node name="WorldSettingsContainer" type="VBoxContainer" parent="VBoxContainer/Split/GeneralContainer"]
margin_left = 660.0
margin_left = 675.0
margin_right = 827.0
margin_bottom = 256.0

[node name="Label" type="Label" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
margin_right = 167.0
margin_right = 152.0
margin_bottom = 24.0
text = "World settings"
align = 1
valign = 1

[node name="HSeparator" type="HSeparator" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
margin_top = 28.0
margin_right = 167.0
margin_right = 152.0
margin_bottom = 32.0

[node name="RestartButton" type="Button" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
margin_top = 36.0
margin_right = 167.0
margin_right = 152.0
margin_bottom = 64.0
text = "Restart"

[node name="RandomButton" type="Button" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
margin_top = 68.0
margin_right = 167.0
margin_right = 152.0
margin_bottom = 96.0
text = "Randomize rules"

[node name="BoundariesButton" type="CheckButton" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
[node name="BoundariesButton" type="OptionButton" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
margin_top = 100.0
margin_right = 167.0
margin_bottom = 136.0
margin_right = 152.0
margin_bottom = 128.0
pressed = true
text = "Boundaries"

[node name="WorldSizeContainer" type="HBoxContainer" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
margin_top = 140.0
margin_right = 167.0
margin_bottom = 202.0
margin_top = 132.0
margin_right = 152.0
margin_bottom = 194.0

[node name="WorldWidthContainer" type="VBoxContainer" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/WorldSizeContainer"]
margin_right = 81.0
margin_right = 74.0
margin_bottom = 62.0
size_flags_horizontal = 3

[node name="Label" type="Label" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/WorldSizeContainer/WorldWidthContainer"]
margin_right = 81.0
margin_right = 74.0
margin_bottom = 24.0
text = "Width"
align = 1
valign = 1

[node name="WorldWidthSpinbox" type="SpinBox" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/WorldSizeContainer/WorldWidthContainer"]
margin_top = 28.0
margin_right = 81.0
margin_right = 74.0
margin_bottom = 62.0
min_value = 400.0
max_value = 1920.0
Expand All @@ -337,21 +337,21 @@ rounded = true
suffix = "px"

[node name="WorldHeightContainer" type="VBoxContainer" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/WorldSizeContainer"]
margin_left = 85.0
margin_right = 167.0
margin_left = 78.0
margin_right = 152.0
margin_bottom = 62.0
size_flags_horizontal = 3

[node name="Label" type="Label" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/WorldSizeContainer/WorldHeightContainer"]
margin_right = 82.0
margin_right = 74.0
margin_bottom = 24.0
text = "Height"
align = 1
valign = 1

[node name="WorldHeightSpinbox" type="SpinBox" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/WorldSizeContainer/WorldHeightContainer"]
margin_top = 28.0
margin_right = 82.0
margin_right = 74.0
margin_bottom = 62.0
min_value = 400.0
max_value = 1080.0
Expand All @@ -361,16 +361,16 @@ rounded = true
suffix = "px"

[node name="Label2" type="Label" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
margin_top = 206.0
margin_right = 167.0
margin_bottom = 230.0
margin_top = 198.0
margin_right = 152.0
margin_bottom = 222.0
text = "Viscosity"
align = 1

[node name="ViscositySlider" type="HSlider" parent="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer"]
margin_top = 234.0
margin_right = 167.0
margin_bottom = 250.0
margin_top = 226.0
margin_right = 152.0
margin_bottom = 242.0
max_value = 1.0
step = 0.1
value = 0.5
Expand Down Expand Up @@ -654,7 +654,7 @@ filters = PoolStringArray( "*.mp3, *.ogg ; Audio files\"" )
[connection signal="pressed" from="VBoxContainer/Split/GeneralContainer/PresetContainer/ImportButtons/ExportButton" to="." method="_on_ExportButton_pressed"]
[connection signal="pressed" from="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/RestartButton" to="." method="_on_RestartButton_pressed"]
[connection signal="pressed" from="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/RandomButton" to="." method="_on_RandomButton_pressed"]
[connection signal="toggled" from="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/BoundariesButton" to="." method="_on_BoundariesButton_toggled"]
[connection signal="item_selected" from="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/BoundariesButton" to="." method="_on_BoundariesButton_item_selected"]
[connection signal="value_changed" from="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/WorldSizeContainer/WorldWidthContainer/WorldWidthSpinbox" to="." method="_on_WorldWidthSpinbox_value_changed"]
[connection signal="value_changed" from="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/WorldSizeContainer/WorldHeightContainer/WorldHeightSpinbox" to="." method="_on_WorldHeightSpinbox_value_changed"]
[connection signal="value_changed" from="VBoxContainer/Split/GeneralContainer/WorldSettingsContainer/ViscositySlider" to="." method="_on_ViscositySlider_value_changed"]
Expand Down
21 changes: 7 additions & 14 deletions LeifProject/simulation/WorldContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var GREEN := Globals.GREEN
var WHITE := Globals.WHITE
var BLUE := Globals.BLUE

var boundaries_enabled = true
var boundaries_type = Globals.BOUNDS_STRICT

var RED_PARTICLE_COUNT := 900
var GREEN_PARTICLE_COUNT := 900
Expand Down Expand Up @@ -105,10 +105,7 @@ func _reset_world() -> void:
world.free()
world = WORLD_SCENE.instance()
$Control/ViewportContainer/WorldViewport.add_child(world)
if boundaries_enabled:
world.BOUNDS_TYPE = Globals.BOUNDS_STRICT
else:
world.BOUNDS_TYPE = Globals.BOUNDS_DISABLED
world.BOUNDS_TYPE = boundaries_type

world.WORLD_SIZE = WORLD_SIZE
world.set_position(WORLD_OFFSET)
Expand Down Expand Up @@ -182,14 +179,6 @@ func _on_GUI_particle_count_applied(red: int, green: int, white: int, blue: int)
restart_simulation()


func _on_GUI_boundaries_enabled_toggle(value: bool):
boundaries_enabled = value
if value:
world.BOUNDS_TYPE = Globals.BOUNDS_STRICT
else:
world.BOUNDS_TYPE = Globals.BOUNDS_DISABLED


func _on_GUI_world_size_changed(new_size: Vector2):
WORLD_SIZE = new_size
WORLD_OFFSET = (BASE_SIZE - WORLD_SIZE) / 2
Expand All @@ -206,9 +195,13 @@ func _on_GUI_restart_world():


func _on_GUI_preset_selected(name):
print(name)
RuleLoader.change_current_rules(name)


func _on_GUI_viscosity_changed(value):
world.set_viscosity(value)


func _on_GUI_boundaries_changed(new_val):
boundaries_type = new_val
world.BOUNDS_TYPE = new_val
2 changes: 1 addition & 1 deletion LeifProject/simulation/WorldContainer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ margin_bottom = 12960.0

[connection signal="mid_changed" from="AudioController" to="." method="_on_AudioController_mid_changed"]
[connection signal="audio_file_selected" from="CanvasLayer2/GUI" to="." method="_on_GUI_audio_file_selected"]
[connection signal="boundaries_enabled_toggle" from="CanvasLayer2/GUI" to="." method="_on_GUI_boundaries_enabled_toggle"]
[connection signal="boundaries_changed" from="CanvasLayer2/GUI" to="." method="_on_GUI_boundaries_changed"]
[connection signal="music_stop" from="CanvasLayer2/GUI" to="." method="_on_GUI_music_stop"]
[connection signal="particle_count_applied" from="CanvasLayer2/GUI" to="." method="_on_GUI_particle_count_applied"]
[connection signal="preset_selected" from="CanvasLayer2/GUI" to="." method="_on_GUI_preset_selected"]
Expand Down
1 change: 1 addition & 0 deletions LeifProject/utility/Globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ const BLUE_COLOR := Color.aqua

const BOUNDS_DISABLED := 0
const BOUNDS_STRICT := 1
const BOUNDS_REPEATING := 2
10 changes: 7 additions & 3 deletions src/leif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void LeifParticle::_process(float delta) {
void LeifWorld::_register_methods() {
register_method("_process", &LeifWorld::_process);
register_method("rule", &LeifWorld::rule);
register_method("set_viscosity", &LeifWorld::set_viscosity);
register_method("_gather_particles", &LeifWorld::_gather_particles);
register_property<LeifWorld, Vector2>("WORLD_SIZE", &LeifWorld::WORLD_SIZE, Vector2(1920, 1080));
register_property<LeifWorld, int>("BOUNDS_TYPE", &LeifWorld::BOUNDS_TYPE, BOUNDS_STRICT);
Expand All @@ -64,6 +65,10 @@ LeifWorld::~LeifWorld() {
void LeifWorld::_init() {
}

void LeifWorld::set_viscosity(float v) {
LeifWorld::viscosity = 1.0 - v;
}

void LeifWorld::_gather_particles() {
Godot::print("Gathering particles");

Expand Down Expand Up @@ -149,7 +154,6 @@ void LeifWorld::rule(int p1name, int p2name, float G, float radius) {
void LeifWorld::_rule(std::vector<LeifParticle *> particles1, std::vector<LeifParticle *> particles2, float G, float radius, int p1_length, int p2_length) {
if (std::abs(G) < 0.1 || std::abs(radius) < 1.0) { return; }
const float g = G / -100;
const float epsilon = 0.0001;

omp_set_num_threads(4);
omp_set_nested(true);
Expand Down Expand Up @@ -207,8 +211,8 @@ void LeifWorld::_rule(std::vector<LeifParticle *> particles1, std::vector<LeifPa

Vector2 p1vel = p1->get_velocity();

p1vel.x = (p1vel.x + (fx * g)) * 0.5;
p1vel.y = (p1vel.y + (fy * g)) * 0.5;
p1vel.x = (p1vel.x + (fx * g)) * viscosity;
p1vel.y = (p1vel.y + (fy * g)) * viscosity;

if (BOUNDS_TYPE == BOUNDS_STRICT) {
if ((p1pos.x - WORLD_SIZE.x) > 0 && p1vel.x > 0) { p1vel.x *= -1; p1->set_pos_x(WORLD_SIZE.x);}
Expand Down
4 changes: 3 additions & 1 deletion src/leif.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const int WHITE = 2;
const int BLUE = 3;
const int BOUNDS_DISABLED = 0;
const int BOUNDS_STRICT = 1;
const int BOUNDS_REPEATING = 1;
const int BOUNDS_REPEATING = 2;

typedef wchar_t CharType;

Expand Down Expand Up @@ -63,6 +63,7 @@ class LeifWorld : public Node2D {
int PARTICLE_COUNT_WHITE = 1000;
int PARTICLE_COUNT_BLUE = 1000;

float viscosity = 0.5;

std::vector<LeifParticle *> red;
std::vector<LeifParticle *> green;
Expand All @@ -80,6 +81,7 @@ class LeifWorld : public Node2D {

void _process(float delta);

void set_viscosity(float val);
void _gather_particles();
void _rule(std::vector<LeifParticle *> particles1, std::vector<LeifParticle *> particles2, float G, float radius, int p1_length, int p2_length);
void rule(int p1name, int p2name, float G, float radius);
Expand Down

0 comments on commit 1890160

Please sign in to comment.