Flower ☠ Power Posted May 4, 2019 Share Posted May 4, 2019 So today I was making a new HUD for players in dx, due this HUD will be displayed all the time I started thinking about how I can optimize it as maximun as possible... Going from this classic code: local screenW, screenH = guiGetScreenSize() local scaleX, scaleY = screenW/1920, screenH/1080 addEventHandler("onClientRender", root, function() dxDrawText("30/", screenW * 0.7786, screenH * 0.0648, screenW * 0.8380, screenH * 0.1426, tocolor(241, 173, 11, 255), scaleX, scaleY, dxfont0_excelsior_sans, "left", "top", false, false, false, false, false) dxDrawText("9999", screenW * 0.8354, screenH * 0.0657, screenW * 0.8807, screenH * 0.1130, tocolor(241, 173, 11, 255), scaleX, scaleY, dxfont1_excelsior_sans, "left", "top", false, false, false, false, false) end) to this "more optimized" one: local screenW, screenH = guiGetScreenSize() local scaleX, scaleY = screenW/1920, screenH/1080 local hudSizes = { (screenW * 0.7786), (screenH * 0.0648), (screenW * 0.8380), (screenH * 0.1426), (screenW * 0.8354), (screenH * 0.0657), (screenW * 0.8807), (screenH * 0.1130) } addEventHandler("onClientRender", root, function() dxDrawText("30/", hudSizes[1], hudSizes[2], hudSizes[3], hudSizes[4], 0xFFF1AD0B, scaleX, scaleY, dxfont0_excelsior_sans, "left", "top", false, false, false, false, false) dxDrawText("9999", hudSizes[5], hudSizes[6], hudSizes[7], hudSizes[8], 0xFFF1AD0B, scaleX, scaleY, dxfont1_excelsior_sans, "left", "top", false, false, false, false, false) end) As you can see I replaced the multiplications with some variables that represent the calculations (so it doesn't need to multiply the number everytime that "onClientRender" is triggered) and the same goes for the tocolor function. So as far as my understanding goes this would increase the performance, right? or atleast that's my question doing this would have any impact in clients performance? or it's just complicating the code for no reason? Link to comment
JCL Posted May 4, 2019 Share Posted May 4, 2019 your question is about lua language performance and not about dx rendering . Link to comment
Awang Posted May 4, 2019 Share Posted May 4, 2019 (edited) I reccomend to use this resource to monitor the usages of your scripts: https://community.multitheftauto.com/index.php?p=resources&s=details&id=12364 But basicly, I dont believe, that your precalculate will decrease the usage. Multiply two number is not a hard task for the CPU, even in every frame. Edited May 4, 2019 by Awang Link to comment
Flower ☠ Power Posted May 4, 2019 Author Share Posted May 4, 2019 6 hours ago, Awang said: I reccomend to use this resource to monitor the usages of your scripts: https://community.multitheftauto.com/index.php?p=resources&s=details&id=12364 But basicly, I dont believe, that your precalculate will decrease the usage. Multiply two number is not a hard task for the CPU, even in every frame. Well, I haven't shown the complete code in this post, we're talking about 30+ multiplications, anyways thanks for posting that script I didn't know we had something like that, so useful 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