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-05-2008, 01:51 PM   #1
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 ARGB

Collapse JASS:
library ARGB initializer init
//******************************************************************************
//*
//* ARGB 1.2
//* ====
//*  For your color needs.
//*  
//*  An ARGB object is a by-value struct, this means that assigning copies the
//* contents of the struct and that you don't have to use .destroy(), the
//* downside is that you cannot assign its members (can't do set c.r= 123 )
//*
//*  This library should have plenty of uses, for example, if your spell involves
//* some unit recoloring you can allow users to input the color in the config
//* section as 0xAARRGGBB and you can then use this to decode that stuff.
//*
//* You can also easily merge two colors and make fading effects using ARGB.mix
//*
//* There's ARGB.fromPlayer which gets an ARGB object containing the player's
//* color. Then you can use the previous utilities on it.
//*
//* The .str() instance method can recolor a string, and the recolorUnit method
//* will apply the ARGB on a unit
//*
//* For other uses, you can use the .red, .green, .blue and .alpha members to get
//* an ARGB object's color value (from 0 to 255).
//*
//* structs that have a recolor method that takes red,green,blue and alpha as 0.255
//* integers can implement the ARGBrecolor module to gain an ability to quickly
//* recolor using an ARGB object.
//*
//********************************************************************************

//=================================================================================
globals
    private string array i2cc
endglobals

