System Fade Unit System

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
=============================================
     _______   __    __    ______
    |   ____| |  |  |  |  / _____\
    |  |__    |  |  |  |  | |
    |   __|   |  |  |  |  | |____
    |  |      |  |  |  |  \____  \
    |  |      \  |__|  /   ____| |
    |__|       \______/   \______/
     
    Fade Unit System ~~v1.0.0~~
    
    This system fades units color over time.
==============================================
    
    Functions provided :
    Fade.start(whichunit, r1, g1, b1, a1, r2, g2, b2, a2, duration) -> Fade index
    Fade.stop(Fade index, WantTargetColor) (If you want to stop fading instantly, use this) =)
    
    Details on parameters :
        Real parameters ->
            r1 -> Original Red Color Index
            r2 -> Target Red Color Index
            g1 -> Original Green Color Index
            g2 -> Target Green Color Index
            b1 -> Original Blue Color Index
            b2 -> Target Blue Color Index
            a1 -> Original Alpha Index
            a2 -> Target Alpha Index
    
        Boolean parameters ->
            WantTargetColor -> Instantly set target color index to unit after stop fading
            
    Pros :
    Uses real on color index calculations, therefore the color generated is more smooth.
    Efficient
    
    Cons :
    Many parameters are needed to call the function.
    
    Requires :
    T32
    Jasshelper 0.9.K.2 or newer (For vJass version)
    Jasshelper 0.9.Z.2 or newer (For Zinc version)


T32's Link here : Click Me!

vJass version :
JASS:
library FUS requires T32
    
    struct Fade
        private static thistype d
        private real red
        private real green
        private real blue
        private real alpha
        private real tred
        private real tgreen
        private real tblue
        private real talpha
        private real cred
        private real cgreen
        private real cblue
        private real calpha
        //Reals for reality =)
        private integer ticks
        private unit targ
        private boolean wanStop
        
        private method periodic takes nothing returns boolean
            if this.ticks > 0 and not this.wanStop then
                set this.ticks = this.ticks - 1
                set this.cred = this.cred + this.red
                set this.cgreen = this.cgreen + this.green
                set this.cblue = this.cblue + this.blue
                set this.calpha = this.calpha + this.alpha
                call SetUnitVertexColor(this.targ,R2I(this.cred),R2I(this.cgreen),R2I(this.cblue),R2I(this.calpha))
                return false
            endif
            call this.destroy()
            return true
        endmethod
        
        implement T32
        
        static method start takes unit whichUnit, integer oriRed, integer oriGreen, integer oriBlue, integer oriAlpha, integer targRed, integer targGreen, integer targBlue, integer targAlpha, real duration returns thistype
            set thistype.d = thistype.allocate()
            set thistype.d.targ = whichUnit
            set thistype.d.cred = oriRed
            set thistype.d.cgreen = oriGreen
            set thistype.d.cblue = oriBlue
            set thistype.d.calpha = oriAlpha
            set thistype.d.tred = targRed
            set thistype.d.tgreen = targGreen
            set thistype.d.tblue = targBlue
            set thistype.d.talpha = targAlpha
            set thistype.d.ticks = R2I(duration / T32_PERIOD)
            set thistype.d.red = (thistype.d.tred - thistype.d.cred) / thistype.d.ticks
            set thistype.d.green = (thistype.d.tgreen - thistype.d.cgreen) / thistype.d.ticks
            set thistype.d.blue = (thistype.d.tblue - thistype.d.cblue) / thistype.d.ticks
            set thistype.d.alpha = (thistype.d.talpha - thistype.d.calpha) / thistype.d.ticks
            set thistype.d.wanStop = false
            call SetUnitVertexColor(whichUnit,oriRed,oriGreen,oriBlue,oriAlpha)
            call thistype.d.startPeriodic()
            return thistype.d
        endmethod   
            
        static method stop takes thistype whichInstance, boolean toTargetColor returns nothing
            set whichInstance.wanStop = true
            if toTargetColor then
                call SetUnitVertexColor(whichInstance.targ,R2I(whichInstance.tred),R2I(whichInstance.tgreen),R2I(whichInstance.tblue),R2I(whichInstance.talpha))
            endif
        endmethod 

    endstruct
