wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 08-12-2008, 10:09 PM   #1
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,053

Submissions (19)

Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default Unit Fade System

This system requires ARGB and Table. With it, you can fade units over time by calling a single function, thanks to ARGB you don't need to pass a million parameters to it.

Collapse JASS:
library UnitFadeSystem initializer Init requires ARGB, Table

//*****************************************************************
//*  UNIT FADE SYSTEM
//*
//*  written by: Anitarf
//*  requires: -ARGB
//*            -Table
//*
//*  A system that makes gradual modification of unit's vertex
//*  colouring, also called fading, an easy affair. The functions
//*  you can use are:
//*
//*  FadeUnitStart - Fades a unit from the start colour to the end
//*                  colour over a given duration.
//*  FadeUnitStop  - If a unit is already fading, then it stops
//*                  and the function returns it's current color;
//*                  else, the function returns 0.
//*  IsUnitFading  - Returns true if the unit is already fading.
//*****************************************************************

    private keyword fadingUnit

    globals
        //this value determines how much time elapses between unit colour updates
        private constant real FADE_PERIOD = 0.04


// END OF CALIBRATION SECTION    
// ================================================================

        private fadingUnit array fuList
        private integer fuListMax = 0
        private HandleTable cache //initialized in Init
    endglobals

    private struct fadingUnit
        integer list
        unit u
        ARGB start = 0
        ARGB end = 0
        real time = 0.0
        real endtime = FADE_PERIOD

        static method check takes unit u returns boolean
            return cache.exists(u)
        endmethod
        static method get takes unit u returns fadingUnit
            local fadingUnit fu = fadingUnit(cache[u])
            if fu==0 then
                set fu = fadingUnit.create()
                set cache[u]=integer(fu)
                set fu.u = u
                set fuList[fuListMax]=fu
                set fu.list = fuListMax
                set fuListMax=fuListMax+1
            endif
            return fu
        endmethod
        method onDestroy takes nothing returns nothing
            call cache.flush(.u)
            set this.u = null
            set fuListMax=fuListMax-1
            set fuList[this.list]=fuList[fuListMax]
            set fuList[this.list].list=this.list
        endmethod
    endstruct

    private function FadeUnits takes nothing returns nothing
        local integer i = 0
        local fadingUnit fu
        loop
            exitwhen i>=fuListMax
            set fu=fuList[i]
            set fu.time=fu.time+FADE_PERIOD
            if fu.time>=fu.endtime then
                set fu.time=fu.endtime
                call fu.destroy()
            else
                set i = i+1
            endif
            call ARGB.mix(fu.start, fu.end, fu.time/fu.endtime).recolorUnit(fu.u)
        endloop
    endfunction

    private function Init takes nothing returns nothing
        local timer t = CreateTimer()
        call TimerStart(t, FADE_PERIOD, true, function FadeUnits)
        set cache = HandleTable.create()
    endfunction

// ================================================================

    function FadeUnitStart takes unit u, ARGB start, ARGB end, real duration returns nothing
        local fadingUnit fu = fadingUnit.get(u)
        if duration < FADE_PERIOD then
            set duration = FADE_PERIOD
        endif
        set fu.start = start
        set fu.end = end
        set fu.time = 0.0
        set fu.endtime = duration
    endfunction

    function FadeUnitStop takes unit u returns ARGB
        local fadingUnit fu = fadingUnit.get(u)
        call fu.destroy()
        return ARGB.mix(fu.start, fu.end, fu.time/fu.endtime)
    endfunction

    function IsUnitFading takes unit u returns boolean
        return fadingUnit.check(u)
    endfunction

endlibrary
__________________
Anitarf is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 08-12-2008, 10:17 PM   #2
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,726

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

From what I can tell, this looks good, solid, and useful. I particularly like that you're building off of other in-database scripts. If you've tested it to make sure it works (It seems like it should be okay, but I might be overlooking something) then I will move it on its way.
__________________
Home Page
DoE v1.14c Download
AotZ v2.03d Download
OD v0.10x Download

Coming soon eventually...

Personal To-Do List:
ICARUS
Aot3

WC3C Chat
Chat IP: 66.103.20.109
Earthbound 2 in English
vJass Manual

"DAMAGE_TYPE_POISON motherfucker!" ~Anitarf
Rising_Dusk is offline   Reply With Quote
Old 08-14-2008, 02:34 PM   #3
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,887

Submissions (4)

Toadcop is just really nice (295)Toadcop is just really nice (295)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

Quote:
local trigger t = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(t, FADE_PERIOD)
call TriggerAddAction(t, function FadeUnits)
does it make sense ?

Quote:
thanks to ARGB you don't need to pass a million parameters to it.
1 vs 4 ? ...
__________________
Toadcop is offline   Reply With Quote
Old 08-14-2008, 02:50 PM   #4
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,053

Submissions (19)

Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by Toadcop
does it make sense ?
Fixed.
Quote:
1 vs 4 ? ...
No, 2 vs 8.
__________________
Anitarf is offline   Reply With Quote
Old 08-15-2008, 04:26 PM   #5
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

It is rather nice. Tested and seems to work.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 02-02-2009, 10:11 AM   #6
kentchow75
User
 
kentchow75's Avatar
 
Join Date: Jun 2007
Posts: 44

kentchow75 has little to show at this moment (3)

Send a message via MSN to kentchow75
Default

Sorry but I'm too noob in Jass.
I was searching all over the planet for a fade system and I found here.

The problem is,
"FadeUnitStart takes unit u, ARGB start, ARGB end, real duration returns nothing"

What perimeter should I put in the "start" and "end" ?
__________________
Yes !
It is me! ~GaLs~


kentchow75 is offline   Reply With Quote
Old 02-02-2009, 11:14 AM   #7
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,153

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

something like:
Quote:
0xFFFF0000
0xFFFF5B3D
__________________
akolyt0r is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 06:33 AM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services