//this double naming stuff is beginning to make me insane, if only TriggerEvaluate() wasn't so slow...
struct ARGB extends array
    static method create takes integer a, integer r, integer g, integer b returns ARGB
        return ARGB(b + g*0x100 + r*0x10000 + a*0x1000000)
    endmethod
    
    // not really part of the exported stuff, I may remove it in the future, so please don't call this textmacro
    //! textmacro ARGB_PLAYER_COLOR_2_ARGB
        if(pc==PLAYER_COLOR_RED) then
            return 0xFFFF0303
        elseif(pc==PLAYER_COLOR_BLUE) then
            return 0xFF0042FF
        elseif(pc==PLAYER_COLOR_CYAN) then
            return 0xFF1CE6B9
        elseif(pc==PLAYER_COLOR_PURPLE) then
            return 0xFF540081
        elseif(pc==PLAYER_COLOR_YELLOW) then
            return 0xFFFFFC01
        elseif(pc==PLAYER_COLOR_ORANGE) then
            return 0xFFFE8A0E
        elseif(pc==PLAYER_COLOR_GREEN) then
            return 0xFF20C000
        elseif(pc==PLAYER_COLOR_PINK) then
            return 0xFFE55BB0
        elseif(pc==PLAYER_COLOR_LIGHT_GRAY) then
            return 0xFF959697
        elseif(pc==PLAYER_COLOR_LIGHT_BLUE) then
            return 0xFF7EBFF1
        elseif(pc==PLAYER_COLOR_AQUA) then
            return 0xFF106246
        elseif(pc==PLAYER_COLOR_BROWN) then
            return 0xFF4E2A04
        endif
        
      return 0xFF111111
    //! endtextmacro
    static method fromPlayerColor takes playercolor pc returns ARGB
        //! runtextmacro ARGB_PLAYER_COLOR_2_ARGB()
    endmethod

    static method fromPlayer takes player p returns ARGB
     local playercolor pc=GetPlayerColor(p)
        //! runtextmacro ARGB_PLAYER_COLOR_2_ARGB()
    endmethod

    method operator alpha takes nothing returns integer
        if( integer(this) <0) then
            return 0x80+(-(-integer(this)+0x80000000))/0x1000000
        else
            return (integer(this))/0x1000000
        endif
    endmethod
    method operator alpha= takes integer na returns ARGB
     local integer a
     local integer r
     local integer g
     local integer b
     local integer col=integer(this)

       if (col<0) then
           set col=-(-col+0x80000000)
           set a=0x80+col/0x1000000
           set col=col-(a-0x80)*0x1000000
       else
           set a=col/0x1000000
           set col=col-a*0x1000000
       endif
       set r=col/0x10000
       set col=col-r*0x10000
       set g=col/0x100
       set b=col-g*0x100
       return ARGB(b + g*0x100 + r*0x10000 + na*0x1000000) 
    endmethod




    method operator red takes nothing returns integer
     local integer c=integer(this)*0x100
        if(c<0) then
            return 0x80+(-(-c+0x80000000))/0x1000000
        else
            return c/0x1000000
        endif
    endmethod
    method operator red= takes integer nr returns ARGB
     local integer a
     local integer r
     local integer g
     local integer b
     local integer col=integer(this)

       if (col<0) then
           set col=-(-col+0x80000000)
           set a=0x80+col/0x1000000
           set col=col-(a-0x80)*0x1000000
       else
           set a=col/0x1000000
           set col=col-a*0x1000000
       endif
       set r=col/0x10000
       set col=col-r*0x10000
       set g=col/0x100
       set b=col-g*0x100
       return ARGB(b + g*0x100 + nr*0x10000 + a*0x1000000) 
    endmethod

    method operator green takes nothing returns integer
     local integer c=integer(this)*0x10000
        if(c<0) then
            return 0x80+(-(-c+0x80000000))/0x1000000
        else
            return c/0x1000000
        endif
    endmethod
    method operator green= takes integer ng returns ARGB
     local integer a
     local integer r
     local integer g
     local integer b
     local integer col=integer(this)

       if (col<0) then
           set col=-(-col+0x80000000)
           set a=0x80+col/0x1000000
           set col=col-(a-0x80)*0x1000000
       else
           set a=col/0x1000000
           set col=col-a*0x1000000
       endif
       set r=col/0x10000
       set col=col-r*0x10000
       set g=col/0x100
       set b=col-g*0x100
       return ARGB(b + ng*0x100 + r*0x10000 + a*0x1000000) 
    endmethod

    //=======================================================
    //
    //
    method operator blue takes nothing returns integer
     local integer c=integer(this)*0x1000000
        if(c<0) then
            return 0x80+(-(-c+0x80000000))/0x1000000
        else
            return c/0x1000000
        endif
    endmethod
    method operator blue= takes integer nb returns ARGB
     local integer a
     local integer r
     local integer g
     local integer b
     local integer col=integer(this)

       if (col<0) then
           set col=-(-col+0x80000000)
           set a=0x80+col/0x1000000
           set col=col-(a-0x80)*0x1000000
       else
           set a=col/0x1000000
           set col=col-a*0x1000000
       endif
       set r=col/0x10000
       set col=col-r*0x10000
       set g=col/0x100
       set b=col-g*0x100
       return ARGB(nb + g*0x100 + r*0x10000 + a*0x1000000) 
    endmethod

    //====================================================================
    // Mixes two colors, s would be a number 0<=s<=1 that determines
    // the weight given to color c2.
    //
    //  mix(c1,c2,0)   = c1
    //  mix(c1,c2,1)   = c2
    //  mix(c1,c2,0.5) = Mixing the colors c1 and c2 in equal proportions.
    //
    static method mix takes ARGB c1, ARGB c2, real s returns ARGB
      //widest function ever
      return ARGB( R2I(c2.blue*s+c1.blue*(1-s)+0.5) + R2I(c2.green*s+c1.green*(1-s)+0.5)*0x100 + R2I(c2.red*s+c1.red*(1-s)+0.5)*0x10000 + R2I(c2.alpha*s+c1.alpha*(1-s)+0.5)*0x1000000)
    endmethod

    method str takes string s returns string
       return "|c"+i2cc[.alpha]+i2cc[.red]+i2cc[.green]+i2cc[.blue]+s+"|r"
    endmethod

    method recolorUnit takes unit u returns nothing
     local integer a
     local integer r
     local integer g
     local integer b
     local integer col=integer(this)

       if (col<0) then
           set col=-(-col+0x80000000)
           set a=0x80+col/0x1000000
           set col=col-(a-0x80)*0x1000000
       else
           set a=col/0x1000000
           set col=col-a*0x1000000
       endif
       set r=col/0x10000
       set col=col-r*0x10000
       set g=col/0x100
       set b=col-g*0x100
       call SetUnitVertexColor(u,r,g,b,a)
    endmethod

endstruct

module ARGBrecolor
    method ARGBrecolor takes ARGB color returns nothing
     local integer a
     local integer r
     local integer g
     local integer b
     local integer col=integer(this)

       if (col<0) then
           set col=-(-col+0x80000000)
           set a=0x80+col/0x1000000
           set col=col-(a-0x80)*0x1000000
       else
           set a=col/0x1000000
           set col=col-a*0x1000000
       endif
       set r=col/0x10000
       set col=col-r*0x10000
       set g=col/0x100
       set b=col-g*0x100
       
       call this.recolor(r, g , b, a)
    endmethod

