HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

What is behind the structs??

04-16-2007, 12:58 AM#1
moyack
I've been reading the JASSHelper tutorial so I can do my spells using this system.

But I'm intrigued about what is behind the structs. I mean, as far as I know, the structs are converted internally into normal jass code, so... how is it managed?? how the code is converted in order to understand the structs?? does it use game cache internally??

if we have a struct like this:
Collapse JASS:
    struct point
        real x=0.0
        real y=0.0

        method move takes real tx, real ty returns nothing
            set this.x=tx
            set this.y=ty
        endmethod

    endstruct

How would it look internally in the map??
04-16-2007, 01:13 AM#2
wantok
It looks like this:

Collapse JASS:
//JASSHelper struct globals:
integer si__point_I=0
integer si__point_N=0
integer array si__point_V
boolean array si__point_active
real array s__point_x
real array s__point_y

endglobals

//Generated allocator of point
function s__point__allocate takes nothing returns integer
 local integer this
    if (si__point_N==0) then
        set si__point_I=si__point_I+1
        set this=si__point_I
        if (this>8190) then
            return 0
        endif
    else
        set this=si__point_V[si__point_N]
        set si__point_N=si__point_N-1
    endif
    set s__point_x[this]=0.0
    set s__point_y[this]=0.0

    set si__point_active[this]=true
 return this
endfunction

//Generated destructor of point
function s__point_destroy takes integer this returns nothing
    if this==null then
        return
    elseif not(si__point_active[this]) then
        return
    endif
    set si__point_N=si__point_N+1
    set si__point_V[si__point_N]=this
    set si__point_active[this]=false
endfunction

function s__point_move takes integer this,real tx,real ty returns nothing
            set s__point_x[this]=tx
            set s__point_y[this]=ty
endfunction

If you want to see what the code looks like after JassHelper compiles it, extract the war3map.j file from the map and look it over. Or you can do what I do and create a trigger with an incorrect name so that when it compiles it gives an error and I can browse through the code in the little error window.
04-16-2007, 01:28 AM#3
moyack
I see... for every component in the struct it is generated an array to store that data.

Thanks for your help wantok :)
04-16-2007, 12:10 PM#4
Toadcop
well but if wrote (it was the past year) what i am using a lot of custom arrays + vars = it was a bad kind of coding... =) but now...
suckers !
04-16-2007, 12:44 PM#5
The)TideHunter(
If you leave a syntax error in your main maps script section, when the box pops up, the code you see is the code after the parser has converted it, so you could take a look and see whats what xD.
04-16-2007, 01:10 PM#6
moyack
Quote:
Originally Posted by Toadcop
well but if wrote (it was the past year) what i am using a lot of custom arrays + vars = it was a bad kind of coding... =) but now...
suckers !
Sorry, I don't get it.

Quote:
Originally Posted by The)TideHunter(
If you leave a syntax error in your main maps script section, when the box pops up, the code you see is the code after the parser has converted it, so you could take a look and see whats what xD.
Hmm.... yes, it's a good idea :)

I was checking the code again and now I understand why it's not offered the possibility to manage arrays inside the structs. It's quite complicated to do it.
04-16-2007, 01:27 PM#7
Vexorian
Quote:
Originally Posted by Toadcop
well but if wrote (it was the past year) what i am using a lot of custom arrays + vars = it was a bad kind of coding... =) but now...
suckers !
Quote:
Sorry, I don't get it.

Nobody does.


Quote:
I was checking the code again and now I understand why it's not offered the possibility to manage arrays inside the structs. It's quite complicated to do it.

What are you talking about?
04-16-2007, 01:58 PM#8
moyack
I had this idea:

Collapse JASS:
    struct Matrix
        integer i=0
        integer j=0
        real array m
        // And the methods goes here...
    endstruct

I developed a structure like this for a project at the university in VB to make matrix calculations.

I was thinking in developing a matrix library to manage splines. And I wanted to know if it was possible and, if so, if it was efficient enough.
04-16-2007, 02:26 PM#9
Toadcop
Quote:
Nobody does.
I does :P ^^

Quote:
I was checking the code again and now I understand why it's not offered the possibility to manage arrays inside the structs. It's quite complicated to do it.
maybe because it's not possible ? =) or if posible the using extra algoritms

btw... it could be the next extension for vJass (dynamic arrays inside of structures !) this would be cool (ofc if performance is not needed...) i already know some ways to do this...
04-16-2007, 02:32 PM#10
iNfraNe
I just use linked lists as arrays inside structs... but its slow.
04-16-2007, 02:40 PM#11
Vexorian
huh?
Collapse JASS:
    struct Matrix
        integer i=0
        integer j=0
        real array m [5]
        // And the methods goes here...
    endstruct

Quote:
btw... it could be the next extension for vJass (dynamic arrays inside of structures !) this would be cool (ofc if performance is not needed...) i already know some ways to do this...`
Too late already working on that, but I really think that the "small" limit of 8190 indexes is still pretty huge and it is better to have the limit than overhead, but that's just me.
04-16-2007, 03:07 PM#12
Toadcop
Quote:
Too late already working on that, but I really think that the "small" limit of 8190 indexes is still pretty huge and it is better to have the limit than overhead, but that's just me.
omg ! all is lost ! ... =) i would use construction like my Ultra Buffer ("if" based extended 2d array) yeah ! and declaration would looks like yours =)

Quote:
I just use linked lists as arrays inside structs... but its slow.
- it's good =)
04-16-2007, 03:17 PM#13
MaD[Lion]
hmm structs is nothing different from the old object orientated array method. Only different is that it makes the code looks cleaner, and u can therefore put more into it without worry it will be messy and looks ugly.
04-16-2007, 04:07 PM#14
Vexorian
There is a huge difference between prefix and suffix notation. like (+ 1 (* 4 3)) vs. 1+4*3