System DS - Data Store

Reaction score
456
DS - Data Store
by: Uberplayer​


So this is just another struct attaching system. I've been testing this many many times, and no problems thus far. This has some kind of a extended arrays system (written by me also) inside the library, but I made them private, because this system uses them.. so they shouldn't be used anywhere else.

Hopefully this does not look like a copy of another already made system.

Code:
JASS:
//= = = = = = = = = = = = = = = =
// DS - DATA STORE
//= = = = = = = = = = = = = = = =
// Author:  Uberplayer @thehelper
// Version: 2.0
// Date:    02/25/2008 - 03/03/2008

//= = = = = = = = = = = = = = = =
// Implementing
// ¯¯¯¯¯¯¯¯¯¯¯¯
// Just copy this trigger to your map. Only system DS
// requires is Extended Arrays, which can be found from 
// this library.
//
// How To Use?
// ¯¯¯¯¯¯¯¯¯¯¯
// You can store one integer per one trigger or
// timer.
//
// Use these functions to store integer to a handle:
//   call SetTriggerData(trigger whichTrigger, integer data)
//   call SetTimerData(timer whichTimer, integer data)
//
// Use these functions to get an integer from a handle:
//   call GetTriggerData(trigger whichTrigger)
//   call GetTimerData(timer whichTimer)

library DataStore

public function H2I takes handle h returns integer
    return h
    return 0
endfunction

//=-=-=
// I. EXTENDED ARRAYS
//=-=-=
    
    //! textmacro ExtendedArrays takes TYPE, TYPENAME, REMOVE
    globals
        private $TYPE$ array $TYPE$ArrayA // 0     - 8192
        private $TYPE$ array $TYPE$ArrayB // 8193  - 16385
        private $TYPE$ array $TYPE$ArrayC // 16386 - 24578
        private $TYPE$ array $TYPE$ArrayD // 24579 - 32771
        private $TYPE$ array $TYPE$ArrayE // 32772 - 40964
        private $TYPE$ array $TYPE$ArrayF // 40965 - 49157
        private $TYPE$ array $TYPE$ArrayG // 49158 - 57350
        private $TYPE$ array $TYPE$ArrayH // 57351 - 65543
    endglobals
    
    private function Get$TYPENAME$Array takes integer index returns $TYPE$
        local integer loopA = index
        
        if index < 8193 then
            return $TYPE$ArrayA[index]
        elseif index < 16386 then
            return $TYPE$ArrayB[index - 8193]
        elseif index < 24579 then
            return $TYPE$ArrayC[index - 16386]
        elseif index < 32772 then
            return $TYPE$ArrayD[index - 24579]
        elseif index < 40965 then
            return $TYPE$ArrayE[index - 32772]
        elseif index < 49158 then
            return $TYPE$ArrayF[index - 40965]
        elseif index < 57351 then
            return $TYPE$ArrayG[index - 49158]
        elseif index < 65544 then
            return $TYPE$ArrayH[index - 57351]
        endif
        
        return $REMOVE$
    endfunction
    
    private function Set$TYPENAME$Array takes $TYPE$ value, integer index returns nothing
        local integer loopA = index
        
        if index < 8193 then
            set $TYPE$ArrayA[index] = value
        elseif index < 16386 then
            set $TYPE$ArrayB[index - 8193] = value
        elseif index < 24579 then
            set $TYPE$ArrayC[index - 16386] = value
        elseif index < 32772 then
            set $TYPE$ArrayD[index - 24579] = value
        elseif index < 40965 then
            set $TYPE$ArrayE[index - 32772] = value
        elseif index < 49158 then
            set $TYPE$ArrayF[index - 40965] = value
        elseif index < 57351 then
            set $TYPE$ArrayG[index - 49158] = value
        elseif index < 65544 then
            set $TYPE$ArrayH[index - 57351] = value
        endif
    endfunction
    //! endtextmacro
    
    //! runtextmacro ExtendedArrays("integer", "Integer", "-1")
    //! runtextmacro ExtendedArrays("trigger", "Trigger", "null")
    //! runtextmacro ExtendedArrays("timer", "Timer", "null")
    //! runtextmacro ExtendedArrays("unit", "Unit", "null")
    
