• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Struct variable using speed

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

I don't know any better title for asking what I want, so I hope you'll understand what I mean.

I have 2 vJass libraries for example. The first on is the MapInit library, which initialize all "static variables":
JASS:
library MapInit initializer init

    struct Mapinit
        static integer game_integer = 0
        static real game_value    = 0.
        // and so on

In my second Temp library I wanna use these statics now, so I do:
JASS:
library Temp initializer init uses MapInit

    static method create takes nothing returns thistype
        local thistype this = .allocate()

        set MapInit.game_integer = MapInit.game_integer + 1
        set MapInit.game_real = MapInit.game_real + 1.337
    endmethod
endlibrary

Okay the thing is in my other libraries I use these statics a lot, so I asked myself which way would be the best and/or the fastes and/or the most effective:

1: I use them as I showed you above.
2: I store them into local variables in the temp library and refer always to the local instead of the static variable
3: I store them into a normal struct variable in the temp library and refer to the struct variable instead of the static one.

Edit: And please if you can, try also to give a reason why you say which is best/faster/most effective, because it's one point to know what, but its another point to know why =D

Greetings - Thanks and Peace
Dr. Boom
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
Im not the best vJasser here but you dont need MapInit library for initializing, the values in structs are globals anyways(static are normal, without prefix are arrayed for use of this - struct instance) so they are initialized anyways
about 1, 2, 3, well I dont know how would you want to make 2.

basically:
JASS:
struct ABC
    static integer abc = 0
    static real abd = 0
    static method create takes nothing returns thistype
        local thistype this = .allocate()
        call BJDebugMsg(I2S(.abc))
        call BJDebugMsg(R2S(.abd))
        set .abd = .abd + 1
        set .abc = .abc + 1
        return this
    endmethod
endstruct
will create this:
JASS:
globals
    integer s_ABC_abc = 0
    real s_ABC_abd = 0
endglobals

function create takes nothing returns nothing
    call BJDebugMsg(I2S(s_ABC_abc))
    call BJDebugMsg(R2S(s_ABC_abd))
    set s_ABC_abd = s_ABC_abd + 1
    set s_ABC_abc = s_ABC_abc + 1
endfunction
+some shitty stuff, the whole thing of this looks like:
JASS:
constant integer si__ABC=1
integer si__ABC_F=0
integer si__ABC_I=0
integer array si__ABC_V
integer s__ABC_abc= 0
real s__ABC_abd= 0

endglobals


//Generated allocator of ABC
function s__ABC__allocate takes nothing returns integer
 local integer this=si__ABC_F
    if (this!=0) then
        set si__ABC_F=si__ABC_V[this]
    else
        set si__ABC_I=si__ABC_I+1
        set this=si__ABC_I
    endif
    if (this>8190) then
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Unable to allocate id for an object of type: ABC")
        return 0
    endif

    set si__ABC_V[this]=-1
 return this
endfunction

//Generated destructor of ABC
function s__ABC_deallocate takes integer this returns nothing
    if this==null then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Attempt to destroy a null struct of type: ABC")
        return
    elseif (si__ABC_V[this]!=-1) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Double free of type: ABC")
        return
    endif
    set si__ABC_V[this]=si__ABC_F
    set si__ABC_F=this
endfunction

    function s__ABC_create takes nothing returns integer
        local integer this= s__ABC__allocate()
        call BJDebugMsg(I2S(s__ABC_abc))
        call BJDebugMsg(R2S(s__ABC_abd))
        set s__ABC_abd=s__ABC_abd + 1
        set s__ABC_abc=s__ABC_abc + 1
        return this
    endfunction
 
Just use them as you showed it above. Static variables behave just like regular globals because they are actually globals. Struct members are global arrays, and using locals would not make a whole lot of sense if you are just trying to prevent a global read.

So just refer to the static variable directly as MapInit.game_integer.
 
Status
Not open for further replies.
Top