Is there a way to speed this function

RangerX

I am justice!
i need to make this function run faster is there any way ?

JASS:
function SlideUnit takes unit u , location startloc , location endloc , real speed returns nothing
local real dx = GetLocationX(endloc) - GetLocationX(startloc)
local real dy = GetLocationY(endloc) - GetLocationY(startloc)
local real x
local real y
local real distreal
local real anglereal
local location a = startloc
local location b = endloc
local location c = GetUnitLoc(u)
set distreal = SquareRoot(dx * dx + dy * dy)
set anglereal = AngleBetweenPoints(a,b)
loop
    exitwhen distreal <= 50
    set x = GetLocationX(c) + 25 * Cos(anglereal * bj_DEGTORAD)
    set y = GetLocationY(c) + 25 * Sin(anglereal * bj_DEGTORAD)
    call SetUnitX(u,x)
    call SetUnitY(u,y)
    call SetUnitFacing(u,anglereal)
    set c = GetUnitLoc(u)
    set dx = GetLocationX(b)- GetLocationX(c)
    set dy = GetLocationY(b)- GetLocationY(c)
    set distreal = SquareRoot(dx * dx + dy * dy)
    set anglereal = AngleBetweenPoints(c,b)
    call TriggerSleepAction(speed)
    
endloop
endfunction


i used this custom script to run the function

Trigger:
  • Custom script: call SlideUnit(bj_lastCreatedUnit,udg_Temp_Loc,udg_Temp_Loc2,0.01)


but it's run very slow :|
it's just sliding the unit to a point :| ...
 

Jedi

New Member
That is because TriggerSleepAction has problems with low numbers(0.00 - 0.30, even 0.00 will run slowly).You should use timer instead.
 

Dinowc

don't expect anything, prepare for everything
and avoid using locations
they do nothing but converting 2 reals into 1 handle...
they shouldn't even be called natives :nuts:

also you don't need to recalculate reals that have the same value during the whole instance
for example:
set anglereal = AngleBetweenPoints(c,b)
this will always be the same angle as long as your unit doesn't steer during the slide
so put it outside the loop
 

RangerX

I am justice!
That is because TriggerSleepAction has problems with low numbers(0.00 - 0.30, even 0.00 will run slowly).You should use timer instead.
how can you please explain how can i use timer as an wait command ?
 

Ayanami

칼리
You could use a periodic timer, however, it would be difficult to transfer your data such as your unit, etc, if a global variable is used. Thus, I recommend using Structs and Key Timers 2.

JASS:
library Slide

struct Slide
    unit u
    real speed
    real angle
    real dist
endstruct

private function SlideUnit takes nothing returns boolean
    local Slide d = KT_GetData()
    if d.dist <= 0 then
        set d.u = null
        call d.destroy()
        return true
    endif
    call SetUnitX(d.u, GetUnitX(d.u) + d.speed * Cos(d.angle))
    call SetUnitY(d.u, GetUnitY(d.u) + d.speed * Sin(d.angle))
    set d.dist = d.dist - d.speed
    return false
endfunction

public function Register takes unit u, location endloc, real interval, real offset returns nothing
    local Slide d = Slide.create()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real lx = GetLocationX(endloc)
    local real ly = GetLocationY(endloc)
    local real dx = x - lx
    local real dy = y - ly
    set d.u = u
    set d.dist = SquareRoot(dx * dx + dy * dy)
    set d.angle = Atan2(ly - y, lx - x)
    set d.speed = offset
    call KT_Add(function SlideUnit, d, interval)
endfunction

endlibrary


And to call the function, it'll be:

Trigger:
  • Actions
    • Custom script: call Slide_Register(MyUnit, MyLoc, MyInterval, MyOffset)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • tom_mai78101 tom_mai78101:
    I have a GIF though
  • tom_mai78101 tom_mai78101:
    In the GIF, I've configured it so the lower the "Main Value" is, the better. I had to compress it pretty far down though.
  • tom_mai78101 tom_mai78101:
    And this is the thread with the video that shows the wall clip. https://tasvideos.org/Forum/Topics/23453
    +2
  • tom_mai78101 tom_mai78101:
    Hmm, about the Headline News, I noticed threads are being moved into the subforum (Health News, Environmental News, etc.). When that happens, the TH Forum Home page loses the articles, and instead would show old articles posted 1 or 2 weeks ago.
  • tom_mai78101 tom_mai78101:
    What do we do with the Home page?
  • Ghan Ghan:
    I added those forums to the filter for that widget.
  • tom_mai78101 tom_mai78101:
    Oh nice. They're back. Thanks.
  • tom_mai78101 tom_mai78101:
    Now I think it makes more sense for me to put news in their own subforums, without worry.
  • The Helper The Helper:
    Awesome Ghan thanks! I was purposely not moving the first 15 news articles in Headline news to the different subforums but I guess I don't have to do that now?
  • tom_mai78101 tom_mai78101:
    Question: Is there a way to remove thread redirects? It creates a copy of the moved thread and takes up space, and I am leaning towards wanting to remove them in the Headline News. But if they have an expiration date, I guess I'm fine with it.
  • The Helper The Helper:
    If you move a thread please leave a permanent redirect. You can delete any redirects after 6 months. The redirects are left to help Search Engines find the moved content.
  • tom_mai78101 tom_mai78101:
    What if you move the permanent redirect, not the thread?
  • The Helper The Helper:
    I think that works but I have not messed with it. You can delete redirects though if you have to that will not delete the original thread
  • The Helper The Helper:
    if a redirect ends up in the same forum as the post it goes to though I think the redirect drops or fails or something but they are not bugged out and when you are working on an indirect the original post is safe.
  • The Helper The Helper:
    Happy Early Friday :)
    +1
  • V-SNES V-SNES:
    Happy Friday :)
  • tom_mai78101 tom_mai78101:
    Fun Friday for me
  • tom_mai78101 tom_mai78101:
    Happy Fun Friday to all.
    +2
  • The Helper The Helper:
    Happy Sunday everyone!!!
  • V-SNES V-SNES:
    Happy Sunday!!!
    +1
  • jonas jonas:
    Happy monday :p
  • jonas jonas:
    Everyone hates mondays?
    +1
  • The Helper The Helper:
    Happy Tuesday!
  • jonas jonas:
    Happy belated tuesday

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top