//=-=-=
// II. DATA STORE
//=-=-=

    //! textmacro DataStore takes TYPE, TYPENAME
    function Get$TYPENAME$Data takes $TYPE$ which$TYPENAME$ returns integer
        local integer loopA = 0
        
        local integer id = H2I(which$TYPENAME$) - 23104 * 45
        
        if Get$TYPENAME$Array(id) != which$TYPENAME$ then
            debug call BJDebugMsg("|CFFED1C24DS Error (get): Unknown handle.")
            return -1
        endif
        
        return GetIntegerArray(id)
    endfunction

    function Set$TYPENAME$Data takes $TYPE$ which$TYPENAME$, integer data returns nothing
        local integer loopA = 0
        
        local integer id = H2I(which$TYPENAME$) - 23104 * 45
        
        if which$TYPENAME$ == null then
            debug call BJDebugMsg("|CFFED1C24DS Error (set): Null handles not allowed.")
            return
        endif
        
        call SetIntegerArray(data, id)
        call Set$TYPENAME$Array(which$TYPENAME$, id)
    endfunction
    //! endtextmacro
    
    //! runtextmacro DataStore("trigger", "Trigger")
    //! runtextmacro DataStore("timer", "Timer")
    //! runtextmacro DataStore("unit", "Unit")
    
endlibrary
 
Reaction score
456
It works like ABC.. but the code is not like ABC's. You don't have to clear the value though.

>Small typo there on GetTimerData (it should be timer whichTimer right?)
Thanks for pointing it out.
 

Hatebreeder

So many apples
Reaction score
381
DS - Data Store
by: Uberplayer​


So this is just another struct attaching system. I've been testing this many many times, and no problems thus far. This has some kind of a extended arrays system (written by me also) inside the library, but I made them private, because this system uses them.. so they shouldn't be used anywhere else.

Hopefully this does not look like a copy of another already made system.

Code:
JASS:
//= = = = = = = = = = = = = = = =
// DS - DATA STORE
//= = = = = = = = = = = = = = = =
// Author:  Uberplayer @thehelper
// Version: 1.0
// Date:    02/25/2008 - 03/02/2008

//= = = = = = = = = = = = = = = =
// Implementing
// ¯¯¯¯¯¯¯¯¯¯¯¯
// Just copy this trigger to your map. Only system DS
// requires is Extended Arrays, which can be found from 
// this library.
//
// How To Use?
// ¯¯¯¯¯¯¯¯¯¯¯
// You can store one integer per one trigger or
// timer.
//
// Use these functions to store integer to a handle:
//   call SetTriggerData(trigger whichTrigger, integer data)
//   call SetTimerData(timer whichTimer, integer data)
//
// Use these functions to get an integer from a handle:
//   call GetTriggerData(trigger whichTrigger)
//   call GetTimerData(trigger whichTrigger)

library DataStore

public function H2I takes handle h returns integer
    return h
    return 0
endfunction

//=-=-=
// I. EXTENDED ARRAYS
//=-=-=
    
    //! textmacro ExtendedArrays takes TYPE, TYPENAME, REMOVE
    globals
        private $TYPE$ array $TYPE$ArrayA // 0     - 8192
        private $TYPE$ array $TYPE$ArrayB // 8193  - 16385
        private $TYPE$ array $TYPE$ArrayC // 16386 - 24578
        private $TYPE$ array $TYPE$ArrayD // 24579 - 32771
        private $TYPE$ array $TYPE$ArrayE // 32772 - 40964
        private $TYPE$ array $TYPE$ArrayF // 40965 - 49157
        private $TYPE$ array $TYPE$ArrayG // 49158 - 57350
        private $TYPE$ array $TYPE$ArrayH // 57351 - 65543
    endglobals
    
    private function Get$TYPENAME$Array takes integer index returns $TYPE$
        local integer loopA = index
        
        if     index > -1    and index < 8193  then
            return $TYPE$ArrayA[loopA]
        elseif index > 8192  and index < 16386 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            return $TYPE$ArrayB[loopA]
        elseif index > 16385 and index < 24579 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            return $TYPE$ArrayC[loopA]
        elseif index > 24578 and index < 32772 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            return $TYPE$ArrayD[loopA]
        elseif index > 32771 and index < 40965 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            return $TYPE$ArrayE[loopA]
        elseif index > 40964 and index < 49158 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            return $TYPE$ArrayF[loopA]
        elseif index > 49157 and index < 57351 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            return $TYPE$ArrayG[loopA]
        elseif index > 57350 and index < 65544 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            return $TYPE$ArrayH[loopA]
        endif
        
        return $REMOVE$
    endfunction
    
    private function Set$TYPENAME$Array takes $TYPE$ value, integer index returns nothing
        local integer loopA = index
        
        if     index > -1    and index < 8193  then
            set $TYPE$ArrayA[index] = value
        elseif index > 8192  and index < 16386 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            set $TYPE$ArrayB[loopA] = value
        elseif index > 16385 and index < 24579 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            set $TYPE$ArrayC[loopA] = value
        elseif index > 24578 and index < 32772 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            set $TYPE$ArrayD[loopA] = value
        elseif index > 32771 and index < 40965 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            set $TYPE$ArrayE[loopA] = value
        elseif index > 40964 and index < 49158 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            set $TYPE$ArrayF[loopA] = value
        elseif index > 49157 and index < 57351 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            set $TYPE$ArrayG[loopA] = value
        elseif index > 57350 and index < 65544 then
            loop
                set loopA = loopA - 8193
                exitwhen loopA <= 8192
            endloop
            set $TYPE$ArrayH[loopA] = value
        endif
    endfunction
    //! endtextmacro
    
    //! runtextmacro ExtendedArrays("integer", "Integer", "-1")
    //! runtextmacro ExtendedArrays("trigger", "Trigger", "null")
    //! runtextmacro ExtendedArrays("timer", "Timer", "null")
    
