• 🏆 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!

Need help to get rid of these BJs.

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
Hi all. I need help to get rid of the following BJs. What are the more efficient ways?
JASS:
function Trig_Begin_Survival_______uActions takes nothing returns nothing
    local integer index
    local force for
    
    set for= GetPlayersAll()
    set index = 0
    loop
        exitwhen index >= 16
        if IsPlayerInForce(Player(index), for) then
            call PanCameraToTimedLocForPlayer( Player(index), GetRectCenter(gg_rct_xiao), 0 )
            call CreateFogModifierRectBJ( true, Player(index), FOG_OF_WAR_VISIBLE, gg_rct_KJD )
            call SetPlayerFlagBJ( PLAYER_STATE_GIVES_BOUNTY, true, Player(index) )
            call SetPlayerStateBJ( Player(index), PLAYER_STATE_RESOURCE_FOOD_CAP, 120 )
        endif
        set index = index + 1
    endloop
    call CreateFogModifierRectBJ( true, Player(11), FOG_OF_WAR_MASKED, gg_rct________104 )
    call DisableTrigger( GetTriggeringTrigger() )
    call EnableTrigger( gg_trg_TZ )
    call DestroyTrigger( GetTriggeringTrigger() )
    
    set for= null
endfunction

and this:
JASS:
all CreateTextTagLocBJ( "TRIGSTR_15046", udg_SDPoint, 50.00, 10, 15.00, 15.00, 100, 0 )
 
If you're using JNGP, you could always check the function list, look for those BJ, click them and see what functions they call... then just use those functions directly... that would do the work, normally...

btw

JASS:
local integer index
    local force for
    
    set for= GetPlayersAll()
    set index = 0

can be

JASS:
local integer index = 0
local force for = GetPlayersAll()
 
Level 11
Joined
Oct 11, 2012
Messages
711
If you're using JNGP, you could always check the function list, look for those BJ, click them and see what functions they call... then just use those functions directly... that would do the work, normally...

btw

JASS:
local integer index
    local force for
    
    set for= GetPlayersAll()
    set index = 0

can be

JASS:
local integer index = 0
local force for = GetPlayersAll()

I did that, but sometimes there are BJs inside a BJ, so what should I do? For example:
JASS:
function CreateTextTagLocBJ takes string s, location loc, real zOffset, real size, real red, real green, real blue, real transparency returns texttag
    set bj_lastCreatedTextTag = CreateTextTag()
    call SetTextTagTextBJ(bj_lastCreatedTextTag, s, size)
    call SetTextTagPosBJ(bj_lastCreatedTextTag, loc, zOffset)
    call SetTextTagColorBJ(bj_lastCreatedTextTag, red, green, blue, transparency)

    return bj_lastCreatedTextTag
endfunction
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Just go through the function list in the Trigger Editor.
i.e.
JASS:
function SetTextTagPosBJ takes texttag tt, location loc, real zOffset returns nothing
    call SetTextTagPos(tt, GetLocationX(loc), GetLocationY(loc), zOffset)
endfunction
and ofc you don't want to use locations.
JASS:
native SetTextTagPos takes texttag t, real x, real y, real heightOffset returns nothing

or
JASS:
function SetTextTagTextBJ takes texttag tt, string s, real size returns nothing
    local real textHeight = TextTagSize2Height(size)

    call SetTextTagText(tt, s, textHeight)
endfunction
is just
JASS:
native SetTextTagText takes texttag t, string s, real height returns nothing
bj_lastCreatedTextTag --> local texttag text = CreateTextTag()
 
Level 11
Joined
Oct 11, 2012
Messages
711
Just go through the function list in the Trigger Editor.
i.e.
JASS:
function SetTextTagPosBJ takes texttag tt, location loc, real zOffset returns nothing
    call SetTextTagPos(tt, GetLocationX(loc), GetLocationY(loc), zOffset)
endfunction
and ofc you don't want to use locations.
JASS:
native SetTextTagPos takes texttag t, real x, real y, real heightOffset returns nothing

or
JASS:
function SetTextTagTextBJ takes texttag tt, string s, real size returns nothing
    local real textHeight = TextTagSize2Height(size)

    call SetTextTagText(tt, s, textHeight)
endfunction
is just
JASS:
native SetTextTagText takes texttag t, string s, real height returns nothing
bj_lastCreatedTextTag --> local texttag text = CreateTextTag()

Thank you BPower. :) +Rep if I can.
 
What's wrong with using the BJ's?

As Adiktuz said, but I'd like to add that there are certain BJ's which are useful. For example, TriggerRegisterAnyUnitEventBJ(), or the RMinBJ() and RMaxBJ() functions. Inlining everything is wasteful (it can increase the map size and lead to code bloat), but you should inline the BJ's that are simply swapped parameters from the original function. Just inline with a practical state of mind. :)
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Well, basically, it's more efficient (performance wise) if there are less function calls... so since a BJ just calls another set of natives (+there are BJs that call a single native), it's better to just skip the BJ and use the natives themselves...

Wouldn't that make the code harder to read though?

I don't suppose vjASS could just do this automatically then when it translates it into the actual JASS script?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Wouldn't that make the code harder to read though?

Naa it is easier to read IMO.

I don't suppose vjASS could just do this automatically then when it translates it into the actual JASS script?

No it does not. It would be nice if it did though.

Also Another reason BJs aren't used is that some of them leak locals which is not acceptable in jass / vJass coding.

Most are just swapped versions of natives. Which makes no sense in why blizzard did such things when making GUI.
 
Level 11
Joined
Oct 11, 2012
Messages
711
As Adiktuz said, but I'd like to add that there are certain BJ's which are useful. For example, TriggerRegisterAnyUnitEventBJ(), or the RMinBJ() and RMaxBJ() functions. Inlining everything is wasteful (it can increase the map size and lead to code bloat), but you should inline the BJ's that are simply swapped parameters from the original function. Just inline with a practical state of mind. :)

Thanks, PnF.

Edit:
Oh, didn't notice the continues discussion in this thread.
Thanks everyone. :)
 
I don't think you need to replace all those BJs to natives, since they do all the work. I actually think those BJs are the useful ones too.

As DIMF said, BJs leaks locals for most of time, that's unacceptable in Jass or Vjass coding, GUI coding is under exception of this however, because GUI uses BJ.
 
Status
Not open for further replies.
Top