System Dynamic Struct Storage - DSS

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
////////////////////////////////////////////////////////////////////
//      DSS -> Dynamic Struct Storage
//              v 2.0.1
//
//  ============
//  What's DSS?
//  ============
//  DSS is a struct attachment system that can make
//  attaching easier. Getting tired with Table/ABC?
//  Use this! =D
//
//  ==================
//  How to implement?
//  ==================
//  1) Copy this library to your map.
//  2) Done.
//
//  ==================
//  How to use?
//  ==================
//  For timer attachment : implement DSS_vJassTimerAttachment.
//  For trigger attachment : implement DSS_vJasTriggerAttachment.
//
//  ===============
//  How to attach?
//  ===============
//  set <structName>[timer] = struct instance.
//  <structName>[timer] -> return attached struct
//  
//  ===========================================
//  How to clear the attached timers/triggers?
//  ===========================================
//  call struct instance.flush()
//
//  =====================
//  Details :
//  =====================
//  1) DSS uses hashtable to store attached data.
//  2) DSS will automatically remove attached data
//     when the struct is destroyed.
//  3) Want unit attachment? DSS is not aimed to that. =)
//  4) The speed of this is as fast as Table.
//
//  ================
//  Requirements :
//  ================
//  Jasshelper 0.A.2.B or later.
//
//////////////////////////////////////////////////////////////////
library DSS

    globals
        public hashtable hasht = InitHashtable()
        public integer keyz = 0
    endglobals
    
    public module vJassTimerAttachment
        private static integer dss_keyz
        private timer attached_timer
        static method operator [] takes timer whichTimer returns thistype
            return LoadInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTimer))
        endmethod
        static method operator []= takes timer whichTimer, thistype whichData returns nothing
            call whichData.flush()
            call SaveInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTimer),whichData)
            set whichData.attached_timer = whichTimer
        endmethod
        method flush takes nothing returns nothing
            call RemoveSavedInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(.attached_timer))
            set .attached_timer = null
        endmethod
        method destroy takes nothing returns nothing
            call deallocate()
        endmethod
        private static method onInit takes nothing returns nothing
            set DSS_keyz = DSS_keyz + 1
            set thistype.dss_keyz = DSS_keyz
        endmethod
    endmodule
    
    public module vJassTriggerAttachment
        private static integer dss_keyz
        private trigger attached_trigger
        static method operator [] takes trigger whichTrigger returns thistype
            return LoadInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTrigger))
        endmethod
        static method operator []= takes trigger whichTrigger, thistype whichData returns nothing
            call whichData.flush()
            call SaveInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTrigger),whichData)
            set whichData.attached_trigger = whichTrigger
        endmethod
        method flush takes nothing returns nothing
            call RemoveSavedInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(.attached_trigger))
            set .attached_trigger = null
        endmethod
        method destroy takes nothing returns nothing
            call .flush()
            call deallocate()
        endmethod
        private static method onInit takes nothing returns nothing
            set DSS_keyz = DSS_keyz + 1
            set thistype.dss_keyz = DSS_keyz
        endmethod
    endmodule
    
endlibrary


