Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: MicroTable  (Read 18521 times)

Rating
Average Score
« Created: August 27, 2016, 09:44:07 PM by AGD »

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
MicroTable
« on: February 10, 2013, 10:50:22 AM »
Description

This small library allows to attach data structs in a easy way.

Requirements:

 - nothing

Actual Code

Code: jass  [Select]
  1. /******************************************************************
  2. *                         MICROTABLE V1.0                         *
  3. *                           By moyack                             *
  4. *                              2013                               *
  5. *              ===================================                *
  6. *              Exclusive resource from wc3jass.com                *
  7. *              ===================================                *
  8. ******************************************************************/
  9. library MicroTable
  10. /*
  11.  the purpose of this library is to allow the attachment of data
  12.  struct by its index in an easy way.
  13.  
  14.  Features:
  15.   - One command style to get, retrieve data (GetData, StoreData)
  16.   - Automatic flush of data when you call any Remove* or Destroy*
  17.     function.
  18.   - You can get the main hashtable so in you map you only need one
  19.     hastable
  20.   - Inline friendly :D
  21.  
  22.  Functions provided:
  23.   - GetTable: Returns the main Hashtable so you can use it in
  24.     other parts of the code in you map.
  25.   - StoreData: Connects the handle with a struct usind an index
  26.     value.
  27.   - GetData: Retrieves the struct data from the respective handle
  28.     and index.
  29.   - HasData: Checks if a handle has a struct stored with the
  30.     specified index.
  31.   - ClearData: Clears the struct info from the handle in the
  32.     specified index.
  33.   - FlushData: Clear ALL the information related to the handle
  34.     (this function is called automatically when you destroy or
  35.     remove that handle)
  36. */
  37.  
  38. globals
  39.     private hashtable H = InitHashtable()
  40. endglobals
  41.  
  42. constant function GetTable takes nothing returns hashtable
  43.     return H
  44. endfunction
  45.  
  46. function StoreData takes handle h, integer index, integer value returns nothing
  47.     call SaveInteger(H, GetHandleId(h), index, value)
  48. endfunction
  49.  
  50. function GetData takes handle h, integer index returns integer
  51.     return LoadInteger(H, GetHandleId(h), index)
  52. endfunction
  53.  
  54. function HasData takes handle h, integer index returns boolean
  55.     return HaveSavedInteger(H, GetHandleId(h), index)
  56. endfunction
  57.  
  58. function ClearData takes handle h, integer index returns nothing
  59.     call RemoveSavedInteger(H, GetHandleId(h), index)
  60. endfunction
  61.  
  62. function FlushData takes handle h returns nothing
  63. endfunction
  64.  
  65. //==================================================
  66. hook RemoveDestructable FlushData
  67. hook RemoveItem FlushData
  68. hook RemoveLocation FlushData
  69. hook RemoveRect FlushData
  70. hook RemoveRegion FlushData
  71. hook RemoveUnit FlushData
  72. hook RemoveWeatherEffect FlushData
  73. hook DestroyBoolExpr FlushData
  74. hook DestroyCondition FlushData
  75. hook DestroyDefeatCondition FlushData
  76. hook DestroyEffect FlushData
  77. hook DestroyFilter FlushData
  78. hook DestroyForce FlushData
  79. hook DestroyGroup FlushData
  80. hook DestroyImage FlushData
  81. hook DestroyItemPool FlushData
  82. hook DestroyLeaderboard FlushData
  83. hook DestroyLightning FlushData
  84. hook DestroyMultiboard FlushData
  85. hook DestroyQuest FlushData
  86. hook DestroyTextTag FlushData
  87. hook DestroyTimer FlushData
  88. hook DestroyTimerDialog FlushData
  89. hook DestroyTrigger FlushData
  90. hook DestroyUbersplat FlushData
  91. hook DestroyUnitPool FlushData
  92.  
  93. endlibrary

Example

Timer Utils made with this and Alloc
Code: jass  [Select]
  1. library TimerUtils requires Alloc, MicroTable
  2.  
  3. private struct data extends array
  4.     static key K // used to connect the data struct with the variable
  5.     static key D // used to link other data struct to the timer
  6.     timer t
  7.    
  8.     implement Alloc
  9.    
  10.     method destroy takes nothing returns nothing
  11.         call PauseTimer(.t)
  12.         call ClearData(.t, thistype.K)
  13.         call .deallocate()
  14.     endmethod
  15.    
  16.     static method create takes nothing returns thistype
  17.         local thistype this = thistype.allocate()
  18.         if this.t == null then
  19.             set this.t = CreateTimer()
  20.         endif
  21.         call StoreData(this.t, thistype.K, this)
  22.         return this
  23.     endmethod
  24.    
  25. endstruct
  26.  
  27. function NewTimer takes nothing returns timer
  28.     return data(data.create()).t
  29. endfunction
  30.  
  31. function ReleaseTimer takes timer t returns nothing
  32.     call data(GetData(t, data.K)).destroy()
  33. endfunction
  34.  
  35. function SetTimerData takes timer t, integer d returns nothing
  36.     call StoreData(t, data.D, d)
  37. endfunction
  38.  
  39. function GetTimerData takes timer t returns integer
  40.     return GetData(t, data.D)
  41. endfunction
  42.  
  43. endlibrary

