Heavy optimizations at the cost of spaghetti code
This commit is contained in:
@@ -7,6 +7,7 @@ local defaultTable = {
|
||||
set_trm_aggression = 200,
|
||||
set_mode = 1,
|
||||
set_silent = 0,
|
||||
previous_velocity_x_in = 0,
|
||||
acceleration = 0,
|
||||
}
|
||||
|
||||
@@ -24,45 +25,54 @@ local signalReceived = function(signal, connection)
|
||||
local mem = allItems[this]
|
||||
|
||||
local signalNum = tonumber(signal.value) or defaultTable[connection.Name]
|
||||
local set_mode = mem.set_mode
|
||||
|
||||
if mem[connection.Name] == signalNum then
|
||||
if
|
||||
mem[connection.Name] == signalNum or
|
||||
connection.Name == "current_velocity_x_in" and set_mode ~= 0
|
||||
then
|
||||
return
|
||||
end
|
||||
|
||||
if connection.Name == "current_velocity_x_in" then
|
||||
mem.acceleration = (signalNum - mem.current_velocity_x_in)
|
||||
mem.current_velocity_x_in = signalNum
|
||||
else
|
||||
mem[connection.Name] = signalNum
|
||||
end
|
||||
mem[connection.Name] = signalNum
|
||||
|
||||
local main_force_out
|
||||
local boost_force_out
|
||||
local velocity_x_in = mem.velocity_x_in
|
||||
|
||||
if mem.set_mode == 1 then
|
||||
main_force_out = mem.velocity_x_in
|
||||
if set_mode == 1 then
|
||||
main_force_out = velocity_x_in
|
||||
boost_force_out = 0
|
||||
|
||||
elseif mem.set_mode == 2 then
|
||||
main_force_out = mem.velocity_x_in
|
||||
boost_force_out = mem.velocity_x_in
|
||||
elseif set_mode == 2 then
|
||||
main_force_out = velocity_x_in
|
||||
boost_force_out = velocity_x_in
|
||||
|
||||
elseif mem.set_mode == 0 then
|
||||
local absolute_current_velocity = math.abs(mem.current_velocity_x_in)
|
||||
if mem.set_trm_target - 0.25 < absolute_current_velocity and mem.velocity_x_in * mem.current_velocity_x_in > 0 then
|
||||
local target_acceleration = - (absolute_current_velocity * mem.set_trm_aggression) + (mem.set_trm_target * mem.set_trm_aggression)
|
||||
elseif set_mode == 0 then
|
||||
local current_velocity_x_in = mem.current_velocity_x_in
|
||||
local set_trm_target = mem.set_trm_target
|
||||
|
||||
if math.abs(mem.velocity_x_in) > math.abs(target_acceleration) then
|
||||
if mem.current_velocity_x_in > 0 then
|
||||
if connection.Name == "current_velocity_x_in" then
|
||||
mem.acceleration = (mem.previous_velocity_x_in - current_velocity_x_in)
|
||||
mem.previous_velocity_x_in = current_velocity_x_in
|
||||
end
|
||||
|
||||
local absolute_current_velocity = math.abs(current_velocity_x_in)
|
||||
if set_trm_target - 0.25 < absolute_current_velocity and velocity_x_in * current_velocity_x_in > 0 then
|
||||
local set_trm_aggression = mem.set_trm_aggression
|
||||
local target_acceleration = - (absolute_current_velocity * set_trm_aggression) + (set_trm_target * set_trm_aggression)
|
||||
|
||||
if math.abs(velocity_x_in) > math.abs(target_acceleration) then
|
||||
if current_velocity_x_in > 0 then
|
||||
main_force_out = target_acceleration
|
||||
else
|
||||
main_force_out = -target_acceleration
|
||||
end
|
||||
else
|
||||
main_force_out = mem.velocity_x_in
|
||||
main_force_out = velocity_x_in
|
||||
end
|
||||
else
|
||||
main_force_out = mem.velocity_x_in
|
||||
main_force_out = velocity_x_in
|
||||
end
|
||||
|
||||
boost_force_out = 0
|
||||
|
Reference in New Issue
Block a user