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

[JASS] Pandamines 3 array Handle system

Status
Not open for further replies.
Level 12
Joined
Aug 20, 2007
Messages
866
Pandamine created a really good system for retrieving handle data for structs, and being able to move them from function to function without ever touching a gamecache

I was fascinated because I love globals, and using something very very similar to a struct, can utilize the system without ever needing JassNewGen!!!

But, since the system was set up for structs, which are specially made, I thought I might get some problems

Basically, I revised the system a bit, and when it loops through all of the data in the 3 variable arrays (which doing it the way I am, should be quickly with maps that have physics in them) will loop back to the beginning and start all over again, making the DataSystem useable no matter how long you play the game

Please Note, I improved it for regular Jass, so the "globals" block is what you need to put up in the udg variables

JASS:
//globals
//    integer array udg_Data1
//    integer array udg_Data2
//    integer array udg_Data3
//    integer udg_LoopData = 0
//endglobals
//*Thanks to Pandamine for the Data Template
//*Modified so that the index will loop back from the start of the arrays when
//it has progressed past the third (not being used in conjuncture with structs)
function DS_H2I takes handle h returns integer
    return h
    return 0
endfunction
function SetData takes handle h, integer v returns nothing
    local integer i = DS_H2I(h) - 0x100000
    set i = i - 24573 * udg_LoopData
    if (i < 8191) then
        set udg_Data1[i] = v
    elseif (i < 16382) then
        set udg_Data2[i - 8191] = v
    elseif (i < 24573) then
        set udg_Data3[i - 16382] = v
    else
        call BJDebugMsg("Data System Error: SetData handle index too high")
        set udg_LoopData = udg_LoopData + 1 //Will loop back, and then reset the data
        call SetData(h , v) //Loop will allow data to continue to be used
    endif
endfunction
function GetData takes handle h returns integer
    local integer i = DS_H2I(h) - 0x100000
    //Needed to drop down 1, because of zero (>= 24573, is also > 24572)
    if i > 24572 * udg_LoopData then //If your getting data stored for an extended period of time
      set i = i - 24573 * udg_LoopData //This if/then will check and retrieve the appropriate data
    endif
    if (i < 8191) then
        return udg_Data1[i]
    elseif (i < 16382) then
        return udg_Data2[i - 8191]
    elseif (i >= 24573) then
        //call BJDebugMsg("Data System Error: GetData handle index too high") would be annoying to have for the last array
    endif
    return udg_Data3[i - 16382]
endfunction
 
Level 9
Joined
Mar 25, 2005
Messages
252
Some thoughts of mine:
(take note that I am assuming that you are referring to HSAS with "Pandamine created a really good system for retrieving handle data for structs")

1. you don't take care of collisions
2. once your system makes it's second loop it wont work for handle indexes between the 24573th to (2*24573 - 1)th

3. I find it interesting that you say you create and destroy 25000+ handles quickly. How does your physics thingy (engine?) achieve that? Sounds almost like you are using a separate timer for each object O.O. Although, even if you do so, you could use a timer recycler that would clear all your H2I problems, or better yet (since you aren't using structs :S) you might want to take a look at SmartTimers. It recycles timers and allocates indexes for you both at the same time which is just what you need if your not using structs or doing those yourself (and it is in regular jass already).

4. If you still feel like having constantly increasing handle indexes in your map, ABC is the preferred choice over HSAS or the like. This is because ABC doesn't care about how high or low the handle indexes are. Though it might be a bit more painful to convert ABC into no-vJass.

5. There is a regular jass (mac) version of PUI. I would use it for units if I was you.

6.
Herman about HSAS said:
But, since the system was set up for structs, which are specially made, I thought I might get some problems

The only thing different between this sytem and HSAS is what they do with the handle indexes. HSAS can also store any integer to a handle, not only structs, so I don't understand at all what you mean by what you said.
 
Level 12
Joined
Aug 20, 2007
Messages
866
I was talking about HSAS

Yeah I honestly don't know alot about how all of this stuff works, but it seemed to me that after a certain while, the indexes of the handles will get over the 3 arrays, and the handle integers assigned by WC become the gigantic # + something over 24573

Yeah, the spell system would create a stored integer for a handle every time it ran, but I was thinking more along the lines of a whole map with 50+ spells that used timers

Hmmm, I will look into that other stuff

Btw, I'm not really sure what you mean that it won't work for the handle indexes, as I'm assuming that you wouldn't be able to access them anymore using the array system, that WC continually assigns integers to handles in a continuous fashion (and the H2I returns that integer)

At the same time I'm assuming structs take care of that problem (somehow)
So I was gonna make it loop back to the beginning (because the indexes cannot be changed, the "i" part of the system can be)


What do you mean it will no longer work?, you won't be able to set them, but you can still get the data (the set will start again), but the if/then at the top of the 2nd part allows you to access the end of the previous loop

Again, I don't know that much about vJASS or structs or attachment systems, but I tried this out and it worked, although I didn't "test" it (too lazy ><)
 
Level 9
Joined
Mar 25, 2005
Messages
252
Lets say that you have stored something to handle index 0x100000, and then you store something to handle index 0x100000+24573. Your system will store the value of the latter one to the array slot where the earlier one was stored. After that you get the newly stored value from both of those handle indexes.

Also if udg_LoopData is 2, and you try to get some data you have stored to handle index 0x100000+24580. This is what will happen:
JASS:
function GetData takes handle (0x100000+24580) returns integer
    local integer i = 24580
    if 24580 > 24572 * 2 then // false
    endif
    if (24580 < 8191) then // false
    elseif (24580 < 16382) then // false
    elseif (24580 >= 24573) then // true
    endif
    return udg_Data3[8198] // 8198 > 8190!!
endfunction
 
Level 12
Joined
Aug 20, 2007
Messages
866
@Disciple

Yeah, the thing is that I thought the idnexes go by order, but I suppose they don't

In other words, the loop wouldn't equal 2 fo that number, it would be 1
[You would've already stored 24573 numbers, and then loop would get +1, and the next seires of numbers would get stored starting from the first array]

Yeah, the variables are integers, so they can be re-wrote with fair ease, and what happens is it will simply re-write the first numbers beginning at the first array, I'm assuming that you don't have +24573 handles stored at one time when the loop starts, or else, yeah it will eliminate the handle #'s already stored
 
Status
Not open for further replies.
Top