System DUI - Davey's unit indexing

SerraAvenger

Cuz I can
Reaction score
234
JASS:
//=======================================================\\
//*****************Davey's Unit Indexing*****************||
//=======================================================//
//Requirements
//    - A little bit of JASS knowledge
//    - And JassPack NewGen 1.4c ( or Higher )
//
//What does this do?
// Davey's Unit Indexing ( DUI ) is a "small" system,
// that allows a unit management similiar to the "Custom Value"
// one which was built in into the World Editor. The differences:
//    - It allows multiple Custom Values at once.
//    - If you start the map in Debug Mode, it shows you the maximum
//      number of Custom Values you may use. The mimum Number for
//      those is 4.
//    - It handles the positions for you, you only need to assign
//      custom values.
//
//Purpose:
// Attach multiple integers to a unit. These integers can be
// used for almost anything, including: as indicies for
// other arrays; As some "Group affinity" marker; As a custom
// level; or whatever.
//
//How to use?
// Simply pick the unit you want to add the custom value to and do:
// call SetUnitValue( unit , custom value number - 1 , the value )
// so to set trigUnit's 2nd custom value to 15, do:
// call SetUnitValue( trigUnit , 1 , 15 )
// With the Standard Settings you can use up to 4 different custom
// values ( 0 , 1 , 2 , 3 ). Using others will result in nothing to
// happen.
//
//====================================================================D
//FAQ:
// Q : There allready is the PUI of Cohadar - Why should I use
//    this one?
// A : Well, there is no really big difference. Memory usage wise, his is
//    a little bit better at the beginning. Efficiency wise, I didn't
//    like his Recycling thus I created my own system which is using a
//    free list and really using an attach custom value system rather
//    than a single indexing method. SO: It is easier to
//    instant-use, Cohadars system needs an extra implementation.
//    Sure, you can extend this system too with that extra implementation.
//    And With a bit of work you can do everything with Cohadars system too.
//
// Q : What If I try to get a CustomValue Number from a unit I did not set
//    for the unit before, or if I try to get a CustomValue from a unit
//    for which I did not assign any CustomValue at all yet?
// A : It will, just like in GetUnitUserData() , return 0.
//
// Q : When I Try to Save, The Syntax checker Tells me that there are
//    plenty of unexpected names / Wc3 Crashes. I have not tried
//    to fuddle with the code.
// A : In most of the cases, you simply forgot to install JassPack
//    NewGen; Or you started the regular WorldEditor instead
//    of the application the JassPack NewGen contains.
//
// Q : When I tell the system I would need more then 2048 Indicies, it does
//    only allocate 2048 at max...
// A : This was done to Set the minimum number of Custom Values that are
//    usable to 4. If you need more Indicies but can live with less
//    custom values, delete the "exitwhen fieldIndicator > 2048" part
//    in the InitDUI function.
//
// Q : How can I concatenate this system with other custom value systems
//    I use?
// A : You'll need to use only this system. Then you can use SetUnitValue( )
//    with one value per system you use. ( 0 for the first; 1 for the
//    second etc )
//
// Q : How is the number of available custom values computed?
// A : 8192 / The Maximum Custom Index. For 2048 possible indexes, this means
//    4; for 1024 it is 8.
//
//====================================================================D