Alloc link: http://wc3jass.com/5012/snippet-allocloop-aka-alloc-2/
« Last Edit: February 15, 2013, 10:32:47 AM by moyack »

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
MicroTable
« Reply #1 on: February 13, 2013, 10:49:27 AM »
Approved.

Some people would find this useful while map-making.

I don't know if GetTable should be in there though. I would discourage it.

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
MicroTable
« Reply #2 on: February 13, 2013, 11:16:14 AM »
Yay!!! thanks :)

Just for the lulz, do you think that the sample of timer utils can be as fast as Vexorian timerutils?? I dare to say that FUCK YESSS :P

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
MicroTable
« Reply #3 on: February 14, 2013, 08:54:38 PM »
I'd say that this would have approximately the same speed as TimerUtils when it stores data into a hashtable :P
The array version however, is probably faster than this at loading data and saving it only because of the speed of the hashtable.
A hashtable gets much slower as you put more data in it because of the hash collisions.

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
MicroTable
« Reply #4 on: February 15, 2013, 10:31:18 AM »
I'd say that this would have approximately the same speed as TimerUtils when it stores data into a hashtable :P
The array version however, is probably faster than this at loading data and saving it only because of the speed of the hashtable.
A hashtable gets much slower as you put more data in it because of the hash collisions.
Hmmm now I'm curious... Is there a test that shows how much hashtable becomes slow?

And I forgot...
I don't know if GetTable should be in there though. I would discourage it.
I did this so people just use one table, just in case they could need to store other kind of stuff different from integers.
« Last Edit: February 16, 2013, 02:50:10 PM by moyack »

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Rookie - level 1
  • *
  • Posts: 48
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 8
  • cool != useful
    • View Profile
MicroTable
« Reply #5 on: February 20, 2013, 03:21:14 PM »
I'm not sure that making some resources only available there is a great idea, i mean the community is more and more little, so imho it should be posted also on hiveworkshop also.
I've nothing to say about the resource by itself, even if i'm not a fan of hooks i suppose it makes sense there.
vJass is already a jass preprocessor, no need to (ab)use vJass features in order to make some inferior vJass preprocessor coded "by hand".

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
MicroTable
« Reply #6 on: February 21, 2013, 07:23:26 AM »
I'm not sure that making some resources only available there is a great idea, i mean the community is more and more little, so imho it should be posted also on hiveworkshop also.
I want to have stuff that you can't find in other sites, besides, we're not restricting in any way. Probably later I'll post them in other sites.
Quote
I've nothing to say about the resource by itself, even if i'm not a fan of hooks i suppose it makes sense there.
In this case there's no problem unless you code horribly and destroy too often handles :P

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Newbie - level 2
  • **
  • Posts: 21
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 1
    • View Profile
Re: MicroTable
« Reply #7 on: August 31, 2015, 04:08:14 AM »
What do you mean by "destroy too often handles"?

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: MicroTable
« Reply #8 on: September 01, 2015, 09:49:07 AM »
What do you mean by "destroy too often handles"?
I refer to the paranoic habit that some wc3 mappers have to over clean variable causing double free dealocation and making the map buggy. This happen due to lack of experience in jass coding.

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Newbie - level 2
  • **
  • Posts: 21
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 1
    • View Profile
Re: MicroTable
« Reply #9 on: September 01, 2015, 12:25:35 PM »
Where would that usually happen? In structs? Or maybe in functions with only one return line but many ifs? The latter of course I would understand, not that I would do it, but structs are still a bit hard to understand for me even though I can use them to a lesser extent.

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: MicroTable
« Reply #10 on: September 01, 2015, 10:21:00 PM »
Where would that usually happen? In structs? Or maybe in functions with only one return line but many ifs? The latter of course I would understand, not that I would do it, but structs are still a bit hard to understand for me even though I can use them to a lesser extent.
In any part done in jass. But the trick is to have a good understanding about the memory usage in WC3.

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

 

Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!