System DAS - Data Attachment System

Flare

Stops copies me!
Reaction score
662
JASS:
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)
                call BJDebugMsg (GetUnitName (U<i>))
                set U[UN] = U<i>
                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)
    call BJDebugMsg (GetUnitName (U[UN]))
    return U[UN]
endfunction</i></i></i></i></i></i></i>


With your demonstration, it displayed Footman 3 times (even though the Id parameter only used 'hfoo' twice)
 

Vestras

Retired
Reaction score
249
Uhm.. That's extremely strange. With me it shows footman, peasant, footman and the footman kills the peasant.
Updated.
 

saw792

Is known to say things. That is all.
Reaction score
280
You need to add |r to the end of your system messages. They don't display with the correct colour without it.
 

emootootoo

Top Banana
Reaction score
51
Your System DAS:

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&#039;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&#039;s TimerUtils, but isn&#039;t so   \\
// much that it means something. I think it&#039;s just as fast as        \\
// TimerUtils (Blue), so speed isn&#039;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   = &quot;|cffff0000&quot; // 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&#039;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 &gt; DAS_MAX then
                    call BJDebugMsg(DAS_SYSTEMCOLOR + &quot;System: number of struct data attached at the same time greater than max. You are in big trouble my friend!&quot;)
                    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(&quot;public&quot;, &quot;handle&quot;, &quot;Handle&quot;)
                
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 + &quot;System: cannot release null timers&quot;)
            return
        endif
        if TN == 8191 then
            call DestroyTimer(t)
        else
            call PauseTimer(t)
        if GetHandleData(t) == RANDOM then
            debug call BJDebugMsg(SYSTEMCOLOR + &quot;System: double free!&quot;)
            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 &gt; 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>



TimerUtils:
JASS:
library_once TimerUtils
//*********************************************************************
//* TimerUtils (Blue flavor)
//* ----------
//*
//*  To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//*  To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass)   More scripts: htt://www.wc3campaigns.net
//*
//* For your timer needs:
//*  * Attaching
//*  * Recycling (with double-free protection)
//*
//* set t=NewTimer()      : Get a timer (alternative to CreateTimer)
//* ReleaseTimer(t)       : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2)     : Attach value 2 to timer
//* GetTimerData(t)       : Get the timer&#039;s value.
//*                         You can assume a timer&#039;s value is 0
//*                         after NewTimer.
//*
//* Blue Flavor: Slower than the red flavor, it got a 408000 handle id
//*             limit, which means that if more than 408000 handle ids
//*             are used in your map, TimerUtils might fail, this
//*             value is quite big and it is much bigger than the 
//*             timer limit in Red flavor.
//*
//********************************************************************

//================================================================
    globals
        private constant integer MAX_HANDLE_ID_COUNT = 408000
        // values lower than 8191: very fast, but very unsafe.
        // values bigger than 8191: not that fast, the bigger the number is the slower the function gets
        // Most maps don&#039;t really need a value bigger than 50000 here, but if you are unsure, leave it
        // as the rather inflated value of 408000
    endglobals

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

    //==================================================================================================
    globals
        private integer array data[MAX_HANDLE_ID_COUNT]
        private constant integer MIN_HANDLE_ID=0x100000
    endglobals

    //It is dependent on jasshelper&#039;s recent inlining optimization in order to perform correctly.
    function SetTimerData takes timer t, integer value returns nothing
        debug if(H2I(t)-MIN_HANDLE_ID&gt;=MAX_HANDLE_ID_COUNT) then
        debug     call BJDebugMsg(&quot;SetTimerData: Handle id too big, increase the max handle id count or use gamecache instead&quot;)
        debug endif
        set data[H2I(t)-MIN_HANDLE_ID]=value
    endfunction

    function GetTimerData takes timer t returns integer
        debug if(H2I(t)-MIN_HANDLE_ID&gt;=MAX_HANDLE_ID_COUNT) then
        debug     call BJDebugMsg(&quot;GetTimerData: Handle id too big, increase the max handle id count or use gamecache instead&quot;)
        debug endif
        return data[H2I(t)-MIN_HANDLE_ID]
    endfunction

    //==========================================================================================
    globals
        private timer array tT
        private integer tN = 0
        private constant integer HELD=0x28829022
        //use a totally random number here, the more improbable someone uses it, the better.
    endglobals

    //==========================================================================================
    function NewTimer takes nothing returns timer
        if (tN==0) then
            set tT[0]=CreateTimer()
        else
            set tN=tN-1
        endif
        call SetTimerData(tT[tN],0)
     return tT[tN]
    endfunction

    //==========================================================================================
    function ReleaseTimer takes timer t returns nothing
        if(t==null) then
            debug call BJDebugMsg(&quot;Warning: attempt to release a null timer&quot;)
            return
        endif
        if (tN==8191) then
            debug call BJDebugMsg(&quot;Warning: Timer stack is full, destroying timer!!&quot;)

            //stack is full, the map already has much more troubles than the chance of bug
            call DestroyTimer(t)
        else
            call PauseTimer(t)
            if(GetTimerData(t)==HELD) then
                debug call BJDebugMsg(&quot;Warning: ReleaseTimer: Double free!&quot;)
                return
            endif
            call SetTimerData(t,HELD)
            set tT[tN]=t
            set tN=tN+1
        endif    
    endfunction