library DUI initializer InitDUI
    globals
        private integer MaxCustomIndex = 2048
    endglobals
    // Above Value needs to be set to the Maximum Number of Custom Values.
    // A lower index will allow for a better initialisation performance;
    // However, less units can be indexed. 2048 Is the maximum; If
    // you choose a higher value you still will only have 2048.

    globals
        private integer array FreeList
        private integer       FirstFree
        private unit    array IndexUnits
        private integer       MaxNumCustomValues
        private integer array CustomValue
    endglobals
    function InitDUI takes nothing returns nothing
        local integer fieldIndicator = 1
        set FirstFree = 0
    
        loop
            exitwhen fieldIndicator > MaxCustomIndex
            exitwhen fieldIndicator > 2048
            set FreeList[ fieldIndicator - 1 ] = fieldIndicator
            set fieldIndicator = fieldIndicator + 1
        endloop
        set MaxNumCustomValues = 8192 / ( fieldIndicator - 1 )
        debug DisplayTextToPlayer( GetLocalPlayer() , 0 , 0 , "The Maximum Number of Custom Values is: " + I2S( MaxNumCustomValues ) )
    endfunction

    private function RecycleIndex takes nothing returns boolean
        local unit    trigUnit       = GetTriggerUnit (          )
        local integer recyclingIndex = GetUnitUserData( trigUnit )  - 1
    
        if not IsUnitType( trigUnit, UNIT_TYPE_HERO ) then
            set  FreeList[ recyclingIndex ] = FirstFree
            set  FirstFree                  = recyclingIndex
            call DestroyTrigger             ( GetTriggeringTrigger() )
        endif
        set  trigUnit = null

        return false
    endfunction

    function SetUnitValue takes unit indexedunit , integer whichindex , integer value returns nothing
        local integer indexedUnitCustomValue = GetUnitUserData( indexedunit )
        local trigger recycler
        local integer loopIndicator          = 0
        if whichindex < MaxNumCustomValues then
            if indexedUnitCustomValue != 0 then
                set  CustomValue[ indexedUnitCustomValue - 1 + MaxCustomIndex * whichindex ] = value
            else
                call SetUnitUserData         ( indexedunit , FirstFree + 1  )
                set  indexedUnitCustomValue  = GetUnitUserData( indexedunit )
                set  CustomValue             [ indexedUnitCustomValue - 1 + MaxCustomIndex * whichindex ] = value
                loop
                    exitwhen loopIndicator > 3
                    if loopIndicator != whichindex then
                        set  CustomValue             [ indexedUnitCustomValue - 1 + MaxCustomIndex * loopIndicator ] = 0
                    endif
                    set loopIndicator = loopIndicator + 1
                endloop
                set  FirstFree               = FreeList[ FirstFree ]
                set  recycler                = CreateTrigger( )
                call TriggerRegisterUnitEvent( recycler , indexedunit , EVENT_UNIT_DEATH       )
                call TriggerAddCondition     ( recycler , Condition( function RecycleIndex )   )
                set  recycler                = null
            endif
        endif
    endfunction

    function GetUnitValue takes unit indexedunit , integer whichindex returns integer
        local integer indexedUnitCustomValue = GetUnitUserData( indexedunit )
        if indexedUnitCustomValue != 0 then
            return CustomValue[ indexedUnitCustomValue - 1 + MaxCustomIndex * whichindex ]
        else
            return 0
        endif
       
    endfunction

endlibrary

The CV tester is a Demo map. It stores the unit's order in which it entered a "special" region, as well as the unit's speed while entering. The last one is actualised everytime the unit enters the region, the first one is not.
And no I don't care about the efficiency / memory leaks of the demo trigger, it really is just there for demonstrating the way it works.
Greetings, Davey.

Changelog:
-Hero's indicies won't be recycled anymore
-Added a small, tiny - 1 where I forgot it yesterday : D


