turret code optimisation
Posted: Sat May 09, 2015 3:39 pm
This isn't really a bug, but then there's no place I can see that would be best to place this kind of sugestion.
I have an idea that could improve the code for your turret animation definitions a little.
This is what you have:
I sugest that instead of making a table first, you make a function, and remove the deepcopy function from within the turret code. the result would be this:
You'd need to make the same change to the laser turret too.
what do you think?
I have an idea that could improve the code for your turret animation definitions a little.
This is what you have:
Code: Select all
gun_turret_extension =
{
filename = "__base__/graphics/entity/gun-turret/gun-turret-extension.png",
priority = "medium",
width = 171,
height = 102,
direction_count = 4,
frame_count = 5,
axially_symmetrical = false,
shift = {1.34375, -0.5 + 0.6}
}
...
folded_animation = (function()
local res = util.table.deepcopy(gun_turret_extension)
res.frame_count = 1
res.line_length = 1
return res
end)(),
preparing_animation = gun_turret_extension,
folding_animation = (function()
local res = util.table.deepcopy(gun_turret_extension)
res.run_mode = "backward"
return res
end)(),
...
Code: Select all
function gun_turret_extension(run_mode, frames)
return
{
filename = "__base__/graphics/entity/gun-turret/gun-turret-extension.png",
frame_count = frames,
line_length = frames,
width = 171,
height = 102,
priority = "medium",
direction_count = 4,
axially_symmetrical = false,
shift = {1.34375, 0.1},
run_mode = run_mode,
}
end
...
folded_animation = laser_turret_extension("forward", 1),
preparing_animation = laser_turret_extension("forward", 5),
folding_animation = laser_turret_extension("backward", 5),
...
what do you think?