Laggy Neutrinos

  • DanielGalrito
    6th Apr 2015 Member 0 Permalink

    Im trying to code an element (which name you'll never guess :P) that goes throught other elements like protons and I understand enough of sim.can_move to use it but when I use it to go throught many kinds of elements 1000 pixels are enough to kill the fps. thats the code chunk i used:

    for all = 1,255 do
    sim.can_move(tpt.element('ntno'), all, 2)
    end

     

    How can i make this not laggy? I've seen another script that has this function set for 255 and doesn't lag. (TPTMod script)

    Edited once by DanielGalrito. Last: 6th Apr 2015
  • Lord_Bowserinator
    6th Apr 2015 Member 0 Permalink

    Try this? (Swap the all and tpt.element('ntno'))

    for i=1,255 do
        sim.can_move(i,tpt.element('ntno'),2)
    end

    Edited once by Lord_Bowserinator. Last: 6th Apr 2015
  • DanielGalrito
    6th Apr 2015 Member 0 Permalink

    It's still laggy :(

  • Lord_Bowserinator
    6th Apr 2015 Member 0 Permalink

    Can I see your whole script? 

  • jacob1
    6th Apr 2015 Developer 0 Permalink
    Yeah, this part of the script isn't going to make it lag at all, it just makes your element move through other elements. Does it have an update function or a graphics function? Those are what cause all the lag for lua elements.
  • EE
    6th Apr 2015 Banned 0 Permalink
    This post is hidden because the user is banned
    Edited once by EE. Last: 6th Apr 2015
  • DanielGalrito
    7th Apr 2015 Member 0 Permalink

    local Ntno = elements.allocate("Ntno", "NTNO")
    elements.element(Ntno, elements.element(elements.DEFAULT_PT_ELEC))
    elements.property(Ntno, "Name", "NTNO")
    elements.property(Ntno, "Colour", 0xFFDFEFFF)
    elements.property(Ntno, "Description", "Neutrino, neutral electron, created by beta- decay and matter-antimatter reactions.")
    elements.property(Ntno, "Weight", -1)
    elements.property(Ntno, "HeatConduct", 0)
    elements.property(Ntno, "Temperature", 295.15)
    elements.property(Ntno, "Properties" , 0x14010)
    elements.property(Ntno, "AirLoss", 1)
    elements.property(Ntno, "Loss", 1)
    elements.property(Ntno, "Collision", -0.99)

    function Ntno(i, x, y, surround, nt)
    if tpt.get_property("tmp2", i) == 0 then
    local a = (math.random(360)-1) * 0.01745329;
    tpt.set_property("life",680,i)
    tpt.set_property("vx",10*math.cos(a),i)
    tpt.set_property("vy",10*math.sin(a),i)
    tpt.set_property("tmp2",1,i)
    end

    for i = 1,255 do
    sim.can_move(i, tpt.element('ntno'), 2)
    end
    end
    tpt.element_func(Ntno, tpt.element('ntno'))

     

    I won't show the whole script because its a ton of code but this is all i got from neutrinos, they're the only particle with sim.can_move (apart from anti-neutrinos) and they're the only that lag.

  • jacob1
    7th Apr 2015 Developer 0 Permalink
    @DanielGalrito (View Post)
    The lag is probably just due to the update function itself. But you can fix most of it really easily. sim.can_move only needs to ever be run once. Update functions are for things that have to happen every frame. They are for reactions and reactions only. Properties like what they move through are set separately.

    So ... move the for loop with the sim.can_move outside of the function and it becomes a lot less laggy.
  • DanielGalrito
    7th Apr 2015 Member 0 Permalink

    So how should the sim.cam_move line be? Can you write it please? :3 And thanks for the help.

  • jacob1
    7th Apr 2015 Developer 0 Permalink
    ...
    elements.property(Ntno, "Loss", 1)
    elements.property(Ntno, "Collision", -0.99)
    for i = 1,255 do
    sim.can_move(Ntno, i, 2)
    end

    function Ntno(i, x, y, surround, nt)
    if tpt.get_property("tmp2", i) == 0 then
    ...
    Edited once by jacob1. Last: 9th Apr 2015