endlibrary

So considering yours is pretty much TimerUtils copied but with more recycling/handles supported?, shouldn't you release it as a mod/addon of TimerUtils and not a system?

This comes to mind from the submission rules thread:

Do not submit other people's work.

And yeah, I saw you give Vexorian credit for the "idea" in your code, but that should really say "code" and be in big bold text at the top of the post or something.

Sorry for not having very positive feedback, but as others have stated, there isn't really much point releasing things that already exist if you aren't doing a better job.

Damn, I'm being a hard-ass, sorry. :(

(I like your RPG though, it's wicked, besides the tree problem, lol.)
 

Vestras

Retired
Reaction score
249
Hehe.. Hehe.. Well, yes. Though as I said earlier, it didn't start this way. I tested multiple stuff, in which much didn't work, and all the other didn't work properly. So, I got an idea; what about mixing TimerUtils and HAIL, so that you could use TimerUtils for not only timers. Well, it works really well, and I'm really glad of the result. Then people can choose if they want to use it or not.

(And thanks about that RPG thing :p)
 

Flare

Stops copies me!
Reaction score
662
what about mixing TimerUtils and HAIL
That'd be, pretty much, CSData + CSSafety - the system doesn't really have anything new or exceptional (the unit recycling, while useful, has limited usage since units tend to do alot of stuff without anyone noticing) that makes it stand out above the rest which doesn't really make it justifiable to use over system(s) that people already know how to use
 

Flare

Stops copies me!
Reaction score
662
CS (the individual system, not the whole package) is very different to CSData - CS (from what I know) consists of functions to aid in spells such as functions for casting (I haven't looked at CS in a long time so I don't really know exactly what is contains, but alot of it is related to spellmaking as far as I know)

CSData, on the other hand, is the struct attachment system contains within the CS package but it can be used independently of everything else in the package, and there isn't anything wrong with using it (since it's small, simple, and does exactly what it's meant to do) - from my understanding, CSData is certainly not outdated
 

Vestras

Retired
Reaction score
249
Oh, well. Damn.
Well, I like what it came out to, and I use it for all my stuff, works great and fast. (Don't know if it's faster than other stuff though, probably isn't.)
 

Darius34

New Member
Reaction score
30
Posted in the wrong place, sorry.

Edit: Since I'm here anyway...

But yeah, while it's nice having all these things in one package, everything is pretty much Vex's work, apart from the unit-recycling code.

Also, why would one use the textmacro with Get/SetHandleData()?
 

Vestras

Retired
Reaction score
249
Posted in the wrong place, sorry.

Edit: Since I'm here anyway...

But yeah, while it's nice having all these things in one package, everything is pretty much Vex's work, apart from the unit-recycling code.

Also, why would one use the textmacro with Get/SetHandleData()?

Because when you use the textmacro, you generate a new attaching data global, which makes it harder to have maximum data at the same, even though that's nearly impossible... if you reached the maximum, you're fucked.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top