endmodule

private function init takes nothing returns nothing
 local integer i=0

    // Don't run textmacros you don't own!
    //! textmacro ARGB_CHAR takes int, chr
        set i=0
        loop
            exitwhen i==16
            set i2cc[$int$*16+i]="$chr$"+i2cc[$int$*16+i]
            set i2cc[i*16+$int$]=i2cc[i*16+$int$]+"$chr$"
            set i=i+1
        endloop
    //! endtextmacro
    //! runtextmacro ARGB_CHAR( "0","0")
    //! runtextmacro ARGB_CHAR( "1","1")
    //! runtextmacro ARGB_CHAR( "2","2")
    //! runtextmacro ARGB_CHAR( "3","3")
    //! runtextmacro ARGB_CHAR( "4","4")
    //! runtextmacro ARGB_CHAR( "5","5")
    //! runtextmacro ARGB_CHAR( "6","6")
    //! runtextmacro ARGB_CHAR( "7","7")
    //! runtextmacro ARGB_CHAR( "8","8")
    //! runtextmacro ARGB_CHAR( "9","9")
    //! runtextmacro ARGB_CHAR("10","A")
    //! runtextmacro ARGB_CHAR("11","B")
    //! runtextmacro ARGB_CHAR("12","C")
    //! runtextmacro ARGB_CHAR("13","D")
    //! runtextmacro ARGB_CHAR("14","E")
    //! runtextmacro ARGB_CHAR("15","F")
endfunction

endlibrary

For example:

Collapse JASS:
function Degrade takes string message, ARGB colorA, ARGB colorB returns string
 local integer i=0
 local integer L=StringLength(message)
 local string  r
    if(L==1) then
        return ARGB.mix(colorA,colorB,0.5).str(message)
    endif
    set r=""
    loop
        exitwhen (i>=L)
        set r=r+ARGB.mix(colorA,colorB, i*(1.0/ (L-1) ) ).str( SubString(message,i,i+1) )
        set i=i+1
    endloop
 return r
endfunction


call BJDebugMsg( Degrade("Hello" , 0xFFFF0000, 0xFF0000FF ) )
This function would just add a degrade effect to some string, notice it 'leaks' some strings.

Version 1.1 comes with a module and therefore requires jasshelper G.0 or greater.

The module can be used by any struct with a recolor method takes red, green, blue and alpha as arguments. (in range 0..255). It will add a method called ARGBrecolor that takes an ARGB and will rapidly decode all four color values then call this other recolor() method, for example:

Collapse JASS:
struct color
    integer r
    integer g
    integer b
    integer a

    method recolor takes integer r, integer g, integer b, integer a returns nothing
        set this.r = r
        set this.g = g
        set this.b = b
        set this.a = a
    endmethod

    implement ARGBrecolor
endstruct

function test takes color cc returns nothing
    call cc.ARGBrecolor( 0xFFE040AA )
endfunction

The example is lame as the struct using the module is lame, but I guess the point is understandable.


Extra stuff:
The purpose of this script (please stop calling it "system") is to aid in a bunch of silly color related operations, it does so, the result code is fine and easy to use and the performance penalty is barely 3 times what the manual stuff would take. Even though struct systax is in use, it doesn't inherit problems from structs like the bloat .create() and .destroy() add or having to worry about cleaning leaks. Users can input colors as 0xAARRGGBB and this thing will handle decoding those things, it is also a proof of concept for doing such things using struct syntax.

Notice how the Degrade function does not need to do .destroy on what's returned by .mix() this simplifies things a little and is all a result of the structs being by-value instead of by-ref, fun? Also notice how Degrade is being called easily without specifying 4 values per color or having to use other variables to create the colors.

Edit: Fixed that bug with recolorUnit
__________________
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
Sponsored Links - Login to hide this ad!
Old 08-05-2008, 02:07 PM   #2
d07.RiV
User
 
d07.RiV's Avatar
 
Join Date: May 2008
Posts: 239

Submissions (1)

d07.RiV is on a distinguished road (10)

Default

How about assignment operators? One might want to do set color.red = 128
And -(-c+0x80000000) is the same as c-0x80000000 isnt it?
__________________
d07.RiV is offline   Reply With Quote
Old 08-05-2008, 02:29 PM   #3
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)

Default