//=-=-=
// II. DATA STORE
//=-=-=

    //! textmacro DataStore takes TYPE, TYPENAME
    function Get$TYPENAME$Data takes $TYPE$ which$TYPENAME$ returns integer
        local integer loopA = 0
        
        local integer id = H2I(which$TYPENAME$)
        
        loop
            exitwhen loopA == 10
            set id = id - (152 * 152) * loopA
            set loopA = loopA + 1
        endloop
        
        if Get$TYPENAME$Array(id) != which$TYPENAME$ then
            debug call BJDebugMsg("|CFFED1C24DS Error (get): Unknown handle.")
            return -1
        endif
        
        return GetIntegerArray(id)
    endfunction

    function Set$TYPENAME$Data takes $TYPE$ which$TYPENAME$, integer data returns nothing
        local integer loopA = 0
        
        local integer id = H2I(which$TYPENAME$)
        
        if which$TYPENAME$ == null then
            debug call BJDebugMsg("|CFFED1C24DS Error (set): Null handles not allowed.")
            return
        endif
        
        loop
            exitwhen loopA == 10
            set id = id - (152 * 152) * loopA
            set loopA = loopA + 1
        endloop
        
        call SetIntegerArray(data, id)
        call Set$TYPENAME$Array(which$TYPENAME$, id)
    endfunction
    //! endtextmacro
    
    //! runtextmacro DataStore("trigger", "Trigger")
    //! runtextmacro DataStore("timer", "Timer")
    
endlibrary

Holy crap :eek:
Ummm... Can you give details, to why I should use you System? Like, give me a list of features ^^
Can I use this to attach a struct, to wherever I want?
or only to Timers, or something?
Is this a fast System?
Are there any Cons about this System?
What must I call to Handle a Struct?
 
Reaction score
456
>why I should use you System?
To attach an integer to a timer or a trigger.

>Can I use this to attach a struct, to wherever I want?
Timers and triggers currently.

>Is this a fast System?
Enough fast.

>Are there any Cons about this System?
Limit of one integer per handle.

>What must I call to Handle a Struct?
What do you mean?


>Hm, struct storage system, right?
You got it right.

>How fast is this?
Enough fast. It uses just small loops and few if then elses.. very simple.
 
Reaction score
456
Well yes. Then. It works the same way, but there is no As Bs and Cs.
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
It looks easy to use. Could you run some kind of a speed or quality test? ^^
 

Steel

Software Engineer
Reaction score
109
It looks easy to use. Could you run some kind of a speed or quality test? ^^

Name a condition where you have actually noticed a problem with the speed of struct attachments?

I can only think of one in my own map that I was able to force through sloppy coding. After cleaning it up I was able to easily make it not the least bit noticeable.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
Not like I'll use it now that I'm hung up on Cohadar's TT and ABC, but it's nice to see people still try to come up with an equal or, God forbid, better system.

Cohadar's like Microsoft and you guys are like the little Linuxes and Macs that wouldn't go away ;)

Keep it up,
+rep

