Compare commits

..

No commits in common. "8b425898a1479fb0d85d3c9c40c6b5ec1ca282e7" and "926abae31bc4800e0f785724cc9ddbe6be6b58cb" have entirely different histories.

2 changed files with 34 additions and 92 deletions

View File

@ -84,7 +84,6 @@ class Vessel(N)
orders.sort!
order = orders.pop # remove last order and execute it
order.execute
# orders.unshift order if order.keep
order
end
end
@ -103,9 +102,8 @@ class Vessel(N)
class Order(N)
setter :station
getter :priority, :group
# property :keep
def initialize(@priority : Int32 = 0, @group : Symbol = :default, @station : Station(N)? = nil, @keep : Bool = false, &@block : Order(N) -> Nil)
def initialize(@priority : Int32 = 0, @group : Symbol = :default, @station : Station(N)? = nil, &@block : Order(N) -> Nil)
end
def to_s(io : IO) : Nil
@ -147,10 +145,10 @@ class Vessel(N)
property current_selected_body : Gravity::Body(N)?
# this is a hard limit for thrust so the pilot can avoid killing all the people aboard
property max_thrust
# permanent mode is the default modes to apply at all time
property permanent_modes : Array(Mode)
# permanent mode is the default mode to apply at all time
property permanent_mode
# temporary mode must be set at each tick and will be reset each time it is applied
property temporary_modes : Array(Mode)
property temporary_mode
enum Mode
Constant
@ -159,14 +157,17 @@ class Vessel(N)
AntiSpeed
end
@permanent_mode : Mode?
@temporary_mode : Mode?
def initialize(*p, **o)
super
@permanent_modes = Array(Mode).new
@temporary_modes = Array(Mode).new
@permanent_mode = nil
@temporary_mode = nil
@low_thrust_save = 0.0
@low_thrust_pressed = false
@computer_input_thrust = Vector(Float64, N).zero
@max_thrust = 20.0
@max_thrust = 10.0
@current_selected_body = nil
end
@ -189,37 +190,25 @@ class Vessel(N)
end
end
def immediate_modes : Array(Mode)
if !@temporary_modes.empty?
@temporary_modes
else
@permanent_modes
end
def immediate_mode
@temporary_mode || @permanent_mode
end
def apply_current_mode
new_acceleration_axis = Vector(Float64, N).zero
must_update_acceleration_axis = false
if immediate_modes.includes?(Mode::AntiGrav)
must_update_acceleration_axis = true
new_acceleration_axis.add!(-vessel.gravity)
end
if immediate_modes.includes?(Mode::AntiSpeed)
must_update_acceleration_axis = true
reset_acceleration = true
if immediate_mode == Mode::AntiGrav
# somehow it doesn't work as expected... :thinking:
set_exact_acceleration_axis(-vessel.gravity)
elsif immediate_mode == Mode::AntiSpeed
if (current_selected_body = @current_selected_body)
relative_speed = vessel.gravity_body.speed - current_selected_body.speed
new_acceleration_axis.add!(-relative_speed)
if relative_speed.magnitude > @max_thrust
relative_speed.normalize.mult!(@max_thrust)
end
set_exact_acceleration_axis(-relative_speed)
end
end
if new_acceleration_axis.magnitude > @max_thrust
new_acceleration_axis.normalize.mult!(@max_thrust)
end
set_exact_acceleration_axis(new_acceleration_axis) if must_update_acceleration_axis
@temporary_modes.clear # each time we apply the temporary_mode, reset it
@temporary_mode = nil # each time we apply the temporary_mode, reset it
end
def accelerate_current_vector!(coef : Float64)

View File

