HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Lookup tables?

06-10-2016, 04:56 AM#1
Pinzu
I have 6 parameters to determine a index value to get a id and a facing value but it just feels extensive to use "binary lookup tables" to accomplish what I want...

Not all the options will be used for example currently 2x2 wont have any, and 6x6 will only have 16, in total about 50-ish varations will exist. Based on which side is open, the height and dimension it will yield an index which can be used to get the correct id and facing angle.

Surely there must be smarter ways to go about this... Please help...

Sorry for this mess of a post but the problem is that i have 6 input parameters that have to be converted to a unique number so that i can return the index value. So thats my headache.

Collapse JASS:
// Bit-0: Open or Closed (West) 	(1 = open)
        // Bit-1: Open or Closed (East) 	(2 = open)
        // Bit-2: Open or Closed (South) 	(4 = open)
        // Bit-3: Open or Closed (North)	(8 = open)
        // Bit-4: Dimension [0-3] 			0 = 2x2, 1 = 4x4, 2 = 6x6, 3 = X
        // Bit-5: Dimension [0-3]
        // Bit-6: Height [0-3]		 		0 = ground level, 1 = Wall level, 2 = Tower level, 3 = X						
        // Bit-7: Height [0-3]
        
        private static method getIndex takes integer height, integer dimension, boolean n, boolean s, boolean e, boolean w returns integer 
            local integer i = 0
            if w then 
                set i = i + 1
            endif
            if e then 
                set i = i + 2
            endif
            if s then 
                set i = i + 4
            endif
            if n then 
                set i = i + 8 
            endif
            if dimension == 4 then 
                set i = i + 16
            elseif dimension == 6 then 
                set i = i + 32
            endif
            if height == 1 then 
                set i = i + 64
            elseif height == 2 then 
                set i = i + 128
            endif
            return i
        endmethod
        
        private static method savePathing takes integer id, real f, integer height, integer dimension, boolean north, boolean south, boolean east, boolean west returns nothing
            local integer i = thistype.getIndex(height, dimension, north, south, east, west)
            set thistype.id[i] = id
            set thistype.facing[i] = f
        endmethod
    
        private static method onInit takes nothing returns nothing 
            call thistype.savePathing(PATH_4X4_LVL1_DEADEND, 270., HEIGHT_1, D4X4, false, false, true, false)    // E = Open
            call thistype.savePathing(PATH_4X4_LVL1_DEADEND, 90., HEIGHT_1, D4X4, false, false, false, true)    // W = Open
            call thistype.savePathing(PATH_4X4_LVL1_DEADEND, 0., HEIGHT_1, D4X4, true, false, false, false)        // N = Open
            call thistype.savePathing(PATH_4X4_LVL1_DEADEND, 180., HEIGHT_1, D4X4, false, true, false, false)    // S = Open
          // And so on...
endmethod
06-16-2016, 07:33 PM#2
Anitarf
The only optimization/cleanup I can think of is to have a static 2D array for dimension and height and do [ljass]set i = i + Size_array[dimension][height]. Although, since you only have two different sizes in each dimension, it doesn't shave much off the code.

Also, perhaps you could pass the four directions as a bitflag instead of four separate parameters, I don't know whether that'd result in complications in the code that calls this function or not.

All in all, the function isn't that complicated, I'm not sure why it is bothering you that much.