• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Is there a point in creating a "point" struct?

Status
Not open for further replies.
Level 13
Joined
Jan 2, 2016
Messages
973
JASS:
struct point
    real x
    real y
endstruct
Is there a point to create such struct, since WE already provides location.
Both this struct, and the location needs creating and destroying, so I don't really see a reason to use point instead of location.

Anyone has a different point of view?
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
I think the speed difference would be negligible. In terms of compiled JASS script, it's not that bad having your own point struct, just a few functions and array variables added. If it would speed up your map development significantly (due to syntax), then I say go. Plus instead of leaking handle locations, you would leak struct indices instead.
I'm just pointing out the two sides of the coin.
 
Level 13
Joined
Nov 7, 2014
Messages
571
I would compare them with each other in 5 secs
Array reads (x // p.x in vJass ) can't possible be slower than native function calls (GetLocationX(p)... so no point in doing a comparison =).

Also if one uses a native location for representing points they would be restricted to having only x and y coordinates, because there's no arbitrary SetLocationZ(p, z) (only MoveLocation(p, x, y)).
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
guys guys guys
why are you talking like "struct" is a jass native or something?
can you simply compile the function using 1st and 2nd type and provide FINAL jass code? I would compare them with each other in 5 secs
The compiled JASS script is not the only factor. Besides like I said, it will only add a few lines and array variables in wc3map.j (whatever the script name file is) .If you're too hurt by that, you can always use a custom Alloc (like the one in Spells section by Nestharus) to lessen the generated script by default allocator of JassHelper.
 
Level 13
Joined
Jan 2, 2016
Messages
973
I read somewhere, that a native function is faster than a BJ function call (even if it does nothing).
I would imagine that custom functions will be as slow as BJ functions, thus adding methods to this struct would not appeal to the "speed demons", who care a lot about code's speed efficiency.
 
Level 19
Joined
Dec 12, 2010
Messages
2,069
I read somewhere, that a native function is faster than a BJ function call (even if it does nothing).
I would imagine that custom functions will be as slow as BJ functions, thus adding methods to this struct would not appeal to the "speed demons", who care a lot about code's speed efficiency.
JASS:
function mySetUnitVertexColor takes unit u, integer r, integer g, integer b, integer a returns nothing
    call SetUnitVertexColor(u,r,g,b,a)
endfunction

call SetUnitVertexColor(udg_Hero[1],100,60,200,200)//x500
call mySetUnitVertexColor(udg_Hero[1],100,60,200,200)//x500
400-500 % difference, yet not even touches 1ms (~200 for native, ~800-900 for custom)

as I just said at speed test topic, depends on amount of arguments passed
JASS:
function mySetUnitVertexColor takes nothing returns nothing
    call SetUnitVertexColor(udg_Hero[1],100,60,200,200)
endfunction

call SetUnitVertexColor(udg_Hero[1],100,60,200,200)//x500
call mySetUnitVertexColor()//x500
diff ~40%
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I read somewhere, that a native function is faster than a BJ function call (even if it does nothing).
I would imagine that custom functions will be as slow as BJ functions, thus adding methods to this struct would not appeal to the "speed demons", who care a lot about code's speed efficiency.

Code efficiency is not top priority though.
The top priority is maintainability, readability, etceterability of the code.
The simple BJ functions are just redirects with sometimes swapped arguments.
Some BJ functions like ModuloReal/Integer, RMinBJ, RMaxBJ, RAbsBJ, RSignBJ, (integer versions), TriggerRegisterPlayerUnitEvents, etc. are still useful as you would want to keep most of those things inside functions anyway.

Ofcourse, you could inline those functions but that goes at the cost of the readability of the code.
 
Status
Not open for further replies.
Top