(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Resources > Submissions

Submissions Submit JASS resources! If approved, they will be moved to their proper section.
Please read me first.

Reply
 
LinkBack Thread Tools Display Modes
Old 11-12-2008, 01:33 PM   #1 (permalink)
 
The_Reborn_Devil's Avatar

Fear me!
 
Join Date: Dec 2006
Posts: 249

The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)


[vJass] RAS v2.0b

This is a little struct attachment system that I made which I called RAS (Reborns Attachment System). It is very easy to use I think.
Since I'm not a pro in vJass there might be some bugs or something.

Here's the code:
vJass


library RAS

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

globals
    private constant integer size = 10000
endglobals

//! textmacro RAS takes DAT
globals
    private integer array struct$DAT$ [size]
endglobals

function GetAttachedStruct$DAT$ takes handle h returns integer
    return struct$DAT$[H2I(h) - 0x100000]
endfunction

function AttachStruct$DAT$ takes handle h, integer dat returns nothing
    set struct$DAT$[H2I(h) - 0x100000] = dat
endfunction
//! endtextmacro

//! runtextmacro RAS("1")
//! runtextmacro RAS("2")
//! runtextmacro RAS("3")

endlibrary



To attach a struct to a handle you just use this: call AttachStruct1(WHICH_HANDLE, THE_STRUCT)
And to retrieve the struct you use this: call GetAttachedStruct1(WHICH_HANDLE)
You may use other numbers than 1 after AttachStruct or GetAttachedStruct, but it must be initialized.
To find out which numbers you may use look at the end of the code.
//! runtextmacro RAS("1")
//! runtextmacro RAS("2")
//! runtextmacro RAS("3")
You can add more numbers there.


History


v1.0 -- Initial Release
v1.1 -- Changed some things to make it safer
v2.0 -- Changed the code (I found some bugs) It also uses textmacros now
v2.0b -- Inlined the functions


Last edited by The_Reborn_Devil; 11-21-2008 at 01:46 PM..
The_Reborn_Devil is offline   Reply With Quote
Old 11-12-2008, 02:56 PM   #2 (permalink)
 
Vestras's Avatar

___ __ _____
 
Join Date: Dec 2007
Posts: 161

Vestras has little to show at this moment (17)Vestras has little to show at this moment (17)


You don't need the ifs. And I would like you to test this vs TimerUtils and CSData. And this method isn't really new, but I must say the test results are impressing.
__________________
Vestras is offline   Reply With Quote
Old 11-12-2008, 03:55 PM   #3 (permalink)
 
The_Reborn_Devil's Avatar

Fear me!
 
Join Date: Dec 2006
Posts: 249

The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)


Quote:
Originally Posted by Vestras
You don't need the ifs
Are you sure? Because I think the max is 1000 or something because of this part: [1000] which Jass New Gen Pack didn't allow me to set higher.

Edit: I've done another benchmark test where I tested HSAS, RAS, TimerUtils and DAS.
And here's the result:
Result




Edit2: I've done another benchmark test where I tested CSData, RAS, TimerUtils and DAS.
And here's the result:
Result2





EDIT3: The code is changed so the results might be wrong!
Attached Thumbnails
result2.png   result3.png  
__________________

Last edited by The_Reborn_Devil; 11-20-2008 at 06:25 PM..
The_Reborn_Devil is offline   Reply With Quote
Old 11-12-2008, 08:16 PM   #4 (permalink)
 
Viikuna's Avatar

User
 
Join Date: Aug 2008
Posts: 30

Viikuna has little to show at this moment (6)


TimerUtils Red or Blue flavor?
Viikuna is offline   Reply With Quote
Old 11-12-2008, 08:26 PM   #5 (permalink)
 
The_Reborn_Devil's Avatar

Fear me!
 
Join Date: Dec 2006
Posts: 249

The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)