Extended Version:
This one allows for custom recyceability for certain units, so you can choose for each unit indivudually wether it shall be recycled or not. Important for units that are still used after their death, or that can die multiple times but shall keep their indicies and attached integers unaffected ( heroes, p.e. )
JASS:
//=======================================================\\
//***************** Davey's Unit Indexing *****************||
//=======================================================//
//                  --Extended  Version--
//Requirements
//    - A little bit of JASS knowledge
//    - And JassPack NewGen 1.4c ( or Higher )
//
//What does this do?
// Davey's Unit Indexing ( DUI ) is a "small" system,
// that allows a unit management similiar to the "Custom Value"
// one which was built in into the World Editor. The differences:
//    - It allows multiple Custom Values at once.
//    - If you start the map in Debug Mode, it shows you the maximum
//      number of Custom Values you may use. The mimum Number for
//      those is 4.
//    - It handles the positions for you, you only need to assign
//      custom values.
//    - It allows Units to keep their Indexes after Dying
//
//Purpose:
// Attach multiple integers to a unit. These integers can be
// used for almost anything, including: as indicies for
// other arrays; As some "Group affinity" marker; As a custom
// level; or whatever.
// Don't let the attached integers be overwritten after death
// for certain units.
//
//How to use?
// Simply pick the unit you want to add the custom value to and do:
// call SetUnitValue( unit , custom value number - 1 , the value )
// so to set trigUnit's 2nd custom value to 15, do:
// call SetUnitValue( trigUnit , 1 , 15 )
// With the Standard Settings you can use up to 4 different custom
// values ( 0 , 1 , 2 , 3 ). Using others might result in a crash.
// Then, if you Want that the new Unit will be revived after its death,
// call SetUnitRecyclable( trigUnit , false ) 
// This will Prevent its indicies from being overwritten / deleted when
// the unit dies. It might be useful for Heros, but every unit you use
// this on will permanently occupy one index, so you might reach the end
// or leak indicies ( when a unit that is not recycable dies and is not
// revived, one index will be leaked ). If you want to change your 
// mind again, use:
// call SetUnitRecyclable( trigUnit , true )
// In Default, all indicies are recycable.
//
//====================================================================D
//FAQ:
// Q : There allready is the PUI of Cohadar - Why should I use
//    this one?
// A : Well, there is no really big difference. Memory usage wise, his is
//    a little bit better at the beginning. Efficiency wise, I didn't
//    like his Recycling thus I created my own system which is using a
//    free list and really using an attach custom value system rather
//    than a single indexing method. SO: It is easier to
//    instant-use, Cohadars system needs an extra implementation.
//    Sure, you can extend this system too with that extra implementation.
//    And With a bit of work you can do everything with Cohadars system too.
//
// Q : What If I try to get a CustomValue Number from a unit I did not set
//    for the unit before, or if I try to get a CustomValue from a unit
//    for which I did not assign any CustomValue at all yet?
// A : It will, just like in GetUnitUserData() , return 0.
//
// Q : When I Try to Save, The Syntax checker Tells me that there are
//    plenty of unexpected names / Wc3 Crashes. I have not tried
//    to fuddle with the code.
// A : In most of the cases, you simply forgot to install JassPack
//    NewGen; Or you started the regular WorldEditor instead
//    of the application the JassPack NewGen contains.
//
// Q : When I tell the system I would need more then 2048 Indicies, it does
//    only allocate 2048 at max...
// A : This was done to Set the minimum number of Custom Values that are
//    usable to 4. If you need more Indicies but can live with less
//    custom values, delete the "exitwhen fieldIndicator > 2048" part
//    in the InitDUI function.
//
// Q : How can I concatenate this system with other custom value systems
//    I use?
// A : You'll need to use only this system. Then you can use SetUnitValue( )
//    with one value per system you use. ( 0 for the first; 1 for the
//    second etc )
//
// Q : How is the number of available custom values computed?
// A : 8192 / The Maximum Custom Index. For 2048 possible indexes, this means
//    4; for 1024 it is 8.
//
//====================================================================D

