wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Samples
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 09-16-2006, 12:46 AM   #1
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default DARY - Dynamic Array System 0.1

DARY is a system for working with dynamically allocated arrays. One master global array, udg_heap, is partitioned by DARY_alloc and DARY_free. Use parallel arrays if you want to work with structures or other types. rheap and uheap are intended for this purpose for reals and units respectively.
It includes some secondary functionality for sorting, heaping, shuffling and searching dynamic arrays, since these are rather tricky to get right.
The arrays are primarily intended for temporary use when speed is essential. In the interest of speed, no array lengthening tricks are used, so you can only allocate 8191 elements. 8191 is the upper limit for one array because save games can fail when one uses the 8192nd element.
For permanent storage, structures and even arrays of fixed length, use Karukef's system. DARY is a niche system for the 1% of the time when you need to random access sets of varying length. If you need more permanent arrays, Vex's CSCache implements very similar functionality with graceful overflow handling.

Example: Find a group of the n closest units to some point
Collapse JASS:
function FillArrayWithGroup takes integer arr, integer max, group g returns integer
    local unit u
    local integer i = 0
    loop
        exitwhen i >= max
        set u = FirstOfGroup(g)
        exitwhen u == null
        set udg_uheap[arr+i] = u
        set i = i + 1
    endloop
    return i
endfunction

function FillUdist takes integer arr, integer len, real x, real y returns nothing
    local integer i = 0
    local real ux
    local real uy
    loop
        exitwhen i >= len
        set ux = GetUnitX(udg_uheap[arr+i]) - x
        set uy = GetUnitY(udg_uheap[arr+i]) - y
        set udg_rheap[arr+i] = ux*ux+uy*uy
        set i = i + 1
    endloop
endfunction


function FillGroupWithPermutedArray takes group g, integer arr, integer size, integer max returns nothing
    local integer i = 0
    if size > max then
        set size = max
    endif
    loop
        exitwhen i>= size 
        call GroupAddUnit(g,udg_uheap[udg_heap[arr+i]])
        set i = i + 1
    endloop
endfunction

//Add 5 closest units to a group
function sort_uloc takes nothing returns nothing
    local group g = CreateGroup()
    local integer arr
    local integer n

    local real x = 0.
    local real y = 0.

    set arr = DARY_allocn(100)
    call GroupEnumUnitsInRange(g,x,y,1000000.,null)
    set n = FillArrayWithGroup(arr,100,g)    //this removes everything in the group
    call DARY_initperm(arr,n)
    call FillUdist(arr,n,x,y)

    call DARY_sort(arr,n,udg_callbacks[DARY_RHEAP_LESS()])

    call FillGroupWithPermutedArray(g,arr,n,5)

    call DARY_freen(arr,100)

    call DestroyGroup(g)
    set g = null
endfunction
Attached Images
File Type: jpg array.jpg (25.8 KB, 320 views)
Attached Files
File Type: w3x arraysys.w3x (25.5 KB, 239 views)
__________________
PipeDream is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 09-17-2006, 03:55 PM   #2
ShadowDestroyer
User
 
ShadowDestroyer's Avatar
 
Join Date: Jan 2006
Posts: 375

ShadowDestroyer is on a distinguished road (15)

Send a message via AIM to ShadowDestroyer
Default

Good Job once again!
__________________
The Shadow of Destruction

clanmord.net
Try Tropical Tag, Militia Rebellion, Capture the Flag WSG, and Footmen Frenzy XV!
ShadowDestroyer is offline   Reply With Quote
Old 09-19-2006, 07:12 AM   #3
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

PipeDream - nice ! this kind of sys's i love at best !

PS i will check it + performance with your StopWatch + it's a offtop but what i need to compile my own natives ??? if the stuff is not large can you give me a link ? + some documentation about JAPI ?
Toadcop is offline   Reply With Quote
Old 09-19-2006, 07:29 AM   #4
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

http://www.wc3campaigns.net/showthread.php?t=84417
__________________
PipeDream is offline   Reply With Quote
Old 09-19-2006, 08:16 AM   #5
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

PipeDream - Great Thanks !!!
Toadcop is offline   Reply With Quote
Old 10-17-2006, 10:26 AM   #6
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

Pipe this sys have some strange method to alloc array for example
[code]
set i=AllocArray(32) // return 33
set i=AllocArray(2)
...
set i=AllocArray(2) // return 33 ??? what a ? i mean it alloc allready used array space !
[code/]
the example is not correct but the fact is what it can alloc the same array spaces.

PS or you don't care about it i can understand it because it's a full public domain =)
Toadcop is offline   Reply With Quote
Old 10-17-2006, 06:42 PM   #7
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

I don't understand your question at all.
__________________
PipeDream is offline   Reply With Quote
Old 10-17-2006, 09:32 PM   #8
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

PipeDream - i know it =)
i mean the array allocation can be not correct ! what's all =)
Toadcop is offline   Reply With Quote
Old 10-17-2006, 10:04 PM   #9
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

I think he means that AllocArray seems to be able to return an already used index
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-17-2006, 10:15 PM   #10
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

Quote:
I think he means that AllocArray seems to be able to return an already used index
- ege ! :idiotical: =) yes it is ! i see you have learned to undestand my EnGleash =)
Toadcop is offline   Reply With Quote
Old 10-17-2006, 11:52 PM   #11
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

Oh thanks. The test map calls DARY_init() in init and then DARY_init() in the sort test which corrupts things pretty badly if you put your tests after it. Just be sure to call DARY_init() only once.
__________________
PipeDream is offline   Reply With Quote
Old 10-18-2006, 11:45 AM   #12
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

PipeDream - OK ! thanks !
Toadcop is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 02:21 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2017, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services