@ -54,16 +54,13 @@ module PhysicsSandboxDraw
draw_slider(
label: "###acceleration_analogue_x",
data: @vessel.gravity_body.acceleration[0],
min: -@vessel.pilot.max_thrust,
max: @vessel.pilot.max_thrust,
flags: (
ImGui::ImGuiSliderFlags::Logarithmic
),
) do |value|
@vessel.pilot.order(priority: 10, group: :acceleration_x) do
@vessel.pilot.set_exact_acceleration_axis(0, value)
@vessel.pilot.permanent_modes.clear
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::Constant
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::Constant
@vessel.pilot.low_thrust_pressed = false
@vessel.pilot.low_thrust_save = value
end
@ -73,16 +70,13 @@ module PhysicsSandboxDraw
draw_slider(
label: "###acceleration_analogue_y",
data: @vessel.gravity_body.acceleration[1],
min: -@vessel.pilot.max_thrust,
max: @vessel.pilot.max_thrust,
flags: (
ImGui::ImGuiSliderFlags::Logarithmic
),
) do |value|
@vessel.pilot.order(priority: 10, group: :acceleration_y) do
@vessel.pilot.set_exact_acceleration_axis(1, value)
@vessel.pilot.permanent_modes.clear
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::Constant
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::Constant
@vessel.pilot.low_thrust_pressed = false
@vessel.pilot.low_thrust_save = value
end
@ -98,11 +92,9 @@ module PhysicsSandboxDraw
draw_slider(
label: "###acceleration_low_analogic_x",
data: @vessel.gravity_body.acceleration[0],
min: -@vessel.pilot.max_thrust,
max: @vessel.pilot.max_thrust,
) do |value|
@vessel.pilot.order(priority: 10, group: :maneuvers) do
@vessel.pilot.temporary_modes << Vessel::Pilot::Mode::Pulse
@vessel.pilot.temporary_mode = Vessel::Pilot::Mode::Pulse
if !@vessel.pilot.low_thrust_pressed
@vessel.pilot.low_thrust_save = @vessel.gravity_body.acceleration[0]
end
@ -126,11 +118,9 @@ module PhysicsSandboxDraw
draw_slider(
label: "###acceleration_low_analogic_y",
data: @vessel.gravity_body.acceleration[1],
min: -@vessel.pilot.max_thrust,
max: @vessel.pilot.max_thrust,
) do |value|
@vessel.pilot.order(priority: 10, group: :maneuvers) do
@vessel.pilot.temporary_modes << Vessel::Pilot::Mode::Pulse
@vessel.pilot.temporary_mode = Vessel::Pilot::Mode::Pulse
if !@vessel.pilot.low_thrust_pressed
@vessel.pilot.low_thrust_save = @vessel.gravity_body.acceleration[1]
end
@ -159,8 +149,6 @@ module PhysicsSandboxDraw
draw_input(
label: "###acceleration_digit_x",
data: @vessel.pilot.computer_input_thrust[0],
min: -@vessel.pilot.max_thrust,
max: @vessel.pilot.max_thrust,
) do |value|
@vessel.pilot.order(priority: 9, group: :maneuvers) do
@vessel.pilot.computer_input_thrust[0] = value
@ -171,8 +159,6 @@ module PhysicsSandboxDraw
draw_input(
label: "###acceleration_digit_y",
data: @vessel.pilot.computer_input_thrust[1],
min: -@vessel.pilot.max_thrust,
max: @vessel.pilot.max_thrust,
) do |value|
@vessel.pilot.order(priority: 9, group: :maneuvers) do
@vessel.pilot.computer_input_thrust[1] = value
@ -181,42 +167,13 @@ module PhysicsSandboxDraw
},
"m/s²",
)
draw_table_line(
"[Security] Max thurst",
->{
draw_input(
label: "###pilot_input_max_thurst",
data: @vessel.pilot.max_thrust,
min: 9,
max: 900,
) do |value|
@vessel.pilot.max_thrust = value
end
},
->{
draw_slider(
label: "###pilot_slider_max_thurst",
data: @vessel.pilot.max_thrust,
min: 9,
max: 900,
) do |value|
@vessel.pilot.max_thrust = value
end
},
->{
ImGui.text @vessel.pilot.max_thrust > 20 ? "Inertia Dampers needed" : "No danger"
}
)
# Manual reset
draw_table_line(
"",
->{
if ImGui.button("Comfirm")
@vessel.pilot.order(priority: 100, group: :maneuvers) do
@vessel.pilot.permanent_modes.clear
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::Constant
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::Constant
@vessel.pilot.set_exact_acceleration_axis(@vessel.pilot.computer_input_thrust)
# @vessel.pilot.set_exact_acceleration_axis(0, @vessel.pilot.computer_input_thrust[0])
# @vessel.pilot.set_exact_acceleration_axis(1, @vessel.pilot.computer_input_thrust[1])
@ -226,8 +183,6 @@ module PhysicsSandboxDraw
->{
if ImGui.button("Reset")
@vessel.pilot.order(priority: 100, group: :prepare) do
@vessel.pilot.permanent_modes.clear
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::Constant
@vessel.pilot.set_exact_acceleration_axis(@vessel.pilot.computer_input_thrust)
# @vessel.pilot.computer_input_thrust[0] = @vessel.gravity_body.acceleration[0]
# @vessel.pilot.computer_input_thrust[1] = @vessel.gravity_body.acceleration[1]
@ -243,15 +198,14 @@ module PhysicsSandboxDraw
end
},
)
draw_table_line(
"",
# AntiGrav
->{
if !@vessel.pilot.permanent_modes.includes?(Vessel::Pilot::Mode::AntiGrav)
if @vessel.pilot.permanent_mode != Vessel::Pilot::Mode::AntiGrav
if ImGui.button("Anti-grav")
@vessel.pilot.order(priority: 10, group: :fly_mode) do
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::AntiGrav
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::AntiGrav
# @vessel.gravity_body.acceleration[0] = @vessel.gravity[0]
# @vessel.gravity_body.acceleration[1] = @vessel.gravity[1]
end
@ -259,8 +213,8 @@ module PhysicsSandboxDraw
else
if ImGui.button("Disable anti-grav")
@vessel.pilot.order(priority: 11, group: :fly_mode) do
if @vessel.pilot.permanent_modes.includes?(Vessel::Pilot::Mode::AntiGrav)
@vessel.pilot.permanent_modes.delete Vessel::Pilot::Mode::AntiGrav
if @vessel.pilot.permanent_mode == Vessel::Pilot::Mode::AntiGrav
@vessel.pilot.permanent_mode = nil
end
end
end
@ -269,10 +223,10 @@ module PhysicsSandboxDraw
# AntiSpeed
->{
if !@vessel.pilot.permanent_modes.includes?(Vessel::Pilot::Mode::AntiSpeed)
if @vessel.pilot.permanent_mode != Vessel::Pilot::Mode::AntiSpeed
if ImGui.button("Anti-speed")
@vessel.pilot.order(priority: 10, group: :fly_mode) do
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::AntiSpeed
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::AntiSpeed
@vessel.pilot.current_selected_body = @star.gravity_body
# @vessel.antispeed[0] = @vessel.speed[0]
# @vessel.antispeed[1] = @vessel.speed[1]
@ -281,15 +235,14 @@ module PhysicsSandboxDraw
else
if ImGui.button("Disable anti-speed")
@vessel.pilot.order(priority: 11, group: :fly_mode) do
if @vessel.pilot.permanent_modes << Vessel::Pilot::Mode::AntiSpeed
@vessel.pilot.permanent_modes.delete Vessel::Pilot::Mode::AntiSpeed
if @vessel.pilot.permanent_mode == Vessel::Pilot::Mode::AntiSpeed
@vessel.pilot.permanent_mode = nil
end
end
end
end
},
)
end
end