library ExtendedDUI initializer InitExtendedDUI
    globals
        private integer MaxCustomIndex = 2048
    endglobals
    // Above Value needs to be set to the Maximum Number of Custom Values.
    // A lower index will allow for a better initialisation performance;
    // However, less units can be indexed. 2048 Is the maximum; If
    // you choose a higher value you still will only have 2048.

    globals
        private integer array FreeList
        private integer       FirstFree
        //private unit    array IndexUnits
        private integer       MaxNumCustomValues
        private integer array CustomValue
        private boolean array Recycable
    endglobals

    function InitExtendedDUI takes nothing returns nothing
        local integer fieldIndicator = 1
        set FirstFree = 0
    
        loop
            exitwhen fieldIndicator > MaxCustomIndex
            exitwhen fieldIndicator > 2048
            set FreeList[ fieldIndicator - 1 ] = fieldIndicator
            set fieldIndicator = fieldIndicator + 1
        endloop
        set MaxNumCustomValues = 8192 / ( fieldIndicator - 1 )
        set FreeList[ fieldIndicator - 1 ] = fieldIndicator - 1
        debug DisplayTextToPlayer( GetLocalPlayer() , 0 , 0 , "The Maximum Number of Custom Values is: " + I2S( MaxNumCustomValues ) )
    endfunction

    private function RecycleIndex takes nothing returns boolean
        local unit    trigUnit       = GetTriggerUnit (          )
        local integer recyclingIndex = GetUnitUserData( trigUnit )  - 1
    
        if Recycable[ recyclingIndex ] then
            set  FreeList[ recyclingIndex ] = FirstFree
            set  FirstFree                  = recyclingIndex
            call SetUnitUserData            ( trigUnit ,           0 )
            call DestroyTrigger             ( GetTriggeringTrigger() )
        endif
        set  trigUnit = null

        return false
    endfunction

    function SetUnitValue takes unit indexedunit , integer whichindex , integer value returns integer
        local integer indexedUnitCustomValue = GetUnitUserData( indexedunit )
        local trigger recycler
        local integer loopIndicator          = 0
        if whichindex < MaxNumCustomValues then
            if indexedUnitCustomValue != 0 then
                set  CustomValue[ indexedUnitCustomValue - 1 + MaxCustomIndex * whichindex ] = value
            else
                call SetUnitUserData         ( indexedunit , FirstFree + 1  )
                set  indexedUnitCustomValue  = GetUnitUserData( indexedunit )
                set  Recycable               [ indexedUnitCustomValue - 1   ] = true
                set  CustomValue             [ indexedUnitCustomValue - 1 + MaxCustomIndex * whichindex ] = value
                loop
                    exitwhen loopIndicator > 3
                    if loopIndicator != whichindex then
                        set  CustomValue             [ indexedUnitCustomValue - 1 + MaxCustomIndex * loopIndicator ] = 0
                    endif
                    set loopIndicator = loopIndicator + 1
                endloop
                set  FirstFree               = FreeList[ FirstFree ]
                set  recycler                = CreateTrigger( )
                call TriggerRegisterUnitEvent( recycler , indexedunit , EVENT_UNIT_DEATH       )
                call TriggerAddCondition     ( recycler , Condition( function RecycleIndex ) )
                set  recycler                = null
            endif
        endif
        return indexedUnitCustomValue
    endfunction

    function GetUnitValue takes unit indexedunit , integer whichindex returns integer
        local integer indexedUnitCustomValue = GetUnitUserData( indexedunit )
        if indexedUnitCustomValue != 0 then
            return CustomValue[ indexedUnitCustomValue - 1 + MaxCustomIndex * whichindex ]
        else
            return 0
        endif
       
    endfunction
    
    function SetUnitRecyclable takes unit whichunit , boolean recycle returns nothing
        local integer unitIndex = GetUnitUserData( whichunit ) - 1
        if unitIndex != -1 then
            set Recycable[ unitIndex ] = recycle
        else
            set Recycable[ SetUnitValue( whichunit , 0 , 0 ) ] = recycle            
        endif
        
    endfunction    
endlibrary


Demo maps updated soon
 

Attachments

  • CV tester.w3x
    20.5 KB · Views: 221
T

Tubba

Guest
Oh, I see. Disregard that then.


Uhh, maybe you should explain a bit more what it does?


Ah, nevermind.
 

Cohadar

master of fugue
Reaction score
209
You recycle indexes when unit dies, not when it is removed from game.

So what happens when you use it to make extended inventory and your hero dies?
It's index gets recycled and it loses items?
 

SerraAvenger

Cuz I can
Reaction score
234
You recycle indexes when unit dies, not when it is removed from game.