Blue
__________________
The_Reborn_Devil is offline   Reply With Quote
Old 11-13-2008, 08:03 AM   #6 (permalink)
 
Vestras's Avatar

___ __ _____
 
Join Date: Dec 2007
Posts: 161

Vestras has little to show at this moment (17)Vestras has little to show at this moment (17)


Try red too.
And damn, DAS is my system. :S
__________________
Vestras is offline   Reply With Quote
Old 11-13-2008, 01:35 PM   #7 (permalink)
 
The_Reborn_Devil's Avatar

Fear me!
 
Join Date: Dec 2006
Posts: 249

The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)


Quote:
Originally Posted by Vestras
And damn, DAS is my system. :S
Yeah, I know. That's why I added it :). I was surprised when I saw the results, because I thought that HSAS was fastest, but both DAS, RAS and CSData was faster than it.

Edit: I have done another benchmark test now, and I've tested: CSData, RAS, TimerUtils Red Flavour and DAS.
Here's the result:
Result




EDIT3: The code is changed so the results might be wrong!
Attached Thumbnails
result3.png  
__________________

Last edited by The_Reborn_Devil; 11-20-2008 at 06:26 PM..
The_Reborn_Devil is offline   Reply With Quote
Old 11-13-2008, 03:07 PM   #8 (permalink)
 
Vestras's Avatar

___ __ _____
 
Join Date: Dec 2007
Posts: 161

Vestras has little to show at this moment (17)Vestras has little to show at this moment (17)


Wow, this really is the fastest.
+rep. (Now I gotta figure out a method to overwhelm this one, mehehehe. :D)
__________________
Vestras is offline   Reply With Quote
Old 11-13-2008, 04:26 PM   #9 (permalink)

Anozer jasser
 
Join Date: Apr 2008
Posts: 237

Troll-Brain has little to show at this moment (13)Troll-Brain has little to show at this moment (13)


But not safe, because for bigs maps, this if below can easily return false :
if i2 < 1000 then
Troll-Brain is offline   Reply With Quote
Old 11-13-2008, 07:26 PM   #10 (permalink)
 
Viikuna's Avatar

User
 
Join Date: Aug 2008
Posts: 30

Viikuna has little to show at this moment (6)


Does it mean that you can only create what: 1000 handles?
Viikuna is offline   Reply With Quote
Old 11-13-2008, 08:04 PM   #11 (permalink)
 
spiwn's Avatar

Fast Learning retard
 
Join Date: Apr 2008
Posts: 1,076

spiwn will become famous soon enough (92)spiwn will become famous soon enough (92)spiwn will become famous soon enough (92)


Quote:
Originally Posted by Viikuna View Post
Does it mean that you can only create what: 1000 handles?
No, but the system has to be tweaked a little bit.
I am testing somethings at the moment. I will give a more detailed comment later.
It seemed to do more :D
Well I will put it like this for now:
cache[max1][max2]
The maximum numbers that can go in there are:
max1=8//Not to sure at the moment ;)
max2=1023
Bigger, and data gets confused, but no game errors(crashes) occur.

Notes


library RAS initializer Init

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

private type int extends integer array [1000][1000]//useless, actually an error, but the compiler doesn't recognize it, i guess
private type int2 extends int array [1000]

globals
    private int2 cache
endglobals

private function Init takes nothing returns nothing
    local integer i = 1//wrong
    set cache = int2.create()
    loop
        exitwhen i == 1000
        set cache[i] = int2.create()//wrong, but doesn't matter
        set i = i + 1
endloop
endfunction

function GetAttachedStruct takes handle h, integer dat returns integer
    local integer i = H2I(h)
    local integer i2 = i - 0x100000
    if i2 < 1000 then//what about dat?
        return cache[i2][dat]
    endif
    return 0
endfunction

function AttachStruct takes handle h, integer dat, integer str returns nothing
    local integer i = H2I(h)
    local integer i2 = i - 0x100000
    if i2 < 1000 then//what about dat?
        set cache[i2][dat] = str
    endif
