• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

The New UnitIndexer - A New Approach

Status
Not open for further replies.
Level 31
Joined
Jul 10, 2007
Messages
6,306
Still need to do the md, finish the Lua project framework thing, and so on. Updated UnitIndexer so that I could use it for testing since it has everything ;).

Anyways, have a look, enjoy the new API, and take a look at the new approach. I'll throw the stuff on github as soon as I have a few resources updated with documentation + have the Lua stuff done.

I'm sorry, I changed the API, but it's better :(

Not to mention that this isn't made to be pasted into WE anyways, lol.

I'm using luaforwindows for the Lua stuff, so you should download that and be ready for some awesome :eek:. Using the notepad++ thing for vJASS editing, but the compiling is all going thru Lua.

[highlight_url=vjass]http://pastebin.com/raw.php?i=EP7ySzaf[/highlight_url]

[highlight_url=vjass]http://pastebin.com/raw.php?i=Kb1pTrBd[/highlight_url]

[highlight_url=vjass]http://pastebin.com/raw.php?i=M1P2Mmu7[/highlight_url]

[highlight_url=vjass]http://pastebin.com/raw.php?i=k7U8UEH0[/highlight_url]

Lua:
require "GetVarObject"

local id = getvarobject("Adef", "abilities", "ABILITIES_UNIT_INDEXER", true)

createobject("Adef", id)
makechange(current, "aart", "")
makechange(current, "arac", "0")
makechange(current, "anam", "Unit Indexer")

updateobjects()
 

Attachments

  • unit index.j
    4.4 KB · Views: 130
  • unit indexer.j
    3.6 KB · Views: 128
  • pregame event.j
    2.7 KB · Views: 81
  • script.j
    2.1 KB · Views: 137
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
Here are the missing scripts if you wanna play around with it

JASS:
library StaticUniqueList /* v1.0.0.2
************************************************************************************
*
*   */uses/*
*   
*       */ ErrorMessage /*         hiveworkshop.com/forums/submissions-414/snippet-error-message-239210/
*
************************************************************************************
*
*   module StaticUniqueList
*
*       Description
*       -------------------------
*
*           Node Properties:
*
*               Unique
*               Not 0
*
*       Fields
*       -------------------------
*
*           readonly static integer sentinel
*
*           readonly static thistype first
*           readonly static thistype last
*
*           readonly thistype next
*           readonly thistype prev
*
*       Methods
*       -------------------------
*
*           static method create takes nothing returns thistype
*           method destroy takes nothing returns nothing
*               - May only destroy lists
*
*           static method push takes thistype node returns nothing
*           static method enqueue takes thistype node returns nothing
*
*           static method pop takes nothing returns nothing
*           static method dequeue takes nothing returns nothing
*
*           method remove takes nothing returns nothing
*
*           static method clear takes nothing returns nothing
*
************************************************************************************/
    module StaticUniqueList
        debug private boolean isNode
        
        private thistype _next
        method operator next takes nothing returns thistype
            debug call ThrowError(this == 0,    "StaticUniqueList", "next", "thistype", this, "Attempted To Go Out Of Bounds.")
            debug call ThrowError(not isNode,   "StaticUniqueList", "next", "thistype", this, "Attempted To Read Invalid Node.")
			
            return _next
        endmethod
        
        private thistype _prev
        method operator prev takes nothing returns thistype
            debug call ThrowError(this == 0,    "StaticUniqueList", "prev", "thistype", this, "Attempted To Go Out Of Bounds.")
            debug call ThrowError(not isNode,   "StaticUniqueList", "prev", "thistype", this, "Attempted To Read Invalid Node.")
			
            return _prev
        endmethod
		
		static method operator first takes nothing returns thistype
			return thistype(0)._next
		endmethod
		static method operator last takes nothing returns thistype
			return thistype(0)._prev
		endmethod
		
		private static method setFirst takes thistype node returns nothing
			set thistype(0)._next = node
		endmethod
		
		private static method setLast takes thistype node returns nothing
			set thistype(0)._prev = node
		endmethod
        
		static constant integer sentinel = 0
        
        static method push takes thistype node returns nothing
            debug call ThrowError(node == 0,    		"StaticUniqueList", "push", "thistype", 0, "Attempted To Push Null Node.")
            debug call ThrowError(node.isNode,          "StaticUniqueList", "push", "thistype", 0, "Attempted To Push Owned Node (" + I2S(node) + ").")
            
            debug set node.isNode = true
			
			set first._prev = node
			set node._next = first
			call setFirst(node)
				
            set node._prev = 0
        endmethod
        static method enqueue takes thistype node returns nothing
            debug call ThrowError(node == 0,		"StaticUniqueList", "enqueue", "thistype", 0, "Attempted To Enqueue Null Node.")
            debug call ThrowError(node.isNode,		"StaticUniqueList", "enqueue", "thistype", 0, "Attempted To Enqueue Owned Node (" + I2S(node) + ").")
            
            debug set node.isNode = true
            
			set last._next = node
			set node._prev = last
			call setLast(node)
            
            set node._next = 0
        endmethod
        static method pop takes nothing returns nothing
            debug call ThrowError(first == 0,      "StaticUniqueList", "pop", "thistype", 0, "Attempted To Pop Empty List.")
            
            debug set first.isNode = false
			
			call setFirst(first._next)
			set first._prev = 0
        endmethod
        static method dequeue takes nothing returns nothing
            debug call ThrowError(last == 0,       "StaticUniqueList", "dequeue", "thistype", 0, "Attempted To Dequeue Empty List.")
            
            debug set last.isNode = false
            
			call setLast(last._prev)
			set last._next = 0
        endmethod
        method remove takes nothing returns nothing
            debug call ThrowError(this == 0,        "StaticUniqueList", "remove", "thistype", 0, "Attempted To Remove Null Node.")
            debug call ThrowError(not isNode,  		"StaticUniqueList", "remove", "thistype", 0, "Attempted To Remove Invalid Node (" + I2S(this) + ").")
            
            debug set isNode = false
			
			set _prev._next = _next
			set _next._prev = _prev
        endmethod
        static method clear takes nothing returns nothing
            static if DEBUG_MODE then
				local thistype node = first
			
                loop
                    exitwhen node == 0
                    set node.isNode = false
                    set node = node._next
                endloop
            endif
			
			call setFirst(0)
			call setLast(0)
        endmethod
    endmodule
endlibrary

JASS:
library Init
	module Init
		static if thistype.init.exists then
			private static method onInit takes nothing returns nothing
				call init()
			endmethod
		endif
	endmodule
endlibrary

JASS:
library ErrorMessage /* v1.0.1.4
*************************************************************************************
*
*   Issue THW Compliant Error Messages
*
************************************************************************************
*
*   debug function ThrowError takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
*       -   In the event of an error the game will be permanently paused
*
*   debug function ThrowWarning takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
*
************************************************************************************/
    static if DEBUG_MODE then
        private struct Fields extends array
            static constant string COLOR_RED = "|cffff0000"
            static constant string COLOR_YELLOW = "|cffffff00"
            static string lastError = null
        endstruct
        
        private function Pause takes nothing returns nothing
            call PauseGame(true)
        endfunction
        
        private function ThrowMessage takes string libraryName, string functionName, string objectName, integer objectInstance, string description, string errorType, string color returns nothing
            local string str
            
            local string color_braces = "|cff66FF99"
            local string orange = "|cffff6600"
            
            set str = "->\n-> " + color_braces + "{|r " + "Library" + color_braces + "(" + orange + libraryName + color_braces + ")"
            if (objectName != null) then
                if (objectInstance > 0) then
                    set str = str + "|r.Object" + color_braces + "(" + orange + objectName + color_braces + " (|rinstance = " + orange + I2S(objectInstance) + color_braces + ") )" + "|r." + "Method" + color_braces + "(" + orange + functionName + color_braces + ")"
                else
                    set str = str + "|r.Object" + color_braces + "(" + orange + objectName + color_braces + ")|r." + "Method" + color_braces + "(" + orange + functionName + color_braces + ")"
                endif
            else
                set str = str + "|r." + "Function" + color_braces + "(" + orange + functionName + color_braces + ")"
            endif
            
            set str = str + color_braces + " }|r " + "has thrown an exception of type " + color_braces + "(" + color + errorType + color_braces + ")|r."
            
            set Fields.lastError = str + "\n->\n" + "->    " + color + description + "|r\n->"
        endfunction
        
        function ThrowError takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
            if (Fields.lastError != null) then
                set objectInstance = 1/0
            endif
        
            if (expression) then
                call ThrowMessage(libraryName, functionName, objectName, objectInstance, description, "Error", Fields.COLOR_RED)
                call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,Fields.lastError)
                call TimerStart(CreateTimer(), 0, true, function Pause)
                set objectInstance = 1/0
            endif
        endfunction

        function ThrowWarning takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
            if (Fields.lastError != null) then
                set objectInstance = 1/0
            endif
        
            if (expression) then
                call ThrowMessage(libraryName, functionName, objectName, objectInstance, description, "Warning", Fields.COLOR_YELLOW)
                call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,Fields.lastError)
                set Fields.lastError = null
            endif
        endfunction
    endif
