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