Best alternative?

Samael88

Evil always finds a way
Reaction score
181
Hello,
I was wondering if someone know wich are the most optimal for jassers to do between these:

Write the most functions in the map script thingy(where you can only write JASS) and then call them from triggers.

or

Let each trigger contain its necessary functions and write nothing in the map script.

Wich is best?
 

Viikuna

No Marlo no game.
Reaction score
265
I feel like helpping someone :D

Use vJass libraries and scopes

If you need to use some functions in many places, place them in one library.

If you need some function in only one trigger, then have it in same scope with your trigger.

The key is to make easy for you to find right functions when you need to edit them.

I hope this helps. Im not suprised if it does not.
 

Samael88

Evil always finds a way
Reaction score
181
I never use custom map script.

So it is slower to use that.
For the vJASS, I am working on learning that, I have downloaded all the stuff I need, newgen and all that. I just never have had the time since then to use it.
Can you use librarys without vJASS?
What does scope make any difference in terms of effectivity?
 

Vexorian

Why no custom sig?
Reaction score
187
If you have duplicates of functions embedded in triggers, you are making the functions hash fatter, and it will eventually make function calls in general slower. This is the only way in which picking where to put functions is related to performance.
 

N-a-z-g-u-l

New Member
Reaction score
30
actually... warcraft puts all your triggers in the map script when saving... the first script is the map script, then all your triggers and function calls to their initialization functions

"triggers" in jass are only handles which are hold in global variables

"triggers" in the trigger editor can help you organizing your scripts

theres no different in speed

(by the way, what do you need the speed for?)
just look through the functions and optimize them, or post a script to be optimized
 

Samael88

Evil always finds a way
Reaction score
181
If you have duplicates of functions embedded in triggers, you are making the functions hash fatter, and it will eventually make function calls in general slower. This is the only way in which picking where to put functions is related to performance.

Thank you vexorian:) You are actually the first one really trying to answer my question:D +rep to you:thup:
 

Samael88

Evil always finds a way
Reaction score
181
(by the way, what do you need the speed for?)

It came to my mind if it was possible to optimize the effectivity of my functions by putting them in a special place or something like that.

On the opimization part, is it not better to take numbers and return numbers in a function, else then letting th triggers work with units and points and other bigger stuff?
 

N-a-z-g-u-l

New Member
Reaction score
30
units and other "bigger stuff" are just integers poiting to some space in the memory, so i think there shouldnt be a big difference in speed

but again, what for? if your map is running fluently, everything is great^^ first steps to optimize your map would be to reduce the amount of units, reduce the amount of periodically running functions and their leaks and search for the triggers which are runned often, then try to remove useless function calls, BJs, locations, any other "bigger stuff" which is not really needed... then if you really need even more performance, do not create "bigger stuff" at all but have some of them in global variables so you can use them temporarly (recycling handles)
and of course, which is quite hard to do with a already written code, think about the structure in general
 

Samael88

Evil always finds a way
Reaction score
181
I try to think of the structure already when I'm writing the code, and the BJ:s I do not even use when I write.

I checked the blizzard.j file. A BJ to me seams like a function that only calls another function, is that correct?
If so it must mean that I just search blizzard.j to find the proper function and then call it myself. Am I wrong?

And the leaks you can also do pretty easy when you are writing the code to.

What are these handles you are talking about? I never really understood the handle things:confused:
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
BJ's are functions that call one or more natives, correct. If you use NewGen or Jasshelper, you dont need to find it in the Blizzard.j, you can look it up in the Native List. Much faster and easier ^^.
 

Samael88

Evil always finds a way
Reaction score
181
BJ's are functions that call one or more natives, correct. If you use NewGen or Jasshelper, you dont need to find it in the Blizzard.j, you can look it up in the Native List. Much faster and easier ^^.

Everything shall go fast today, what is wrong with the old fashion way of patience, it works better for me:D But do not think that I am old beacuse of that:eek:
 

N-a-z-g-u-l

New Member
Reaction score
30
a handle is a variable which holds more than one value... basically...^^

you can detect a handle this way:

JASS:
local location p = Location(0,0)
local location p2 = p
call RemoveLocation(p)
// p2 is a pointer to the same space in memory, it is removed, too!

local integer i = 100
local integer i2 = i
set i = 0
// i2 is still 100


so a handle works with a pointer to some space in the memory, and it uses its "value" just as a referrer, where integers just use the number to store the information

yes, everything is quite easy, but it takes time to learn, everything
and i assume that you did not write "perfect" code^^

if you want you can post a trigger executed very often and i will take a look ;) i bet i will find something to optimize^^
 

Samael88