endlibrary

JASS:
	globals
		constant integer ABILITIES_UNIT_INDEXER = 'A000'
	endglobals

JASS:
library WorldBounds /* v2.0.0.0
************************************************************************************
*
*   struct WorldBounds extends array
*       readonly static integer maxX
*       readonly static integer maxY
*       readonly static integer minX
*       readonly static integer minY
*       readonly static integer centerX
*       readonly static integer centerY
*       readonly static rect world
*       readonly static region worldRegion
*
************************************************************************************/
    
    private module WorldBoundInit
        private static method onInit takes nothing returns nothing
            set world=GetWorldBounds()
            set maxX=R2I(GetRectMaxX(world))
            set maxY=R2I(GetRectMaxY(world))
            set minX=R2I(GetRectMinX(world))
            set minY=R2I(GetRectMinY(world))
            set centerX=R2I((maxX+minX)/2)
            set centerY=R2I((minY+maxY)/2)
            set worldRegion=CreateRegion()
            call RegionAddRect(worldRegion,world)
        endmethod
    endmodule
    struct WorldBounds extends array
        readonly static integer maxX
        readonly static integer maxY
        readonly static integer minX
        readonly static integer minY
        readonly static integer centerX
        readonly static integer centerY
        readonly static rect world
        readonly static region worldRegion
        implement WorldBoundInit
    endstruct