Collapse JASS:
    static method create takes integer a, integer r, integer g, integer b returns ARGB
        return ARGB(b + g*0x100 + r*0x10000 + a*0x1000000)
    endmethod
Rofl, nice struct abuse.

By double naming you mean having same name for library and struct?
What is wrong with that?
I mean what would be the alternative, to declare a generator global variable LIBRARY_NAME to be used instead?

SCOPE_PREFIX--
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 08-05-2008, 04:42 PM   #4
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

Quote:
Originally Posted by d07.RiV
How about assignment operators? One might want to do set color.red = 128
And -(-c+0x80000000) is the same as c-0x80000000 isnt it?
Well, right now you can do set color= ARGB.create(color.red, color.green, color.blue)

Can't do assignment stuff without making the structs by-ref again then you would need destroy and all sorts of things like that.

Edit; I think assignment operators would work if I changed jasshelper to allow:
Collapse JASS:
set x.r = 2
To be converted to:
Collapse JASS:
set x= assign_r(x,2)

Instead of
Collapse JASS:
   call assign_r(x,2)
Perhaps if []= and .= return the struct's type do that? There is really no use right now for the return value of the = operator methods anyway.
__________________
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 08-05-2008, 09:02 PM   #5
d07.RiV
User
 
d07.RiV's Avatar
 
Join Date: May 2008
Posts: 239

Submissions (1)

d07.RiV is on a distinguished road (10)

Default

Ops I forgot that color's "this" changes after assignments ><
Syntax abuse ftl

Color system would benefit from global operator overloading, as would many other systems.
__________________

Last edited by d07.RiV : 08-05-2008 at 09:04 PM.
d07.RiV is offline   Reply With Quote
Old 08-05-2008, 10:41 PM   #6
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

now 1 million question. in which way it's better than for example

struct argb
integer a
integer r
integer g
integer b
endstruct

??? ok you can do this with out any sturct simple parrarel arrays. (avoid the allocation stuff)

yes the only good stuff is
Collapse JASS:
    static method mix takes ARGB c1, ARGB c2, real s returns ARGB
      //widest function ever
      return ARGB( R2I(c2.blue*s+c1.blue*(1-s)+0.5) + R2I(c2.green*s+c1.green*(1-s)+0.5)*0x100 + R2I(c2.red*s+c1.red*(1-s)+0.5)*0x10000 + R2I(c2.alpha*s+c1.alpha*(1-s)+0.5)*0x1000000)
    endmethod
