View Single Post
Old 12-13-2010, 01:19 AM   #2
Join Date: Apr 2009
Posts: 38

BlackRose is on a distinguished road (13)


Useful. I like it, especially the optional support for AutoIndex, as people also use other indexers.

Collapse JASS:
//*  Finally, to be able to reset a unit's color and scale, the
//*  library provides the followin functions that return the
//*  default values for a given unit type:

I found a mistake here: "Followin".

Although one thing I don't understand is why UnitEntersMap is not placed in UnitEntersMapTrigger, instead it's being called. Something like this:

Collapse JASS:
private static method UnitEntersMapTrigger takes nothing returns nothing
    local unit u = GetTriggerUnit()
    static if LIBRARY_AutoIndex then
        set unitsScale[GetUnitId(u)] = GetUnitTypeScale(GetUnitTypeId(u))
        set unitsColor[GetUnitId(u)] = GetUnitTypeVertexColor(GetUnitTypeId(u))
        set unitScale[u] = R2I(GetUnitTypeScale(GetUnitTypeId(u))*1000.0)
        set unitColor[u] = integer(GetUnitTypeVertexColor(GetUnitTypeId(u)))
    set u = null

Was it to avoid the declaration of a local unit? *Shrugs*
Also can't GetUnitTypeId(u) be set to a local to avoid double call? Although this is done on initialization, so I guess it's negligible. The same goes for GetUnitId().

Collapse JASS:
private function SetUnitScalePercent_hook takes unit whichUnit, real percentScaleX, real percentScaleY, real percentScaleZ returns nothing
    call SetUnitScale_hook(whichUnit, percentScaleX * 0.01, percentScaleY * 0.01, percentScaleZ * 0.01)

scaleY and scaleZ don't work, so you could save two multiplications. I don't know why Blizzard implemented them.

Collapse JASS:
private function SetUnitVertexColorBJ_hook takes unit whichUnit, real red, real green, real blue, real transparency returns nothing
    call SetUnitVertexColor_hook(whichUnit, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))

All those PercentTo255 calls are:

Collapse JASS:
function PercentTo255 takes real percentage returns integer
    return PercentToInt(percentage, 255)

function PercentToInt takes real percentage, integer max returns integer
    local integer result = R2I(percentage * I2R(max) * 0.01)

    if (result < 0) then
        set result = 0
    elseif (result > max) then
        set result = max

    return result

Or simply: R2I(255 /*(100 for alpha)*/ * I2R(max) * 0.01)? No need to check for max, users shouldn't be setting values to below 0 or above 255 anyways.
BlackRose is offline   Reply With Quote