turret code optimisation

This subforum contains all the issues which we already resolved.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

turret code optimisation

Post 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?
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: turret code optimisation

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: turret code optimisation

Post by ssilk »

it looks like your worm turrets already use something similar
Image
With whom are you talking? :)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: turret code optimisation

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: turret code optimisation

Post by ssilk »

Image
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: turret code optimisation

Post by slpwnd »

@bobingabout Not sure about the performance improvement, but your suggested solution is more readable and cleaner so it was implemented.
Post Reply

Return to “Resolved Problems and Bugs”