So what happens when you use it to make extended inventory and your hero dies?
It's index gets recycled and it loses items?

Well I though about that, too, but yesterday at 23:30 I was too tired to add that scenario; And it is not an important part of the system itself, so I uploaded the system without a "has been removed" checker.
I'ld go to wait a few seconds and recycle the index only if the GetUnitUserData() would return 0 then.

Greetings, Davey

EIDT: After some testing I got the result that for decayed units ( I waited 4 minutes ), GetUnitUserData does not work or at least not return 0. Thus my indicies were no longer recycled : /
Now I changed it so that the indicies of heroes won't be recycled; So at least the problem you talked about no longer exists.

EDIT2: Uploaded an extended version that removes the problem you were talking about by allowing a custom, individual setting wether the index is recycled or not. Hth, Davey.
 

PurgeandFire

zxcvmkgdfg
Reaction score
508
I really don't see the point in this - PUI works perfectly well. Good work anyway.

I can't see why people don't read. >.<

Well, there is no really big difference. Memory usage wise, his is
// a little bit better at the beginning. Efficiency wise, I didn't
// like his Recycling thus I created my own system which is using a
// free list and really using an attach custom value system rather
// than a single indexing method. SO: It is easier to
// instant-use, Cohadars system needs an extra implementation.
// Sure, you can extend this system too with that extra implementation.
// And With a bit of work you can do everything with Cohadars system too.
 

SerraAvenger

Cuz I can
Reaction score
234
And I can't see why people believe everything they read.

What's wrong with that ?
[...] which is using a
free list and really using an attach custom value system rather
than a single indexing method. SO: It is easier to
instant-use, Cohadars system needs an extra implementation.
To use your system you need to introduce your own global arrays and use the custom index you got.
Mine simply got such an array preimplemented.
[...] Memory usage wise, his is
// a little bit better at the beginning.
Yours uses a dynamical Memory usage which is a bit neater
Mine has an up to 2048 index predeclared array, which takes ( as far as Sooda told me ) more memory than a 0 index predeclared one. However with the time this additional array looses its memory usage importance towards your system as you got atleast one additional Array more than mine. As the memory usage of the freelist is constant, however the one of the other arrays is linear, the quotient of memory usage goes towards 1 when the other arrays go towards infinity.
[...]Efficiency wise, I didn't
// like his Recycling
That's really true. I simply don't like this periodic checking. Going through up to 2047 array fields per second is too inefficient for me. I don't even know wether your recycling works on dead units, either with decay or not. Have you ever checked it? Mine does.
// Sure, you can extend this system too with that extra implementation.
// And With a bit of work you can do everything with Cohadars system too.
This is true. You can allways use your own global arrays and use the custom values for the array indicies.
And you can ofcourse create such an integer attachment system with your system too, you'ld just need to add an additional global integer array, as well as a getter and setter function.

Also I forgot to add your system has no builtin individual "Recycling state" setter.

Now, tell me what of the things I wrote was false and which was true instead of insulting random people that just tried to help and spreading rumours you cannot document.

Not that I'ld say your system is worse then mine or better, they are just two different ways to do a similiar thing. Each one has its built-in advantages and disadvantages, and if you are lazy and only use integers to attach anyways I'ld use mine becouse
- You simply don't need to create globals and create a complicate setting and getting method ( wether you need to write additional code or you need to think everytime you use the custom index )
- The looping through the whole array gets really time consuming lateron. up to 2047 function calls within less then one second, every second... I don't like the idea of it
- You can easily increase / decrease the number of custom values per unit and the maximum number of units stored
- You can set the Recycablity for each unit individually, so that even units that theoretically COULD be revived but never again will can be freed. ( Heroes for the neutral hostile players perhaps )

Please keep friendly here all, we are not in a battlefield but in a cultivated forum.

Greetings, Davey
 

Cohadar

master of fugue
Reaction score
209
Well first of all the name of your system is false.
It is not an indexing system but an attaching system.
Therefore it means it has all properties as using gamecache for unit attaching,
witch means it is 10 times better to simply use Vexorian's CSData for the job.