endlibrary


Zinc Version:
JASS:
//! zinc
library UFS requires T32
{
    public struct Fade
    {
        
        private 
        {
        real red, green, blue, alpha, tred, tgreen, tblue, talpha, cred, cblue, cgreen, calpha;
        unit targ;
        integer ticks;
        boolean wantStop;
        static thistype d;
        }
        
        method periodic() -> boolean
        {
            while (this.ticks > 0)
            {
                while (this.wantStop == false)
                {
                    this.ticks = this.ticks - 1;
                    this.cred = this.cred + this.red;
                    this.cgreen = this.cgreen + this.green;
                    this.cblue = this.cblue + this.blue;
                    this.calpha = this.calpha + this.alpha;
                    SetUnitVertexColor(this.targ,R2I(this.cred),R2I(this.cgreen),R2I(this.cblue),R2I(this.calpha));
                    return false;
                }
            }
            this.destroy();
            return true;
        }

        implement T32;
        
        static method start (unit whichUnit, integer oriRed, integer oriGreen, integer oriBlue, integer oriAlpha, integer targRed, integer targGreen, integer targBlue, integer targAlpha, real duration) -> thistype
        {
            thistype.d = thistype.allocate();
            thistype.d.targ = whichUnit;
            thistype.d.cred = oriRed;
            thistype.d.cgreen = oriGreen;
            thistype.d.cblue = oriBlue;
            thistype.d.calpha = oriAlpha;
            thistype.d.tred = targRed;
            thistype.d.tgreen = targGreen;
            thistype.d.tblue = targBlue;
            thistype.d.talpha = targAlpha;
            thistype.d.ticks = R2I(duration / T32_PERIOD);
            thistype.d.red = (thistype.d.tred - thistype.d.cred) / thistype.d.ticks;
            thistype.d.green = (thistype.d.tgreen - thistype.d.cred) / thistype.d.ticks;
            thistype.d.blue = (thistype.d.tblue - thistype.d.cblue) / thistype.d.ticks;
            thistype.d.alpha = (thistype.d.talpha - thistype.d.calpha) / thistype.d.ticks;
            thistype.d.wantStop = false;
            SetUnitVertexColor(whichUnit,oriRed,oriGreen,oriBlue,oriAlpha);
            thistype.d.startPeriodic();
            return thistype.d;
        }
        
        static method stop (thistype whichInstance, boolean toTargetColor)
        {
            whichInstance.wantStop = true;
            if (toTargetColor == true)
            {
                SetUnitVertexColor(whichInstance.targ, R2I(whichInstance.tred) , R2I(whichInstance.tgreen) , R2I(whichInstance.tblue), R2I(whichInstance.talpha));
            }
        }

    }
}
//! endzinc


There are 2 unit fading systems approved at here. But this is more efficient. :thup:
 

Romek

Super Moderator
Reaction score
963
> There are 2 unit fading systems approved at here. But mine is more efficient.
Why don't you post in those threads, and tell the creators what they could improve to increase efficiency? :thdown:

Why is 'stop' static?

I also don't think systems this simple should use acronyms.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Why is 'stop' static?
Fade.start()
Fade.stop()
Nicer functions' name. lol :D

Why don't you post in those threads, and tell the creators what they could improve to increase efficiency?
Those systems do fading in different way.

Uberplayer's fade system only fades alpha channel.

Larcenist's FadeUnitTimed is kinda weird.
4) 2, true, 4. The first number here, 2, is how many seconds it will take for the unit to fade from (in my case) 0 to 100%. The next value, true, is a boolean to tell the system if you want the unit to regain it's starting transparency after the fade. The last number is the time it takes to regain the starting transparency (4 seconds to go from 100% to 0% transparency in my case).
= =?

So, I created this Fade Unit System to ease the fading and providing an efficient script to users.
 