Zinc Plug-in :
JASS:
////////////////////////////////////////////////////////////////////
//      DSS -> Dynamic Struct Storage (Zinc)
//              v 2.0.1         by kingking
//
//  ============
//  What's DSS?
//  ============
//  DSS is a struct attachment system that can make
//  attaching easier. Getting tired with Table/ABC?
//  Use this! =D
//
//  ==================
//  How to implement?
//  ==================
//  1) Copy this library to your map.
//  2) Done.
//
//  ==================
//  How to use?
//  ==================
//  For timer attachment : module DSS_ZincTimerAttachment.
//  For trigger attachment : module DSS_ZincTriggerAttachment.
//
//  ===============
//  How to attach?
//  ===============
//  set <structName>[timer] = struct instance.
//  <structName>[timer] -> return attached struct
//  
//  ===========================================
//  How to clear the attached timers/triggers?
//  ===========================================
//  call struct instance.flush()
//
//  =====================
//  Details :
//  =====================
//  1) DSS uses hashtable to store attached data.
//  2) DSS will automatically remove attached data
//     when the struct is destroyed.
//  3) Want unit attachment? DSS is not aimed to that. =)
//  4) The speed of this is as fast as Table.
//
//  ================
//  Requirements :
//  ================
//  Jasshelper 0.A.2.B or later.
//  Dynamic Struct Storage
//
//////////////////////////////////////////////////////////////////
//! zinc
library DSSZinc requires DSS {

    public module DSS_ZincTimerAttachment {
        private static integer dss_keyz;
        private timer attached_timer;
        
        static method operator [] (timer whichTimer) -> thistype { 
            return LoadInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTimer)); 
        }
        
        static method operator []= (timer whichTimer, thistype whichData) {
            whichData.flush();
            SaveInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTimer),whichData);
            whichData.attached_timer = whichTimer;
        }
        
        method flush () {
            RemoveSavedInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(this.attached_timer));
            this.attached_timer = null;
        }
        
        method destroy () { deallocate(); }
        
        private static method onInit () {
            DSS_keyz += 1;
            thistype.dss_keyz = DSS_keyz;
        }
    }
    
    public module DSS_ZincTriggerAttachment {
        private static integer dss_keyz;
        private trigger attached_trigger;
        
        static method operator [] (trigger whichTrigger) -> thistype { 
            return LoadInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTrigger)); 
        }
        
        static method operator []= (trigger whichTrigger, thistype whichData) {
            whichData.flush();
            SaveInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTrigger),whichData);
            whichData.attached_trigger = whichTrigger;
        }
        
        method flush () {
            RemoveSavedInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(this.attached_trigger));
            this.attached_trigger = null;
        }
        
        method destroy () { deallocate(); }
        
        private static method onInit () {
            DSS_keyz += 1;
            thistype.dss_keyz = DSS_keyz;
        }
    }
}
//! endzinc
 

Jesus4Lyf

Good Idea™
Reaction score
397
Graveyarded for containing H2I-offset in unsafe circumstances.
Edit: My bad, you documented that it should only be used for preloaded handles.
JASS:
            debug static if $TYPE$ == "unit" then
                debug call BJDebugMsg("DSS notification : You are trying to use DSS to attach struct to unit! Please change to unit indexing library instead of DSS for struct attaching!")
            debug endif

Won't compile in debug mode, I'm sure of it...

What's this do that Table doesn't?
Why do you enforce typesafety?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Looking foward to your answers.
Table requires Table.create to create a key.
DSS does not requires, it will automatically create a key on initialization.

By using DSS, you can use the struct's name directly.
In Table, you need use the key's name instead of struct's name.

GetHandleId() - offset is also a feature that Table does not provide.
For DSS_Struct, it has an advantage over Table. Sometimes when you get attached value from function, jasshelper will give you an error because of the returned value is integer, not struct. In this case, you need to use Data(index). DSS_Struct does not provides trouble, because it returns thistype instead of integer. :thup:

Why do you enforce typesafety?
If I do not do so, some naughty users will use it to attach struct to units. ><
 

Jesus4Lyf

Good Idea™
Reaction score
397
The interface of this is not as clean as [LJASS]hashtable[/LJASS]s and [LJASS]key[/LJASS]s. (This should use keys, btw, which inline.)

Since this serves the exact same functionality of hashtables with keys, but has a worse interface, this is unnecessary, because people can use hashtables with keys. :thup:

Graveyarded.
 

Romek

Super Moderator
Reaction score
964
You honestly don't need to submit everything you make, kingkingyyk3. Most, if not all of your recent submissions seem to be reinventions of what has been made in the past, without any new features or advantages over past systems.

Do you think people will use your submission? If so, I suggest you don't submit things until you realise what people (including yourself) would actually use or find useful. Though I get the feeling that you know people won't use your stuff, and you just submit it for the sake of having submissions. :p

Good system ideas usually come from you needing something yourself, and realising that it hasn't been made before (that other people could also benefit from); not from sitting around thinking of a system to write.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
It provides better functionality. It will automatically remove attached struct from timer/trigger when you called .destroy, which Table can't provide this. :)
 

Romek

Super Moderator
Reaction score
964
He could if he wanted to, though he chooses not to.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • 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

      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