endlibrary

JASS:
library Alloc /* v1.1.0.1
*************************************************************************************
*
*   */uses/*
*   
*       */ ErrorMessage /*         hiveworkshop.com/forums/submissions-414/snippet-error-message-239210/
*
************************************************************************************
*
*   module Alloc
*
*       static method allocate takes nothing returns thistype
*       method deallocate takes nothing returns nothing
*
*		debug boolean isAllocated
*
*       debug static method calculateMemoryUsage takes nothing returns integer
*       debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************/
    module Alloc
        private static integer array recycler
		
		debug method operator isAllocated takes nothing returns boolean
			return recycler[this] == -1
		endmethod
        
        static method allocate takes nothing returns thistype
            local thistype this = recycler[0]
            
            debug call ThrowError(this == 0, "Alloc", "allocate", "thistype", 0, "Overflow.")
            
            set recycler[0] = recycler[this]
            debug set recycler[this] = -1
            
            return this
        endmethod
        
        method deallocate takes nothing returns nothing
            debug call ThrowError(recycler[this] != -1, "Alloc", "deallocate", "thistype", this, "Attempted To Deallocate Null Instance.")
            
            set recycler[this] = recycler[0]
            set recycler[0] = this
        endmethod
        
        private static method onInit takes nothing returns nothing
            local integer i = 0

            set recycler[8191] = 0 //so that the array doesn't reallocate over and over again
            
            loop
                set recycler[i] = i + 1
                
                exitwhen i == 8190
                set i = i + 1
            endloop
        endmethod
        
        static if DEBUG_MODE then
            static method calculateMemoryUsage takes nothing returns integer
                local integer start = 1
                local integer end = 8191
                local integer count = 0
                
                loop
                    exitwhen start > end
                    if (start + 500 > end) then
                        set count = count + checkRegion(start, end)
                        set start = end + 1
                    else
                        set count = checkRegion(start, start + 500)
                        set start = start + 501
                    endif
                endloop
                
                return count
            endmethod
              
            private static method checkRegion takes integer start, integer end returns integer
                local integer count = 0
            
                loop
                    exitwhen start > end
                    if (recycler[start] == -1) then
                        set count = count + 1
                    endif
                    set start = start + 1
                endloop
                
                return count
            endmethod
            
            static method getAllocatedMemoryAsString takes nothing returns string
                local integer start = 1
                local integer end = 8191
                local string memory = null
                
                loop
                    exitwhen start > end
                    if (start + 500 > end) then
                        if (memory != null) then
                            set memory = memory + ", "
                        endif
                        set memory = memory + checkRegion2(start, end)
                        set start = end + 1
                    else
                        if (memory != null) then
                            set memory = memory + ", "
                        endif
                        set memory = memory + checkRegion2(start, start + 500)
                        set start = start + 501
                    endif
                endloop
                
                return memory
            endmethod
              
            private static method checkRegion2 takes integer start, integer end returns string
                local string memory = null
            
                loop
                    exitwhen start > end
                    if (recycler[start] == -1) then
                        if (memory == null) then
                            set memory = I2S(start)
                        else
                            set memory = memory + ", " + I2S(start)
                        endif
                    endif
                    set start = start + 1
                endloop
                
                return memory
            endmethod
        endif
    endmodule
