Snippet GetNearestUnit

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>An instant casted Chain Lightning which jumps thorugh each unit, from the closest to the farthest.

Well, the way I see it a chain lightning works basiclly in the following way:

1. a [ljass]lightning[/ljass] effect is created ruffly(maybe it has some z for example) from the origin of the caster to the spell target unit.
2. if number of jumps/bounces of the lightning > 0 go to 2.1. else END
---- 2.1. find the closest unit (matching some conditions ex: enemy) which is also not equall to the last spell-target/jump-target unit (otherwise the chain lightning will just hit the first spell target unit multiple times), decrement bounces and go to 2.

My point is that you always have to call GetNearestUnitEx(..., 1), in order for the spell to work properly because not all of the targets of the chain lightning would be located within the initial range of the spell, and this means that the sorting is pretty useless in this case because you don't actaully need GetNearstUnitEx(..., n).

A good example of where the sorting might do well (and no I am not using my imagiantion I am recalling from memory) would be the Healing Wave spell of the Head Hunter (one of orc's heros), the way it works is that after the initial healing of the spell target unit it jumps/finds the unit with least amount of hp and from there it jumps again and again, although the same thing applies here that you still need to call GetLowestHpUnit(..., 1) which again means the sorting is pretty useless.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
@Sgqvur

Dear mate, your coding is too ugly.....keep variable names more human.
Also this:
JASS:
set R1 = $x$ - GetUnitX(U0)
set R2 = $y$ - GetUnitY(U0)
set R3 = R1 * R1 + R2 * R2

is slower than this:
JASS:
set de=(GetUnitX(e)-x)*(GetUnitX(e)-x)+(GetUnitY(e)-y)*(GetUnitY(e)-y)


Sometimes speed doesn't matter when it comes to understanding.
If you want the fastest coding, work with "0/1"
 

lep

Active Member
Reaction score
8
jass helper updated?
Try it yourself. Or tell me where that [ljass]this[/ljass] comes from in the method shown below taken from the op.
Or tell me where it returns some value of type [ljass]thistype[/ljass].
JASS:


        static method for takes real x, real y, real r, boolexpr c returns thistype
            local List node
            local unit e
            call GroupEnumUnitsInRange(bj_lastCreatedGroup,x,y,r,c)
            loop
                set e = FirstOfGroup(bj_lastCreatedGroup)
                exitwhen e==null
                set node = List.allocate()
                set node.unit = e
                set node.distance = (GetUnitX(e)-x)*(GetUnitX(e)-x)+(GetUnitY(e)-y)*(GetUnitY(e)-y)
                call base.insertNode(node)
                call GroupRemoveUnit(bj_lastCreatedGroup,e)
            endloop
            call sort(this)
            set e = null
        endmethod


Also: 0.A.2.B.
 

Dirac

22710180
Reaction score
147
My bad, forgot to change the "returns thistype" to "returns nothing" from the previous version.
Code updated with the fix, it now compiles
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>Dear mate, your coding is too ugly.....keep variable names more human.

You mean more human-readable? The point of the script was:
"Well, actually the fastest way to do it, that I know of would be this:"
For whatever/uknown reason Jass2/bytecode or something executes slower with longer variable names.

>Also this:
Jass:

set R1 = $x$ - GetUnitX(U0)
set R2 = $y$ - GetUnitY(U0)
set R3 = R1 * R1 + R2 * R2

is slower than this:
set de=(GetUnitX(e)-x)*(GetUnitX(e)-x)+(GetUnitY(e)-y)*(GetUnitY(e)-y)


What?! No offence but lets try to count the operations, mate:

3 liner:
asignments = 3
additions = 1
subtractions = 2
multiplication = 2
natives called = 2
total = 10 (of which only two function calls, i.e the slowest operations in this case)

1 liner:
asignments = 1
additions = 1
subtractions = 4
multiplication = 2
natives called = 4
total = 12 (of which 4 are function calls)


=)
 

Dirac

22710180
Reaction score
147
You forgot local declaration or global read, which are actually slower
And I have proof

But in this case declaring locals to operate might increase effiency.
When i have the time i'll update.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
@Sgqvur

"For whatever/uknown reason Jass2/bytecode or something executes slower with longer variable names."
Dude you act like getting a intel core i7-3960X processor to have better experience in microsoft word.

Well your idea is making 10 actions and my 12......so what. I don't use locals to declare, and the assignments and maths are done in the native lang and not in jass.
 

Laiev

Hey Listen!!
Reaction score
188
When you call the same function multiply times in a row (like [ljass]GetUnitX[/ljass] in the example) is more efficient and faster you store it in a variable and use the variable.
 

lep

Active Member
Reaction score
8
The fastest, easiest and with more flexible way to retrieve the nearest unit from a point

[…]

It is nice that you reuse other libraries but this really is not the fastest way to get the unit(s).
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top