but it's pure math.
+ no the widest func is (as far i didn't wrote a another one xD)

Collapse JASS:
function TcX_getweapon_dps_BX takes xunit xu returns real
    local xupar xpar=xu.params
    local real dps=0
  if tcx_mod==1 and xu.weap_current>0 then
   if xu.weap_current<9 then
    if xu.weap_current<5 then
     if xu.weap_current<3 then  
      if xu.weap_current<2 then
        set dps=((AmplifyValue2BX(((xweap_saw_dmg_1+(xpar.min[STAT_DMG_PHYS]+(xpar.min[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_saw_dmg_1+(xpar.max[STAT_DMG_PHYS]+(xpar.max[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_PHYS_PERC]+(xpar.par[STAT_DMG_PHYS_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultphys)/(weaponcooldown[X_saw]/xu.attackspeedmul)
      else
        set dps=((AmplifyValue2BX(((xweap_machinegun_dmg_1+(xpar.min[STAT_DMG_PHYS]+(xpar.min[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_machinegun_dmg_1+(xpar.max[STAT_DMG_PHYS]+(xpar.max[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_PHYS_PERC]+(xpar.par[STAT_DMG_PHYS_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultphys)/(weaponcooldown[X_machinegun]/xu.attackspeedmul)
      endif
     else
      if xu.weap_current<4 then
        set dps=((AmplifyValue2BX(((xweap_shotgun_dmg_1+(xpar.min[STAT_DMG_PHYS]+(xpar.min[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_shotgun_dmg_1+(xpar.max[STAT_DMG_PHYS]+(xpar.max[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_PHYS_PERC]+(xpar.par[STAT_DMG_PHYS_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultphys)/(weaponcooldown[X_shotgun]/xu.attackspeedmul)*xweap_shotgun_maxpellets
      else
        set dps=((AmplifyValue2BX(((xweap_shaft_dmg_1+(xpar.min[STAT_DMG_ELEC]+(xpar.min[STAT_DMG_ELEC_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_shaft_dmg_1+(xpar.max[STAT_DMG_ELEC]+(xpar.max[STAT_DMG_ELEC_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_ELEC_PERC]+(xpar.par[STAT_DMG_ELEC_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultelec)/(weaponcooldown[X_shaft]/xu.attackspeedmul)
      endif
     endif
    else
     if xu.weap_current<7 then  
      if xu.weap_current<6 then
        set dps=((AmplifyValue2BX(((xweap_granade_dmg_1+(xpar.min[STAT_DMG_TERM]+(xpar.min[STAT_DMG_TERM_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_granade_dmg_1+(xpar.max[STAT_DMG_TERM]+(xpar.max[STAT_DMG_TERM_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_TERM_PERC]+(xpar.par[STAT_DMG_TERM_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultterm)/(weaponcooldown[X_granade]/xu.attackspeedmul)
      else
        set dps=((AmplifyValue2BX(((xweap_plasma_dmg_1+(xpar.min[STAT_DMG_PLAS]+(xpar.min[STAT_DMG_PLAS_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_plasma_dmg_1+(xpar.max[STAT_DMG_PLAS]+(xpar.max[STAT_DMG_PLAS_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_PLAS_PERC]+(xpar.par[STAT_DMG_PLAS_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultplas)/(weaponcooldown[X_plasma]/xu.attackspeedmul)
      endif
     else
      if xu.weap_current<8 then
        set dps=((AmplifyValue2BX(((xweap_rocket_dmg_1+(xpar.min[STAT_DMG_TERM]+(xpar.min[STAT_DMG_TERM_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_rocket_dmg_1+(xpar.max[STAT_DMG_TERM]+(xpar.max[STAT_DMG_TERM_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_TERM_PERC]+(xpar.par[STAT_DMG_TERM_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultterm)/(weaponcooldown[X_rocket]/xu.attackspeedmul)
      else
        set dps=((AmplifyValue2BX(((xweap_railgun_dmg_1+(xpar.min[STAT_DMG_SPEC]+(xpar.min[STAT_DMG_SPEC_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_railgun_dmg_1+(xpar.max[STAT_DMG_SPEC]+(xpar.max[STAT_DMG_SPEC_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_SPEC_PERC]+(xpar.par[STAT_DMG_SPEC_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultspec)/(weaponcooldown[X_railgun]/xu.attackspeedmul)
      endif
     endif
    endif
   else

    if xu.weap_current<13 then
     if xu.weap_current<11 then  
      if xu.weap_current<10 then
        set dps=((AmplifyValue2BX(((xweap_deathdisc_dmg_1+(xpar.min[STAT_DMG_PHYS]+(xpar.min[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_deathdisc_dmg_1+(xpar.max[STAT_DMG_PHYS]+(xpar.max[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_PHYS_PERC]+(xpar.par[STAT_DMG_PHYS_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultphys)/(weaponcooldown[X_bloodysaw]/xu.attackspeedmul)
      else
        set dps=((AmplifyValue2BX(((xweap_chaingun_dmg_1+(xpar.min[STAT_DMG_PHYS]+(xpar.min[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_chaingun_dmg_1+(xpar.max[STAT_DMG_PHYS]+(xpar.max[STAT_DMG_PHYS_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_PHYS_PERC]+(xpar.par[STAT_DMG_PHYS_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultphys)/(weaponcooldown[X_chaingun]/xu.attackspeedmul)
      endif
     else
      if xu.weap_current<12 then
        set dps=((AmplifyValue2BX(((xweap_flamegun_dmg_1+(xpar.min[STAT_DMG_TERM]+(xpar.min[STAT_DMG_TERM_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_flamegun_dmg_1+(xpar.max[STAT_DMG_TERM]+(xpar.max[STAT_DMG_TERM_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_TERM_PERC]+(xpar.par[STAT_DMG_TERM_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultterm)/(weaponcooldown[X_flamegun]/xu.attackspeedmul)
      else
        set dps=((AmplifyValue2BX(((xweap_shaftex_dmg_1+(xpar.min[STAT_DMG_ELEC]+(xpar.min[STAT_DMG_ELEC_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_shaftex_dmg_1+(xpar.max[STAT_DMG_ELEC]+(xpar.max[STAT_DMG_ELEC_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_ELEC_PERC]+(xpar.par[STAT_DMG_ELEC_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultelec)/(weaponcooldown[X_shaftex]/xu.attackspeedmul)
      endif
     endif
    else
     if xu.weap_current<15 then  
      if xu.weap_current<14 then
        set dps=((AmplifyValue2BX(((xweap_wispgun_dmg_1+(xpar.min[STAT_DMG_SPEC]+(xpar.min[STAT_DMG_SPEC_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_wispgun_dmg_1+(xpar.max[STAT_DMG_SPEC]+(xpar.max[STAT_DMG_SPEC_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_SPEC_PERC]+(xpar.par[STAT_DMG_SPEC_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultspec)/(weaponcooldown[X_wispgun]/xu.attackspeedmul)
      else
        set dps=((AmplifyValue2BX(((xweap_plasmaex_dmg_1+(xpar.min[STAT_DMG_PLAS]+(xpar.min[STAT_DMG_PLAS_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_plasmaex_dmg_1+(xpar.max[STAT_DMG_PLAS]+(xpar.max[STAT_DMG_PLAS_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_PLAS_PERC]+(xpar.par[STAT_DMG_PLAS_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultplas)/(weaponcooldown[X_plasmaex]/xu.attackspeedmul)
      endif
     else
      if xu.weap_current<16 then
        set dps=((AmplifyValue2BX(((xweap_bfg_dmg_1+(xpar.min[STAT_DMG_PLAS]+(xpar.min[STAT_DMG_PLAS_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_bfg_dmg_1+(xpar.max[STAT_DMG_PLAS]+(xpar.max[STAT_DMG_PLAS_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_PLAS_PERC]+(xpar.par[STAT_DMG_PLAS_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultplas)/(weaponcooldown[X_bfg]/xu.attackspeedmul)
      else
        set dps=((AmplifyValue2BX(((xweap_railgunex_dmg_1+(xpar.min[STAT_DMG_SPEC]+(xpar.min[STAT_DMG_SPEC_LVL]*xu.lvl)+xu.mindmg)*FLOAT_POINT_PREC)+(xweap_railgunex_dmg_1+(xpar.max[STAT_DMG_SPEC]+(xpar.max[STAT_DMG_SPEC_LVL]*xu.lvl)+xu.maxdmg)*FLOAT_POINT_PREC))*0.5,xu.dmgperc+(xpar.par[STAT_DMG_SPEC_PERC]+(xpar.par[STAT_DMG_SPEC_PERC_LVL]*xu.lvl))*FLOAT_POINT_PREC))*xu.dmgmultx*xu.dmgmult*xu.dmgmultspec)/(weaponcooldown[X_railgunex]/xu.attackspeedmul)
      endif
     endif
    endif

      
   endif
  endif
   return dps
endfunction

well imo it's too simple. (this script)
__________________
Toadcop is offline   Reply With Quote
Old 08-05-2008, 11:11 PM   #7
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)

Default

After seeing this I am 100% sure default GUI code generator was made by some Russian.

@Vexorian
Although that struct index abuse is interesting it cannot supplement the higher language functionality you need here.
I believe better solution would be making a standard destroyable struct with a copy (clone) method.


Anyways Vex we really don't need any more strange-operator-candy-stuff in jasshelper.
Those static [] and []= are becoming a common request btw...
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 08-05-2008, 11:24 PM   #8
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

i bet this func is more complicated than anything else in your Pyramidal defence xD
well whatever.

my personal "problem" with this "system" is what it does do too much useless calculations... (converting to chars/integer)
__________________
Toadcop is offline   Reply With Quote
Old 08-05-2008, 11:48 PM   #9
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

Quote:
struct argb
integer a
integer r
integer g
integer b
endstruct
* 8191 limit.
* Extra code, arrays and overhead if you want to go above.
* You have to use .destroy.
* Can't let people assign stuff like this:
* Uses 4x more memory.

Collapse JASS:
globals
    private constant ARGB x=0xFFFF0000
endglobals

Config stuff was the first thing these functions were made for.

The only 'advantage' whatsoever with using instance structs here would be the ability to do member assignments, however that's utterly lame, assignments are useless for this sort of thing, the only assigment you'll ever need is x=0xFFFF0000.

And the calculations might worry you only if you like speed, unless we begin to care about the overhead things like create and destroy add or the fact that the applications for this are not really speed intensive.

Quote:
Those static [] and []= are becoming a common request btw...
Request? how come if they are already implemented?
__________________
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 08-06-2008, 09:30 AM   #10
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:
8191 limit.
lol... i could repeat tons of your words to disprove this one.

Quote:
* Extra code, arrays and overhead if you want to go above.
displayed code... after preproccesing it will become X times larger.

Quote:
Uses 4x more memory.
lol.

the sense is what you make simple things overcomplicated. it's like to store all playercolor tags in 1 string and to get the needed on with SubString (or something similar)

in fact such stuff is degradation of coding. OFC for you not, but for those who use it =) // it's much like the vJass concept.

Quote:
if you like speed
well if i create a spell for dynamic coloring of units i need to begin to worry about speed =)

the feature is what map (playable) contains of alot simple parts but together they take some performance. so you need to watch what are you doing.

ofc in "static" aplications speed is not really essential.

and one thing...

Collapse JASS:
set a=0xff
set r=0xff
set g=0x00
set b=0x00
it'a all about the perspective of vision =)
__________________
Toadcop is offline   Reply With Quote
Old 08-07-2008, 08:43 AM   #11
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)cohadar is a jewel in the rough (246)

Default

Quote:
Originally Posted by Vexorian
Request? how come if they are already implemented?

I got stupid for a sec there.
Was thinking about static structs.
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 08-07-2008, 01:40 PM   #12
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

Quote:
well if i create a spell for dynamic coloring of units i need to begin to worry about speed =)

the feature is what map (playable) contains of alot simple parts but together they take some performance. so you need to watch what are you doing.

ofc in "static" aplications speed is not really essential.

and one thing...

You seem to have the idea that SetUnitVertexColor(u, red[a], green[a], blue[a], alpha[a]) is incredibly much faster than the .recolor method in here. For a guy that has made a playable map (I guess that now counts as an achievement) you seem to have a wrong idea of what is fast and what isn't, or the scale in which something is faster than the other. You actually sound very alarmist about speed sometimes yet other times use something that causes more speed issues that another thing. I think a really experienced Jasser (and I am yet to see one) would have made an actual benchmark before making claims, instead of using his playable-map-maker license...

I guess, the recolor method is much slower than SetUnitVertexColor(u, red[a], green[a], blue[a], alpha[a]), if much slower means 0.1%? or 1% or 100%?. Let's even forget about .create() and .destroy() and the fact that you are making a periodic timer that changes a unit's vertex color every 0.025 seconds... let's assume the bottleneck is with the divisions (it's amazing how these divisions are so evil in comparison to array lookups in these color utilities functions yet so good when we are comparing hash tables with array lookups)

Let's also forget that if you used normal structs mix() will actually need to call create() in order to work in the same way, and that application of recoloring some unit with a periodic event - I guess it is all about the mix function, else it wouldn't make any sense to be doing that periodic recoloring anyway. Let's add a call to create() to the mix() function because we care so much about speed... When you think about it, mix will still need R2I calls, double multiplication, division and addition regardless of whether you used struct members or not, But the integer division used in the .recolor method is obviously much worse.

Of course, there are workarounds, like modifying the mix function so it takes 3 arguments, now the code to use has gotten more complicated, but who cares? Speed is what matters here, you will still be calling mix() which is obviously a huge problem performance-wise... I got an idea! Since we like speed so much, let's instead preload the colors to be used in the periodic loop! That should work!

... but, we could have preloaded the colors into groups of four r,g,b,a variables anyway if we sticked to the original implementation of ARGB... So much work for nothing.


Quote:
displayed code... after preproccesing it will become X times larger.
But your idea of a single struct holding red green and blue will get larger than that. Oh and if you wanted to get rid of the 8190 limit, much, much larger.

In my opinion, making something equivalent to this using struct members (and I mean equivalent in functionality) would require you to have like a big instance limit since you are not ever going to use .destroy() or .create whatsoever . Because of this, you would need function calls to get the values for red green and blue... If you made an equivalent thing using struct members, it would get slower.

Something to consider is that speed is not the focus here, because at the end of the day, not using this script and doing everything manually, not even with structs but with local variables r,g,b,a is many times faster, any optimization making it use members instead of encoded integers would be worthless, the fastest way is to do all the mixing manually. So, you may be wondering up, what's the point of this script if it isn't the fastest way possible? Sometimes things are not meant to speed execution up, but to speed development time up... I know you, it is very hard for you to accept the fact someone would be more interested in reducing development time rather than performance time. But I got to say, almost everybody out there that is making actual playable maps rather than demos or ego projects, cares more about releasing his maps soon than about speeding up a function by 1%, speed is nice and all, but Jass being an interpreted language, there is sometimes no point really in using something that is faster than something else when the time to code it, implement it and debug it would be much larger than the alternative, unless the difference in performance is really big, but that would be things like O(n^2) vs. O(n) rather than things like division vs. arrays... If we were talking about a freaking game engine instead of changing the color of a unit every 0.025 seconds using an interpreted language, speed would matter much more, sadly we are not.

--
Everyone can make a playable map, I did, you did, who cares? There's something you are missing greatly and it is that not everybody wants to spend 2 or 3 years making a map, the worst thing that could happen is that they end up taking so much time that when they finish it there really are no players left, perhaps if they speeded the development up of their map instead of going ultra low level just to get 1% more speed in one function they would have finished their map much before, perhaps by the time Allstars was released... instead of 2008...
__________________
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 08-07-2008, 08:59 PM   #13
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:
I guess, the recolor method is much slower than SetUnitVertexColor(u, red[a], green[a], blue[a], alpha[a]), if much slower means 0.1%? or 1% or 100%?.
300%+ (for sure.) ...

Quote:
There's something you are missing greatly and it is that not everybody wants to spend 2 or 3 years making a map,
if you talking "about me" (TcX) so... i start it april 2007 and released 1.00 18 aug 2007. so well 4-5 months. a full custom map (which does offer many unique features for war3.) ofc it's not mega optimized but it really decent coded. and i made the full map by my self. (some art was made by some guys but the most part by me, for example all billboard icons...)
Your theory fails. (2-3 years lol...)
the guys with X long projects are Dreamers an loosers. they simply don't see wha they phail... a good map maker know which work he can complete.
(you may think i am a theorizer but it's wrong. I allways try to analise the task before i begin it and if i begin it so i "exactly" know how to realise it. otherwise i will not start it.)


ONCE AGAIN. it's fine post this "system" in scripting section as "feature" and thats it. it's nice and there are some stuff for discussion.
but to post it as a submission... n/c.
+ if so just upload it to the resource db and . you are admin here so no one will realy care about. (me inluding)

the problem is creating the circus.

oh damn ! the best solution ever ! post it in you sub forum "Vex spell and etc". It will make much sense =) but ofc it's your decission.

"It doesnt matter how this code is written, it does matter how this code does work" ... algorithm logic > all.

thats all imo ofc you can ignore it =)
__________________
Toadcop is offline   Reply With Quote
Old 08-07-2008, 09:45 PM   #14
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

Quote:
if you talking "about me"
Not really, just trying to say that sometimes ease of use is much more desirable than raw speed. But "4 to 5 months" does sound like a lot of time.

--
I want this to be reviewed if you don't mind, I was already criticized by Cohadar for doing what you suggested and in my opinion he was right. If you don't like circuses please don't go around starting them for no reason. In this case, the excuse you used for yet again starting a circus was the theoric performance issues caused by integer divisions, it seems that not only speed is not the priority of this script, but according to your own words the speed cost is really not that bad.- You said you are sure this is 300% times slower, even though you still haven't made any benchmark (have you ever done a benchmark?) I'll take that as a fact, if this is barely 300% slower than direct stuff then it is quite good already.

The purpose of this script (please stop calling it "system") is to aid in a bunch of silly color related operations, it does so, the result code is fine and easy to use and the performance penalty is barely 3 times what the manual stuff would take. Even though struct systax is in use, it doesn't inherit problems from structs like the bloat .create() and .destroy() add or having to worry about cleaning leaks. Users can input colors as 0xAARRGGBB and this thing will handle decoding those things, it is also a proof of concept for doing such things using struct syntax.
__________________
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 08-08-2008, 12:27 AM   #15
Rising_Dusk
Obscurity, the Art


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

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

Quote:
Originally Posted by Vexorian
I want this to be reviewed if you don't mind,
I'd love to, but I oftentimes have a hard time understanding both what it should do and then if how you're doing it is the best way. Of all of the people on this site, though, I trust the name of Vexorian the most for well-thought out and designed code, so I trust there will be zero changes that will need be made.

So let me see if I understand. I can input a value like 0xAARRGGBB as you say and it will know exactly the Wc3 color code in RGB (255, 255, 255) for what that input value is? Is that right, even close?
__________________
Rising_Dusk 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 07:44 PM.


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