Evil always finds a way
Reaction score
181
yes, everything is quite easy, but it takes time to learn, everything
and i assume that you did not write "perfect" code^^

if you want you can post a trigger executed very often and i will take a look ;) i bet i will find something to optimize^^

Thank you for you explanation:D Now i understand it a little better:thup:

I have not begun with the triggers yet, I have started to experiment with standard JASS just recently. I found it easier to start with just writing functions and call them with gui. I will post a function I made here, the first one actually:D

JASS:
globals
integer udg_Index
real udg_GravityForce
real array udg_Y_Velocity
boolean array udg_Up
real array udg_YA
real array udg_YB
unit array udg_Unit
endglobals           

function boolconvert takes integer udg_Index returns boolean
    if udg_Y_Velocity[udg_Index] <10 then
    return true
    else
    return false 
    endif
endfunction

function groundcheck takes integer udg_Index returns boolean
    if udg_YA[udg_Index] < 10 then
    set udg_Up[udg_Index] = true
    elseif ( GetBooleanAnd(boolconvert(udg_Index)==true, udg_Up[udg_Index]==true)) then
    set udg_Up[udg_Index] = false                           
    endif
    return udg_Up[udg_Index]
endfunction  

function MoveZ takes integer udg_Index returns real
    if udg_Up[udg_Index] == true then
    set udg_Y_Velocity[udg_Index] = (udg_Y_Velocity[udg_Index] - udg_GravityForce)
    set udg_YB[udg_Index] = udg_Y_Velocity[udg_Index] * 0.03
    set udg_YA[udg_Index] = udg_YA[udg_Index] + udg_YB[udg_Index]
    call groundcheck(udg_Index)
    call SetUnitFlyHeight(udg_Unit[udg_Index], udg_YA[udg_Index], 0)
    elseif udg_Up[udg_Index] == false then
    set udg_Y_Velocity[udg_Index] = (udg_Y_Velocity[udg_Index] + udg_GravityForce)
    set udg_YB[udg_Index] = udg_Y_Velocity[udg_Index] * 0.03
    set udg_YA[udg_Index] = udg_YA[udg_Index] - udg_YB[udg_Index]
    call groundcheck(udg_Index)
    call SetUnitFlyHeight(udg_Unit[udg_Index], udg_YA[udg_Index], 0)
    endif
    return udg_YA[udg_Index]
endfunction


It makes a ball bounce up and down and lose height for each bounce:) It is mui and works with about 70balls for now:) Think I can get it over a 150 if I make the trigger calling it in JASS to, or atleast I hope:)
You can please take a look at it if you want, I would really like to learn opimizing function atleast:) This one is written in directly into the map script, you know the place where you can only write. Hope you know what I mean:eek:

Edit: I mean more that 70 balls and it starts to lag, atleast on my computer:(
 

N-a-z-g-u-l

New Member
Reaction score
30
JASS:
globals
	integer udg_Index
	real udg_GravityForce
	real array udg_Y_Velocity
	boolean array udg_Up
	real array udg_YA
	real array udg_YB
	unit array udg_Unit
endglobals 

function MoveZ takes integer udg_Index returns real
	if udg_Up[udg_Index] then
		set udg_Y_Velocity[udg_Index] = (udg_Y_Velocity[udg_Index] - udg_GravityForce)
		set udg_YB[udg_Index] = udg_Y_Velocity[udg_Index] * 0.03
		set udg_YA[udg_Index] = udg_YA[udg_Index] + udg_YB[udg_Index]
	else
		set udg_Y_Velocity[udg_Index] = (udg_Y_Velocity[udg_Index] + udg_GravityForce)
		set udg_YB[udg_Index] = udg_Y_Velocity[udg_Index] * 0.03
		set udg_YA[udg_Index] = udg_YA[udg_Index] - udg_YB[udg_Index]
	endif
	if udg_YA[udg_Index] < 10 then
		set udg_Up[udg_Index] = true
	elseif udg_Y_Velocity[udg_Index]<10 and udg_Up[udg_Index] then
		set udg_Up[udg_Index] = false                       
	endif
	call SetUnitFlyHeight(udg_Unit[udg_Index], udg_YA[udg_Index], 0)
	return udg_YA[udg_Index]
endfunction


inlining helps improving the performance...

however, if you dont want to inline your functions, at least dont use GetBooleanAnd(), instead only "and", dont use == true

JASS:
function boolconvert takes integer udg_Index returns boolean
    return (udg_Y_Velocity[udg_Index] <10)
endfunction


create conditions in this way


by the way, i dont really understand why you use "up" there... just ALWAYS reduce the z speed by the gravity, and if the projectile hits the ground, set SpeedZ = -0.9*SpeedZ


thats how i would do it... and thats what i am calling "structure"^^
JASS:
globals
	integer udg_Index
	real udg_GravityForce
	real array udg_SpeedZ
	real array udg_Z
	unit array udg_Unit
endglobals 

function MoveZ takes integer udg_Index returns real
	set udg_SpeedZ=udg_SpeedZ-udg_GravityForce
	set udg_Z=udg_Z-udg_SpeedZ*0.03
	if udg_Z<=0 then
		set udg_Z = 0
		set udg_SpeedZ = -0.9*udg_SpeedZ
	endif
	call SetUnitFlyHeight(udg_Unit[udg_Index], udg_Z[udg_Index], 0)
	return udg_Z[udg_Index]
endfunction


and "takes integer udg_Index".... udg_Index is a global.... either you let the function take a parameter, or you set the global and make the function take nothing

and heres a slightly advanced system i made :D http://www.hiveworkshop.com/forums/resource.php?t=81933
 

Samael88

Evil always finds a way
Reaction score
181
Are you that N-a-z-g-u-l?
Dude, you are awesome, I have seen some screens on that map before and heard a lot about it, but never thought I would acctually write with the maker:rolleyes:

Thank you for teaching me this:) I will have all of this in mind when I work on my own physics engine:thup:
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Are you that N-a-z-g-u-l?
Dude, you are awesome, I have seen some screens on that map before and heard a lot about it, but never thought I would acctually write with the maker:rolleyes:

Thank you for teaching me this:) I will have all of this in mind when I work on my own physics engine:thup:

Yup, that's him. Creator of BTanks.

:p

Muahaha... I did your job for you! Now you don't feel as much pride. :rolleyes:
 

Samael88

Evil always finds a way
Reaction score
181
And by the way N-a-z-g-u-l.
This function you made, it does not really work like mine did:S
JASS:
globals
	integer udg_Index
	real udg_GravityForce
	real array udg_SpeedZ
	real array udg_Z
	unit array udg_Unit
endglobals 

function MoveZ takes integer udg_Index returns real
	set udg_SpeedZ=udg_SpeedZ-udg_GravityForce
	set udg_Z=udg_Z-udg_SpeedZ*0.03
	if udg_Z<=0 then
		set udg_Z = 0
		set udg_SpeedZ = -0.9*udg_SpeedZ
	endif
	call SetUnitFlyHeight(udg_Unit[udg_Index], udg_Z[udg_Index], 0)
	return udg_Z[udg_Index]
endfunction

You forget to check if they are going up or down, this function as it is written here makes the balls go up continuesly;)
That is why I had the up boolean, If i did not have that, they would had gone in only one direction, and either bounced nor come down depending on the formula:shades:
 

N-a-z-g-u-l

New Member
Reaction score
30
And by the way N-a-z-g-u-l.
This function you made, it does not really work like mine did:S
JASS:
globals
	integer udg_Index
	real udg_GravityForce
	real array udg_SpeedZ
	real array udg_Z
	unit array udg_Unit
endglobals 

function MoveZ takes integer udg_Index returns real
	set udg_SpeedZ=udg_SpeedZ-udg_GravityForce
	set udg_Z=udg_Z-udg_SpeedZ*0.03
	if udg_Z<=0 then
		set udg_Z = 0
		set udg_SpeedZ = -0.9*udg_SpeedZ
	endif
	call SetUnitFlyHeight(udg_Unit[udg_Index], udg_Z[udg_Index], 0)
	return udg_Z[udg_Index]
endfunction

You forget to check if they are going up or down, this function as it is written here makes the balls go up continuesly;)
That is why I had the up boolean, If i did not have that, they would had gone in only one direction, and either bounced nor come down depending on the formula:shades:


ah yes, my mistake... i am substracting the speed...

this way is right:

JASS:
globals
	integer udg_Index
	real udg_GravityForce
	real array udg_SpeedZ
	real array udg_Z
	unit array udg_Unit
endglobals 

function MoveZ takes integer udg_Index returns real
	set udg_SpeedZ[udg_Index]=udg_SpeedZ[udg_Index]-udg_GravityForce
	set udg_Z[udg_Index]=udg_Z+udg_SpeedZ[udg_Index]*0.03
	if udg_Z[udg_Index]<=0 then
		set udg_Z[udg_Index] = 0
		set udg_SpeedZ[udg_Index] = -0.9*udg_SpeedZ[udg_Index]
	endif
	call SetUnitFlyHeight(udg_Unit[udg_Index], udg_Z[udg_Index], 0)
	return udg_Z[udg_Index]
endfunction


moving down = SpeedZ<0, by the way
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      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