endfunction
endlibrary


So the corrected code would look like this:
Corrected


library RAS initializer Init

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

private type int extends integer array [1023]
private type int2 extends int array [1023]

globals
    private int2 cache
endglobals

private function Init takes nothing returns nothing
    local integer i = 0
    set cache = int2.create()
    loop
        exitwhen i == int2.size//note this
        set cache[i] = int.create()
        set i = i + 1
endloop
endfunction

function GetAttachedStruct takes handle h, integer dat returns integer
    local integer i = H2I(h)
    local integer i2 = i - 0x100000
    if i2 < int2.size and dat<int.size then//but this check reduces performance
        return cache[i2][dat]
    endif
    return 0
endfunction

function AttachStruct takes handle h, integer dat, integer str returns nothing
    local integer i = H2I(h)
    local integer i2 = i - 0x100000
    if i2 < int2.size and dat<int.size then//same
        set cache[i2][dat] = str
    endif
endfunction
endlibrary


But how do you compare it to the other attachment systems?
(I know you use the benchmark system)
But they all work for handle indexes >1000 and the code you posted does not.

I suggest using this:
Suggestion


library RAS initializer Init

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

private type int extends integer array [1023]
private type int2 extends int array [1023]

globals
    private int2 cache
private integer i=0
endglobals

private function Init takes nothing returns nothing
    set cache = int2.create()
loop
        exitwhen i == int2.size
        set cache[i]=int.create()
        set i = i + 1
    endloop
endfunction

function GetAttachedStruct takes handle h returns integer
    set i=H2I(h) - 0x100000
    return cache[R2I(i/5191)][i - (i / 5191) * 5191]
endfunction

function AttachStruct takes handle h, integer str returns nothing
    set i=H2I(h) - 0x100000
    set cache[R2I(i/5191)][i - (i / 5191) * 5191]=str
endfunction
endlibrary


You can say it is faster than HSAS, but slightly. Those things depend on a lot of factors. For instance, on my HDD and with WC3 1.22 Game cache is the fastest. I think Blizzard modified the game optimizing the game cache so that Dota Allstars can run smother.
However, this will only work indexes up to 8191. To make it work for bigger indexes you should change the line:
private type int extends integer array [1023]
to
private type int extends integer array [1023,409550]
This way it will work up to 409550 indexes, but at the cost of performance, big cost. Even with lower maximum instances speed is drastically reduced.

To attach more than 1 struct to the same handle I suggest doing this the same way as HSAS(with text macros). Something like this:
With macros


library RAS initializer blah

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

private type int extends integer array [1023,409550]
private type int2 extends int array [1023,10230]
globals
    private integer i
endglobals
//! textmacro RAS takes IDENTIFIER
globals
    private int2 cache$IDENTIFIER$
endglobals

private function Init$IDENTIFIER$ takes nothing returns nothing
    local integer j = 0
    set cache$IDENTIFIER$ = int2.create()
    loop
        exitwhen j == int2.size
        set cache$IDENTIFIER$[j]=int.create()
        set j = j + 1
    endloop
endfunction

function GetAttachedStruct$IDENTIFIER$ takes handle h returns integer
    set i=H2I(h) - 0x100000
    return cache$IDENTIFIER$[R2I(i/5191)][i - (i / 5191) *5191]
endfunction

function AttachStruct$IDENTIFIER$ takes handle h, integer str returns nothing
    set i=H2I(h) - 0x100000
    set cache$IDENTIFIER$[R2I(i/5191)][i - (i / 5191) * 5191]=str
endfunction
//! endtextmacro

//! runtextmacro RAS("")
//! runtextmacro RAS("RAS1")
//! runtextmacro RAS("RAS2")
//! runtextmacro RAS("RAS3")
private function blah takes nothing returns nothing
    call Init()
    call InitRAS1()
    call InitRAS2()
    call InitRAS3()
