Hello there!
I've wrote a little code that can replace current LUA "Color()" function.
Why? My function will work much faster that current one, because it's using bitwise operations.
It will take only one number instead of whole table of 4 numbers.
So, here's the code:
[CODE]--[[
New Gmod experimental color system
(C) NanoCat, 2013
]]
local bor, band, lshift, rshift = bit.bor, bit.band, bit.lshift, bit.rshift
function Color( r, g, b, a )
return bor( lshift( band( r or 0, 0xFF ), 24 ), lshift( band( g or 0, 0xFF ), 16 ), lshift( band( b or 0, 0xFF ), 8 ), band( a or 255, 0xFF ) )
end
function Red( color )
return rshift( color, 24 )
end
function Green( color )
return band( rshift( color, 16 ), 0xFF )
end
function Blue( color )
return band( rshift( color, 8 ), 0xFF )
end
function Alpha( color )
return band( color, 0xFF )
end
function RGBA( color )
return Red( color ), Green( color ), Blue( color ), Alpha( color )
end
--[[
Uncomment to test it :)
print( RGBA( Color( 167, 122, 64, 243 ) ) )
]][/CODE]
Say what you think about it :3
P.S. Sorry for my bad english :c
I didn't even realise the Color stuff needed any optimisation.
Have you actually benchmarked it, or are you just assuming it's faster?
Plus, you don't have any modifier functions. How would I write color.g = color.g / 2 with your system?
Sorry, you need to Log In to post a reply to this thread.