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.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top