![]() |
#1 | |
Free Software Terrorist
Technical Director
|
![]() ![]() 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: ![]() 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 ) ) 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: ![]() 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 Extra stuff:
Edit: Fixed that bug with recolorUnit |
|
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
User
Join Date: May 2008
Posts: 241
![]() |
![]() How about assignment operators? One might want to do set color.red = 128
__________________And -(-c+0x80000000) is the same as c-0x80000000 isnt it? |
![]() |
![]() |
![]() |
#3 |
master of fugue
Join Date: Jun 2007
Posts: 2,453
![]() ![]() ![]() ![]() ![]() |
![]() ![]() static method create takes integer a, integer r, integer g, integer b returns ARGB return ARGB(b + g*0x100 + r*0x10000 + a*0x1000000) endmethod 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-- ![]() |
![]() |
![]() |
![]() |
#4 | |
Free Software Terrorist
Technical Director
|
![]() Quote:
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: ![]() set x.r = 2 ![]() set x= assign_r(x,2) Instead of ![]() call assign_r(x,2) |
|
![]() |
![]() |
![]() |
#5 |
User
Join Date: May 2008
Posts: 241
![]() |
![]() 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 10:04 PM. |
![]() |
![]() |
![]() |
#6 |
BuranX
|
![]() 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 ![]() 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 + no the widest func is (as far i didn't wrote a another one xD) ![]() 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) |
![]() |
![]() |
![]() |
#7 |
master of fugue
Join Date: Jun 2007
Posts: 2,453
![]() ![]() ![]() ![]() ![]() |
![]() 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... |
![]() |
![]() |
![]() |
#8 |
BuranX
|
![]() 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) |
![]() |
![]() |
![]() |
#9 | ||
Free Software Terrorist
Technical Director
|
![]() Quote:
* 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. ![]() 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:
|
||
![]() |
![]() |
![]() |
#10 | ||||
BuranX
|
![]() Quote:
Quote:
Quote:
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:
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... ![]() set a=0xff set r=0xff set g=0x00 set b=0x00 |
||||
![]() |
![]() |
![]() |
#11 | |
master of fugue
Join Date: Jun 2007
Posts: 2,453
![]() ![]() ![]() ![]() ![]() |
![]() Quote:
I got stupid for a sec there. Was thinking about static structs. |
|
![]() |
![]() |
![]() |
#12 | ||
Free Software Terrorist
Technical Director
|
![]() Quote:
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:
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... |
||
![]() |
![]() |
![]() |
#13 | ||
BuranX
|
![]() Quote:
Quote:
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 =) |
||
![]() |
![]() |
![]() |
#14 | |
Free Software Terrorist
Technical Director
|
![]() Quote:
-- 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. |
|
![]() |
![]() |
![]() |
#15 | |
Obscurity, the Art
|
![]() Quote:
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? |
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|