endlibrary

JASS:
library Event /* v2.0.0.1
************************************************************************************
*
*   Functions
*
*       function CreateEvent takes nothing returns integer
*       function TriggerRegisterEvent takes trigger t, integer ev returns nothing
*
************************************************************************************
*
*       struct Event extends array
*
*           static method create takes nothing returns thistype
*           method registerTrigger takes trigger t returns nothing
*           method register takes boolexpr c returns nothing
*           method fire takes nothing returns nothing
*
************************************************************************************/
    globals
        private real q=0
    endglobals
    struct Event extends array
        private static integer w=0
        private static trigger array e
        static method create takes nothing returns thistype
            set w=w+1
            set e[w]=CreateTrigger()
            return w
        endmethod
        method registerTrigger takes trigger t returns nothing
            call TriggerRegisterVariableEvent(t,SCOPE_PRIVATE+"q",EQUAL,this)
        endmethod
        method register takes boolexpr c returns nothing
            call TriggerAddCondition(e[this],c)
        endmethod
        method fire takes nothing returns nothing
            set q=0
            set q=this
            call TriggerEvaluate(e[this])
        endmethod
    endstruct
    function CreateEvent takes nothing returns Event
        return Event.create()
    endfunction
    function TriggerRegisterEvent takes trigger t,Event ev returns nothing
        call ev.registerTrigger(t)
    endfunction
    function RegisterEvent takes boolexpr c,Event ev returns nothing
        call ev.register(c)
    endfunction
    function FireEvent takes Event ev returns nothing
        call ev.fire()
    endfunction
endlibrary
 