PUI is everything but time consuming, the recycling algorithm is perfectly designed, and it will never lag. (pay attention to the op_limiter field)
You simply did not understand the code so the sole reason you created your system is void.

Your statement that it is easier to use than PUI is also false,
because it cannot do the same things as PUI (one example being that inventory I mentioned).
Unless you saying it is simple because it has less functionality?

Or maybe it is simply because with PUI you have to declare an array
and get function (there is not set function in PUI)
while with yours you only need to use both get and set function + declare a trigger to clear the indexes on death, or if not that handle special cases with special triggers just so you would be able to mimic PUI functionality (the mentioned inventory case)

Also what is the number of things you can attach to unit with your system, four(4)?
With PUI there is no such limit because it is not attaching but indexing system, therefore you can assign theoretically INFINITE number of data to the unit.

For the end here is a bit advice:
Next time you (or anyone else) think you can do something better (efficient,easier,whatever..) than cohadar keep in mind that I am a software engineer and that I actually went to school to make shit like this.
Therefore you can safely assume that I am older, more intelligent, more experienced and generally more badass than you.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
For the end here is a bit advice:
Next time you (or anyone else) think you can do something better (efficient,easier,whatever..) than cohadar keep in mind that I am a software engineer and that I actually went to school to make shit like this.
Therefore you can safely assume that I am older, more intelligent, more experienced and generally more badass than you.

You forgot cocky and "almost as cool as Magentix" <3
 

SerraAvenger

Cuz I can
Reaction score
234
Well first of all the name of your system is false.
It is not an indexing system but an attaching system.
Therefore it means it has all properties as using gamecache for unit attaching,
witch means it is 10 times better to simply use Vexorian's CSData for the job.

PUI is everything but time consuming, the recycling algorithm is perfectly designed, and it will never lag. (pay attention to the op_limiter field)
You simply did not understand the code so the sole reason you created your system is void.
In fact, it is an indexing system, as it assigns certain indicies to units that are lateron used as array indicies. Sorry for you if you weren't able to understand the code...

Where the hell shall that operation limiter be?
I'll simply ingore the 3 memory leaks you invoke and the few additional function calls in your code that could be removed by simply writing 5 additional letters and wouldn't matter that much for the code's maintainability and take a look at your recycling system.
Basically, you call this function every 1 second.
Code:
private function RecycleIndex takes nothing returns boolean
    local integer i 
    local integer temp

    set i = 1  // zero index is not used
    loop
        exitwhen i > topIndex
        
        if IndexDecayTime[i] == 0 then
            if (GetUnitUserData(UnitArray[i])==0) then
                set IndexDecayTime[i] = 1
            endif
        else
            set IndexDecayTime[i] = IndexDecayTime[i] + 1
            if IndexDecayTime[i] >= INDEX_DECAY_PERIODS then
                set UnitArray[i] = UnitArray[topIndex]
                set UnitArray[topIndex] = null
                set IndexDecayTime[i] = IndexDecayTime[topIndex]
                set IndexDecayTime[topIndex] = 0
                set temp = IndexArray[i]
                set IndexArray[i] = IndexArray[topIndex]
                set IndexArray[topIndex] = temp
                //debug call BJDebugMsg("|c0000FF00PUI: Index successfully recycled #" + I2S(IndexArray[topIndex]))
                set topIndex = topIndex - 1
            endif            
        endif
        
        set i = i + 1
    endloop
    
    return false
endfunction

This means for every IndexDecayTime which is 0, it will call GetUnitUserData. As soon as these are more then 1000 units, you'll have 1000 function calls a second. Hell was that perfectly designed. Too bad that mine uses 3 function calls whenever it is needed ( perhaps only twice a minute ) and fixes itselfs leaks.

If you mean "INDEX_LIMIT = 2048" with your op_limiter, you mean with that that 2048 function calls per second are ok and are still bearable for a map that has many other functions in use there? I Never tried executing 2048 functions in a row, so I cannot tell how fast that would gonna be.