Reaction score
456
My Fade System can be dropped off. I don't plan updating it, because I personally think this kind of stuff is useless :).
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, not to be selfish here, but isn't this almost the same (Apart from you having alot more members (Which are a bit unecessary imho)) as in my thread here:
http://www.thehelper.net/forums/showthread.php?t=137304

Why not help me out there, instead if you think it lacks features, since mine already has more features than yours ? :eek:

(Looks like this atm:)
JASS:
library SmoothUnitMod requires T32, UnitAppearance

    struct SmoothScaleChange
    
        //private code userFunc
        private integer ticks
        
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.ticks = this.ticks - 1
        
            call ModifyUnitScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].scale ) )
            
            if this.ticks <= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Scaler, real Time, real scaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Scaler
            //set this.userFunc = userFunc
            set this.increment = ( ( scaleMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( scaleMod / this.increment ) // How many times the timer must fire...
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function ScaleSimple takes unit Scaler, real Time, real scaleMod returns SmoothScaleChange
        return SmoothScaleChange.create( Scaler, Time, scaleMod, null )
    endfunction
    
    function ScaleEx takes unit Scaler, real Time, real scaleMod, code userFunc returns SmoothScaleChange
        return SmoothScaleChange.create( Scaler, Time, scaleMod, userFunc )
    endfunction
    
    function GetUnitScale takes unit u returns real
        return Appearance[ u ].scale
    endfunction
    
    struct SmoothColorChange
    
        private integer ticks
        
        private real rincrement
        private real gincrement
        private real bincrement
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.ticks = this.ticks - 1
        
            call ModifyUnitVertexColor( this.u, R2I( this.rincrement ), R2I( this.gincrement ), R2I( this.bincrement ), R2I( this.increment ) )
            
            debug call BJDebugMsg( R2S( Appearance[this.u].alpha ) )
            
            if this.ticks <= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Fader
            set this.increment = ( ( alphaMod * T32_PERIOD ) / Time )
            set this.rincrement = ( ( redMod * T32_PERIOD ) / Time )
            set this.gincrement = ( ( greenMod * T32_PERIOD ) / Time )
            set this.bincrement = ( ( blueMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( alphaMod / this.increment )
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function FadeSimple takes unit Fader, real Time, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Fader, Time, 0., 0., 0., alphaMod )
    endfunction
    
    function FadeEx takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Fader, Time, redMod, greenMod, blueMod, alphaMod )
    endfunction
    
    function GetUnitAlpha takes unit u returns integer
        return Appearance[ u ].alpha
    endfunction

    function GetUnitRedColor takes unit u returns integer
        return Appearance[ u ].red
    endfunction
    
    function GetUnitGreenColor takes unit u returns integer
        return Appearance[ u ].green
    endfunction
    
    function GetUnitBlueColor takes unit u returns integer
        return Appearance[ u ].blue
    endfunction
    
    struct SmoothTSChange
    
        //private code userFunc
        private integer ticks
        
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.ticks = this.ticks - 1
        
            call ModifyUnitTimeScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].timescale ) )
            
            if this.ticks <= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Timer, real Time, real timescaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Timer
            //set this.userFunc = userFunc
            set this.increment = ( ( timescaleMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( timescaleMod / this.increment ) // How many times the timer must fire...
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function TimeScaleChange takes unit Timer, real Time, real timescaleMod returns SmoothTSChange
        return SmoothTSChange.create( Timer, Time, timescaleMod, null )
    endfunction
    
    function TimeScaleChangeEx takes unit Timer, real Time, real timescaleMod, code userFunc returns SmoothTSChange
        return SmoothTSChange.create( Timer, Time, timescaleMod, userFunc )
    endfunction
    
    function GetUnitTimeScale takes unit u returns real
        return Appearance[ u ].timescale
    endfunction

endlibrary
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Your system does more stuffs. I can help you if possible. :)

But the aim of this system is providing an easy and lite fading interface for everyone. =)
 
Reaction score
91
> because I personally think this kind of stuff is useless
Have to agree with this one, you'll probably be using fading in 1-2 spells so coding it yourself is better...
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
How the heck are you expected to know the initial colour values? Lol.
So I added the value for users to set. lol.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top