ehh, I know that the //! import features and the Lua is all nice and convenient for the coder and "fundamentally sound", but you should really consider the user's end. The way I see it, resources should be treated as products. Coders (i.e. consumers) should be willing to use them. As such, resources should be set up so that they are easy to implement (so that users will use it, duh).

At the moment, the Lua requires you to avoid the standard Lua implementation, and requires GetVarObject (iirc that requires a few other things as well). I highly doubt anyone will use it over the conventional method of copy + paste. And when they do copy + paste, they have to make sure they add the global with the proper ID (unless they scroll down to your other post).

Then they have to download the j files and move them to the JASS folder so that the //! import commands will work. The import command is cool for personal map-making, but it is a bit annoying when external resources require them. It is neat in the sense that it is a one-time thing, but it is a deterrent nonetheless.

Then they have to copy and paste six other scripts.

Now, a lot of the complications are reduced when you have a test map (you can easily copy and paste the folder, and then copy and paste the ability.. you still have to do the import stuff tho). However, the implementation is still sorta annoying. That isn't the worst part. All resources that use UnitIndexer will also inherit the difficult implementation.

Finally, when you make an update, they have to redownload the J files or update their j files.

All in all, logically it isn't the worst thing. A lot of your ideas make sense as far as programming conventions and other junk go. And even if it may only take 5-10 minutes to implement, and 1-2 minutes for the other times, it doesn't take away from the fact that it is difficult to implement. iirc, I actually redirected a JASSer to Bribe's indexer for ease of implementation, and it is GUI!!!!!!!!!!!!!! WHEN DID THIS HAPPEN?!

Those are just my 2 cents. Keep in mind that this is solely my opinion. For all I know, others may be willing to take the time to do it or they may support your approach. I just don't think I'll personally use it. tbh, I'm thinking of just going back to PUI (somewhere, cohadar is smiling).
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
I'm working on something that'll make this all easy to implement. I'm doing a huge Lua framework thing that will automatically handle script installation for maps and stuff. It'll actually be easier than the traditional way ^_^. Furthermore, it'll have auto-updating, woo. It will be harder on the coders tho >.<, but easier for the consumers =).

However, if you try to use this stuff without the crazy Lua framework thing, it will be hell to implement, yes : P

imma have a compile.bat file too :eek:, that way you won't need any special IDEs or anything. You'll be able to actually run this off of vanilla WE.
 
Level 10
Joined
Sep 19, 2011
Messages
527
I'm working on something that'll make this all easy to implement. I'm doing a huge Lua framework thing that will automatically handle script installation for maps and stuff. It'll actually be easier than the traditional way ^_^. Furthermore, it'll have auto-updating, woo. It will be harder on the coders tho >.<, but easier for the consumers =).

do you know npm or bower?

it would be something like:

<utility's name> install unit-indexer-nestharus

and that will grab all (including dependencies).
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
is that better as optional?
No, unless you give a shit about debugging.
If you appreciate a well strutured debug library, Error message is all you need.
It is also a very small library.

Most of Nestharus' resources depend on each other. A fact you have to accept if you want to use them.

Btw why are you interested in this resource? It won't see an update for a long time, maybe never.
If you want to use an UnitIndexer use one of these: UnitDex, UnitIndexer (Nestharus), UnitIndexer(Bribe), AIDS.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
everyone *shhh*

this current library is buggy

use the current "approved" version of UnitIndexer. This is in the lab because it is untested. I read through some of the code, and it indeed will not work correctly ;). No other libraries currently use this one either.

If you would like to contact me and have me actually see it, be sure to raise an issue as a question or something, or email me. I'm on github atm. Eventually, I'll probably come back here after I get everything sorted >.<. I'll definitely be back for Dota 2 if that kicks off =).

Again, don't use this library :).


here is my latest work on unit indexing (it's an article) https://github.com/nestharus/JASS/wiki/Paper:-Unit-Specific-Deindexing-and-Optimization-on-Undefend

no current library uses that stuff
 
Status
Not open for further replies.
Top