Your statement that it is easier to use than PUI is also false,
because it cannot do the same things as PUI (one example being that inventory I mentioned).
Unless you saying it is simple because it has less functionality?
Or maybe it is simply because with PUI you have to declare an array
and get function (there is not set function in PUI)
while with yours you only need to use both get and set function + declare a trigger to clear the indexes on death, or if not that handle special cases with special triggers just so you would be able to mimic PUI functionality (the mentioned inventory case)

So you don't need to handle special cases with special "triggers" as you call it ( in fact it was a single function ) ? What if I use Heroes in your system but I never revive them? Then your system leaked an index. Same for units that do not decay, as far as I see your system. Becouse you only recycle indicies of removed units, those which cannot be removed will leak indicies in any case.
Apart from that you patched your system, too, in order to remove a bug "caused by attaching to "Can't Raise, Does not decay" type units." So I may patch my system too allowing for additional features and increase the functionality. It's a shame you didn't get what I meant with my getters and setters.
Look: If someone wants to use your system, he first has to create a custom array. Then he might also need to write his own setters and getters functions, especially like when he's imitating an n dimensional array ( like my system does ), or doing some other stuff at the same time. Also my getters and setters are unindexed-unit proof, which is not guarantueed when using your system. The common user might accidentally try to access to the most probably uninitialised array field [0].
At the moment it is not wrong.userdata secure, but one can only achive a 50 % security there by checking wether the unit you go the custom value from merges with the one in the unit array.
Also what is the number of things you can attach to unit with your system, four(4)?
With PUI there is no such limit because it is not attaching but indexing system, therefore you can assign theoretically INFINITE number of data to the unit.
Sorry if you cannot understand what I'm writing, but:
1. If you use less units you have more integers you can attach. If you would've read AND understood my system you would see that it uses a 2 dimensional array indexing in the custom value data, which, logically for 8192 field arrays, means that you have x rows and 8192 / x columns. For 1024 that would be 8, for 8192 1. Wasn't that hard, was it?

2. You can always declare an array and use one or more of the attached values as array indicies ( if not even just the unituserdata of the units ). Perhaps it was too hard for you to think of that, so I just tell you for the third time. Perhaps you get it at some time.

For the end here is a bit advice:
Next time you (or anyone else) think you can do something better (efficient,easier,whatever..) than cohadar keep in mind that I am a software engineer and that I actually went to school to make shit like this.
Therefore you can safely assume that I am older, more intelligent, more experienced and generally more badass than you.
Uhhh shall I be afraid now?
A software engineer that uses the same variables multiple times for different things, names his variables "i", "s" and "trig"? And that was the best you could do ( "perfectly designed" )? Ridiculous.
My mom is software engineerer too, and I'm just studying informatics ( with 16, and while parallely going to school ).
And I allways can do one thing better then you: Being polite. Perhaps instead of not reading my code you should try to go to softskill trainings, might serve you better.

Oh and btw:
The true reason for what I created the system was becouse I needed it and I don't like your recycling method. And I thought that perhaps it might be some use for someone that is but using integers and is too lazy to create his own array and write his own get / set functions .

Greetings, ( the now somewhat angry ) Davey
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
PUI can attach integers to a unit.
DUI can attach integers to a unit.
Magentix can attach a leash to his non-existing dog.

Everyone happy now? <3


P.S.: Yes, I am pointing out the fact that structs are integers and thus you could attach a huge amount of stuff to a unit using only one "integer" with both PUI and DUI and perhaps even a leash.
 

Cohadar

master of fugue
Reaction score
209
leaks? lol you even don't know what leak is do you.

So to cut the long story short:
I made a map and the map is using PUI. (and a ton of other systems I made)
And it also has more triggered stuff happening at the same time than in any other map I know of.
And guess what, it works perfectly.
Do I need anything more than that? Guess not.

