Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

MicroTable No New Posts Codes & Snippets

Started by
moyack

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

« Created: October 08, 2017, 11:53:08 PM by moyack »
+ Show previous

MicroTable
on: February 10, 2013, 10:50:22 AM
Category: Execution, Variables
Language: vJASS

Description

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

Requirements:

 - nothing

Actual Code

Code: jass
  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

Check the library Hibrid TimerUtils in the related links.
« Last Edit: December 24, 2017, 10:54:10 AM by moyack »



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.



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


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.



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 »



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".


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


Re: MicroTable
Reply #7 on: August 31, 2015, 04:08:14 AM

What do you mean by "destroy too often handles"?



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.


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.



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.


 

Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...