Page 1 of 1

turret code optimisation

Posted: Sat May 09, 2015 3:39 pm
by bobingabout
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:

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)(),
...
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:

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),
...
You'd need to make the same change to the laser turret too.
what do you think?

Re: turret code optimisation

Posted: Mon May 11, 2015 12:03 am
by bobingabout
Looking through other things, it looks like your worm turrets already use something similar, with scale and tint instead of frame, you just have 2 different versions for the different animations.

Re: turret code optimisation

Posted: Mon May 11, 2015 5:45 pm
by ssilk
it looks like your worm turrets already use something similar
Image
With whom are you talking? :)

Re: turret code optimisation

Posted: Tue May 12, 2015 4:59 pm
by bobingabout
ssilk wrote:
it looks like your worm turrets already use something similar
With whom are you talking? :)
Game Devs. The Worm turret code already uses a function similar to the one I'm sugesting they use for Gun turrets and Laser turrets.

Re: turret code optimisation

Posted: Tue May 12, 2015 5:31 pm
by ssilk
Image

Re: turret code optimisation

Posted: Thu Jun 04, 2015 2:33 pm
by slpwnd
@bobingabout Not sure about the performance improvement, but your suggested solution is more readable and cleaner so it was implemented.