I advise you to read again the last paragraph of my previous post and memorize it.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
leaks? lol you even don't know what leak is do you.

Only leaks if you allow it to...
If you know what you're doing, it won't leak...

I'm using PUI for example with struct arrays, and so far I haven't seen a single leak nor error yet since I know what I'm doing with it.
 

SerraAvenger

Cuz I can
Reaction score
234
leaks? lol you even don't know what leak is do you.

So to cut the long story short:
I made a map and the map is using PUI. (and a ton of other systems I made)
And it also has more triggered stuff happening at the same time than in any other map I know of.
And guess what, it works perfectly.
Do I need anything more than that? Guess not.

I advise you to read again the last paragraph of my previous post and memorize it.
I know what a leak is. And you have three here:
Code:
    set trig = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic( trig, RECYCLING_PERIOD )
    call TriggerAddCondition( trig, Condition(function RecycleIndex) )
    [B]
    set trig = CreateTrigger()[/B]
    call TriggerRegisterPlayerChatEvent( trig, Player(0), "-topindex", true )
    call TriggerAddCondition( trig, Condition(function DisplayTopIndex) [B])
    
    set trig = CreateTrigger()[/B]
    call TriggerRegisterPlayerChatEvent( trig, Player(0), "-pui", true )
    call TriggerAddCondition( trig, Condition(function DisplayArray) )  
[B]endfunction
[/B]

And guess what, it works perfectly.
Do I need anything more than that? Guess not.
Did I ever tell yours wouldn't work? Did I ever say mine was better than yours?
While you said that about mine, I didn't about yours.
They are simply two different ways to approach a similiar goal. Well I'm happy with the way my system works, and that's all I need. I just didn't want to use a system made by YOU in my map. Simply becouse it's by you. 2 days ago I didn't have this feeling, but with the way you reacted to another system I can only tell that.
Greetings, Davey
 

Cohadar

master of fugue
Reaction score
209
Those are not handle leaks.
Only objects that are destroyed can have handle leaks.
 

SerraAvenger

Cuz I can
Reaction score
234
Those are not handle leaks.
Only objects that are destroyed can have handle leaks.

These are memory leaks
You allocate memory for triggers, three times
And then you simply remove the sole reference to them.
Now they are unreferenced objects. This the definition of a memory leak. It doesn't matter wether they are wanted leaks or unwanted leaks. But they are leaks. As they are intentional and only 3, there's not that much of a point in cleaning these.
Yet, if we had a garbage collector in JASS, both our code would not work, as all our triggers would be removed as soon as the garbage collector would do its rounds. ( As a software enigeer you know that most GC implementations don't look there for leaks all the time, they rather go over the whole memory every xxx seconds checking for unreferenced objects and self-references in huger object data. ). But as there is none, we can all live happily and in peace. At least we can try to.

just a thought... You are sure you know what a memory leak is, aren't you? Not as an insult, or some sort of disbelief in your personality, but not everyone needs to know everything...


Greetings, Davey
 

Cohadar

master of fugue
Reaction score
209
No those are not memory leaks.
Leak is when you have an unreferenced unused object.
That means an object wasting memory with no reason.

Also the references to those triggers are not lost,
you can access any of them with a GetTriggeringTrigger().

JASS does not have garbage collector, it has handle recycler.
Those are 2 completely different thing.

Handle is not a pointer it is Id of a struct (in the lack of a better name)
that is pointing to a real in-game object.

So handles are used as a connection between the jass virtual machine memory and a real game memory.

JASS:
struct Handle
    void* pointer  // pointing to real game object
    integer refCounter // number of jass variables that have id of this handle
endstruct


Why we null locals:
JASS:
local location loc = GetSpellTargetLoc() // refCounter == 1
local location loc2 = loc // refCounter == 2
set loc2 = null // refCounter == 1
set loc = null // refCounter == 0


When a function ends if a reference counter for a handle is not zero the handle cannot be recycled.
That is called a handle leak.

I hope that was clear enough.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top