System DAS - Data Attachment System

Vestras

Retired
Reaction score
248
Data Attachment System
kthxbye?

So, basicly, this system is like ABC, HAIL, HSAS; it stores struct data. Now, does ABC, HAIL, HSAS allow recycling? This does. It allows timer and unit recycling, and then every single thing-struct data attaching!

NOTICE - Requires vJASS!!!

Code: (Sorry, it's pretty heavy.)
JASS:
//===================================================================\\
//             D A T A  A T T A C H M E N T  S Y S T E M             \\
//                        B Y  V E S T R A S                         \\
//===================================================================\\

//===================================================================\\
// U S A G E:                                                        \\
//                                                                   \\
// In the top of your trigger, run DAS_CreateFunctions textmacro,    \\
// this will create all necessary data attachment functions for use. \\
//                                                                   \\
//===================================================================\\

//===================================================================\\
// P R O S  /  C O N S:                                              \\
//                                                                   \\
// Pros:                                                             \\
// Using this system, you are able to store data in whatever you     \\
// want, whether it's stupid or not. (Timers, units, triggers, you   \\
// name it.) You can also recycle timers and units.                  \\
//                                                                   \\
// Cons:                                                             \\
// A little bit lower max than Vexorian's TimerUtils, but isn't so   \\
// much that it means something. I think it's just as fast as        \\
// TimerUtils (Blue), so speed isn't a problem.                      \\
//===================================================================\\

//===================================================================\\
// G I V E  C R E D I T  T O  V E S T R A S !!!                      \\
//===================================================================\\

library DAS

            // Globals
            globals
                        public constant string         SYSTEMCOLOR   = "|cffff0000" // The color used in system messages
                        // End of globals
            endglobals

        public function H2I takes handle h returns integer
            return h
            return 0
        endfunction
            
        globals
            public integer INTEGER = 0x100000
            // Taken from Vexorian's TimerUtils
            public constant integer MAX  = 400000
            // A little bit lower than TimerUtils (Blue)
        endglobals
            
        //! textmacro DAS_CreateFunctions takes SCOPE, TYPE, NAME
        
        globals
            $SCOPE$ integer array DATA[DAS_MAX]
            // Used for storing the data
            $SCOPE$ integer TIMES = 0
            // Counter
        endglobals
        
            $SCOPE$ function Set$NAME$Data takes $TYPE$ h, integer d returns nothing
                set TIMES = TIMES + 1
                if TIMES > DAS_MAX then
                    call BJDebugMsg(DAS_SYSTEMCOLOR + "System: number of struct data attached at the same time greater than max. You are in big trouble my friend!")
                    return
                endif
                set DATA[DAS_H2I(h) - DAS_INTEGER] = d
            endfunction
            
            $SCOPE$ function Get$NAME$Data takes $TYPE$ h returns integer
                set TIMES = TIMES - 1
                return DATA[DAS_H2I(h) - DAS_INTEGER]
            endfunction

            //! endtextmacro
            
// Setting handle data, for recycling (can be for public use as well though)

    globals
            // Used for displaying stuff
            private integer HTIMES = 0
    endglobals

                //! runtextmacro DAS_CreateFunctions("public", "handle", "Handle")
                
globals
        private timer array T
        private integer TN = 0
        private unit array U
        private integer UN = 0
        private constant integer RANDOM = 0x558329029
        // Used for displaying stuff
        private integer UNITS = 0
        private integer TIMERS = 0
endglobals

// Credits to Vexorian for this idea, this does not work with units, please use non-textmacro function below
public function NewTimer takes nothing returns timer
    if TN == 0 then
        set T[0] = CreateTimer()
    else
        set TN = TN - 1
    endif
    call SetHandleData(T[TN], 0)
    return T[TN]
endfunction

public function ReleaseTimer takes timer t returns nothing
    if t == null then
            call BJDebugMsg(SYSTEMCOLOR + "System: cannot release null timers")
            return
        endif
        if TN == 8191 then
            call DestroyTimer(t)
        else
            call PauseTimer(t)
        if GetHandleData(t) == RANDOM then
            debug call BJDebugMsg(SYSTEMCOLOR + "System: double free!")
            return
        endif
        call SetHandleData(t, RANDOM)
        set T[TN] = t
        set TN = TN + 1 
        set TIMERS = TN
    endif
endfunction

public function NewUnit takes player p, integer id, real x, real y returns unit
    local integer i = 0
    local boolean b = false
      if UN != 0 then
        loop
            exitwhen i > UN or b
                if id == GetUnitTypeId(U<i>) then
                    call ShowUnit(U<i>, true)
                        call SetUnitX(U<i>, x)
                            call SetUnitY(U<i>, y)
                                call SetUnitOwner(U<i>, p, true)
                        set b = true
                        else
                            set i = i + 1
                        endif
                    endloop
            if b != true then
                call CreateUnit(p, id, x, y, 0)
            endif
        endif
    if UN == 0 then
        set U[0] = CreateUnit(p, id, x, y, 0)
    else
        set UN = UN - 1
    endif
    call SetHandleData(U[UN], 0)
    return U<i>
endfunction

public function ReleaseUnit takes unit u returns nothing
    if u == null then
            call BJDebugMsg(SYSTEMCOLOR + &quot;System: cannot release null units&quot;)
            return
        endif
        if UN == 8191 then
            call RemoveUnit(u)
        else
            call ShowUnit(u, false)
        if GetHandleData(u) == RANDOM then
            debug call BJDebugMsg(SYSTEMCOLOR + &quot;System: double free!&quot;)
            return
        endif
        call SetHandleData(u, RANDOM)
        set U[UN] = u
        set UN = UN + 1 
        set UNITS = UN
    endif
endfunction

public function DisplayData takes nothing returns nothing
    call BJDebugMsg(SYSTEMCOLOR + &quot;//=====================================================\\&quot;)
    call BJDebugMsg(SYSTEMCOLOR + &quot;//Current number of units in system: &quot; + I2S(UNITS))
    call BJDebugMsg(SYSTEMCOLOR + &quot;//Current number of timers in system: &quot; + I2S(TIMERS))
    call BJDebugMsg(SYSTEMCOLOR + &quot;//Current number of struct attachments for handles: &quot; + I2S(HTIMES))
    call BJDebugMsg(SYSTEMCOLOR + &quot;//=====================================================\\&quot;)
endfunction

endlibrary</i></i></i></i></i></i>


I hope you guys goddamnit enjoys this one, it was really hard making. :)
 

Forty

New Member
Reaction score
6
looks like csdata with a bit more type-safety. but why use it? why throw away TT, ABCT, ABC and CSData?

and ive already got recycling, also with timers. and the unit recycling is not even a good idea in my opinion (if you have too many units, it will lag, its like memory leaks)
 

Flare

Stops copies me!
Reaction score
662
Hmmm, why is INTEGER public and non-constant? Someone could easily just do
JASS:
set DAS_INTEGER = InduceSystemFailure () //or something else that would be able to change the value such as
set DAS_INTEGER = 1


And you should add something to the documentation about the fact that there is a pre-existing function available (since you ran the textmacro within the system) so they don't really need to do it again

every single thing-struct data attaching!
??? You mean handle-struct attachment?

And why are your global blocks separated in the top section of code, and why did you go mad with Tab key when indenting SYSTEMCOLOR (and the whole library for that matter, there's no real need to indent global/function/struct/other declarations (i.e. the ones that are contained in 'blocks')
 

Vestras

Retired
Reaction score
248
> looks like csdata with a bit more type-safety. but why use it? why throw away TT, ABCT, ABC and CSData?

and ive already got recycling, also with timers. and the unit recycling is not even a good idea in my opinion (if you have too many units, it will lag, its like memory leaks)

The same reason you would use TimerUtils over these. This is like a bigger version of TimerUtils.

> Flare

I'll make it private constant. And could people please stop complaining about my indentation?
Whoops, the prefix should be System, not spellpack, could some mod please change it?
 

Flare

Stops copies me!
Reaction score
662
And could people please stop complaining about my indentation?
But it is quite scattered - with regard to the attachment system section of the code, that's probably the only thing that sticks out (since it's clearly out of line with other things). I won't start on the other section of the code, since any 'discussion' probably won't bring about any change (since you seem to back your indenting method strongly :p)
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
Ohh, not another attachment system... I think we have enough of them. Why do people keep making and making new ones? Personally, I'll still stick to the older ones, since they are a lot better than the fresh made and I'm used to using them. There's no reason to keep recreating one same thing with different names - it's really pointless. Anyway, good luck with it.
 

Forty

New Member
Reaction score
6
The same reason you would use TimerUtils over these. This is like a bigger version of TimerUtils.

why would i use TimerUltils? i dont see a point in that as i dont know TimerUtils and also like ABC, etc, because they are user-friendly and efficent. so i dont see a use in this system
 

Vestras

Retired
Reaction score
248
> Flare

Well, then, end of discussion :)

> cr4xzZz

Well, I actually made this because I thought TimerUtils was awesome, and I wanted it for not only timers.

> Forty

Because it's awesome. (Yes, that's a valid reason.)
 

Flare

Stops copies me!
Reaction score
662
Well, I actually needed unit recycling as well
Copy your unit recycling code into CSSafety once you import

Well, CSData isn't CS (it's a part of the whole package, but CSData, by itself, is independent of everything else in the package) - Safety requires Data, SafeCache requires Data, and I think the Caster System functions themselves requires SafeCache and/or Data

Code:
exitwhen i > UN
You could make that
JASS:
exitwhen i &gt; UN or b

and remove the bit where you set i = UN

Code:
return U[UN]
Hmmmm, that may not be the right unit - let's say you have 50 units in the list, and unit 25 (when i == 25) is suitable. You are returning unit 50 (since UN is 50) even though unit 25 is the first suitable unit found (so you may end up returning the wrong unit) - you should be returning the unit within the then actions (where id == GetUnitTypeId (u) ) - maybe you already are, but your indentation is making things hard to read :p

Test it out with the last unit in the list being of a totally different type to the intended one
 

Hatebreeder

So many apples
Reaction score
381
Did you run any Tests to check whether this is faster than other Systems? Oder maybe efficient than other Systems? All I can see right now is, that your claiming that it is good. Explain please =)
Also, does it have any restrictions like in ABC (it only allows Timers, Dialogs and Triggers to handle, i think) ?
 
Z

ZyrX

Guest
Did you run any Tests to check whether this is faster than other Systems? Oder maybe efficient than other Systems? All I can see right now is, that your claiming that it is good. Explain please =)
Also, does it have any restrictions like in ABC (it only allows Timers, Dialogs and Triggers to handle, i think) ?

He already said this is a somewhat confusing manner:

and then every single thing-struct data attaching!

So from what I understood, you can attach to any handle.
 

Forty

New Member
Reaction score
6
it allows everything and should be faster than ABC but i think it will slow down if your map leaks
 

Vestras

Retired
Reaction score
248
You can attach data to anything you want, by running the textmacro.

JASS:
//! runtextmacro DAS_CreateFunctions(&quot;private&quot;, &quot;timer&quot;, &quot;Timer&quot;)


That will make you able to attach to timers.
But you can also, if you're lazy, just use the already existing handle attacher:
JASS:
call DAS_SetHandleData(...)
call DAS_GetHandleData(...)


Haven't run a speed test yet, I was actually going to ask if anyone knew a good and easy way to do it, so is there?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top