Edit: need to spread the <3 a bit more first before I can hand it to you again :eek:
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Can I attach multiple struct to 1 same handle?

@How fast --> Try do a benchmark that HSAS done.
 
Reaction score
456
>Can I attach multiple struct to 1 same handle?
One integer per one handle. If you attach another integer to same handle, it will overwrite the previous one. :)

>Cohadar's like Microsoft and you guys are like the little Linuxes and Macs that wouldn't go away
Haha, nice x)
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Hmm, then is system is not equivalent with ABC nor HSAS.
 
Reaction score
456
Well.. name a situation where you need many integers for one handle?

I always use just one struct for one spell.. excluding few exceptions, but in those, I've used another trigger for the other struct.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
Can I attach multiple struct to 1 same handle?

Yes you can structs are nothing but integers representing data packets, so you could use a packet struct:

JASS:
library Packets initializer Init
    interface PacketStruct
    endinterface

    struct A extends PacketStruct
        integer i = 0
    endstruct

    struct B extends PacketStruct
        integer i = 0
    endstruct

    struct C extends PacketStruct
        integer i = 0
    endstruct


    struct Packet
        private integer Counter = 0
        private integer structCount = 8 // &lt;----&lt;&lt; Change this to allow more or less structs
        private PacketStruct array Structs[8] // &lt;----&lt;&lt; Change this to allow more or less structs

        method GetStructFromPacket takes integer typeid returns PacketStruct
            local integer i = 0

            loop
            exitwhen i &gt; .structCount - 1
                if .Structs<i>.getType() == typeid then
                    return .Structs<i>
                endif

                set i = i + 1
            endloop
            return 0
        endmethod

        method AddStructToPacket takes PacketStruct S returns nothing
            if .Counter == .structCount then
                debug call BJDebugMsg(&quot;Error: Struct packet is full.&quot;)
                return
            endif
            
            set .Structs[.Counter] = S
            set .Counter = .Counter + 1
        endmethod
    endstruct

    private function Actions takes nothing returns nothing
        local A a = A.create()
        local B b = B.create()
        local C c = C.create()
        local Packet p = Packet.create()
     
        set a.i = 1
        set b.i = 2
        set c.i = 3
      
        call p.AddStructToPacket(a)
        call p.AddStructToPacket(b)
        call p.AddStructToPacket(c)
      
        set a = p.GetStructFromPacket(A.typeid) // Retrieve the struct of type A
        set b = p.GetStructFromPacket(B.typeid) // Retrieve the struct of type B
        set c = p.GetStructFromPacket(C.typeid) // Retrieve the struct of type C
        
        call BJDebugMsg(I2S(a.i))
        call BJDebugMsg(I2S(b.i))
        call BJDebugMsg(I2S(c.i))
      
        call a.destroy()
        call b.destroy()
        call c.destroy()
        call p.destroy()
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger T = CreateTrigger()
        call TriggerRegisterTimerEventSingle(T,5.00)
        call TriggerAddAction(T,function Actions)
    endfunction
endlibrary
</i></i>



Only limit is you can only attach one A, B, C, etc. to the packet; never 2 A's, 3B's, etc.

P.S.: Wrote this from the top of my head, but I think it works
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Lmao, you just abusing the CSSafety system Vex made. But nvm, thanks.

I don't feel like doing extra job myself only.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
JASS:
library CSSafety
//******************************************************************************************
//*
//* CSSafety 14.4
//* ¯¯¯¯¯¯¯¯
//*
//*  Utilities to make things safer. Currently this simply includes a timer recycling
//* Stack. Once you replace CreateTimer with NewTimer and DestroyTimer with ReleaseTimer
//* you no longer have to care about setting timers to null nor about timer related issues
//* with the handle index stack.
//*
//******************************************************************************************

    //==========================================================================================
    globals
        private timer array T
        private integer N = 0
    endglobals

    //==========================================================================================
    function NewTimer takes nothing returns timer
        if (N==0) then
            return CreateTimer()
        endif
     set N=N-1
     return T[N]
    endfunction

    //==========================================================================================
    function ReleaseTimer takes timer t returns nothing
        call PauseTimer(t)
        if (N==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
            set T[N]=t
            set N=N+1
        endif    
    endfunction

endlibrary

//Forced by WE
function InitTrig_CSSafety_by_Vexorian takes nothing returns nothing
endfunction


It doesn't look completely same, but the idea was 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