undefined Posted February 3, 2016 Share Posted February 3, 2016 (edited) I'm use this function to draw text outline. But it's use %13 CPU. I think it's so big for only draw outline. How can i decrease it? function tocolorToRGBA(color) return bitExtract(color, 0, 8 ), bitExtract(color, 8, 8 ), bitExtract(color, 16, 8 ), bitExtract(color, 24, 8 ) end local _dxDrawText = dxDrawText function dxDrawText(...) local args = {...} args[4] = args[2] + args[4] args[5] = args[3] + args[5] return _dxDrawText(unpack(args)) end function dxDrawTextOutline(...) local args = {...} local _, startX, startY = unpack(args) local color = args[6] local _,_,_,a = tocolorToRGBA(color) args[6] = tocolor(0,0,0,a) args[2], args[3] = startX-1, startY-1 dxDrawText(unpack(args)) args[2], args[3] = startX-1, startY+1 dxDrawText(unpack(args)) args[2], args[3] = startX+1, startY+1 dxDrawText(unpack(args)) args[2], args[3] = startX+1, startY-1 dxDrawText(unpack(args)) args[2], args[3], args[6] = startX, startY, color dxDrawText(unpack(args)) end addEventHandler("onClientRender", root, functon() dxDrawOutlineText(text, x, y, ...) end) Edited February 3, 2016 by Guest Link to comment
Bonus Posted February 3, 2016 Share Posted February 3, 2016 draw it on a renderTarget and draw the renderTarget with dxDrawImage Link to comment
Dealman Posted February 3, 2016 Share Posted February 3, 2016 draw it on a renderTarget and draw the renderTarget with dxDrawImage This makes absolutely no sense. In what way would this decrease CPU usage...? Link to comment
undefined Posted February 3, 2016 Author Share Posted February 3, 2016 draw it on a renderTarget and draw the renderTarget with dxDrawImage It have no effect. Link to comment
Bonus Posted February 3, 2016 Share Posted February 3, 2016 You know what a render target is, right? Link to comment
undefined Posted February 3, 2016 Author Share Posted February 3, 2016 Sure, but it is useless. Link to comment
Bonsai Posted February 3, 2016 Share Posted February 3, 2016 Everything that doesn't change over time should be outside of the render function. If it only changes sometimes, it should be set somewhere else and the render function should only use those values, not calculate them itself. Link to comment
Bonus Posted February 3, 2016 Share Posted February 3, 2016 Absolutely not I'll tell you the difference: Your code: You use the function in every frame. When you have 60 FPS , your function has to get called 60 times per second. Thats 60x tocolorToRGBA, 300x dxDrawText ... RenderTarget: You create a RenderTarget, set the render target to this rendertarget and use your dxDrawOutlineText only 1 time! After that you clear the render target and use your rendertarget-texture: You just draw the rendertarget every frame. Thats only 60x dxDrawImage per Second Much better performance. example: http://www2.pic-upload.de/img/29634650/mta-screen_2016-01-16_05-24-27.png This window is just one renderTarget, 1 dxDrawText and 1 dxDrawRectangle. That means onClientRender uses only 1 dxDrawImage, 1 dxDrawText and 1 dxDrawRectangle every second. Without the renderTarget onClientRender-function would have to call atleast 8 dxDrawImage, 12 dxDrawText, 45 dxDrawImage and 4 dxDrawLine every second!! Which one is better? Link to comment
Mr_Moose Posted February 4, 2016 Share Posted February 4, 2016 Well, dxDrawText itself it a pretty CPU hungry function and you got at least 5 of those (usually gives around 10% CPU usage), you could build your text as a single multi line string first and then send it to the draw function once to reduce your CPU usage to 2% maybe 3% if your lucky. Table unpack is quiet heavy too, maybe you could skip that and pass the data directly as it is using index numbers instead. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now