endfunction
endlibrary


I would have suggested like this, but I found out it does not work:
With an array


library RAS initializer Init

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

private type int extends integer array [1023,409550]
private type int2 extends int array [1023,10230]

globals
    private int2 array cache [8]
    private integer i
endglobals

private function Init takes nothing returns nothing
    local integer ij = 0
    local integer j = 0
loop
        exitwhen j==8
        set cache[j] = int2.create()
        loop
            exitwhen ij == int2.size
set cache[j][ij]=int.create()
            set ij = ij + 1
        endloop
        set j=j+1
    endloop
endfunction

function GetAttachedStruct takes handle h,integer dat returns integer
    set i=H2I(h) - 0x100000
    return cache[dat][R2I(i/1023)][i - (i / 1023) * 1023]//here dat may cause a problem, but checking it would reduce performance
endfunction

function AttachStruct takes handle h, integer dat, integer str returns nothing
    set i=H2I(h) - 0x100000
    set cache[dat][R2I(i/5191)][i - (i / 5191) * 5191]=str//here dat may cause a problem, but checking it would reduce performance
endfunction
endlibrary



I will do some more tests :P
P.s. And whatever I did, I could not make a 3D array(working).

Edit: I suppose some of this is just junk, but some of it is not :P
__________________

Use the reputation system for people you think deserve it.
Bux.to - Get Money for viewing ads

Last edited by spiwn; 11-14-2008 at 01:36 PM..
spiwn is offline   Reply With Quote
Old 11-14-2008, 10:18 AM   #12 (permalink)

Anozer jasser
 
Join Date: Apr 2008
Posts: 237

Troll-Brain has little to show at this moment (13)Troll-Brain has little to show at this moment (13)


Quote:
For instance, on my HDD and with WC3 1.22 Game cache is the fastest. I think Blizzard modified the game optimizing the game cache so that Dota Allstars can run smother.
Wtf ?!

Could you post your test code and the results with the patch 1.22 and 1.21b plz
Troll-Brain is offline   Reply With Quote
Old 11-14-2008, 11:23 AM   #13 (permalink)
 
spiwn's Avatar

Fast Learning retard
 
Join Date: Apr 2008
Posts: 1,076

spiwn will become famous soon enough (92)spiwn will become famous soon enough (92)spiwn will become famous soon enough (92)


Code is from the implemented benchmark system in the the test map from here
Only editing I did was changing the script from testing ABC to testing RAS.
Those 2 are the results I got before 1.22
Single Struct Attachment Speed Test




Multiple Struct Attachment Speed Test




As you can see at that time my HDD performed well vs HSAS but could not beat it. And it is not a high performance one - Seagate 250GB 7200 RPM 16 MB cache. On the market there are hdds that are way faster than this.
And here are the 1.22 results
Single Struct Attachment Speed Test on 1.22




Multiple Struct Attachment Speed Test on 1.22




After the patch, Gama cache beats HSAS. And After I did the last optimization I thought of to RAS it's performance improved a little bit, so that is why it has such a lead over Game cache in the Single Struct Attachment Speed Test.
The exact RAS code I used for the last result is in my previous post in the Suggestion.

Anyway, the benchmark system only check speed and not data integrity.
Attached Thumbnails
test-single.jpg   test.-multiple.jpg  
__________________

Use the reputation system for people you think deserve it.
Bux.to - Get Money for viewing ads
spiwn is offline   Reply With Quote
Old 11-14-2008, 11:59 AM   #14 (permalink)
 
The_Reborn_Devil's Avatar

Fear me!
 
Join Date: Dec 2006
Posts: 249

The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)The_Reborn_Devil has little to show at this moment (32)


I will update the code when I come back, which will be on Sunday.

Edit: I have updated the code a little.
__________________

Last edited by The_Reborn_Devil; 11-16-2008 at 06:43 PM..